diff options
author | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2024-12-16 08:14:09 -0500 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2025-01-09 10:51:38 -0500 |
commit | e41aabcc93edd6c9a6acb15212b2783d8a7ec5a3 (patch) | |
tree | 59c38ffb6d10a0580266a0bf249ea0ad2a0dc4fe /sysdeps/unix/sysv | |
parent | 82688ca3107c93d9eba6440981e473d1877b6281 (diff) | |
download | glibc-e41aabcc93edd6c9a6acb15212b2783d8a7ec5a3.zip glibc-e41aabcc93edd6c9a6acb15212b2783d8a7ec5a3.tar.gz glibc-e41aabcc93edd6c9a6acb15212b2783d8a7ec5a3.tar.bz2 |
tests: Verify inheritance of cpu affinity
Add a couple of tests to verify that CPU affinity set using
sched_setaffinity and pthread_setaffinity_np are inherited by a child
process and child thread.
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sysdeps/unix/sysv')
-rw-r--r-- | sysdeps/unix/sysv/linux/Makefile | 1 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/tst-sched-affinity-inheritance.c | 71 |
2 files changed, 72 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 4e7044f..8a75529 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -226,6 +226,7 @@ tests += \ tst-process_mrelease \ tst-quota \ tst-rlimit-infinity \ + tst-sched-affinity-inheritance \ tst-sched_setattr \ tst-scm_rights \ tst-sigtimedwait \ diff --git a/sysdeps/unix/sysv/linux/tst-sched-affinity-inheritance.c b/sysdeps/unix/sysv/linux/tst-sched-affinity-inheritance.c new file mode 100644 index 0000000..fe0297f --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-sched-affinity-inheritance.c @@ -0,0 +1,71 @@ +/* CPU Affinity inheritance test - sched_{gs}etaffinity. + Copyright The GNU Toolchain Authors. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +/* See top level comment in nptl/tst-skeleton-affinity-inheritance.c for a + description of this test. */ + +#include <sched.h> +#include <string.h> +#include <stdio.h> +#include <support/check.h> + +static void +set_my_affinity (size_t size, const cpu_set_t *set) +{ + int ret = sched_setaffinity (0, size, set); + + if (ret != 0) + FAIL ("sched_setaffinity returned %d (%s)", ret, strerror (ret)); +} + +static void +verify_my_affinity (int nproc, size_t size, const cpu_set_t *expected_set) +{ + cpu_set_t *set = CPU_ALLOC (nproc); + cpu_set_t *xor_set = CPU_ALLOC (nproc); + + if (set == NULL || xor_set== NULL) + FAIL_EXIT1 ("verify_my_affinity: Failed to allocate cpuset: %m\n"); + + int ret = sched_getaffinity (0, size, set); + if (ret != 0) + FAIL ("sched_getaffinity returned %d (%s)", ret, strerror (ret)); + + CPU_XOR_S (size, xor_set, expected_set, set); + + int cpucount = CPU_COUNT_S (size, xor_set); + + if (cpucount > 0) + { + FAIL ("Affinity mask not inherited, " + "following %d CPUs mismatched in the expected and actual sets:\n", + cpucount); + for (int cur = 0; cur < nproc && cpucount >= 0; cur++) + if (CPU_ISSET_S (size, cur, xor_set)) + { + printf ("%d ", cur); + cpucount--; + } + printf ("\n"); + } + + CPU_FREE (set); + CPU_FREE (xor_set); +} + +#include <nptl/tst-skeleton-affinity-inheritance.c> |