This is the mail archive of the
libc-ports@sources.redhat.com
mailing list for the libc-ports project.
[PATCH] Avoid unnecessary busy loop in __lll_timedlock_wait on ARM.
- From: <katsuki dot uwatoko at toshiba dot co dot jp>
- To: <libc-ports at sourceware dot org>
- Date: Thu, 31 Jan 2013 08:42:17 +0000
- Subject: [PATCH] Avoid unnecessary busy loop in __lll_timedlock_wait on ARM.
- Msscp.transfermailtomossagent: 103
Hi,
I have found an issue in __lll_timedlock_wait on ARM.
The following sequence causes unnecessary busy loop.
"A thread" gets the lock. (futex = 1)
"B thread" tries to get the lock, and has not called futex syscall yet. (futex = 2)
"A thread" releases the lock (futex = 0)
"C thread" gets the lock, and does not call futex syscall because of futex=0 (futex = 1)
"B thread" calls futex syscall, and returns with an error.
Because futex syscall in Linux Kernel checks if the val is changed
from 2, which is the 3rd arg of the syscall at futex_wait_setup(),
but in this case futex is 1.
"B thread" tries to get the lock in userspace but cannot get it
because futex is not 0.
After all the thread keeps calling futex syscall
until "C thread" will release it (futex = 0) or timeout.
Therefore I think that the value should be set 2 in every loop
the same as __lll_lock_wait_private, and attached a patch for this issue.
--
UWATOKO Katsuki
---
.../unix/sysv/linux/arm/nptl/lowlevellock.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/ports/sysdeps/unix/sysv/linux/arm/nptl/lowlevellock.c b/ports/sysdeps/unix/sysv/linux/arm/nptl/lowlevellock.c
index 756f39f..a495d85 100644
--- a/ports/sysdeps/unix/sysv/linux/arm/nptl/lowlevellock.c
+++ b/ports/sysdeps/unix/sysv/linux/arm/nptl/lowlevellock.c
@@ -65,6 +65,7 @@ __lll_timedlock_wait (int *futex, const struct timespec *abstime, int private)
do
{
struct timeval tv;
+ int oldval;
/* Get the current time. */
(void) __gettimeofday (&tv, NULL);
@@ -82,8 +83,10 @@ __lll_timedlock_wait (int *futex, const struct timespec *abstime, int private)
if (rt.tv_sec < 0)
return ETIMEDOUT;
+ oldval = atomic_compare_and_exchange_val_acq (futex, 2, 1);
// XYZ: Lost the lock to check whether it was private.
- lll_futex_timed_wait (futex, 2, &rt, private);
+ if (oldval != 0)
+ lll_futex_timed_wait (futex, 2, &rt, private);
}
while (atomic_compare_and_exchange_bool_acq (futex, 2, 0) != 0);
--
1.7.4.1