[PATCH v2] tst-{pthread|sched}-affinity-inheritance: Only use in-mask CPUs in affinity mask.

Stefan Liebler stli@linux.ibm.com
Wed Feb 4 09:56:20 GMT 2026


On 2/2/26 10:53, Florian Weimer wrote:
> * Stefan Liebler:
> 
>> +  /* Only use CPUs which were in mask 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; cpus > 0; cur++)
>> +    {
>> +      if (CPU_ISSET_S (cur, param->size, param->set_at_startup))
>> +	{
>> +	  CPU_SET_S (cur, param->size, param->set);
>> +	  cpus--;
>> +	}
>> +    }
> 
> Sorry, my advice there was wrong.  This is now an endless loop when
> running something like:
> 
>   taskset -c 5 make t=nptl/tst-pthread-affinity-inheritance test
> 
> Florian
> 
Makes sense, you are right.
But with the "extra check" in the loop-condition (cur <
param->nproc_configured), the test just fails with ...
$ taskset -c 5 make t=nptl/tst-pthread-affinity-inheritance test
error: tst-skeleton-affinity-inheritance.c:74: Failed to add all
requested CPUs to the affinity set
... as it tries to add nproc CPUs to the set.

But we can also get rid of test_param->nproc at all. Instead in
set_cpu_mask(), the number of CPUs will be based on
CPU_COUNT_S(set_at_startup). Then the test works also with taskset'ing
to one CPU. Then the "extra check" is also not needed. I'll send a V3
with this change shortly (if you won't have opposed in between).

Thanks,
Stefan


More information about the Libc-alpha mailing list