GNU C Library master sources
Find a file
Frank Barrus 1db84775f8 pthreads NPTL: lost wakeup fix 2
This fixes the lost wakeup (from a bug in signal stealing) with a change
in the usage of g_signals[] in the condition variable internal state.
It also completely eliminates the concept and handling of signal stealing,
as well as the need for signalers to block to wait for waiters to wake
up every time there is a G1/G2 switch.  This greatly reduces the average
and maximum latency for pthread_cond_signal.

The g_signals[] field now contains a signal count that is relative to
the current g1_start value.  Since it is a 32-bit field, and the LSB is
still reserved (though not currently used anymore), it has a 31-bit value
that corresponds to the low 31 bits of the sequence number in g1_start.
(since g1_start also has an LSB flag, this means bits 31:1 in g_signals
correspond to bits 31:1 in g1_start, plus the current signal count)

By making the signal count relative to g1_start, there is no longer
any ambiguity or A/B/A issue, and thus any checks before blocking,
including the futex call itself, are guaranteed not to block if the G1/G2
switch occurs, even if the signal count remains the same.  This allows
initially safely blocking in G2 until the switch to G1 occurs, and
then transitioning from G1 to a new G1 or G2, and always being able to
distinguish the state change.  This removes the race condition and A/B/A
problems that otherwise ocurred if a late (pre-empted) waiter were to
resume just as the futex call attempted to block on g_signal since
otherwise there was no last opportunity to re-check things like whether
the current G1 group was already closed.

By fixing these issues, the signal stealing code can be eliminated,
since there is no concept of signal stealing anymore.  The code to block
for all waiters to exit g_refs can also be removed, since any waiters
that are still in the g_refs region can be guaranteed to safely wake
up and exit.  If there are still any left at this time, they are all
sent one final futex wakeup to ensure that they are not blocked any
longer, but there is no need for the signaller to block and wait for
them to wake up and exit the g_refs region.

The signal count is then effectively "zeroed" but since it is now
relative to g1_start, this is done by advancing it to a new value that
can be observed by any pending blocking waiters.  Any late waiters can
always tell the difference, and can thus just cleanly exit if they are
in a stale G1 or G2.  They can never steal a signal from the current
G1 if they are not in the current G1, since the signal value that has
to match in the cmpxchg has the low 31 bits of the g1_start value
contained in it, and that's first checked, and then it won't match if
there's a G1/G2 change.

Note: the 31-bit sequence number used in g_signals is designed to
handle wrap-around when checking the signal count, but if the entire
31-bit wraparound (2 billion signals) occurs while there is still a
late waiter that has not yet resumed, and it happens to then match
the current g1_start low bits, and the pre-emption occurs after the
normal "closed group" checks (which are 64-bit) but then hits the
futex syscall and signal consuming code, then an A/B/A issue could
still result and cause an incorrect assumption about whether it
should block.  This particular scenario seems unlikely in practice.
Note that once awake from the futex, the waiter would notice the
closed group before consuming the signal (since that's still a 64-bit
check that would not be aliased in the wrap-around in g_signals),
so the biggest impact would be blocking on the futex until the next
full wakeup from a G1/G2 switch.

