This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 1/6] Optimize number of accesses to *adapt_count in lock elision code.
- From: Dominik Vogt <vogt at linux dot vnet dot ibm dot com>
- To: libc-alpha at sourceware dot org
- Date: Mon, 2 Sep 2013 09:58:08 +0200
- Subject: Re: [PATCH 1/6] Optimize number of accesses to *adapt_count in lock elision code.
- Authentication-results: sourceware.org; auth=none
- References: <20130902075228 dot GA4792 at linux dot vnet dot ibm dot com>
- Reply-to: libc-alpha at sourceware dot org
The changes to the original patches before 2.18 led to semantical changes of
the adapt_count argument. In the current code, *adapt_count cannot fall below
zero. When elision is attempted, *adapt_count is always exactly zero. This
fact can be exploited to reduce the number of accesses to *adapt_count and to
simplify updating *adapt_count.
Ciao
Dominik ^_^ ^_^
--
Dominik Vogt
IBM Germany
>From b1c13da1dc413fabebf809a37d3fec4099653955 Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@de.ibm.com>
Date: Mon, 2 Sep 2013 06:42:46 +0000
Subject: [PATCH 1/7] x86: Optimize number of accesses to *adapt_count in lock
elision code.
As *adapt_count cannot become negative, several if-conditions can be
simplified.
---
nptl/sysdeps/unix/sysv/linux/x86/elision-lock.c | 6 +++---
nptl/sysdeps/unix/sysv/linux/x86/elision-trylock.c | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/nptl/sysdeps/unix/sysv/linux/x86/elision-lock.c b/nptl/sysdeps/unix/sysv/linux/x86/elision-lock.c
index 9d00983..45370ed 100644
--- a/nptl/sysdeps/unix/sysv/linux/x86/elision-lock.c
+++ b/nptl/sysdeps/unix/sysv/linux/x86/elision-lock.c
@@ -44,7 +44,7 @@
int
__lll_lock_elision (int *futex, short *adapt_count, EXTRAARG int private)
{
- if (*adapt_count <= 0)
+ if (*adapt_count == 0)
{
unsigned status;
int try_xbegin;
@@ -71,13 +71,13 @@ __lll_lock_elision (int *futex, short *adapt_count, EXTRAARG int private)
{
/* Right now we skip here. Better would be to wait a bit
and retry. This likely needs some spinning. */
- if (*adapt_count != aconf.skip_lock_busy)
+ if (aconf.skip_lock_busy > 0)
*adapt_count = aconf.skip_lock_busy;
}
/* Internal abort. There is no chance for retry.
Use the normal locking and next time use lock.
Be careful to avoid writing to the lock. */
- else if (*adapt_count != aconf.skip_lock_internal_abort)
+ else if (aconf.skip_lock_internal_abort > 0)
*adapt_count = aconf.skip_lock_internal_abort;
break;
}
diff --git a/nptl/sysdeps/unix/sysv/linux/x86/elision-trylock.c b/nptl/sysdeps/unix/sysv/linux/x86/elision-trylock.c
index f6c47ef..be22270 100644
--- a/nptl/sysdeps/unix/sysv/linux/x86/elision-trylock.c
+++ b/nptl/sysdeps/unix/sysv/linux/x86/elision-trylock.c
@@ -37,7 +37,7 @@ __lll_trylock_elision (int *futex, short *adapt_count)
_xabort (_ABORT_NESTED_TRYLOCK);
/* Only try a transaction if it's worth it. */
- if (*adapt_count <= 0)
+ if (*adapt_count == 0)
{
unsigned status;
@@ -56,7 +56,7 @@ __lll_trylock_elision (int *futex, short *adapt_count)
{
/* Internal abort. No chance for retry. For future
locks don't try speculation for some time. */
- if (*adapt_count != aconf.skip_trylock_internal_abort)
+ if (aconf.skip_trylock_internal_abort > 0)
*adapt_count = aconf.skip_trylock_internal_abort;
}
/* Could do some retries here. */
--
1.7.11.4