Userspace Resource Manager
Loading...
Searching...
No Matches
UrmPlatformAL.h
1// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2// SPDX-License-Identifier: BSD-3-Clause-Clear
3
4#ifndef COMMON_UTILS_H
5#define COMMON_UTILS_H
6
7#ifdef __cplusplus
8#include <cstdint>
9#include <cstring>
10#else
11#include <stdint.h>
12#include <string.h>
13#endif
14
15// Use these options to configure a well defined value
16#define OPT_WITHMAX 0x00000001
17#define OPT_WITHMIN 0x00000002
18
19// Used to define the new config value, relative to the already configured value
20#define OPT_WITHREL 0X00000004
21
27typedef struct {
34 uint32_t mResCode;
40 int32_t mResInfo;
41 int32_t mOptionalInfo;
46 int32_t mNumValues;
47
48 union {
49 int32_t value;
50 int32_t* values;
51 } mResValue;
53
58enum RequestPriority {
59 REQ_PRIORITY_HIGH = 0,
60 REQ_PRIORITY_LOW,
61 NUMBER_OF_RQUEST_PRIORITIES
62};
63
71enum Modes {
72 MODE_RESUME = 0x01,
73 MODE_SUSPEND = 0x02,
74 MODE_DOZE = 0x04
75};
76
77// Helper Macros to set Request and SysResource attributes.
78#define SET_REQUEST_PRIORITY(properties, priority)({ \
79 int32_t retVal; \
80 if(properties < 0 || priority < 0 || priority >= NUMBER_OF_RQUEST_PRIORITIES) { \
81 retVal = -1; \
82 } else { \
83 retVal = (int32_t) ((properties | priority)); \
84 } \
85 retVal; \
86}) \
87
88#define ADD_ALLOWED_MODE(properties, mode)({ \
89 int32_t retVal; \
90 if(properties < 0 || mode < MODE_RESUME || mode > MODE_DOZE) { \
91 retVal = -1; \
92 } else { \
93 retVal = (int32_t) (properties | (((properties >> 8) | mode) << 8)); \
94 } \
95 retVal; \
96}) \
97
98#define EXTRACT_REQUEST_PRIORITY(properties)({ \
99 (int8_t) ((properties) & ((1 << 8) - 1)); \
100})
101
102#define EXTRACT_ALLOWED_MODES(properties)({ \
103 (int8_t) ((properties >> 8) & ((1 << 8) - 1)); \
104}) \
105
106// Define Utilities to parse and set the mResInfo field in Resource struct.
107#define EXTRACT_RESOURCE_CORE_VALUE(resInfo)({ \
108 (int8_t) ((resInfo) & ((1 << 8) - 1)); \
109}) \
110
111#define EXTRACT_RESOURCE_CLUSTER_VALUE(resInfo)({ \
112 (int8_t) ((resInfo >> 8) & ((1 << 8) - 1)); \
113}) \
114
115#define EXTRACT_RESOURCE_MPAM_VALUE(resInfo)({ \
116 (int8_t) ((resInfo >> 16) & ((1 << 8) - 1)); \
117}) \
118
119#define SET_RESOURCE_CORE_VALUE(resInfo, newValue)({ \
120 (int32_t) ((resInfo ^ EXTRACT_RESOURCE_CORE_VALUE(resInfo)) | newValue); \
121}) \
122
123#define SET_RESOURCE_CLUSTER_VALUE(resInfo, newValue)({ \
124 (int32_t) ((resInfo ^ (EXTRACT_RESOURCE_CLUSTER_VALUE(resInfo) << 8)) | (newValue << 8)); \
125}) \
126
127#define SET_RESOURCE_MPAM_VALUE(resInfo, newValue)({ \
128 (int32_t) ((resInfo ^ (EXTRACT_RESOURCE_MPAM_VALUE(resInfo) << 16)) | (newValue << 16)); \
129}) \
130
131#define GET_SIGNAL_ID(sigCode)({ \
132 (uint32_t) ((uint64_t)sigCode >> 32); \
133}) \
134
135#define GET_SIGNAL_TYPE(sigCode)({ \
136 (uint32_t) (((uint64_t)sigCode) & 0xffffffff); \
137}) \
138
139#define CONSTRUCT_RES_CODE(resType, resCode) ({ \
140 uint32_t resourceBitmap = 0; \
141 resourceBitmap |= ((uint32_t)resCode); \
142 resourceBitmap |= ((uint32_t)resType << 16); \
143 resourceBitmap; \
144}) \
145
146#define CONSTRUCT_SIG_CODE(sigCat, sigID) ({ \
147 uint32_t signalBitmap = 0; \
148 signalBitmap |= ((uint32_t)sigID); \
149 signalBitmap |= ((uint32_t)sigCat << 16); \
150 signalBitmap; \
151}) \
152
153#define CUSTOM(opCode) ({ \
154 uint32_t opBitmap = opCode; \
155 opBitmap |= (1 << 31); \
156 opBitmap; \
157}) \
158
159// Common ResCode and ResInfo codes
160// These enums can be used directly as part of tuneResources API, to uniquely
161// specify the resource to be tuned.
162// For target-specific resources use the custom ResourcesConfig.yaml file for
163// declaration. These values are only applicable for upstream resources.
164#define RES_CODE_LIST \
165/* Resources */ \
166X(RES_SCALE_MIN_FREQ, 0x00040000) \
167X(RES_SCALE_MAX_FREQ, 0x00040001) \
168X(RES_RATE_LIMIT_US, 0x00040002) \
169X(RES_CPU_IDLE_DISABLE_ST0, 0x00040003) \
170X(RES_CPU_IDLE_DISABLE_ST1, 0x00040004) \
171X(RES_CPU_IDLE_DISABLE_ST2, 0x00040005) \
172X(RES_SCHED_UTIL_CLAMP_MIN, 0x00030000) \
173X(RES_SCHED_UTIL_CLAMP_MAX, 0x00030001) \
174X(RES_SCHED_ENERGY_AWARE, 0x00030002) \
175X(RES_SCHED_RT_RUNTIME, 0x00030003) \
176X(RES_CPU_DMA_LATENCY, 0x00010000) \
177X(RES_PM_QOS_LATENCY, 0x00010001) \
178X(RES_DEVFREQ_GPU_MAX, 0x00050000) \
179X(RES_DEVFREQ_GPU_MIN, 0x00050001) \
180X(RES_DEVFREQ_GPU_POLL_INTV, 0x00050002) \
181X(RES_DEVFREQ_UFS_MAX, 0x000a0000) \
182X(RES_DEVFREQ_UFS_MIN, 0x000a0001) \
183X(RES_DEVFREQ_UFS_POLL_INTV, 0x000a0002) \
184/* cgroup resources */ \
185X(RES_CGRP_MOVE_PID, 0x00090000) \
186X(RES_CGRP_MOVE_TID, 0x00090001) \
187X(RES_CGRP_RUN_CORES, 0x00090002) \
188X(RES_CGRP_RUN_CORES_EXCL, 0x00090003) \
189X(RES_CGRP_FREEZE, 0x00090004) \
190X(RES_CGRP_LIMIT_CPU_TIME, 0x00090005) \
191X(RES_CGRP_RUN_WHEN_CPU_IDLE, 0x00090006) \
192X(RES_CGRP_UCLAMP_MIN, 0x00090007) \
193X(RES_CGRP_UCLAMP_MAX, 0x00090008) \
194X(RES_CGRP_REL_CPU_WEIGHT, 0x00090009) \
195X(RES_CGRP_HIGH_MEM, 0x0009000a) \
196X(RES_CGRP_MAX_MEM, 0x0009000b) \
197X(RES_CGRP_LOW_MEM, 0x0009000c) \
198X(RES_CGRP_MIN_MEM, 0x0009000d) \
199X(RES_CGRP_SWAP_MAX_MEMORY, 0x0009000e) \
200X(RES_CGRP_IO_WEIGHT, 0x0009000f) \
201X(RES_CGRP_BFQ_IO_WEIGHT, 0x00090010) \
202X(RES_CGRP_CPU_LATENCY, 0x00090011) \
203X(FOCUSED_CGROUP_IDENTIFIER, 0x00000004) \
204/* Cluster and Core Configurations */ \
205X(CLUSTER_LITTLE_ALL_CORES, 0x00000000) \
206X(CLUSTER_LITTLE_CORE_0, 0x00000001) \
207X(CLUSTER_LITTLE_CORE_1, 0x00000002) \
208X(CLUSTER_LITTLE_CORE_2, 0x00000003) \
209X(CLUSTER_LITTLE_CORE_3, 0x00000004) \
210X(CLUSTER_BIG_ALL_CORES, 0x00000100) \
211X(CLUSTER_BIG_CORE_0, 0x00000101) \
212X(CLUSTER_BIG_CORE_1, 0x00000102) \
213X(CLUSTER_BIG_CORE_2, 0x00000103) \
214X(CLUSTER_BIG_CORE_3, 0x00000104) \
215X(CLUSTER_PLUS_ALL_CORES, 0x00000200) \
216X(CLUSTER_PLUS_CORE_0, 0x00000201) \
217X(CLUSTER_PLUS_CORE_1, 0x00000202) \
218X(CLUSTER_PLUS_CORE_2, 0x00000203) \
219X(CLUSTER_PLUS_CORE_3, 0x00000204) \
220/* misc */ \
221X(DEFAULT_SIGNAL_TYPE, 0x00000000) \
222
223enum ResCodesDef {
224#define X(name, value) name = value,
225 RES_CODE_LIST
226#undef X
227};
228
229typedef struct {
230 const char* name;
231 uint32_t code;
232} ResPair;
233
234static ResPair resCodeMapping[] = {
235#define X(name, value) {#name, (uint32_t)value,},
236 RES_CODE_LIST
237#undef X
238};
239
240static inline uint32_t getResCodeFromString(const char* strCode, int8_t* found) {
241 int32_t size = sizeof(resCodeMapping) / sizeof(resCodeMapping[0]);
242 for(int32_t i = 0; i < size; i++) {
243 if(strcmp(resCodeMapping[i].name, strCode) == 0) {
244 *found = true;
245 return resCodeMapping[i].code;
246 }
247 }
248
249 return 0;
250}
251
252//Predefined Resource Types
253enum {
254 CPU_LPM = 0x00,
255 CACHE_MGMT = 0x01,
256 CPU_SCHED = 0x02,
257 CPU_FREQ = 0x03,
258 GPU_OPP = 0x04,
259 NPU_OPP = 0x06,
260 MEMORY_QOS = 0x07,
261 MPAM_QOS = 0x08,
262 CGRP_OPS = 0x09,
263 STORAGE_IO = 0x0a,
264 CUSTOM = 0x80
265};
266
267// Predefined Signal Categories
268enum {
269 URM_SIG_CAT_TEST = 0x01,
270 URM_SIG_CAT_GENERIC = 0x02,
271 URM_SIG_CAT_MULTIMEDIA = 0x03,
272 URM_SIG_CAT_GAMING = 0x04,
273 URM_SIG_CAT_BROWSER = 0x05,
274 URM_SIG_CAT_CUSTOM = 0x80
275};
276
277//Signal codes
278enum {
279 // Generic
280 URM_SIG_APP_OPEN = 0x00020001,
281 URM_SIG_BROWSER_APP_OPEN = 0x00020002,
282 URM_SIG_GAME_APP_OPEN = 0x00020003,
283 URM_SIG_MULTIMEDIA_APP_OPEN = 0x00020004,
284
285 // Multimedia
286 URM_SIG_VIDEO_DECODE = 0x00030001,
287 URM_SIG_CAMERA_PREVIEW = 0x00030002,
288 URM_SIG_CAMERA_ENCODE = 0x00030003,
289 URM_SIG_CAMERA_ENCODE_MULTI_STREAMS = 0x00030004,
290 URM_SIG_ENCODE_DECODE = 0x00030005,
291};
292
293#endif
Used to store information regarding Resources / Tunables which need to be Provisioned as part of the ...
int32_t value
Use this field for single Valued Resources.
uint32_t mResCode
A uniqued 32-bit (unsigned) identifier for the Resource.
int32_t mNumValues
Number of values to be configured for the Resource, both single-valued and multi-valued Resources are...
int32_t mResInfo
Holds Logical Core and Cluster Information:
int32_t mOptionalInfo
Field to hold optional information for Request Processing.
int32_t * values
Use this field for Multi Valued Resources.