From patchwork Mon Nov 23 19:52:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41159 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 3E0ED386F430; Mon, 23 Nov 2020 19:53:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E0ED386F430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606161185; bh=jBH22MJ9pWNq61iSknC2htil+Xg1ePgJI2gWrDXQaBA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=nBgJj/R31AVThEVAdOc2Bz7cWLTwdCw44YrD9RwvubjLHdu5gGOO1DiIpgIBghIQ+ xaZ3keOxQKeptmcVTrUXq3vBmhteXgcIvhyRoMlDlFltaeu3rghsm80p0dpgFKMThi W80cy2I+dedGAtoEYOTWfBKrhEKambmk9CVxwUEU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by sourceware.org (Postfix) with ESMTPS id 19D2B385802D for ; Mon, 23 Nov 2020 19:53:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 19D2B385802D Received: by mail-qk1-x742.google.com with SMTP id y18so1854617qki.11 for ; Mon, 23 Nov 2020 11:53:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=jBH22MJ9pWNq61iSknC2htil+Xg1ePgJI2gWrDXQaBA=; b=c7G/VlqK9OkFU88SV34PlFF8JaFy02aZc48X9docezjezlDb9ef1KxN25Mk3Inxo/D 2K/CBaf49/PZYPsl7IERCgI8g1x1FrQfo9iUM0hAxd91uAVhdCSFsc3Mpn1FzWDc5PAc GjVyOaf7I6GjaP5dOwaCRg1xtqWOEWN8C4nvPNPsCXmd2sx6XqLs0SbXrUKmMx9EHhyr Lb+Q3044upz+YASIDOos/si7LRGoUZETDARNu54biztCvvCgKJaORR7uEYkxaJSImfjX dj5TRVI0EGB4wADygT+iTQleEpdk1FsfZLDnEwCXiW7kNSO6eHN3U39vys9o5WQr+Qq6 eFWQ== X-Gm-Message-State: AOAM532aj/9NR6CAp05AXJ16UcSLwbx01EBYmXGzec+ibEM8U5yb6xSQ TiE0RdTAl4/F4AZVvCzXigyP2ZRnANrfeQ== X-Google-Smtp-Source: ABdhPJxeHsPoNtynKYX6LfT7heKwm4rKR8y9YopWKInMvxFA33fqJg51s/MsvK2nYJqacGEvVM5BNQ== X-Received: by 2002:a37:6814:: with SMTP id d20mr1101965qkc.445.1606161182318; Mon, 23 Nov 2020 11:53:02 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v9sm10440432qkv.34.2020.11.23.11.53.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:53:01 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 01/13] linux: Remove unused internal futex functions Date: Mon, 23 Nov 2020 16:52:44 -0300 Message-Id: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Michael Kerrisk Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The __futex_abstimed_wait usage was remove with 3102e28bd11 and the __futex_abstimed_wait_cancelable by 323592fdc92 and b8d3e8fbaac. The futex_lock_pi can be replaced by a futex_lock_pi64. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski --- nptl/pthread_mutex_lock.c | 3 +- sysdeps/nptl/futex-internal.h | 98 ----------------------------------- 2 files changed, 1 insertion(+), 100 deletions(-) diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c index fac774e608..0439002454 100644 --- a/nptl/pthread_mutex_lock.c +++ b/nptl/pthread_mutex_lock.c @@ -413,8 +413,7 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex) int private = (robust ? PTHREAD_ROBUST_MUTEX_PSHARED (mutex) : PTHREAD_MUTEX_PSHARED (mutex)); - int e = futex_lock_pi ((unsigned int *) &mutex->__data.__lock, - NULL, private); + int e = futex_lock_pi64 (&mutex->__data.__lock, NULL, private); if (e == ESRCH || e == EDEADLK) { assert (e != EDEADLK diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h index c27d0cdac8..21e3b74be6 100644 --- a/sysdeps/nptl/futex-internal.h +++ b/sysdeps/nptl/futex-internal.h @@ -275,76 +275,6 @@ futex_abstimed_supported_clockid (clockid_t clockid) return lll_futex_supported_clockid (clockid); } -/* Like futex_reltimed_wait, but the provided timeout (ABSTIME) is an - absolute point in time; a call will time out after this point in time. */ -static __always_inline int -futex_abstimed_wait (unsigned int* futex_word, unsigned int expected, - clockid_t clockid, - const struct timespec* abstime, int private) -{ - /* Work around the fact that the kernel rejects negative timeout values - despite them being valid. */ - if (__glibc_unlikely ((abstime != NULL) && (abstime->tv_sec < 0))) - return ETIMEDOUT; - int err = lll_futex_clock_wait_bitset (futex_word, expected, - clockid, abstime, - private); - switch (err) - { - case 0: - case -EAGAIN: - case -EINTR: - case -ETIMEDOUT: - return -err; - - case -EFAULT: /* Must have been caused by a glibc or application bug. */ - case -EINVAL: /* Either due to wrong alignment, unsupported - clockid or due to the timeout not being - normalized. 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 (); - } -} - -/* Like futex_reltimed_wait but is a POSIX cancellation point. */ -static __always_inline int -futex_abstimed_wait_cancelable (unsigned int* futex_word, - unsigned int expected, - clockid_t clockid, - const struct timespec* abstime, int private) -{ - /* Work around the fact that the kernel rejects negative timeout values - despite them being valid. */ - if (__glibc_unlikely ((abstime != NULL) && (abstime->tv_sec < 0))) - return ETIMEDOUT; - int oldtype; - oldtype = __pthread_enable_asynccancel (); - int err = lll_futex_clock_wait_bitset (futex_word, expected, - clockid, abstime, - private); - __pthread_disable_asynccancel (oldtype); - switch (err) - { - case 0: - case -EAGAIN: - case -EINTR: - case -ETIMEDOUT: - return -err; - - case -EFAULT: /* Must have been caused by a glibc or application bug. */ - case -EINVAL: /* Either due to wrong alignment or due to the timeout not - being normalized. 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 (); - } -} - /* Atomically wrt other futex operations on the same futex, this unblocks the specified number of processes, or all processes blocked on this futex if there are fewer than the specified number. Semantically, this is @@ -410,34 +340,6 @@ futex_wake (unsigned int* futex_word, int processes_to_wake, int private) futex. - ETIMEDOUT if the ABSTIME expires. */ -static __always_inline int -futex_lock_pi (unsigned int *futex_word, const struct timespec *abstime, - int private) -{ - int err = lll_futex_timed_lock_pi (futex_word, abstime, private); - 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 (); - } -} - static __always_inline int futex_lock_pi64 (int *futex_word, const struct __timespec64 *abstime, int private) From patchwork Mon Nov 23 19:52:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41160 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 C1BBE3870900; Mon, 23 Nov 2020 19:53:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1BBE3870900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606161187; bh=Tdm6GyWREpFH7smQ9ILJK7hKJVVnNnEW/aKAHF53DzQ=; 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=oC7LOGMJt6buUUgxukyIIyAshJzAvEgzPnP2TCoGrKtk8ThcydTm86lrxTqWENpYq cz5oaZOLUd+xaSbOwGpIcw4YL/xaqXOY6lrjz/2MJv5e22Yzq8yqVccjiUthIbOEc9 moSqDYHO9VmCJJk6t15AfJLTgWK29Ks/KofB2c7I= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by sourceware.org (Postfix) with ESMTPS id B7A8F384A01C for ; Mon, 23 Nov 2020 19:53:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B7A8F384A01C Received: by mail-qk1-x741.google.com with SMTP id v143so18210731qkb.2 for ; Mon, 23 Nov 2020 11:53:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Tdm6GyWREpFH7smQ9ILJK7hKJVVnNnEW/aKAHF53DzQ=; b=lcIu1EvJUopW0I4s3oY0/0c+GWhVVYnMDlhP9RfAQj2ROVIn/8ksRsSbuZ6SO1q3nY GPtjVWfwBS+9dIBRfFfxadChPFeM3ejwbkMuta6vlxGRObvujRC6glydMomTqMNSEkE3 muzpVEi0TJd7CiQCaIQBEW4S7XxLZC+W3klGT1Q2swh5Fx/W8QCIU5PNpA1y3kh7P6wO LCVLIRgVR3vICIC1wy4DqvGOqnMzqJcZilqxz8iJvznAVdigK19QZg9ZmWK9hZxzzkHv y5F6LxWQf0cewlrpBTOe4EsB9vQ1eAZvMSPgyCYpU89Mjb4kkIXxLH3l+CICCijGda9N K3ow== X-Gm-Message-State: AOAM531mH7etNBHVoNMnSYaXj5dL9J1FOat+aLs0GzYithJ4lyB09RWQ 5r+pLxdE2fhsubPM2+g0140scEFFzTjkvw== X-Google-Smtp-Source: ABdhPJyWmsO9tY5p/Gze4mpxuMsvsV5AsxX/xAUzEJcF6GmURTDopFZAvbMSCKL7hELKGsQf2RmezQ== X-Received: by 2002:a37:a185:: with SMTP id k127mr1124514qke.413.1606161184095; Mon, 23 Nov 2020 11:53:04 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v9sm10440432qkv.34.2020.11.23.11.53.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:53:03 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 02/13] nptl: Remove futex_wait_cancelable Date: Mon, 23 Nov 2020 16:52:45 -0300 Message-Id: <20201123195256.3336217-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> References: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Michael Kerrisk Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" It is used solely on __pthread_cond_wait_common and the call can be replaced by a __futex_abstimed_wait_cancelable64 one. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski --- nptl/pthread_cond_wait.c | 22 ++-------------------- sysdeps/nptl/futex-internal.h | 29 ----------------------------- 2 files changed, 2 insertions(+), 49 deletions(-) diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c index 7d158d553f..685dbca32f 100644 --- a/nptl/pthread_cond_wait.c +++ b/nptl/pthread_cond_wait.c @@ -501,26 +501,8 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, cbuffer.private = private; __pthread_cleanup_push (&buffer, __condvar_cleanup_waiting, &cbuffer); - if (abstime == NULL) - { - /* Block without a timeout. */ - err = futex_wait_cancelable ( - cond->__data.__g_signals + g, 0, private); - } - else - { - /* Block, but with a timeout. - Work around the fact that the kernel rejects negative timeout - values despite them being valid. */ - if (__glibc_unlikely (abstime->tv_sec < 0)) - err = ETIMEDOUT; - else - { - err = __futex_abstimed_wait_cancelable64 - (cond->__data.__g_signals + g, 0, clockid, abstime, - private); - } - } + err = __futex_abstimed_wait_cancelable64 ( + cond->__data.__g_signals + g, 0, clockid, abstime, private); __pthread_cleanup_pop (&buffer, 0); diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h index 21e3b74be6..96d1318091 100644 --- a/sysdeps/nptl/futex-internal.h +++ b/sysdeps/nptl/futex-internal.h @@ -177,35 +177,6 @@ futex_wait_simple (unsigned int *futex_word, unsigned int expected, ignore_value (futex_wait (futex_word, expected, private)); } - -/* Like futex_wait but is a POSIX cancellation point. */ -static __always_inline int -futex_wait_cancelable (unsigned int *futex_word, unsigned int expected, - int private) -{ - int oldtype; - oldtype = __pthread_enable_asynccancel (); - int err = lll_futex_timed_wait (futex_word, expected, NULL, private); - __pthread_disable_asynccancel (oldtype); - switch (err) - { - case 0: - case -EAGAIN: - case -EINTR: - return -err; - - case -ETIMEDOUT: /* Cannot have happened as we provided no timeout. */ - case -EFAULT: /* Must have been caused by a glibc or application bug. */ - case -EINVAL: /* Either due to wrong alignment or due to the timeout not - being normalized. 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 (); - } -} - /* Like futex_wait, but will eventually time out (i.e., stop being blocked) after the duration of time provided (i.e., RELTIME) has passed. The caller must provide a normalized RELTIME. RELTIME can also From patchwork Mon Nov 23 19:52:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41161 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 5A653384A01C; Mon, 23 Nov 2020 19:53:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A653384A01C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606161189; bh=7HgRrPI1nI/Xz7OLpLVKyhpB7AQBfUQ9CEzV4Ou54bI=; 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=KRSMjzTjbw9q9D5MuK8WS6h0ZGv48xfLTuqG1Q7LSuSkVObc+6rR5Zedm62njyyrs Q+RTsNue01zp2XYchdCs2Y+Lbk0eI6Yt8BWfupEPfgg6CejrlRvucofoM5kDOG7Nrx I2gnrMGU+eSINXYkCVCHRRP0HUfq+8FPRDAJ7cOM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by sourceware.org (Postfix) with ESMTPS id 8BA59385802D for ; Mon, 23 Nov 2020 19:53:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8BA59385802D Received: by mail-qk1-x744.google.com with SMTP id u4so18170315qkk.10 for ; Mon, 23 Nov 2020 11:53:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7HgRrPI1nI/Xz7OLpLVKyhpB7AQBfUQ9CEzV4Ou54bI=; b=uVnLBV1Stt0PWQwIH4OM1ycX2YQ0tfkVv0m3wnbYgDDZBTOSzZ04mKonqc5Fzxnoca OkidvL0tdazqbynPIiK8kJxys7NmLFUmQE4iS707SNctOf05Vcg9p1FWopdndxEU2Hz/ K4yqhTDPhuESVaURiIhroUpwRyMgrTIABNoRQOCrsZq5/5Nzw1xCNJLGdtnVEgZ+2mCG HlLyhPvECOO4qNeY09lLbnF7kbxjEEzjYGJvDJWZvpM3XV4HoTG8ZivkCMG+Bw2UBpAt 9Kb+R2zZUic4AlWVAME2IwapPW2Vp3MicoKG4rHRNX3GZPtpYImD73voeSlo9pomPwHc Jsjg== X-Gm-Message-State: AOAM532WovyZURRL4kPlq9Us6LfKw2BBFRWI1uKaAB8FS81IWIo01tS9 b4iyMq5ebY75Qcs2LEVVbfOnOtviSPYTwQ== X-Google-Smtp-Source: ABdhPJwZe1X3NZjz1q4HRpyXKZ3NVlJuR5a8VrKcylN+j1KcwS0Rq1yQx3tfyfjKzYGQNjsYMNTH+g== X-Received: by 2002:a37:8d6:: with SMTP id 205mr1131272qki.279.1606161185875; Mon, 23 Nov 2020 11:53:05 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v9sm10440432qkv.34.2020.11.23.11.53.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:53:05 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 03/13] nptl: Remove clockwait_tid Date: Mon, 23 Nov 2020 16:52:46 -0300 Message-Id: <20201123195256.3336217-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> References: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Michael Kerrisk Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" It can be replaced with a __futex_abstimed_wait_cancelable64 call, with the advantage that there is no need to further clock adjustments to create a absolute timeout. It allows to remove the now ununsed futex_timed_wait_cancel64 internal function. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski --- nptl/pthread_join_common.c | 70 ++++++----------------------------- sysdeps/nptl/futex-internal.h | 49 ------------------------ 2 files changed, 12 insertions(+), 107 deletions(-) diff --git a/nptl/pthread_join_common.c b/nptl/pthread_join_common.c index 67d8e2b780..8a95c58ff3 100644 --- a/nptl/pthread_join_common.c +++ b/nptl/pthread_join_common.c @@ -32,55 +32,6 @@ cleanup (void *arg) atomic_compare_exchange_weak_acquire (&arg, &self, NULL); } -/* The kernel notifies a process which uses CLONE_CHILD_CLEARTID via futex - wake-up when the clone terminates. The memory location contains the - thread ID while the clone is running and is reset to zero by the kernel - afterwards. The kernel up to version 3.16.3 does not use the private futex - operations for futex wake-up when the clone terminates. */ -static int -clockwait_tid (pid_t *tidp, clockid_t clockid, - const struct __timespec64 *abstime) -{ - pid_t tid; - int ret; - - if (! valid_nanoseconds (abstime->tv_nsec)) - return EINVAL; - - /* Repeat until thread terminated. */ - while ((tid = *tidp) != 0) - { - struct __timespec64 rt; - - /* Get the current time. This can only fail if clockid is - invalid. */ - if (__glibc_unlikely (__clock_gettime64 (clockid, &rt))) - return EINVAL; - - /* Compute relative timeout. */ - rt.tv_sec = abstime->tv_sec - rt.tv_sec; - rt.tv_nsec = abstime->tv_nsec - rt.tv_nsec; - if (rt.tv_nsec < 0) - { - rt.tv_nsec += 1000000000; - --rt.tv_sec; - } - - /* Already timed out? */ - if (rt.tv_sec < 0) - return ETIMEDOUT; - - /* If *tidp == tid, wait until thread terminates or the wait times out. - The kernel up to version 3.16.3 does not use the private futex - operations for futex wake-up when the clone terminates. */ - ret = futex_timed_wait_cancel64 (tidp, tid, &rt, LLL_SHARED); - if (ret == -ETIMEDOUT || ret == -EOVERFLOW) - return -ret; - } - - return 0; -} - int __pthread_clockjoin_ex (pthread_t threadid, void **thread_return, clockid_t clockid, @@ -137,15 +88,18 @@ __pthread_clockjoin_ex (pthread_t threadid, void **thread_return, un-wait-ed for again. */ pthread_cleanup_push (cleanup, &pd->joinid); - if (abstime != NULL) - result = clockwait_tid (&pd->tid, clockid, abstime); - else - { - pid_t tid; - /* We need acquire MO here so that we synchronize with the - kernel's store to 0 when the clone terminates. (see above) */ - while ((tid = atomic_load_acquire (&pd->tid)) != 0) - lll_futex_wait_cancel (&pd->tid, tid, LLL_SHARED); + /* We need acquire MO here so that we synchronize with the + kernel's store to 0 when the clone terminates. (see above) */ + pid_t tid; + while ((tid = atomic_load_acquire (&pd->tid)) != 0) + { + int ret = __futex_abstimed_wait_cancelable64 ( + (unsigned int *) &pd->tid, tid, clockid, abstime, LLL_SHARED); + if (ret == ETIMEDOUT || ret == EOVERFLOW) + { + result = ret; + break; + } } pthread_cleanup_pop (0); diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h index 96d1318091..d5f13d15fb 100644 --- a/sysdeps/nptl/futex-internal.h +++ b/sysdeps/nptl/futex-internal.h @@ -390,55 +390,6 @@ futex_unlock_pi (unsigned int *futex_word, int private) } } -static __always_inline int -futex_timed_wait_cancel64 (pid_t *tidp, pid_t tid, - const struct __timespec64 *timeout, int private) -{ - int err = INTERNAL_SYSCALL_CANCEL (futex_time64, tidp, - __lll_private_flag (FUTEX_WAIT, private), - tid, timeout); -#ifndef __ASSUME_TIME64_SYSCALLS - if (err == -ENOSYS) - { - if (in_time_t_range (timeout->tv_sec)) - { - struct timespec ts32 = valid_timespec64_to_timespec (*timeout); - - err = INTERNAL_SYSCALL_CANCEL (futex, tidp, - __lll_private_flag (FUTEX_WAIT, - private), - tid, &ts32); - } - else - err = -EOVERFLOW; - } -#endif - switch (err) - { - case 0: - case -EAGAIN: - case -EINTR: - case -ETIMEDOUT: - case -EDEADLK: - case -ENOSYS: - case -EOVERFLOW: /* Passed absolute timeout uses 64 bit time_t type, but - underlying kernel does not support 64 bit time_t futex - syscalls. */ - case -EPERM: /* The caller is not allowed to attach itself to the futex. - Used to check if PI futexes are supported by the - kernel. */ - return -err; - - case -EINVAL: /* Either due to wrong alignment or due to the timeout not - being normalized. Must have been caused by a glibc or - application bug. */ - case -EFAULT: /* Must have been caused by a glibc or application bug. */ - /* No other errors are documented at this time. */ - default: - futex_fatal_error (); - } -} - /* The futex_abstimed_wait_cancelable64 has been moved to a separate file to avoid problems with exhausting available registers on some architectures - e.g. on m68k architecture. */ From patchwork Mon Nov 23 19:52:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41162 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 E08643840C28; Mon, 23 Nov 2020 19:53:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E08643840C28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606161190; bh=tsD0slqr6YvPe0ua52iBE0DIsItAzrpcF6yq+3t0Fn4=; 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=iZd2Zuw4AvZE7jqyKN1AzirZ8mhkgbcCL4xMzZ2Yj1cD9vRVedWqNpWMd8Sa/7apg HsO5O/+CjqT4ai+iMlXllBS6SG4lwp6OgrBd1xmj4++OyUevC4Y1WD28vA4cg2o2Ga fq7UhcidmPF4LbX/jCvy9GLs6SEGDtLUgJ5UsAGM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by sourceware.org (Postfix) with ESMTPS id 40539386EC0B for ; Mon, 23 Nov 2020 19:53:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 40539386EC0B Received: by mail-qk1-x744.google.com with SMTP id q5so18156192qkc.12 for ; Mon, 23 Nov 2020 11:53:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tsD0slqr6YvPe0ua52iBE0DIsItAzrpcF6yq+3t0Fn4=; b=GoJSPSU4ImvqWtjiGrV0Zgkc+mLGGaa9Ou/7jjHf+hJn0lm3rGOefaVNEuw5wZm09I OEIHQDht8bFgRuKi6yTWANttpPT2LWK1DTMmvn3q4kErlRMP7ILuDXg2AkyfZ02SseCj HPdIb6yEGn06dvEVBYe7C93QLu6FIM4vn7dPwvinmgTwYIqqFqDX8rwJ7wJBNGq8m6vv DoviZa1bEgJ9oQDynstbxOv9D0JE9H9bACygq3mu59Gld89nvMjN/QarWxNha6Y7nppi c8O0t+xzxSUg+nU8tcH6pgLvycT8P1hJhceRfUmcnnQn3wJ+osvYPeVVWoHfSjF7L+g0 Kx8Q== X-Gm-Message-State: AOAM533rEwIEutGf2Q05FHRADO5pGJWT6GcODLtR5ABk2RONH1YaHGHw 6wpS6eHgmyXK8CaFdCgIIq8Mz7KoEWuP+A== X-Google-Smtp-Source: ABdhPJzasNv9J42/Y6s5cve6vpil9Ome2lE8wnLpJZMivR6IT57IS0HiVIgX76HcFiYXsfDcjJ9FcQ== X-Received: by 2002:a05:620a:746:: with SMTP id i6mr1195524qki.16.1606161187665; Mon, 23 Nov 2020 11:53:07 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v9sm10440432qkv.34.2020.11.23.11.53.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:53:07 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 04/13] linux: Extend __futex_abstimed_wait_cancelable64 comment Date: Mon, 23 Nov 2020 16:52:47 -0300 Message-Id: <20201123195256.3336217-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> References: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Michael Kerrisk Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" And add a small optimization to avoid setting the operation for the 32-bit time fallback operation. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski --- sysdeps/nptl/futex-internal.c | 8 ++------ sysdeps/nptl/futex-internal.h | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/sysdeps/nptl/futex-internal.c b/sysdeps/nptl/futex-internal.c index 457cd3cd69..e4a14b477c 100644 --- a/sysdeps/nptl/futex-internal.c +++ b/sysdeps/nptl/futex-internal.c @@ -25,7 +25,7 @@ #ifndef __ASSUME_TIME64_SYSCALLS static int __futex_abstimed_wait_cancelable32 (unsigned int* futex_word, - unsigned int expected, clockid_t clockid, + unsigned int expected, int op, const struct __timespec64* abstime, int private) { @@ -39,10 +39,6 @@ __futex_abstimed_wait_cancelable32 (unsigned int* futex_word, pts32 = &ts32; } - unsigned int clockbit = (clockid == CLOCK_REALTIME) - ? FUTEX_CLOCK_REALTIME : 0; - int op = __lll_private_flag (FUTEX_WAIT_BITSET | clockbit, private); - return INTERNAL_SYSCALL_CANCEL (futex, futex_word, op, expected, pts32, NULL /* Unused. */, FUTEX_BITSET_MATCH_ANY); @@ -119,7 +115,7 @@ __futex_abstimed_wait_cancelable64 (unsigned int* futex_word, #ifndef __ASSUME_TIME64_SYSCALLS if (err == -ENOSYS) err = __futex_abstimed_wait_cancelable32 (futex_word, expected, - clockid, abstime, private); + op, abstime, private); #endif switch (err) diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h index d5f13d15fb..cefab74301 100644 --- a/sysdeps/nptl/futex-internal.h +++ b/sysdeps/nptl/futex-internal.h @@ -390,9 +390,21 @@ futex_unlock_pi (unsigned int *futex_word, int private) } } -/* The futex_abstimed_wait_cancelable64 has been moved to a separate file - to avoid problems with exhausting available registers on some architectures - - e.g. on m68k architecture. */ +/* Like futex_wait, but will eventually time out (i.e., stop being blocked) + after the duration of time provided (i.e., ABSTIME) has passed using the + clock specified by CLOCKID (currently only CLOCK_REALTIME and + CLOCK_MONOTONIC, the ones support by lll_futex_supported_clockid). ABSTIME + can also equal NULL, in which case this function behaves equivalent to + futex_wait. + + Returns the same values as futex_wait under those same conditions; + additionally, returns ETIMEDOUT if the timeout expired. + + The call acts a cancellation entrypoint. + + (The implementation has been moved to a separate file to avoid problems + with exhausting available registers on some architectures - e.g. on + m68k). */ int __futex_abstimed_wait_cancelable64 (unsigned int* futex_word, unsigned int expected, clockid_t clockid, From patchwork Mon Nov 23 19:52:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41163 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 02D3F383F84B; Mon, 23 Nov 2020 19:53:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 02D3F383F84B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606161193; bh=uLvxg/EyHWEIP6KCE4UiDz5YjdgA5FknSIsg0TnJomw=; 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=q7Yy9l+Kyxm7Udj9WxZgInrw/Qqp7ma7vdCJgsMZbMm+QUpoqwLNE6klvWKrgMuUR oWQQvnQ8qKNUXIzIkIj75YgGoIb8kC+fBWA0iho0XpeZ1/E3qxIBKxWNUxQHXQ1JjG Af/UiaoSbkbxGAVUbmd+Eu/ejKvYvo/VTTVk/NoQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by sourceware.org (Postfix) with ESMTPS id 1270C3840C22 for ; Mon, 23 Nov 2020 19:53:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1270C3840C22 Received: by mail-qk1-x744.google.com with SMTP id y197so18181210qkb.7 for ; Mon, 23 Nov 2020 11:53:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uLvxg/EyHWEIP6KCE4UiDz5YjdgA5FknSIsg0TnJomw=; b=n2Gras9kXp0VKV3U+UO2JicwbjZfrAeXlUVWViKj7kIjxNSm7LkbwDr+/kvSgeSRDP XU843QzLP6oKfShM4orWRLBUco/HiwFTSxsUGUgJkxy0oUsmY4RXnxhPvRNvkSjEIQuI 91sFVhDgMWnMD7SyRweX/Q0i47ZlR8XNaKOFRbZFCOIAh2QhZYlcBOFhqsSEPnzhyz/d lV0nmxNjdR3APE4td0TGuP9DzmX411bBnf/VdUoBR1v2qFk7/YPftV1bdQ7I1cfYl6ci NtXdr+YBJ3P/mpV4Kcr9n26D8gyMmV+sxDLqpcBRkWFCCtTlVGRjmd3cyVxyg6bVk4Ts uSQw== X-Gm-Message-State: AOAM531X6mAOHJM1wjdJfqtVmPxuA1mlIle2ADIctuc6lXVFUZqb+GCk 36Eca/ltLnmo13aoSP7LxZfEYSG+5l6iZQ== X-Google-Smtp-Source: ABdhPJyOqR5SpTp0V5UfelZ8bZUwOFLj1DbQMp5iNfFujeP6j7at3ksC5t1S8iMOw2u6pfkHC86VIg== X-Received: by 2002:a05:620a:5a5:: with SMTP id q5mr1149406qkq.199.1606161189403; Mon, 23 Nov 2020 11:53:09 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v9sm10440432qkv.34.2020.11.23.11.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:53:09 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 05/13] linux: nptl: Consolidate __futex_abstimed_wait_{cancelable}64 Date: Mon, 23 Nov 2020 16:52:48 -0300 Message-Id: <20201123195256.3336217-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> References: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Michael Kerrisk Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The only different is how to issue the syscall. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski --- sysdeps/nptl/futex-internal.c | 111 +++++++++++----------------------- 1 file changed, 35 insertions(+), 76 deletions(-) diff --git a/sysdeps/nptl/futex-internal.c b/sysdeps/nptl/futex-internal.c index e4a14b477c..f9a2e28ee6 100644 --- a/sysdeps/nptl/futex-internal.c +++ b/sysdeps/nptl/futex-internal.c @@ -24,10 +24,10 @@ #ifndef __ASSUME_TIME64_SYSCALLS static int -__futex_abstimed_wait_cancelable32 (unsigned int* futex_word, - unsigned int expected, int op, - const struct __timespec64* abstime, - int private) +__futex_abstimed_wait_common32 (unsigned int* futex_word, + unsigned int expected, int op, + const struct __timespec64* abstime, + int private, bool cancel) { struct timespec ts32, *pts32 = NULL; if (abstime != NULL) @@ -39,34 +39,16 @@ __futex_abstimed_wait_cancelable32 (unsigned int* futex_word, pts32 = &ts32; } - return INTERNAL_SYSCALL_CANCEL (futex, futex_word, op, expected, + if (cancel) + return INTERNAL_SYSCALL_CANCEL (futex, futex_word, op, expected, + pts32, NULL /* Unused. */, + FUTEX_BITSET_MATCH_ANY); + else + return INTERNAL_SYSCALL_CALL (futex, futex_word, op, expected, pts32, NULL /* Unused. */, FUTEX_BITSET_MATCH_ANY); } -static int -__futex_abstimed_wait32 (unsigned int* futex_word, - unsigned int expected, clockid_t clockid, - const struct __timespec64* abstime, - int private) -{ - struct timespec ts32; - - if (abstime != NULL && ! in_time_t_range (abstime->tv_sec)) - return -EOVERFLOW; - - unsigned int clockbit = (clockid == CLOCK_REALTIME) ? - FUTEX_CLOCK_REALTIME : 0; - int op = __lll_private_flag (FUTEX_WAIT_BITSET | clockbit, private); - - if (abstime != NULL) - ts32 = valid_timespec64_to_timespec (*abstime); - - return INTERNAL_SYSCALL_CALL (futex, futex_word, op, expected, - abstime != NULL ? &ts32 : NULL, - NULL /* Unused. */, FUTEX_BITSET_MATCH_ANY); -} - static int __futex_clock_wait_bitset32 (int *futexp, int val, clockid_t clockid, const struct __timespec64 *abstime, int private) @@ -89,11 +71,11 @@ __futex_clock_wait_bitset32 (int *futexp, int val, clockid_t clockid, } #endif /* ! __ASSUME_TIME64_SYSCALLS */ -int -__futex_abstimed_wait_cancelable64 (unsigned int* futex_word, - unsigned int expected, clockid_t clockid, - const struct __timespec64* abstime, - int private) +static int +__futex_abstimed_wait_common64 (unsigned int* futex_word, + unsigned int expected, clockid_t clockid, + const struct __timespec64* abstime, + int private, bool cancel) { unsigned int clockbit; int err; @@ -109,13 +91,18 @@ __futex_abstimed_wait_cancelable64 (unsigned int* futex_word, clockbit = (clockid == CLOCK_REALTIME) ? FUTEX_CLOCK_REALTIME : 0; int op = __lll_private_flag (FUTEX_WAIT_BITSET | clockbit, private); - err = INTERNAL_SYSCALL_CANCEL (futex_time64, futex_word, op, expected, - abstime, NULL /* Unused. */, + if (cancel) + err = INTERNAL_SYSCALL_CANCEL (futex_time64, futex_word, op, expected, + abstime, NULL /* Unused. */, + FUTEX_BITSET_MATCH_ANY); + else + err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op, expected, + abstime, NULL /* Ununsed. */, FUTEX_BITSET_MATCH_ANY); #ifndef __ASSUME_TIME64_SYSCALLS if (err == -ENOSYS) - err = __futex_abstimed_wait_cancelable32 (futex_word, expected, - op, abstime, private); + err = __futex_abstimed_wait_common32 (futex_word, expected, op, abstime, + private, cancel); #endif switch (err) @@ -145,46 +132,18 @@ __futex_abstimed_wait64 (unsigned int* futex_word, unsigned int expected, clockid_t clockid, const struct __timespec64* abstime, int private) { - unsigned int clockbit; - int err; - - /* Work around the fact that the kernel rejects negative timeout values - despite them being valid. */ - if (__glibc_unlikely ((abstime != NULL) && (abstime->tv_sec < 0))) - return ETIMEDOUT; - - if (! lll_futex_supported_clockid (clockid)) - return EINVAL; - - clockbit = (clockid == CLOCK_REALTIME) ? FUTEX_CLOCK_REALTIME : 0; - int op = __lll_private_flag (FUTEX_WAIT_BITSET | clockbit, private); - - err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op, expected, - abstime, NULL /* Unused. */, - FUTEX_BITSET_MATCH_ANY); -#ifndef __ASSUME_TIME64_SYSCALLS - if (err == -ENOSYS) - err = __futex_abstimed_wait32 (futex_word, expected, - clockid, abstime, private); -#endif - switch (err) - { - case 0: - case -EAGAIN: - case -EINTR: - case -ETIMEDOUT: - return -err; + return __futex_abstimed_wait_common64 (futex_word, expected, clockid, + abstime, private, false); +} - case -EFAULT: /* Must have been caused by a glibc or application bug. */ - case -EINVAL: /* Either due to wrong alignment, unsupported - clockid or due to the timeout not being - normalized. 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 (); - } +int +__futex_abstimed_wait_cancelable64 (unsigned int* futex_word, + unsigned int expected, clockid_t clockid, + const struct __timespec64* abstime, + int private) +{ + return __futex_abstimed_wait_common64 (futex_word, expected, clockid, + abstime, private, true); } int From patchwork Mon Nov 23 19:52:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41164 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 8EBE6383F84D; Mon, 23 Nov 2020 19:53:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EBE6383F84D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606161194; bh=0Mhd3jAkHziuzxTiw9LfVeO4qPUnCZibG2B5JMp7/es=; 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=VHF5E+2Bh4X3uPWdPbi9IjFBlsMxmc3Kvc4df5sXHydn/M0zusFVxe8ozdZ0kTOck dodT6FoSCTx9wj70r9QsOvuraodI2LseSbvQWrdfBIHWekCmlF/J0inMm8MHdU4I2l 5PTRG28apytVHWgZvlIWcSofW1vgyBpY4TRMc3IE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by sourceware.org (Postfix) with ESMTPS id BC9933840C22 for ; Mon, 23 Nov 2020 19:53:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BC9933840C22 Received: by mail-qk1-x744.google.com with SMTP id q5so18156397qkc.12 for ; Mon, 23 Nov 2020 11:53:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0Mhd3jAkHziuzxTiw9LfVeO4qPUnCZibG2B5JMp7/es=; b=b1rsTsCT6V7NKI3CQbzUM1ECEJFTsCTOtb+csARtnbwnydOhmuEBxa1ru6uKTAwwJA aVK/FNlr7arO7p+bRPNCJne1Dj5gLYTLom7TW7MORaqhlz+Peq+sDu258Zp1ZEp8840J bBqcdnL1c6tXdg7BykM0u3QZEcLPMResZNOKMML2p+Sd2+mDG9BorIWtPfOesw1sGj+p EZNoTE1VWfOb/MjU2P6R1rGlzF+P+gS8xHXkiaoPh7bjRif1qcxL2Qaj+F6xbIPHEHKd 38m1iX+YjLhBvql9ySY4FOqTDI+BJ6UYM8njKjznhjtG7kk/OMs79gt+zKvjC3UFXpF0 P5Ow== X-Gm-Message-State: AOAM53345DcHu++CUc5CMUl3OOHDI3nRNMPyfKn7qowaePGbMC1/SR8i Cu1DzXDF58U74laDezTiqcqAfVB5h1LYAQ== X-Google-Smtp-Source: ABdhPJxXbAo8p16yTEftBzy7B+OPQzzoLylt/ydirW4/kjNW2z7t2jKSvUoe5mIT5H+qhsmXO/P0yg== X-Received: by 2002:a37:8d6:: with SMTP id 205mr1131645qki.279.1606161191113; Mon, 23 Nov 2020 11:53:11 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v9sm10440432qkv.34.2020.11.23.11.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:53:10 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 06/13] linux: nptl: Remove _futex_clock_wait_bitset64 Date: Mon, 23 Nov 2020 16:52:49 -0300 Message-Id: <20201123195256.3336217-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> References: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Michael Kerrisk Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" It can be replaced with a __futex_abstimed_wait64 call. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski --- nptl/pthread_mutex_timedlock.c | 7 +++--- sysdeps/nptl/futex-internal.c | 46 ---------------------------------- sysdeps/nptl/futex-internal.h | 5 ---- 3 files changed, 4 insertions(+), 54 deletions(-) diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index de88e9fc25..0ec47359be 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -265,12 +265,13 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex, assume_other_futex_waiters |= FUTEX_WAITERS; /* Block using the futex. */ - int err = __futex_clock_wait_bitset64 (&mutex->__data.__lock, + int err = __futex_abstimed_wait64 ( + (unsigned int *) &mutex->__data.__lock, oldval, clockid, abstime, PTHREAD_ROBUST_MUTEX_PSHARED (mutex)); /* The futex call timed out. */ - if (err == -ETIMEDOUT) - return -err; + if (err == ETIMEDOUT) + return err; /* Reload current lock value. */ oldval = mutex->__data.__lock; } diff --git a/sysdeps/nptl/futex-internal.c b/sysdeps/nptl/futex-internal.c index f9a2e28ee6..30c662547f 100644 --- a/sysdeps/nptl/futex-internal.c +++ b/sysdeps/nptl/futex-internal.c @@ -48,27 +48,6 @@ __futex_abstimed_wait_common32 (unsigned int* futex_word, pts32, NULL /* Unused. */, FUTEX_BITSET_MATCH_ANY); } - -static int -__futex_clock_wait_bitset32 (int *futexp, int val, clockid_t clockid, - const struct __timespec64 *abstime, int private) -{ - struct timespec ts32; - - if (abstime != NULL && ! in_time_t_range (abstime->tv_sec)) - return -EOVERFLOW; - - const unsigned int clockbit = - (clockid == CLOCK_REALTIME) ? FUTEX_CLOCK_REALTIME : 0; - const int op = __lll_private_flag (FUTEX_WAIT_BITSET | clockbit, private); - - if (abstime != NULL) - ts32 = valid_timespec64_to_timespec (*abstime); - - return INTERNAL_SYSCALL_CALL (futex, futexp, op, val, - abstime != NULL ? &ts32 : NULL, - NULL /* Unused. */, FUTEX_BITSET_MATCH_ANY); -} #endif /* ! __ASSUME_TIME64_SYSCALLS */ static int @@ -198,28 +177,3 @@ __futex_clocklock_wait64 (int *futex, int val, clockid_t clockid, return -err; } - -int -__futex_clock_wait_bitset64 (int *futexp, int val, clockid_t clockid, - const struct __timespec64 *abstime, - int private) -{ - int ret; - if (! lll_futex_supported_clockid (clockid)) - { - return -EINVAL; - } - - const unsigned int clockbit = - (clockid == CLOCK_REALTIME) ? FUTEX_CLOCK_REALTIME : 0; - const int op = __lll_private_flag (FUTEX_WAIT_BITSET | clockbit, private); - - ret = INTERNAL_SYSCALL_CALL (futex_time64, futexp, op, val, - abstime, NULL /* Unused. */, - FUTEX_BITSET_MATCH_ANY); -#ifndef __ASSUME_TIME64_SYSCALLS - if (ret == -ENOSYS) - ret = __futex_clock_wait_bitset32 (futexp, val, clockid, abstime, private); -#endif - return ret; -} diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h index cefab74301..dcc7958d59 100644 --- a/sysdeps/nptl/futex-internal.h +++ b/sysdeps/nptl/futex-internal.h @@ -440,9 +440,4 @@ __futex_clocklock64 (int *futex, clockid_t clockid, return err; } -int -__futex_clock_wait_bitset64 (int *futexp, int val, clockid_t clockid, - const struct __timespec64 *abstime, - int private) attribute_hidden; - #endif /* futex-internal.h */ From patchwork Mon Nov 23 19:52:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41165 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 1DBFA383F858; Mon, 23 Nov 2020 19:53:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1DBFA383F858 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606161196; bh=l/sWVLcXP+DlI/UWFuPqyuX4HoEp/lLU5aqEpbq57jo=; 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=tle6wuUnfgrGO0mzPWH0cmy6IVntnof4IgAekffu/ffIoy58CaxFGz93YGs7D4Rls jR0DnduKqIH1+U3K87p2urIvAiBofHOON/Nwvm9iMnkc2hu9ALz14tPHR9JsIy70f/ tzB4xRCos7LOkOHjS5o5L0fgGiDikAAsatbUWhx4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by sourceware.org (Postfix) with ESMTPS id 9E605383F84F for ; Mon, 23 Nov 2020 19:53:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9E605383F84F Received: by mail-qk1-x741.google.com with SMTP id y18so1855243qki.11 for ; Mon, 23 Nov 2020 11:53:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l/sWVLcXP+DlI/UWFuPqyuX4HoEp/lLU5aqEpbq57jo=; b=Mlva+Cn0+ZGY0KD+uWtTvTctiY0DHmnrcQOB3YiLVIXTlrkUM6xKd4xG6QKZTzqX6B O9HkREzHfws+O8asBu+5Pa8bxiCad5v9GuwtqFTDY7NWy/tlJCYlt4bEQfU28x+tYU7Y RYwvnlXeUxotO9xUX6k5Fc8jCFxDyONSf1UWh4QBRAYNWF/bPryy+3gETeK5K6W5GUJO mZCTFeYAiC6o9QWxh17BquvsWjG1FIGMf4PWCvuv477mv4KFicuID6bhVYF97KVS9s1S YsClkkTjNrM6MXNbdSwEOCkgL1hHbAsw2GEL/di3E/uRuym0y/A9TXan4SLJ2s4FwcZx jJMw== X-Gm-Message-State: AOAM532cz3E3f0Qg9/ROG+aJOKVQe3f7HG+b/pDiPKmjWEhqm8O/4gdv ac2iqAUqHe3/9mrHbWubqIiR+DGQ+wy/3Q== X-Google-Smtp-Source: ABdhPJz5k184F3Al1Ge2wsXrCjcYdo9jvboB90G/BxaOufiMYKWCs8AbNJGd49bcRGO8U4mb90N9kQ== X-Received: by 2002:a05:620a:746:: with SMTP id i6mr1195893qki.16.1606161192944; Mon, 23 Nov 2020 11:53:12 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v9sm10440432qkv.34.2020.11.23.11.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:53:12 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 07/13] linux: nptl: Replace __futex_clocklock_wait64 with __futex_abstimed_wait64 Date: Mon, 23 Nov 2020 16:52:50 -0300 Message-Id: <20201123195256.3336217-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> References: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Michael Kerrisk Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The __futex_abstimed_wait64 needs also to return EINVAL syscall errors. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski --- nptl/pthread_mutex_timedlock.c | 4 +-- sysdeps/nptl/futex-internal.c | 57 +--------------------------------- sysdeps/nptl/futex-internal.h | 7 ++--- 3 files changed, 5 insertions(+), 63 deletions(-) diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index 0ec47359be..e643eab258 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -391,8 +391,8 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex, /* Delay the thread until the timeout is reached. Then return ETIMEDOUT. */ do - e = __futex_clocklock_wait64 (&(int){0}, 0, clockid, abstime, - private); + e = __futex_abstimed_wait64 (&(unsigned int){0}, 0, clockid, + abstime, private); while (e != ETIMEDOUT); return ETIMEDOUT; } diff --git a/sysdeps/nptl/futex-internal.c b/sysdeps/nptl/futex-internal.c index 30c662547f..11031cc46a 100644 --- a/sysdeps/nptl/futex-internal.c +++ b/sysdeps/nptl/futex-internal.c @@ -90,15 +90,13 @@ __futex_abstimed_wait_common64 (unsigned int* futex_word, case -EAGAIN: case -EINTR: case -ETIMEDOUT: + case -EINVAL: case -EOVERFLOW: /* Passed absolute timeout uses 64 bit time_t type, but underlying kernel does not support 64 bit time_t futex syscalls. */ return -err; case -EFAULT: /* Must have been caused by a glibc or application bug. */ - case -EINVAL: /* Either due to wrong alignment or due to the timeout not - being normalized. 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: @@ -124,56 +122,3 @@ __futex_abstimed_wait_cancelable64 (unsigned int* futex_word, return __futex_abstimed_wait_common64 (futex_word, expected, clockid, abstime, private, true); } - -int -__futex_clocklock_wait64 (int *futex, int val, clockid_t clockid, - const struct __timespec64 *abstime, int private) -{ - struct __timespec64 ts, *tsp = NULL; - - if (abstime != NULL) - { - /* Reject invalid timeouts. */ - if (! valid_nanoseconds (abstime->tv_nsec)) - return EINVAL; - - /* Get the current time. This can only fail if clockid is not valid. */ - if (__glibc_unlikely (__clock_gettime64 (clockid, &ts) != 0)) - return EINVAL; - - /* Compute relative timeout. */ - ts.tv_sec = abstime->tv_sec - ts.tv_sec; - ts.tv_nsec = abstime->tv_nsec - ts.tv_nsec; - if (ts.tv_nsec < 0) - { - ts.tv_nsec += 1000000000; - --ts.tv_sec; - } - - if (ts.tv_sec < 0) - return ETIMEDOUT; - - tsp = &ts; - } - - int err = INTERNAL_SYSCALL_CALL (futex_time64, futex, - __lll_private_flag (FUTEX_WAIT, private), - val, tsp); -#ifndef __ASSUME_TIME64_SYSCALLS - if (err == -ENOSYS) - { - if (tsp != NULL && ! in_time_t_range (tsp->tv_sec)) - return EOVERFLOW; - - struct timespec ts32; - if (tsp != NULL) - ts32 = valid_timespec64_to_timespec (*tsp); - - err = INTERNAL_SYSCALL_CALL (futex, futex, - __lll_private_flag (FUTEX_WAIT, private), - val, tsp != NULL ? &ts32 : NULL); - } -#endif - - return -err; -} diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h index dcc7958d59..632051278b 100644 --- a/sysdeps/nptl/futex-internal.h +++ b/sysdeps/nptl/futex-internal.h @@ -417,10 +417,6 @@ __futex_abstimed_wait64 (unsigned int* futex_word, unsigned int expected, const struct __timespec64* abstime, int private) attribute_hidden; -int -__futex_clocklock_wait64 (int *futex, int val, clockid_t clockid, - const struct __timespec64 *abstime, - int private) attribute_hidden; static __always_inline int __futex_clocklock64 (int *futex, clockid_t clockid, @@ -432,7 +428,8 @@ __futex_clocklock64 (int *futex, clockid_t clockid, { while (atomic_exchange_acq (futex, 2) != 0) { - err = __futex_clocklock_wait64 (futex, 2, clockid, abstime, private); + err = __futex_abstimed_wait64 ((unsigned int *) futex, 2, clockid, + abstime, private); if (err == EINVAL || err == ETIMEDOUT || err == EOVERFLOW) break; } From patchwork Mon Nov 23 19:52:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41166 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 A43EC383F840; Mon, 23 Nov 2020 19:53:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A43EC383F840 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606161198; bh=m9r8ByyDjFCxxJHNzXbB0OToLdJXk3efTfu/oq8Va+Q=; 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=OkiY+6dabCUaf9AJvn/7tHleguv3sLoK8eIr3rnpA2oVz2Pr7oy/axNCl+Z+zd8gl xViED279HiAXraBKtffDdQQDmPXFdHUsp0NWt27BnjG+hMZFCRIOOvbT6HT1EdDXSx VgKUVH2TT3RPFn5NR7g3sIJoslL6rDXO6jvak3rU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by sourceware.org (Postfix) with ESMTPS id 74503383F84F for ; Mon, 23 Nov 2020 19:53:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 74503383F84F Received: by mail-qt1-x844.google.com with SMTP id z3so14295841qtw.9 for ; Mon, 23 Nov 2020 11:53:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m9r8ByyDjFCxxJHNzXbB0OToLdJXk3efTfu/oq8Va+Q=; b=AMJ/i2ALxPu9fHsgrbHCoOvSMHci6Rj/TxYr7+hVb36PB2TXc/UTP205Z7EEoSfrRf g0lwmUitzzhIF9dym2OuKUiNtpjhqJHGY3HpDVyY+cQcqvaw9UyrcqcgkFLejEx2WMJa VbUYJWnMa8usfRBUiMBAOYSzSAB2pvqTgwgz3G3KIbaFFq6nqG+roTgVBnRhF+mE21T8 YRfeqyCBQz/2a3ZQ1nRdalhy4loJFPTMJmG4vn2ClQFtTodFQMNZnILtLPQB54G1ymOF lguB9jromfL+q8FhJyGDaxtLhIMFTfb/UaDAOR7j5wtmlEoYfMt6UEQZges/Plcs5s4P k+qg== X-Gm-Message-State: AOAM531C6tL0en6q1Yx61HmUElcV3Po3o45W48n0/mbS51FNUXavVd+R H2fH2qlLYC2L5W20r5chGAWLyojC7EhKQg== X-Google-Smtp-Source: ABdhPJxdNTpXTVHJPr0w2EvuLlq9ovat1s8TWaznTQ/q4CVc3XUzQulbURD3kN5brSkL/wW6FOh6XQ== X-Received: by 2002:a05:622a:28b:: with SMTP id z11mr831314qtw.94.1606161194819; Mon, 23 Nov 2020 11:53:14 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v9sm10440432qkv.34.2020.11.23.11.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:53:14 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 08/13] linux: nptl: Replace lll_timedwait with __futex_abstimed_wait64 Date: Mon, 23 Nov 2020 16:52:51 -0300 Message-Id: <20201123195256.3336217-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> References: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Michael Kerrisk Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Checked with x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski --- nptl/Makefile | 1 - nptl/lll_timedlock_wait.c | 62 ------------------------------------- nptl/pthread_mutex_lock.c | 4 +-- sysdeps/nptl/lowlevellock.h | 32 ------------------- 4 files changed, 2 insertions(+), 97 deletions(-) delete mode 100644 nptl/lll_timedlock_wait.c diff --git a/nptl/Makefile b/nptl/Makefile index 74ab758c12..968768d33b 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -147,7 +147,6 @@ libpthread-routines = nptl-init nptlfreeres vars events version pt-interp \ pt-longjmp pt-cleanup\ cancellation \ lowlevellock \ - lll_timedlock_wait \ pt-fork pt-fcntl \ $(pthread-compat-wrappers) \ pt-raise pt-system \ diff --git a/nptl/lll_timedlock_wait.c b/nptl/lll_timedlock_wait.c deleted file mode 100644 index eabdca70c8..0000000000 --- a/nptl/lll_timedlock_wait.c +++ /dev/null @@ -1,62 +0,0 @@ -/* Timed low level locking for pthread library. Generic futex-using version. - Copyright (C) 2003-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Paul Mackerras , 2003. - - 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 - - -int -__lll_clocklock_wait (int *futex, int val, clockid_t clockid, - const struct timespec *abstime, int private) -{ - struct timespec ts, *tsp = NULL; - - if (abstime != NULL) - { - /* Reject invalid timeouts. */ - if (! valid_nanoseconds (abstime->tv_nsec)) - return EINVAL; - - /* Get the current time. This can only fail if clockid is not valid. */ - if (__glibc_unlikely (__clock_gettime (clockid, &ts) != 0)) - return EINVAL; - - /* Compute relative timeout. */ - ts.tv_sec = abstime->tv_sec - ts.tv_sec; - ts.tv_nsec = abstime->tv_nsec - ts.tv_nsec; - if (ts.tv_nsec < 0) - { - ts.tv_nsec += 1000000000; - --ts.tv_sec; - } - - if (ts.tv_sec < 0) - return ETIMEDOUT; - - tsp = &ts; - } - - /* If *futex == val, wait until woken or timeout. */ - lll_futex_timed_wait (futex, val, tsp, private); - - return 0; -} diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c index 0439002454..1f137f6201 100644 --- a/nptl/pthread_mutex_lock.c +++ b/nptl/pthread_mutex_lock.c @@ -425,8 +425,8 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex) /* Delay the thread indefinitely. */ while (1) - lll_timedwait (&(int){0}, 0, 0 /* ignored */, NULL, - private); + __futex_abstimed_wait64 (&(unsigned int){0}, 0, + 0 /* ignored */, NULL, private); } oldval = mutex->__data.__lock; diff --git a/sysdeps/nptl/lowlevellock.h b/sysdeps/nptl/lowlevellock.h index 68b3be8819..3de87d31a9 100644 --- a/sysdeps/nptl/lowlevellock.h +++ b/sysdeps/nptl/lowlevellock.h @@ -122,38 +122,6 @@ extern void __lll_lock_wait (int *futex, int private) attribute_hidden; #define lll_cond_lock(futex, private) __lll_cond_lock (&(futex), private) -extern int __lll_clocklock_wait (int *futex, int val, clockid_t, - const struct timespec *, - int private) attribute_hidden; - -#define lll_timedwait(futex, val, clockid, abstime, private) \ - __lll_clocklock_wait (futex, val, clockid, abstime, private) - -/* As __lll_lock, but with an absolute timeout measured against the clock - specified in CLOCKID. If the timeout occurs then return ETIMEDOUT. If - ABSTIME is invalid, return EINVAL. */ -#define __lll_clocklock(futex, clockid, abstime, private) \ - ({ \ - int *__futex = (futex); \ - int __val = 0; \ - \ - if (__glibc_unlikely \ - (atomic_compare_and_exchange_bool_acq (__futex, 1, 0))) \ - { \ - while (atomic_exchange_acq (futex, 2) != 0) \ - { \ - __val = __lll_clocklock_wait (__futex, 2, clockid, \ - abstime, private); \ - if (__val == EINVAL || __val == ETIMEDOUT) \ - break; \ - } \ - } \ - __val; \ - }) -#define lll_clocklock(futex, clockid, abstime, private) \ - __lll_clocklock (&(futex), clockid, abstime, private) - - /* This is an expression rather than a statement even though its value is void, so that it can be used in a comma expression or as an expression that's cast to void. */ From patchwork Mon Nov 23 19:52:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41167 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 30A48383F861; Mon, 23 Nov 2020 19:53:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30A48383F861 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606161199; bh=VNWLh5f9uLbeGJlhRkHyzAraaGL9uUM69xrEtv83m6c=; 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=VEzdEZqok7qTbScbebtO0EYLJR7xu/YmdSahM4keqzP7hJy17oQeHkOHo6BjTgLi3 0inIpvUqaXb6ku4Oq0ZWEoNVtuwJ0j88ZvhhWwvadUFW956KUJH8B+s4vzGDhsdurT TORwJD6HRQH7Q7gg+4oAytNnaGdSZkIW5CMPz8rc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by sourceware.org (Postfix) with ESMTPS id 2A35C383F84F for ; Mon, 23 Nov 2020 19:53:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2A35C383F84F Received: by mail-qv1-xf41.google.com with SMTP id x13so9409639qvk.8 for ; Mon, 23 Nov 2020 11:53:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VNWLh5f9uLbeGJlhRkHyzAraaGL9uUM69xrEtv83m6c=; b=GHUczlEFZlNHIiER/eNMBf6m1w/+TWyFTu0t/MsRoT1RQ10zLCd8uBcoBLGvQ6ftw7 ELW9Fwzj+Ar3/OXfcDNgWd4lZTcyg4o2jGw5wNb86fJ6qPzl+piJDvtKj/1jbrKGwAJu iwp9WrEuZRU1MWdz2ZzKLAnON/7GqBGaSZSXM05UhaGdsO/1JV1qODp5LDkqeWmBU3XB gDjVLfOHejcjkF1LVxQFYOq/7ohErvOnzXm/kq+4hJ+mg2w1BzMGW1Ag3vHTT6SIX0Il SLZBJMbWmt2aoGpl/rfxe3ZubQJMQIMYP0dxDIHZg37o9rA7rVgoL3iyhPaPxIQmWAXK mQQw== X-Gm-Message-State: AOAM531mu0DTzD39lYF3+1LA/oF30fP6D5WE+M2/DBiej1moDHOLre5V O1DVrHo1KejqiH/OpsdGb7gdnIbYYNE1Lg== X-Google-Smtp-Source: ABdhPJzlLPMwx+V7sPdTa2AA8WXApBcW0WaAWziw/6KUIqDg0f9o4XogB99FgEM7VTTYZ+3G0N7N9w== X-Received: by 2002:ad4:4b01:: with SMTP id r1mr965629qvw.51.1606161196546; Mon, 23 Nov 2020 11:53:16 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v9sm10440432qkv.34.2020.11.23.11.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:53:16 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 09/13] linux: nptl: Replace lll_futex_{timed_}wait by futex-internal.h Date: Mon, 23 Nov 2020 16:52:52 -0300 Message-Id: <20201123195256.3336217-9-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> References: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Michael Kerrisk Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The idea is to make NPTL implementation to use on the functions provided by futex-internal.h. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski --- nptl/lowlevellock.c | 6 +++--- nptl/pthread_mutex_lock.c | 9 +++++---- nptl/pthread_mutex_setprioceiling.c | 5 +++-- nptl/pthread_mutex_timedlock.c | 6 +++--- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/nptl/lowlevellock.c b/nptl/lowlevellock.c index f69547a235..973df4d03a 100644 --- a/nptl/lowlevellock.c +++ b/nptl/lowlevellock.c @@ -18,7 +18,7 @@ . */ #include -#include +#include #include #include @@ -32,7 +32,7 @@ __lll_lock_wait_private (int *futex) { futex: LIBC_PROBE (lll_lock_wait_private, 1, futex); - lll_futex_wait (futex, 2, LLL_PRIVATE); /* Wait if *futex == 2. */ + futex_wait ((unsigned int *) futex, 2, LLL_PRIVATE); /* Wait if *futex == 2. */ } } @@ -49,7 +49,7 @@ __lll_lock_wait (int *futex, int private) { futex: LIBC_PROBE (lll_lock_wait, 1, futex); - lll_futex_wait (futex, 2, private); /* Wait if *futex == 2. */ + futex_wait ((unsigned int *) futex, 2, private); /* Wait if *futex == 2. */ } } #endif diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c index 1f137f6201..965c5a3f4a 100644 --- a/nptl/pthread_mutex_lock.c +++ b/nptl/pthread_mutex_lock.c @@ -307,8 +307,8 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex) assume_other_futex_waiters |= FUTEX_WAITERS; /* Block using the futex and reload current lock value. */ - lll_futex_wait (&mutex->__data.__lock, oldval, - PTHREAD_ROBUST_MUTEX_PSHARED (mutex)); + futex_wait ((unsigned int *) &mutex->__data.__lock, oldval, + PTHREAD_ROBUST_MUTEX_PSHARED (mutex)); oldval = mutex->__data.__lock; } @@ -568,8 +568,9 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex) break; if (oldval != ceilval) - lll_futex_wait (&mutex->__data.__lock, ceilval | 2, - PTHREAD_MUTEX_PSHARED (mutex)); + futex_wait ((unsigned int * ) &mutex->__data.__lock, + ceilval | 2, + PTHREAD_MUTEX_PSHARED (mutex)); } while (atomic_compare_and_exchange_val_acq (&mutex->__data.__lock, ceilval | 2, ceilval) diff --git a/nptl/pthread_mutex_setprioceiling.c b/nptl/pthread_mutex_setprioceiling.c index 521da72622..cbef202579 100644 --- a/nptl/pthread_mutex_setprioceiling.c +++ b/nptl/pthread_mutex_setprioceiling.c @@ -21,6 +21,7 @@ #include #include #include +#include int @@ -84,8 +85,8 @@ pthread_mutex_setprioceiling (pthread_mutex_t *mutex, int prioceiling, break; if (oldval != ceilval) - lll_futex_wait (&mutex->__data.__lock, ceilval | 2, - PTHREAD_MUTEX_PSHARED (mutex)); + futex_wait ((unsigned int *) &mutex->__data.__lock, ceilval | 2, + PTHREAD_MUTEX_PSHARED (mutex)); } while (atomic_compare_and_exchange_val_acq (&mutex->__data.__lock, ceilval | 2, ceilval) diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index e643eab258..343acf6107 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -561,9 +561,9 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex, goto failpp; } - lll_futex_timed_wait (&mutex->__data.__lock, - ceilval | 2, &rt, - PTHREAD_MUTEX_PSHARED (mutex)); + __futex_abstimed_wait64 ( + (unsigned int *) &mutex->__data.__lock, clockid, + ceilval | 2, &rt, PTHREAD_MUTEX_PSHARED (mutex)); } } while (atomic_compare_and_exchange_val_acq (&mutex->__data.__lock, From patchwork Mon Nov 23 19:52:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41168 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 BA7A3383F85D; Mon, 23 Nov 2020 19:53:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA7A3383F85D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606161200; bh=X5N4r5Aqt0CHYAWRMj3IelhhjbpcHRfiIzeHglnkdgo=; 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=GSvK9joobjME7ApdYpWnXVqvfPZc3m4/CXO1UVHPl6AXv1ybGI8dzqRaH3hYzE13T 5cUf6BIXgoVJFUlQtzB4TNQiLLMdrHbJJjt/+tWwKVgnORZnmF7fzTFxsymkG7Gw83 uxZTeZCICfVn0k2lkhtWXSnhHb5ACBM9rG+WnqDk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by sourceware.org (Postfix) with ESMTPS id C5FD1383F85D for ; Mon, 23 Nov 2020 19:53:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C5FD1383F85D Received: by mail-qt1-x844.google.com with SMTP id d5so5279742qtn.0 for ; Mon, 23 Nov 2020 11:53:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X5N4r5Aqt0CHYAWRMj3IelhhjbpcHRfiIzeHglnkdgo=; b=dgDyIv+NEgaUM7LqJFxft0z2XwGaiIVc9RNgaGiTgKfxkKDKkZ3LqfXkdeQkEPms7Y wAr3774kiBnYpWcVjX2oRaBxYd3xPx8pVaORpx4zNpD/GcwhubtFNeM6dVYXcLs/0ZTL QzxTLGtASV9QvwfMuIuf1swDQ8E3ELrNiOTgOEjDJkFQ+K7Nv3NW8Uox9LK5iDbHTN+z 1VaUCokSkoFwWrvhb85GW9RrZwQRvYfClmW4JPIwBMHr8GN1PnQ3FUwgowb3JjtF+CDE XVKC3YLcwEGV/3kaS9XlvfKpgF0KL+XYdfNwY4SSb4lD9N1pC2EmzGL9tCIMfQxkbQg5 4cHg== X-Gm-Message-State: AOAM531gIZxUWAjtjvNLuu56QvVqCSaQbo+pgJ8qTx0E9GW4cMAzTlaT +qJeh5tvugU4L08wmX3KL70Ejyl2b5SJcw== X-Google-Smtp-Source: ABdhPJyyTUSdWfutTDpPpF+4w44nMcSw8scj3Khm09a5fM5vY8dE6VtngbUTDY61B5t+oEGGJXLSOQ== X-Received: by 2002:ac8:6f46:: with SMTP id n6mr799018qtv.151.1606161198266; Mon, 23 Nov 2020 11:53:18 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v9sm10440432qkv.34.2020.11.23.11.53.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:53:17 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 10/13] linux: nptl: Replace lll_futex_supported_clockid with futex-internal.h Date: Mon, 23 Nov 2020 16:52:53 -0300 Message-Id: <20201123195256.3336217-10-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> References: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Michael Kerrisk Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The idea is to make NPTL implementation to use on the functions provided by futex-internal.h. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski --- nptl/pthread_mutex_timedlock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index 343acf6107..b42862193a 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -600,7 +600,7 @@ __pthread_mutex_clocklock64 (pthread_mutex_t *mutex, clockid_t clockid, const struct __timespec64 *abstime) { - if (__glibc_unlikely (!lll_futex_supported_clockid (clockid))) + if (__glibc_unlikely (!futex_abstimed_supported_clockid (clockid))) return EINVAL; LIBC_PROBE (mutex_clocklock_entry, 3, mutex, clockid, abstime); From patchwork Mon Nov 23 19:52:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41169 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 D906D383E804; Mon, 23 Nov 2020 19:53:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D906D383E804 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606161203; bh=i3WqhNI8F6Sb1F46OAhb+6YGFX0ySByejmmN+BbrTKw=; 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=ZpKNb3KgHkDC+j97szH4Q9XIiiDyCakYb54sCm1bU/rg/ETIcEyL0lm3WgZHlcs9u AqValWXx4W9fPIVBVhf/4UE1dC7sqsZejJZVF0GtcStdBvU1Dp305es+XkqhW3p+f4 CC1pp/HfsnGVfVd5Szoa3CYZjx6B6qI8diHV+mVo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by sourceware.org (Postfix) with ESMTPS id F3DFA383F86C for ; Mon, 23 Nov 2020 19:53:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F3DFA383F86C Received: by mail-qk1-x741.google.com with SMTP id y18so1855679qki.11 for ; Mon, 23 Nov 2020 11:53:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i3WqhNI8F6Sb1F46OAhb+6YGFX0ySByejmmN+BbrTKw=; b=nxUSwda5+pQorynlfwqIf0Wj8AHvZoSu+V3r3L6YP/AdKZGgCFSwYKGPmR0lUq2wdR 6EN+wcp65knp8gSOZSGkA/Vj/ZvrYe5lPhTElTb0d2V7PrcKA+xEg9oJUq08vYY6f493 M9EmMkiQqhctWc5HzcwHfYdjXBMkOtwxxqkJnLUh2yzaI3qS0a9UZckGlY9sDqbsx8z9 HMz7W6M7O2lKj4A9/lEdCcf9Jcx2wX3gw+HZowHJshISqvBO9J5O/B74qkrmbCU4nIVv RqH/4nlv2GaAii52BcxJLutN5MccH/2luWEozbEc8+QyjQyAc8hFydqwiMScDdDIzhF/ b2ew== X-Gm-Message-State: AOAM533bOE6VE3zHp6DUI6q1cQhCb9jSQB7dTLpp0LDlYg8/ByCQwkpK dBHKRJthRAmT4zLLiUOk+oVOHpxHhRCNdw== X-Google-Smtp-Source: ABdhPJxm6KVO9LK+vMGtjLGpKPsh54+VXAj4+W96ZgNo5S4wewuJ8zgFKtXkWukrs7Xa4gG9iYkL5A== X-Received: by 2002:a37:4816:: with SMTP id v22mr1235054qka.42.1606161200407; Mon, 23 Nov 2020 11:53:20 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v9sm10440432qkv.34.2020.11.23.11.53.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:53:19 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 11/13] nptl: Replace lll_futex_wake with futex-internal.h Date: Mon, 23 Nov 2020 16:52:54 -0300 Message-Id: <20201123195256.3336217-11-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> References: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Michael Kerrisk Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The idea is to make NPTL implementation to use on the functions provided by futex-internal.h. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski --- nptl/pthread_mutex_setprioceiling.c | 4 ++-- nptl/pthread_mutex_unlock.c | 6 +++--- nptl/sem_post.c | 9 ++------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/nptl/pthread_mutex_setprioceiling.c b/nptl/pthread_mutex_setprioceiling.c index cbef202579..8f1d6e1326 100644 --- a/nptl/pthread_mutex_setprioceiling.c +++ b/nptl/pthread_mutex_setprioceiling.c @@ -116,8 +116,8 @@ pthread_mutex_setprioceiling (pthread_mutex_t *mutex, int prioceiling, | (prioceiling << PTHREAD_MUTEX_PRIO_CEILING_SHIFT); atomic_full_barrier (); - lll_futex_wake (&mutex->__data.__lock, INT_MAX, - PTHREAD_MUTEX_PSHARED (mutex)); + futex_wake ((unsigned int *)&mutex->__data.__lock, INT_MAX, + PTHREAD_MUTEX_PSHARED (mutex)); return 0; } diff --git a/nptl/pthread_mutex_unlock.c b/nptl/pthread_mutex_unlock.c index 2b4abb8ebe..56f1732e6d 100644 --- a/nptl/pthread_mutex_unlock.c +++ b/nptl/pthread_mutex_unlock.c @@ -162,7 +162,7 @@ __pthread_mutex_unlock_full (pthread_mutex_t *mutex, int decr) private = PTHREAD_ROBUST_MUTEX_PSHARED (mutex); if (__glibc_unlikely ((atomic_exchange_rel (&mutex->__data.__lock, 0) & FUTEX_WAITERS) != 0)) - lll_futex_wake (&mutex->__data.__lock, 1, private); + futex_wake ((unsigned int *) &mutex->__data.__lock, 1, private); /* We must clear op_pending after we release the mutex. FIXME However, this violates the mutex destruction requirements @@ -332,8 +332,8 @@ __pthread_mutex_unlock_full (pthread_mutex_t *mutex, int decr) &oldval, newval)); if ((oldval & ~PTHREAD_MUTEX_PRIO_CEILING_MASK) > 1) - lll_futex_wake (&mutex->__data.__lock, 1, - PTHREAD_MUTEX_PSHARED (mutex)); + futex_wake ((unsigned int *)&mutex->__data.__lock, 1, + PTHREAD_MUTEX_PSHARED (mutex)); int oldprio = newval >> PTHREAD_MUTEX_PRIO_CEILING_SHIFT; diff --git a/nptl/sem_post.c b/nptl/sem_post.c index 88cfc24b30..5dbfb3a214 100644 --- a/nptl/sem_post.c +++ b/nptl/sem_post.c @@ -84,19 +84,14 @@ int attribute_compat_text_section __old_sem_post (sem_t *sem) { - int *futex = (int *) sem; + unsigned int *futex = (unsigned int *) sem; /* We must need to synchronize with consumers of this token, so the atomic increment must have release MO semantics. */ atomic_write_barrier (); (void) atomic_increment_val (futex); /* We always have to assume it is a shared semaphore. */ - int err = lll_futex_wake (futex, 1, LLL_SHARED); - if (__builtin_expect (err, 0) < 0) - { - __set_errno (-err); - return -1; - } + futex_wake (futex, 1, LLL_SHARED); return 0; } compat_symbol (libpthread, __old_sem_post, sem_post, GLIBC_2_0); From patchwork Mon Nov 23 19:52:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41170 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 69779383E800; Mon, 23 Nov 2020 19:53:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 69779383E800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606161205; bh=cDn++xrhCF7PhS8rXAeI/EV74wwLAadcDS5mZw6MrH8=; 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=OBkJa+vT3lmM/VR1O6vjYMULEMf4BuWNKqJsOiUVT0GnaIttXQvodOAfKrDQYmYM7 J0Sx2tppZ8M7kqK3lStbnQuTE9qfli2ScnFw917bfv1tEo6tJ6EyWNNINeNtxjlDEb CXtYU+tjDMVAWvYGm2DFhUTbIQcZiMRgu+Anl68E= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by sourceware.org (Postfix) with ESMTPS id C4146383F86C for ; Mon, 23 Nov 2020 19:53:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C4146383F86C Received: by mail-qk1-x742.google.com with SMTP id d9so18175772qke.8 for ; Mon, 23 Nov 2020 11:53:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cDn++xrhCF7PhS8rXAeI/EV74wwLAadcDS5mZw6MrH8=; b=solafm1tUn4h4FO0f+1bcUFcU9N3Xe8ujBc38NGq/HPxe0Tbd03Tb1/7kXHEBFl4MF O5AZRtBPHAWFjEoFEwCtA6lukSYhfqEvkOrcJuge0guv50Pe4HcB8++ErNytHizHn3c+ cbdn3xmgCJyj/G4iQwC3DtzXevEyWKVErS5S+hZW0hXAV+ENThw79m7VKM/CsKNDphXF t6+Ikc8wFzIT3yv8thPTuEUmXvD89PVOutgJ4oiFaLvaQtxhIPZFdkYNL2BYA7s6qmpt 5hOgrwnGd4GtP/CS6r4iY3S5Dgq0T7HEwWGwlQdSfoGC/cxzNSVFzzpDiYbjz70K+wrB eHEw== X-Gm-Message-State: AOAM5318XRe4jpIGVlhDH+d68tVFP+8cllkInXA1np0/3kiXMoWUKGTF gWpGZ9rp0Da4ZKWC1qkAJLY4L2lwz5m0sg== X-Google-Smtp-Source: ABdhPJz6n7Ow+EP6B3w/WcKD3csu3s+iMbFetX+yI9ovV7LubodhH22A1jONz2VWD5ZmWpAEOOb02g== X-Received: by 2002:a05:620a:15a8:: with SMTP id f8mr1222240qkk.346.1606161202157; Mon, 23 Nov 2020 11:53:22 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v9sm10440432qkv.34.2020.11.23.11.53.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:53:21 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v2 12/13] nptl: Return EINVAL for pthread_mutex_clocklock/PI with CLOCK_MONOTONIC [BZ #26801] Date: Mon, 23 Nov 2020 16:52:55 -0300 Message-Id: <20201123195256.3336217-12-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> References: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Michael Kerrisk Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Changes from previous version: - Replace ENOTSUP by EINVAL Reviewed-by: Lukasz Majewski Reviewed-by: Lukasz Majewski --- Linux futex FUTEX_LOCK_PI operation only supports CLOCK_REALTIME, so pthread_mutex_clocklock operation with priority aware mutexes may fail depending of the input timeout. Also, it is not possible to convert a CLOCK_MONOTONIC to a CLOCK_REALTIME due the possible wall clock time change which might invalid the requested timeout. Checked on x86_64-linux-gnu and i686-linux-gnu. --- nptl/Makefile | 2 +- nptl/pthread_mutex_timedlock.c | 7 ++++ nptl/tst-mutexpi10.c | 68 ++++++++++++++++++++++++++++++++++ sysdeps/pthread/tst-mutex5.c | 2 + sysdeps/pthread/tst-mutex9.c | 2 + 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 nptl/tst-mutexpi10.c diff --git a/nptl/Makefile b/nptl/Makefile index 968768d33b..a48426a396 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -265,7 +265,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-mutexpi9 tst-mutexpi10 \ tst-cond22 tst-cond26 \ tst-robustpi1 tst-robustpi2 tst-robustpi3 tst-robustpi4 tst-robustpi5 \ tst-robustpi6 tst-robustpi7 tst-robustpi9 \ diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index b42862193a..aaaafa21ce 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -313,6 +313,13 @@ __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 diff --git a/nptl/tst-mutexpi10.c b/nptl/tst-mutexpi10.c new file mode 100644 index 0000000000..84ba1dfa97 --- /dev/null +++ b/nptl/tst-mutexpi10.c @@ -0,0 +1,68 @@ +/* Check if pthread_mutex_clocklock with PRIO_INHERIT fails with clock + different than CLOCK_REALTIME. + Copyright (C) 2015-2020 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 diff --git a/sysdeps/pthread/tst-mutex5.c b/sysdeps/pthread/tst-mutex5.c index 14490768c3..bfe1a79fa4 100644 --- a/sysdeps/pthread/tst-mutex5.c +++ b/sysdeps/pthread/tst-mutex5.c @@ -112,7 +112,9 @@ 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; } diff --git a/sysdeps/pthread/tst-mutex9.c b/sysdeps/pthread/tst-mutex9.c index 2d7927b7c2..bfc01f8c75 100644 --- a/sysdeps/pthread/tst-mutex9.c +++ b/sysdeps/pthread/tst-mutex9.c @@ -133,7 +133,9 @@ 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; } From patchwork Mon Nov 23 19:52:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41171 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 F37D1383F841; Mon, 23 Nov 2020 19:53:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F37D1383F841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606161208; bh=HU96DbSUu+nrkwaiKnYH3RcFgWf2fa3SzX/2yTGJOCQ=; 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=XSmh3pljundEwhrooJ/FXXwHG1XsApv0/Vk86UQcssYDB17BWBRgKYWS/I8OCwsHB EVTuJ3AofqBjn9Bq/jEppDjI6hJet2h7NAZameANddmXKvxrM2ioxFFQ/XLTZnxgH9 xLlhBNMswwNNXnQbkvOvlyRXvaxJ1gINTYUKkH7g= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by sourceware.org (Postfix) with ESMTPS id 05A31383F86C for ; Mon, 23 Nov 2020 19:53:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 05A31383F86C Received: by mail-qt1-x841.google.com with SMTP id f15so10808671qto.13 for ; Mon, 23 Nov 2020 11:53:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HU96DbSUu+nrkwaiKnYH3RcFgWf2fa3SzX/2yTGJOCQ=; b=NXcPGMkLqQzIjoRCHh1eTK1CCe6YkT0kD4DKoxi2QgWCVSfY9zHRSw9mzbODDkNCW2 d89mbKxf0xzSX2wUBLv32yg1Jb3gERrs1cvLqBsZ7Xbrh8it7spNTa6KXSHuPJq2y+I+ Z07XTOlpWd/8v0KtUB6ibZ2L4OmZ/cvIBpXXHrqQ6bN5ROc1krrHVnXQ6Z3olPJiyczG eFUyYi+78nKgc+qL34enJ94Ymnr2m3gr0+4PwFXo/s9cDFvO03oJutav6++NsdDONkRu hbpNsC/WIXnRh2fKeMZObsz+8wa2t1KzbcJSnkbzWRF/pJbFVmGC4jda/qs6UcyUTCJb qvUg== X-Gm-Message-State: AOAM5314nxFPoF0fqfWUWtHkvuSLDM045h5XReyp4lNN25PMXQKR3Bxb ixGLqfeoSMQoZeDcRUnldV9jB2UouHC2iA== X-Google-Smtp-Source: ABdhPJwd/pyOUv7+keOj72GO1Hf4CnbwPvY1+Ii/AataiclPIzKtxT+4pyaO8gaoCapsZjL0bEZEOg== X-Received: by 2002:a05:622a:d1:: with SMTP id p17mr806844qtw.233.1606161204308; Mon, 23 Nov 2020 11:53:24 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v9sm10440432qkv.34.2020.11.23.11.53.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:53:23 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 13/13] linux: Return EINVAL for invalid clock for pthread_clockjoin_np Date: Mon, 23 Nov 2020 16:52:56 -0300 Message-Id: <20201123195256.3336217-13-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> References: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Michael Kerrisk Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The align the GNU extension with the others one that accept specify which clock to wait for (such as pthread_mutex_clocklock). Check on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski Tested-by: Lukasz Majewski --- nptl/pthread_clockjoin.c | 4 ++ sysdeps/pthread/Makefile | 2 +- sysdeps/pthread/tst-join15.c | 80 ++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 sysdeps/pthread/tst-join15.c diff --git a/nptl/pthread_clockjoin.c b/nptl/pthread_clockjoin.c index 0baba1e83d..3d54fe588f 100644 --- a/nptl/pthread_clockjoin.c +++ b/nptl/pthread_clockjoin.c @@ -17,12 +17,16 @@ . */ #include +#include #include "pthreadP.h" int __pthread_clockjoin_np64 (pthread_t threadid, void **thread_return, clockid_t clockid, const struct __timespec64 *abstime) { + if (!futex_abstimed_supported_clockid (clockid)) + return EINVAL; + return __pthread_clockjoin_ex (threadid, thread_return, clockid, abstime, true); } diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile index 45a15b0b1a..8f335c13b5 100644 --- a/sysdeps/pthread/Makefile +++ b/sysdeps/pthread/Makefile @@ -77,7 +77,7 @@ tests += tst-cnd-basic tst-mtx-trylock tst-cnd-broadcast \ tst-getpid3 \ tst-join1 tst-join2 tst-join3 tst-join4 tst-join5 tst-join6 tst-join7 \ tst-join8 tst-join9 tst-join10 tst-join11 tst-join12 tst-join13 \ - tst-join14 \ + tst-join14 tst-join15 \ tst-key1 tst-key2 tst-key3 tst-key4 \ tst-kill1 tst-kill2 tst-kill3 tst-kill4 tst-kill5 tst-kill6 \ tst-locale1 tst-locale2 \ diff --git a/sysdeps/pthread/tst-join15.c b/sysdeps/pthread/tst-join15.c new file mode 100644 index 0000000000..4ed767e733 --- /dev/null +++ b/sysdeps/pthread/tst-join15.c @@ -0,0 +1,80 @@ +/* Check pthread_clockjoin_np clock support. + Copyright (C) 2020 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 +#include +#include + +static void * +tf (void *arg) +{ + pause (); + return NULL; +} + + +static int +do_test (void) +{ + const clockid_t clocks[] = { + CLOCK_REALTIME, + CLOCK_MONOTONIC, + CLOCK_PROCESS_CPUTIME_ID, + CLOCK_THREAD_CPUTIME_ID, + CLOCK_THREAD_CPUTIME_ID, + CLOCK_MONOTONIC_RAW, + CLOCK_REALTIME_COARSE, + CLOCK_MONOTONIC_COARSE, +#ifdef CLOCK_BOOTTIME + CLOCK_BOOTTIME, +#endif +#ifdef CLOCK_REALTIME_ALARM + CLOCK_REALTIME_ALARM, +#endif +#ifdef CLOCK_BOOTTIME_ALARM + CLOCK_BOOTTIME_ALARM, +#endif +#ifdef CLOCK_TAI + CLOCK_TAI +#endif + }; + + pthread_t thr = xpthread_create (NULL, tf, NULL); + + for (int t = 0; t < array_length (clocks); t++) + { + /* A valid timeout so valid clock timeout. */ + struct timespec tmo = timespec_add (xclock_now (clocks[t]), + make_timespec (0, 100000000)); + + int ret = clocks[t] == CLOCK_REALTIME || clocks[t] == CLOCK_MONOTONIC + ? ETIMEDOUT : EINVAL; + + TEST_COMPARE (pthread_clockjoin_np (thr, NULL, clocks[t], &tmo), ret); + } + + return 0; +} + +#include