From 8352b6df371f1d08f86b4600a7725a5181e021ee Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Fri, 25 Jun 2021 10:11:00 +0200 Subject: nptl: Use FUTEX_LOCK_PI2 when available This patch uses the new futex PI operation provided by Linux v5.14 when it is required. The futex_lock_pi64() is moved to futex-internal.c (since it used on two different places and its code size might be large depending of the kernel configuration) and clockid is added as an argument. Co-authored-by: Kurt Kanzenbach --- sysdeps/nptl/futex-internal.h | 58 +++---------------------------------------- 1 file changed, 4 insertions(+), 54 deletions(-) (limited to 'sysdeps/nptl/futex-internal.h') diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h index 79a366604d..a46730cad6 100644 --- a/sysdeps/nptl/futex-internal.h +++ b/sysdeps/nptl/futex-internal.h @@ -236,8 +236,8 @@ futex_wake (unsigned int* futex_word, int processes_to_wake, int private) are done in descending priority order. The ABSTIME arguments provides an absolute timeout (measured against the - CLOCK_REALTIME clock). If TIMEOUT is NULL, the operation will block - indefinitely. + CLOCK_REALTIME or CLOCK_MONOTONIC clock). If TIMEOUT is NULL, the operation + will block indefinitely. Returns: @@ -250,58 +250,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_pi64 (int *futex_word, const struct __timespec64 *abstime, - int private) -{ - int err; -#ifdef __ASSUME_TIME64_SYSCALLS - err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, - __lll_private_flag (FUTEX_LOCK_PI, private), 0, - abstime); -#else - bool need_time64 = abstime != NULL && !in_time_t_range (abstime->tv_sec); - if (need_time64) - { - err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, - __lll_private_flag (FUTEX_LOCK_PI, private), - 0, abstime); - if (err == -ENOSYS) - err = -EOVERFLOW; - } - else - { - 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, clockid_t clockid, + const struct __timespec64 *abstime, int private); /* Wakes the top priority waiter that called a futex_lock_pi operation on the futex. -- cgit 1.4.1