From patchwork Mon Jun 21 11:16:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Kanzenbach X-Patchwork-Id: 43931 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5FF073898516 for ; Mon, 21 Jun 2021 11:22:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FF073898516 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624274552; bh=dXLn4q07B5AjJKQbo/WqnAY5L9DKAHzerKc17b+8LZE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=avQKXd9iMW5cQg3euDjneuOrMNAe010zPAS95OpnLnYD9JpQHu4MtcOmHvKGjlT26 lHLugZr2z6dMCu3Qfb8YzxC3bKshTBMsZuT26uhHwROZvrZ+Y/I+ba3YNydtwG2kSg Fg8GxbENNNI4gqDDeSRImdqSMm8vKsLrHjsJYsBk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by sourceware.org (Postfix) with ESMTPS id 6CEAC393A42C for ; Mon, 21 Jun 2021 11:17:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6CEAC393A42C To: libc-alpha@sourceware.org Subject: [PATCH RFC 3/3] nptl: Include CLOCK_MONOTONIC in mutex tests Date: Mon, 21 Jun 2021 13:16:50 +0200 Message-Id: <20210621111650.1164689-4-kurt@linutronix.de> In-Reply-To: <20210621111650.1164689-1-kurt@linutronix.de> References: <20210621111650.1164689-1-kurt@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Kurt Kanzenbach via Libc-alpha From: Kurt Kanzenbach Reply-To: Kurt Kanzenbach Cc: Florian Weimer , Sebastian Andrzej Siewior , Kurt Kanzenbach , Thomas Gleixner Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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 --- 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 #include +#include + 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 #include #include +#include #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 #include #include +#include #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 */