[PATCH] Linux: Start misc/tst-sched_setattr-thread with SCHED_OTHER
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Tue Nov 10 15:20:35 GMT 2026
On 10/11/26 11:59, Florian Schmaus wrote:
> The test expected its threads to run under SCHED_OTHER, but they actually
> ran under the scheduling policy inherited from the environment. If a build
> host runs its builds and tests under SCHED_BATCH, the test fails with:
>
> tst-sched_setattr-thread.c:36: numeric comparison failure
> left: 3 (0x3); from: attr.sched_policy
> right: 0 (0x0); from: SCHED_OTHER
>
> Fix this by setting the policy and initial nice value with sched_setattr
> instead of nice. This also removes the assumption that the inherited nice
> value is 0. When the policy or the nice value cannot be set without
> privileges, the test is still unsupported.
>
> Signed-off-by: Florian Schmaus <flo@geekplace.eu>
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> .../sysv/linux/tst-sched_setattr-thread.c | 21 +++++++++++++++++--
> 1 file changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/sysdeps/unix/sysv/linux/tst-sched_setattr-thread.c b/sysdeps/unix/sysv/linux/tst-sched_setattr-thread.c
> index 392e735788db..4fe79a413bb9 100644
> --- a/sysdeps/unix/sysv/linux/tst-sched_setattr-thread.c
> +++ b/sysdeps/unix/sysv/linux/tst-sched_setattr-thread.c
> @@ -18,6 +18,7 @@
>
> #include <sched.h>
>
> +#include <errno.h>
> #include <stddef.h>
> #include <stdio.h>
> #include <support/check.h>
> @@ -79,8 +80,24 @@ thread_routine (void *nice_value_ptr)
> static int
> do_test (void)
> {
> - if (nice (initial_nice_value) != initial_nice_value)
> - FAIL_UNSUPPORTED ("cannot set nice value to initial_nice_value: %m");
> + /* Start with SCHED_OTHER and initial_nice_value to avoid the
> + environment's scheduling policy and nice value affecting us
> + as much as possible. */
> + struct sched_attr attr =
> + {
> + .size = sizeof (attr),
> + .sched_policy = SCHED_OTHER,
> + .sched_nice = initial_nice_value,
> + };
> + if (sched_setattr (0, &attr, 0) != 0)
> + {
> + /* Leaving SCHED_IDLE or lowering the nice value needs
> + CAP_SYS_NICE or a sufficient RLIMIT_NICE. */
> + if (errno == EPERM)
> + FAIL_UNSUPPORTED ("cannot set SCHED_OTHER with nice value %d: %m",
> + initial_nice_value);
> + FAIL_EXIT1 ("sched_setattr: %m");
> + }
>
> xpthread_barrier_init (&barrier, NULL, 3);
>
More information about the Libc-alpha
mailing list