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 SCHED_RTG_H
17 #define SCHED_RTG_H
18 
19 #include <unistd.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #define DEFAULT_RT_FRAME_ID 8
26 #define FRAME_START (1 << 0)
27 #define FRAME_END (1 << 1)
28 
29 void SetTaskRtg(pid_t tid, unsigned int grpId);
30 void SetRtgStatus(unsigned long long status);
31 void SetRtgQos(int qos);
32 void SetRtgLoadMode(unsigned int grpId, bool utilEnabled, bool freqEnabled);
33 void set_task_min_util(pid_t tid, unsigned int util);
34 
35 /* inner use */
36 
37 struct RtgGroupTask {
38     pid_t pid;
39     unsigned int grpId;
40     bool pmu_sample_enabled;
41 };
42 
43 struct RtgLoadMode {
44     unsigned int grpId;
45     unsigned int freqEnabled;
46     unsigned int utilEnabled;
47 };
48 
49 struct TaskConfig {
50     pid_t pid;
51     unsigned int value;
52 };
53 
54 #define SET_TASK_RTG 11
55 #define SET_FRAME_STATUS 10
56 #define SET_FRAME_RATE 8
57 #define SET_RTG_LOAD_MODE 22
58 #define SET_TASK_MIN_UTIL 28
59 
60 #define PERF_CTRL_MAGIC 'x'
61 #define PERF_CTRL_SET_TASK_RTG _IOWR(PERF_CTRL_MAGIC, SET_TASK_RTG, struct RtgGroupTask)
62 #define PERF_CTRL_SET_FRAME_STATUS _IOWR(PERF_CTRL_MAGIC, SET_FRAME_STATUS, unsigned long long)
63 #define PERF_CTRL_SET_FRAME_RATE _IOWR(PERF_CTRL_MAGIC, SET_FRAME_RATE, int)
64 #define PERF_CTRL_SET_RTG_LOAD_MODE _IOW(PERF_CTRL_MAGIC, SET_RTG_LOAD_MODE, struct RtgLoadMode)
65 #define PERF_CTRL_SET_TASK_MIN_UTIL _IOW(PERF_CTRL_MAGIC, SET_TASK_MIN_UTIL, struct TaskConfig)
66 
67 #ifdef __cplusplus
68 }
69 #endif
70 
71 #endif /* SCHED_RTG_H */
72