From patchwork Fri Jun 25 08:10:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Kanzenbach X-Patchwork-Id: 44013 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 3411239BF4B7 for ; Fri, 25 Jun 2021 08:13:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3411239BF4B7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624608800; bh=IsSBBwuSqOJz1cynIplqPlmkPBatU/WX6rIycSCO7oI=; 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=Ko5rdfzQFElLWmp5OnjZkJtc3dvBibhgaGC/xBa9uFKIOu6OqSPCVkxCk5sxypVPp mivadM18BYKgJXVr++sgDTyo9UtONaAFN5cwPqa2Jl6tUacydtoT3La6yO8JmJVmfD g9AEn3kg0Ft7FEqD+kfLoYS/Xa2NglnftNm2yFaw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by sourceware.org (Postfix) with ESMTPS id 9026F385702B for ; Fri, 25 Jun 2021 08:11:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9026F385702B To: libc-alpha@sourceware.org Subject: [PATCH v1 1/6] Linux: Add FUTEX_LOCK_PI2 Date: Fri, 25 Jun 2021 10:10:59 +0200 Message-Id: <20210625081104.1134598-2-kurt@linutronix.de> In-Reply-To: <20210625081104.1134598-1-kurt@linutronix.de> References: <20210625081104.1134598-1-kurt@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, 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 , Peter Zijlstra , Thomas Gleixner , Joseph Myers Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Linux v5.14.0 introduced a new futex operation called FUTEX_LOCK_PI2. This kernel feature can be used to implement pthread_mutex_clocklock(MONOTONIC)/PI. Signed-off-by: Kurt Kanzenbach Reviewed-by: Adhemerval Zanella --- sysdeps/unix/sysv/linux/kernel-features.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h index 1680b10ca1b6..af4b2b304715 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 >= 0x050e00 +# define __ASSUME_FUTEX_LOCK_PI2 1 +#else +# define __ASSUME_FUTEX_LOCK_PI2 0 +#endif + #endif /* kernel-features.h */ From patchwork Fri Jun 25 08:11:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Kanzenbach X-Patchwork-Id: 44012 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 012BF39BF4B3 for ; Fri, 25 Jun 2021 08:12:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 012BF39BF4B3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624608755; bh=FYTOmX+g/Uw3po98kn9GWUvUfReDXVQxsz+NEpkcv9o=; 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=xFNmLRIWVoTYVzhOuKQg4AYfXxRuac67rTLHikCWMU4iPxDSDgw50q6M2tLiQtE4P nXtNrOnmNDbya67LLiYiHbg2/BuReOPTY97UNiSS1IxTB9qynWejmlYGqGxI7eANQ/ BB52a9XYcshf9hCrYfazv/rqBmEEKUp6QJA2jsDs= 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 C305C385AC22 for ; Fri, 25 Jun 2021 08:11:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C305C385AC22 To: libc-alpha@sourceware.org Subject: [PATCH v1 2/6] nptl: Introduce futex_lock_pi2() Date: Fri, 25 Jun 2021 10:11:00 +0200 Message-Id: <20210625081104.1134598-3-kurt@linutronix.de> In-Reply-To: <20210625081104.1134598-1-kurt@linutronix.de> References: <20210625081104.1134598-1-kurt@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-10.1 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 , Peter Zijlstra , Thomas Gleixner , Joseph Myers Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This variant of futex_lock() has support for selectable clocks and priority inheritance. The underlying FUTEX_LOCK_PI2 operation has been recently introduced into the Linux kernel. It can be used for implementing pthread_mutex_clocklock(MONOTONIC)/PI. The code works like this: * If kernel support is assumed, then use FUTEX_LOCK_PI2 * If not, distuingish between clockid: * For realtime use FUTEX_LOCK_PI * For monotonic try to use FUTEX_LOCK_PI2 which might not be available Signed-off-by: Kurt Kanzenbach --- sysdeps/nptl/futex-internal.h | 131 ++++++++++++++++++++++++++++++ sysdeps/nptl/lowlevellock-futex.h | 1 + 2 files changed, 132 insertions(+) diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h index 79a366604d9e..38c969831276 100644 --- a/sysdeps/nptl/futex-internal.h +++ b/sysdeps/nptl/futex-internal.h @@ -303,6 +303,137 @@ futex_lock_pi64 (int *futex_word, const struct __timespec64 *abstime, } } +/* The operation checks the value of the futex, if the value is 0, then + it is atomically set to the caller's thread ID. If the futex value is + nonzero, it is atomically sets the FUTEX_WAITERS bit, which signals wrt + other futex owner that it cannot unlock the futex in user space by + atomically by setting its value to 0. + + If more than one wait operations is issued, the enqueueing of the waiters + are done in descending priority order. + + The ABSTIME arguments provides an absolute timeout (measured against the + CLOCK_REALTIME or CLOCK_MONOTONIC clock). If TIMEOUT is NULL, the operation + will block indefinitely. + + Returns: + + - 0 if woken by a PI unlock operation or spuriously. + - EAGAIN if the futex owner thread ID is about to exit, but has not yet + handled the state cleanup. + - EDEADLK if the futex is already locked by the caller. + - ESRCH if the thread ID int he futex does not exist. + - EINVAL is the state is corrupted or if there is a waiter on the + futex or if the clockid is invalid. + - ETIMEDOUT if the ABSTIME expires. +*/ +static __always_inline int +futex_lock_pi2_64 (int *futex_word, clockid_t clockid, + const struct __timespec64 *abstime, int private) +{ + unsigned int clockbit; + int err; + + if (! lll_futex_supported_clockid (clockid)) + return EINVAL; + + clockbit = (clockid == CLOCK_REALTIME) ? FUTEX_CLOCK_REALTIME : 0; + int op = __lll_private_flag (FUTEX_LOCK_PI2 | clockbit, private); + + /* FUTEX_LOCK_PI2 is a new futex operation. It supports selectable clocks + whereas the old FUTEX_LOCK_PI does only support CLOCK_REALTIME. + + Therefore, the code works like this: + + - If kernel support is available, then use FUTEX_LOCK_PI2 + - If not, distuingish between clockid: For realtime use FUTEX_LOCK_PI and + for monotonic try to use FUTEX_LOCK_PI2 which might not be available. */ + +#if __ASSUME_FUTEX_LOCK_PI2 + +# ifdef __ASSUME_TIME64_SYSCALLS + err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op, 0, abstime); +# else + + bool need_time64 = abstime != NULL && !in_time_t_range (abstime->tv_sec); + if (need_time64) + { + err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op, 0, abstime); + if (err == -ENOSYS) + err = -EOVERFLOW; + } + else + { + struct timespec ts32; + + if (abstime != NULL) + ts32 = valid_timespec64_to_timespec (*abstime); + + err = INTERNAL_SYSCALL_CALL (futex, futex_word, op, 0, + abstime != NULL ? &ts32 : NULL); + } +# endif /* __ASSUME_TIME64_SYSCALLS */ + +#else + + /* For CLOCK_MONOTONIC the only option is to use FUTEX_LOCK_PI2 */ + if (abstime != NULL && clockid != CLOCK_REALTIME) + { +# ifdef __ASSUME_TIME64_SYSCALLS + err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op, 0, abstime); +# else + bool need_time64 = abstime != NULL && !in_time_t_range (abstime->tv_sec); + if (need_time64) + { + err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op, 0, + abstime); + } + else + { + struct timespec ts32; + + if (abstime != NULL) + ts32 = valid_timespec64_to_timespec (*abstime); + + err = INTERNAL_SYSCALL_CALL (futex, futex_word, op, 0, + abstime != NULL ? &ts32 : NULL); + } +# endif /* __ASSUME_TIME64_SYSCALLS */ + + /* FUTEX_LOCK_PI2 is not available on this kernel */ + if (err == -ENOSYS) + return EINVAL; + } + else + { + /* Otherwise use CLOCK_REALTIME and FUTEX_LOCK_PI */ + return futex_lock_pi64 (futex_word, abstime, private); + } +#endif /* __ASSUME_FUTEX_LOCK_PI2 */ + + switch (err) + { + case 0: + case -EAGAIN: + case -EINTR: + case -ETIMEDOUT: + case -ESRCH: + case -EDEADLK: + case -EINVAL: /* This indicates either state corruption or that the kernel + found a waiter on futex address which is waiting via + FUTEX_WAIT or FUTEX_WAIT_BITSET. This is reported on + some futex_lock_pi usage (pthread_mutex_timedlock for + instance). */ + return -err; + + case -EFAULT: /* Must have been caused by a glibc or application bug. */ + case -ENOSYS: /* Must have been caused by a glibc bug. */ + /* No other errors are documented at this time. */ + default: + futex_fatal_error (); + } +} + /* Wakes the top priority waiter that called a futex_lock_pi operation on the futex. diff --git a/sysdeps/nptl/lowlevellock-futex.h b/sysdeps/nptl/lowlevellock-futex.h index 66ebfe50f4c1..abda179e0de2 100644 --- a/sysdeps/nptl/lowlevellock-futex.h +++ b/sysdeps/nptl/lowlevellock-futex.h @@ -38,6 +38,7 @@ #define FUTEX_WAKE_BITSET 10 #define FUTEX_WAIT_REQUEUE_PI 11 #define FUTEX_CMP_REQUEUE_PI 12 +#define FUTEX_LOCK_PI2 13 #define FUTEX_PRIVATE_FLAG 128 #define FUTEX_CLOCK_REALTIME 256 From patchwork Fri Jun 25 08:11:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Kanzenbach X-Patchwork-Id: 44014 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 5B75539C050E for ; Fri, 25 Jun 2021 08:14:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B75539C050E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624608844; bh=Ikvzo1q+2KX8aIdhQAXMzlVeuxJqXm+HfLqTxrThoTY=; 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=Scb02JKz5CkiC6IYRCZ12j1KP9oMSlt+iU1Ooc/5n4Uyupt9WVN7wOzj1aCqDNGjB sIoti35G7rR7XOYO4LUrwbG2sfkFBd8+/sjoh398Vfq3ZicyQpP+NQOqd7ipArbaQr lTyNYJN6BCzbb31jTCMdtIHdUuaBZqgBBdpaQIpY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by sourceware.org (Postfix) with ESMTPS id 67C1039BECD3 for ; Fri, 25 Jun 2021 08:11:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 67C1039BECD3 To: libc-alpha@sourceware.org Subject: [PATCH v1 3/6] nptl: Use futex_lock_pi2() Date: Fri, 25 Jun 2021 10:11:01 +0200 Message-Id: <20210625081104.1134598-4-kurt@linutronix.de> In-Reply-To: <20210625081104.1134598-1-kurt@linutronix.de> References: <20210625081104.1134598-1-kurt@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 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 , Peter Zijlstra , Thomas Gleixner , Joseph Myers Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Currently it is not possible to specify CLOCK_MONOTONIC for timeouts for PI mutexes. The FUTEX_LOCK_PI2 operation can be used to implement that. Therefore, use it by default. In case FUTEX_LOCK_PI2 is not available on the running kernel, then EINVAL is returned as of now. Signed-off-by: Kurt Kanzenbach --- nptl/pthread_mutex_timedlock.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index 5afd6222d61e..95892a32a6af 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -300,13 +300,6 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex, case PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP: case PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP: { - /* Currently futex FUTEX_LOCK_PI operation only provides support for - CLOCK_REALTIME and trying to emulate by converting a - CLOCK_MONOTONIC to CLOCK_REALTIME will take in account possible - changes to the wall clock. */ - if (__glibc_unlikely (clockid != CLOCK_REALTIME)) - return EINVAL; - int kind, robust; { /* See concurrency notes regarding __kind in struct __pthread_mutex_s @@ -370,7 +363,8 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex, int private = (robust ? PTHREAD_ROBUST_MUTEX_PSHARED (mutex) : PTHREAD_MUTEX_PSHARED (mutex)); - int e = futex_lock_pi64 (&mutex->__data.__lock, abstime, private); + int e = futex_lock_pi2_64 (&mutex->__data.__lock, clockid, abstime, + private); if (e == ETIMEDOUT) return ETIMEDOUT; else if (e == ESRCH || e == EDEADLK) From patchwork Fri Jun 25 08:11:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Kanzenbach X-Patchwork-Id: 44015 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 C477639C050F for ; Fri, 25 Jun 2021 08:14:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C477639C050F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624608896; bh=4kM3F6ZrgYaoFKzAStmGjJa3Es1BWiFfYqGaa6ziSS0=; 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=HtTu727DxwR+UIAWDIjpDQObbrZ2Corps0xUEDxzosBYkxJuC5M2mYEhUeG7MJsJ0 1Uq4Cw9c/GNfSN3N51+puYwUDc9wHS05to0V/ToOMaTwD1Kqe4v2thB2IHVXjGDWWr QOvxRkj50+JcvZ4dSf70PT6gum4gXVCq2rGaJTSA= 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 C289239BECE3 for ; Fri, 25 Jun 2021 08:11:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C289239BECE3 To: libc-alpha@sourceware.org Subject: [PATCH v1 4/6] nptl: Remove mutex test 10 Date: Fri, 25 Jun 2021 10:11:02 +0200 Message-Id: <20210625081104.1134598-5-kurt@linutronix.de> In-Reply-To: <20210625081104.1134598-1-kurt@linutronix.de> References: <20210625081104.1134598-1-kurt@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, 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 , Peter Zijlstra , Thomas Gleixner , Joseph Myers Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" That test checks whether pthread_mutex_clocklock(MONOTONIC)/PI returns EINVAL. However, support for that has been implemented. Therefore, remove the test. Signed-off-by: Kurt Kanzenbach --- nptl/Makefile | 2 +- nptl/tst-mutexpi10.c | 68 -------------------------------------------- 2 files changed, 1 insertion(+), 69 deletions(-) delete mode 100644 nptl/tst-mutexpi10.c diff --git a/nptl/Makefile b/nptl/Makefile index c64e4af2f680..5ab25c524fac 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -269,7 +269,7 @@ tests = tst-attr2 tst-attr3 tst-default-attr \ tst-mutex5a tst-mutex7a \ tst-mutexpi1 tst-mutexpi2 tst-mutexpi3 tst-mutexpi4 \ tst-mutexpi5 tst-mutexpi5a tst-mutexpi6 tst-mutexpi7 tst-mutexpi7a \ - tst-mutexpi9 tst-mutexpi10 \ + tst-mutexpi9 \ tst-cond22 tst-cond26 \ tst-robustpi1 tst-robustpi2 tst-robustpi3 tst-robustpi4 tst-robustpi5 \ tst-robustpi6 tst-robustpi7 tst-robustpi9 \ diff --git a/nptl/tst-mutexpi10.c b/nptl/tst-mutexpi10.c deleted file mode 100644 index da781d0d7a93..000000000000 --- a/nptl/tst-mutexpi10.c +++ /dev/null @@ -1,68 +0,0 @@ -/* Check if pthread_mutex_clocklock with PRIO_INHERIT fails with clock - different than CLOCK_REALTIME. - Copyright (C) 2020-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include - -#include -#include -#include - -static int -do_test (void) -{ - const int types[] = { - PTHREAD_MUTEX_NORMAL, - PTHREAD_MUTEX_ERRORCHECK, - PTHREAD_MUTEX_RECURSIVE, - PTHREAD_MUTEX_ADAPTIVE_NP - }; - const int robust[] = { - PTHREAD_MUTEX_STALLED, - PTHREAD_MUTEX_ROBUST - }; - - - for (int t = 0; t < array_length (types); t++) - for (int r = 0; r < array_length (robust); r++) - { - pthread_mutexattr_t attr; - - xpthread_mutexattr_init (&attr); - xpthread_mutexattr_setprotocol (&attr, PTHREAD_PRIO_INHERIT); - xpthread_mutexattr_settype (&attr, types[t]); - xpthread_mutexattr_setrobust (&attr, robust[r]); - - pthread_mutex_t mtx; - xpthread_mutex_init (&mtx, &attr); - - struct timespec tmo = timespec_add (xclock_now (CLOCK_MONOTONIC), - make_timespec (0, 100000000)); - - TEST_COMPARE (pthread_mutex_clocklock (&mtx, CLOCK_MONOTONIC, &tmo), - EINVAL); - - xpthread_mutex_destroy (&mtx); - } - - return 0; -} - -#include From patchwork Fri Jun 25 08:11:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Kanzenbach X-Patchwork-Id: 44017 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 1BC9539C051A for ; Fri, 25 Jun 2021 08:16:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1BC9539C051A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624608985; bh=UvF8nGdqSn4dQJJFpdR8rkf91XYKCqnWQd+7pdlhGtE=; 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=KzAv5caArGtIHbS8r0lUX6i2YqpeOFGSZ0hLBj0KdXjoOkr/wZ7u5qM776lvdx+Ar 5LsL8puJ01+bqXRg84rZE8eYvHOEK4Q2HubGhS7owVUW4mCJPl+ASI9FMI/WsuuVqg tCd/lTVLLEKMkEctIQcevJOo8lZ258J7IGDtPzlA= 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 55AED39BF486 for ; Fri, 25 Jun 2021 08:11:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 55AED39BF486 To: libc-alpha@sourceware.org Subject: [PATCH v1 5/6] nptl: mutex-test5: Include CLOCK_MONOTONIC for PI Date: Fri, 25 Jun 2021 10:11:03 +0200 Message-Id: <20210625081104.1134598-6-kurt@linutronix.de> In-Reply-To: <20210625081104.1134598-1-kurt@linutronix.de> References: <20210625081104.1134598-1-kurt@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 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 , Peter Zijlstra , Thomas Gleixner , Joseph Myers Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" pthread_mutex_clocklock(MONOTONIC)/PI is now supported. Adjust the test accordingly. Signed-off-by: Kurt Kanzenbach --- sysdeps/pthread/tst-mutex5.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/sysdeps/pthread/tst-mutex5.c b/sysdeps/pthread/tst-mutex5.c index 7dc5331cfc08..6ad50f845601 100644 --- a/sysdeps/pthread/tst-mutex5.c +++ b/sysdeps/pthread/tst-mutex5.c @@ -77,11 +77,21 @@ 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); + { + err = pthread_mutex_timedlock (&m, &ts_timeout); + TEST_COMPARE (err, ETIMEDOUT); + } else - TEST_COMPARE (pthread_mutex_clocklock (&m, clockid, &ts_timeout), - ETIMEDOUT); - TEST_TIMESPEC_BEFORE_NOW (ts_timeout, clockid_for_get); + { + err = pthread_mutex_clocklock (&m, clockid, &ts_timeout); + + /* In case of CLOCK_MONOTONIC the error might be EINVAL if CLOCK_MONOTONIC + is not supported. */ + TEST_VERIFY (err == ETIMEDOUT || + (clockid == CLOCK_MONOTONIC && err == EINVAL)); + } + if (err == ETIMEDOUT) + TEST_TIMESPEC_BEFORE_NOW (ts_timeout, clockid_for_get); /* The following makes the ts value invalid. */ ts_timeout.tv_nsec += 1000000000; @@ -122,9 +132,7 @@ static int do_test (void) do_test_clock (CLOCK_USE_TIMEDLOCK, "timedlock"); do_test_clock (CLOCK_REALTIME, "clocklock(realtime)"); -#ifndef ENABLE_PI do_test_clock (CLOCK_MONOTONIC, "clocklock(monotonic)"); -#endif return 0; } From patchwork Fri Jun 25 08:11:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Kanzenbach X-Patchwork-Id: 44016 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 F230A39C0517 for ; Fri, 25 Jun 2021 08:15:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F230A39C0517 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624608941; bh=s2eDUsIjebBmqpJJ77d7cAjv42W50THtY9sH+mVlOAE=; 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=lTdNIn4izAdAd/pHcxK8VxliYK5941YfENjiDa7Y60UU3byzccWxW41dlJHvFFtIr tJhfVagqlOLTU6z31M4vYseDR7i5DXKRB+BKuWhvySN6ko7SHeTEoNW+FCcYDB/Iu7 Ymr7dKHTAYEJwE6StqaKvcLsGIjmfG8hX3oMSZaw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by sourceware.org (Postfix) with ESMTPS id 52B7139BF485 for ; Fri, 25 Jun 2021 08:11:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 52B7139BF485 To: libc-alpha@sourceware.org Subject: [PATCH v1 6/6] nptl: mutex-test9: Include CLOCK_MONOTONIC for PI Date: Fri, 25 Jun 2021 10:11:04 +0200 Message-Id: <20210625081104.1134598-7-kurt@linutronix.de> In-Reply-To: <20210625081104.1134598-1-kurt@linutronix.de> References: <20210625081104.1134598-1-kurt@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 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 , Peter Zijlstra , Thomas Gleixner , Joseph Myers Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" pthread_mutex_clocklock(MONOTONIC)/PI is now supported. Adjust the test accordingly. Signed-off-by: Kurt Kanzenbach --- sysdeps/pthread/tst-mutex9.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sysdeps/pthread/tst-mutex9.c b/sysdeps/pthread/tst-mutex9.c index 58c3a1aec263..d53eda841551 100644 --- a/sysdeps/pthread/tst-mutex9.c +++ b/sysdeps/pthread/tst-mutex9.c @@ -114,7 +114,12 @@ do_test_clock (clockid_t clockid) if (clockid == CLOCK_USE_TIMEDLOCK) TEST_COMPARE (pthread_mutex_timedlock (m, &ts), ETIMEDOUT); else - TEST_COMPARE (pthread_mutex_clocklock (m, clockid, &ts), ETIMEDOUT); + { + int err = pthread_mutex_clocklock (m, clockid, &ts); + + TEST_VERIFY (err == ETIMEDOUT || + (clockid == CLOCK_MONOTONIC && err == EINVAL)); + } alarm (1); @@ -144,9 +149,7 @@ do_test (void) do_test_clock (CLOCK_USE_TIMEDLOCK); do_test_clock (CLOCK_REALTIME); -#ifndef ENABLE_PI do_test_clock (CLOCK_MONOTONIC); -#endif return 0; }