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.
+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.
/* 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 ()
abort ();
}
#else
+#define PAGE_SIZE 1 /* unknown */
+#define CHECK_SIZE(SIZE) fprintf (stderr, "OS unsupported\n");
+
int
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 }
};
/* 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 ()
abort ();
}
#else
+#define PAGE_SIZE 1 /* unknown */
+#define CHECK_SIZE(SIZE) fprintf (stderr, "OS unsupported\n");
+
int
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 }
/* 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 ()
{
}
#else
int
+#define PAGE_SIZE 10000*1024 /* unknown */
+
get_pinned_mem ()
{
return 0;
#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 },
/* 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 ()
{
}
#else
int
+#define PAGE_SIZE 10000*1024 /* unknown */
+
get_pinned_mem ()
{
return 0;
#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 },
/* 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 ()
abort ();
}
#else
+#define PAGE_SIZE 1 /* unknown */
+#define CHECK_SIZE(SIZE) fprintf (stderr, "OS unsupported\n");
+
int
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 ();
/* 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 ()
{
abort ();
}
#else
+#define PAGE_SIZE 10000*1024 /* unknown */
+
int
get_pinned_mem ()
{
#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);
/* 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>
int val;
if (sscanf (buf, "VmLck: %d", &val))
{
- printf ("lock %d\n", val);
fclose (proc);
return val;
}
#include <omp.h>
-/* Allocate more than a page each time, but stay within the ulimit. */
-#define SIZE 10*1024
-
int
main ()
{