glibc/sysdeps/sh
Torvald Riegel ed19993b5b New condvar implementation that provides stronger ordering guarantees.
This is a new implementation for condition variables, required
after http://austingroupbugs.net/view.php?id=609 to fix bug 13165.  In
essence, we need to be stricter in which waiters a signal or broadcast
is required to wake up; this couldn't be solved using the old algorithm.
ISO C++ made a similar clarification, so this also fixes a bug in
current libstdc++, for example.

We can't use the old algorithm anymore because futexes do not guarantee
to wake in FIFO order.  Thus, when we wake, we can't simply let any
waiter grab a signal, but we need to ensure that one of the waiters
happening before the signal is woken up.  This is something the previous
algorithm violated (see bug 13165).

There's another issue specific to condvars: ABA issues on the underlying
futexes.  Unlike mutexes that have just three states, or semaphores that
have no tokens or a limited number of them, the state of a condvar is
the *order* of the waiters.  A waiter on a semaphore can grab a token
whenever one is available; a condvar waiter must only consume a signal
if it is eligible to do so as determined by the relative order of the
waiter and the signal.
Therefore, this new algorithm maintains two groups of waiters: Those
eligible to consume signals (G1), and those that have to wait until
previous waiters have consumed signals (G2).  Once G1 is empty, G2
becomes the new G1.  64b counters are used to avoid ABA issues.

