From patchwork Thu Feb 28 17:21:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 159404 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp900765jad; Thu, 28 Feb 2019 09:21:31 -0800 (PST) X-Google-Smtp-Source: APXvYqwPcXyT1diA7s4YMh2UYdC/Y02jfr5P/gP7hOIWWgeR21A8BfIHZCzJ5uaoV3ghQIyhSs3l X-Received: by 2002:a17:902:bd96:: with SMTP id q22mr449467pls.7.1551374491841; Thu, 28 Feb 2019 09:21:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551374491; cv=none; d=google.com; s=arc-20160816; b=DSTid7vnvLJ8pTkq1IdouivSC8sDIpdkdUGeF4UYGVxP8/6GPXFCzsoPnbMvIPCuLs 8m1d35+XOHpmmRZXSsBM6nelx3pO09Akk6Phma1Ud5FqhD2AU5Ys6zTysOVMa8PVbltH SwnODKjvsumrO0vzBKlQ8HBSfzd6JcbCiRCEfFrbd+PJs1ZL1OLrGj3aVWhBUoXdu/T0 fl2oUy6/b05Du7xwV4TB5buAzQCC/9RDq/iuHJ+3Ugm6Boc+71f6RBRp3LAtccwjgSE9 JFXQl+bjw8VWFDXru+rimU9Pls0yH7T+hf2c60i5bYtokx0bgNnSk/bcJ6i57XsvEwvM +eSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:dkim-signature:delivered-to:sender :list-help:list-post:list-archive:list-subscribe:list-unsubscribe :list-id:precedence:mailing-list:dkim-signature:domainkey-signature; bh=ImmU6TZl5KqVRnb8aU9O8sG8OSsxNefQKMJiJCUjjz4=; b=V57WXPnLkdl3/pTPIE62x3zqlJJvMKjuy/qqGs8+ZWMPYa9T0gTKXwku9+gcFwQ5iM kFGMCMrL/rfGoPvvCV3to57QM9h4zYAI/OuoA5ih1qVWauZ64ONMg/QQQ9vfhK9qnxrr muTVoazDdzDr8ZZU/TsaNPmE/WnfLF/aKVDDW+lAiF9f69Pb4XB10yWd9SEAGqqw03HX uy1GU6cTQ0a0A/e43UmgZR0I2ATso3zUua5DxWXsimkUQpr72mFhjL/vTAlm9p4NBCLA 0w/KkplnUlQCMCUOmJfZzKmkhZvP8E6WZJdVDjK8uh/lMya9TwI8MR3I7Gg9zDta2fXG WT6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=vBlSA01v; dkim=pass header.i=@linaro.org header.s=google header.b=Ef+A19+6; spf=pass (google.com: domain of libc-alpha-return-100327-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-100327-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id h66si1327198pgc.537.2019.02.28.09.21.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 09:21:31 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-100327-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=vBlSA01v; dkim=pass header.i=@linaro.org header.s=google header.b=Ef+A19+6; spf=pass (google.com: domain of libc-alpha-return-100327-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-100327-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=UF48CsQ2zcFdNHZ1W1KYAQU168FQBSkmZ1uR/T03Mjw9xUyzyuc0+ pKgws6ICqcYUwV8w6HBoL57K1Dh02oGZ1MA340q7lG4sSe42thvfllTU9phfkJr1 x2OByRa5vtLBtZv7EsNrhB4rMQGycnKI4gb4V2uMUoQtgeS0MMX2kA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=pwCMqu2kXSvWlF5HxfJN72RfpCg=; b=vBlSA01vogtaAWneBnIG87mGkaqt xG+0hTW3IKd0qG6jwozQMXR1+09zUeRqN5NNgRsHguKf+MXSA8fhtp2pz4e3h9GF /kWLtZhbOBSaxjzxwyMq+NjV9R2D1uQf1+GPhPdjqhuRKgLIxFr37s0gHvSy+V7N g4g686vOnh5vqpA= Received: (qmail 76247 invoked by alias); 28 Feb 2019 17:21:20 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 76237 invoked by uid 89); 28 Feb 2019 17:21:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, LOTS_OF_MONEY, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=$1000 X-HELO: mail-qt1-f196.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id; bh=ImmU6TZl5KqVRnb8aU9O8sG8OSsxNefQKMJiJCUjjz4=; b=Ef+A19+6L9eOTbnHTR1PSo0FtNv3Kp8qNBIQnOw69HxLpXvdphzrOyiRNt78yt1kLO EaecOPTPWRJGcSb8MX0s1adJ17b/9YXmQJZS2Udy4AgGBhRjPhqSgqsrbgjCo9H+8C3g zB4LX1qEjn3yGwe24ZV0xUwItGT9vS4OF1W0TbzLoHR1Su9LsSlEyxpT4cKuLuLAJL2S fGs1+hqy6/L+ZutrekAYLKBGV3l5LgYgpnxLSCKEWqokRjSXt3ng3R7xPv5Dfd/cRUWL nwnTKpLNRpgfHEFdNd+uM33yiAJv6b31+yqlwhjwjDBLdO1pqlfGxelYzyz4Ndg/inO2 l4YQ== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] nptl: Assume __ASSUME_FUTEX_CLOCK_REALTIME support Date: Thu, 28 Feb 2019 14:21:10 -0300 Message-Id: <20190228172110.15833-1-adhemerval.zanella@linaro.org> This patch assumes realtime clock support for nptl and thus removes all the associated code. For __pthread_mutex_timedlock the fallback usage for the case where lll_futex_timed_wait_bitset it not set define is also removed. The generic lowlevellock-futex.h always define it, so for NPTL code the check always yield true. Checked on x86_64-linux-gnu and i686-linux-gnu. * nptl/nptl-init.c (__have_futex_clock_realtime, __have_futex_clock_realtime): Remove definition. (__pthread_initialize_minimal_internal): Remove FUTEX_CLOCK_REALTIME check test for !__ASSUME_FUTEX_CLOCK_REALTIME. * nptl/pthread_mutex_timedlock.c (__pthread_mutex_timedlock): Assume __ASSUME_FUTEX_CLOCK_REALTIME support. * sysdeps/unix/sysv/linux/i386/lowlevellock.S: Likewise. * sysdeps/unix/sysv/linux/x86_64/lowlevellock.S: Likewise. * sysdeps/unix/sysv/linux/kernel-features.h (__ASSUME_FUTEX_CLOCK_REALTIME): Remove. * sysdeps/nptl/lowlevellock-futex.h (lll_futex_timed_wait_bitset): Adjust comment. --- nptl/nptl-init.c | 29 ----- nptl/pthread_mutex_timedlock.c | 27 ---- sysdeps/nptl/lowlevellock-futex.h | 3 +- sysdeps/unix/sysv/linux/i386/lowlevellock.S | 100 --------------- sysdeps/unix/sysv/linux/kernel-features.h | 3 - sysdeps/unix/sysv/linux/x86_64/lowlevellock.S | 115 ------------------ 6 files changed, 1 insertion(+), 276 deletions(-) -- 2.17.1 diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c index b5895fabf3..61ec8ed12a 100644 --- a/nptl/nptl-init.c +++ b/nptl/nptl-init.c @@ -58,15 +58,6 @@ int __set_robust_list_avail; # define set_robust_list_not_avail() do { } while (0) #endif -#ifndef __ASSUME_FUTEX_CLOCK_REALTIME -/* Nonzero if we do not have FUTEX_CLOCK_REALTIME. */ -int __have_futex_clock_realtime; -# define __set_futex_clock_realtime() \ - __have_futex_clock_realtime = 1 -#else -#define __set_futex_clock_realtime() do { } while (0) -#endif - /* Version of the library, used in libthread_db to detect mismatches. */ static const char nptl_version[] __attribute_used__ = VERSION; @@ -298,26 +289,6 @@ __pthread_initialize_minimal_internal (void) set_robust_list_not_avail (); } -#ifdef __NR_futex -# ifndef __ASSUME_FUTEX_CLOCK_REALTIME - { - int word = 0; - /* NB: the syscall actually takes six parameters. The last is the - bit mask. But since we will not actually wait at all the value - is irrelevant. Given that passing six parameters is difficult - on some architectures we just pass whatever random value the - calling convention calls for to the kernel. It causes no harm. */ - INTERNAL_SYSCALL_DECL (err); - word = INTERNAL_SYSCALL (futex, err, 5, &word, - FUTEX_WAIT_BITSET | FUTEX_CLOCK_REALTIME - | FUTEX_PRIVATE_FLAG, 1, NULL, 0); - assert (INTERNAL_SYSCALL_ERROR_P (word, err)); - if (INTERNAL_SYSCALL_ERRNO (word, err) != ENOSYS) - __set_futex_clock_realtime (); - } -# endif -#endif - /* Set initial thread's stack block from 0 up to __libc_stack_end. It will be bigger than it actually is, but for unwind.c/pt-longjmp.c purposes this is good enough. */ diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index 2f61a7d0d5..270b072c97 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -240,27 +240,6 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex, values despite them being valid. */ if (__glibc_unlikely (abstime->tv_sec < 0)) return ETIMEDOUT; -#if (!defined __ASSUME_FUTEX_CLOCK_REALTIME \ - || !defined lll_futex_timed_wait_bitset) - struct timeval tv; - struct timespec rt; - - /* Get the current time. */ - (void) __gettimeofday (&tv, NULL); - - /* Compute relative timeout. */ - rt.tv_sec = abstime->tv_sec - tv.tv_sec; - rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000; - if (rt.tv_nsec < 0) - { - rt.tv_nsec += 1000000000; - --rt.tv_sec; - } - - /* Already timed out? */ - if (rt.tv_sec < 0) - return ETIMEDOUT; -#endif /* We cannot acquire the mutex nor has its owner died. Thus, try to block using futexes. Set FUTEX_WAITERS if necessary so that @@ -287,18 +266,12 @@ __pthread_mutex_timedlock (pthread_mutex_t *mutex, assume_other_futex_waiters |= FUTEX_WAITERS; /* Block using the futex. */ -#if (!defined __ASSUME_FUTEX_CLOCK_REALTIME \ - || !defined lll_futex_timed_wait_bitset) - lll_futex_timed_wait (&mutex->__data.__lock, oldval, - &rt, PTHREAD_ROBUST_MUTEX_PSHARED (mutex)); -#else int err = lll_futex_timed_wait_bitset (&mutex->__data.__lock, oldval, abstime, FUTEX_CLOCK_REALTIME, PTHREAD_ROBUST_MUTEX_PSHARED (mutex)); /* The futex call timed out. */ if (err == -ETIMEDOUT) return -err; -#endif /* Reload current lock value. */ oldval = mutex->__data.__lock; } diff --git a/sysdeps/nptl/lowlevellock-futex.h b/sysdeps/nptl/lowlevellock-futex.h index bb8effe288..63d917d8da 100644 --- a/sysdeps/nptl/lowlevellock-futex.h +++ b/sysdeps/nptl/lowlevellock-futex.h @@ -43,8 +43,7 @@ #define lll_futex_timed_wait(futexp, val, timeout, private) \ -ENOSYS -/* This macro should be defined only if FUTEX_CLOCK_REALTIME is also defined. - If CLOCKBIT is zero, this is identical to lll_futex_timed_wait. +/* If CLOCKBIT is zero, this is identical to lll_futex_timed_wait. If CLOCKBIT has FUTEX_CLOCK_REALTIME set, then it's the same but TIMEOUT is counted by CLOCK_REALTIME rather than CLOCK_MONOTONIC. */ #define lll_futex_timed_wait_bitset(futexp, val, timeout, clockbit, private) \ diff --git a/sysdeps/unix/sysv/linux/i386/lowlevellock.S b/sysdeps/unix/sysv/linux/i386/lowlevellock.S index 83191a3899..a9898e94fd 100644 --- a/sysdeps/unix/sysv/linux/i386/lowlevellock.S +++ b/sysdeps/unix/sysv/linux/i386/lowlevellock.S @@ -148,16 +148,6 @@ __lll_timedlock_wait: cfi_adjust_cfa_offset(4) cfi_rel_offset(%ebx, 0) -# ifndef __ASSUME_FUTEX_CLOCK_REALTIME -# ifdef PIC - LOAD_PIC_REG (bx) - cmpl $0, __have_futex_clock_realtime@GOTOFF(%ebx) -# else - cmpl $0, __have_futex_clock_realtime -# endif - je .Lreltmo -# endif - cmpl $0, (%edx) js 8f @@ -199,96 +189,6 @@ __lll_timedlock_wait: 8: movl $ETIMEDOUT, %eax jmp 7b -# ifndef __ASSUME_FUTEX_CLOCK_REALTIME -.Lreltmo: - /* Check for a valid timeout value. */ - cmpl $1000000000, 4(%edx) - jae 3f - - pushl %esi - cfi_adjust_cfa_offset(4) - cfi_rel_offset(%esi, 0) - pushl %edi - cfi_adjust_cfa_offset(4) - cfi_rel_offset(%edi, 0) - - /* Stack frame for the timespec and timeval structs. */ - subl $8, %esp - cfi_adjust_cfa_offset(8) - - movl %ecx, %ebp - movl %edx, %edi - - movl $2, %edx - xchgl %edx, (%ebp) - - test %edx, %edx - je 6f - -1: - /* Get current time. */ - movl %esp, %ebx - xorl %ecx, %ecx - movl $__NR_gettimeofday, %eax - ENTER_KERNEL - - /* Compute relative timeout. */ - movl 4(%esp), %eax - movl $1000, %edx - mul %edx /* Milli seconds to nano seconds. */ - movl (%edi), %ecx - movl 4(%edi), %edx - subl (%esp), %ecx - subl %eax, %edx - jns 4f - addl $1000000000, %edx - subl $1, %ecx -4: testl %ecx, %ecx - js 2f /* Time is already up. */ - - /* Store relative timeout. */ - movl %ecx, (%esp) - movl %edx, 4(%esp) - - /* Futex call. */ - movl %ebp, %ebx - movl $2, %edx - movl %esp, %esi - movl 16(%esp), %ecx - LOAD_FUTEX_WAIT (%ecx) - movl $SYS_futex, %eax - ENTER_KERNEL - - /* NB: %edx == 2 */ - xchgl %edx, (%ebp) - - testl %edx, %edx - je 6f - - cmpl $-ETIMEDOUT, %eax - jne 1b -2: movl $ETIMEDOUT, %edx - -6: addl $8, %esp - cfi_adjust_cfa_offset(-8) - popl %edi - cfi_adjust_cfa_offset(-4) - cfi_restore(%edi) - popl %esi - cfi_adjust_cfa_offset(-4) - cfi_restore(%esi) -7: popl %ebx - cfi_adjust_cfa_offset(-4) - cfi_restore(%ebx) - popl %ebp - cfi_adjust_cfa_offset(-4) - cfi_restore(%ebp) - movl %edx, %eax - ret - -3: movl $EINVAL, %edx - jmp 7b -# endif cfi_endproc .size __lll_timedlock_wait,.-__lll_timedlock_wait #endif diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h index 0db1b987a4..bc5c959f58 100644 --- a/sysdeps/unix/sysv/linux/kernel-features.h +++ b/sysdeps/unix/sysv/linux/kernel-features.h @@ -57,9 +57,6 @@ 2.6.27. */ #define __ASSUME_IN_NONBLOCK 1 -/* Support for the FUTEX_CLOCK_REALTIME flag was added in 2.6.29. */ -#define __ASSUME_FUTEX_CLOCK_REALTIME 1 - /* Support for preadv and pwritev was added in 2.6.30. */ #define __ASSUME_PREADV 1 #define __ASSUME_PWRITEV 1 diff --git a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S index 166dbcfd3b..00ba88d5d2 100644 --- a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S +++ b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S @@ -127,15 +127,6 @@ __lll_lock_wait: .align 16 __lll_timedlock_wait: cfi_startproc -# ifndef __ASSUME_FUTEX_CLOCK_REALTIME -# ifdef PIC - cmpl $0, __have_futex_clock_realtime(%rip) -# else - cmpl $0, __have_futex_clock_realtime -# endif - je .Lreltmo -# endif - cmpq $0, (%rdx) js 5f @@ -176,112 +167,6 @@ __lll_timedlock_wait: 5: movl $ETIMEDOUT, %eax retq -# ifndef __ASSUME_FUTEX_CLOCK_REALTIME -.Lreltmo: - /* Check for a valid timeout value. */ - cmpq $1000000000, 8(%rdx) - jae 3f - - pushq %r8 - cfi_adjust_cfa_offset(8) - pushq %r9 - cfi_adjust_cfa_offset(8) - pushq %r12 - cfi_adjust_cfa_offset(8) - pushq %r13 - cfi_adjust_cfa_offset(8) - pushq %r14 - cfi_adjust_cfa_offset(8) - cfi_offset(%r8, -16) - cfi_offset(%r9, -24) - cfi_offset(%r12, -32) - cfi_offset(%r13, -40) - cfi_offset(%r14, -48) - pushq %rsi - cfi_adjust_cfa_offset(8) - - /* Stack frame for the timespec and timeval structs. */ - subq $24, %rsp - cfi_adjust_cfa_offset(24) - - movq %rdi, %r12 - movq %rdx, %r13 - - movl $2, %edx - xchgl %edx, (%r12) - - testl %edx, %edx - je 6f - -1: - /* Get current time. */ - movq %rsp, %rdi - xorl %esi, %esi - /* This call works because we directly jump to a system call entry - which preserves all the registers. */ - call JUMPTARGET(__gettimeofday) - - /* Compute relative timeout. */ - movq 8(%rsp), %rax - movl $1000, %edi - mul %rdi /* Milli seconds to nano seconds. */ - movq (%r13), %rdi - movq 8(%r13), %rsi - subq (%rsp), %rdi - subq %rax, %rsi - jns 4f - addq $1000000000, %rsi - decq %rdi -4: testq %rdi, %rdi - js 2f /* Time is already up. */ - - /* Store relative timeout. */ - movq %rdi, (%rsp) - movq %rsi, 8(%rsp) - - /* Futex call. */ - movl $2, %edx - movl $1, %eax - movq %rsp, %r10 - movl 24(%rsp), %esi - LOAD_FUTEX_WAIT (%esi) - movq %r12, %rdi - movl $SYS_futex, %eax - syscall - - /* NB: %edx == 2 */ - xchgl %edx, (%r12) - - testl %edx, %edx - je 6f - - cmpl $-ETIMEDOUT, %eax - jne 1b -2: movl $ETIMEDOUT, %edx - -6: addq $32, %rsp - cfi_adjust_cfa_offset(-32) - popq %r14 - cfi_adjust_cfa_offset(-8) - cfi_restore(%r14) - popq %r13 - cfi_adjust_cfa_offset(-8) - cfi_restore(%r13) - popq %r12 - cfi_adjust_cfa_offset(-8) - cfi_restore(%r12) - popq %r9 - cfi_adjust_cfa_offset(-8) - cfi_restore(%r9) - popq %r8 - cfi_adjust_cfa_offset(-8) - cfi_restore(%r8) - movl %edx, %eax - retq - -3: movl $EINVAL, %eax - retq -# endif cfi_endproc .size __lll_timedlock_wait,.-__lll_timedlock_wait #endif