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 "UrmPlatformAL.h"
12#include "Resource.h"
13#include "Extensions.h"
14#include "Logger.h"
15#include "Utils.h"
16
22 APPLY_CORE,
23 APPLY_CLUSTER,
24 APPLY_GLOBAL,
25 APPLY_CGROUP
26};
27
34typedef struct {
38 std::string mResourceName;
42 std::string mResourcePath;
66 uint8_t mModes;
80 ResourceLifecycleCallback mResourceApplierCallback;
84 enum TranslationUnit mUnit;
89 ResourceLifecycleCallback mResourceTearCallback;
91
98private:
99 static std::shared_ptr<ResourceRegistry> resourceRegistryInstance;
100 int32_t mTotalResources;
101
102 std::vector<ResConfInfo*> mResourceConfigs;
103 std::unordered_map<uint32_t, int32_t> mSILMap;
104 std::unordered_map<std::string, std::string> mDefaultValueStore;
105
107
108 int8_t isResourceConfigMalformed(ResConfInfo* resourceConfigInfo);
109 void setLifeCycleCallbacks(ResConfInfo* resourceConfigInfo);
110 void fetchAndStoreDefaults(ResConfInfo* resourceConfigInfo);
111
112public:
114
121 void registerResource(ResConfInfo* resourceConfigInfo);
122
123 std::vector<ResConfInfo*> getRegisteredResources();
124
132 ResConfInfo* getResConf(uint32_t resourceId);
133
134 int32_t getResourceTableIndex(uint32_t resourceId);
135 int32_t getTotalResourcesCount();
136 std::string getDefaultValue(const std::string& fileName);
137
138 void addDefaultValue(const std::string& key, const std::string& value);
139 void deleteDefaultValue(const std::string& filePath);
140 void restoreResourcesToDefaultValues();
141 void displayResources();
142
143 // Merge the Changes provided by the BU with the existing ResourceTable.
144 void pluginModifications();
145
146 static std::shared_ptr<ResourceRegistry> getInstance() {
147 if(resourceRegistryInstance == nullptr) {
148 resourceRegistryInstance = std::shared_ptr<ResourceRegistry>(new ResourceRegistry());
149 }
150 return resourceRegistryInstance;
151 }
152};
153
154class ResourceConfigInfoBuilder {
155private:
156 ResConfInfo* mResourceConfigInfo;
157
158public:
159 int32_t mTargetRefCount;
160
161 ResourceConfigInfoBuilder();
162 ~ResourceConfigInfoBuilder();
163
164 ErrCode setName(const std::string& resourceName);
165 ErrCode setPath(const std::string& resourcePath);
166 ErrCode setResType(const std::string& resTypeString);
167 ErrCode setResID(const std::string& resIDString);
168 ErrCode setHighThreshold(const std::string& highThreshold);
169 ErrCode setLowThreshold(const std::string& lowThreshold);
170 ErrCode setPermissions(const std::string& permissionString);
171 ErrCode setModes(const std::string& modeString);
172 ErrCode setSupported(const std::string& supported);
173 ErrCode setPolicy(const std::string& policyString);
174 ErrCode setTranslationUnit(const std::string& unitString);
175 ErrCode setApplyType(const std::string& applyTypeString);
176 ErrCode addTargetEnabled(const std::string& target);
177 ErrCode addTargetDisabled(const std::string& target);
178
179 ResConfInfo* build();
180};
181
182void defaultClusterLevelApplierCb(void* context);
183void defaultClusterLevelTearCb(void* context);
184void defaultCoreLevelApplierCb(void* context);
185void defaultCoreLevelTearCb(void* context);
186void defaultCGroupLevelApplierCb(void* context);
187void defaultCGroupLevelTearCb(void* context);
188void defaultGlobalLevelApplierCb(void* context);
189void defaultGlobalLevelTearCb(void* context);
190
191#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)
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.