mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
A doorbell cost the submitting thread an async session call: about 20 us, twice a synchronous call through the driver (a Ping is 10 us), because an async call sets up its completion and hops to the session queue. From build 263, AQLQueueKick called synchronously rings the doorbell on the delivery thread itself. DriverKit delivers every client's calls on that thread, which must never sleep (build 241). The doorbell there takes no session lock and reads none of the session queue's tables: - kick_table.h: the KFD queues that may be rung on the delivery thread, by handle and owner, under a spinlock nothing holds across a sleep. The session queue publishes a queue once it exists and retires it before anything of it goes: its DESTROY_QUEUE, its owner's close, the device's stop. A ring holds the lock across its doorbell write, so once retire returns no doorbell of the queue is written and its memory may go. The table also closes for power transitions (power_set), which waits for a write in progress. - rt_kfd_queue_kick_nowait: the doorbell under the session's kick spinlock alone. A queue is ringable from its creation until its DESTROY_QUEUE (queue_release_locked clears it under that lock first, since the doorbell is then released to other queues). Both doorbell paths share the highest value written, and neither writes a lower one. As on Linux, where the process writes its doorbell page itself, the value is not checked against the write index. - The PCI access gate under the doorbell write is a spinlock and atomic counters, so nothing on that path sleeps. The store to the BAR stays in the driver, behind its removal gate; nothing is mapped into the client. What the fast path cannot vouch for (a legacy queue, a busy or closing session, an unpublished queue) it answers kIOReturnUnsupported, and the runtime sends that doorbell as the async session call. Offline, VMError, NoDevice and BadArgument answer as the async call does. Tests: test-kick-table races four delivery threads against queues published, retired and freed at once, client closes and power gates, under ThreadSanitizer and AddressSanitizer. No ring reaches a retired, freed, foreign or gated queue. The delivery threads kept ringing while the session thread slept (a slow DESTROY_QUEUE): rings during the sleeps 2830 under TSan, 29100 under ASan. Longest wait for the lock 137 us under TSan, 38 us under ASan. test-kfd-session covers the nowait path on the real KFD session code: written, never lower, refused from DESTROY_QUEUE on, -EFAULT after a GPU fault. test-dext-compute-production covers publish, owner, gate and retire on destroy and on client close. test-hsa-power-transport covers the runtime's synchronous form and each answer.
16 lines
690 B
Bash
Executable File
16 lines
690 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# Doorbells on the delivery thread (dext/sources/kick_table.h): delivery
|
|
# threads ringing while the session queue publishes, retires and frees
|
|
# queues, closes clients and gates power transitions, under
|
|
# ThreadSanitizer and under AddressSanitizer (linuxu/tests/test_kick_table.c).
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
test_dir=$(mktemp -d)
|
|
trap 'rm -rf "$test_dir"' EXIT
|
|
for sanitizer in thread address,undefined; do
|
|
clang -std=gnu11 -Wall -Wextra -Werror -g -O1 -fsanitize=$sanitizer -fno-sanitize-recover=all \
|
|
-Idext/sources linuxu/tests/test_kick_table.c -lpthread -o "$test_dir/test_kick_table"
|
|
echo "($sanitizer)"
|
|
"$test_dir/test_kick_table"
|
|
done
|