]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - schedutils/sched_attr.h
39d8532a358576a81c016b3c4ae3078035c2eadc
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
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.
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.
15 * Copyright (C) 2004 Robert Love
16 * Copyright (C) 2020-2021 Qais Yousef
17 * Copyright (C) 2020-2021 Arm Ltd
19 #ifndef UTIL_LINUX_SCHED_ATTR_H
20 #define UTIL_LINUX_SCHED_ATTR_H
22 /* the SCHED_BATCH is supported since Linux 2.6.16
23 * -- temporary workaround for people with old glibc headers
25 #if defined (__linux__) && !defined(SCHED_BATCH)
26 # define SCHED_BATCH 3
29 /* the SCHED_IDLE is supported since Linux 2.6.23
30 * commit id 0e6aca43e08a62a48d6770e9a159dbec167bf4c6
31 * -- temporary workaround for people with old glibc headers
33 #if defined (__linux__) && !defined(SCHED_IDLE)
37 /* flag by sched_getscheduler() */
38 #if defined(__linux__) && !defined(SCHED_RESET_ON_FORK)
39 # define SCHED_RESET_ON_FORK 0x40000000
42 /* flag by sched_getattr() */
43 #if defined(__linux__) && !defined(SCHED_FLAG_RESET_ON_FORK)
44 # define SCHED_FLAG_RESET_ON_FORK 0x01
47 #if defined(__linux__) && !defined(SCHED_FLAG_RECLAIM)
48 # define SCHED_FLAG_RECLAIM 0x02
51 #if defined(__linux__) && !defined(SCHED_FLAG_DL_OVERRUN)
52 # define SCHED_FLAG_DL_OVERRUN 0x04
55 #if defined(__linux__) && !defined(SCHED_FLAG_KEEP_POLICY)
56 # define SCHED_FLAG_KEEP_POLICY 0x08
59 #if defined(__linux__) && !defined(SCHED_FLAG_KEEP_PARAMS)
60 # define SCHED_FLAG_KEEP_PARAMS 0x10
63 #if defined(__linux__) && !defined(SCHED_FLAG_UTIL_CLAMP_MIN)
64 # define SCHED_FLAG_UTIL_CLAMP_MIN 0x20
67 #if defined(__linux__) && !defined(SCHED_FLAG_UTIL_CLAMP_MAX)
68 # define SCHED_FLAG_UTIL_CLAMP_MAX 0x40
71 #if defined (__linux__)
72 # include <sys/syscall.h>
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
80 #if defined (__linux__) && !defined(SYS_sched_getattr) && defined(__NR_sched_getattr)
81 # define SYS_sched_getattr __NR_sched_getattr
84 #if defined (__linux__) && !defined(HAVE_SCHED_SETATTR) && defined(SYS_sched_setattr)
85 # define HAVE_SCHED_SETATTR
89 uint32_t sched_policy
;
92 /* SCHED_NORMAL, SCHED_BATCH */
95 /* SCHED_FIFO, SCHED_RR */
96 uint32_t sched_priority
;
98 /* SCHED_DEADLINE (nsec) */
99 uint64_t sched_runtime
;
100 uint64_t sched_deadline
;
101 uint64_t sched_period
;
103 /* UTILIZATION CLAMPING */
104 uint32_t sched_util_min
;
105 uint32_t sched_util_max
;
108 static int sched_setattr(pid_t pid
, const struct sched_attr
*attr
, unsigned int flags
)
110 return syscall(SYS_sched_setattr
, pid
, attr
, flags
);
113 static int sched_getattr(pid_t pid
, struct sched_attr
*attr
, unsigned int size
, unsigned int flags
)
115 return syscall(SYS_sched_getattr
, pid
, attr
, size
, flags
);
119 /* the SCHED_DEADLINE is supported since Linux 3.14
120 * commit id aab03e05e8f7e26f51dee792beddcb5cca9215a5
121 * -- sched_setattr() is required for this policy!
123 #if defined (__linux__) && !defined(SCHED_DEADLINE) && defined(HAVE_SCHED_SETATTR)
124 # define SCHED_DEADLINE 6
127 #endif /* UTIL_LINUX_SCHED_ATTR_H */