diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2021-08-11 18:17:41 +0000 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2021-10-01 10:11:11 -0300 |
commit | 2313ab153de29849f8fb0817ed3789fa1745225a (patch) | |
tree | 00bb8f53d537de33fb4c8ab831daaaf0563798c8 /sysdeps | |
parent | 9cba3fa34b15017b269f2674ce7656bbc9d4d06d (diff) | |
download | glibc-2313ab153de29849f8fb0817ed3789fa1745225a.tar glibc-2313ab153de29849f8fb0817ed3789fa1745225a.tar.gz glibc-2313ab153de29849f8fb0817ed3789fa1745225a.tar.bz2 glibc-2313ab153de29849f8fb0817ed3789fa1745225a.zip |
nptl: Add CLOCK_MONOTONIC support for PI mutexes
Linux added FUTEX_LOCK_PI2 to support clock selection
(commit bf22a6976897977b0a3f1aeba6823c959fc4fdae). With the new
flag we can now proper support CLOCK_MONOTONIC for
pthread_mutex_clocklock with Priority Inheritance. If kernel
does not support, EINVAL is returned instead.
The difference is the futex operation will be issued and the kernel
will advertise the missing support (instead of hard-code error
return).
Checked on x86_64-linux-gnu and i686-linux-gnu on Linux 5.14, 5.11,
and 4.15.
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/pthread/tst-mutex5.c | 23 | ||||
-rw-r--r-- | sysdeps/pthread/tst-mutex9.c | 20 |
2 files changed, 28 insertions, 15 deletions
diff --git a/sysdeps/pthread/tst-mutex5.c b/sysdeps/pthread/tst-mutex5.c index b2a06b3650..89ad03fd8f 100644 --- a/sysdeps/pthread/tst-mutex5.c +++ b/sysdeps/pthread/tst-mutex5.c @@ -25,6 +25,7 @@ #include <config.h> #include <support/check.h> #include <support/timespec.h> +#include <support/xthread.h> #ifdef ENABLE_PP #include "tst-tpp.h" @@ -39,7 +40,7 @@ #define CLOCK_USE_TIMEDLOCK (-1) static int -do_test_clock (clockid_t clockid, const char *fnname) +do_test_clock (clockid_t clockid, const char *fnname, int tmo_result) { pthread_mutex_t m; pthread_mutexattr_t a; @@ -76,11 +77,12 @@ do_test_clock (clockid_t clockid, const char *fnname) make_timespec (2, 0)); if (clockid == CLOCK_USE_TIMEDLOCK) - TEST_COMPARE (pthread_mutex_timedlock (&m, &ts_timeout), ETIMEDOUT); + TEST_COMPARE (pthread_mutex_timedlock (&m, &ts_timeout), tmo_result); else TEST_COMPARE (pthread_mutex_clocklock (&m, clockid, &ts_timeout), - ETIMEDOUT); - TEST_TIMESPEC_BEFORE_NOW (ts_timeout, clockid_for_get); + tmo_result); + if (tmo_result == ETIMEDOUT) + TEST_TIMESPEC_BEFORE_NOW (ts_timeout, clockid_for_get); /* The following makes the ts value invalid. */ ts_timeout.tv_nsec += 1000000000; @@ -119,11 +121,16 @@ static int do_test (void) init_tpp_test (); #endif - do_test_clock (CLOCK_USE_TIMEDLOCK, "timedlock"); - do_test_clock (CLOCK_REALTIME, "clocklock(realtime)"); -#ifndef ENABLE_PI - do_test_clock (CLOCK_MONOTONIC, "clocklock(monotonic)"); + int monotonic_result = +#ifdef ENABLE_PI + support_mutex_pi_monotonic () ? ETIMEDOUT : EINVAL; +#else + ETIMEDOUT; #endif + + do_test_clock (CLOCK_USE_TIMEDLOCK, "timedlock", ETIMEDOUT); + do_test_clock (CLOCK_REALTIME, "clocklock(realtime)", ETIMEDOUT); + do_test_clock (CLOCK_MONOTONIC, "clocklock(monotonic)", monotonic_result); return 0; } diff --git a/sysdeps/pthread/tst-mutex9.c b/sysdeps/pthread/tst-mutex9.c index 63bac69b6d..b29d6efcc8 100644 --- a/sysdeps/pthread/tst-mutex9.c +++ b/sysdeps/pthread/tst-mutex9.c @@ -28,6 +28,7 @@ #include <support/check.h> #include <support/timespec.h> #include <support/xunistd.h> +#include <support/xthread.h> #ifdef ENABLE_PP #include "tst-tpp.h" @@ -39,7 +40,7 @@ #define CLOCK_USE_TIMEDLOCK (-1) static void -do_test_clock (clockid_t clockid) +do_test_clock (clockid_t clockid, int tmo_result) { const clockid_t clockid_for_get = (clockid == CLOCK_USE_TIMEDLOCK) ? CLOCK_REALTIME : clockid; @@ -111,9 +112,9 @@ do_test_clock (clockid_t clockid) make_timespec (0, 500000000)); if (clockid == CLOCK_USE_TIMEDLOCK) - TEST_COMPARE (pthread_mutex_timedlock (m, &ts), ETIMEDOUT); + TEST_COMPARE (pthread_mutex_timedlock (m, &ts), tmo_result); else - TEST_COMPARE (pthread_mutex_clocklock (m, clockid, &ts), ETIMEDOUT); + TEST_COMPARE (pthread_mutex_clocklock (m, clockid, &ts), tmo_result); alarm (1); @@ -141,11 +142,16 @@ do_test (void) init_tpp_test (); #endif - do_test_clock (CLOCK_USE_TIMEDLOCK); - do_test_clock (CLOCK_REALTIME); -#ifndef ENABLE_PI - do_test_clock (CLOCK_MONOTONIC); + int monotonic_result = +#ifdef ENABLE_PI + support_mutex_pi_monotonic () ? ETIMEDOUT : EINVAL; +#else + ETIMEDOUT; #endif + + do_test_clock (CLOCK_USE_TIMEDLOCK, ETIMEDOUT); + do_test_clock (CLOCK_REALTIME, ETIMEDOUT); + do_test_clock (CLOCK_MONOTONIC, monotonic_result); return 0; } |