Skip to content

Commit

Permalink
Add elision tunables
Browse files Browse the repository at this point in the history
This patch adds several new tunables to control the behavior of
elision on supported platforms[1].   Since elision now depends
on tunables, we should always *compile* with elision enabled,
and leave the code disabled, but available for runtime
selection.  This gives us *much* better compile-time testing of
the existing code to avoid bit-rot[2].

Tested on ppc, ppc64, ppc64le, s390x and x86_64.

[1] This part of the patch was initially proposed by
Paul Murphy but was "staled" because the framework have changed
since the patch was originally proposed:

https://patchwork.sourceware.org/patch/10342/

[2] This part of the patch was inititally proposed as a RFC by
Carlos O'Donnell.  Make sense to me integrate this on the patch:

https://sourceware.org/ml/libc-alpha/2017-05/msg00335.html

	* elf/dl-tunables.list: Add elision parameters.
	* manual/tunables.texi: Add entries about elision tunable.
	* sysdeps/unix/sysv/linux/powerpc/elision-conf.c:
	Add callback functions to dynamically enable/disable elision.
	Add multiple callbacks functions to set elision parameters.
	Deleted __libc_enable_secure check.
	* sysdeps/unix/sysv/linux/s390/elision-conf.c: Likewise.
	* sysdeps/unix/sysv/linux/x86/elision-conf.c: Likewise.
	* configure: Regenerated.
	* configure.ac: Option enable_lock_elision was deleted.
	* config.h.in: ENABLE_LOCK_ELISION flag was deleted.
	* config.make.in: Remove references to enable_lock_elision.
	* manual/install.texi: Elision configure option was removed.
	* INSTALL: Regenerated to remove enable_lock_elision.
	* nptl/Makefile:
	Disable elision so it can verify error case for destroying a mutex.
	* sysdeps/powerpc/nptl/elide.h:
	Cleanup ENABLE_LOCK_ELISION check.
	Deleted macros for the case when ENABLE_LOCK_ELISION was not defined.
	* sysdeps/s390/configure: Regenerated.
	* sysdeps/s390/configure.ac: Remove references to enable_lock_elision..
	* nptl/tst-mutex8.c:
	Deleted all #ifndef ENABLE_LOCK_ELISION from the test.
	* sysdeps/powerpc/powerpc32/sysdep.h:
	Deleted all ENABLE_LOCK_ELISION checks.
	* sysdeps/powerpc/powerpc64/sysdep.h: Likewise.
	* sysdeps/powerpc/sysdep.h: Likewise.
	* sysdeps/s390/nptl/bits/pthreadtypes-arch.h: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/force-elision.h: Likewise.
	* sysdeps/unix/sysv/linux/s390/elision-conf.h: Likewise.
	* sysdeps/unix/sysv/linux/s390/force-elision.h: Likewise.
	* sysdeps/unix/sysv/linux/s390/lowlevellock.h: Likewise.
	* sysdeps/unix/sysv/linux/s390/Makefile: Remove references to
	enable-lock-elision.

Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>
  • Loading branch information
Rogerio Alves authored and tuliom committed Dec 5, 2017
1 parent a5a2a76 commit 07ed18d
Show file tree
Hide file tree
Showing 26 changed files with 357 additions and 94 deletions.
39 changes: 39 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
2017-12-05 Rogerio A. Cardoso <rcardoso@linux.vnet.ibm.com>,
Paul E. Murphy <murphyp@linux.vnet.ibm.com>,
Carlos O'Donnell <carlos@redhat.com>

