[PATCH 1/2] nptl: Replace futex_lock_pi with __futex_lock_pi64
Adhemerval Zanella
adhemerval.zanella@linaro.org
Thu Oct 29 19:42:07 GMT 2020
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.
--
2.25.1
More information about the Libc-alpha
mailing list