Resource Tuner
Loading...
Searching...
No Matches
CocoTable.h
Go to the documentation of this file.
1// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2// SPDX-License-Identifier: BSD-3-Clause-Clear
3
4#ifndef COCOQ_H
5#define COCOQ_H
6
7#include <fstream>
8#include <vector>
9#include <unordered_map>
10#include <mutex>
11#include <cerrno>
12#include <atomic>
13#include <cstring>
14#include <memory>
15
16#include "ResourceRegistry.h"
17#include "TargetRegistry.h"
18#include "Request.h"
19#include "RequestQueue.h"
20#include "ResourceTunerSettings.h"
21#include "MemoryPool.h"
22#include "Logger.h"
23#include "Utils.h"
24
90class CocoTable {
91private:
92 static std::shared_ptr<CocoTable> mCocoTableInstance;
93 static std::mutex instanceProtectionLock;
94
95 std::vector<ResourceConfigInfo*> mResourceTable;
96 std::unordered_map<int32_t, int32_t> mFlatClusterMap;
97
102 std::vector<std::vector<std::pair<CocoNode*, CocoNode*>>> mCocoTable;
103
107 std::vector<int32_t> mCurrentlyAppliedPriority;
108
109 CocoTable();
110
111 void timerExpired(Request* req);
112 void applyAction(CocoNode* currNode, int32_t index, int8_t priority);
113 void removeAction(int32_t index, Resource* resource);
114 void processResourceCleanupAt(Request* request, int32_t index);
115
116 int32_t getCocoTablePrimaryIndex(uint32_t resCode);
117 int32_t getCocoTableSecondaryIndex(Resource* resource, int8_t priority);
118
119 void deleteNode(CocoNode* node,
120 int32_t primaryIndex,
121 int32_t secondaryIndex,
122 int8_t priority);
123
124 int8_t insertInCocoTable(CocoNode* currNode,
125 Resource* resource,
126 int8_t priority);
127
128 void insertInCocoTableHigherLower(CocoNode* newNode,
129 int32_t primaryIndex,
130 int32_t secondaryIndex,
131 int32_t policy,
132 int8_t priority);
133
134 void insertInCocoTableLazyApply(CocoNode* newNode,
135 int32_t primaryIndex,
136 int32_t secondaryIndex,
137 int8_t priority);
138
139 void insertInCocoTableInstantApply(CocoNode* newNode,
140 int32_t primaryIndex,
141 int32_t secondaryIndex,
142 int8_t priority);
143
144public:
145 ~CocoTable();
146
158 int8_t insertRequest(Request* req);
159
171 int8_t removeRequest(Request* req);
172
184 int8_t updateRequest(Request* req, int64_t duration);
185
186 static std::shared_ptr<CocoTable> getInstance() {
187 if(mCocoTableInstance == nullptr) {
188 instanceProtectionLock.lock();
189 if(mCocoTableInstance == nullptr) {
190 try {
191 mCocoTableInstance = std::shared_ptr<CocoTable> (new CocoTable());
192 } catch(const std::bad_alloc& e) {
193 instanceProtectionLock.unlock();
194 return nullptr;
195 }
196 }
197 instanceProtectionLock.unlock();
198 }
199 return mCocoTableInstance;
200 }
201};
202
203#endif
204
CocoTable.
Definition CocoTable.h:90
int8_t insertRequest(Request *req)
Used to insert a request into the CocoTable, so that it can be applied to the desired Resource Nodes.
std::vector< int32_t > mCurrentlyAppliedPriority
Data structure storing the c2urrently applied priority for each resource. It is referred to whenever ...
Definition CocoTable.h:107
int8_t removeRequest(Request *req)
Used to untune a previously issued Tune Request.
std::vector< std::vector< std::pair< CocoNode *, CocoNode * > > > mCocoTable
The main data structure which is a 2D vector. It stores entries for each resource and each entry stor...
Definition CocoTable.h:102
int8_t updateRequest(Request *req, int64_t duration)
Used to update the duration of an Active Request.
Encapsulation type for a Resource Provisioning Request.
Definition Request.h:28
Used to store information regarding Resources / Tunables which need to be Provisioned as part of the ...
Definition Resource.h:16