From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1729) id 2AEB8384F025; Wed, 29 Jun 2022 14:46:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2AEB8384F025 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Kwok Yeung To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-12] libgomp: autodetect page sizes in pinned memory tests X-Act-Checkin: gcc X-Git-Author: Andrew Stubbs X-Git-Refname: refs/heads/devel/omp/gcc-12 X-Git-Oldrev: 39bdcd849ec435bd8349161e7ad3e2c94160f645 X-Git-Newrev: 02b4955747ddf2e32f7d01eef19e294f36462ade Message-Id: <20220629144616.2AEB8384F025@sourceware.org> Date: Wed, 29 Jun 2022 14:46:16 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Jun 2022 14:46:16 -0000 https://gcc.gnu.org/g:02b4955747ddf2e32f7d01eef19e294f36462ade commit 02b4955747ddf2e32f7d01eef19e294f36462ade Author: Andrew Stubbs Date: Wed Apr 13 10:10:10 2022 +0100 libgomp: autodetect page sizes in pinned memory tests 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. Diff: --- libgomp/ChangeLog.omp | 10 ++++++++++ libgomp/testsuite/libgomp.c/alloc-pinned-1.c | 24 +++++++++++++++++++----- libgomp/testsuite/libgomp.c/alloc-pinned-2.c | 24 +++++++++++++++++++----- libgomp/testsuite/libgomp.c/alloc-pinned-3.c | 15 ++++++++++----- libgomp/testsuite/libgomp.c/alloc-pinned-4.c | 15 ++++++++++----- libgomp/testsuite/libgomp.c/alloc-pinned-5.c | 24 +++++++++++++++++++----- libgomp/testsuite/libgomp.c/alloc-pinned-6.c | 15 ++++++++++----- libgomp/testsuite/libgomp.c/alloc-pinned-7.c | 9 +++------ 8 files changed, 100 insertions(+), 36 deletions(-) diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp index 1693c212a12..e3ae0b33e82 100644 --- a/libgomp/ChangeLog.omp +++ b/libgomp/ChangeLog.omp @@ -1,3 +1,13 @@ +2022-04-13 Andrew Stubbs + + * 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 * testsuite/libgomp.c/usm-6.c: Add omp_target_alloc. diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-1.c b/libgomp/testsuite/libgomp.c/alloc-pinned-1.c index 0a6360cda29..79792b16d83 100644 --- a/libgomp/testsuite/libgomp.c/alloc-pinned-1.c +++ b/libgomp/testsuite/libgomp.c/alloc-pinned-1.c @@ -4,13 +4,23 @@ /* Test that pinned memory works. */ +#include +#include + #ifdef __linux__ #include #include -#include -#include #include +#include + +#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 -/* 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 } }; diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-2.c b/libgomp/testsuite/libgomp.c/alloc-pinned-2.c index 8fdb4ff5cfd..228c656b715 100644 --- a/libgomp/testsuite/libgomp.c/alloc-pinned-2.c +++ b/libgomp/testsuite/libgomp.c/alloc-pinned-2.c @@ -4,13 +4,23 @@ /* Test that pinned memory works (pool_size code path). */ +#include +#include + #ifdef __linux__ #include #include -#include -#include #include +#include + +#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 -/* 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 } diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-3.c b/libgomp/testsuite/libgomp.c/alloc-pinned-3.c index 943dfea5c9b..90539ffe3e0 100644 --- a/libgomp/testsuite/libgomp.c/alloc-pinned-3.c +++ b/libgomp/testsuite/libgomp.c/alloc-pinned-3.c @@ -2,15 +2,18 @@ /* Test that pinned memory fails correctly. */ +#include +#include + #ifdef __linux__ #include #include -#include -#include #include #include +#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 -/* 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 }, diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-4.c b/libgomp/testsuite/libgomp.c/alloc-pinned-4.c index d9cb8dfe1fd..534e49eefc4 100644 --- a/libgomp/testsuite/libgomp.c/alloc-pinned-4.c +++ b/libgomp/testsuite/libgomp.c/alloc-pinned-4.c @@ -2,15 +2,18 @@ /* Test that pinned memory fails correctly, pool_size code path. */ +#include +#include + #ifdef __linux__ #include #include -#include -#include #include #include +#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 -/* 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 }, diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-5.c b/libgomp/testsuite/libgomp.c/alloc-pinned-5.c index 8355ca83790..315c7161a39 100644 --- a/libgomp/testsuite/libgomp.c/alloc-pinned-5.c +++ b/libgomp/testsuite/libgomp.c/alloc-pinned-5.c @@ -4,13 +4,23 @@ /* Test that ompx_pinned_mem_alloc works. */ +#include +#include + #ifdef __linux__ #include #include -#include -#include #include +#include + +#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 -/* 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 (); diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-6.c b/libgomp/testsuite/libgomp.c/alloc-pinned-6.c index 80fd37ab875..bbe20c04875 100644 --- a/libgomp/testsuite/libgomp.c/alloc-pinned-6.c +++ b/libgomp/testsuite/libgomp.c/alloc-pinned-6.c @@ -2,15 +2,18 @@ /* Test that ompx_pinned_mem_alloc fails correctly. */ +#include +#include + #ifdef __linux__ #include #include -#include -#include #include #include +#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 -/* 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); diff --git a/libgomp/testsuite/libgomp.c/alloc-pinned-7.c b/libgomp/testsuite/libgomp.c/alloc-pinned-7.c index 6fd19b46a5c..8dc19055038 100644 --- a/libgomp/testsuite/libgomp.c/alloc-pinned-7.c +++ b/libgomp/testsuite/libgomp.c/alloc-pinned-7.c @@ -5,11 +5,12 @@ /* Test that pinned memory works. */ +#include +#include + #ifdef __linux__ #include #include -#include -#include #include @@ -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 -/* Allocate more than a page each time, but stay within the ulimit. */ -#define SIZE 10*1024 - int main () {