From e8c659d74e011346785355eeef03b7fb6f533c61 Mon Sep 17 00:00:00 2001 From: Andi Kleen Date: Sat, 22 Dec 2012 01:03:04 -0800 Subject: Add elision to pthread_mutex_{try,timed,un}lock Add elision paths to the basic mutex locks. The normal path has a check for RTM and upgrades the lock to RTM when available. Trylocks cannot automatically upgrade, so they check for elision every time. We use a 4 byte value in the mutex to store the lock elision adaptation state. This is separate from the adaptive spin state and uses a separate field. Condition variables currently do not support elision. Recursive mutexes and condition variables may be supported at some point, but are not in the current implementation. Also "trylock" will not automatically enable elision unless some other lock call has been already called on the lock. This version does not use IFUNC, so it means every lock has one additional check for elision. Benchmarking showed the overhead to be negligible. --- nptl/sysdeps/unix/sysv/linux/x86/bits/pthreadtypes.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'nptl/sysdeps/unix/sysv/linux/x86/bits/pthreadtypes.h') diff --git a/nptl/sysdeps/unix/sysv/linux/x86/bits/pthreadtypes.h b/nptl/sysdeps/unix/sysv/linux/x86/bits/pthreadtypes.h index ccd896ca03..1852e07842 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86/bits/pthreadtypes.h +++ b/nptl/sysdeps/unix/sysv/linux/x86/bits/pthreadtypes.h @@ -101,14 +101,23 @@ typedef union binary compatibility. */ int __kind; #ifdef __x86_64__ - int __spins; + short __spins; + short __elision; __pthread_list_t __list; # define __PTHREAD_MUTEX_HAVE_PREV 1 +# define __PTHREAD_MUTEX_HAVE_ELISION 1 #else unsigned int __nusers; __extension__ union { - int __spins; + struct + { + short __espins; + short __elision; +# define __spins d.__espins +# define __elision d.__elision +# define __PTHREAD_MUTEX_HAVE_ELISION 2 + } d; __pthread_slist_t __list; }; #endif -- cgit 1.4.1