Files
mac_linuxgpu/scripts/test-compute-lifetime.sh
geramyloveless aa0aca57a9 linuxu: waits park until woken instead of polling every millisecond
wait_event and its variants, schedule_timeout, completions, contended
mutexes, rw semaphores and semaphores, and dma_fence waits all slept in
1 ms (or 50 us) steps and re-checked, so every sleeping thread woke about
a thousand times a second, waiting or not.

They now park (rt/park.h): a futex over addresses, with condition
variables in hashed buckets, where the waker changes state and unparks
the key and the waiter re-checks under the bucket lock, so no wake is
lost. Tasks park on themselves and linuxu_task_wake unparks them, which
covers wake queues, wake_up_process, signals and kthread_stop.
wait_event queues the task on its wake queue as Linux does; fence waits
add a callback that unparks.

Every wait whose condition it can test is bounded by a backstop that
starts at 2 ms and doubles to 1 s while nothing happens, so an idle
waiter costs about one wakeup a second. A backstop that finds the
condition already true means its producer did not wake it: the wait
site is reported once (file and line, or the caller's address) and
counted. schedule_timeout returns early at the 1 s backstop, a spurious
wake as Linux allows.

test_wait_event checks that a wake_up wakes its waiter at once and not
another, that schedule_timeout ends at wake_up_process, that an idle
300 ms wait wakes 8 times rather than 300, and that the backstop finds
a producer that never wakes (its existing producer is one).
2026-10-03 17:50:21 -07:00

20 lines
791 B
Bash

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
test_dir=$(mktemp -d)
trap 'rm -rf "$test_dir"' EXIT
cat > "$test_dir/flags.mk" <<'MAKE'
.PHONY: print-includes
print-includes:
@printf '%s\n' $(INCPATHS)
MAKE
include_string=$(make -s -f Makefile -f "$test_dir/flags.mk" print-includes | tr '\n' ' ')
read -r -a includes <<< "$include_string"
clang -w -std=gnu11 -D__KERNEL__ -include linux/autoconf.h \
-g -O1 -fsanitize=address,undefined -fno-sanitize-recover=all \
-ffunction-sections -fdata-sections "${includes[@]}" \
linuxu/tests/test_compute_lifetime.c linuxu/src/sync.c linuxu/src/shims/printk.c \
linuxu/src/refcount.c linuxu/src/bug.c linuxu/src/shims/task.c \
-Wl,-dead_strip -lpthread -o "$test_dir/test_compute_lifetime"
"$test_dir/test_compute_lifetime"