Userspace Resource Manager
Loading...
Searching...
No Matches
Common.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 CONSTRUCT_RES_CODE(resType, resCode) ({ \
132 uint32_t resourceBitmap = 0; \
133 resourceBitmap |= ((uint32_t)resCode); \
134 resourceBitmap |= ((uint32_t)resType << 16); \
135 resourceBitmap; \
136}) \
137
138#define CONSTRUCT_SIG_CODE(sigID, category) ({ \
139 uint32_t signalBitmap = 0; \
140 signalBitmap |= ((uint32_t)category); \
141 signalBitmap |= ((uint32_t)sigID << 8); \
142 signalBitmap; \
143}) \
144
145#define CUSTOM(opCode) ({ \
146 uint32_t opBitmap = opCode; \
147 opBitmap |= (1 << 31); \
148 opBitmap; \
149}) \
150
151// Common ResCode and ResInfo codes
152// These enums can be used directly as part of tuneResources API, to uniquely
153// specify the resource to be tuned.
154// For target-specific resources use the custom ResourcesConfig.yaml file for
155// declaration. These values are only applicable for upstream resources.
156#define RES_CODE_LIST \
157/* Resources */ \
158X(RES_SCALE_MIN_FREQ, 0x00040000) \
159X(RES_SCALE_MAX_FREQ, 0x00040001) \
160X(RES_RATE_LIMIT_US, 0x00040002) \
161X(RES_SCHED_UTIL_CLAMP_MIN, 0x00030000) \
162X(RES_SCHED_UTIL_CLAMP_MAX, 0x00030001) \
163X(RES_SCHED_ENERGY_AWARE, 0x00030002) \
164X(RES_CPU_DMA_LATENCY, 0x00010000) \
165X(RES_PM_QOS_LATENCY, 0x00010001) \
166/* cgroup resources */ \
167X(RES_CGRP_MOVE_PID, 0x00090000) \
168X(RES_CGRP_MOVE_TID, 0x00090001) \
169X(RES_CGRP_RUN_CORES, 0x00090002) \
170X(RES_CGRP_RUN_CORES_EXCL, 0x00090003) \
171X(RES_CGRP_FREEZE, 0x00090004) \
172X(RES_CGRP_LIMIT_CPU_TIME, 0x00090005) \
173X(RES_CGRP_RUN_WHEN_CPU_IDLE, 0x00090006) \
174X(RES_CGRP_UCLAMP_MIN, 0x00090007) \
175X(RES_CGRP_UCLAMP_MAX, 0x00090008) \
176X(RES_CGRP_REL_CPU_WEIGHT, 0x00090009) \
177X(RES_CGRP_HIGH_MEM, 0x0009000a) \
178X(RES_CGRP_MAX_MEM, 0x0009000b) \
179X(RES_CGRP_LOW_MEM, 0x0009000c) \
180X(RES_CGRP_MIN_MEM, 0x0009000d) \
181X(RES_CGRP_SWAP_MAX_MEMORY, 0x0009000e) \
182X(RES_CGRP_IO_WEIGHT, 0x0009000f) \
183X(RES_CGRP_BFQ_IO_WEIGHT, 0x00090010) \
184X(RES_CGRP_CPU_LATENCY, 0x00090011) \
185X(FOCUSED_CGROUP_IDENTIFIER, 0x00000004) \
186/* Cluster and Core Configurations */ \
187X(CLUSTER_LITTLE_ALL_CORES, 0x00000000) \
188X(CLUSTER_LITTLE_CORE_0, 0x00000001) \
189X(CLUSTER_LITTLE_CORE_1, 0x00000002) \
190X(CLUSTER_LITTLE_CORE_2, 0x00000003) \
191X(CLUSTER_LITTLE_CORE_3, 0x00000004) \
192X(CLUSTER_BIG_ALL_CORES, 0x00000100) \
193X(CLUSTER_BIG_CORE_0, 0x00000101) \
194X(CLUSTER_BIG_CORE_1, 0x00000102) \
195X(CLUSTER_BIG_CORE_2, 0x00000103) \
196X(CLUSTER_BIG_CORE_3, 0x00000104) \
197X(CLUSTER_PLUS_ALL_CORES, 0x00000200) \
198X(CLUSTER_PLUS_CORE_0, 0x00000201) \
199X(CLUSTER_PLUS_CORE_1, 0x00000202) \
200X(CLUSTER_PLUS_CORE_2, 0x00000203) \
201X(CLUSTER_PLUS_CORE_3, 0x00000204) \
202
203enum ResCodesDef {
204#define X(name, value) name = value,
205 RES_CODE_LIST
206#undef X
207};
208
209typedef struct {
210 const char* name;
211 uint32_t code;
212} ResPair;
213
214static ResPair resCodeMapping[] = {
215#define X(name, value) {#name, (uint32_t)value,},
216 RES_CODE_LIST
217#undef X
218};
219
220static uint32_t getResCodeFromString(const char* strCode, int8_t* found) {
221 int32_t size = sizeof(resCodeMapping) / sizeof(resCodeMapping[0]);
222 for(int32_t i = 0; i < size; i++) {
223 if(strcmp(resCodeMapping[i].name, strCode) == 0) {
224 *found = true;
225 return resCodeMapping[i].code;
226 }
227 }
228
229 return 0;
230}
231
232#endif
Used to store information regarding Resources / Tunables which need to be Provisioned as part of the ...
Definition Common.h:27
int32_t value
Use this field for single Valued Resources.
Definition Common.h:49
uint32_t mResCode
A uniqued 32-bit (unsigned) identifier for the Resource.
Definition Common.h:34
int32_t mNumValues
Number of values to be configured for the Resource, both single-valued and multi-valued Resources are...
Definition Common.h:46
int32_t mResInfo
Holds Logical Core and Cluster Information:
Definition Common.h:40
int32_t mOptionalInfo
Field to hold optional information for Request Processing.
Definition Common.h:41
int32_t * values
Use this field for Multi Valued Resources.
Definition Common.h:50