Files
geramyloveless 9d10aa0e33 Session calls never run on the driver's incoming-call thread
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.
2026-10-04 21:22:42 -07:00

26 lines
982 B
C

/* A call bounded in time for a caller that must not sleep long (the
* driver's incoming-call thread): the work runs on a wait-pool thread
* (rt/wait_pool.h), and the caller waits for it at most a bounded time.
* Work that overruns keeps running; it then owns its argument and frees it
* when it ends. Runtime: linuxu/src/amdgpu-rt/bounded.c. */
#ifndef LINUXU_RT_BOUNDED_H
#define LINUXU_RT_BOUNDED_H
#ifdef __cplusplus
extern "C" {
#endif
/* Run @fn(@arg) on a pool thread and wait up to @ms for it. 0: it ran to
* the end, the caller owns @arg (and frees it). -ETIMEDOUT: it is still
* running, and @release(@arg) runs on its thread when it ends. -EAGAIN or
* -ENOMEM: it did not start; the caller owns @arg. Linux errno values. */
int rt_bounded_run(void (*fn)(void *arg), void *arg, void (*release)(void *arg),
unsigned int ms);
/* Bounded calls whose work overran and still runs. */
unsigned int rt_bounded_overrunning(void);
#ifdef __cplusplus
}
#endif
#endif