* elf/dl-tunables.list: Add elision parameters.
* manual/tunables.texi: Add entries about elision tunable.
* sysdeps/unix/sysv/linux/powerpc/elision-conf.c:
Add callback functions to dynamically enable/disable elision.
Add multiple callbacks functions to set elision parameters.
Deleted __libc_enable_secure check.
* sysdeps/unix/sysv/linux/s390/elision-conf.c: Likewise.
* sysdeps/unix/sysv/linux/x86/elision-conf.c: Likewise.
* configure: Regenerated.
* configure.ac: Option enable_lock_elision was deleted.
* config.h.in: ENABLE_LOCK_ELISION flag was deleted.
* config.make.in: Remove references to enable_lock_elision.
* manual/install.texi: Elision configure option was removed.
* INSTALL: Regenerated to remove enable_lock_elision.
* nptl/Makefile:
Disable elision so it can verify error case for destroying a mutex.
* sysdeps/powerpc/nptl/elide.h:
Cleanup ENABLE_LOCK_ELISION check.
Deleted macros for the case when ENABLE_LOCK_ELISION was not defined.
* sysdeps/s390/configure: Regenerated.
* sysdeps/s390/configure.ac: Remove references to enable_lock_elision..
* nptl/tst-mutex8.c:
Deleted all #ifndef ENABLE_LOCK_ELISION from the test.
* sysdeps/powerpc/powerpc32/sysdep.h:
Deleted all ENABLE_LOCK_ELISION checks.
* sysdeps/powerpc/powerpc64/sysdep.h: Likewise.
* sysdeps/powerpc/sysdep.h: Likewise.
* sysdeps/s390/nptl/bits/pthreadtypes-arch.h: Likewise.
* sysdeps/unix/sysv/linux/powerpc/force-elision.h: Likewise.
* sysdeps/unix/sysv/linux/s390/elision-conf.h: Likewise.
* sysdeps/unix/sysv/linux/s390/force-elision.h: Likewise.
* sysdeps/unix/sysv/linux/s390/lowlevellock.h: Likewise.
* sysdeps/unix/sysv/linux/s390/Makefile: Remove references to
enable-lock-elision.

2017-12-05 Joseph Myers <joseph@codesourcery.com>

* stdlib/strtod.c: Include <bits/floatn.h>.
Expand Down
3 changes: 0 additions & 3 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ will be used, and CFLAGS sets optimization options for the compiler.
formats may change over time. Consult the 'timezone' subdirectory
for more details.

'--enable-lock-elision=yes'
Enable lock elision for pthread mutexes by default.

'--enable-stack-protector'
'--enable-stack-protector=strong'
'--enable-stack-protector=all'
Expand Down
3 changes: 0 additions & 3 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@
/* Define if __stack_chk_guard canary should be randomized at program startup. */
#undef ENABLE_STACKGUARD_RANDOMIZE

/* Define if lock elision should be enabled by default. */
#undef ENABLE_LOCK_ELISION

/* Package description. */
#undef PKGVERSION

Expand Down
1 change: 0 additions & 1 deletion config.make.in
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ build-nscd = @build_nscd@
use-nscd = @use_nscd@
build-hardcoded-path-in-tests= @hardcoded_path_in_tests@
build-pt-chown = @build_pt_chown@
enable-lock-elision = @enable_lock_elision@
have-tunables = @have_tunables@

# Build tools.
Expand Down
17 changes: 0 additions & 17 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,6 @@ enable_werror
all_warnings
force_install
bindnow
enable_lock_elision
hardcoded_path_in_tests
enable_timezone_tools
use_default_link
Expand Down Expand Up @@ -768,7 +767,6 @@ enable_profile
enable_timezone_tools
enable_hardcoded_path_in_tests
enable_stackguard_randomization
enable_lock_elision
enable_hidden_plt
enable_bind_now
enable_stack_protector
Expand Down Expand Up @@ -1428,8 +1426,6 @@ Optional Features:
--enable-stackguard-randomization
initialize __stack_chk_guard canary with a random
number at program start
--enable-lock-elision=yes/no
Enable lock elision for pthread mutexes by default
--disable-hidden-plt do not hide internal function calls to avoid PLT
--enable-bind-now disable lazy relocations in DSOs
--enable-stack-protector=[yes|no|all|strong]
Expand Down Expand Up @@ -3395,19 +3391,6 @@ if test "$enable_stackguard_randomize" = yes; then

fi

# Check whether --enable-lock-elision was given.
if test "${enable_lock_elision+set}" = set; then :
enableval=$enable_lock_elision; enable_lock_elision=$enableval
else
enable_lock_elision=no
fi


if test "$enable_lock_elision" = yes ; then
$as_echo "#define ENABLE_LOCK_ELISION 1" >>confdefs.h

fi

# Check whether --enable-hidden-plt was given.
if test "${enable_hidden_plt+set}" = set; then :
enableval=$enable_hidden_plt; hidden=$enableval
Expand Down
10 changes: 0 additions & 10 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,6 @@ if test "$enable_stackguard_randomize" = yes; then
AC_DEFINE(ENABLE_STACKGUARD_RANDOMIZE)
fi

AC_ARG_ENABLE([lock-elision],
AC_HELP_STRING([--enable-lock-elision[=yes/no]],
[Enable lock elision for pthread mutexes by default]),
[enable_lock_elision=$enableval],
[enable_lock_elision=no])
AC_SUBST(enable_lock_elision)
if test "$enable_lock_elision" = yes ; then
AC_DEFINE(ENABLE_LOCK_ELISION)
fi

