227 Commits
Author SHA1 Message Date
Adhemerval Zanella 2b13da5e0e Makerules: add 'make check-parallel' to run tests without serialization
The default 'make check' serializes the timing-sensitive test runs: the
threading (nptl, or htl on Hurd) and realtime (rt) subdirectories run
with .NOTPARALLEL and are ordered after the rest of the test run, so they
are not perturbed by competing machine load.

Add a check-parallel (and xcheck-parallel) variant for when that is not
wanted -- an idle machine, or a run where the extra throughput is worth
the risk of flakiness in the timing-sensitive tests (check the
libc-alpha discussion [1] for more context why this approach was proposed).

A new serialize-tests flag (default yes, defined in Makeconfig) gates both
the per-subdirectory .NOTPARALLEL and the top-level run-time ordering;
check-parallel just runs the suite with serialize-tests=no, so every test
program builds and runs at full concurrency in a single pass.

'make check' and its default behavior are unchanged.

[1] https://inbox.sourceware.org/libc-alpha/lhutsr3khz7.fsf@oldenburg.str.redhat.com/

Reviewed-by: Sam James <sam@gentoo.org>
2026-07-03 13:01:13 -03:00
Adhemerval Zanella 7cac99621e Makefile: Run the subdirectory recursion in parallel
The top-level makefile was marked .NOTPARALLEL and ran the
per-subdirectory sub-makes strictly one at a time in the topological
order computed by scripts/gen-sorted.awk.  Only the compilations inside
a single subdirectory could run in parallel, so on wide machines every
subdirectory's compile tail and link steps left most cores idle, once
per subdirectory per pass.

Drop .NOTPARALLEL and encode the ordering the serial recursion relied
on as explicit dependencies between the per-subdirectory targets:

  * The subdirectories that generate shared files in $(common-objpfx)
    consumed by the rest of the build without explicit dependencies run
    serially, in their sorted order, before the rest fan out: csu
    provides the tree-wide gen-as-const headers, and on Hurd the mach
    and hurd directories generate the MiG RPC headers (every other
    subdirectory otherwise runs a nested make in hurd/ to create them,
    racing under parallel recursion; see sysdeps/mach/hurd/Makefile).
    The first of them also materializes the other shared generated files
    (abi-versions.h, sysd-syscalls, before-compile headers).

  * The edges requested by the Depend files (now emitted by
    gen-sorted.awk as subdir-deps-*) are preserved.  Edges pointing to
    elf are dropped, as the sorted list already overrides them by
    forcing elf last.

  * The tests and xtests classes only run the per-directory test
    programs, which are mutually independent once the others pass has
    built the tree.  They therefore carry only the others pass barrier
    below and none of the csu-first or Depend edges (+ordered_parallel_-
    subdir_targets excludes them); otherwise "make subdir/tests" would
    also run the tests of every subdirectory reachable through those
    edges, rather than just the requested one.

  * elf stays last: its rtld link consumes $(common-objpfx)libc_pic.a,
    which aggregates every other subdirectory's objects, and its
    rtld-Rules recursion compiles into the other subdirectories' object
    directories.

  * Pass barriers replace the implicit pass ordering: others after lib
    (a subdirectory others sub-make would otherwise race to link
    libc.so itself), tests/xtests after others, and the testroot
    install behind others.

  * The threading (nptl, or htl on Hurd) and realtime (rt) tests are
    timing-sensitive and were previously shielded from system load by
    the global .NOTPARALLEL.  With the recursion now parallel, a full
    test run ('make check'/'tests', run-built-tests=yes) orders them
    after the rest of the test run and one group at a time -- the
    threading subdirectory, then rt -- and each serializes its own run
    via a .NOTPARALLEL in its Makefile.  A targeted 'make subdir/tests'
    is not ordered.

    The serialization (the per-subdirectory .NOTPARALLEL and the ordering
    above) constrains only the test run, not the build of the test
    programs; but building and running a subdirectory's tests are fused
    in its sub-make, so under run-built-tests=yes the serialized
    subdirectories would also build their test programs serially.  To
    avoid that, the top-level 'make check' (in Makerules) now runs two
    passes: it builds every test program with run-built-tests=no, where
    the recursion is fully parallel and none of the serialization
    applies, and then runs the tests with run-built-tests=yes.  'make
    tests' and a subdirectory's own 'check' stay single pass.

  * The subdirectory-built files that the top-level libc.so and
    linkobj/libc_pic.a rules list as prerequisites (elf/ld.so,
    interp.os, sofini.os, sunrpc/librpc_compat_pic.a, and on Hurd
    mach/libmachuser_pic.a and hurd/libhurduser_pic.a, from which the
    lib*user-link.so inputs of libc.so are built) get order-only edges
    on the corresponding sub-make with an explicit empty recipe.  A
    prerequisite-only rule would trigger an implicit rule search and
    this level would compile them itself in the wrong context.

  * The install, clean, abi, and stubs target classes keep the
    previous total order via a serial dependency chain.

  * The elf DSO sorting test recipes, run when make remakes the
    included generated makefiles at parse time, create the elf object
    directory before writing into it; the serial recursion no longer
    guarantees another rule created it first.

  * catgets builds locale-specific message catalogs (and tst-catgets
    reads one) by running gencat under de_DE.ISO-8859-1, hr_HR.ISO-8859-2
    and ja_JP.SJIS, but never declared those locales as prerequisites: it
    relied on localedata running before it in the serial order.  Under
    the parallel recursion gencat could run before localedata generated
    the locale, fall back to C, and fail.  catgets/Makefile now pulls the
    locales in via gen-locales.mk, like the other subdirectories that use
    locales in their tests.

