linux/tools/build
Arnaldo Carvalho de Melo 4456c404c6 perf mutex: Add a robust, process-shared mutex initializer
A mutex held by a process that can die before unlocking it, like the
tests forked by 'perf test' that will take turns using the per user
budget set in kernel.perf_event_mlock_kb, has to be taken over by the
next locker instead of staying locked forever.

Robust mutexes, on top of the kernel's robust futexes, do that: when an
owner dies while holding it the kernel marks the futex word owner-died
and the next pthread_mutex_lock() returns EOWNERDEAD, then mutex_lock()
makes it consistent and takes it over; mutex_trylock() and cond_wait()
come back with EOWNERDEAD too, so they take it over the same way, with
mutex_trylock() giving the mutex back when it can't be taken over: it
is held all the same, and a failed trylock must not leak it.

Add mutex_init_pshared_robust(), returning false when robust mutexes
aren't available: from libcs without the API, gated by a feature check,
to musl and glibc refusing them at runtime, when get_robust_list(2) or
set_robust_list(2) aren't usable.  glibc only sets a flag in
pthread_mutexattr_setrobust(), refusing the mutex itself in
pthread_mutex_init() with ENOTSUP instead, other errors from it still
being reported.  Robust mutexes being unavailable isn't an error, just a
debug message for whoever then falls back.

Reviewed-by: Ian Rogers <irogers@google.com>
Tested-by: Ian Rogers <irogers@google.com>
Assisted-by: LLM
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2026-10-17 10:30:20 -03:00
..
Documentation
feature perf mutex: Add a robust, process-shared mutex initializer 2026-10-17 10:30:20 -03:00
tests
.gitignore
Build tools build: Fix fixdep dependencies 2025-10-14 14:45:20 -07:00
Build.include tools build: Fix rust cross compilation 2026-03-04 11:37:30 -03:00
fixdep.c
Makefile perf build: Fix perf build issues with fixdep 2025-10-23 09:53:49 +02:00
Makefile.build tools build: Make in-target rule robust against too long argument error 2026-03-04 11:21:48 -03:00
Makefile.feature perf mutex: Add a robust, process-shared mutex initializer 2026-10-17 10:30:20 -03:00
Makefile.include