[PATCH] tst-{pthread|sched}-affinity-inheritance: Only use online CPUs in affinity mask.
Stefan Liebler
stli@linux.ibm.com
Fri Jan 23 13:58:37 GMT 2026
I've just send a V2:
[PATCH v2] tst-{pthread|sched}-affinity-inheritance: Only use in-mask
CPUs in affinity mask.
https://inbox.sourceware.org/libc-alpha/20260123135642.1328020-1-stli@linux.ibm.com/T/#u
On 1/22/26 18:27, Florian Weimer wrote:
> * Stefan Liebler:
>
>> On s390x, the two tests are failing on a lpar with linux 6.18 booted with nosmt:
>> FAIL: misc/tst-sched-affinity-inheritance
>> FAIL: nptl/tst-pthread-affinity-inheritance
>>
>> Both tests were failing because they are claiming that the CPU affinity mask was
>> not correctly inherited in the forked process/thread.
>> The error already happened before forking, as the mask was set up to use
>> CPUs 0-14 in set_cpu_mask(). But according to e.g. lscpu or the line
>> "Cpus_allowed_list" in /proc/self/status, only the following CPUs were online:
>> 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
>> while 1, 3, 5, ... were configured, but not online.
>>
>> Now the test first gets the current CPU mask at startup in do_test() and
>> set_cpu_mask() only selects those online CPUs.
>
> The “online” part is a bit confusing to me because I associated that
> with /sys/devices/system/cpu/online.
>
> Maybe “in-mask CPUs” is a good short alternative?
I've adjusted the comments in V2.
>
> To be clear, checking the startup mask is the right thing to do. I
> think going to /sys and trying to pick up CPUs from there would be
> confusing.
>
>> diff --git a/nptl/tst-skeleton-affinity-inheritance.c b/nptl/tst-skeleton-affinity-inheritance.c
>> index e1f328ae26..0910727cc3 100644
>> --- a/nptl/tst-skeleton-affinity-inheritance.c
>> +++ b/nptl/tst-skeleton-affinity-inheritance.c
>> @@ -45,6 +45,7 @@ struct test_param
>> int nproc;
>> int nproc_configured;
>> cpu_set_t *set;
>> + cpu_set_t *set_at_startup;
>> size_t size;
>> bool entry;
>> };
>> @@ -58,12 +59,53 @@ set_cpu_mask (struct test_param *param, bool entry)
>> if (entry && cpus > 1)
>> cpus--;
>>
>> + /* Only use CPUs which were online at start of the test process. */
>> CPU_ZERO_S (param->size, param->set);
>> - while (cpus > 0)
>> - CPU_SET_S (--cpus, param->size, param->set);
>> + for (int cur = 0; cur < param->nproc_configured && cpus > 0; cur ++)
>> + {
>> + if (CPU_ISSET_S (cur, param->size, param->set_at_startup))
>> + {
>> + CPU_SET_S (cur, param->size, param->set);
>> + cpus --;
>> + }
>
> Extra spaces: “cur ++“, “cpus --”
Done in V2
>
> And I think the check against param->nproc_configured is not needed for
> this loop.
Done in V2. Also in the loop in verify_my_affinity().
>
>> +static void
>> +verify_my_affinity (int nproc_configured, size_t size,
>> + const cpu_set_t *expected_set)
>> +{
>> + 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");
>
> Missing space: “xor_set==”
Done in V2
>
> Overall it looks okay to me, but I haven't tested it yet.
>
> Thanks,
> Florian
>
Thanks,
Stefan
More information about the Libc-alpha
mailing list