Hi!

When writing the places-*.c tests, I've noticed that we mishandle threads
abstract name with specified num-places if num-places isn't a multiple of
number of hw threads in a core.  It then happily ignores the maximum count
and overwrites for the remaining hw threads in a core further places that
haven't been allocated.

Regtested on x86_64-linux and i686-linux, committed to trunk.

2021-10-15  Jakub Jelinek  <ja...@redhat.com>

        * config/linux/affinity.c (gomp_affinity_init_level_1): For level 1
        after creating count places clean up and return immediately.
        * testsuite/libgomp.c/places-6.c: New test.
        * testsuite/libgomp.c/places-7.c: New test.
        * testsuite/libgomp.c/places-8.c: New test.
        * testsuite/libgomp.c/places-9.c: New test.
        * testsuite/libgomp.c/places-10.c: New test.

--- libgomp/config/linux/affinity.c.jj  2021-10-14 22:04:30.595333461 +0200
+++ libgomp/config/linux/affinity.c     2021-10-15 13:20:19.561484351 +0200
@@ -338,8 +338,13 @@ gomp_affinity_init_level_1 (int level, i
                      if (gomp_affinity_add_cpus (pl, first, 1, 0, true))
                        {
                          CPU_CLR_S (first, gomp_cpuset_size, copy);
-                         if (level == 1)
-                           gomp_places_list_len++;
+                         if (level == 1
+                             && ++gomp_places_list_len >= count)
+                           {
+                             fclose (f);
+                             free (line);
+                             return;
+                           }
                        }
                    }
                if (*p == ',')
--- libgomp/testsuite/libgomp.c/places-6.c.jj   2021-10-15 13:28:17.461582786 
+0200
+++ libgomp/testsuite/libgomp.c/places-6.c      2021-10-15 13:28:25.228470619 
+0200
@@ -0,0 +1,10 @@
+/* { dg-set-target-env-var OMP_PLACES "threads(1)" } */
+
+#include <omp.h>
+
+int
+main ()
+{
+  omp_display_env (0);
+  return 0;
+}
--- libgomp/testsuite/libgomp.c/places-7.c.jj   2021-10-15 13:28:17.465582728 
+0200
+++ libgomp/testsuite/libgomp.c/places-7.c      2021-10-15 13:28:30.295397448 
+0200
@@ -0,0 +1,10 @@
+/* { dg-set-target-env-var OMP_PLACES "cores(1)" } */
+
+#include <omp.h>
+
+int
+main ()
+{
+  omp_display_env (0);
+  return 0;
+}
--- libgomp/testsuite/libgomp.c/places-8.c.jj   2021-10-15 13:28:17.469582670 
+0200
+++ libgomp/testsuite/libgomp.c/places-8.c      2021-10-15 13:28:35.181326887 
+0200
@@ -0,0 +1,10 @@
+/* { dg-set-target-env-var OMP_PLACES "sockets(1)" } */
+
+#include <omp.h>
+
+int
+main ()
+{
+  omp_display_env (0);
+  return 0;
+}
--- libgomp/testsuite/libgomp.c/places-9.c.jj   2021-10-15 13:28:17.473582613 
+0200
+++ libgomp/testsuite/libgomp.c/places-9.c      2021-10-15 13:28:39.913258548 
+0200
@@ -0,0 +1,10 @@
+/* { dg-set-target-env-var OMP_PLACES "ll_caches(1)" } */
+
+#include <omp.h>
+
+int
+main ()
+{
+  omp_display_env (0);
+  return 0;
+}
--- libgomp/testsuite/libgomp.c/places-10.c.jj  2021-10-15 13:28:17.477582555 
+0200
+++ libgomp/testsuite/libgomp.c/places-10.c     2021-10-15 13:28:46.433164392 
+0200
@@ -0,0 +1,10 @@
+/* { dg-set-target-env-var OMP_PLACES "numa_domains(1)" } */
+
+#include <omp.h>
+
+int
+main ()
+{
+  omp_display_env (0);
+  return 0;
+}

        Jakub

Reply via email to