mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
DriverKit delivers every client's calls, and the driver's own Stop, on one thread, and runs each under its target queue with a synchronous dispatch. Session clients shared the owner's queue, and observers and Linux-file clients hopped to it synchronously, so a session call that slept there (a probe, an allocation that evicts, a fence wait, a session close), or anything queued behind one, held every client; on a GPU that stopped, forever (build 241). Every client now has a queue of its own, and nothing on the delivery thread waits for the owner's queue: - Selectors that never sleep answer there: Ping, RuntimeBuild (from flags the session queue publishes; the context is never touched), the cached QueryInfo tags, the power query and the power wait's registration, and OWNER_RESULT (88). - Every other selector must be called with IOConnectCallAsync*: the call returns at once with a token and runs on the owner's queue, in arrival order, exactly as it ran there before; it completes with its IOReturn, scalar outputs and structure output length, and OWNER_RESULT fetches the structure output once. EVENT_WAIT keeps its own completion; a wait that does not start completes at once with the reason. A synchronous call of such a selector is refused (kIOReturnNotPermitted, logged once per client). - SysfsRead and DrmInfo stay synchronous but bounded: the read runs on a wait-pool thread (rt_bounded_run, new) and the call waits at most 250 ms (kIOReturnTimeout; while one overruns, the next is kIOReturnBusy). The observer's self-test, Retire and ReleaseQuarantine are async calls. - A session client's Stop, and an observer's FinishStop, run on the owner's queue after the client's queued calls. Linux-file clients join the session on the owner's queue with their first open (LX_CALL_ASYNC), and the first open's InitDevice and HostWindow are async calls. - CopyClientMemoryForType no longer touches the session: BOMap makes the BO's descriptor on the owner's queue and the mapping looks it up; the raw BAR lease takes its own spinlock. Clients: host/owner_call.h and host/selector_call.h (header-only) call a selector as the driver serves it, synchronously or as an awaited async call; the HSA runtime, the host app (callScalar, callStruct, callMethod) and libmlg_drm use them, and scripts/mlg_owner_call.py does the same for drm-selftest.py and display-test.py's initialization. A client older than this driver fails at its first session call that can sleep, with the reason in the driver log. Tests: test-owner-call runs the production owner_call machinery (extracted, DriverKit mocked) against a session call that sleeps: calls return at once, cached queries and the power wait answer while it sleeps, later calls queue in order, completions carry the right layout, OWNER_RESULT once, BO memory is found without the session, and a hung bounded read times out within its bound. test-bounded covers rt_bounded_run on the real wait pool; test-session-shutdown checks the selector rules and runs the Stop paths through the owner's queue.
55 lines
2.6 KiB
Bash
Executable File
55 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# libmlg_drm, the Linux-file RPC client library: on its own against a
|
|
# recording transport, then end to end through the Linux-file core into
|
|
# upstream DRM/amdgpu on the CS fixture device (links the host library).
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
make -s lib >/dev/null
|
|
work=$(mktemp -d)
|
|
trap 'rm -rf "$work"' EXIT
|
|
client=(-std=c11 -Wall -Wextra -Werror -Wno-missing-field-initializers -g -O1
|
|
-DMLG_LX_CLIENT_BUILD -Ihost -Ilibmlg_drm/include -Ilibmlg_drm/compat -Ilibmlg_drm/src
|
|
-Ithird_party/linux/include/uapi -idirafter linuxu/headers)
|
|
client_srcs=(libmlg_drm/src/mlg_drm.c libmlg_drm/src/mlg_transport_iokit.c libmlg_drm/src/mlg_init.c
|
|
linuxu/src/amdgpu-rt/lx_frame.c linuxu/src/amdgpu-rt/lx_describe.c)
|
|
frameworks=(-framework IOKit -framework CoreFoundation)
|
|
|
|
clang "${client[@]}" -fsanitize=address,undefined -fno-sanitize-recover=all \
|
|
libmlg_drm/tests/test_mlg_drm.c "${client_srcs[@]}" "${frameworks[@]}" -o "$work/test_mlg_drm"
|
|
"$work/test_mlg_drm"
|
|
# Bringing the GPU up from a Linux-file client: host window, then InitDevice.
|
|
clang "${client[@]}" -fsanitize=address,undefined -fno-sanitize-recover=all \
|
|
libmlg_drm/tests/test_mlg_init.c libmlg_drm/src/mlg_init.c -o "$work/test_mlg_init"
|
|
"$work/test_mlg_init"
|
|
|
|
cat > "$work/flags.mk" <<'MAKE'
|
|
.PHONY: print-includes
|
|
print-includes:
|
|
@printf '%s\n' $(INCPATHS)
|
|
.PHONY: print-hostcflags
|
|
print-hostcflags:
|
|
@printf '%s\n' $(filter-out -MMD -MP -DLINUXU_RT_HOST_SHADOW=1,$(HOSTCFLAGS))
|
|
MAKE
|
|
include_string=$(make -s -f Makefile -f "$work/flags.mk" print-includes | tr '\n' ' ')
|
|
read -r -a includes <<< "$include_string"
|
|
host_string=$(make -s -f Makefile -f "$work/flags.mk" print-hostcflags | tr '\n' ' ')
|
|
read -r -a hostcflags <<< "$host_string"
|
|
kernel=("${hostcflags[@]}" -g -O1 "${includes[@]}")
|
|
objects=()
|
|
# Plain-memory GART and VRAM accessors for the fixture (test-cs-selftest.sh).
|
|
for source in third_party/linux/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c \
|
|
third_party/linux/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c \
|
|
linuxu/tests/cs_fixture.c linuxu/tests/lx_loopback.c; do
|
|
object="$work/k_$(basename "$source" .c).o"
|
|
clang "${kernel[@]}" -Ilibmlg_drm/include -c "$source" -o "$object"
|
|
objects+=("$object")
|
|
done
|
|
for source in libmlg_drm/tests/test_mlg_drm_cs.c "${client_srcs[@]}"; do
|
|
object="$work/c_$(basename "$source" .c).o"
|
|
clang "${client[@]}" -fsanitize=address -Ilinuxu/tests -c "$source" -o "$object"
|
|
objects+=("$object")
|
|
done
|
|
clang -fsanitize=address "${objects[@]}" build/libmacamgdu.a "${frameworks[@]}" -lpthread \
|
|
-o "$work/test_mlg_drm_cs"
|
|
"$work/test_mlg_drm_cs"
|