|
|
147e83 |
commit c2f5813ae0a68f6c6d69e66dac2da6e46b9df034
|
|
|
147e83 |
Author: Joseph Myers <joseph@codesourcery.com>
|
|
|
147e83 |
Date: Wed Mar 18 17:05:38 2015 +0000
|
|
|
147e83 |
|
|
|
147e83 |
Make sem_timedwait use FUTEX_CLOCK_REALTIME (bug 18138).
|
|
|
147e83 |
|
|
|
147e83 |
sem_timedwait converts absolute timeouts to relative to pass them to
|
|
|
147e83 |
the futex syscall. (Before the recent reimplementation, on x86_64 it
|
|
|
147e83 |
used FUTEX_CLOCK_REALTIME, but not on other architectures.)
|
|
|
147e83 |
|
|
|
147e83 |
Correctly implementing POSIX requirements, however, requires use of
|
|
|
147e83 |
FUTEX_CLOCK_REALTIME; passing a relative timeout to the kernel does
|
|
|
147e83 |
not conform to POSIX. The POSIX specification for sem_timedwait says
|
|
|
147e83 |
"The timeout shall be based on the CLOCK_REALTIME clock.". The POSIX
|
|
|
147e83 |
specification for clock_settime says "If the value of the
|
|
|
147e83 |
CLOCK_REALTIME clock is set via clock_settime(), the new value of the
|
|
|
147e83 |
clock shall be used to determine the time of expiration for absolute
|
|
|
147e83 |
time services based upon the CLOCK_REALTIME clock. This applies to the
|
|
|
147e83 |
time at which armed absolute timers expire. If the absolute time
|
|
|
147e83 |
requested at the invocation of such a time service is before the new
|
|
|
147e83 |
value of the clock, the time service shall expire immediately as if
|
|
|
147e83 |
the clock had reached the requested time normally.". If a relative
|
|
|
147e83 |
timeout is passed to the kernel, it is interpreted according to the
|
|
|
147e83 |
CLOCK_MONOTONIC clock, and so fails to meet that POSIX requirement in
|
|
|
147e83 |
the event of clock changes.
|
|
|
147e83 |
|
|
|
147e83 |
This patch makes sem_timedwait use lll_futex_timed_wait_bitset with
|
|
|
147e83 |
FUTEX_CLOCK_REALTIME when possible, as done in some other places in
|
|
|
147e83 |
NPTL. FUTEX_CLOCK_REALTIME is always available for supported Linux
|
|
|
147e83 |
kernel versions; unavailability of lll_futex_timed_wait_bitset is only
|
|
|
147e83 |
an issue for hppa (an issue noted in
|
|
|
147e83 |
<https://sourceware.org/glibc/wiki/PortStatus>, and fixed by the
|
|
|
147e83 |
unreviewed
|
|
|
147e83 |
<https://sourceware.org/ml/libc-alpha/2014-12/msg00655.html> that
|
|
|
147e83 |
removes the hppa lowlevellock.h completely).
|
|
|
147e83 |
|
|
|
147e83 |
In the FUTEX_CLOCK_REALTIME case, the glibc code still needs to check
|
|
|
147e83 |
for negative tv_sec and handle that as timeout, because the Linux
|
|
|
147e83 |
kernel returns EINVAL not ETIMEDOUT for that case, so resulting in
|
|
|
147e83 |
failures of nptl/tst-abstime and nptl/tst-sem13 in the absence of that
|
|
|
147e83 |
check. If we're trying to distinguish between Linux-specific and
|
|
|
147e83 |
generic-futex NPTL code, I suppose having this in an nptl/ file isn't
|
|
|
147e83 |
ideal, but there doesn't seem to be any better place at present.
|
|
|
147e83 |
|
|
|
147e83 |
It's not possible to add a testcase for this issue to the testsuite
|
|
|
147e83 |
because of the requirement to change the system clock as part of a
|
|
|
147e83 |
test (this is a case where testing would require some form of
|
|
|
147e83 |
container, with root in that container, and one whose CLOCK_REALTIME
|
|
|
147e83 |
is isolated from that of the host; I'm not sure what forms of
|
|
|
147e83 |
containers, short of a full virtual machine, provide that clock
|
|
|
147e83 |
isolation).
|
|
|
147e83 |
|
|
|
147e83 |
Tested for x86_64. Also tested for powerpc with the testcase included
|
|
|
147e83 |
in the bug.
|
|
|
147e83 |
|
|
|
147e83 |
[BZ #18138]
|
|
|
147e83 |
* nptl/sem_waitcommon.c: Include <kernel-features.h>.
|
|
|
147e83 |
(futex_abstimed_wait)
|
|
|
147e83 |
[__ASSUME_FUTEX_CLOCK_REALTIME && lll_futex_timed_wait_bitset]:
|
|
|
147e83 |
Use lll_futex_timed_wait_bitset with FUTEX_CLOCK_REALTIME instead
|
|
|
147e83 |
of lll_futex_timed_wait.
|
|
|
147e83 |
|
|
|
147e83 |
Index: glibc-2.17-c758a686/nptl/sysdeps/unix/sysv/linux/sem_waitcommon.c
|
|
|
147e83 |
===================================================================
|
|
|
147e83 |
--- glibc-2.17-c758a686.orig/nptl/sysdeps/unix/sysv/linux/sem_waitcommon.c
|
|
|
147e83 |
+++ glibc-2.17-c758a686/nptl/sysdeps/unix/sysv/linux/sem_waitcommon.c
|
|
|
147e83 |
@@ -17,6 +17,7 @@
|
|
|
147e83 |
License along with the GNU C Library; if not, see
|
|
|
147e83 |
<http://www.gnu.org/licenses/>. */
|
|
|
147e83 |
|
|
|
147e83 |
+#include <kernel-features.h>
|
|
|
147e83 |
#include <errno.h>
|
|
|
147e83 |
#include <sysdep.h>
|
|
|
147e83 |
#include <lowlevellock.h>
|
|
|
147e83 |
@@ -45,6 +46,13 @@ futex_abstimed_wait (unsigned int* futex
|
|
|
147e83 |
}
|
|
|
147e83 |
else
|
|
|
147e83 |
{
|
|
|
147e83 |
+#if (defined __ASSUME_FUTEX_CLOCK_REALTIME \
|
|
|
147e83 |
+ && defined lll_futex_timed_wait_bitset)
|
|
|
147e83 |
+ /* The Linux kernel returns EINVAL for this, but in userspace
|
|
|
147e83 |
+ such a value is valid. */
|
|
|
147e83 |
+ if (abstime->tv_sec < 0)
|
|
|
147e83 |
+ return ETIMEDOUT;
|
|
|
147e83 |
+#else
|
|
|
147e83 |
struct timeval tv;
|
|
|
147e83 |
struct timespec rt;
|
|
|
147e83 |
int sec, nsec;
|
|
|
147e83 |
@@ -68,9 +76,16 @@ futex_abstimed_wait (unsigned int* futex
|
|
|
147e83 |
/* Do wait. */
|
|
|
147e83 |
rt.tv_sec = sec;
|
|
|
147e83 |
rt.tv_nsec = nsec;
|
|
|
147e83 |
+#endif
|
|
|
147e83 |
if (cancel)
|
|
|
147e83 |
oldtype = __pthread_enable_asynccancel ();
|
|
|
147e83 |
+#if (defined __ASSUME_FUTEX_CLOCK_REALTIME \
|
|
|
147e83 |
+ && defined lll_futex_timed_wait_bitset)
|
|
|
147e83 |
+ err = lll_futex_timed_wait_bitset (futex, expected, abstime,
|
|
|
147e83 |
+ FUTEX_CLOCK_REALTIME, private);
|
|
|
147e83 |
+#else
|
|
|
147e83 |
err = lll_futex_timed_wait (futex, expected, &rt, private);
|
|
|
147e83 |
+#endif
|
|
|
147e83 |
if (cancel)
|
|
|
147e83 |
__pthread_disable_asynccancel (oldtype);
|
|
|
147e83 |
}
|