]> gcc.gnu.org Git - gcc.git/commitdiff
openmp: Fix up handling of OMP_PLACES=threads(1)
authorJakub Jelinek <jakub@redhat.com>
Fri, 15 Oct 2021 14:25:25 +0000 (16:25 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 10 May 2022 08:14:28 +0000 (10:14 +0200)
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.

2021-10-15  Jakub Jelinek  <jakub@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.

(cherry picked from commit 4764049dd620affcd3e2658dc7f03a6616370a29)

libgomp/config/linux/affinity.c
libgomp/testsuite/libgomp.c/places-6.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c/places-7.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c/places-8.c [new file with mode: 0644]

index 9d4c483add1e0961a8e2868953096af1afc2b09f..fff84cb88341955b6fd46543b1a4ecb9618bc6c1 100644 (file)
@@ -281,8 +281,13 @@ gomp_affinity_init_level_1 (int level, int this_level, unsigned long count,
                      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 == ',')
diff --git a/libgomp/testsuite/libgomp.c/places-6.c b/libgomp/testsuite/libgomp.c/places-6.c
new file mode 100644 (file)
index 0000000..8310346
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-set-target-env-var OMP_PLACES "threads(1)" } */
+/* { dg-set-target-env-var OMP_DISPLAY_ENV "true" } */
+
+int
+main ()
+{
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/places-7.c b/libgomp/testsuite/libgomp.c/places-7.c
new file mode 100644 (file)
index 0000000..f0a77f4
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-set-target-env-var OMP_PLACES "cores(1)" } */
+/* { dg-set-target-env-var OMP_DISPLAY_ENV "true" } */
+
+int
+main ()
+{
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/places-8.c b/libgomp/testsuite/libgomp.c/places-8.c
new file mode 100644 (file)
index 0000000..31c6983
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-set-target-env-var OMP_PLACES "sockets(1)" } */
+/* { dg-set-target-env-var OMP_DISPLAY_ENV "true" } */
+
+int
+main ()
+{
+  return 0;
+}
This page took 0.062703 seconds and 5 git commands to generate.