1 /* 2 * Copyright (c) 2022 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 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /* 24 * generic 25 */ 26 constexpr int SYSTEM_UID = 1000; 27 constexpr int ROOT_UID = 0; 28 constexpr int NR_QOS = 7; 29 constexpr unsigned int SET_RTG_ENABLE = 1; 30 constexpr unsigned int QOS_CTRL_IPC_MAGIC = 0xCC; 31 constexpr unsigned int RTG_SCHED_IPC_MAGIC = 0xAB; 32 33 constexpr unsigned int AF_QOS_ALL = 0x0003; 34 constexpr unsigned int AF_QOS_DELEGATED = 0x0001; 35 36 /* 37 * qos ctrl 38 */ 39 enum class QosManipulateType { 40 QOS_APPLY = 1, 41 QOS_LEAVE, 42 QOS_GET, 43 QOS_MAX_NR, 44 }; 45 46 struct QosCtrlData { 47 int pid; 48 unsigned int type; 49 unsigned int level; 50 int qos; 51 #ifdef QOS_EXT_ENABLE 52 int staticQos; 53 int dynamicQos; 54 bool tagSchedEnable = false; 55 #endif 56 }; 57 58 struct QosPolicyData { 59 int nice; 60 int latencyNice; 61 int uclampMin; 62 int uclampMax; 63 int rtSchedPriority; 64 int policy; 65 }; 66 67 enum SchedPolicy { 68 SCHED_POLICY_OTHER = 0, 69 SCHED_POLICY_FIFO = 1, 70 SCHED_POLICY_RR = 2, 71 SCHED_POLICY_RT_EX = 0xFF, 72 }; 73 74 enum QosPolicyType { 75 QOS_POLICY_DEFAULT = 1, 76 QOS_POLICY_SYSTEM_SERVER = 2, 77 QOS_POLICY_FRONT = 3, 78 QOS_POLICY_BACK = 4, 79 QOS_POLICY_FOCUS = 5, 80 QOS_POLICY_MAX_NR, 81 }; 82 83 #define QOS_FLAG_NICE 0X01 84 #define QOS_FLAG_LATENCY_NICE 0X02 85 #define QOS_FLAG_UCLAMP 0x04 86 #define QOS_FLAG_RT 0x08 87 88 #define QOS_FLAG_ALL (QOS_FLAG_NICE | \ 89 QOS_FLAG_LATENCY_NICE | \ 90 QOS_FLAG_UCLAMP | \ 91 QOS_FLAG_RT) 92 93 #define SCHED_RESET_ON_FORK 0x40000000 94 95 struct QosPolicyDatas { 96 int policyType; 97 unsigned int policyFlag; 98 struct QosPolicyData policys[NR_QOS]; 99 }; 100 101 enum QosCtrlCmdid { 102 QOS_CTRL = 1, 103 QOS_POLICY = 2, 104 QOS_CTRL_MAX_NR 105 }; 106 107 #define QOS_CTRL_BASIC_OPERATION \ 108 _IOWR(QOS_CTRL_IPC_MAGIC, QOS_CTRL, struct QosCtrlData) 109 #define QOS_CTRL_POLICY_OPERATION \ 110 _IOWR(QOS_CTRL_IPC_MAGIC, QOS_POLICY, struct QosPolicyDatas) 111 112 struct RtgEnableData { 113 int enable; 114 int len; 115 char *data; 116 }; 117 118 #define CMD_ID_SET_ENABLE \ 119 _IOWR(RTG_SCHED_IPC_MAGIC, SET_RTG_ENABLE, struct RtgEnableData) 120 121 /* 122 * interface 123 */ 124 int EnableRtg(bool flag); 125 int QosApply(unsigned int level); 126 int QosApplyForOther(unsigned int level, int tid); 127 int QosLeave(void); 128 int QosLeaveForOther(int tid); 129 int QosPolicySet(const struct QosPolicyDatas *policyDatas); 130 int QosGet(int &level); 131 int QosGetForOther(int tid, int &level); 132 133 #ifdef __cplusplus 134 } 135 #endif 136 #endif /* OQS_INTERFACE_H */ 137