1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Copyright (c) 2021, BELLSOFT. All rights reserved.
4 */
5
6 #ifndef TST_SCHED_H_
7 #define TST_SCHED_H_
8
9 #include <sched.h>
10
11 #include "lapi/syscalls.h"
12
13 #define TST_LIBC_SCHED_SCALL_(SCALL, ...)({ \
14 int tst_ret = SCALL(__VA_ARGS__); \
15 if (tst_ret == -1 && errno == ENOSYS) { \
16 tst_brk(TCONF, #SCALL " not supported"); \
17 } \
18 tst_ret; \
19 })
20
sys_sched_setparam(pid_t pid,const struct sched_param * param)21 static inline int sys_sched_setparam(pid_t pid, const struct sched_param *param)
22 {
23 return tst_syscall(__NR_sched_setparam, pid, param);
24 }
25
sys_sched_getparam(pid_t pid,struct sched_param * param)26 static inline int sys_sched_getparam(pid_t pid, struct sched_param *param)
27 {
28 return tst_syscall(__NR_sched_getparam, pid, param);
29 }
30
sys_sched_setscheduler(pid_t pid,int policy,const struct sched_param * param)31 static inline int sys_sched_setscheduler(pid_t pid, int policy, const struct sched_param *param)
32 {
33 return tst_syscall(__NR_sched_setscheduler, pid, policy, param);
34 }
35
sys_sched_getscheduler(pid_t pid)36 static inline int sys_sched_getscheduler(pid_t pid)
37 {
38 return tst_syscall(__NR_sched_getscheduler, pid);
39 }
40
libc_sched_setparam(pid_t pid,const struct sched_param * param)41 static inline int libc_sched_setparam(pid_t pid, const struct sched_param *param)
42 {
43 return TST_LIBC_SCHED_SCALL_(sched_setparam, pid, param);
44 }
45
libc_sched_getparam(pid_t pid,struct sched_param * param)46 static inline int libc_sched_getparam(pid_t pid, struct sched_param *param)
47 {
48 return TST_LIBC_SCHED_SCALL_(sched_getparam, pid, param);
49 }
50
libc_sched_setscheduler(pid_t pid,int policy,const struct sched_param * param)51 static inline int libc_sched_setscheduler(pid_t pid, int policy, const struct sched_param *param)
52 {
53 return TST_LIBC_SCHED_SCALL_(sched_setscheduler, pid, policy, param);
54 }
55
libc_sched_getscheduler(pid_t pid)56 static inline int libc_sched_getscheduler(pid_t pid)
57 {
58 return TST_LIBC_SCHED_SCALL_(sched_getscheduler, pid);
59 }
60
61 struct sched_variant {
62 char *desc;
63
64 int (*sched_setparam)(pid_t pid, const struct sched_param *param);
65 int (*sched_getparam)(pid_t pid, struct sched_param *param);
66 int (*sched_setscheduler)(pid_t pid, int policy, const struct sched_param *param);
67 int (*sched_getscheduler)(pid_t pid);
68
69 } sched_variants[] = {
70 { .sched_setparam = libc_sched_setparam,
71 .sched_getparam = libc_sched_getparam,
72 .sched_setscheduler = libc_sched_setscheduler,
73 .sched_getscheduler = libc_sched_getscheduler,
74 .desc = "libc"
75 },
76 { .sched_setparam = sys_sched_setparam,
77 .sched_getparam = sys_sched_getparam,
78 .sched_setscheduler = sys_sched_setscheduler,
79 .sched_getscheduler = sys_sched_getscheduler,
80 .desc = "syscall"
81 },
82 };
83
84 #endif /* TST_SCHED_H_ */
85