From 215078017fd25fd64074e25ccd3dde0f6f19d4fe Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Wed, 30 Oct 2019 15:56:39 -0300 Subject: nptl: Replace non cancellable pause/nanosleep with futex To help y2038 work avoid duplicate all the logic of nanosleep on non cancellable version, the patch replace it with a new futex operation, lll_timedwait. The changes are: - Add a expected value for __lll_clocklock_wait, so it can be used to wait for generic values. - Remove its internal atomic operation and move the logic to __lll_clocklock. It makes __lll_clocklock_wait even more generic and __lll_clocklock slight faster on fast-path (since it won't require a function call anymore). - Add lll_timedwait, which uses __lll_clocklock_wait, to replace both __pause_nocancel and __nanosleep_nocancel. It also allows remove the sparc32 __lll_clocklock_wait implementation (since it is similar to the generic one). Checked on x86_64-linux-gnu, sparcv9-linux-gnu, and i686-linux-gnu. Reviewed-by: Carlos O'Donell --- nptl/lll_timedlock_wait.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'nptl/lll_timedlock_wait.c') diff --git a/nptl/lll_timedlock_wait.c b/nptl/lll_timedlock_wait.c index cd3cc3d371..952b042555 100644 --- a/nptl/lll_timedlock_wait.c +++ b/nptl/lll_timedlock_wait.c @@ -25,39 +25,38 @@ int -__lll_clocklock_wait (int *futex, clockid_t clockid, +__lll_clocklock_wait (int *futex, int val, clockid_t clockid, const struct timespec *abstime, int private) { - /* Reject invalid timeouts. */ - if (! valid_nanoseconds (abstime->tv_nsec)) - return EINVAL; + struct timespec ts, *tsp = NULL; - /* Try locking. */ - while (atomic_exchange_acq (futex, 2) != 0) + if (abstime != NULL) { - struct timespec ts; + /* Reject invalid timeouts. */ + if (! valid_nanoseconds (abstime->tv_nsec)) + return EINVAL; - /* Get the current time. This can only fail if clockid is not - valid. */ + /* Get the current time. This can only fail if clockid is not valid. */ if (__glibc_unlikely (__clock_gettime (clockid, &ts) != 0)) return EINVAL; /* Compute relative timeout. */ - struct timespec rt; - rt.tv_sec = abstime->tv_sec - ts.tv_sec; - rt.tv_nsec = abstime->tv_nsec - ts.tv_nsec; - if (rt.tv_nsec < 0) + ts.tv_sec = abstime->tv_sec - ts.tv_sec; + ts.tv_nsec = abstime->tv_nsec - ts.tv_nsec; + if (ts.tv_nsec < 0) { - rt.tv_nsec += 1000000000; - --rt.tv_sec; + ts.tv_nsec += 1000000000; + --ts.tv_sec; } - if (rt.tv_sec < 0) + if (ts.tv_sec < 0) return ETIMEDOUT; - /* If *futex == 2, wait until woken or timeout. */ - lll_futex_timed_wait (futex, 2, &rt, private); + tsp = &ts; } + /* If *futex == val, wait until woken or timeout. */ + lll_futex_timed_wait (futex, val, tsp, private); + return 0; } -- cgit 1.4.1