diff mbox series

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

Message ID 20210621111650.1164689-4-kurt@linutronix.de
State RFC
Headers show
Series nptl: Introduce and use FUTEX_LOCK_PI2 | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Kurt Kanzenbach June 21, 2021, 11:16 a.m. UTC
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(-)

Comments

Joseph Myers June 21, 2021, 8:07 p.m. UTC | #1
On Mon, 21 Jun 2021, Kurt Kanzenbach via Libc-alpha wrote:

> 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

0x051400 is 5.20.0, not 5.14.0.

I'd expect this change to appear in an earlier patch, with 
__ASSUME_FUTEX_LOCK_PI2 conditionals being used to disable fallback 
support for kernels found at runtime not to support the new feature.
Kurt Kanzenbach June 22, 2021, 8:58 a.m. UTC | #2
On Mon Jun 21 2021, Joseph Myers wrote:
> On Mon, 21 Jun 2021, Kurt Kanzenbach via Libc-alpha wrote:
>
>> 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
>
> 0x051400 is 5.20.0, not 5.14.0.

OK.

>
> I'd expect this change to appear in an earlier patch, with 
> __ASSUME_FUTEX_LOCK_PI2 conditionals being used to disable fallback 
> support for kernels found at runtime not to support the new feature.

Yes, understood.

Thanks,
Kurt
diff mbox series

Patch

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 */