]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
powerpc: Optimize lock elision for pthread_mutex_t
authorPaul Murphy <murphyp@linux.vnet.ibm.com>
Thu, 3 Sep 2015 18:40:21 +0000 (13:40 -0500)
committerTulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>
Thu, 15 Oct 2015 21:56:10 +0000 (18:56 -0300)
With TLE enabled, the adapt count variable update incurs
an 8% overhead before entering the critical section of an
elided mutex.

Instead, if it is done right after leaving the critical
section, this serialization can be avoided.

This alters the existing behavior of __lll_trylock_elision
as it will only decrement the adapt_count if it successfully
acquires the lock.

* sysdeps/unix/sysv/linux/powerpc/elision-lock.c
(__lll_lock_elision): Remove adapt_count decrement...
* sysdeps/unix/sysv/linux/powerpc/elision-trylock.c
(__lll_trylock_elision): Likewise.
* sysdeps/unix/sysv/linux/powerpc/elision-unlock.c
(__lll_unlock_elision): ... to here. And utilize
new adapt_count parameter.
* sysdeps/unix/sysv/linux/powerpc/lowlevellock.h
(__lll_unlock_elision): Update to include adapt_count
parameter.
(lll_unlock_elision): Pass pointer to adapt_count
variable.

ChangeLog
sysdeps/unix/sysv/linux/powerpc/elision-lock.c
sysdeps/unix/sysv/linux/powerpc/elision-trylock.c
sysdeps/unix/sysv/linux/powerpc/elision-unlock.c
sysdeps/unix/sysv/linux/powerpc/lowlevellock.h

index 6a743e454b75fcecc2a3e4e669621a11fc0736ed..917c4649d932273957c83861725f9baf008cb43e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2015-10-15  Paul E. Murphy  <murphyp@linux.vnet.ibm.com>
+
+       * sysdeps/unix/sysv/linux/powerpc/elision-lock.c
+       (__lll_lock_elision): Remove adapt_count decrement...
+       * sysdeps/unix/sysv/linux/powerpc/elision-trylock.c
+       (__lll_trylock_elision): Likewise.
+       * sysdeps/unix/sysv/linux/powerpc/elision-unlock.c
+       (__lll_unlock_elision): ... to here. And utilize
+       new adapt_count parameter.
+       * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h
+       (__lll_unlock_elision): Update to include adapt_count
+       parameter.
+       (lll_unlock_elision): Pass pointer to adapt_count
+       variable.
+
 2015-10-15  Paul E. Murphy  <murphyp@linux.vnet.ibm.com>
 
        * nptl/pthread_mutex_unlock.c (lll_unlock_elision):
index 26d272e619f1840b40779d1916258c261a557166..376273237989c90612da2e6bb59ae7b2abc3fb39 100644 (file)
@@ -47,7 +47,6 @@ __lll_lock_elision (int *lock, short *adapt_count, EXTRAARG int pshared)
 {
   if (*adapt_count > 0)
     {
-      (*adapt_count)--;
       goto use_lock;
     }
 
index 7b6d1b9b98320888ed958022cd14f96d9783a4fe..440939cda155b170e13447eb523ab9783cce9d7d 100644 (file)
@@ -36,7 +36,6 @@ __lll_trylock_elision (int *futex, short *adapt_count)
   /* Only try a transaction if it's worth it.  */
   if (*adapt_count > 0)
     {
-      (*adapt_count)--;
       goto use_lock;
     }
 
index f04c3393831b75d9c6c0f88c09428b39a1d0097b..72b893d9f410fabd492ccd515febed822657731c 100644 (file)
 #include "htm.h"
 
 int
-__lll_unlock_elision(int *lock, int pshared)
+__lll_unlock_elision (int *lock, short *adapt_count, int pshared)
 {
   /* When the lock was free we're in a transaction.  */
   if (*lock == 0)
     __builtin_tend (0);
   else
-    lll_unlock ((*lock), pshared);
+    {
+      lll_unlock ((*lock), pshared);
+
+      /* Update the adapt count AFTER completing the critical section.
+         Doing this here prevents unneeded stalling when entering
+         a critical section.  Saving about 8% runtime on P8.  */
+      if (*adapt_count > 0)
+       (*adapt_count)--;
+    }
   return 0;
 }
index 16479e77530f3a3de03ca44df68e619822b6d06e..6769c253ceebbd3342d02573f2d1a05b9af65210 100644 (file)
@@ -32,7 +32,7 @@ extern int __lll_timedlock_elision
 extern int __lll_lock_elision (int *futex, short *adapt_count, int private)
   attribute_hidden;
 
-extern int __lll_unlock_elision(int *lock, int private)
+extern int __lll_unlock_elision (int *lock, short *adapt_count, int private)
   attribute_hidden;
 
 extern int __lll_trylock_elision(int *lock, short *adapt_count)
@@ -41,7 +41,7 @@ extern int __lll_trylock_elision(int *lock, short *adapt_count)
 #define lll_lock_elision(futex, adapt_count, private) \
   __lll_lock_elision (&(futex), &(adapt_count), private)
 #define lll_unlock_elision(futex, adapt_count, private) \
-  __lll_unlock_elision (&(futex), private)
+  __lll_unlock_elision (&(futex), &(adapt_count), private)
 #define lll_trylock_elision(futex, adapt_count) \
   __lll_trylock_elision (&(futex), &(adapt_count))