• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef QOS_INTERFACE_H
17 #define QOS_INTERFACE_H
18 #include "internal_inc/config.h"
19 #include "eu/worker_thread.h"
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /*
25  * generic
26  */
27 #define SYSTEM_UID 1000
28 #define ROOT_UID 0
29 
30 /*
31  * auth_ctrl
32  */
33 struct AuthCtrlData {
34     unsigned int uid;
35     unsigned int type;
36     unsigned int rtgUaFlag;
37     unsigned int qosUaFlag;
38     unsigned int status;
39 };
40 
41 enum AuthManipulateType {
42     AUTH_ENABLE = 1,
43     AUTH_DELETE,
44     AUTH_GET,
45     AUTH_SWITCH,
46     AUTH_MAX_NR,
47 };
48 
49 enum AuthStatus {
50     AUTH_STATUS_DISABLED = 1,
51     AUTH_STATUS_SYSTEM_SERVER = 2,
52     AUTH_STATUS_FOREGROUND = 3,
53     AUTH_STATUS_BACKGROUND = 4,
54     AUTH_STATUS_DEAD,
55 };
56 
57 enum AuthCtrlCmdid {
58     BASIC_AUTH_CTRL = 1,
59     AUTH_CTRL_MAX_NR
60 };
61 
62 #define AUTH_CTRL_IPC_MAGIG 0xCD
63 
64 #define BASIC_AUTH_CTRL_OPERATION \
65     _IOWR(AUTH_CTRL_IPC_MAGIG, BASIC_AUTH_CTRL, struct AuthCtrlData)
66 
67 /*
68  * qos ctrl
69  */
70 
71 constexpr unsigned char NR_QOS = 6;
72 constexpr unsigned char QOS_NUM_MAX = 10;
73 
74 constexpr unsigned char AF_QOS_ALL = 0x0003;
75 constexpr unsigned char AF_QOS_DELEGATED = 0x0001;
76 
77 enum QosManipulateType {
78     QOS_APPLY = 1,
79     QOS_LEAVE,
80     QOS_GET,
81     QOS_MAX_NR,
82 };
83 
84 struct QosCtrlData {
85     int pid;
86     unsigned int type;
87     unsigned int level;
88     int qos;
89     int static_qos;
90     int dynamic_qos;
91 };
92 
93 struct QosPolicyData {
94     int latency_nice;
95     int uclamp_min;
96     int uclamp_max;
97     unsigned long affinity;
98     unsigned char priority;
99     unsigned char init_load;
100     unsigned char prefer_idle;
101 };
102 
103 enum QosPolicyType {
104     QOS_POLICY_DEFAULT = 1,
105     QOS_POLICY_SYSTEM_SERVER = 2,
106     QOS_POLICY_FRONT = 3,
107     QOS_POLICY_BACK = 4,
108     QOS_POLICY_MAX_NR,
109 };
110 
111 constexpr unsigned char QOS_FLAG_NICE = 0X01;
112 constexpr unsigned char QOS_FLAG_LATENCY_NICE = 0X02;
113 constexpr unsigned char QOS_FLAG_UCLAMP = 0x04;
114 constexpr unsigned char QOS_FLAG_RT = 0x08;
115 
116 #define QOS_FLAG_ALL    (QOS_FLAG_NICE          | \
117             QOS_FLAG_LATENCY_NICE       | \
118             QOS_FLAG_UCLAMP     | \
119             QOS_FLAG_RT)
120 
121 struct QosPolicyDatas {
122     int policyType;
123     unsigned int policyFlag;
124     struct QosPolicyData policys[NR_QOS + 1];
125 };
126 
127 enum QosCtrlCmdid {
128     QOS_CTRL = 1,
129     QOS_POLICY,
130     QOS_CTRL_MAX_NR
131 };
132 
133 #define QOS_CTRL_IPC_MAGIG 0xCC
134 
135 #define QOS_CTRL_BASIC_OPERATION \
136     _IOWR(QOS_CTRL_IPC_MAGIG, QOS_CTRL, struct QosCtrlData)
137 #define QOS_CTRL_POLICY_OPERATION \
138     _IOWR(QOS_CTRL_IPC_MAGIG, QOS_POLICY, struct QosPolicyDatas)
139 
140 /*
141  * RTG
142  */
143 #define AF_RTG_ALL          0x1fff
144 #define AF_RTG_DELEGATED    0x1fff
145 
146 struct RtgEnableData {
147     int enable;
148     int len;
149     char *data;
150 };
151 
152 enum RtgSchedCmdid {
153     SET_ENABLE = 1,
154     SET_RTG,
155     SET_CONFIG,
156     SET_RTG_ATTR,
157     BEGIN_FRAME_FREQ = 5,
158     END_FRAME_FREQ,
159     END_SCENE,
160     SET_MIN_UTIL,
161     SET_MARGIN,
162     LIST_RTG = 10,
163     LIST_RTG_THREAD,
164     SEARCH_RTG,
165     GET_ENABLE,
166     RTG_CTRL_MAX_NR,
167 };
168 
169 #define RTG_SCHED_IPC_MAGIC 0xAB
170 
171 #define CMD_ID_SET_ENABLE \
172     _IOWR(RTG_SCHED_IPC_MAGIC, SET_ENABLE, struct RtgEnableData)
173 
174 /*
175  * interface
176  */
177 int EnableRtg(bool flag);
178 int AuthEnable(unsigned int uid, unsigned int uaFlag, unsigned int status);
179 int AuthPause(unsigned int uid);
180 int AuthDelete(unsigned int uid);
181 int AuthGet(unsigned int uid, unsigned int *uaFlag, unsigned int *status);
182 int AuthSwitch(unsigned int uid, unsigned int rtgFlag, unsigned int qosFlag, unsigned int status);
183 int QosApply(unsigned int level);
184 int QosApplyForOther(unsigned int level, int tid);
185 int QosLeave(void);
186 int QosLeaveForOther(int tid);
187 int QosGet(struct QosCtrlData &data);
188 int QosGetForOther(int tid, struct QosCtrlData &data);
189 int QosPolicy(struct QosPolicyDatas *policyDatas);
190 typedef int (*Func_affinity)(unsigned long affinity, int tid);
191 void setFuncAffinity(Func_affinity func);
192 Func_affinity getFuncAffinity();
193 typedef void (*Func_priority)(unsigned char priority, ffrt::WorkerThread* thread);
194 void setFuncPriority(Func_priority func);
195 Func_priority getFuncPriority();
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 
201 #endif /* OQS_INTERFACE_H */
202