From patchwork Thu Oct 29 19:42:07 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: 40927 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 CAF1B386F43B; Thu, 29 Oct 2020 19:42:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CAF1B386F43B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1604000536; bh=+ZFz9pjVjgDlViyvGWAoGUGuPnurtOfOdrb7nu16V48=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=K7hMhzOJkVRPvMpOV8zdllaoYtZysPnVbbXw2Lw06SZxzrwV+EqiepZwTOXyOR3Rg JJaD5mf+ZiKWJdixS4T7m4JgkCTmCwFQbWZfCnHAJfmBW+HpPwmTdWZ4GQt6B8FeiA kRY09jYsjyVcvEJHZzbzw6vC5SM/H5Fvg324pC+I= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by sourceware.org (Postfix) with ESMTPS id 8DCA83858020 for ; Thu, 29 Oct 2020 19:42:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8DCA83858020 Received: by mail-qk1-x743.google.com with SMTP id a65so767054qkg.13 for ; Thu, 29 Oct 2020 12:42:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=+ZFz9pjVjgDlViyvGWAoGUGuPnurtOfOdrb7nu16V48=; b=P3d9DpYBDIVrEqm8m28Z0/gCprQQA31BvOSQhApGvWi/Q1rYnymgJsU1VTVsf5G8jk YbTI2yQh3jc+o1RE86hIjmBubXdiCcZ+yDQkgMV77ul+YO/5XAC9ApMRzZxSVz71as4O ivuEJJtcZRUuqHKfzggGb8CkdeW2ue6k/Z/Ax+UGrlY7IlX+I42vXuzjyuw/Xitpu+0x UIzVqWBFg7U6Bf2EIm0SMXhfv2ipYeYQEgjfIPKqzug6cqw0oAEY6uXJP1Rx2Dj/bQh9 g2qqWfnhbpjhaVNV9DKnqMbUYH8htqQ3i/1uZ0v8pRIIcf066Istm74Vs1Tv/A+so8pD ap+g== X-Gm-Message-State: AOAM532ikV7Iay9VKGOEXg88Uyx/elkZKViEPwIF+oClr6wocTmH4+Gr iw/sSZKXYCpRKgTcBcuBRfI6Ib1A8tARfQ== X-Google-Smtp-Source: ABdhPJw8mxCEh8zEugPTz0smQ/JzQfyLUMhmEWWc6W7+82qCH5p8mdTdfuqad9Cr9Ofd6ihTyq07lw== X-Received: by 2002:a37:e20d:: with SMTP id g13mr5290118qki.325.1604000533748; Thu, 29 Oct 2020 12:42:13 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v65sm1656433qkb.88.2020.10.29.12.42.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 12:42:13 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 1/2] nptl: Replace futex_lock_pi with __futex_lock_pi64 Date: Thu, 29 Oct 2020 16:42:07 -0300 Message-Id: <20201029194208.2715606-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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 Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" And also move __futex_lock_pi64 to futex-internal.c, it decreases the libpthread code since there is no much gain in optimizing the slow path. Checked on x86_64-linux-gnu and i686-linux-gnu. --- nptl/pthread_mutex_lock.c | 3 +- nptl/pthread_mutex_timedlock.c | 2 +- sysdeps/nptl/futex-internal.c | 45 +++++++++++++++++++++ sysdeps/nptl/futex-internal.h | 74 +--------------------------------- 4 files changed, 49 insertions(+), 75 deletions(-) diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c index 7858abd528..8b6bf45795 100644 --- a/nptl/pthread_mutex_lock.c +++ b/nptl/pthread_mutex_lock.c @@ -416,8 +416,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/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index fe9e651f6c..d839e6862f 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -378,7 +378,7 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex, int private = (robust ? PTHREAD_ROBUST_MUTEX_PSHARED (mutex) : PTHREAD_MUTEX_PSHARED (mutex)); - int e = futex_lock_pi64 (&mutex->__data.__lock, abstime, private); + int e = __futex_lock_pi64 (&mutex->__data.__lock, abstime, private); if (e == ETIMEDOUT) return ETIMEDOUT; else if (e == ESRCH || e == EDEADLK) diff --git a/sysdeps/nptl/futex-internal.c b/sysdeps/nptl/futex-internal.c index 457cd3cd69..87de7e2fac 100644 --- a/sysdeps/nptl/futex-internal.c +++ b/sysdeps/nptl/futex-internal.c @@ -268,3 +268,48 @@ __futex_clock_wait_bitset64 (int *futexp, int val, clockid_t clockid, #endif return ret; } + +int +__futex_lock_pi64 (int *futex_word, const struct __timespec64 *abstime, + int private) +{ + int err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, + __lll_private_flag + (FUTEX_LOCK_PI, private), 0, abstime); +#ifndef __ASSUME_TIME64_SYSCALLS + if (err == -ENOSYS) + { + if (abstime != NULL && ! in_time_t_range (abstime->tv_sec)) + return EOVERFLOW; + + struct timespec ts32; + if (abstime != NULL) + ts32 = valid_timespec64_to_timespec (*abstime); + + err = INTERNAL_SYSCALL_CALL (futex, futex_word, __lll_private_flag + (FUTEX_LOCK_PI, private), 0, + abstime != NULL ? &ts32 : NULL); + } +#endif + 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 (); + } +} diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h index cd356e4fa8..f0e3c1458a 100644 --- a/sysdeps/nptl/futex-internal.h +++ b/sysdeps/nptl/futex-internal.h @@ -409,78 +409,8 @@ 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) -{ - int err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, - __lll_private_flag - (FUTEX_LOCK_PI, private), 0, abstime); -#ifndef __ASSUME_TIME64_SYSCALLS - if (err == -ENOSYS) - { - if (abstime != NULL && ! in_time_t_range (abstime->tv_sec)) - return EOVERFLOW; - - struct timespec ts32; - if (abstime != NULL) - ts32 = valid_timespec64_to_timespec (*abstime); - - err = INTERNAL_SYSCALL_CALL (futex, futex_word, __lll_private_flag - (FUTEX_LOCK_PI, private), 0, - abstime != NULL ? &ts32 : NULL); - } -#endif - 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 (); - } -} +int __futex_lock_pi64 (int *futex_word, const struct __timespec64 *abstime, + int private) attribute_hidden; /* Wakes the top priority waiter that called a futex_lock_pi operation on the futex.