mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
A hang the queue reset cannot end now runs upstream's device reset (amdgpu_device_gpu_recover, mode1 on gfx12) when the platform allows it (rt_recovery_set_full_reset_gate), and wedges the GPU otherwise. The driver's gate allows it only when the personality enables device resets (MacLinuxGPUDeviceReset, absent = off until a reset is validated over Thunderbolt) and no client maps one of the GPU's BARs: neither a raw BAR lease nor any Linux-file mapping through a BAR (rt_lx_bar_mappings), since a client store into a BAR that stops decoding can take the Mac down. Every refusal is logged with its reason as the wedge's. Upstream's own recovery runs unchanged, with three bounds around it: the ASIC reset is wrapped so one recovery makes at most two attempts (upstream retries a reset whose IB tests fail without limit on bare metal); a device reset that fails (reset_domain->reset_res) wedges the GPU, where upstream would leave its schedulers stopped with no event; and one that succeeds advances the reset generation, with RT_RECOVERY_LAST_VRAM_LOST when the VRAM-lost counter moved. The KFD and user-queue reset works go through the same path. RESET_WAIT (selector 91, observers and session clients, registration on the delivery thread) completes when the reset generation differs from the one the caller knows, with the generation and MLG_RESET_FLAG_*; a client's waits end with it. The host's daemon re-arms it to post its notification. Tests: device_reset_check (the CS fixture, which now has soc24's reset method and an ASIC reset that restarts its engines) allows device resets and hangs a queue whose reset fails: upstream's amdgpu_device_gpu_recover runs, the GPU does not come back (no VBIOS), the device wedges after one ASIC reset and nothing retries. test-owner- call covers RESET_WAIT (new generation, stale generation, cancel) and the gate (personality, raw lease, client BAR mappings); test_lx_files counts a client's BAR mapping.
68 lines
4.2 KiB
Bash
68 lines
4.2 KiB
Bash
#!/usr/bin/env bash
|
|
# The dext's session calls (dext/sources/MacLinuxGPUXcode.mm owner_call):
|
|
# a call that can sleep never runs on the delivery thread, with the
|
|
# production functions extracted and DriverKit mocked
|
|
# (linuxu/tests/test_owner_call.cpp). Also checks that host/owner_call.h
|
|
# carries session_state.h's numbers.
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
test_dir=$(mktemp -d)
|
|
trap 'rm -rf "$test_dir"' EXIT
|
|
python3 - "$test_dir" <<'PY'
|
|
import pathlib, re, sys
|
|
source = pathlib.Path("dext/sources/MacLinuxGPUXcode.mm").read_text()
|
|
start = "// RESET_WAIT (session_state.h): waits for the reset generation to change."
|
|
end = "// A client's last display op result (MacLinuxGPUUserClient_IVars::displayResults)."
|
|
if source.count(start) != 1 or source.count(end) != 1:
|
|
raise SystemExit("owner call extraction markers changed")
|
|
text = source[source.index(start):source.index(end)]
|
|
if len(text.splitlines()) > 620:
|
|
raise SystemExit("owner call extraction exceeded its bounded section")
|
|
pathlib.Path(sys.argv[1], "owner_call_production.inc").write_text(text)
|
|
state = pathlib.Path("dext/sources/session_state.h").read_text()
|
|
client = pathlib.Path("host/owner_call.h").read_text()
|
|
def number(text, name):
|
|
found = re.search(r"#define\s+" + name + r"\s+\(?(\w+)", text)
|
|
if not found:
|
|
raise SystemExit(f"{name} not found")
|
|
return found.group(1).rstrip("u")
|
|
for driver, mirror in (("MLG_SELECTOR_OWNER_RESULT", "MLG_OWNER_CALL_SELECTOR_RESULT"),
|
|
("MLG_OWNER_ASYNC_HEADER", "MLG_OWNER_CALL_HEADER"),
|
|
("MLG_OWNER_ASYNC_SCALARS", "MLG_OWNER_CALL_SCALARS"),
|
|
("MLG_OWNER_ASYNC_MAX_SCALARS", "MLG_OWNER_CALL_MAX_SCALARS")):
|
|
if number(state, driver) != number(client, mirror):
|
|
raise SystemExit(f"host/owner_call.h {mirror} differs from session_state.h {driver}")
|
|
backend = pathlib.Path("dext/sources/dext_compute_backend.inc").read_text()
|
|
runtime = re.search(r"#define DEXT_RUNTIME_BUILD (\d+)u", backend)
|
|
if not runtime or int(runtime.group(1)) < int(number(state, "MLG_SESSION_CALLS_ASYNC_BUILD")):
|
|
raise SystemExit("DEXT_RUNTIME_BUILD predates MLG_SESSION_CALLS_ASYNC_BUILD: clients would refuse this driver")
|
|
python = pathlib.Path("scripts/mlg_owner_call.py").read_text()
|
|
bounds = re.search(r"^BOUND_S, LONG_BOUND_S, LONG_SELECTORS = (\d+), (\d+), \(([\d, ]+)\)", python, re.M)
|
|
header_bounds = (re.search(r"#define MLG_OWNER_CALL_BOUND_MS\s+(\d+)u", client),
|
|
re.search(r"#define MLG_OWNER_CALL_LONG_BOUND_MS\s+(\d+)u", client))
|
|
long_cases = sorted(int(n) for n in re.findall(r"case (\d+)u:", client.split("mlg_owner_call_bound_ms")[1].split("default:")[0]))
|
|
if not bounds or not all(header_bounds) or \
|
|
int(bounds.group(1)) * 1000 != int(header_bounds[0].group(1)) or \
|
|
int(bounds.group(2)) * 1000 != int(header_bounds[1].group(1)) or \
|
|
sorted(int(n) for n in bounds.group(3).split(",")) != long_cases:
|
|
raise SystemExit("scripts/mlg_owner_call.py bounds differ from host/owner_call.h")
|
|
for driver, mirror in (("MLG_SELECTOR_OWNER_RESULT", "OWNER_RESULT"),
|
|
("MLG_OWNER_ASYNC_HEADER", "OWNER_HEADER"),
|
|
("MLG_OWNER_ASYNC_SCALARS", "OWNER_SCALARS"),
|
|
("MLG_OWNER_ASYNC_MAX_SCALARS", "OWNER_MAX_SCALARS"),
|
|
("MLG_SESSION_CALLS_ASYNC_BUILD", "SESSION_CALLS_ASYNC_BUILD")):
|
|
found = re.search(r"^" + mirror + r"\s*=\s*(\d+)", python, re.M)
|
|
if not found or found.group(1) != number(state, driver):
|
|
raise SystemExit(f"scripts/mlg_owner_call.py {mirror} differs from session_state.h {driver}")
|
|
PY
|
|
clang++ -std=c++20 -fblocks -Wall -Wextra -Werror -Wno-unused-function -Wno-unused-parameter \
|
|
-g -O1 -fsanitize=address,undefined -fno-sanitize-recover=all \
|
|
-I"$test_dir" -Idext/sources -idirafter linuxu/headers \
|
|
linuxu/tests/test_owner_call.cpp -lpthread -o "$test_dir/test_owner_call"
|
|
"$test_dir/test_owner_call"
|
|
# The host side: host/owner_call.h's bounded wait.
|
|
clang -std=gnu11 -Wall -Wextra -Werror -g -O1 -fsanitize=address,undefined -Ihost \
|
|
linuxu/tests/test_owner_call_host.c -framework IOKit -framework CoreFoundation \
|
|
-o "$test_dir/test_owner_call_host"
|
|
"$test_dir/test_owner_call_host"
|