AC_ARG_ENABLE([hidden-plt],
AC_HELP_STRING([--disable-hidden-plt],
[do not hide internal function calls to avoid PLT]),
Expand Down
34 changes: 34 additions & 0 deletions elf/dl-tunables.list
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,38 @@ glibc {
default: HWCAP_IMPORTANT
}
}

elision {
enable {
type: INT_32
minval: 0
maxval: 1
security_level: SXID_ERASE
}
skip_lock_busy {
type: INT_32
default: 3
security_level: SXID_ERASE
}
skip_lock_internal_abort {
type: INT_32
default: 3
security_level: SXID_ERASE
}
skip_lock_after_retries {
type: INT_32
default: 3
security_level: SXID_ERASE
}
tries {
type: INT_32
default: 3
security_level: SXID_ERASE
}
skip_trylock_internal_abort {
type: INT_32
default: 3
security_level: SXID_ERASE
}
}
}
3 changes: 0 additions & 3 deletions manual/install.texi
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ Note that you need to make sure the external tools are kept in sync with
the versions that @theglibc{} expects as the data formats may change over
time. Consult the @file{timezone} subdirectory for more details.

@item --enable-lock-elision=yes
Enable lock elision for pthread mutexes by default.

@item --enable-stack-protector
@itemx --enable-stack-protector=strong
@itemx --enable-stack-protector=all
Expand Down
69 changes: 69 additions & 0 deletions manual/tunables.texi
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ their own namespace.
@menu
* Tunable names:: The structure of a tunable name
* Memory Allocation Tunables:: Tunables in the memory allocation subsystem
* Elision Tunables:: Tunables in elision subsystem
* Hardware Capability Tunables:: Tunables that modify the hardware
capabilities seen by @theglibc{}
@end menu
Expand Down Expand Up @@ -212,6 +213,74 @@ pre-fill the per-thread cache with. The default, or when set to zero,
is no limit.
@end deftp

@node Elision Tunables
@section Elision Tunables
@cindex elision tunables
@cindex tunables, elision

@deftp {Tunable namespace} glibc.elision
Contended locks are usually slow and can lead to performance and scalability
issues in multithread code. Lock elision will use memory transactions to under
certain conditions, to elide locks and improve performance.
Elision behavior can be modified by setting the following tunables in
the @code{elision} namespace:
@end deftp

@deftp Tunable glibc.elision.enable
The @code{glibc.elision.enable} tunable enables lock elision if the feature is
supported by the hardware. If elision is not supported by the hardware this
tunable has no effect.

Elision tunables are supported for 64-bit Intel, IBM POWER, and z System
architectures.
@end deftp

@deftp Tunable glibc.elision.skip_lock_busy
The @code{glibc.elision.skip_lock_busy} tunable sets how many times to use a
non-transactional lock after a transactional failure has occurred because the
lock is already acquired. Expressed in number of lock acquisition attempts.

The default value of this tunable is @samp{3}.
@end deftp

@deftp Tunable glibc.elision.skip_lock_internal_abort
The @code{glibc.elision.skip_lock_internal_abort} tunable sets how many times
the thread should avoid using elision if a transaction aborted for any reason
other than a different thread's memory accesses. Expressed in number of lock
acquisition attempts.

The default value of this tunable is @samp{3}.
@end deftp

@deftp Tunable glibc.elision.skip_lock_after_retries
The @code{glibc.elision.skip_lock_after_retries} tunable sets how many times
to try to elide a lock with transactions, that only failed due to a different
thread's memory accesses, before falling back to regular lock.
Expressed in number of lock elision attempts.

This tunable is supported only on IBM POWER, and z System architectures.

The default value of this tunable is @samp{3}.
@end deftp

@deftp Tunable glibc.elision.tries
The @code{glibc.elision.tries} sets how many times to retry elision if there is
chance for the transaction to finish execution e.g., it wasn't
aborted due to the lock being already acquired. If elision is not supported
by the hardware this tunable is set to @samp{0} to avoid retries.

The default value of this tunable is @samp{3}.
@end deftp

@deftp Tunable glibc.elision.skip_trylock_internal_abort
The @code{glibc.elision.skip_trylock_internal_abort} tunable sets how many
times the thread should avoid trying the lock if a transaction aborted due to
reasons other than a different thread's memory accesses. Expressed in number
of try lock attempts.

The default value of this tunable is @samp{3}.
@end deftp

@node Hardware Capability Tunables
@section Hardware Capability Tunables
@cindex hardware capability tunables
Expand Down
4 changes: 4 additions & 0 deletions nptl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,10 @@ endif

