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; }