This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH][s390,ppc] Use FUTEX_WAIT_BITSET for *timedwait
- From: Siddhesh Poyarekar <siddhesh at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Fri, 26 Oct 2012 15:49:27 +0530
- Subject: [PATCH][s390,ppc] Use FUTEX_WAIT_BITSET for *timedwait
Hi,
Here's the second patch that implements
pthread_rwlock_timed*lock and lll_robust_timedlock_wait using
FUTEX_WAIT_BITSET if available. It needs the earlier FUTEX_WAIT_BITSET
patch to work correctly. I have also committed this patch to the
siddhesh/wait_bitset branch (and learned that rebases are only good
when you're working locally).
This is again tested on s390 and ppc. If both patches are OK, I will
fold all of them into a single commit if that is fine (with a single
ChangeLog of course).
Regards,
Siddhesh
nptl/ChangeLog:
* pthread_rwlock_timedrdlock.c (pthread_rwlock_timedrdlock):
Time out if absolute timeout is negative.
[__ASSUME_FUTEX_CLOCK_REALTIME &&
lll_futex_timed_wait_bitset]: Use lll_futex_timed_wait_bitset.
* pthread_rwlock_timedwrlock.c (pthread_rwlock_timedwrlock):
Likewise.
* sysdeps/unix/sysv/linux/lowlevelrobustlock.c
(__lll_robust_timedlock_wait): Likewise.
diff --git a/nptl/pthread_rwlock_timedrdlock.c b/nptl/pthread_rwlock_timedrdlock.c
index be8216d..b7622ab 100644
--- a/nptl/pthread_rwlock_timedrdlock.c
+++ b/nptl/pthread_rwlock_timedrdlock.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003,2004,2007,2011 Free Software Foundation, Inc.
+/* Copyright (C) 2003-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003.
@@ -76,6 +76,16 @@ pthread_rwlock_timedrdlock (rwlock, abstime)
break;
}
+ /* Work around the fact that the kernel rejects negative timeout values
+ despite them being valid. */
+ if (__builtin_expect (abstime->tv_sec < 0, 0))
+ {
+ result = ETIMEDOUT;
+ break;
+ }
+
+#if (!defined __ASSUME_FUTEX_CLOCK_REALTIME \
+ || !defined lll_futex_timed_wait_bitset)
/* Get the current time. So far we support only one clock. */
struct timeval tv;
(void) gettimeofday (&tv, NULL);
@@ -96,6 +106,7 @@ pthread_rwlock_timedrdlock (rwlock, abstime)
result = ETIMEDOUT;
break;
}
+#endif
/* Remember that we are a reader. */
if (++rwlock->__data.__nr_readers_queued == 0)
@@ -112,8 +123,16 @@ pthread_rwlock_timedrdlock (rwlock, abstime)
lll_unlock (rwlock->__data.__lock, rwlock->__data.__shared);
/* Wait for the writer to finish. */
+#if (!defined __ASSUME_FUTEX_CLOCK_REALTIME \
+ || !defined lll_futex_timed_wait_bitset)
err = lll_futex_timed_wait (&rwlock->__data.__readers_wakeup,
waitval, &rt, rwlock->__data.__shared);
+#else
+ err = lll_futex_timed_wait_bitset (&rwlock->__data.__readers_wakeup,
+ waitval, abstime,
+ FUTEX_CLOCK_REALTIME,
+ rwlock->__data.__shared);
+#endif
/* Get the lock. */
lll_lock (rwlock->__data.__lock, rwlock->__data.__shared);
diff --git a/nptl/pthread_rwlock_timedwrlock.c b/nptl/pthread_rwlock_timedwrlock.c
index 8eb31cf..5f2399f 100644
--- a/nptl/pthread_rwlock_timedwrlock.c
+++ b/nptl/pthread_rwlock_timedwrlock.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003,2004,2007,2011 Free Software Foundation, Inc.
+/* Copyright (C) 2003-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003.
@@ -67,6 +67,16 @@ pthread_rwlock_timedwrlock (rwlock, abstime)
break;
}
+ /* Work around the fact that the kernel rejects negative timeout values
+ despite them being valid. */
+ if (__builtin_expect (abstime->tv_sec < 0, 0))
+ {
+ result = ETIMEDOUT;
+ break;
+ }
+
+#if (!defined __ASSUME_FUTEX_CLOCK_REALTIME \
+ || !defined lll_futex_timed_wait_bitset)
/* Get the current time. So far we support only one clock. */
struct timeval tv;
(void) gettimeofday (&tv, NULL);
@@ -86,6 +96,7 @@ pthread_rwlock_timedwrlock (rwlock, abstime)
result = ETIMEDOUT;
break;
}
+#endif
/* Remember that we are a writer. */
if (++rwlock->__data.__nr_writers_queued == 0)
@@ -102,8 +113,16 @@ pthread_rwlock_timedwrlock (rwlock, abstime)
lll_unlock (rwlock->__data.__lock, rwlock->__data.__shared);
/* Wait for the writer or reader(s) to finish. */
+#if (!defined __ASSUME_FUTEX_CLOCK_REALTIME \
+ || !defined lll_futex_timed_wait_bitset)
err = lll_futex_timed_wait (&rwlock->__data.__writer_wakeup,
waitval, &rt, rwlock->__data.__shared);
+#else
+ err = lll_futex_timed_wait_bitset (&rwlock->__data.__writer_wakeup,
+ waitval, abstime,
+ FUTEX_CLOCK_REALTIME,
+ rwlock->__data.__shared);
+#endif
/* Get the lock. */
lll_lock (rwlock->__data.__lock, rwlock->__data.__shared);
diff --git a/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c b/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c
index 7b4e843..9a9e673 100644
--- a/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c
+++ b/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 2006-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Jakub Jelinek <jakub@redhat.com>, 2006.
@@ -70,8 +70,15 @@ __lll_robust_timedlock_wait (int *futex, const struct timespec *abstime,
if (oldval == 0)
goto try;
+ /* Work around the fact that the kernel rejects negative timeout values
+ despite them being valid. */
+ if (__builtin_expect (abstime->tv_sec < 0, 0))
+ return ETIMEDOUT;
+
do
{
+#if (!defined __ASSUME_FUTEX_CLOCK_REALTIME \
+ || !defined lll_futex_timed_wait_bitset)
struct timeval tv;
struct timespec rt;
@@ -90,6 +97,7 @@ __lll_robust_timedlock_wait (int *futex, const struct timespec *abstime,
/* Already timed out? */
if (rt.tv_sec < 0)
return ETIMEDOUT;
+#endif
/* Wait. */
if (__builtin_expect (oldval & FUTEX_OWNER_DIED, 0))
@@ -100,7 +108,13 @@ __lll_robust_timedlock_wait (int *futex, const struct timespec *abstime,
&& atomic_compare_and_exchange_bool_acq (futex, newval, oldval))
continue;
+#if (!defined __ASSUME_FUTEX_CLOCK_REALTIME \
+ || !defined lll_futex_timed_wait_bitset)
lll_futex_timed_wait (futex, newval, &rt, private);
+#else
+ lll_futex_timed_wait_bitset (futex, newval, abstime,
+ FUTEX_CLOCK_REALTIME, private);
+#endif
try:
;