public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Kurt Kanzenbach <kurt@linutronix.de>
To: libc-alpha@sourceware.org
Cc: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	Florian Weimer <fweimer@redhat.com>,
	Carlos O'Donell <carlos@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Kurt Kanzenbach <kurt@linutronix.de>
Subject: [PATCH RFC 3/3] nptl: Include CLOCK_MONOTONIC in mutex tests
Date: Mon, 21 Jun 2021 13:16:50 +0200	[thread overview]
Message-ID: <20210621111650.1164689-4-kurt@linutronix.de> (raw)
In-Reply-To: <20210621111650.1164689-1-kurt@linutronix.de>

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


  parent reply	other threads:[~2021-06-21 11:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-21 11:16 [PATCH RFC 0/3] nptl: Introduce and use FUTEX_LOCK_PI2 Kurt Kanzenbach
2021-06-21 11:16 ` [PATCH RFC 1/3] nptl: Introduce futex_lock_pi2() Kurt Kanzenbach
2021-06-21 11:16 ` [PATCH RFC 2/3] nptl: Use futex_lock_pi2() Kurt Kanzenbach
2021-06-21 11:16 ` Kurt Kanzenbach [this message]
2021-06-21 20:07   ` [PATCH RFC 3/3] nptl: Include CLOCK_MONOTONIC in mutex tests Joseph Myers
2021-06-22  8:58     ` Kurt Kanzenbach
2021-06-21 21:32 ` [PATCH RFC 0/3] nptl: Introduce and use FUTEX_LOCK_PI2 Adhemerval Zanella
2021-06-22  7:26   ` Kurt Kanzenbach
2021-06-22  7:29     ` Florian Weimer
2021-06-22  8:55       ` Kurt Kanzenbach
2021-06-22 12:30     ` Adhemerval Zanella
2021-06-22 14:25       ` Kurt Kanzenbach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210621111650.1164689-4-kurt@linutronix.de \
    --to=kurt@linutronix.de \
    --cc=adhemerval.zanella@linaro.org \
    --cc=bigeasy@linutronix.de \
    --cc=carlos@redhat.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).