Add test for inheritance of thread affinity mask (RHEL-61559)

Resolves: RHEL-61559
This commit is contained in:
Florian Weimer 2025-01-21 10:11:44 +01:00
parent df60b451a2
commit a61c995534
5 changed files with 878 additions and 1 deletions

394
glibc-RHEL-61559-1.patch Normal file
View File

@ -0,0 +1,394 @@
commit b600f47758332d78f04daa970b02a4044a37ebd9
Author: Carlos O'Donell <carlos@redhat.com>
Date: Wed May 17 08:27:59 2023 -0400
nptl: Reformat Makefile.
Reflow all long lines adding comment terminators.
Rename files that cause inconsistent ordering.
Sort all reflowed text using scripts/sort-makefile-lines.py.
No code generation changes observed in binary artifacts.
No regressions on x86_64 and i686.
Conflicts:
nptl/Makefile
(different list of tests)
diff --git a/nptl/Makefile b/nptl/Makefile
index f89bb07747cf5522..eec8563f95a42554 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -202,6 +202,7 @@ routines = \
tpp \
unwind \
vars \
+ # routines
static-only-routines = pthread_atfork
libpthread-routines = libpthread-compat
@@ -265,70 +266,133 @@ LDLIBS-tst-thread-exit-clobber = -lstdc++
CFLAGS-tst-minstack-throw.o = -std=gnu++11
LDLIBS-tst-minstack-throw = -lstdc++
-tests = tst-attr2 tst-attr3 tst-default-attr \
- tst-mutex5a tst-mutex7a \
- tst-mutexpi1 tst-mutexpi2 tst-mutexpi3 tst-mutexpi4 \
- tst-mutexpi5 tst-mutexpi5a tst-mutexpi6 tst-mutexpi7 tst-mutexpi7a \
- tst-mutexpi9 tst-mutexpi10 \
- tst-cond22 tst-cond26 \
- tst-robustpi1 tst-robustpi2 tst-robustpi3 tst-robustpi4 tst-robustpi5 \
- tst-robustpi6 tst-robustpi7 tst-robustpi9 \
- tst-rwlock2 tst-rwlock2a tst-rwlock2b tst-rwlock3 \
- tst-rwlock6 tst-rwlock7 tst-rwlock8 \
- tst-rwlock9 tst-rwlock10 tst-rwlock11 \
- tst-rwlock15 tst-rwlock17 tst-rwlock18 \
- tst-once5 \
- tst-sem17 \
- tst-tsd3 tst-tsd4 \
- tst-cancel4_1 tst-cancel4_2 \
- tst-cancel7 tst-cancel17 tst-cancel24 \
- tst-signal3 \
- tst-exec4 tst-exec5 \
- tst-stack2 tst-stack3 tst-stack4 \
- tst-pthread-attr-affinity \
- tst-pthread-attr-affinity-fail \
- tst-dlsym1 \
- tst-context1 \
- tst-sched1 \
- tst-initializers1 $(addprefix tst-initializers1-,\
- c89 gnu89 c99 gnu99 c11 gnu11) \
- tst-thread_local1 \
- tst-robust-fork \
- tst-thread-exit-clobber tst-minstack-cancel tst-minstack-exit \
- tst-minstack-throw \
- tst-rwlock-pwn \
- tst-thread-affinity-pthread \
- tst-thread-affinity-pthread2 \
- tst-thread-affinity-sched \
- tst-pthread-defaultattr-free \
- tst-pthread-attr-sigmask \
- tst-pthread-timedlock-lockloop \
- tst-pthread-gdb-attach tst-pthread-gdb-attach-static \
- tst-pthread_exit-nothreads \
- tst-pthread_exit-nothreads-static \
- tst-thread-setspecific \
+tests = \
+ tst-attr2 \
+ tst-attr3 \
+ tst-cancel4_1 \
+ tst-cancel4_2 \
+ tst-cancel7 \
+ tst-cancel17 \
+ tst-cancel24 \
+ tst-cond22 \
+ tst-cond26 \
+ tst-context1 \
+ tst-default-attr \
+ tst-dlsym1 \
+ tst-exec4 \
+ tst-exec5 \
+ tst-initializers1 \
+ tst-initializers1-c11 \
+ tst-initializers1-c89 \
+ tst-initializers1-c99 \
+ tst-initializers1-gnu11 \
+ tst-initializers1-gnu89 \
+ tst-initializers1-gnu99 \
+ tst-minstack-cancel \
+ tst-minstack-exit \
+ tst-minstack-throw \
+ tst-mutex5a \
+ tst-mutex7a \
+ tst-mutexpi1 \
+ tst-mutexpi2 \
+ tst-mutexpi3 \
+ tst-mutexpi4 \
+ tst-mutexpi5 \
+ tst-mutexpi6 \
+ tst-mutexpi7 \
+ tst-mutexpi9 \
+ tst-mutexpi10 \
+ tst-mutexpi11 \
+ tst-mutexpi12 \
+ tst-once5 \
+ tst-pthread-attr-affinity \
+ tst-pthread-attr-affinity-fail \
+ tst-pthread-attr-sigmask \
+ tst-pthread-defaultattr-free \
+ tst-pthread-gdb-attach \
+ tst-pthread-gdb-attach-static \
tst-pthread-getcpuclockid-invalid \
+ tst-pthread-timedlock-lockloop \
+ tst-pthread_exit-nothreads \
+ tst-pthread_exit-nothreads-static \
+ tst-robust-fork \
+ tst-robustpi1 \
+ tst-robustpi2 \
+ tst-robustpi3 \
+ tst-robustpi4 \
+ tst-robustpi5 \
+ tst-robustpi6 \
+ tst-robustpi7 \
+ tst-robustpi9 \
+ tst-rwlock-pwn \
+ tst-rwlock2 \
+ tst-rwlock3 \
+ tst-rwlock6 \
+ tst-rwlock7 \
+ tst-rwlock8 \
+ tst-rwlock9 \
+ tst-rwlock10 \
+ tst-rwlock11 \
+ tst-rwlock15 \
+ tst-rwlock17 \
+ tst-rwlock18 \
+ tst-rwlock21 \
+ tst-rwlock22 \
+ tst-sched1 \
+ tst-sem17 \
+ tst-signal3 \
+ tst-stack2 \
+ tst-stack3 \
+ tst-stack4 \
+ tst-thread-affinity-pthread \
+ tst-thread-affinity-pthread2 \
+ tst-thread-affinity-sched \
+ tst-thread-exit-clobber \
+ tst-thread-setspecific \
+ tst-thread_local1 \
+ tst-tsd3 \
+ tst-tsd4 \
+ # tests
tests-nolibpthread = \
tst-pthread_exit-nothreads \
tst-pthread_exit-nothreads-static \
+ # tests-nolibpthread
tests-container = tst-pthread-getattr
-tests-internal := tst-robustpi8 tst-rwlock19 tst-rwlock20 \
- tst-sem11 tst-sem12 tst-sem13 \
- tst-barrier5 tst-signal7 tst-mutex8 tst-mutex8-static \
- tst-mutexpi8 tst-mutexpi8-static \
- tst-setgetname \
- tst-nptl-padding \
- # tests-internal
-
-xtests = tst-setuid1 tst-setuid1-static tst-setuid2 \
- tst-mutexpp1 tst-mutexpp6 tst-mutexpp10 tst-setgroups \
- tst-mutexpp5 tst-mutexpp9
+tests-internal := \
+ tst-barrier5 \
+ tst-mutex8 \
+ tst-mutex8-static \
+ tst-mutexpi8 \
+ tst-mutexpi8-static \
+ tst-nptl-padding \
+ tst-robustpi8 \
+ tst-rwlock19 \
+ tst-rwlock20 \
+ tst-sem11 \
+ tst-sem12 \
+ tst-sem13 \
+ tst-setgetname \
+ tst-signal7 \
+ # tests-internal
+
+xtests = \
+ tst-mutexpp1 \
+ tst-mutexpp5 \
+ tst-mutexpp6 \
+ tst-mutexpp9 \
+ tst-mutexpp10 \
+ tst-setgroups \
+ tst-setuid1 \
+ tst-setuid1-static \
+ tst-setuid2 \
+ # xtests
tests-time64 := \
tst-cancel4_2-time64
+ # tests-time64
# This test can run into task limits because of a linux kernel bug
# and then cause the make process to fail too, see bug 24537.
@@ -341,9 +405,14 @@ gen-as-const-headers = unwindbuf.sym \
gen-py-const-headers := nptl_lock_constants.pysym
pretty-printers := nptl-printers.py
-tests-printers := test-mutexattr-printers test-mutex-printers \
- test-condattr-printers test-cond-printers \
- test-rwlockattr-printers test-rwlock-printers
+tests-printers := \
+ test-cond-printers \
+ test-condattr-printers \
+ test-mutex-printers \
+ test-mutexattr-printers \
+ test-rwlock-printers \
+ test-rwlockattr-printers \
+ # tests-printers
# We must specify both CFLAGS and CPPFLAGS to override any
# compiler options the user might have provided that conflict
@@ -378,25 +447,51 @@ CPPFLAGS-tst-pthread-gdb-attach-static.c := \
# were launched with an explicit ld.so invocation.
tst-pthread-gdb-attach-no-pie = yes
-tests += tst-cancelx7 tst-cancelx17
+tests += \
+ tst-cancelx7 \
+ tst-cancelx17 \
+ # tests
ifeq ($(build-shared),yes)
-tests += tst-compat-forwarder tst-audit-threads
-tests-internal += tst-tls3 tst-tls3-malloc tst-tls5 tst-stackguard1
+tests += \
+ tst-audit-threads \
+ tst-compat-forwarder \
+ # tests
+tests-internal += \
+ tst-stackguard1 \
+ tst-tls3 \
+ tst-tls3-malloc \
+ tst-tls5 \
+ # tests-internal
ifeq ($(have-z-execstack),yes)
tests += tst-execstack
endif
endif
-modules-names = tst-tls3mod \
- tst-tls5mod tst-tls5moda tst-tls5modb tst-tls5modc \
- tst-tls5modd tst-tls5mode tst-tls5modf tst-stack4mod \
- tst-execstack-mod \
- tst-compat-forwarder-mod tst-audit-threads-mod1 \
- tst-audit-threads-mod2
-extra-test-objs += $(addsuffix .os,$(strip $(modules-names))) \
- tst-cleanup4aux.o tst-cleanupx4aux.o
-test-extras += tst-cleanup4aux tst-cleanupx4aux
+modules-names = \
+ tst-audit-threads-mod1 \
+ tst-audit-threads-mod2 \
+ tst-compat-forwarder-mod \
+ tst-execstack-mod \
+ tst-stack4mod \
+ tst-tls3mod \
+ tst-tls5mod \
+ tst-tls5moda \
+ tst-tls5modb \
+ tst-tls5modc \
+ tst-tls5modd \
+ tst-tls5mode \
+ tst-tls5modf \
+ # modules-names
+extra-test-objs += \
+ $(addsuffix .os,$(strip $(modules-names))) \
+ tst-cleanup4aux.o \
+ tst-cleanupx4aux.o \
+ # extra-test-objs
+test-extras += \
+ tst-cleanup4aux \
+ tst-cleanupx4aux \
+ # test-extras
# This test exercises compat symbols removed in glibc 2.34.
ifdef have-GLIBC_2.33
@@ -434,20 +529,31 @@ CFLAGS-funlockfile.c += $(libio-mtsafe)
link-libc-static := $(common-objpfx)libc.a $(static-gnulib) \
$(common-objpfx)libc.a
-tests-static += tst-stackguard1-static \
- tst-cancel24-static \
- tst-mutex8-static tst-mutexpi8-static tst-sem11-static \
- tst-sem12-static tst-cond11-static \
- tst-pthread-gdb-attach-static \
- tst-pthread_exit-nothreads-static
+tests-static += \
+ tst-cancel24-static \
+ tst-mutex8-static \
+ tst-mutexpi8-static \
+ tst-pthread-gdb-attach-static \
+ tst-pthread_exit-nothreads-static \
+ tst-sem11-static \
+ tst-sem12-static tst-cond11-static \
+ tst-stackguard1-static \
+ # tests-static
tests += tst-cancel24-static
-tests-internal += tst-sem11-static tst-sem12-static tst-stackguard1-static
+tests-internal += \
+ tst-sem11-static \
+ tst-sem12-static \
+ tst-stackguard1-static \
+ # tests-internal
xtests-static += tst-setuid1-static
ifeq ($(run-built-tests),yes)
-tests-special += $(objpfx)tst-stack3-mem.out $(objpfx)tst-oddstacklimit.out
+tests-special += \
+ $(objpfx)tst-oddstacklimit.out \
+ $(objpfx)tst-stack3-mem.out \
+ # tests-special
ifeq ($(build-shared),yes)
tests-special += $(objpfx)tst-tls6.out
endif
@@ -455,8 +561,13 @@ endif
ifeq (,$(CXX))
# These tests require a C++ compiler and runtime.
-tests-unsupported += tst-cancel24 tst-cancel24-static tst-once5 \
- tst-thread-exit-clobber tst-minstack-throw
+tests-unsupported += \
+ tst-cancel24 \
+ tst-cancel24-static \
+ tst-minstack-throw \
+ tst-once5 \
+ tst-thread-exit-clobber \
+ # tests-unsupported
endif
# These tests require a C++ compiler and runtime with thread_local support.
ifneq ($(have-cxx-thread_local),yes)
@@ -502,7 +613,10 @@ tst-stack3-ENV = MALLOC_TRACE=$(objpfx)tst-stack3.mtrace \
$(objpfx)tst-stack3-mem.out: $(objpfx)tst-stack3.out
$(common-objpfx)malloc/mtrace $(objpfx)tst-stack3.mtrace > $@; \
$(evaluate-test)
-generated += tst-stack3-mem.out tst-stack3.mtrace
+generated += \
+ tst-stack3-mem.out \
+ tst-stack3.mtrace \
+ # generated
tst-stack4mod.sos=$(shell for i in 0 1 2 3 4 5 6 7 8 9 10 \
11 12 13 14 15 16 17 18 19; do \
@@ -544,7 +658,10 @@ LDLIBS-tst-cancel24-static = $(LDLIBS-tst-cancel24)
ifeq ($(build-shared),yes)
-generated += multidir.mk tst-tls6.out
+generated += \
+ multidir.mk \
+ tst-tls6.out \
+ # generated
endif
tst-exec4-ARGS = $(host-test-program-cmd)
diff --git a/nptl/tst-mutexpi5a.c b/nptl/tst-mutexpi11.c
similarity index 100%
rename from nptl/tst-mutexpi5a.c
rename to nptl/tst-mutexpi11.c
diff --git a/nptl/tst-mutexpi7a.c b/nptl/tst-mutexpi12.c
similarity index 100%
rename from nptl/tst-mutexpi7a.c
rename to nptl/tst-mutexpi12.c
diff --git a/nptl/tst-rwlock2a.c b/nptl/tst-rwlock21.c
similarity index 100%
rename from nptl/tst-rwlock2a.c
rename to nptl/tst-rwlock21.c
diff --git a/nptl/tst-rwlock2b.c b/nptl/tst-rwlock22.c
similarity index 100%
rename from nptl/tst-rwlock2b.c
rename to nptl/tst-rwlock22.c

353
glibc-RHEL-61559-2.patch Normal file
View File

@ -0,0 +1,353 @@
commit e41aabcc93edd6c9a6acb15212b2783d8a7ec5a3
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
Date: Mon Dec 16 08:14:09 2024 -0500
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>
Conflicts:
sysdeps/unix/sysv/linux/Makefile
(test list has not been reformatted downstream)
diff --git a/nptl/Makefile b/nptl/Makefile
index eec8563f95a42554..455703bbd763d516 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -305,6 +305,7 @@ tests = \
tst-mutexpi11 \
tst-mutexpi12 \
tst-once5 \
+ tst-pthread-affinity-inheritance \
tst-pthread-attr-affinity \
tst-pthread-attr-affinity-fail \
tst-pthread-attr-sigmask \
diff --git a/nptl/tst-pthread-affinity-inheritance.c b/nptl/tst-pthread-affinity-inheritance.c
new file mode 100644
index 0000000000000000..c020530dd916dea1
--- /dev/null
+++ b/nptl/tst-pthread-affinity-inheritance.c
@@ -0,0 +1,71 @@
+/* CPU Affinity inheritance test - pthread_{gs}etaffinity_np.
+ 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 <pthread.h>
+#include <sched.h>
+#include <stdio.h>
+#include <string.h>
+#include <support/check.h>
+
+static void
+set_my_affinity (size_t size, const cpu_set_t *set)
+{
+ int ret = pthread_setaffinity_np (pthread_self (), size, set);
+
+ if (ret != 0)
+ FAIL ("pthread_setaffinity_np 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 = pthread_getaffinity_np (pthread_self (), size, set);
+ if (ret != 0)
+ FAIL ("pthread_getaffinity_np 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: ",
+ 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 "tst-skeleton-affinity-inheritance.c"
diff --git a/nptl/tst-skeleton-affinity-inheritance.c b/nptl/tst-skeleton-affinity-inheritance.c
new file mode 100644
index 0000000000000000..6de6d9c9428a0c9d
--- /dev/null
+++ b/nptl/tst-skeleton-affinity-inheritance.c
@@ -0,0 +1,152 @@
+/* CPU Affinity inheritance test - common infrastructure.
+ 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/>. */
+
+/* The general idea of this test is to verify that the set of CPUs assigned to
+ a task gets inherited by a child (thread or process) of that task. This is
+ a framework that is included by specific APIs for the test, e.g.
+ sched_getaffinity/sched_setaffinity and
+ pthread_setaffinity_np/pthread_getaffinity_np. This is a framework, actual
+ tests entry points are in nptl/tst-pthread-affinity-inheritance.c and
+ sysdeps/unix/sysv/linux/tst-sched-affinity-inheritance.c.
+
+ There are two levels to the test with two different CPU masks. The first
+ level verifies that the affinity set on the main process is inherited by its
+ children subprocess or thread. The second level verifies that a subprocess
+ or subthread passes on its affinity to their respective subprocess or
+ subthread. We set a slightly different mask in both levels to ensure that
+ they're both inherited. */
+
+#include <errno.h>
+#include <stdio.h>
+#include <support/test-driver.h>
+#include <support/xthread.h>
+#include <support/xunistd.h>
+#include <sys/sysinfo.h>
+#include <sys/wait.h>
+
+struct test_param
+{
+ int nproc;
+ cpu_set_t *set;
+ size_t size;
+ bool entry;
+};
+
+void __attribute__((noinline))
+set_cpu_mask (struct test_param *param, bool entry)
+{
+ int cpus = param->nproc;
+
+ /* Less CPUS for the first level, if that's possible. */
+ if (entry && cpus > 1)
+ cpus--;
+
+ CPU_ZERO_S (param->size, param->set);
+ while (cpus > 0)
+ CPU_SET_S (--cpus, param->size, param->set);
+
+ if (CPU_COUNT_S (param->size, param->set) == 0)
+ FAIL_EXIT1 ("Failed to add any CPUs to the affinity set\n");
+}
+
+static void *
+child_test (void *arg)
+{
+ struct test_param *param = arg;
+
+ printf ("%d:%d child\n", getpid (), gettid ());
+ verify_my_affinity (param->nproc, param->size, param->set);
+ return NULL;
+}
+
+void *
+do_one_test (void *arg)
+{
+ void *(*child) (void *) = NULL;
+ struct test_param *param = arg;
+ bool entry = param->entry;
+
+ if (entry)
+ {
+ printf ("%d:%d Start test run\n", getpid (), gettid ());
+ /* First level: Reenter as a subprocess and then as a subthread. */
+ child = do_one_test;
+ set_cpu_mask (param, true);
+ set_my_affinity (param->size, param->set);
+ param->entry = false;
+ }
+ else
+ {
+ /* Verification for the first level. */
+ verify_my_affinity (param->nproc, param->size, param->set);
+
+ /* Launch the second level test, launching CHILD_TEST as a subprocess and
+ then as a subthread. Use a different mask to see if it gets
+ inherited. */
+ child = child_test;
+ set_cpu_mask (param, false);
+ set_my_affinity (param->size, param->set);
+ }
+
+ /* Verify that a child of a thread/process inherits the affinity mask. */
+ printf ("%d:%d%sdo_one_test: fork\n", getpid (), gettid (),
+ entry ? " " : " ");
+ int pid = xfork ();
+
+ if (pid == 0)
+ {
+ child (param);
+ return NULL;
+ }
+
+ xwaitpid (pid, NULL, 0);
+
+ /* Verify that a subthread of a thread/process inherits the affinity
+ mask. */
+ printf ("%d:%d%sdo_one_test: thread\n", getpid (), gettid (),
+ entry ? " " : " ");
+ pthread_t t = xpthread_create (NULL, child, param);
+ xpthread_join (t);
+
+ return NULL;
+}
+
+static int
+do_test (void)
+{
+ int num_cpus = get_nprocs ();
+
+ struct test_param param =
+ {
+ .nproc = num_cpus,
+ .set = CPU_ALLOC (num_cpus),
+ .size = CPU_ALLOC_SIZE (num_cpus),
+ .entry = true,
+ };
+
+ if (param.set == NULL)
+ FAIL_EXIT1 ("error: CPU_ALLOC (%d) failed\n", num_cpus);
+
+ do_one_test (&param);
+
+ CPU_FREE (param.set);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 8632bfe6eac31ff2..08b4e7765c07f6a3 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -127,6 +127,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
tst-getauxval \
tst-fdopendir-o_path \
tst-linux-mremap1 \
+ tst-sched-affinity-inheritance \
# tests
# Test for the symbol version of fcntl that was replaced in glibc 2.28.
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 0000000000000000..fe0297f743d55e2f
--- /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>

103
glibc-RHEL-61559-3.patch Normal file
View File

@ -0,0 +1,103 @@
commit 09ea1afec75ed0d41cb0da27a9df1b8c3dd56ddc
Author: Stefan Liebler <stli@linux.ibm.com>
Date: Fri Jan 10 12:55:50 2025 -0500
affinity-inheritance: Overallocate CPU sets
Some kernels on S390 appear to return a CPU affinity mask based on
configured processors rather than the ones online. Overallocate the CPU
set to match that, but operate only on the ones online.
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Co-authored-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
diff --git a/nptl/tst-pthread-affinity-inheritance.c b/nptl/tst-pthread-affinity-inheritance.c
index c020530dd916dea1..153fc904dfe14c9d 100644
--- a/nptl/tst-pthread-affinity-inheritance.c
+++ b/nptl/tst-pthread-affinity-inheritance.c
@@ -34,10 +34,11 @@ set_my_affinity (size_t size, const cpu_set_t *set)
}
static void
-verify_my_affinity (int nproc, size_t size, const cpu_set_t *expected_set)
+verify_my_affinity (int nproc, int nproc_configured, size_t size,
+ const cpu_set_t *expected_set)
{
- cpu_set_t *set = CPU_ALLOC (nproc);
- cpu_set_t *xor_set = CPU_ALLOC (nproc);
+ cpu_set_t *set = CPU_ALLOC (nproc_configured);
+ cpu_set_t *xor_set = CPU_ALLOC (nproc_configured);
if (set == NULL || xor_set== NULL)
FAIL_EXIT1 ("verify_my_affinity: Failed to allocate cpuset: %m\n");
diff --git a/nptl/tst-skeleton-affinity-inheritance.c b/nptl/tst-skeleton-affinity-inheritance.c
index 6de6d9c9428a0c9d..926f49622990e9e4 100644
--- a/nptl/tst-skeleton-affinity-inheritance.c
+++ b/nptl/tst-skeleton-affinity-inheritance.c
@@ -42,6 +42,7 @@
struct test_param
{
int nproc;
+ int nproc_configured;
cpu_set_t *set;
size_t size;
bool entry;
@@ -70,7 +71,8 @@ child_test (void *arg)
struct test_param *param = arg;
printf ("%d:%d child\n", getpid (), gettid ());
- verify_my_affinity (param->nproc, param->size, param->set);
+ verify_my_affinity (param->nproc, param->nproc_configured, param->size,
+ param->set);
return NULL;
}
@@ -93,7 +95,8 @@ do_one_test (void *arg)
else
{
/* Verification for the first level. */
- verify_my_affinity (param->nproc, param->size, param->set);
+ verify_my_affinity (param->nproc, param->nproc_configured, param->size,
+ param->set);
/* Launch the second level test, launching CHILD_TEST as a subprocess and
then as a subthread. Use a different mask to see if it gets
@@ -129,13 +132,17 @@ do_one_test (void *arg)
static int
do_test (void)
{
+ /* Large enough in case the kernel decides to return the larger mask. This
+ seems to happen on some kernels for S390x. */
+ int num_configured_cpus = get_nprocs_conf ();
int num_cpus = get_nprocs ();
struct test_param param =
{
.nproc = num_cpus,
- .set = CPU_ALLOC (num_cpus),
- .size = CPU_ALLOC_SIZE (num_cpus),
+ .nproc_configured = num_configured_cpus,
+ .set = CPU_ALLOC (num_configured_cpus),
+ .size = CPU_ALLOC_SIZE (num_configured_cpus),
.entry = true,
};
diff --git a/sysdeps/unix/sysv/linux/tst-sched-affinity-inheritance.c b/sysdeps/unix/sysv/linux/tst-sched-affinity-inheritance.c
index fe0297f743d55e2f..8a42d275fce35e84 100644
--- a/sysdeps/unix/sysv/linux/tst-sched-affinity-inheritance.c
+++ b/sysdeps/unix/sysv/linux/tst-sched-affinity-inheritance.c
@@ -34,10 +34,11 @@ set_my_affinity (size_t size, const cpu_set_t *set)
}
static void
-verify_my_affinity (int nproc, size_t size, const cpu_set_t *expected_set)
+verify_my_affinity (int nproc, int nproc_configured, size_t size,
+ const cpu_set_t *expected_set)
{
- cpu_set_t *set = CPU_ALLOC (nproc);
- cpu_set_t *xor_set = CPU_ALLOC (nproc);
+ cpu_set_t *set = CPU_ALLOC (nproc_configured);
+ cpu_set_t *xor_set = CPU_ALLOC (nproc_configured);
if (set == NULL || xor_set== NULL)
FAIL_EXIT1 ("verify_my_affinity: Failed to allocate cpuset: %m\n");

20
glibc-RHEL-61559-4.patch Normal file
View File

@ -0,0 +1,20 @@
commit 71b49e299dbe22853095119da5064303e1d6b9ff
Author: Florian Weimer <fweimer@redhat.com>
Date: Tue Jan 21 10:36:58 2025 +0100
nptl: Include <stdbool.h> in tst-skeleton-affinity-inheritance.c
The file uses the identifiers bool, false, true.
diff --git a/nptl/tst-skeleton-affinity-inheritance.c b/nptl/tst-skeleton-affinity-inheritance.c
index 926f49622990e9e4..e1f328ae265b2bfb 100644
--- a/nptl/tst-skeleton-affinity-inheritance.c
+++ b/nptl/tst-skeleton-affinity-inheritance.c
@@ -32,6 +32,7 @@
they're both inherited. */
#include <errno.h>
+#include <stdbool.h>
#include <stdio.h>
#include <support/test-driver.h>
#include <support/xthread.h>

View File

@ -157,7 +157,7 @@ end \
Summary: The GNU libc libraries
Name: glibc
Version: %{glibcversion}
Release: 153%{?dist}
Release: 154%{?dist}
# In general, GPLv2+ is used by programs, LGPLv2+ is used for
# libraries.
@ -1076,6 +1076,10 @@ Patch768: glibc-RHEL-69633-1.patch
Patch769: glibc-RHEL-69633-2.patch
Patch770: glibc-RHEL-58987-1.patch
Patch771: glibc-RHEL-58987-2.patch
Patch772: glibc-RHEL-61559-1.patch
Patch773: glibc-RHEL-61559-2.patch
Patch774: glibc-RHEL-61559-3.patch
Patch775: glibc-RHEL-61559-4.patch
##############################################################################
# Continued list of core "glibc" package information:
@ -3069,6 +3073,9 @@ update_gconv_modules_cache ()
%endif
%changelog
* Tue Jan 21 2025 Florian Weimer <fweimer@redhat.com> - 2.34-154
- Add test for inheritance of thread affinity mask (RHEL-61559)
* Mon Jan 20 2025 Florian Weimer <fweimer@redhat.com> - 2.34-153
- Additional dynamic linker dependency sorting tests (RHEL-58987)