mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
On 241 a request that waited on a GPU ring that had stopped ran on the one thread DriverKit delivers every client's calls on: every client froze, and the driver could not take its own Stop after the GPU was powered off. Every Linux-file request that can sleep now runs on a worker of the client's process and completes through AsyncCompletion: - mlg_lx_cmd_sleeps (lx_describe.c, shared by the client library and the driver) names the few requests that provably do not sleep: VERSION, GET_CAP, SET_CLIENT_CAP, the syncobj create, destroy, export, import, reset, signal, timeline signal, query and eventfd requests, a syncobj wait that only polls, and KFD GET_VERSION. Everything else is async, AMDGPU_CS, INFO, GEM and context requests included. - LX_IOCTL runs only those, through rt_lx_ioctl_nosleep; any other is refused without running (kIOReturnNotPermitted) and logged with the request and the process. - LX_CALL_ASYNC (selector 105) runs open, close, mmap and munmap on a worker; the synchronous selectors 96, 97, 101 and 103 are retired. - A Linux-file client's Stop hands its process's exit to a thread of its own (rt_lx_client_retire) instead of waiting for its calls on the incoming-call thread; a session close waits for those exits (rt_lx_retire_drain) before the driver goes. On an unplug the Stop has already begun removal, which completes the GPU's fences, so the exits finish. - An async call holds one of MLG_LX_MAX_ASYNC slots until its result is delivered: with the completion (the slot frees before it is sent) or by LX_RESULT, whose result is in place before the completion goes out. The client library keeps its calls within the limit, waiting on its own thread. A worker still sending a completion holds no slot, so a call queues for it instead of failing. - The transport revision is MLG_LX_ABI 2: libmlg_drm's dylib compatibility version, and the text MLG_LX_ABI_TAG in the library for launchers to check. A client library older than this driver fails at its first sleeping request or open, with the reason in the driver log. Events reach the unified log; routine lines stay in the retained ring. The dext logged every line through os_log, and nothing from it reached the unified log in the boot where 241 hung (probably quarantined for volume), so the hang's cause was lost with the dext. Now only events go there, prefixed "mac.linuxgpu: EVENT ": driver start, probe outcome, removal, quarantine and release, session close, DMA mapping failures, printk at error level and above (ring timeouts among them), and the head of a device coredump, which dev_coredumpm now logs before freeing it. Read them with log show --predicate 'eventMessage BEGINSWITH "mac.linuxgpu: EVENT"' Tests: test_lx_files covers the table, the synchronous refusal, the operations on workers, inline and fetched results and the new slot rules. blocked_call_check (test-cs-selftest) blocks a client's AMDGPU_CS behind amdgpu_sched_jobs submissions on a held compute engine and checks that every call returns at once, the blocked client's non-sleeping request runs and its sleeping one is refused synchronously, another client opens, allocates and completes SDMA work, the blocked client's Stop returns at once and its exit finishes when the engine runs, and, during the surprise removal check, that removal ends a blocked submission and the client's exit completes.
97 lines
4.1 KiB
Bash
97 lines
4.1 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
test_dir=$(mktemp -d)
|
|
trap 'rm -rf "$test_dir"' EXIT
|
|
clang -w -std=gnu11 -D__KERNEL__ -include linux/autoconf.h -include linux/compiler.h -g -O1 -fsanitize=address,undefined \
|
|
-fno-sanitize-recover=all -ffunction-sections -fdata-sections -Ilinuxu/headers \
|
|
linuxu/tests/test_primitive_headers.c linuxu/src/shims/printk.c linuxu/src/shims/dev_coredump.c \
|
|
third_party/linux/lib/sort.c \
|
|
-Wl,-dead_strip -lpthread -o "$test_dir/test_primitive_headers"
|
|
"$test_dir/test_primitive_headers"
|
|
cat > "$test_dir/assertion.c" <<'SRC'
|
|
#include <linux/build_bug.h>
|
|
void forbidden(void) {
|
|
BUILD_BUG_ON_MSG(1, "first invalid contract");
|
|
BUILD_BUG_ON_MSG(1, "second invalid contract");
|
|
}
|
|
SRC
|
|
if clang -w -std=gnu11 -O2 -Ilinuxu/headers -c "$test_dir/assertion.c" \
|
|
-o "$test_dir/assertion.o" > "$test_dir/assertion.log" 2>&1; then
|
|
echo 'BUILD_BUG_ON failed to reject an invalid compile-time contract' >&2
|
|
exit 1
|
|
fi
|
|
grep -q 'first invalid contract' "$test_dir/assertion.log"
|
|
grep -q 'second invalid contract' "$test_dir/assertion.log"
|
|
cat > "$test_dir/folded.c" <<'SRC'
|
|
#include <linux/build_bug.h>
|
|
void valid(void) {
|
|
size_t from = sizeof(unsigned long);
|
|
size_t to = sizeof(unsigned long);
|
|
BUILD_BUG_ON(from != to);
|
|
BUILD_BUG_ON_MSG(sizeof(char) != 1, "valid character size");
|
|
}
|
|
SRC
|
|
clang -w -std=gnu11 -O2 -Ilinuxu/headers -c "$test_dir/folded.c" -o "$test_dir/folded.o"
|
|
# Include order must not change Linux byte units or enable debug config.
|
|
for first in kernel sizes; do
|
|
if [ "$first" = kernel ]; then second=sizes; else second=kernel; fi
|
|
cat > "$test_dir/size-contract.c" <<SRC
|
|
#include <linux/$first.h>
|
|
#include <linux/$second.h>
|
|
#include <linux/lockdep.h>
|
|
#ifdef CONFIG_LOCKDEP
|
|
#error header must not enable CONFIG_LOCKDEP
|
|
#endif
|
|
_Static_assert(SZ_1K == 1024 && SZ_4K == 4096, "kilobyte sizes");
|
|
_Static_assert(SZ_64K == 65536 && SZ_1M == 1048576, "megabyte sizes");
|
|
_Static_assert(SZ_1G == 1073741824 && SZ_4G == 4294967296ULL, "gigabyte sizes");
|
|
_Static_assert(SZ_1T == 1099511627776ULL, "terabyte sizes");
|
|
void no_debug_map(void) {
|
|
lock_acquire_shared_recursive(&disabled_config_symbol, 0, 1, NULL, NULL);
|
|
lock_release(&disabled_config_symbol, NULL);
|
|
}
|
|
SRC
|
|
clang -w -std=gnu11 -O2 -Ilinuxu/headers -c "$test_dir/size-contract.c" -o "$test_dir/size-contract.o"
|
|
done
|
|
# Verify emitted ordering instructions; a host stress loop alone cannot prove
|
|
# that an ARM publication barrier exists or that include order preserves it.
|
|
for first in compiler list; do
|
|
if [ "$first" = compiler ]; then second=list; else second=compiler; fi
|
|
cat > "$test_dir/barriers.c" <<SRC
|
|
#include <linux/$first.h>
|
|
#include <linux/$second.h>
|
|
#include <asm/barrier.h>
|
|
#include <linux/smp.h>
|
|
void publish(void **slot, void *value) { smp_store_release(slot, value); }
|
|
void *consume(void **slot) { return smp_load_acquire(slot); }
|
|
void full_device(void) { mb(); }
|
|
void read_device(void) { rmb(); }
|
|
void write_device(void) { wmb(); }
|
|
void full_cpu(void) { smp_mb(); }
|
|
void read_cpu(void) { smp_rmb(); }
|
|
void write_cpu(void) { smp_wmb(); }
|
|
void before_atomic(void) { smp_mb__before_atomic(); }
|
|
void after_atomic(void) { smp_mb__after_atomic(); }
|
|
void store_full(int *slot, int value) { smp_store_mb(*slot, value); }
|
|
SRC
|
|
clang -w -arch arm64 -std=gnu11 -O2 -Ilinuxu/headers -S \
|
|
"$test_dir/barriers.c" -o "$test_dir/barriers.s"
|
|
python3 - "$test_dir/barriers.s" <<'PY'
|
|
import pathlib, re, sys
|
|
assembly = pathlib.Path(sys.argv[1]).read_text()
|
|
def body(name):
|
|
return assembly.split('_' + name + ':', 1)[1].split('ret', 1)[0]
|
|
for name, instruction in {
|
|
'publish': r'\bstlr\b', 'consume': r'\blda(?:p)?r\b',
|
|
'full_device': r'\bdmb\s+osh\b', 'read_device': r'\bdmb\s+oshld\b',
|
|
'write_device': r'\bdmb\s+oshst\b', 'full_cpu': r'\bdmb\s+ish\b',
|
|
'read_cpu': r'\bdmb\s+ishld\b', 'write_cpu': r'\bdmb\s+ish\b',
|
|
'before_atomic': r'\bdmb\s+ish\b', 'after_atomic': r'\bdmb\s+ish\b',
|
|
}.items():
|
|
assert re.search(instruction, body(name)), (name, body(name))
|
|
assert re.search(r'\bstr\b[\s\S]*\bdmb\s+ish\b', body('store_full'))
|
|
print('ARM64 host publication and device barriers: passed')
|
|
PY
|
|
done
|