diff options
author | Florian Weimer <fweimer@redhat.com> | 2021-02-23 14:59:34 +0100 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2021-02-23 14:59:34 +0100 |
commit | 5a664d7ae8e42d641a7b4b436987ff67ab483b08 (patch) | |
tree | d2530831e3613ab86b5f536341304ac8cc98f452 /sysdeps/unix/sysv | |
parent | 597d0267b5c4a925f0175837ec09df9f77e0a250 (diff) | |
download | glibc-5a664d7ae8e42d641a7b4b436987ff67ab483b08.tar glibc-5a664d7ae8e42d641a7b4b436987ff67ab483b08.tar.gz glibc-5a664d7ae8e42d641a7b4b436987ff67ab483b08.tar.bz2 glibc-5a664d7ae8e42d641a7b4b436987ff67ab483b08.zip |
nptl: Move elision implementations into libc
The elision interfaces are closely aligned between the targets that
implement them, so declare them in the generic <lowlevellock.h>
file.
Empty .c stubs are provided, so that fewer makefile updates
under sysdeps are needed. Also simplify initialization via
__libc_early_init.
The symbols __lll_clocklock_elision, __lll_lock_elision,
__lll_trylock_elision, __lll_unlock_elision, __pthread_force_elision
move into libc. For the time being, non-hidden references are used
from libpthread to access them, but once that part of libpthread
is moved into libc, hidden symbols will be used again. (Hidden
references seem desirable to reduce the likelihood of transactions
aborts.)
Diffstat (limited to 'sysdeps/unix/sysv')
36 files changed, 24 insertions, 684 deletions
diff --git a/sysdeps/unix/sysv/linux/powerpc/Makefile b/sysdeps/unix/sysv/linux/powerpc/Makefile index cc2f804d86..a093cda68b 100644 --- a/sysdeps/unix/sysv/linux/powerpc/Makefile +++ b/sysdeps/unix/sysv/linux/powerpc/Makefile @@ -32,7 +32,5 @@ endif ifeq ($(subdir),nptl) libpthread-routines += sysdep -libpthread-sysdep_routines += elision-lock elision-unlock elision-timed \ - elision-trylock libpthread-shared-only-routines += sysdep endif diff --git a/sysdeps/unix/sysv/linux/powerpc/elision-conf.c b/sysdeps/unix/sysv/linux/powerpc/elision-conf.c index 003bc82343..1ecc2a7b8f 100644 --- a/sysdeps/unix/sysv/linux/powerpc/elision-conf.c +++ b/sysdeps/unix/sysv/linux/powerpc/elision-conf.c @@ -51,12 +51,6 @@ struct elision_config __elision_aconf = .skip_trylock_internal_abort = 3, }; -/* Force elision for all new locks. This is used to decide whether existing - DEFAULT locks should be automatically use elision in pthread_mutex_lock(). - Disabled for suid programs. Only used when elision is available. */ - -int __pthread_force_elision attribute_hidden = 0; - #if HAVE_TUNABLES static inline void __always_inline @@ -104,10 +98,8 @@ TUNABLE_CALLBACK_FNDECL (skip_trylock_internal_abort, int32_t); /* Initialize elision. */ -static void -elision_init (int argc __attribute__ ((unused)), - char **argv __attribute__ ((unused)), - char **environ) +void +__lll_elision_init (void) { #if HAVE_TUNABLES /* Elision depends on tunables and must be explicitly turned on by setting @@ -150,17 +142,3 @@ elision_init (int argc __attribute__ ((unused)), if (!__pthread_force_elision) __elision_aconf.try_tbegin = 0; /* Disable elision on rwlocks. */ } - -#ifdef SHARED -# define INIT_SECTION ".init_array" -# define MAYBE_CONST -#else -# define INIT_SECTION ".preinit_array" -# define MAYBE_CONST const -#endif - -void (*MAYBE_CONST __pthread_init_array []) (int, char **, char **) - __attribute__ ((section (INIT_SECTION), aligned (sizeof (void *)))) = -{ - &elision_init -}; diff --git a/sysdeps/unix/sysv/linux/powerpc/elision-conf.h b/sysdeps/unix/sysv/linux/powerpc/elision-conf.h index 8c444d8695..86c677fb7a 100644 --- a/sysdeps/unix/sysv/linux/powerpc/elision-conf.h +++ b/sysdeps/unix/sysv/linux/powerpc/elision-conf.h @@ -22,6 +22,9 @@ #include <pthread.h> #include <time.h> +#define ENABLE_ELISION_SUPPORT 1 +#define ELISION_UNLOCK_NEEDS_ADAPT_COUNT 1 + /* Should make sure there is no false sharing on this. */ struct elision_config { @@ -34,9 +37,4 @@ struct elision_config extern struct elision_config __elision_aconf attribute_hidden; -extern int __pthread_force_elision attribute_hidden; - -/* Tell the test suite to test elision for this architecture. */ -#define HAVE_ELISION 1 - #endif diff --git a/sysdeps/unix/sysv/linux/powerpc/elision-lock.c b/sysdeps/unix/sysv/linux/powerpc/elision-lock.c index 767d439f88..f5fb46df25 100644 --- a/sysdeps/unix/sysv/linux/powerpc/elision-lock.c +++ b/sysdeps/unix/sysv/linux/powerpc/elision-lock.c @@ -23,12 +23,6 @@ #include <elision-conf.h> #include "htm.h" -#if !defined(LLL_LOCK) && !defined(EXTRAARG) -/* Make sure the configuration code is always linked in for static - libraries. */ -#include "elision-conf.c" -#endif - #ifndef EXTRAARG # define EXTRAARG #endif @@ -84,3 +78,4 @@ __lll_lock_elision (int *lock, short *adapt_count, EXTRAARG int pshared) use_lock: return LLL_LOCK ((*lock), pshared); } +libc_hidden_def (__lll_lock_elision) diff --git a/sysdeps/unix/sysv/linux/powerpc/elision-trylock.c b/sysdeps/unix/sysv/linux/powerpc/elision-trylock.c index ab92f4d72f..5ebbced427 100644 --- a/sysdeps/unix/sysv/linux/powerpc/elision-trylock.c +++ b/sysdeps/unix/sysv/linux/powerpc/elision-trylock.c @@ -67,3 +67,4 @@ __lll_trylock_elision (int *futex, short *adapt_count) use_lock: return lll_trylock (*futex); } +libc_hidden_def (__lll_trylock_elision) diff --git a/sysdeps/unix/sysv/linux/powerpc/elision-unlock.c b/sysdeps/unix/sysv/linux/powerpc/elision-unlock.c index 35044af40b..5aa87521c5 100644 --- a/sysdeps/unix/sysv/linux/powerpc/elision-unlock.c +++ b/sysdeps/unix/sysv/linux/powerpc/elision-unlock.c @@ -41,3 +41,4 @@ __lll_unlock_elision (int *lock, short *adapt_count, int pshared) } return 0; } +libc_hidden_def (__lll_unlock_elision) diff --git a/sysdeps/unix/sysv/linux/powerpc/force-elision.h b/sysdeps/unix/sysv/linux/powerpc/force-elision.h deleted file mode 100644 index d1fa611c52..0000000000 --- a/sysdeps/unix/sysv/linux/powerpc/force-elision.h +++ /dev/null @@ -1,62 +0,0 @@ -/* force-elision.h: Automatic enabling of elision for mutexes - Copyright (C) 2015-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -/* Automatically enable elision for existing user lock kinds. */ -#define FORCE_ELISION(m, s) \ - if (__pthread_force_elision) \ - { \ - /* See concurrency notes regarding __kind in \ - struct __pthread_mutex_s in \ - sysdeps/nptl/bits/thread-shared-types.h. \ - \ - There are the following cases for the kind of a mutex \ - (The mask PTHREAD_MUTEX_ELISION_FLAGS_NP covers the flags \ - PTHREAD_MUTEX_ELISION_NP and PTHREAD_MUTEX_NO_ELISION_NP where \ - only one of both flags can be set): \ - - both flags are not set: \ - This is the first lock operation for this mutex. Enable \ - elision as it is not enabled so far. \ - Note: It can happen that multiple threads are calling e.g. \ - pthread_mutex_lock at the same time as the first lock \ - operation for this mutex. Then elision is enabled for this \ - mutex by multiple threads. Storing with relaxed MO is enough \ - as all threads will store the same new value for the kind of \ - the mutex. But we have to ensure that we always use the \ - elision path regardless if this thread has enabled elision or \ - another one. \ - \ - - PTHREAD_MUTEX_ELISION_NP flag is set: \ - Elision was already enabled for this mutex by a previous lock \ - operation. See case above. Just use the elision path. \ - \ - - PTHREAD_MUTEX_NO_ELISION_NP flag is set: \ - Elision was explicitly disabled by pthread_mutexattr_settype. \ - Do not use the elision path. \ - Note: The flag PTHREAD_MUTEX_NO_ELISION_NP will never be \ - changed after mutex initialization. */ \ - int mutex_kind = atomic_load_relaxed (&((m)->__data.__kind)); \ - if ((mutex_kind & PTHREAD_MUTEX_ELISION_FLAGS_NP) == 0) \ - { \ - mutex_kind |= PTHREAD_MUTEX_ELISION_NP; \ - atomic_store_relaxed (&((m)->__data.__kind), mutex_kind); \ - } \ - if ((mutex_kind & PTHREAD_MUTEX_ELISION_NP) != 0) \ - { \ - s; \ - } \ - } diff --git a/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h b/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h deleted file mode 100644 index 65962020c6..0000000000 --- a/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h +++ /dev/null @@ -1,49 +0,0 @@ -/* PowerPC specific lock definitions. - Copyright (C) 2015-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#ifndef _POWERPC_LOWLEVELLOCK_H -#define _POWERPC_LOWLEVELLOCK_H 1 - -#include <sysdeps/nptl/lowlevellock.h> - -/* Transactional lock elision definitions. */ -extern int __lll_clocklock_elision - (int *futex, short *adapt_count, - clockid_t clockid, const struct __timespec64 *timeout, int private) - attribute_hidden; - -#define lll_clocklock_elision(futex, adapt_count, clockid, timeout, private) \ - __lll_clocklock_elision (&(futex), &(adapt_count), clockid, timeout, private) - -extern int __lll_lock_elision (int *futex, short *adapt_count, int private) - attribute_hidden; - -extern int __lll_unlock_elision (int *lock, short *adapt_count, int private) - attribute_hidden; - -extern int __lll_trylock_elision(int *lock, short *adapt_count) - attribute_hidden; - -#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), &(adapt_count), private) -#define lll_trylock_elision(futex, adapt_count) \ - __lll_trylock_elision (&(futex), &(adapt_count)) - -#endif diff --git a/sysdeps/unix/sysv/linux/powerpc/pthread_mutex_cond_lock.c b/sysdeps/unix/sysv/linux/powerpc/pthread_mutex_cond_lock.c deleted file mode 100644 index f33bac7ca1..0000000000 --- a/sysdeps/unix/sysv/linux/powerpc/pthread_mutex_cond_lock.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (C) 2015-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -/* The cond lock is not actually elided yet, but we still need to handle - already elided locks. */ -#include <elision-conf.h> - -#include <nptl/pthread_mutex_cond_lock.c> diff --git a/sysdeps/unix/sysv/linux/powerpc/pthread_mutex_lock.c b/sysdeps/unix/sysv/linux/powerpc/pthread_mutex_lock.c deleted file mode 100644 index 110a6bf47b..0000000000 --- a/sysdeps/unix/sysv/linux/powerpc/pthread_mutex_lock.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Elided version of pthread_mutex_lock. - Copyright (C) 2015-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <elision-conf.h> -#include <force-elision.h> - -#include <nptl/pthread_mutex_lock.c> diff --git a/sysdeps/unix/sysv/linux/powerpc/pthread_mutex_timedlock.c b/sysdeps/unix/sysv/linux/powerpc/pthread_mutex_timedlock.c deleted file mode 100644 index 6f8b06d459..0000000000 --- a/sysdeps/unix/sysv/linux/powerpc/pthread_mutex_timedlock.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Elided version of pthread_mutex_timedlock. - Copyright (C) 2015-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <elision-conf.h> -#include <force-elision.h> - -#include <nptl/pthread_mutex_timedlock.c> diff --git a/sysdeps/unix/sysv/linux/powerpc/pthread_mutex_trylock.c b/sysdeps/unix/sysv/linux/powerpc/pthread_mutex_trylock.c deleted file mode 100644 index ee9fe1d186..0000000000 --- a/sysdeps/unix/sysv/linux/powerpc/pthread_mutex_trylock.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Elided version of pthread_mutex_trylock. - Copyright (C) 2015-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <elision-conf.h> -#include <force-elision.h> - -#include <nptl/pthread_mutex_trylock.c> diff --git a/sysdeps/unix/sysv/linux/s390/Makefile b/sysdeps/unix/sysv/linux/s390/Makefile index d9db1b5422..3de9579e23 100644 --- a/sysdeps/unix/sysv/linux/s390/Makefile +++ b/sysdeps/unix/sysv/linux/s390/Makefile @@ -12,9 +12,6 @@ gen-as-const-headers += ucontext_i.sym endif ifeq ($(subdir),nptl) -libpthread-sysdep_routines += elision-lock elision-unlock elision-timed \ - elision-trylock - elision-CFLAGS = -mhtm -msoft-float CFLAGS-elision-lock.c = $(elision-CFLAGS) CFLAGS-elision-timed.c = $(elision-CFLAGS) diff --git a/sysdeps/unix/sysv/linux/s390/elision-conf.c b/sysdeps/unix/sysv/linux/s390/elision-conf.c index c05c046e56..a7a90e73eb 100644 --- a/sysdeps/unix/sysv/linux/s390/elision-conf.c +++ b/sysdeps/unix/sysv/linux/s390/elision-conf.c @@ -51,13 +51,6 @@ struct elision_config __elision_aconf = .skip_trylock_internal_abort = 3, }; -/* Force elision for all new locks. This is used to decide whether existing - DEFAULT locks should be automatically upgraded to elision in - pthread_mutex_lock(). Disabled for suid programs. Only used when elision - is available. */ - -int __pthread_force_elision attribute_hidden = 0; - #if HAVE_TUNABLES static inline void __always_inline @@ -104,10 +97,8 @@ TUNABLE_CALLBACK_FNDECL (skip_trylock_internal_abort, int32_t); /* Initialize elison. */ -static void -elision_init (int argc __attribute__ ((unused)), - char **argv __attribute__ ((unused)), - char **environ) +void +__lll_elision_init (void) { #if HAVE_TUNABLES /* Elision depends on tunables and must be explicitly turned on by setting @@ -130,17 +121,3 @@ elision_init (int argc __attribute__ ((unused)), if (!__pthread_force_elision) __elision_aconf.try_tbegin = 0; /* Disable elision on rwlocks. */ } - -#ifdef SHARED -# define INIT_SECTION ".init_array" -# define MAYBE_CONST -#else -# define INIT_SECTION ".preinit_array" -# define MAYBE_CONST const -#endif - -void (*MAYBE_CONST __pthread_init_array []) (int, char **, char **) - __attribute__ ((section (INIT_SECTION), aligned (sizeof (void *)))) = -{ - &elision_init -}; diff --git a/sysdeps/unix/sysv/linux/s390/elision-conf.h b/sysdeps/unix/sysv/linux/s390/elision-conf.h index 846c5ff297..cb8a784ad0 100644 --- a/sysdeps/unix/sysv/linux/s390/elision-conf.h +++ b/sysdeps/unix/sysv/linux/s390/elision-conf.h @@ -21,6 +21,9 @@ #include <pthread.h> #include <time.h> +#define ENABLE_ELISION_SUPPORT 1 +#define ELISION_UNLOCK_NEEDS_ADAPT_COUNT 1 + /* Should make sure there is no false sharing on this. */ struct elision_config @@ -34,9 +37,4 @@ struct elision_config extern struct elision_config __elision_aconf attribute_hidden; -extern int __pthread_force_elision attribute_hidden; - -/* Tell the test suite to test elision for this architecture. */ -#define HAVE_ELISION 1 - #endif diff --git a/sysdeps/unix/sysv/linux/s390/elision-lock.c b/sysdeps/unix/sysv/linux/s390/elision-lock.c index 26474c6398..d5dd6023a0 100644 --- a/sysdeps/unix/sysv/linux/s390/elision-lock.c +++ b/sysdeps/unix/sysv/linux/s390/elision-lock.c @@ -23,12 +23,6 @@ #include <elision-conf.h> #include <stdint.h> -#if !defined(LLL_LOCK) && !defined(EXTRAARG) -/* Make sure the configuration code is always linked in for static - libraries. */ -#include "elision-conf.c" -#endif - #ifndef EXTRAARG #define EXTRAARG #endif @@ -123,3 +117,4 @@ __lll_lock_elision (int *futex, short *adapt_count, EXTRAARG int private) succeed. */ return LLL_LOCK ((*futex), private); } +libc_hidden_def (__lll_lock_elision) diff --git a/sysdeps/unix/sysv/linux/s390/elision-trylock.c b/sysdeps/unix/sysv/linux/s390/elision-trylock.c index 484c3cc913..2470955c89 100644 --- a/sysdeps/unix/sysv/linux/s390/elision-trylock.c +++ b/sysdeps/unix/sysv/linux/s390/elision-trylock.c @@ -95,3 +95,4 @@ __lll_trylock_elision (int *futex, short *adapt_count) succeed. */ return lll_trylock (*futex); } +libc_hidden_def (__lll_trylock_elision) diff --git a/sysdeps/unix/sysv/linux/s390/elision-unlock.c b/sysdeps/unix/sysv/linux/s390/elision-unlock.c index 5ac6758df2..87a5bd7cbf 100644 --- a/sysdeps/unix/sysv/linux/s390/elision-unlock.c +++ b/sysdeps/unix/sysv/linux/s390/elision-unlock.c @@ -59,3 +59,4 @@ __lll_unlock_elision(int *futex, short *adapt_count, int private) } return 0; } +libc_hidden_def (__lll_unlock_elision) diff --git a/sysdeps/unix/sysv/linux/s390/force-elision.h b/sysdeps/unix/sysv/linux/s390/force-elision.h deleted file mode 100644 index 154740d37f..0000000000 --- a/sysdeps/unix/sysv/linux/s390/force-elision.h +++ /dev/null @@ -1,62 +0,0 @@ -/* Automatic enabling of elision for mutexes - Copyright (C) 2014-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -/* Automatically enable elision for existing user lock kinds. */ -#define FORCE_ELISION(m, s) \ - if (__pthread_force_elision) \ - { \ - /* See concurrency notes regarding __kind in \ - struct __pthread_mutex_s in \ - sysdeps/nptl/bits/thread-shared-types.h. \ - \ - There are the following cases for the kind of a mutex \ - (The mask PTHREAD_MUTEX_ELISION_FLAGS_NP covers the flags \ - PTHREAD_MUTEX_ELISION_NP and PTHREAD_MUTEX_NO_ELISION_NP where \ - only one of both flags can be set): \ - - both flags are not set: \ - This is the first lock operation for this mutex. Enable \ - elision as it is not enabled so far. \ - Note: It can happen that multiple threads are calling e.g. \ - pthread_mutex_lock at the same time as the first lock \ - operation for this mutex. Then elision is enabled for this \ - mutex by multiple threads. Storing with relaxed MO is enough \ - as all threads will store the same new value for the kind of \ - the mutex. But we have to ensure that we always use the \ - elision path regardless if this thread has enabled elision or \ - another one. \ - \ - - PTHREAD_MUTEX_ELISION_NP flag is set: \ - Elision was already enabled for this mutex by a previous lock \ - operation. See case above. Just use the elision path. \ - \ - - PTHREAD_MUTEX_NO_ELISION_NP flag is set: \ - Elision was explicitly disabled by pthread_mutexattr_settype. \ - Do not use the elision path. \ - Note: The flag PTHREAD_MUTEX_NO_ELISION_NP will never be \ - changed after mutex initialization. */ \ - int mutex_kind = atomic_load_relaxed (&((m)->__data.__kind)); \ - if ((mutex_kind & PTHREAD_MUTEX_ELISION_FLAGS_NP) == 0) \ - { \ - mutex_kind |= PTHREAD_MUTEX_ELISION_NP; \ - atomic_store_relaxed (&((m)->__data.__kind), mutex_kind); \ - } \ - if ((mutex_kind & PTHREAD_MUTEX_ELISION_NP) != 0) \ - { \ - s; \ - } \ - } diff --git a/sysdeps/unix/sysv/linux/s390/lowlevellock.h b/sysdeps/unix/sysv/linux/s390/lowlevellock.h deleted file mode 100644 index 98d78f5270..0000000000 --- a/sysdeps/unix/sysv/linux/s390/lowlevellock.h +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (C) 2003-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#ifndef _S390_LOWLEVELLOCK_H -#define _S390_LOWLEVELLOCK_H 1 - -#include <sysdeps/nptl/lowlevellock.h> - -/* Transactional lock elision definitions. */ -extern int __lll_clocklock_elision - (int *futex, short *adapt_count, - clockid_t clockid, const struct __timespec64 *timeout, int private) - attribute_hidden; - -# define lll_clocklock_elision(futex, adapt_count, clockid, timeout, private) \ - __lll_clocklock_elision (&(futex), &(adapt_count), clockid, timeout, private) - -extern int __lll_lock_elision (int *futex, short *adapt_count, int private) - attribute_hidden; - -extern int __lll_unlock_elision(int *futex, short *adapt_count, int private) - attribute_hidden; - -extern int __lll_trylock_elision(int *futex, short *adapt_count) - attribute_hidden; - -# 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), &(adapt_count), private) -# define lll_trylock_elision(futex, adapt_count) \ - __lll_trylock_elision(&(futex), &(adapt_count)) - -#endif /* lowlevellock.h */ diff --git a/sysdeps/unix/sysv/linux/s390/pthread_mutex_cond_lock.c b/sysdeps/unix/sysv/linux/s390/pthread_mutex_cond_lock.c deleted file mode 100644 index 8398ff6425..0000000000 --- a/sysdeps/unix/sysv/linux/s390/pthread_mutex_cond_lock.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (C) 2014-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -/* The cond lock is not actually elided yet, but we still need to handle - already elided locks. */ -#include <elision-conf.h> - -#include <nptl/pthread_mutex_cond_lock.c> diff --git a/sysdeps/unix/sysv/linux/s390/pthread_mutex_lock.c b/sysdeps/unix/sysv/linux/s390/pthread_mutex_lock.c deleted file mode 100644 index b193b5b2b0..0000000000 --- a/sysdeps/unix/sysv/linux/s390/pthread_mutex_lock.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Elided version of pthread_mutex_lock. - Copyright (C) 2014-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <elision-conf.h> -#include <force-elision.h> - -#include <nptl/pthread_mutex_lock.c> diff --git a/sysdeps/unix/sysv/linux/s390/pthread_mutex_timedlock.c b/sysdeps/unix/sysv/linux/s390/pthread_mutex_timedlock.c deleted file mode 100644 index 8538f157a0..0000000000 --- a/sysdeps/unix/sysv/linux/s390/pthread_mutex_timedlock.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Elided version of pthread_mutex_timedlock. - Copyright (C) 2014-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <elision-conf.h> -#include <force-elision.h> - -#include <nptl/pthread_mutex_timedlock.c> diff --git a/sysdeps/unix/sysv/linux/s390/pthread_mutex_trylock.c b/sysdeps/unix/sysv/linux/s390/pthread_mutex_trylock.c deleted file mode 100644 index c4de1363cb..0000000000 --- a/sysdeps/unix/sysv/linux/s390/pthread_mutex_trylock.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Elided version of pthread_mutex_trylock. - Copyright (C) 2014-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <elision-conf.h> -#include <force-elision.h> - -#include <nptl/pthread_mutex_trylock.c> diff --git a/sysdeps/unix/sysv/linux/x86/Makefile b/sysdeps/unix/sysv/linux/x86/Makefile index 6bfd6bec49..9dfdd689a9 100644 --- a/sysdeps/unix/sysv/linux/x86/Makefile +++ b/sysdeps/unix/sysv/linux/x86/Makefile @@ -12,8 +12,6 @@ sysdep_headers += sys/elf.h sys/perm.h sys/reg.h sys/vm86.h sys/debugreg.h sys/i endif ifeq ($(subdir),nptl) -libpthread-sysdep_routines += elision-lock elision-unlock elision-timed \ - elision-trylock CFLAGS-elision-lock.c += -mrtm CFLAGS-elision-unlock.c += -mrtm CFLAGS-elision-timed.c += -mrtm diff --git a/sysdeps/unix/sysv/linux/x86/elision-conf.c b/sysdeps/unix/sysv/linux/x86/elision-conf.c index e8ffe022f0..a5a4043d15 100644 --- a/sysdeps/unix/sysv/linux/x86/elision-conf.c +++ b/sysdeps/unix/sysv/linux/x86/elision-conf.c @@ -48,13 +48,6 @@ struct elision_config __elision_aconf = .skip_trylock_internal_abort = 3, }; -/* Force elision for all new locks. This is used to decide whether existing - DEFAULT locks should be automatically upgraded to elision in - pthread_mutex_lock(). Disabled for suid programs. Only used when elision - is available. */ - -int __pthread_force_elision attribute_hidden = 0; - #if HAVE_TUNABLES static __always_inline void do_set_elision_enable (int32_t elision_enable) @@ -98,10 +91,8 @@ TUNABLE_CALLBACK_FNDECL (skip_trylock_internal_abort, int32_t); /* Initialize elision. */ -static void -elision_init (int argc __attribute__ ((unused)), - char **argv __attribute__ ((unused)), - char **environ) +void +__lll_elision_init (void) { #if HAVE_TUNABLES /* Elision depends on tunables and must be explicitly turned on by setting @@ -122,15 +113,3 @@ elision_init (int argc __attribute__ ((unused)), if (!__pthread_force_elision) __elision_aconf.retry_try_xbegin = 0; /* Disable elision on rwlocks. */ } - -#ifdef SHARED -# define INIT_SECTION ".init_array" -#else -# define INIT_SECTION ".preinit_array" -#endif - -void (*const __pthread_init_array []) (int, char **, char **) - __attribute__ ((section (INIT_SECTION), aligned (sizeof (void *)))) = -{ - &elision_init -}; diff --git a/sysdeps/unix/sysv/linux/x86/elision-conf.h b/sysdeps/unix/sysv/linux/x86/elision-conf.h index bc5e73bd10..6016820312 100644 --- a/sysdeps/unix/sysv/linux/x86/elision-conf.h +++ b/sysdeps/unix/sysv/linux/x86/elision-conf.h @@ -21,6 +21,9 @@ #include <pthread.h> #include <time.h> +#define ENABLE_ELISION_SUPPORT 1 +#define ELISION_UNLOCK_NEEDS_ADAPT_COUNT 0 + /* Should make sure there is no false sharing on this. */ struct elision_config @@ -33,9 +36,4 @@ struct elision_config extern struct elision_config __elision_aconf attribute_hidden; -extern int __pthread_force_elision attribute_hidden; - -/* Tell the test suite to test elision for this architecture. */ -#define HAVE_ELISION 1 - #endif diff --git a/sysdeps/unix/sysv/linux/x86/elision-lock.c b/sysdeps/unix/sysv/linux/x86/elision-lock.c index 16d4f6e4f1..ea5f373c67 100644 --- a/sysdeps/unix/sysv/linux/x86/elision-lock.c +++ b/sysdeps/unix/sysv/linux/x86/elision-lock.c @@ -22,12 +22,6 @@ #include "hle.h" #include <elision-conf.h> -#if !defined(LLL_LOCK) && !defined(EXTRAARG) -/* Make sure the configuration code is always linked in for static - libraries. */ -#include "elision-conf.c" -#endif - #ifndef EXTRAARG #define EXTRAARG #endif @@ -105,3 +99,4 @@ __lll_lock_elision (int *futex, short *adapt_count, EXTRAARG int private) /* Use a normal lock here. */ return LLL_LOCK ((*futex), private); } +libc_hidden_def (__lll_lock_elision) diff --git a/sysdeps/unix/sysv/linux/x86/elision-trylock.c b/sysdeps/unix/sysv/linux/x86/elision-trylock.c index ef9aa23819..5e689f577f 100644 --- a/sysdeps/unix/sysv/linux/x86/elision-trylock.c +++ b/sysdeps/unix/sysv/linux/x86/elision-trylock.c @@ -73,3 +73,4 @@ __lll_trylock_elision (int *futex, short *adapt_count) return lll_trylock (*futex); } +libc_hidden_def (__lll_trylock_elision) diff --git a/sysdeps/unix/sysv/linux/x86/elision-unlock.c b/sysdeps/unix/sysv/linux/x86/elision-unlock.c index edd8b1fd08..eb877bc18c 100644 --- a/sysdeps/unix/sysv/linux/x86/elision-unlock.c +++ b/sysdeps/unix/sysv/linux/x86/elision-unlock.c @@ -31,3 +31,4 @@ __lll_unlock_elision(int *lock, int private) lll_unlock ((*lock), private); return 0; } +libc_hidden_def (__lll_unlock_elision) diff --git a/sysdeps/unix/sysv/linux/x86/force-elision.h b/sysdeps/unix/sysv/linux/x86/force-elision.h deleted file mode 100644 index 3c0a0e0ac5..0000000000 --- a/sysdeps/unix/sysv/linux/x86/force-elision.h +++ /dev/null @@ -1,62 +0,0 @@ -/* force-elision.h: Automatic enabling of elision for mutexes - Copyright (C) 2013-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -/* Automatically enable elision for existing user lock kinds. */ -#define FORCE_ELISION(m, s) \ - if (__pthread_force_elision) \ - { \ - /* See concurrency notes regarding __kind in \ - struct __pthread_mutex_s in \ - sysdeps/nptl/bits/thread-shared-types.h. \ - \ - There are the following cases for the kind of a mutex \ - (The mask PTHREAD_MUTEX_ELISION_FLAGS_NP covers the flags \ - PTHREAD_MUTEX_ELISION_NP and PTHREAD_MUTEX_NO_ELISION_NP where \ - only one of both flags can be set): \ - - both flags are not set: \ - This is the first lock operation for this mutex. Enable \ - elision as it is not enabled so far. \ - Note: It can happen that multiple threads are calling e.g. \ - pthread_mutex_lock at the same time as the first lock \ - operation for this mutex. Then elision is enabled for this \ - mutex by multiple threads. Storing with relaxed MO is enough \ - as all threads will store the same new value for the kind of \ - the mutex. But we have to ensure that we always use the \ - elision path regardless if this thread has enabled elision or \ - another one. \ - \ - - PTHREAD_MUTEX_ELISION_NP flag is set: \ - Elision was already enabled for this mutex by a previous lock \ - operation. See case above. Just use the elision path. \ - \ - - PTHREAD_MUTEX_NO_ELISION_NP flag is set: \ - Elision was explicitly disabled by pthread_mutexattr_settype. \ - Do not use the elision path. \ - Note: The flag PTHREAD_MUTEX_NO_ELISION_NP will never be \ - changed after mutex initialization. */ \ - int mutex_kind = atomic_load_relaxed (&((m)->__data.__kind)); \ - if ((mutex_kind & PTHREAD_MUTEX_ELISION_FLAGS_NP) == 0) \ - { \ - mutex_kind |= PTHREAD_MUTEX_ELISION_NP; \ - atomic_store_relaxed (&((m)->__data.__kind), mutex_kind); \ - } \ - if ((mutex_kind & PTHREAD_MUTEX_ELISION_NP) != 0) \ - { \ - s; \ - } \ - } diff --git a/sysdeps/unix/sysv/linux/x86/lowlevellock.h b/sysdeps/unix/sysv/linux/x86/lowlevellock.h index 435a190ec9..7205bcadfd 100644 --- a/sysdeps/unix/sysv/linux/x86/lowlevellock.h +++ b/sysdeps/unix/sysv/linux/x86/lowlevellock.h @@ -82,30 +82,6 @@ __lll_cas_lock (int *futex) __lll_unlock (&(lock), private); \ })) -extern int __lll_clocklock_elision (int *futex, short *adapt_count, - clockid_t clockid, - const struct __timespec64 *timeout, - int private) attribute_hidden; - -#define lll_clocklock_elision(futex, adapt_count, clockid, timeout, private) \ - __lll_clocklock_elision (&(futex), &(adapt_count), clockid, timeout, private) - -extern int __lll_lock_elision (int *futex, short *adapt_count, int private) - attribute_hidden; - -extern int __lll_unlock_elision (int *lock, int private) - attribute_hidden; - -extern int __lll_trylock_elision (int *lock, short *adapt_count) - attribute_hidden; - -#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) -#define lll_trylock_elision(futex, adapt_count) \ - __lll_trylock_elision (&(futex), &(adapt_count)) - #endif /* !__ASSEMBLER__ */ #endif /* lowlevellock.h */ diff --git a/sysdeps/unix/sysv/linux/x86/pthread_mutex_cond_lock.c b/sysdeps/unix/sysv/linux/x86/pthread_mutex_cond_lock.c deleted file mode 100644 index 7604f8706f..0000000000 --- a/sysdeps/unix/sysv/linux/x86/pthread_mutex_cond_lock.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (C) 2013-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -/* The cond lock is not actually elided yet, but we still need to handle - already elided locks. */ -#include <elision-conf.h> - -#include <nptl/pthread_mutex_cond_lock.c> diff --git a/sysdeps/unix/sysv/linux/x86/pthread_mutex_lock.c b/sysdeps/unix/sysv/linux/x86/pthread_mutex_lock.c deleted file mode 100644 index 6e5f1f9964..0000000000 --- a/sysdeps/unix/sysv/linux/x86/pthread_mutex_lock.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Elided version of pthread_mutex_lock. - Copyright (C) 2011-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <elision-conf.h> -#include "force-elision.h" - -#include "nptl/pthread_mutex_lock.c" diff --git a/sysdeps/unix/sysv/linux/x86/pthread_mutex_timedlock.c b/sysdeps/unix/sysv/linux/x86/pthread_mutex_timedlock.c deleted file mode 100644 index 3fbfe02690..0000000000 --- a/sysdeps/unix/sysv/linux/x86/pthread_mutex_timedlock.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Elided version of pthread_mutex_timedlock. - Copyright (C) 2011-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <elision-conf.h> -#include "force-elision.h" - -#include "nptl/pthread_mutex_timedlock.c" diff --git a/sysdeps/unix/sysv/linux/x86/pthread_mutex_trylock.c b/sysdeps/unix/sysv/linux/x86/pthread_mutex_trylock.c deleted file mode 100644 index c7abb5ad4f..0000000000 --- a/sysdeps/unix/sysv/linux/x86/pthread_mutex_trylock.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Elided version of pthread_mutex_trylock. - Copyright (C) 2011-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <elision-conf.h> -#include "force-elision.h" - -#include "nptl/pthread_mutex_trylock.c" |