[PATCH RFC 3/3] nptl: Include CLOCK_MONOTONIC in mutex tests

Kurt Kanzenbach kurt@linutronix.de
Mon Jun 21 11:16:50 GMT 2021


Include pthread_mutex_clocklock(MONOTONIC)/PI in the testcases if FUTEX_LOCK_PI2
is available. Add the check at compile time to keep the test implementation
simple.

Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de>
---
 nptl/tst-mutexpi10.c                      | 8 ++++++++
 sysdeps/pthread/tst-mutex5.c              | 3 ++-
 sysdeps/pthread/tst-mutex9.c              | 3 ++-
 sysdeps/unix/sysv/linux/kernel-features.h | 8 ++++++++
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/nptl/tst-mutexpi10.c b/nptl/tst-mutexpi10.c
index da781d0d7a93..19644b6f06a9 100644
--- a/nptl/tst-mutexpi10.c
+++ b/nptl/tst-mutexpi10.c
@@ -25,6 +25,8 @@
 #include <support/xthread.h>
 #include <support/timespec.h>
 
+#include <kernel-features.h>
+
 static int
 do_test (void)
 {
@@ -56,8 +58,14 @@ do_test (void)
 	struct timespec tmo = timespec_add (xclock_now (CLOCK_MONOTONIC),
 					    make_timespec (0, 100000000));
 
+#if __ASSUME_FUTEX_LOCK_PI2
+	TEST_COMPARE (pthread_mutex_clocklock (&mtx, CLOCK_MONOTONIC, &tmo),
+		      0);
+	xpthread_mutex_unlock (&mtx);
+#else
 	TEST_COMPARE (pthread_mutex_clocklock (&mtx, CLOCK_MONOTONIC, &tmo),
 		      EINVAL);
+#endif
 
 	xpthread_mutex_destroy (&mtx);
       }
diff --git a/sysdeps/pthread/tst-mutex5.c b/sysdeps/pthread/tst-mutex5.c
index 7dc5331cfc08..82235ae479b0 100644
--- a/sysdeps/pthread/tst-mutex5.c
+++ b/sysdeps/pthread/tst-mutex5.c
@@ -26,6 +26,7 @@
 #include <config.h>
 #include <support/check.h>
 #include <support/timespec.h>
+#include <kernel-features.h>
 
 #ifdef ENABLE_PP
 #include "tst-tpp.h"
@@ -122,7 +123,7 @@ static int do_test (void)
 
   do_test_clock (CLOCK_USE_TIMEDLOCK, "timedlock");
   do_test_clock (CLOCK_REALTIME, "clocklock(realtime)");
-#ifndef ENABLE_PI
+#if ! defined(ENABLE_PI) || __ASSUME_FUTEX_LOCK_PI2
   do_test_clock (CLOCK_MONOTONIC, "clocklock(monotonic)");
 #endif
   return 0;
diff --git a/sysdeps/pthread/tst-mutex9.c b/sysdeps/pthread/tst-mutex9.c
index 58c3a1aec263..e43efb80bada 100644
--- a/sysdeps/pthread/tst-mutex9.c
+++ b/sysdeps/pthread/tst-mutex9.c
@@ -29,6 +29,7 @@
 #include <support/check.h>
 #include <support/timespec.h>
 #include <support/xunistd.h>
+#include <kernel-features.h>
 
 #ifdef ENABLE_PP
 #include "tst-tpp.h"
@@ -144,7 +145,7 @@ do_test (void)
 
   do_test_clock (CLOCK_USE_TIMEDLOCK);
   do_test_clock (CLOCK_REALTIME);
-#ifndef ENABLE_PI
+#if ! defined(ENABLE_PI) || __ASSUME_FUTEX_LOCK_PI2
   do_test_clock (CLOCK_MONOTONIC);
 #endif
   return 0;
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index 1680b10ca1b6..eb5c4d5a04bd 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -218,4 +218,12 @@
 # define __ASSUME_FACCESSAT2 0
 #endif
 
+/* The FUTEX_LOCK_PI2 operation was introduced across all architectures in Linux
+   5.14.  */
+#if __LINUX_KERNEL_VERSION >= 0x051400
+# define __ASSUME_FUTEX_LOCK_PI2 1
+#else
+# define __ASSUME_FUTEX_LOCK_PI2 0
+#endif
+
 #endif /* kernel-features.h */
-- 
2.30.2



More information about the Libc-alpha mailing list