Signed-off-by: Frank Barrus <frankbarrus_sw@shaggy.cc>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2025-01-17 14:56:58 -05:00
advisories Document CVE-2024-33599, CVE-2024-33600, CVE-2024-33601, CVE-2024-33602 2024-05-06 15:12:31 -04:00
argp Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
assert assert: Remove the use of %n from __assert_fail_base (BZ #32456) 2025-01-02 10:19:42 -03:00
benchtests benchtests: Add dummy in put files cospi, cospif, sinpi, sinpif, tanpi, tanpif 2025-01-16 19:59:58 +01:00
bits AArch64: Add vector tanpi routines 2025-01-03 21:39:56 +00:00
catgets Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
ChangeLog.old Add ChangeLog file 2024-07-21 18:33:37 +02:00
conform conform: Do not use __SIG_ATOMIC_TYPE__ 2025-01-03 09:53:53 -03:00
csu Consolidate TLS block allocation for static binaries with ld.so 2025-01-16 20:02:42 +01:00
ctype Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
debug Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
dirent Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
dlfcn Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
elf Consolidate TLS block allocation for static binaries with ld.so 2025-01-16 20:02:42 +01:00
gmon gmon: Disable tst-profile-static with clang 2025-01-13 10:17:42 -03:00
gnulib Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
hesiod Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
htl htl: Fix making pthread_join check timeout value 2025-01-07 01:02:20 +01:00
hurd hurd: Add CLOCK_MONOTONIC support to lll 2025-01-12 22:47:00 +01:00
iconv Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
iconvdata Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
include include/string.h: Also redirect calls if not inlined in libpthread 2025-01-07 20:53:18 +01:00
inet inet: Add common IPv6 packet header macros 2025-01-13 10:54:38 -03:00
intl Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
io Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
libio Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
locale Update copyright dates not handled by scripts/update-copyrights 2025-01-01 11:22:09 -08:00
localedata Update copyright dates not handled by scripts/update-copyrights 2025-01-01 11:22:09 -08:00
login Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
mach mach: Add missing error messages 2025-01-14 22:41:03 +01:00
malloc malloc: obscure calloc use in tst-calloc 2025-01-10 03:57:06 +00:00
manual Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
math AArch64: Add vector tanpi routines 2025-01-03 21:39:56 +00:00
mathvec Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
misc mlock, mlock2, munlock: Use __attr_access_none macro 2025-01-02 17:58:06 +00:00
nis Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
nptl pthreads NPTL: lost wakeup fix 2 2025-01-17 14:56:58 -05:00
nptl_db Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
nscd Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
nss Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
po Regenerate libc.pot 2025-01-04 11:05:03 +01:00
posix Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
resolv Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
resource Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
rt Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
scripts Don't update copyright notices in Linux licenses 2025-01-01 12:16:24 -08:00
setjmp Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
signal Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
socket socket/tst-cmsghdr: Fix alignment of cmsghdr 2025-01-12 15:57:26 +01:00
soft-fp Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
stdio-common stdio-common: Suppress Clang warnings on scanf13.c with fortify enable 2025-01-13 10:53:08 -03:00
stdlib Linux: Fixes for getrandom fork handling 2025-01-16 19:58:09 +01:00
string Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
sunrpc Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
support tst-xdirent: Fix allocating dirent for readdir_r call 2025-01-07 01:56:41 +01:00
sysdeps math: update arm ulps 2025-01-17 19:36:22 +00:00
sysvipc Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
termios Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
time Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
timezone Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
wcsmbs Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
wctype Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
.b4-config Add .b4-config file 2024-10-21 14:26:42 +01:00
.clang-format Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
.gitattributes Assume __NR_openat is always defined 2016-03-23 23:35:08 +01:00
.gitignore Add *.pyc to .gitignore 2015-05-18 15:26:26 +05:30
abi-tags Remove the bulk of the NaCl port. 2017-05-20 08:09:10 -04:00
aclocal.m4 Use -finput-charset=ascii only if supported 2024-12-22 12:42:02 +08:00
config.h.in mach: Add CLOCK_MONOTONIC case in clock_gettime() 2025-01-12 22:47:00 +01:00
config.make.in manual: add syscalls 2024-07-09 11:54:29 +02:00
configure configure: Clear libc_cv_cc_wimplicit_fallthrough if not supported 2025-01-10 09:07:05 +08:00
configure.ac configure: Clear libc_cv_cc_wimplicit_fallthrough if not supported 2025-01-10 09:07:05 +08:00
CONTRIBUTED-BY crypt: Remove libcrypt support 2023-10-30 13:03:59 -03:00
COPYING Update to latest versions of GPL-2.0 and LGPL-2.1 2013-09-09 12:52:48 +10:00
COPYING.LIB Update to latest versions of GPL-2.0 and LGPL-2.1 2013-09-09 12:52:48 +10:00
extra-lib.mk Rename cppflags-iterator.mk to libof-iterator.mk, remove extra-modules.mk. 2017-05-09 07:06:29 -04:00
gen-locales.mk locale: Handle loading a missing locale twice (Bug 14247) 2024-04-22 16:03:00 -04:00
INSTALL INSTALL, NEWS: Document requirement of gawk with MPFR support 2024-12-30 17:03:36 +01:00
libc-abis riscv: support GNU indirect function 2021-01-10 21:25:13 -05:00
libof-iterator.mk Rename cppflags-iterator.mk to libof-iterator.mk, remove extra-modules.mk. 2017-05-09 07:06:29 -04:00
LICENSES added url of CORE-MATH project 2024-12-18 17:24:43 -03:00
MAINTAINERS Add MAINTAINERS 2017-05-11 13:38:30 -04:00
Makeconfig Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
Makefile Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
Makefile.help Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
Makefile.in Rename have-mtls-descriptor to have-test-mtls-descriptor 2025-01-04 04:51:21 +08:00
Makerules Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
NEWS Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
o-iterator.mk Fri Mar 17 12:58:37 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> 1995-03-17 18:42:51 +00:00
README Remove ia64-linux-gnu 2024-01-08 17:09:36 -03:00
Rules Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
SECURITY.md Adapt the security policy for the security page 2023-12-05 09:15:10 -05:00
SHARED-FILES math: Use tanhf from CORE-MATH 2024-12-18 17:24:43 -03:00
shlib-versions crypt: Remove libcrypt support 2023-10-30 13:03:59 -03:00
test-skeleton.c Update copyright dates with scripts/update-copyrights 2025-01-01 11:22:09 -08:00
version.h Increase version number to 2.40.9000 2024-07-21 18:49:35 +02:00

This directory contains the sources of the GNU C Library.
See the file "version.h" for what release version you have.

The GNU C Library is the standard system C library for all GNU systems,
and is an important part of what makes up a GNU system.  It provides the
system API for all programs written in C and C-compatible languages such
as C++ and Objective C; the runtime facilities of other programming
languages use the C library to access the underlying operating system.

In GNU/Linux systems, the C library works with the Linux kernel to
implement the operating system behavior seen by user applications.
In GNU/Hurd systems, it works with a microkernel and Hurd servers.

The GNU C Library implements much of the POSIX.1 functionality in the
GNU/Hurd system, using configurations i[4567]86-*-gnu and x86_64-gnu.

When working with Linux kernels, this version of the GNU C Library
requires Linux kernel version 3.2 or later.

Also note that the shared version of the libgcc_s library must be
installed for the pthread library to work correctly.

The GNU C Library supports these configurations for using Linux kernels:

	aarch64*-*-linux-gnu
	alpha*-*-linux-gnu
	arc*-*-linux-gnu
	arm-*-linux-gnueabi
	csky-*-linux-gnuabiv2
	hppa-*-linux-gnu
	i[4567]86-*-linux-gnu
	x86_64-*-linux-gnu	Can build either x86_64 or x32
	loongarch64-*-linux-gnu Hardware floating point, LE only.
	m68k-*-linux-gnu
	microblaze*-*-linux-gnu
	mips-*-linux-gnu
	mips64-*-linux-gnu
	or1k-*-linux-gnu
	powerpc-*-linux-gnu	Hardware or software floating point, BE only.
	powerpc64*-*-linux-gnu	Big-endian and little-endian.
	s390-*-linux-gnu
	s390x-*-linux-gnu
	riscv32-*-linux-gnu
	riscv64-*-linux-gnu
	sh[34]-*-linux-gnu
	sparc*-*-linux-gnu
	sparc64*-*-linux-gnu

If you are interested in doing a port, please contact the glibc
maintainers; see https://www.gnu.org/software/libc/ for more
information.

See the file INSTALL to find out how to configure, build, and install
the GNU C Library.  You might also consider reading the WWW pages for
the C library at https://www.gnu.org/software/libc/.

The GNU C Library is (almost) completely documented by the Texinfo manual
found in the `manual/' subdirectory.  The manual is still being updated
and contains some known errors and omissions; we regret that we do not
have the resources to work on the manual as much as we would like.  For
corrections to the manual, please file a bug in the `manual' component,
following the bug-reporting instructions below.  Please be sure to check
the manual in the current development sources to see if your problem has
already been corrected.

Please see https://www.gnu.org/software/libc/bugs.html for bug reporting
information.  We are now using the Bugzilla system to track all bug reports.
This web page gives detailed information on how to report bugs properly.

The GNU C Library is free software.  See the file COPYING.LIB for copying
conditions, and LICENSES for notices about a few contributions that require
these additional notices to be distributed.  License copyright years may be
listed using range notation, e.g., 1996-2015, indicating that every year in
the range, inclusive, is a copyrightable year that would otherwise be listed
individually.