1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * include/linux/sched/qos_ctrl.h 4 * 5 * Copyright (c) 2022 Huawei Device Co., Ltd. 6 */ 7 8 #ifndef _QOS_CTRL_H 9 #define _QOS_CTRL_H 10 11 #include <linux/sched.h> 12 #include <linux/fs.h> 13 14 enum ioctl_abi_format_qos{ 15 QOS_IOCTL_ABI_ARM32, 16 QOS_IOCTL_ABI_AARCH64, 17 }; 18 19 enum qos_ctrl_cmdid { 20 QOS_CTRL = 1, 21 QOS_POLICY, 22 QOS_CTRL_MAX_NR 23 }; 24 25 #define QOS_CTRL_IPC_MAGIG 0xCC 26 27 #define QOS_CTRL_BASIC_OPERATION \ 28 _IOWR(QOS_CTRL_IPC_MAGIG, QOS_CTRL, struct qos_ctrl_data) 29 #define QOS_CTRL_POLICY_OPERATION \ 30 _IOWR(QOS_CTRL_IPC_MAGIG, QOS_POLICY, struct qos_policy_datas) 31 32 #define NO_QOS -1 33 #define NR_QOS 6 34 #define NR_RT_QOS 1 35 #define MIN_RT_QOS_LEVEL (NR_QOS - NR_RT_QOS) 36 37 #define QOS_NUM_MAX 2000 38 39 enum qos_manipulate_type { 40 QOS_APPLY = 1, 41 QOS_LEAVE, 42 QOS_OPERATION_CMD_MAX_NR, 43 }; 44 45 #ifndef CONFIG_QOS_POLICY_MAX_NR 46 #define QOS_POLICYS_COUNT 5 47 #else 48 #define QOS_POLICYS_COUNT CONFIG_QOS_POLICY_MAX_NR 49 #endif 50 51 /* 52 * keep match with auth_status 53 * 54 * range (QOS_POLICY_SYSTEM, QOS_POLICY_MAX_NR) could defined by user 55 * use ctrl_qos_policy 56 */ 57 enum qos_policy_type { 58 QOS_POLICY_DEFAULT = 1, /* reserved for "NO QOS" */ 59 QOS_POLICY_SYSTEM = 2, /* reserved for ROOT and SYSTEM */ 60 QOS_POLICY_MAX_NR = QOS_POLICYS_COUNT, 61 }; 62 63 struct qos_ctrl_data { 64 int pid; 65 66 /* 67 * type: operation type, see qos_manipulate_type 68 * level: valid from 1 to NR_QOS. Larger value, more aggressive supply 69 */ 70 unsigned int type; 71 72 /* 73 * user space level, range from [1, NR_QOS] 74 * 75 * NOTICE!!!: 76 * minus 1 before use in kernel, so the kernel range is [0, NR_QOS) 77 */ 78 unsigned int level; 79 }; 80 81 struct qos_policy_data { 82 int nice; 83 int latency_nice; 84 int uclamp_min; 85 int uclamp_max; 86 int rt_sched_priority; 87 }; 88 89 #define QOS_FLAG_NICE 0x01 90 #define QOS_FLAG_LATENCY_NICE 0x02 91 #define QOS_FLAG_UCLAMP 0x04 92 #define QOS_FLAG_RT 0x08 93 94 #define QOS_FLAG_ALL (QOS_FLAG_NICE | \ 95 QOS_FLAG_LATENCY_NICE | \ 96 QOS_FLAG_UCLAMP | \ 97 QOS_FLAG_RT) 98 99 struct qos_policy_datas { 100 /* 101 * policy_type: id for qos policy, valid from [1, QOS_POLICY_MAX_NR) 102 * policy_flag: control valid sched attr for policy, QOS_FLAG_ALL for whole access 103 * policys: sched params for specific level qos, minus 1 for matching struct in kerenl 104 */ 105 int policy_type; 106 unsigned int policy_flag; 107 struct qos_policy_data policys[NR_QOS + 1]; 108 }; 109 110 struct auth_struct; 111 112 int qos_apply(struct qos_ctrl_data *data); 113 int qos_leave(struct qos_ctrl_data *data); 114 115 void qos_switch(struct auth_struct *auth, int target_status); 116 117 void init_task_qos(struct task_struct *p); 118 void sched_exit_qos_list(struct task_struct *p); 119 void remove_qos_tasks(struct auth_struct *auth); 120 121 long do_qos_ctrl_ioctl(int abi, struct file *file, unsigned int cmd, unsigned long arg); 122 123 #endif /* _QOS_CTRL_H */ 124 125