Add __glibc_unlikely hint in lll_trylock, lll_cond_trylock.

Message ID 4adc080f-9975-4ee0-003e-675f3c9f1203@linux.vnet.ibm.com
State Committed
Headers

Commit Message

Stefan Liebler Dec. 13, 2016, 8:54 a.m. UTC
  Hi,

the macros lll_trylock, lll_cond_trylock are extended by a
__glibc_unlikely hint. Now the trylock macros are based on the
same assumption about a free/busy lock as lll_lock.
With the hint gcc emits code in e.g. pthread_mutex_trylock which does
not use jumps if the lock is free.  Without the hint it had to jump away
if the lock is free.

Tested on s390x, ppc.

Okay to commit?

Bye
Stefan

ChangeLog:

	* sysdeps/nptl/lowlevellock.h (lll_trylock, lll_cond_trylock):
	Add __glibc_unlikely hint.
  

Comments

Stefan Liebler Feb. 6, 2017, 7:49 a.m. UTC | #1
On 12/13/2016 09:54 AM, Stefan Liebler wrote:
> Hi,
>
> the macros lll_trylock, lll_cond_trylock are extended by a
> __glibc_unlikely hint. Now the trylock macros are based on the
> same assumption about a free/busy lock as lll_lock.
> With the hint gcc emits code in e.g. pthread_mutex_trylock which does
> not use jumps if the lock is free.  Without the hint it had to jump away
> if the lock is free.
>
> Tested on s390x, ppc.
>
> Okay to commit?
>
> Bye
> Stefan
>
> ChangeLog:
>
>     * sysdeps/nptl/lowlevellock.h (lll_trylock, lll_cond_trylock):
>     Add __glibc_unlikely hint.

ping
  
Siddhesh Poyarekar Feb. 6, 2017, 8:33 a.m. UTC | #2
On Tuesday 13 December 2016 02:24 PM, Stefan Liebler wrote:
> Hi,
> 
> the macros lll_trylock, lll_cond_trylock are extended by a
> __glibc_unlikely hint. Now the trylock macros are based on the
> same assumption about a free/busy lock as lll_lock.
> With the hint gcc emits code in e.g. pthread_mutex_trylock which does
> not use jumps if the lock is free.  Without the hint it had to jump away
> if the lock is free.
> 
> Tested on s390x, ppc.
> 
> Okay to commit?

Yes, looks good.

Siddhesh
  
Stefan Liebler Feb. 6, 2017, 12:49 p.m. UTC | #3
On 02/06/2017 09:33 AM, Siddhesh Poyarekar wrote:
> On Tuesday 13 December 2016 02:24 PM, Stefan Liebler wrote:
>> Hi,
>>
>> the macros lll_trylock, lll_cond_trylock are extended by a
>> __glibc_unlikely hint. Now the trylock macros are based on the
>> same assumption about a free/busy lock as lll_lock.
>> With the hint gcc emits code in e.g. pthread_mutex_trylock which does
>> not use jumps if the lock is free.  Without the hint it had to jump away
>> if the lock is free.
>>
>> Tested on s390x, ppc.
>>
>> Okay to commit?
>
> Yes, looks good.
>
> Siddhesh
>
Thanks. Committed.
  

Patch

commit 2e11862aaf6d563518780a470b97b59a6e0b2717
Author: Stefan Liebler <stli@linux.vnet.ibm.com>
Date:   Tue Dec 13 09:14:09 2016 +0100

    Add __glibc_unlikely hint in lll_trylock, lll_cond_trylock.
    
    The macros lll_trylock, lll_cond_trylock are extended by an __glibc_unlikely
    hint. Now the trylock macros are based on the same assumption about a
    free/busy lock as lll_lock.
    With the hint gcc emits code in e.g. pthread_mutex_trylock which does
    not use jumps if the lock is free.  Without the hint it had to jump away
    if the lock is free.
    
    Tested on s390x, ppc.
    
    ChangeLog:
    
    	* sysdeps/nptl/lowlevellock.h (lll_trylock, lll_cond_trylock):
    	Add __glibc_unlikely hint.

diff --git a/sysdeps/nptl/lowlevellock.h b/sysdeps/nptl/lowlevellock.h
index 3890145..b77043b 100644
--- a/sysdeps/nptl/lowlevellock.h
+++ b/sysdeps/nptl/lowlevellock.h
@@ -64,13 +64,13 @@ 
    0.  Otherwise leave lock unchanged and return non-zero to indicate that the
    lock was not acquired.  */
 #define lll_trylock(lock)	\
-  atomic_compare_and_exchange_bool_acq (&(lock), 1, 0)
+  __glibc_unlikely (atomic_compare_and_exchange_bool_acq (&(lock), 1, 0))
 
 /* If LOCK is 0 (not acquired), set to 2 (acquired, possibly with waiters) and
    return 0.  Otherwise leave lock unchanged and return non-zero to indicate
    that the lock was not acquired.  */
 #define lll_cond_trylock(lock)	\
-  atomic_compare_and_exchange_bool_acq (&(lock), 2, 0)
+  __glibc_unlikely (atomic_compare_and_exchange_bool_acq (&(lock), 2, 0))
 
 extern void __lll_lock_wait_private (int *futex) attribute_hidden;
 extern void __lll_lock_wait (int *futex, int private) attribute_hidden;