]> git.ipfire.org Git - thirdparty/util-linux.git/blob - schedutils/sched_attr.h
flock: initialize timevals [-Werror=maybe-uninitialized]
[thirdparty/util-linux.git] / schedutils / sched_attr.h
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2, as
4 * published by the Free Software Foundation
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License along
12 * with this program; if not, write to the Free Software Foundation, Inc.,
13 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14 *
15 * Copyright (C) 2004 Robert Love
16 * Copyright (C) 2020-2021 Qais Yousef
17 * Copyright (C) 2020-2021 Arm Ltd
18 */
19 #ifndef UTIL_LINUX_SCHED_ATTR_H
20 #define UTIL_LINUX_SCHED_ATTR_H
21
22 /* the SCHED_BATCH is supported since Linux 2.6.16
23 * -- temporary workaround for people with old glibc headers
24 */
25 #if defined (__linux__) && !defined(SCHED_BATCH)
26 # define SCHED_BATCH 3
27 #endif
28
29 /* the SCHED_IDLE is supported since Linux 2.6.23
30 * commit id 0e6aca43e08a62a48d6770e9a159dbec167bf4c6
31 * -- temporary workaround for people with old glibc headers
32 */
33 #if defined (__linux__) && !defined(SCHED_IDLE)
34 # define SCHED_IDLE 5
35 #endif
36
37 /* flag by sched_getscheduler() */
38 #if defined(__linux__) && !defined(SCHED_RESET_ON_FORK)
39 # define SCHED_RESET_ON_FORK 0x40000000
40 #endif
41
42 /* flag by sched_getattr() */
43 #if defined(__linux__) && !defined(SCHED_FLAG_RESET_ON_FORK)
44 # define SCHED_FLAG_RESET_ON_FORK 0x01
45 #endif
46
47 #if defined(__linux__) && !defined(SCHED_FLAG_RECLAIM)
48 # define SCHED_FLAG_RECLAIM 0x02
49 #endif
50
51 #if defined(__linux__) && !defined(SCHED_FLAG_DL_OVERRUN)
52 # define SCHED_FLAG_DL_OVERRUN 0x04
53 #endif
54
55 #if defined(__linux__) && !defined(SCHED_FLAG_KEEP_POLICY)
56 # define SCHED_FLAG_KEEP_POLICY 0x08
57 #endif
58
59 #if defined(__linux__) && !defined(SCHED_FLAG_KEEP_PARAMS)
60 # define SCHED_FLAG_KEEP_PARAMS 0x10
61 #endif
62
63 #if defined(__linux__) && !defined(SCHED_FLAG_UTIL_CLAMP_MIN)
64 # define SCHED_FLAG_UTIL_CLAMP_MIN 0x20
65 #endif
66
67 #if defined(__linux__) && !defined(SCHED_FLAG_UTIL_CLAMP_MAX)
68 # define SCHED_FLAG_UTIL_CLAMP_MAX 0x40
69 #endif
70
71 #ifdef HAVE_SYS_SYSCALL_H
72 # include <sys/syscall.h>
73 #endif
74
75 /* usable kernel-headers, but old glibc-headers */
76 #if defined (__linux__) && !defined(SYS_sched_setattr) && defined(__NR_sched_setattr)
77 # define SYS_sched_setattr __NR_sched_setattr
78 #endif
79
80 #if defined (__linux__) && !defined(SYS_sched_getattr) && defined(__NR_sched_getattr)
81 # define SYS_sched_getattr __NR_sched_getattr
82 #endif
83
84 #if defined (__linux__) && !defined(HAVE_SCHED_SETATTR) && defined(SYS_sched_setattr)
85 # define HAVE_SCHED_SETATTR
86
87 struct sched_attr {
88 uint32_t size;
89 uint32_t sched_policy;
90 uint64_t sched_flags;
91
92 /* SCHED_NORMAL, SCHED_BATCH */
93 int32_t sched_nice;
94
95 /* SCHED_FIFO, SCHED_RR */
96 uint32_t sched_priority;
97
98 /* SCHED_DEADLINE (nsec) */
99 uint64_t sched_runtime;
100 uint64_t sched_deadline;
101 uint64_t sched_period;
102
103 /* UTILIZATION CLAMPING */
104 uint32_t sched_util_min;
105 uint32_t sched_util_max;
106 };
107
108 static int sched_setattr(pid_t pid, const struct sched_attr *attr, unsigned int flags)
109 {
110 return syscall(SYS_sched_setattr, pid, attr, flags);
111 }
112
113 static int sched_getattr(pid_t pid, struct sched_attr *attr, unsigned int size, unsigned int flags)
114 {
115 return syscall(SYS_sched_getattr, pid, attr, size, flags);
116 }
117 #endif
118
119 /* the SCHED_DEADLINE is supported since Linux 3.14
120 * commit id aab03e05e8f7e26f51dee792beddcb5cca9215a5
121 * -- sched_setattr() is required for this policy!
122 */
123 #if defined (__linux__) && !defined(SCHED_DEADLINE) && defined(HAVE_SCHED_SETATTR)
124 # define SCHED_DEADLINE 6
125 #endif
126
127 #endif /* UTIL_LINUX_SCHED_ATTR_H */