Results on a x86_64 machine [1] with default configuration [3]: a
from-scratch build improves from 78.728s to 61s, and check with
run-built-tests=no from 374s to 190s.

On a 80-core aarch64 machine [2] with default configuration [3]: a
from-scratch build improves from 105.251s to 56.703s, and check with
run-built-tests=no from 886.183s to 298.726s.

Build results are unchanged: all 8919 built objects, archives, and
shared objects are bit-identical to the serial build across 7 clean
parallel builds, the installed tree layout is identical, and the
tests.sum failure sets are identical.  i686-gnu was verified with
repeated from-scratch builds.

[1] Ryzen 5900x, 12c/24t, gcc 16.1.1, binutils 2.26, and GNU make 4.3
[2] N1, 80c, gcc 15.1.1, binutils 2.25, GNU make 4.3
[3] --enable-stack-protector=all --enable-bind-now=yes --enable-profile=yes
    --enable-fortify-source=2 --enable-hardcoded-path-in-tests

Reviewed-by: Sam James <sam@gentoo.org>
2026-07-03 12:46:47 -03:00
Samuel Thibault f5ed4272da elf: directly call dl_init_static_tls
htl can now have it directly in ld.so
2026-03-16 05:29:06 +00:00
Samuel Thibault 5f11203d34 mach: Add __mach_rwlock_*
We cannot use pthread_rwlock for these until we have reimplemented
pthread_rwlock with gsync, so fork __libc_rwlock off for now.
2026-03-14 17:59:08 +00:00
Samuel Thibault b874221766 htl: Make sure the exit path of last thread sees all thread cleanups
In case e.g. some atexit() handlers expect all threads to have finished
their side effects.

Reported-by: Brent Baccala <cosine@freesoft.org> 's Claude assistant
2026-03-08 18:19:19 +01:00
Samuel Thibault 15134aabfb htl: Call thread-specific destructors for last thread too
As required by posix.

Reported-by: Brent Baccala <cosine@freesoft.org> 's Claude assistant
2026-03-08 01:10:01 +01:00
Samuel Thibault 4b5a74412e htl: Fix mt-safeness of libio
Since d2e0491883 ("Single threaded stdio optimization")
we are supposed to call _IO_enable_locks when creating the first thread,
but that commit missed doing it for htl.
2026-03-01 17:57:54 +01:00
Samuel Thibault c4a81e882e hurd: Take cancel_lock in critical section
read/write etc. shall be signal-safe, and take cancel_lock, so we have to
defer signal delivery while holding cancel_lock.

