Resource Tuner
Loading...
Searching...
No Matches
ResourceRegistry.h
1// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2// SPDX-License-Identifier: BSD-3-Clause-Clear
3
4#ifndef RESOURCE_REGISTRY_H
5#define RESOURCE_REGISTRY_H
6
7#include <iostream>
8#include <vector>
9#include <memory>
10#include <unordered_map>
11
12#include "Common.h"
13#include "Utils.h"
14#include "TargetRegistry.h"
15#include "Resource.h"
16#include "ResourceTunerSettings.h"
17#include "AuxRoutines.h"
18#include "Extensions.h"
19#include "Logger.h"
20
26 APPLY_CORE,
27 APPLY_CLUSTER,
28 APPLY_GLOBAL,
29 APPLY_CGROUP
30};
31
38typedef struct {
42 std::string mResourceName;
46 std::string mResourcePath;
70 uint8_t mModes;
74 int8_t mSupported;
88 ResourceLifecycleCallback mResourceApplierCallback;
89
94 ResourceLifecycleCallback mResourceTearCallback;
96
103private:
104 static std::shared_ptr<ResourceRegistry> resourceRegistryInstance;
105 int32_t mTotalResources;
106
107 std::vector<ResourceConfigInfo*> mResourceConfig;
108 std::unordered_map<uint32_t, int32_t> mSystemIndependentLayerMappings;
109 std::unordered_map<std::string, std::string> mDefaultValueStore;
110
112
113 int8_t isResourceConfigMalformed(ResourceConfigInfo* resourceConfigInfo);
114 void setLifeCycleCallbacks(ResourceConfigInfo* resourceConfigInfo);
115 void fetchAndStoreDefaults(ResourceConfigInfo* resourceConfigInfo);
116
117public:
119
126 void registerResource(ResourceConfigInfo* resourceConfigInfo, int8_t isBuSpecified=false);
127
128 std::vector<ResourceConfigInfo*> getRegisteredResources();
129
137 ResourceConfigInfo* getResourceById(uint32_t resourceId);
138
139 int32_t getResourceTableIndex(uint32_t resourceId);
140 int32_t getTotalResourcesCount();
141 std::string getDefaultValue(const std::string& fileName);
142
143 void addDefaultValue(const std::string& key, const std::string& value);
144 void restoreResourcesToDefaultValues();
145 void displayResources();
146
147 // Merge the Changes provided by the BU with the existing ResourceTable.
148 void pluginModifications();
149
150 static std::shared_ptr<ResourceRegistry> getInstance() {
151 if(resourceRegistryInstance == nullptr) {
152 resourceRegistryInstance = std::shared_ptr<ResourceRegistry>(new ResourceRegistry());
153 }
154 return resourceRegistryInstance;
155 }
156};
157
158class ResourceConfigInfoBuilder {
159private:
160 ResourceConfigInfo* mResourceConfigInfo;
161
162public:
163 ResourceConfigInfoBuilder();
164 ~ResourceConfigInfoBuilder();
165
166 ErrCode setName(const std::string& resourceName);
167 ErrCode setPath(const std::string& resourcePath);
168 ErrCode setResType(const std::string& resTypeString);
169 ErrCode setResID(const std::string& resIDString);
170 ErrCode setHighThreshold(const std::string& highThreshold);
171 ErrCode setLowThreshold(const std::string& lowThreshold);
172 ErrCode setPermissions(const std::string& permissionString);
173 ErrCode setModes(const std::string& modeString);
174 ErrCode setSupported(const std::string& supported);
175 ErrCode setPolicy(const std::string& policyString);
176 ErrCode setApplyType(const std::string& applyTypeString);
177
178 ResourceConfigInfo* build();
179};
180
181void defaultClusterLevelApplierCb(void* context);
182void defaultClusterLevelTearCb(void* context);
183void defaultCoreLevelApplierCb(void* context);
184void defaultCoreLevelTearCb(void* context);
185void defaultCGroupLevelApplierCb(void* context);
186void defaultCGroupLevelTearCb(void* context);
187void defaultGlobalLevelApplierCb(void* context);
188void defaultGlobalLevelTearCb(void* context);
189
190#endif
ErrCode
Custom Error Codes used by Resource Tuner APIs and Internal Functions.
Definition ErrCodes.h:17
Permissions
Certain resources can be accessed only by system clients and some which have no such restrictions and...
Definition Utils.h:35
Policy
Different Resource Policies supported by Resource Tuner.
Definition Utils.h:61
ResourceRegistry.
ResourceConfigInfo * getResourceById(uint32_t resourceId)
Get the ResourceConfigInfo object corresponding to the given Resource ID.
void registerResource(ResourceConfigInfo *resourceConfigInfo, int8_t isBuSpecified=false)
Used to register a Config specified (through YAML) Resource with Resource Tuner.
Application type or level for a Resource.
Representation of a single Resource Configuration.
ResourceLifecycleCallback mResourceTearCallback
Optional Custom Resource Tear Callback, it needs to be supplied by the BU via the Extension Interface...
enum Permissions mPermissions
The Permission Level needed by a client in order to tune this Resource.
enum ResourceApplyType mApplyType
Application Type Enum, indicating whether the specified value for the Resource by a Request,...
int32_t mLowThreshold
Min Possible Value which can be configured for this Resource.
uint16_t mResourceResID
Unique Resource ID associated with the resource.
uint8_t mResourceResType
Type of the Resource, for example: LPM, CPU_DCVS, GPU etc.
ResourceLifecycleCallback mResourceApplierCallback
Optional Custom Resource Applier Callback, it needs to be supplied by the BU via the Extension Interf...
uint8_t mModes
Specify the mode (ex: Display on, display off, doze) under which the Resource can be provisioned.
std::string mResourceName
Name of the Resource (Placeholder).
int8_t mSupported
boolean flag which is set if node is available for Tuning.
int32_t mHighThreshold
Max Possible Value which can be configured for this Resource.
enum Policy mPolicy
Policy by which the resource is governed, for example Higher is Better.
std::string mResourcePath
Path to the Sysfs node, CGroup controller file or as applicable.