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. */