Reported-by: Michael Banck <mbanck@gmx.net>
2026-02-05 00:12:29 +01:00
Paul Eggert 66f3e9219d Update copyright dates with scripts/update-copyrights 2026-01-01 13:42:29 -08:00
H.J. Lu 3dd2cbfa35 Use 64-bit atomic on sem_t with 8-byte alignment [BZ #33632]
commit 7fec8a5de6
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Thu Nov 13 14:26:08 2025 -0300

    Revert __HAVE_64B_ATOMICS configure check

uses 64-bit atomic operations on sem_t if 64-bit atomics are supported.
But sem_t may be aligned to 32-bit on 32-bit architectures.

1. Add a macro, SEM_T_ALIGN, for sem_t alignment.
2. Add a macro, HAVE_UNALIGNED_64B_ATOMICS.  Define it if unaligned 64-bit
atomic operations are supported.
3. Add a macro, USE_64B_ATOMICS_ON_SEM_T.  Define to 1 if 64-bit atomic
operations are supported and SEM_T_ALIGN is at least 8-byte aligned or
HAVE_UNALIGNED_64B_ATOMICS is defined.
4. Assert that size and alignment of sem_t are not lower than those of
the internal struct new_sem.
5. Check USE_64B_ATOMICS_ON_SEM_T, instead of USE_64B_ATOMICS, when using
64-bit atomic operations on sem_t.

This fixes BZ #33632.

Reviewed-by: Wilco Dijkstra  <Wilco.Dijkstra@arm.com>
2025-12-02 06:50:49 +08:00
gfleury 585eee3962 htl: move c11 symbols into libc.
thrd_{create,detach,exit,join}.
mtx_{init,destroy,lock,trylock,unlock,timeelock}.
cnd_{broadcast,destroy,init,signal,timewait,wait,destroy}
tss_{create,delete,get,set}. call_once.
Message-ID: <20251121191336.1224485-1-gfleury@disroot.org>
2025-11-22 03:28:48 +01:00
Samuel Thibault 604bdb0f8e htl: Also use __libc_thread_freeres to clean TLS state 2025-11-22 03:27:40 +01:00
Samuel Thibault ff92750112 htl: Move pthread_atfork compatibility symbol to libc
There is no new symbol version because of the compatibility symbol
status.
2025-11-21 00:29:44 +01:00
gfleury b36a126f7d htl: move pthread_spin_{destroy, lock, init, trylock, unlock) and remove _pthread_spin_lock, into libc.
Message-ID: <20251120085647.326643-1-gfleury@disroot.org>
2025-11-21 00:29:44 +01:00
gfleury d989840693 htl: move pthread_hurd_cond_timedwait_np, pthread_hurd_cond_wait_np into libc.
Message-ID: <20251118125044.1160780-3-gfleury@disroot.org>
2025-11-18 15:01:35 +01:00
gfleury bb3524a879 htl: move pthread_getname_np/setname_np into libc.
Message-ID: <20251118125044.1160780-2-gfleury@disroot.org>
2025-11-18 15:01:35 +01:00
gfleury 77f446346a htl: fix compatibility
This fix 91fb9914d8 which break a system
built with an old glibc
Message-ID: <20251118125044.1160780-1-gfleury@disroot.org>
2025-11-18 15:01:35 +01:00
Samuel Thibault 5b6ee0e0ba htl: move pthread_create to into libc
This is notably needed for the main thread structure to be always
initialized so that some pthread functions can work from the main thread
without other threads, e.g. pthread_cancel.
2025-11-17 00:38:37 +00:00
Samuel Thibault f63dd92431 htl: Move __pthread_enable/disable_asynccancel into libc
This is actually needed before we make pthread_cancel available in libc.
2025-11-17 00:38:36 +00:00
Adhemerval Zanella 7fec8a5de6 Revert __HAVE_64B_ATOMICS configure check
The 53807741fb added a configure check
for 64-bit atomic operations that were not previously enabled on some
32-bit ABIs.

However, the NPTL semaphore code casts a sem_t to a new_sem and issues
a 64-bit atomic operation for __HAVE_64B_ATOMICS.  Since sem_t has
32-bit alignment on 32-bit architectures, this prevents the use of
64-bit atomics even if the ABI supports them.

Assume 64-bit atomic support from __WORDSIZE, which maps to how glibc
defines it before the broken change.  Also rename __HAVE_64B_ATOMICS
to USE_64B_ATOMICS to define better the flag meaning.

Checked on x86_64-linux-gnu and i686-linux-gnu.

Reviewed-by: Wilco Dijkstra  <Wilco.Dijkstra@arm.com>
2025-11-14 14:05:20 -03:00
Samuel Thibault 91fb9914d8 htl: Remove errno and herrno from libpthread
libc already has them.
2025-11-13 23:45:42 +01:00
Samuel Thibault 23b8e6ae4f htl: Drop pthread-functions infrastructure
All previously forwarded functions are now called directly (either via local
call in libc, or through a __export).t
2025-11-13 23:23:13 +01:00
Samuel Thibault 6c933807a9 htl: Move __pthread_cleanup_stack out of libc_pthread_init.c
It does not actually need to be extern any more.
2025-11-13 23:22:57 +01:00
Samuel Thibault f6a60e9867 htl: move {,_IO_}f{,un,try}lockfile implementation into libc 2025-11-13 23:01:07 +01:00
Samuel Thibault f851a74346 hurd: Drop remnants of cthreads
These are not used in GNU/Hurd since very long now.
2025-11-12 01:11:11 +01:00
gfleury 098e449df0 htl: move sem_unlink into libc.
Message-ID: <20250817104023.91919-8-gfleury@disroot.org>
2025-08-18 01:06:41 +02:00
gfleury f5a43420e2 htl: move sem_{clockwait, timedwait, wait, trywait} into libc.
Message-ID: <20250817104023.91919-7-gfleury@disroot.org>
2025-08-18 01:06:38 +02:00
gfleury 795f5f2a8b htl: move sem_post into libc.
Message-ID: <20250817104023.91919-6-gfleury@disroot.org>
2025-08-18 00:55:33 +02:00
gfleury 50f5ddc20a htl: move sem_open, sem_close into libc.
Message-ID: <20250817104023.91919-5-gfleury@disroot.org>
2025-08-18 00:55:18 +02:00
gfleury b2b6d32f11 htl: move sem_init into libc.
Message-ID: <20250817104023.91919-4-gfleury@disroot.org>
2025-08-18 00:23:11 +02:00
gfleury 11c07af422 htl: move sem_getvalue into libc.
Message-ID: <20250817104023.91919-3-gfleury@disroot.org>
2025-08-18 00:22:53 +02:00
gfleury c2560a0c56 htl: move sem_destroy into libc.
Message-ID: <20250817104023.91919-2-gfleury@disroot.org>
2025-08-18 00:22:43 +02:00
gfleury 35296a6e73 htl: move __pthread_startup into libc.
Message-ID: <20250815181500.107433-20-gfleury@disroot.org>
2025-08-16 01:44:51 +02:00
gfleury 80412aee3e htl: move __pthread_setup into libc.
Message-ID: <20250815181500.107433-19-gfleury@disroot.org>
2025-08-16 01:44:51 +02:00
gfleury b6616efe8c htl: move pthread_{join, clockjoin_np, timedjoin_np, tryjoin_np} into libc.
Message-ID: <20250815181500.107433-18-gfleury@disroot.org>
2025-08-16 01:44:51 +02:00
gfleury 36982b0fdb htl: move pthread_exit into libc.
Message-ID: <20250815181500.107433-17-gfleury@disroot.org>
2025-08-16 01:44:51 +02:00
gfleury a901f2599e htl: move pthread_detach into libc.
Message-ID: <20250815181500.107433-16-gfleury@disroot.org>
2025-08-16 01:44:51 +02:00
gfleury d0667a77de htl: move __pthread_sigstate_init into libc.
Message-ID: <20250815181500.107433-15-gfleury@disroot.org>
2025-08-16 01:44:51 +02:00
gfleury f6a47e2d61 htl: move pthread_mutex_transfer_np into libc.
Message-ID: <20250815181500.107433-14-gfleury@disroot.org>
2025-08-16 01:44:51 +02:00
gfleury 1e6588e777 htl: move pthread_getattr_np into libc.
Message-ID: <20250815181500.107433-13-gfleury@disroot.org>
2025-08-16 01:44:51 +02:00
gfleury 6541288cb5 htl: move pthread_testcancel into libc.
Message-ID: <20250815181500.107433-12-gfleury@disroot.org>
2025-08-16 01:44:50 +02:00
gfleury edcc9ca48c htl: move pthread_kill into libc.
Message-ID: <20250815181500.107433-11-gfleury@disroot.org>
2025-08-16 01:44:27 +02:00
gfleury de8351f4de htl: move pthread_cancel, __pthread_do_cancel into libc.
Message-ID: <20250815181500.107433-10-gfleury@disroot.org>
2025-08-16 01:44:27 +02:00
gfleury e0b765d9ba htl: move __thread_set_pcsptp into libc.
Message-ID: <20250815181500.107433-9-gfleury@disroot.org>
2025-08-16 01:44:27 +02:00
gfleury 2dcb8fb8e7 htl: move pthread_yield into libc.
Message-ID: <20250815181500.107433-8-gfleury@disroot.org>
2025-08-16 01:44:27 +02:00
gfleury fa35ccbba8 htl: move pthread_getcpuclockid into libc.
Message-ID: <20250815181500.107433-7-gfleury@disroot.org>
2025-08-16 01:44:27 +02:00
gfleury c3abc99cb0 htl: move __pthread_thread_{alloc, start, terminate} into libc.
Message-ID: <20250815181500.107433-6-gfleury@disroot.org>
2025-08-16 01:44:26 +02:00
gfleury 450912d5db htl: move __pthread_stack_alloc into libc.
Message-ID: <20250815181500.107433-5-gfleury@disroot.org>
2025-08-16 01:15:37 +02:00
gfleury 2522a3f3ae htl: move __pthread_init_{specific, static_tls}, __pthread_{alloc}, dealloc} into libc.
Message-ID: <20250815181500.107433-4-gfleury@disroot.org>
2025-08-16 01:13:22 +02:00
gfleury b586357e2a htl: move pthread_get/setconcurrency into libc.
Message-ID: <20250815181500.107433-3-gfleury@disroot.org>
2025-08-16 01:12:21 +02:00