$(objpfx)tst-compat-forwarder: $(objpfx)tst-compat-forwarder-mod.so

# Disable elision for tst-mutex8 so it can verify error case for
# destroying a mutex.
tst-mutex8-ENV = GLIBC_TUNABLES=glibc.elision.enable=0

# The tests here better do not run in parallel
ifneq ($(filter %tests,$(MAKECMDGOALS)),)
.NOTPARALLEL:
Expand Down
12 changes: 2 additions & 10 deletions nptl/tst-mutex8.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ check_type (const char *mas, pthread_mutexattr_t *ma)
return 1;
}

/* Elided mutexes don't fail destroy. If elision is not explicitly disabled
we don't know, so can also not check this. */
#ifndef ENABLE_LOCK_ELISION
/* Elided mutexes don't fail destroy, but this test is run with
elision disabled so we can test them. */
e = pthread_mutex_destroy (m);
if (e == 0)
{
Expand All @@ -142,7 +141,6 @@ check_type (const char *mas, pthread_mutexattr_t *ma)
mas);
return 1;
}
#endif

if (pthread_mutex_unlock (m) != 0)
{
Expand All @@ -157,7 +155,6 @@ check_type (const char *mas, pthread_mutexattr_t *ma)
}

/* Elided mutexes don't fail destroy. */
#ifndef ENABLE_LOCK_ELISION
e = pthread_mutex_destroy (m);
if (e == 0)
{
Expand All @@ -171,7 +168,6 @@ mutex_destroy of self-trylocked mutex did not return EBUSY %s\n",
mas);
return 1;
}
#endif

if (pthread_mutex_unlock (m) != 0)
{
Expand Down Expand Up @@ -207,7 +203,6 @@ mutex_destroy of self-trylocked mutex did not return EBUSY %s\n",
}

/* Elided mutexes don't fail destroy. */
#ifndef ENABLE_LOCK_ELISION
e = pthread_mutex_destroy (m);
if (e == 0)
{
Expand All @@ -220,7 +215,6 @@ mutex_destroy of self-trylocked mutex did not return EBUSY %s\n",
mutex_destroy of condvar-used mutex did not return EBUSY for %s\n", mas);
return 1;
}
#endif

done = true;
if (pthread_cond_signal (&c) != 0)
Expand Down Expand Up @@ -280,7 +274,6 @@ mutex_destroy of condvar-used mutex did not return EBUSY for %s\n", mas);
}

/* Elided mutexes don't fail destroy. */
#ifndef ENABLE_LOCK_ELISION
e = pthread_mutex_destroy (m);
if (e == 0)
{
Expand All @@ -295,7 +288,6 @@ mutex_destroy of condvar-used mutex did not return EBUSY for %s\n", mas);
mas);
return 1;
}
#endif

if (pthread_cancel (th) != 0)
{
Expand Down
9 changes: 0 additions & 9 deletions sysdeps/powerpc/nptl/elide.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#ifndef ELIDE_PPC_H
# define ELIDE_PPC_H

#ifdef ENABLE_LOCK_ELISION
# include <htm.h>
# include <elision-conf.h>

Expand Down Expand Up @@ -114,12 +113,4 @@ __elide_unlock (int is_lock_free)
# define ELIDE_UNLOCK(is_lock_free) \
__elide_unlock (is_lock_free)

# else

# define ELIDE_LOCK(adapt_count, is_lock_free) 0
# define ELIDE_TRYLOCK(adapt_count, is_lock_free, write) 0
# define ELIDE_UNLOCK(is_lock_free) 0

#endif /* ENABLE_LOCK_ELISION */

#endif
2 changes: 1 addition & 1 deletion sysdeps/powerpc/powerpc32/sysdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ GOT_LABEL: ; \
cfi_endproc; \
ASM_SIZE_DIRECTIVE(name)

#if ! IS_IN(rtld) && defined (ENABLE_LOCK_ELISION)
#if ! IS_IN(rtld)
# define ABORT_TRANSACTION \
cmpwi 2,0; \
beq 1f; \
Expand Down
2 changes: 1 addition & 1 deletion sysdeps/powerpc/powerpc64/sysdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ LT_LABELSUFFIX(name,_name_end): ; \
TRACEBACK_MASK(name,mask); \
END_2(name)

#if !IS_IN(rtld) && defined (ENABLE_LOCK_ELISION)
#if !IS_IN(rtld)
# define ABORT_TRANSACTION \
cmpdi 13,0; \
beq 1f; \
Expand Down
Loading

0 comments on commit 07ed18d

Please sign in to comment.