]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libgomp: autodetect page sizes in pinned memory tests
authorAndrew Stubbs <ams@codesourcery.com>
Wed, 13 Apr 2022 09:10:10 +0000 (10:10 +0100)
committerAndrew Stubbs <ams@codesourcery.com>
Wed, 13 Apr 2022 13:16:52 +0000 (14:16 +0100)
There's not one number that works everywhere.
This also fixes the failure mode on non-Linux hosts.

libgomp/ChangeLog:

* testsuite/libgomp.c/alloc-pinned-1.c: Autodetect page size.
* testsuite/libgomp.c/alloc-pinned-2.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-3.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-4.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-5.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-6.c: Likewise.
* testsuite/libgomp.c/alloc-pinned-7.c: Clean up.

libgomp/ChangeLog.omp
libgomp/testsuite/libgomp.c/alloc-pinned-1.c
libgomp/testsuite/libgomp.c/alloc-pinned-2.c
libgomp/testsuite/libgomp.c/alloc-pinned-3.c
libgomp/testsuite/libgomp.c/alloc-pinned-4.c
libgomp/testsuite/libgomp.c/alloc-pinned-5.c
libgomp/testsuite/libgomp.c/alloc-pinned-6.c
libgomp/testsuite/libgomp.c/alloc-pinned-7.c

index b89a393b1faf0e110fa840505fa4b39c08a6ad9c..ce3d9e5c536786924b2e40b96633fd081b2da213 100644 (file)
@@ -1,3 +1,13 @@
+2022-04-13  Andrew Stubbs  <ams@codesourcery.com>
+
+       * testsuite/libgomp.c/alloc-pinned-1.c: Autodetect page size.
+       * testsuite/libgomp.c/alloc-pinned-2.c: Likewise.
+       * testsuite/libgomp.c/alloc-pinned-3.c: Likewise.
+       * testsuite/libgomp.c/alloc-pinned-4.c: Likewise.
+       * testsuite/libgomp.c/alloc-pinned-5.c: Likewise.
+       * testsuite/libgomp.c/alloc-pinned-6.c: Likewise.
+       * testsuite/libgomp.c/alloc-pinned-7.c: Clean up.
+
 2022-04-02  Andrew Stubbs  <ams@codesourcery.com>
 
        * testsuite/libgomp.c/usm-6.c: Add omp_target_alloc.
index 0a6360cda29a48649347d43bad2ea9eb353ff994..79792b16d838867487ab8699323fcb86c1f2f614 100644 (file)
@@ -4,13 +4,23 @@
 
 /* Test that pinned memory works.  */
 
+#include <stdio.h>
+#include <stdlib.h>
+
 #ifdef __linux__
 #include <sys/types.h>
 #include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
 
 #include <sys/mman.h>
+#include <sys/resource.h>
+
+#define PAGE_SIZE sysconf(_SC_PAGESIZE)
+#define CHECK_SIZE(SIZE) { \
+  struct rlimit limit; \
+  if (getrlimit (RLIMIT_MEMLOCK, &limit) \
+      || limit.rlim_cur <= SIZE) \
+    fprintf (stderr, "unsufficient lockable memory; please increase ulimit\n"); \
+  }
 
 int
 get_pinned_mem ()
@@ -34,6 +44,9 @@ get_pinned_mem ()
   abort ();
 }
 #else
