Resource Tuner
Loading...
Searching...
No Matches
ClientDataManager.h
1// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2// SPDX-License-Identifier: BSD-3-Clause-Clear
3
4#ifndef CLIENT_DATA_MANAGER_H
5#define CLIENT_DATA_MANAGER_H
6
7#include <vector>
8#include <unordered_map>
9#include <unordered_set>
10#include <shared_mutex>
11#include <memory>
12#include <mutex>
13#include "string.h"
14#include "unistd.h"
15#include "fstream"
16#include "sstream"
17
18#include "ResourceTunerSettings.h"
19#include "MemoryPool.h"
20#include "Logger.h"
21#include "Utils.h"
22
23typedef struct {
24 std::vector<int32_t>* mClientTIDs;
25 uint8_t mClientType;
26} ClientInfo;
27
28typedef struct {
29 std::unordered_set<int64_t>* mClientHandles;
30 int64_t mLastRequestTimestamp;
31 double mHealth;
32} ClientTidData;
33
45private:
46 static std::shared_ptr<ClientDataManager> mClientDataManagerInstance;
47 static std::mutex instanceProtectionLock;
48 std::unordered_map<int32_t, ClientInfo*> mClientRepo;
49 std::unordered_map<int32_t, ClientTidData*> mClientTidRepo;
50 std::shared_timed_mutex mGlobalTableMutex;
51
53
54public:
63 int8_t clientExists(int32_t clientPID, int32_t clientTID);
64
74 int8_t createNewClient(int32_t clientPID, int32_t clientTID);
75
82 std::unordered_set<int64_t>* getRequestsByClientID(int32_t clientTID);
83
90 void insertRequestByClientId(int32_t clientTID, int64_t requestHandle);
91
98 void deleteRequestByClientId(int32_t clientTID, int64_t requestHandle);
99
107 double getHealthByClientID(int32_t clientTID);
108
116 int64_t getLastRequestTimestampByClientID(int32_t clientTID);
117
124 void updateHealthByClientID(int32_t clientTID, double health);
125
132 void updateLastRequestTimestampByClientID(int32_t clientTID, int64_t currentMillis);
133
143 int8_t getClientLevelByClientID(int32_t clientPID);
144
151 std::vector<int32_t>* getThreadsByClientId(int32_t clientPID);
152
157 void getActiveClientList(std::vector<int32_t>& clientList);
158
163 void deleteClientPID(int32_t clientPID);
164
169 void deleteClientTID(int32_t clientTID);
170
171 static std::shared_ptr<ClientDataManager> getInstance() {
172 if(mClientDataManagerInstance == nullptr) {
173 instanceProtectionLock.lock();
174 if(mClientDataManagerInstance == nullptr) {
175 try {
176 mClientDataManagerInstance = std::shared_ptr<ClientDataManager> (new ClientDataManager());
177 } catch(const std::bad_alloc& e) {
178 instanceProtectionLock.unlock();
179 return nullptr;
180 }
181 }
182 instanceProtectionLock.unlock();
183 }
184 return mClientDataManagerInstance;
185 }
186};
187
188#endif
void deleteClientPID(int32_t clientPID)
Delete a client PID Entry from the Client Table.
void getActiveClientList(std::vector< int32_t > &clientList)
This method is called by the PulseMonitor to fetch the list of all active clients.
void deleteClientTID(int32_t clientTID)
Delete a client TID Entry from the Client TID Data Table.
void updateHealthByClientID(int32_t clientTID, double health)
This method is called by the RateLimiter to update the current health for a given client in the Clien...
std::unordered_set< int64_t > * getRequestsByClientID(int32_t clientTID)
Returns a list of active requests for the client with the given PID.
double getHealthByClientID(int32_t clientTID)
This method is called by the RateLimiter to fetch the current health for a given client in the Client...
void updateLastRequestTimestampByClientID(int32_t clientTID, int64_t currentMillis)
This method is called by the RateLimiter to update the Last Request Timestamp for a given client in t...
void deleteRequestByClientId(int32_t clientTID, int64_t requestHandle)
This method is called by the RequestMap to delete a Request (represented by it's handle) for the clie...
std::vector< int32_t > * getThreadsByClientId(int32_t clientPID)
Returns the list of threads corresponding to the thread with the given ID.
int64_t getLastRequestTimestampByClientID(int32_t clientTID)
This method is called by the RateLimiter to fetch the Last Request Timestamp for a given client in th...
int8_t createNewClient(int32_t clientPID, int32_t clientTID)
Create a new entry for the client with the given PID in the ClientData Table.
std::unordered_map< int32_t, ClientTidData * > mClientTidRepo
Maintains Client Info indexed by TID.
int8_t clientExists(int32_t clientPID, int32_t clientTID)
Checks if the client with the given ID exists in the Client Data Table.
int8_t getClientLevelByClientID(int32_t clientPID)
This method is called by the Verifier to fetch the Permission Level for a given client in the Client ...
std::unordered_map< int32_t, ClientInfo * > mClientRepo
Maintains Client Info indexed by PID.
void insertRequestByClientId(int32_t clientTID, int64_t requestHandle)
This method is called by the RequestMap to insert a new Request (represented by it's handle) for the ...