[PATCHv2] powerpc: Fix usage of elision transient failure adapt param

Message ID 55DF2324.2040308@linux.vnet.ibm.com
State Committed
Delegated to: Tulio Magno Quites Machado Filho
Headers

Commit Message

Paul E. Murphy Aug. 27, 2015, 2:48 p.m. UTC
  This is now rebased around Tulio's fix for elide.h: 
http://patchwork.sourceware.org/patch/8413/

Changes are fairly trivial. Note, attempt goes from
try_tbegin towards 0, but not to 0.

---
The skip_lock_out_of_tbegin_retries adaptive parameter was
not being used correctly, nor as described.  This prevents
a fallback for all users of the lock if a transient abort
occurs within the accepted number of retries.

2015-08-26  Paul E. Murphy  <murphyp@linux.vnet.ibm.com>
	* sysdeps/powerpc/nptl/elide.h(__elide_lock): Fix
	usage of .skip_lock_out_of_tbegin_retries
	* sysdeps/unix/sysv/linux/powerpc/elision-lock.c
	* (__lll_lock_elision):
	Likewise, and respect a value of try_tbegin <= 0
---
 ChangeLog                                      |    8 ++++++++
 sysdeps/powerpc/nptl/elide.h                   |    6 +++---
 sysdeps/unix/sysv/linux/powerpc/elision-lock.c |   15 ++++++---------
 3 files changed, 17 insertions(+), 12 deletions(-)
  

Comments

Tulio Magno Quites Machado Filho Oct. 27, 2015, 7:35 p.m. UTC | #1
"Paul E. Murphy" <murphyp@linux.vnet.ibm.com> writes:

> This is now rebased around Tulio's fix for elide.h: 
> http://patchwork.sourceware.org/patch/8413/
>
> Changes are fairly trivial. Note, attempt goes from
> try_tbegin towards 0, but not to 0.
>
> ---
> The skip_lock_out_of_tbegin_retries adaptive parameter was
> not being used correctly, nor as described.  This prevents
> a fallback for all users of the lock if a transient abort
> occurs within the accepted number of retries.
>
> 2015-08-26  Paul E. Murphy  <murphyp@linux.vnet.ibm.com>
> 	* sysdeps/powerpc/nptl/elide.h(__elide_lock): Fix
> 	usage of .skip_lock_out_of_tbegin_retries
> 	* sysdeps/unix/sysv/linux/powerpc/elision-lock.c
> 	* (__lll_lock_elision):
> 	Likewise, and respect a value of try_tbegin <= 0

I added a reference to bug #19174 and pushed it as 72f1463.

Thanks!
  

Patch

diff --git a/ChangeLog b/ChangeLog
index 50e9d81..e09e31b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@ 
+2015-08-26  Paul E. Murphy  <murphyp@linux.vnet.ibm.com>
+
+	* sysdeps/powerpc/nptl/elide.h(__elide_lock): Fix
+	usage of .skip_lock_out_of_tbegin_retries
+	* sysdeps/unix/sysv/linux/powerpc/elision-lock.c
+	(__lll_lock_elision):
+	Likewise, and respect a value of try_tbegin <= 0
+
 2015-08-26  Tulio Magno Quites Machado Filho  <tuliom@linux.vnet.ibm.com>
 
 	[BZ #18743]
diff --git a/sysdeps/powerpc/nptl/elide.h b/sysdeps/powerpc/nptl/elide.h
index 1cc9890..a1e5563 100644
--- a/sysdeps/powerpc/nptl/elide.h
+++ b/sysdeps/powerpc/nptl/elide.h
@@ -27,7 +27,7 @@ 
    configurations.  Returns true if the system should retry again or false
    otherwise.  */
 static inline bool
-__get_new_count (uint8_t *adapt_count)
+__get_new_count (uint8_t *adapt_count, int attempt)
 {
   /* A persistent failure indicates that a retry will probably
      result in another failure.  Use normal locking now and
@@ -40,7 +40,7 @@  __get_new_count (uint8_t *adapt_count)
     }
   /* Same logic as above, but for a number of temporary failures in a
      a row.  */
-  else if (__elision_aconf.skip_lock_out_of_tbegin_retries > 0
+  else if (attempt <= 1 && __elision_aconf.skip_lock_out_of_tbegin_retries > 0
 	   && __elision_aconf.try_tbegin > 0)
     *adapt_count = __elision_aconf.skip_lock_out_of_tbegin_retries;
   return true;
@@ -76,7 +76,7 @@  __get_new_count (uint8_t *adapt_count)
 	      __builtin_tabort (_ABORT_LOCK_BUSY);			\
 	    }								\
 	  else								\
-	    if (!__get_new_count(&adapt_count))				\
+	    if (!__get_new_count (&adapt_count,i))			\
 	      break;							\
 	}								\
     ret;								\
diff --git a/sysdeps/unix/sysv/linux/powerpc/elision-lock.c b/sysdeps/unix/sysv/linux/powerpc/elision-lock.c
index 26d272e..7b6c806 100644
--- a/sysdeps/unix/sysv/linux/powerpc/elision-lock.c
+++ b/sysdeps/unix/sysv/linux/powerpc/elision-lock.c
@@ -51,8 +51,7 @@  __lll_lock_elision (int *lock, short *adapt_count, EXTRAARG int pshared)
       goto use_lock;
     }
 
-  int try_begin = aconf.try_tbegin;
-  while (1)
+  for (int i = aconf.try_tbegin; i > 0; i--)
     {
       if (__builtin_tbegin (0))
 	{
@@ -66,21 +65,19 @@  __lll_lock_elision (int *lock, short *adapt_count, EXTRAARG int pshared)
 	  /* A persistent failure indicates that a retry will probably
 	     result in another failure.  Use normal locking now and
 	     for the next couple of calls.  */
-	  if (try_begin-- <= 0
-	      || _TEXASRU_FAILURE_PERSISTENT (__builtin_get_texasru ()))
+	  if (_TEXASRU_FAILURE_PERSISTENT (__builtin_get_texasru ()))
 	    {
 	      if (aconf.skip_lock_internal_abort > 0)
 		*adapt_count = aconf.skip_lock_internal_abort;
 	      goto use_lock;
 	    }
-	  /* Same logic as above, but for for a number of temporary failures
-	     in a row.  */
-	  else if (aconf.skip_lock_out_of_tbegin_retries > 0
-                   && aconf.try_tbegin > 0)
-	    *adapt_count = aconf.skip_lock_out_of_tbegin_retries;
 	}
      }
 
+  /* Fall back to locks for a bit if retries have been exhausted */
+  if (aconf.try_tbegin > 0 && aconf.skip_lock_out_of_tbegin_retries > 0)
+    *adapt_count = aconf.skip_lock_out_of_tbegin_retries;
+
 use_lock:
   return LLL_LOCK ((*lock), pshared);
 }