+#define PAGE_SIZE 1 /* unknown */
+#define CHECK_SIZE(SIZE) fprintf (stderr, "OS unsupported\n");
+
 int
 get_pinned_mem ()
 {
@@ -43,12 +56,13 @@ get_pinned_mem ()
 
 #include <omp.h>
 
-/* Allocate more than a page each time, but stay within the ulimit.  */
-#define SIZE 10*1024
-
 int
 main ()
 {
+  /* Allocate at least a page each time, but stay within the ulimit.  */
+  const int SIZE = PAGE_SIZE;
+  CHECK_SIZE (SIZE*3);
+
   const omp_alloctrait_t traits[] = {
       { omp_atk_pinned, 1 }
   };
index 8fdb4ff5cfd0af5daf69647d4c5fd9f4f406e25e..228c656b715468b69e54dfd1cf07933bcfc7c4da 100644 (file)
@@ -4,13 +4,23 @@
 
 /* Test that pinned memory works (pool_size code path).  */
 
+#include <stdio.h>
+#include <stdlib.h>
+
 #ifdef __linux__
 #include <sys/types.h>
 #include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
 
 #include <sys/mman.h>
+#include <sys/resource.h>
+
+#define PAGE_SIZE sysconf(_SC_PAGESIZE)
+#define CHECK_SIZE(SIZE) { \
+  struct rlimit limit; \
+  if (getrlimit (RLIMIT_MEMLOCK, &limit) \
+      || limit.rlim_cur <= SIZE) \
+    fprintf (stderr, "unsufficient lockable memory; please increase ulimit\n"); \
+  }
 
 int
 get_pinned_mem ()
@@ -34,6 +44,9 @@ get_pinned_mem ()
   abort ();
 }
 #else
