Userspace Resource Manager
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 <vector>
8#include <memory>
9#include <unordered_map>
10
11#include "Common.h"
12#include "Utils.h"
13#include "TargetRegistry.h"
14#include "Resource.h"
15#include "UrmSettings.h"
16#include "AuxRoutines.h"
17#include "Extensions.h"
18#include "Logger.h"
19
25 APPLY_CORE,
26 APPLY_CLUSTER,
27 APPLY_GLOBAL,
28 APPLY_CGROUP
29};
30
37typedef struct {
41 std::string mResourceName;
45 std::string mResourcePath;
69 uint8_t mModes;
83 ResourceLifecycleCallback mResourceApplierCallback;
87 enum TranslationUnit mUnit;
92 ResourceLifecycleCallback mResourceTearCallback;
94
101private:
102 static std::shared_ptr<ResourceRegistry> resourceRegistryInstance;
103 int32_t mTotalResources;
104
105 std::vector<ResConfInfo*> mResourceConfigs;
106 std::unordered_map<uint32_t, int32_t> mSystemIndependentLayerMappings;
107 std::unordered_map<std::string, std::string> mDefaultValueStore;
108
110
111 int8_t isResourceConfigMalformed(ResConfInfo* resourceConfigInfo);
112 void setLifeCycleCallbacks(ResConfInfo* resourceConfigInfo);
113 void fetchAndStoreDefaults(ResConfInfo* resourceConfigInfo);
114
115public:
117
124 void registerResource(ResConfInfo* resourceConfigInfo, int8_t isBuSpecified=false);
125
126 std::vector<ResConfInfo*> getRegisteredResources();
127
135 ResConfInfo* getResConf(uint32_t resourceId);
136
137 int32_t getResourceTableIndex(uint32_t resourceId);
138 int32_t getTotalResourcesCount();
139 std::string getDefaultValue(const std::string& fileName);
140
141 void addDefaultValue(const std::string& key, const std::string& value);
142 void restoreResourcesToDefaultValues();
143 void displayResources();
144
145 // Merge the Changes provided by the BU with the existing ResourceTable.
146 void pluginModifications();
147
148 static std::shared_ptr<ResourceRegistry> getInstance() {
149 if(resourceRegistryInstance == nullptr) {
150 resourceRegistryInstance = std::shared_ptr<ResourceRegistry>(new ResourceRegistry());
151 }
152 return resourceRegistryInstance;
153 }
154};
155
156class ResourceConfigInfoBuilder {
157private:
158 ResConfInfo* mResourceConfigInfo;
159
160public:
161 int32_t mTargetRefCount;
162
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 setTranslationUnit(const std::string& unitString);
177 ErrCode setApplyType(const std::string& applyTypeString);
178 ErrCode addTargetEnabled(const std::string& target);
179 ErrCode addTargetDisabled(const std::string& target);
180
181 ResConfInfo* build();
182};
183
184void defaultClusterLevelApplierCb(void* context);
185void defaultClusterLevelTearCb(void* context);
186void defaultCoreLevelApplierCb(void* context);
187void defaultCoreLevelTearCb(void* context);
188void defaultCGroupLevelApplierCb(void* context);
189void defaultCGroupLevelTearCb(void* context);
190void defaultGlobalLevelApplierCb(void* context);
191void defaultGlobalLevelTearCb(void* context);
192
193#endif
ErrCode
Custom Error Codes used by Resource Tuner APIs and Internal Functions.
Definition ErrCodes.h:19
Permissions
Certain resources can be accessed only by system clients and some which have no such restrictions and...
Definition Utils.h:43
Policy
Different Resource Policies supported by Resource Tuner.
Definition Utils.h:69
ResourceRegistry.
void registerResource(ResConfInfo *resourceConfigInfo, int8_t isBuSpecified=false)
Used to register a Config specified (through YAML) Resource with Resource Tuner.
ResConfInfo * getResConf(uint32_t resourceId)
Get the ResConfInfo object corresponding to the given Resource ID.
Representation of a single Resource Configuration.
int32_t mHighThreshold
Max Possible Value which can be configured for this 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...
ResourceLifecycleCallback mResourceTearCallback
Optional Custom Resource Tear Callback, it needs to be supplied by the BU via the Extension Interface...
enum Policy mPolicy
Policy by which the resource is governed, for example Higher is Better.
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,...
std::string mResourceName
Name of the Resource (Placeholder).
uint8_t mModes
Specify the mode (ex: Display on, display off, doze) under which the Resource can be provisioned.
enum TranslationUnit mUnit
Translation Unit for the Resource, for example KB, MB, MHz etc.
int32_t mLowThreshold
Min Possible Value which can be configured for this Resource.
uint16_t mResourceResID
Unique Resource ID associated with the resource.
std::string mResourcePath
Path to the Sysfs node, CGroup controller file or as applicable.
Application type or level for a Resource.