Message ID | 20210806164730.51040-2-aleksei.kodanev@bell-sw.com |
---|---|
State | Accepted |
Headers | show |
Series | syscalls/sched_*: convert to new API and handle ENOSYS errno | expand |
Hi Alexey, On Sat, Aug 7, 2021 at 12:48 AM Alexey Kodanev <aleksei.kodanev@bell-sw.com> wrote: > The new wrappers allow to test libc and syscall variants. This is needed > because libc implementation can differ from calling syscall directly. > For example, musl libc implementation returns ENOSYS for some sched_*() > functions due to commit 1e21e78bf7a5 ("add support for thread scheduling > (POSIX TPS option)"). > > Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com> > --- > include/tst_sched.h | 70 +++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 70 insertions(+) > create mode 100644 include/tst_sched.h > > diff --git a/include/tst_sched.h b/include/tst_sched.h > new file mode 100644 > index 000000000..a5dc767b3 > --- /dev/null > +++ b/include/tst_sched.h > @@ -0,0 +1,70 @@ > +/* SPDX-License-Identifier: GPL-2.0-or-later */ > +/* > + * Copyright (c) 2021, BELLSOFT. All rights reserved. > + */ > + > +#ifndef TST_SCHED_H_ > +#define TST_SCHED_H_ > + > +#include <sched.h> > + > +#include "lapi/syscalls.h" > + > +struct sched_variants { > + char *desc; > + > + int (*sched_setparam)(pid_t pid, const struct sched_param *param); > + int (*sched_getparam)(pid_t pid, struct sched_param *param); > + int (*sched_setscheduler)(pid_t pid, int policy, const struct > sched_param *param); > + int (*sched_getscheduler)(pid_t pid); > +}; > The whole patchset looks tidy and correctly, but I'm thinking maybe we can define the varints[] unified here instead of stating them in each test case again and again? I.e. --- a/include/tst_sched.h +++ b/include/tst_sched.h @@ -10,15 +10,6 @@ #include "lapi/syscalls.h" -struct sched_variants { - char *desc; - - int (*sched_setparam)(pid_t pid, const struct sched_param *param); - int (*sched_getparam)(pid_t pid, struct sched_param *param); - int (*sched_setscheduler)(pid_t pid, int policy, const struct sched_param *param); - int (*sched_getscheduler)(pid_t pid); -}; - #define _TST_LIBC_SCHED_SCALL(SCALL, ...)({ \ int tst_ret = SCALL(__VA_ARGS__); \ if (tst_ret == -1 && errno == ENOSYS) { \ @@ -67,4 +58,24 @@ static inline int libc_sched_getscheduler(pid_t pid) return _TST_LIBC_SCHED_SCALL(sched_getscheduler, pid); } +struct sched_variants { + char *desc; + + int (*sched_setparam)(pid_t pid, const struct sched_param *param); + int (*sched_getparam)(pid_t pid, struct sched_param *param); + int (*sched_setscheduler)(pid_t pid, int policy, const struct sched_param *param); + int (*sched_getscheduler)(pid_t pid); +} variants[] = { + { .sched_setparam = libc_sched_setparam, + .sched_getparam = libc_sched_getparam, + .sched_setscheduler = libc_sched_setscheduler, + .desc = "libc" + }, + { .sched_setparam = sys_sched_setparam, + .sched_getparam = sys_sched_getparam, + .sched_setscheduler = sys_sched_setscheduler, + .desc = "syscall" + }, +}; + #endif /* TST_SCHED_H_ */
Hi!
> +#define _TST_LIBC_SCHED_SCALL(SCALL, ...)({ \
Please do not add any identifiers that start with underscore, these are
reserved for OS implementation e.g. libc and kernel headers.
We usually add the underscore to the end instead, so this will end up as
#define TST_LIBC_SCHED_SCALL_(SCALL, ...) ...
diff --git a/include/tst_sched.h b/include/tst_sched.h new file mode 100644 index 000000000..a5dc767b3 --- /dev/null +++ b/include/tst_sched.h @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2021, BELLSOFT. All rights reserved. + */ + +#ifndef TST_SCHED_H_ +#define TST_SCHED_H_ + +#include <sched.h> + +#include "lapi/syscalls.h" + +struct sched_variants { + char *desc; + + int (*sched_setparam)(pid_t pid, const struct sched_param *param); + int (*sched_getparam)(pid_t pid, struct sched_param *param); + int (*sched_setscheduler)(pid_t pid, int policy, const struct sched_param *param); + int (*sched_getscheduler)(pid_t pid); +}; + +#define _TST_LIBC_SCHED_SCALL(SCALL, ...)({ \ + int tst_ret = SCALL(__VA_ARGS__); \ + if (tst_ret == -1 && errno == ENOSYS) { \ + tst_brk(TCONF, #SCALL " not supported"); \ + } \ + tst_ret; \ +}) + +static inline int sys_sched_setparam(pid_t pid, const struct sched_param *param) +{ + return tst_syscall(__NR_sched_setparam, pid, param); +} + +static inline int sys_sched_getparam(pid_t pid, struct sched_param *param) +{ + return tst_syscall(__NR_sched_getparam, pid, param); +} + +static inline int sys_sched_setscheduler(pid_t pid, int policy, const struct sched_param *param) +{ + return tst_syscall(__NR_sched_setscheduler, pid, policy, param); +} + +static inline int sys_sched_getscheduler(pid_t pid) +{ + return tst_syscall(__NR_sched_getscheduler, pid); +} + +static inline int libc_sched_setparam(pid_t pid, const struct sched_param *param) +{ + return _TST_LIBC_SCHED_SCALL(sched_setparam, pid, param); +} + +static inline int libc_sched_getparam(pid_t pid, struct sched_param *param) +{ + return _TST_LIBC_SCHED_SCALL(sched_getparam, pid, param); +} + +static inline int libc_sched_setscheduler(pid_t pid, int policy, const struct sched_param *param) +{ + return _TST_LIBC_SCHED_SCALL(sched_setscheduler, pid, policy, param); +} + +static inline int libc_sched_getscheduler(pid_t pid) +{ + return _TST_LIBC_SCHED_SCALL(sched_getscheduler, pid); +} + +#endif /* TST_SCHED_H_ */
The new wrappers allow to test libc and syscall variants. This is needed because libc implementation can differ from calling syscall directly. For example, musl libc implementation returns ENOSYS for some sched_*() functions due to commit 1e21e78bf7a5 ("add support for thread scheduling (POSIX TPS option)"). Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com> --- include/tst_sched.h | 70 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 include/tst_sched.h