affinity-inheritance: Overallocate CPU sets

Message ID 20250110180150.125539-1-siddhesh@sourceware.org (mailing list archive)
State Superseded
Headers
Series affinity-inheritance: Overallocate CPU sets |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed

Commit Message

Siddhesh Poyarekar Jan. 10, 2025, 6:01 p.m. UTC
  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>
---
 nptl/tst-skeleton-affinity-inheritance.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Comments

Stefan Liebler Jan. 13, 2025, 1:09 p.m. UTC | #1
On 10.01.25 19:01, Siddhesh Poyarekar wrote:
> 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>
> ---
>  nptl/tst-skeleton-affinity-inheritance.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/nptl/tst-skeleton-affinity-inheritance.c b/nptl/tst-skeleton-affinity-inheritance.c
> index 6de6d9c942..e6b778e5a7 100644
> --- a/nptl/tst-skeleton-affinity-inheritance.c
> +++ b/nptl/tst-skeleton-affinity-inheritance.c
> @@ -129,13 +129,16 @@ 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),
> +      .set = CPU_ALLOC (num_configured_cpus),
> +      .size = CPU_ALLOC_SIZE (num_configured_cpus),
>        .entry = true,
>      };
>  
Hi Siddhesh,

the online vs configured CPUs is the solution as sched_getaffinity
syscall otherwise fails with EINVAL.

But we also have to adjust the other CPU_ALLOCs in the
verify_my_affinity functions. Otherwise the getaffinity functions are
called with size for configured-CPUs but a set only suitable for the
online-CPUs.
With the attached diff on top of your patch, both tests are passing on
my s390x(64bit)/s390(31bit) machines.

Thanks,
Stefan
  
Siddhesh Poyarekar Jan. 14, 2025, 1:38 p.m. UTC | #2
On 2025-01-13 08:09, Stefan Liebler wrote:
> the online vs configured CPUs is the solution as sched_getaffinity
> syscall otherwise fails with EINVAL.
> 
> But we also have to adjust the other CPU_ALLOCs in the
> verify_my_affinity functions. Otherwise the getaffinity functions are
> called with size for configured-CPUs but a set only suitable for the
> online-CPUs.
> With the attached diff on top of your patch, both tests are passing on
> my s390x(64bit)/s390(31bit) machines.

Ahh yes, thank you.  I'll test this on my systems and push if it 
continues to work.

Thanks,
Sid
  

Patch

diff --git a/nptl/tst-skeleton-affinity-inheritance.c b/nptl/tst-skeleton-affinity-inheritance.c
index 6de6d9c942..e6b778e5a7 100644
--- a/nptl/tst-skeleton-affinity-inheritance.c
+++ b/nptl/tst-skeleton-affinity-inheritance.c
@@ -129,13 +129,16 @@  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),
+      .set = CPU_ALLOC (num_configured_cpus),
+      .size = CPU_ALLOC_SIZE (num_configured_cpus),
       .entry = true,
     };