+#define PAGE_SIZE 1 /* unknown */
+#define CHECK_SIZE(SIZE) fprintf (stderr, "OS unsupported\n");
+
 int
 get_pinned_mem ()
 {
@@ -43,12 +56,13 @@ get_pinned_mem ()
 
 #include <omp.h>
 
-/* Allocate more than a page each time, but stay within the ulimit.  */
-#define SIZE 10*1024
-
 int
 main ()
 {
+  /* Allocate at least a page each time, but stay within the ulimit.  */
+  const int SIZE = PAGE_SIZE;
+  CHECK_SIZE (SIZE*3);
+
   const omp_alloctrait_t traits[] = {
       { omp_atk_pinned, 1 },
       { omp_atk_pool_size, SIZE*8 }
index 943dfea5c9b7fa99c945118e8faf2da68d88cd53..90539ffe3e0ce304cc3404071600bf360f95a620 100644 (file)
@@ -2,15 +2,18 @@
 
 /* Test that pinned memory fails correctly.  */
 
+#include <stdio.h>
+#include <stdlib.h>
+
 #ifdef __linux__
 #include <sys/types.h>
 #include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
 
 #include <sys/mman.h>
 #include <sys/resource.h>
 
+#define PAGE_SIZE sysconf(_SC_PAGESIZE)
+
 int
 get_pinned_mem ()
 {
@@ -45,6 +48,8 @@ set_pin_limit (int size)
 }
 #else
 int
+#define PAGE_SIZE 10000*1024 /* unknown */
+
 get_pinned_mem ()
 {
   return 0;
@@ -58,12 +63,12 @@ set_pin_limit ()
 
 #include <omp.h>
 
-/* This should be large enough to cover multiple pages.  */
-#define SIZE 10000*1024
-
 int
 main ()
 {
+  /* This needs to be large enough to cover multiple pages.  */
+  const int SIZE = PAGE_SIZE*4;
+
   /* Pinned memory, no fallback.  */
   const omp_alloctrait_t traits1[] = {
       { omp_atk_pinned, 1 },
index d9cb8dfe1fd7b8398d9febe3e438f2fade8e8391..534e49eefc4dd6749a7af04c7fbb2dbc4a5ccf59 100644 (file)
@@ -2,15 +2,18 @@
 
 /* Test that pinned memory fails correctly, pool_size code path.  */
 
+#include <stdio.h>
+#include <stdlib.h>
+
 #ifdef __linux__
 #include <sys/types.h>
 #include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
 
 #include <sys/mman.h>
 #include <sys/resource.h>
 
+#define PAGE_SIZE sysconf(_SC_PAGESIZE)
+
 int
 get_pinned_mem ()
 {
@@ -45,6 +48,8 @@ set_pin_limit (int size)
 }
 #else
 int
+#define PAGE_SIZE 10000*1024 /* unknown */
+
 get_pinned_mem ()
 {
   return 0;
@@ -58,12 +63,12 @@ set_pin_limit ()
 
 #include <omp.h>
 
-/* This should be large enough to cover multiple pages.  */
-#define SIZE 10000*1024
-
 int
 main ()
 {
+  /* This needs to be large enough to cover multiple pages.  */
+  const int SIZE = PAGE_SIZE*4;
+
   /* Pinned memory, no fallback.  */
   const omp_alloctrait_t traits1[] = {
       { omp_atk_pinned, 1 },
index 8355ca83790abf5fd5563de098c7a49f8cd8602d..315c7161a390cf30f71906e2fede42e3cc66d595 100644 (file)
@@ -4,13 +4,23 @@
 
 /* Test that ompx_pinned_mem_alloc works.  */
 
+#include <stdio.h>
+#include <stdlib.h>
+
 #ifdef __linux__
 #include <sys/types.h>
 #include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
 
 #include <sys/mman.h>
+#include <sys/resource.h>
+
+#define PAGE_SIZE sysconf(_SC_PAGESIZE)
+#define CHECK_SIZE(SIZE) { \
+  struct rlimit limit; \
+  if (getrlimit (RLIMIT_MEMLOCK, &limit) \
+      || limit.rlim_cur <= SIZE) \
+    fprintf (stderr, "unsufficient lockable memory; please increase ulimit\n"); \
+  }
 
 int
 get_pinned_mem ()
@@ -34,6 +44,9 @@ get_pinned_mem ()
   abort ();
 }
 #else
+#define PAGE_SIZE 1 /* unknown */
+#define CHECK_SIZE(SIZE) fprintf (stderr, "OS unsupported\n");
+
 int
 get_pinned_mem ()
 {
@@ -43,12 +56,13 @@ get_pinned_mem ()
 
 #include <omp.h>
 
-/* Allocate more than a page each time, but stay within the ulimit.  */
-#define SIZE 10*1024
-
 int
 main ()
 {
+  /* Allocate at least a page each time, but stay within the ulimit.  */
+  const int SIZE = PAGE_SIZE;
+  CHECK_SIZE (SIZE*3);
+
   // Sanity check
   if (get_pinned_mem () != 0)
     abort ();
index 80fd37ab875fcc4103688b3f9409c4d52f5d76ff..bbe20c048753ea3f26fc5c1894b18c60307b949c 100644 (file)
@@ -2,15 +2,18 @@
 
 /* Test that ompx_pinned_mem_alloc fails correctly.  */
 
+#include <stdio.h>
+#include <stdlib.h>
+
 #ifdef __linux__
 #include <sys/types.h>
 #include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
 
 #include <sys/mman.h>
 #include <sys/resource.h>
 
+#define PAGE_SIZE sysconf(_SC_PAGESIZE)
+
 int
 get_pinned_mem ()
 {
@@ -44,6 +47,8 @@ set_pin_limit (int size)
     abort ();
 }
 #else
+#define PAGE_SIZE 10000*1024 /* unknown */
+
 int
 get_pinned_mem ()
 {
@@ -58,12 +63,12 @@ set_pin_limit ()
 
 #include <omp.h>
 
-/* This should be large enough to cover multiple pages.  */
-#define SIZE 10000*1024
-
 int
 main ()
 {
+  /* Allocate at least a page each time, but stay within the ulimit.  */
+  const int SIZE = PAGE_SIZE*4;
+
   /* Ensure that the limit is smaller than the allocation.  */
   set_pin_limit (SIZE/2);
 
index 6fd19b46a5ce11b01833ad014d9e4c87c85749a7..8dc190550380a216bf0ae9cf7025faca428be06a 100644 (file)
@@ -5,11 +5,12 @@
 
 /* Test that pinned memory works.  */
 
+#include <stdio.h>
+#include <stdlib.h>
+
 #ifdef __linux__
 #include <sys/types.h>
 #include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
 
 #include <sys/mman.h>
 
@@ -28,7 +29,6 @@ get_pinned_mem ()
       int val;
       if (sscanf (buf, "VmLck: %d", &val))
        {
-         printf ("lock %d\n", val);
          fclose (proc);
          return val;
        }
@@ -47,9 +47,6 @@ get_pinned_mem ()
 
 #include <omp.h>
 
-/* Allocate more than a page each time, but stay within the ulimit.  */
-#define SIZE 10*1024
-
 int
 main ()
 {