mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
The driver now handles DriverKit's power changes and gives clients a power state, a way to ask for low power, and a way to wait for changes. SetPowerState(Low), the device in a reduced power state while the system runs, and a client's PowerControl PREPARE quiesce the compute session through upstream KFD suspend (rt/power.h): every user queue off MES with its work saved, VRAM untouched. RESUME by the last holder, or SetPowerState(On), resumes it through upstream KFD resume and the saved work continues. SetPowerState(Off), system sleep, takes the Thunderbolt link and with it the endpoint's state; VRAM cannot survive it on these hosts, and upstream's only dGPU path evicts all of VRAM to system memory through SDMA, which neither fits on the iPad nor is safe over the link. The driver closes the compute session through its ordinary close path before acknowledging the change; the acknowledgement waits for the close on the default queue, with a watcher that acknowledges at a deadline so a stuck close never stalls the sleep. On wake the state is lost if a session was closed, and the next InitDevice probes afresh and makes it active again. A quiesced session closes as it is, its queues already off MES; the KFD suspend is handed back before upstream removal takes its own, so upstream's suspend count stays balanced across sessions. A failed quiesce or resume hands the suspend back, so MES maps the queues again and the close removes them through MES; a GPU that cannot prove itself idle leaves the session to the existing quarantine rather than freeing memory it may use. Clients see state, generation, flags (VRAM preserved among them), cause, error and counters through QueryInfo tag "LPWR" (observers too) and the PowerControl selector 83: QUERY, PREPARE, RESUME and an async WAIT completing at the next generation change. While suspending, suspended or resuming, selectors that would put work on the GPU are refused with kIOReturnOffline, which a client retries after resume; frees, queue destruction and cached queries stay available. A closing client's waits end and its hold is dropped. Observers may request transitions only with the session-release entitlement. power_state.h holds the state machine, the snapshot, the admission policy and the plan each event leads to, with a host test that also checks the runtime's copy of the protocol. The session shutdown test covers the removal hook and the observer policy for the new tag and selector, and read-driver-log.py prints the power state.
12 lines
478 B
Bash
Executable File
12 lines
478 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# The driver's device power state machine (dext/sources/power_state.h) and
|
|
# the runtime's copy of its protocol (hsa/abi/amdgpu_power_abi.h).
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
test_dir=$(mktemp -d)
|
|
trap 'rm -rf "$test_dir"' EXIT
|
|
clang++ -std=c++20 -Wall -Wextra -Werror -g -O1 -fsanitize=address,undefined \
|
|
-fno-sanitize-recover=all -Idext/sources linuxu/tests/test_power_state.cpp \
|
|
-o "$test_dir/test_power_state"
|
|
"$test_dir/test_power_state"
|