Resource Tuner
Loading...
Searching...
No Matches
TargetRegistry.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 TARGET_REGISTRY_H
5#define TARGET_REGISTRY_H
6
11#include <memory>
12#include <unordered_map>
13#include <vector>
14#include <dirent.h>
15#include <fstream>
16#include <sstream>
17#include <algorithm>
18#include <cstring>
19#include <cstdlib>
20#include <sys/stat.h>
21#include <regex>
22#include <memory>
23
24#include "ResourceTunerSettings.h"
25#include "AuxRoutines.h"
26#include "ErrCodes.h"
27#include "Logger.h"
28
29#define POLICY_DIR_PATH "/sys/devices/system/cpu/cpufreq/"
30#define ONLINE_CPU_FILE_PATH "/sys/devices/system/cpu/online"
31#define CPU_CAPACITY_FILE_PATH "/sys/devices/system/cpu/cpu%d/cpu_capacity"
32
37typedef struct {
38 std::string mCgroupName;
39 int32_t mCgroupID;
41 int8_t mIsThreaded;
43
48typedef struct {
49 int32_t mPhysicalID;
50 int32_t mCapacity;
51 int32_t mStartCpu;
52 int32_t mNumCpus;
54
59typedef struct {
61 std::string mMpamGroupName;
62 int32_t mPriority;
64
69typedef struct {
70 std::string mCacheType;
73} CacheInfo;
74
81private:
82 static std::shared_ptr<TargetRegistry> targetRegistryInstance;
83
84 std::unordered_map<int32_t, int32_t> mLogicalToPhysicalClusterMapping;
85 std::unordered_map<int32_t, ClusterInfo*> mPhysicalClusters;
86 std::unordered_map<int32_t, CGroupConfigInfo*> mCGroupMapping;
87 std::unordered_map<int32_t, MpamGroupConfigInfo*> mMpamGroupMapping;
88 std::unordered_map<std::string, CacheInfo*> mCacheInfoMapping;
89
91
92 void generatePolicyBasedMapping(std::vector<std::string>& policyDirs);
93 void getClusterIdBasedMapping();
94
95public:
97
98 // Methods for adding Target Info via TargetConfig.yaml
99 void addClusterSpreadInfo(const std::string& physicalID, const std::string& coreCount);
100 void addClusterMapping(const std::string& logicalID, const std::string& physicalID);
101
102 // Method for adding CGroup configs from InitConfig.yaml
103 void addCGroupMapping(CGroupConfigInfo* cGroupConfigInfo);
104
105 // Method for adding Mpam Group configs from InitConfig.yaml
106 void addMpamGroupMapping(MpamGroupConfigInfo* mpamGroupConfigInfo);
107
108 void addCacheInfoMapping(CacheInfo* cacheInfo);
109
110 void getClusterIDs(std::vector<int32_t>& clusterIDs);
111
123 int32_t getPhysicalCoreId(int32_t logicalClusterId, int32_t logicalCoreId);
124
134 int32_t getPhysicalClusterId(int32_t logicalClusterId);
135
153
154 CGroupConfigInfo* getCGroupConfig(int32_t cGroupID);
155 void getCGroupNames(std::vector<std::string>& cGroupNames);
156 int32_t getCreatedCGroupsCount();
157
158 MpamGroupConfigInfo* getMpamGroupConfig(int32_t mpamGroupID);
159 void getMpamGroupNames(std::vector<std::string>& cGroupNames);
160 int32_t getCreatedMpamGroupsCount();
161
162 void displayTargetInfo();
163
164 static std::shared_ptr<TargetRegistry> getInstance() {
165 if(targetRegistryInstance == nullptr) {
166 targetRegistryInstance = std::shared_ptr<TargetRegistry>(new TargetRegistry());
167 }
168 return targetRegistryInstance;
169 }
170};
171
172class CGroupConfigInfoBuilder {
173private:
174 CGroupConfigInfo* mCGroupConfigInfo;
175
176public:
177 CGroupConfigInfoBuilder();
178
179 ErrCode setCGroupName(const std::string& cGroupName);
180 ErrCode setCGroupID(const std::string& cGroupIdentifier);
181 ErrCode setCreationNeeded(const std::string& creationNeeded);
182 ErrCode setThreaded(const std::string& isThreaded);
183
184 CGroupConfigInfo* build();
185};
186
187class MpamGroupConfigInfoBuilder {
188private:
189 MpamGroupConfigInfo* mMpamGroupInfo;
190
191public:
192 MpamGroupConfigInfoBuilder();
193
194 ErrCode setName(const std::string& name);
195 ErrCode setLgcID(const std::string& logicalID);
196 ErrCode setPriority(const std::string& priority);
197
198 MpamGroupConfigInfo* build();
199};
200
201class CacheInfoBuilder {
202private:
203 CacheInfo* mCacheInfo;
204
205public:
206 CacheInfoBuilder();
207
208 ErrCode setType(const std::string& type);
209 ErrCode setNumBlocks(const std::string& numBlocks);
210 ErrCode setPriorityAware(const std::string& isPriorityAware);
211
212 CacheInfo* build();
213};
214
215#endif
ErrCode
Custom Error Codes used by Resource Tuner APIs and Internal Functions.
Definition ErrCodes.h:17
TargetRegistry.
int32_t getPhysicalCoreId(int32_t logicalClusterId, int32_t logicalCoreId)
Called by the Verifier to get the physical core ID corresponding to the Logical Core ID value.
void readTargetInfo()
Called during Server Init, to read and Parse the Logical To Physical Core / Cluster Mappings.
int32_t getPhysicalClusterId(int32_t logicalClusterId)
Called by the Verifier to get the physical Cluster ID corresponding to the Logical Cluster ID value.
Representation of a single CGroup Configuration Info.
int32_t mCgroupID
32-bit identifier for the Cgroup (to be used as part of tuneResources API)
int8_t mIsThreaded
Flag indicating if the Cgroup is threaded.
int8_t mCreationNeeded
Flag indicating if Cgroup needs to be created by Resource Tuner, or if it already exists.
std::string mCgroupName
Cgroup Name.
Representation for a single Cluster Type Info.
int8_t mPriorityAware
Flag indicating if the Cache type is priority aware.
int32_t mNumCacheBlocks
Number of cache blocks for this type.
std::string mCacheType
Cache Type, for example: L2 or L3.
Representation for various Clusters detected on the device.
int32_t mCapacity
Cluster Capacity.
int32_t mNumCpus
Number of CPUs part of the Cluster.
int32_t mPhysicalID
Physical Cluster ID corresponding to the logical ID.
int32_t mStartCpu
Starting CPU index in this cluster.
Representation of a single Mpam Group Configuration Info.
int32_t mPriority
Mpam group Priority.
int32_t mMpamGroupInfoID
32-bit identifier for the Mpam Group (to be used as part of tuneResources API)
std::string mMpamGroupName
Mpam group Name.