This condvar doesn't yet use a requeue optimization (ie, on a broadcast,
waking just one thread and requeueing all others on the futex of the
mutex supplied by the program).  I don't think doing the requeue is
necessarily the right approach (but I haven't done real measurements
yet):
* If a program expects to wake many threads at the same time and make
that scalable, a condvar isn't great anyway because of how it requires
waiters to operate mutually exclusive (due to the mutex usage).  Thus, a
thundering herd problem is a scalability problem with or without the
optimization.  Using something like a semaphore might be more
appropriate in such a case.
* The scalability problem is actually at the mutex side; the condvar
could help (and it tries to with the requeue optimization), but it
should be the mutex who decides how that is done, and whether it is done
at all.
* Forcing all but one waiter into the kernel-side wait queue of the
mutex prevents/avoids the use of lock elision on the mutex.  Thus, it
prevents the only cure against the underlying scalability problem
inherent to condvars.
* If condvars use short critical sections (ie, hold the mutex just to
check a binary flag or such), which they should do ideally, then forcing
all those waiter to proceed serially with kernel-based hand-off (ie,
futex ops in the mutex' contended state, via the futex wait queues) will
be less efficient than just letting a scalable mutex implementation take
care of it.  Our current mutex impl doesn't employ spinning at all, but
if critical sections are short, spinning can be much better.
* Doing the requeue stuff requires all waiters to always drive the mutex
into the contended state.  This leads to each waiter having to call
futex_wake after lock release, even if this wouldn't be necessary.

	[BZ #13165]
	* nptl/pthread_cond_broadcast.c (__pthread_cond_broadcast): Rewrite to
	use new algorithm.
	* nptl/pthread_cond_destroy.c (__pthread_cond_destroy): Likewise.
	* nptl/pthread_cond_init.c (__pthread_cond_init): Likewise.
	* nptl/pthread_cond_signal.c (__pthread_cond_signal): Likewise.
	* nptl/pthread_cond_wait.c (__pthread_cond_wait): Likewise.
	(__pthread_cond_timedwait): Move here from pthread_cond_timedwait.c.
	(__condvar_confirm_wakeup, __condvar_cancel_waiting,
	__condvar_cleanup_waiting, __condvar_dec_grefs,
	__pthread_cond_wait_common): New.
	(__condvar_cleanup): Remove.
	* npt/pthread_condattr_getclock.c (pthread_condattr_getclock): Adapt.
	* npt/pthread_condattr_setclock.c (pthread_condattr_setclock):
	Likewise.
	* npt/pthread_condattr_getpshared.c (pthread_condattr_getpshared):
	Likewise.
	* npt/pthread_condattr_init.c (pthread_condattr_init): Likewise.
	* nptl/tst-cond1.c: Add comment.
	* nptl/tst-cond20.c (do_test): Adapt.
	* nptl/tst-cond22.c (do_test): Likewise.
	* sysdeps/aarch64/nptl/bits/pthreadtypes.h (pthread_cond_t): Adapt
	structure.
	* sysdeps/arm/nptl/bits/pthreadtypes.h (pthread_cond_t): Likewise.
	* sysdeps/ia64/nptl/bits/pthreadtypes.h (pthread_cond_t): Likewise.
	* sysdeps/m68k/nptl/bits/pthreadtypes.h (pthread_cond_t): Likewise.
	* sysdeps/microblaze/nptl/bits/pthreadtypes.h (pthread_cond_t):
	Likewise.
	* sysdeps/mips/nptl/bits/pthreadtypes.h (pthread_cond_t): Likewise.
	* sysdeps/nios2/nptl/bits/pthreadtypes.h (pthread_cond_t): Likewise.
	* sysdeps/s390/nptl/bits/pthreadtypes.h (pthread_cond_t): Likewise.
	* sysdeps/sh/nptl/bits/pthreadtypes.h (pthread_cond_t): Likewise.
	* sysdeps/tile/nptl/bits/pthreadtypes.h (pthread_cond_t): Likewise.
	* sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h (pthread_cond_t):
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h (pthread_cond_t):
	Likewise.
	* sysdeps/x86/bits/pthreadtypes.h (pthread_cond_t): Likewise.
	* sysdeps/nptl/internaltypes.h (COND_NWAITERS_SHIFT): Remove.
	(COND_CLOCK_BITS): Adapt.
	* sysdeps/nptl/pthread.h (PTHREAD_COND_INITIALIZER): Adapt.
	* nptl/pthreadP.h (__PTHREAD_COND_CLOCK_MONOTONIC_MASK,
	__PTHREAD_COND_SHARED_MASK): New.
	* nptl/nptl-printers.py (CLOCK_IDS): Remove.
	(ConditionVariablePrinter, ConditionVariableAttributesPrinter): Adapt.
	* nptl/nptl_lock_constants.pysym: Adapt.
	* nptl/test-cond-printers.py: Adapt.
	* sysdeps/unix/sysv/linux/hppa/internaltypes.h (cond_compat_clear,
	cond_compat_check_and_clear): Adapt.
	* sysdeps/unix/sysv/linux/hppa/pthread_cond_timedwait.c: Remove file ...
	* sysdeps/unix/sysv/linux/hppa/pthread_cond_wait.c
	(__pthread_cond_timedwait): ... and move here.
	* nptl/DESIGN-condvar.txt: Remove file.
	* nptl/lowlevelcond.sym: Likewise.
	* nptl/pthread_cond_timedwait.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/i486/pthread_cond_broadcast.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/i586/pthread_cond_broadcast.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/i586/pthread_cond_signal.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/i586/pthread_cond_timedwait.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/i586/pthread_cond_wait.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/i686/pthread_cond_broadcast.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/i686/pthread_cond_signal.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/i686/pthread_cond_timedwait.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/i686/pthread_cond_wait.S: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S: Likewise.
2016-12-31 14:56:47 +01:00
..
bits Add femode_t functions. 2016-09-07 16:40:09 +00:00
nptl New condvar implementation that provides stronger ordering guarantees. 2016-12-31 14:56:47 +01:00
sh3 Add missing hidden_def (__sigsetjmp). 2016-12-01 20:49:25 +00:00
sh4 Add missing hidden_def (__sigsetjmp). 2016-12-01 20:49:25 +00:00
soft-fp soft-fp: support after-rounding tininess detection. 2014-02-12 18:27:12 +00:00
Implies Make soft-float sh use soft-fp fma/fmaf. 2013-12-17 09:00:05 +09:00
Makefile Move SH code out of nptl/ subdirectory. 2014-06-12 09:05:54 -07:00
____longjmp_chk.S Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
_mcount.S Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
abort-instr.h SH: ABORT_INSTRUCTION. 2012-06-23 11:47:39 +02:00
backtrace.c Yet more ia64 removal fallout 2012-01-07 11:44:02 -05:00
bsd-_setjmp.S Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
bsd-setjmp.S Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
configure rename configure.in to configure.ac 2013-10-30 17:32:08 +10:00
configure.ac rename configure.in to configure.ac 2013-10-30 17:32:08 +10:00
crti.S Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
crtn.S Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
dl-machine.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
dl-tls.h elf: Consolidate machine-agnostic DTV definitions in <dl-dtv.h> 2016-06-20 14:31:40 +02:00
dl-trampoline.S Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
fpu_control.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
gccframe.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
gmp-mparam.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
jmpbuf-offsets.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
jmpbuf-unwind.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
ldsodefs.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
libc-tls.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
libm-test-ulps Don't include individual test ulps in libm-test-ulps. 2014-03-05 15:02:38 +00:00
libm-test-ulps-name Do not hardcode platform names in manual/libm-err-tab.pl (bug 14139). 2016-11-04 16:49:06 +00:00
linkmap.h Rename bits/linkmap.h to linkmap.h (bug 14912). 2015-09-04 19:44:27 +00:00
machine-gmon.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
math_private.h math: add LDBL_CLASSIFY_COMPAT support 2015-12-03 13:00:46 -05:00
memcpy.S Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
memset.S Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
memusage.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
preconfigure Move base_machine and machine settings from configure.ac to sysdeps preconfigure fragments. 2014-06-25 17:52:56 +00:00
s_fma.c Make soft-float sh use soft-fp fma/fmaf. 2013-12-17 09:00:05 +09:00
s_fmaf.c Make soft-float sh use soft-fp fma/fmaf. 2013-12-17 09:00:05 +09:00
sotruss-lib.c Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
stackguard-macros.h Add SH implementation of stackguard-macros.h. 2013-09-27 10:59:02 +09:00
stackinfo.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
start.S Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
strlen.S Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
sysdep.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00
tininess.h Fix strtod handling of underflow (bug 14047). 2012-10-30 13:51:27 +00:00
tls-macros.h Split tls-macros.h into sysdeps directories. 2012-07-17 11:30:58 +00:00
tst-audit.h Update copyright dates with scripts/update-copyrights. 2016-01-04 16:05:18 +00:00