Files
mac_linuxgpu/scripts
geramyloveless 5607122bec AQLQueueKick on the delivery thread
A doorbell cost the submitting thread an async session call: about 20 us,
twice a synchronous call through the driver (a Ping is 10 us), because an
async call sets up its completion and hops to the session queue. From
build 263, AQLQueueKick called synchronously rings the doorbell on the
delivery thread itself.

DriverKit delivers every client's calls on that thread, which must never
sleep (build 241). The doorbell there takes no session lock and reads none
of the session queue's tables:
- kick_table.h: the KFD queues that may be rung on the delivery thread, by
  handle and owner, under a spinlock nothing holds across a sleep. The
  session queue publishes a queue once it exists and retires it before
  anything of it goes: its DESTROY_QUEUE, its owner's close, the device's
  stop. A ring holds the lock across its doorbell write, so once retire
  returns no doorbell of the queue is written and its memory may go. The
  table also closes for power transitions (power_set), which waits for a
  write in progress.
- rt_kfd_queue_kick_nowait: the doorbell under the session's kick
  spinlock alone. A queue is ringable from its creation until its
  DESTROY_QUEUE (queue_release_locked clears it under that lock first,
  since the doorbell is then released to other queues). Both doorbell
  paths share the highest value written, and neither writes a lower one.
  As on Linux, where the process writes its doorbell page itself, the
  value is not checked against the write index.
- The PCI access gate under the doorbell write is a spinlock and atomic
  counters, so nothing on that path sleeps. The store to the BAR stays in
  the driver, behind its removal gate; nothing is mapped into the client.

What the fast path cannot vouch for (a legacy queue, a busy or closing
session, an unpublished queue) it answers kIOReturnUnsupported, and the
runtime sends that doorbell as the async session call. Offline,
VMError, NoDevice and BadArgument answer as the async call does.

Tests: test-kick-table races four delivery threads against queues
published, retired and freed at once, client closes and power gates, under
ThreadSanitizer and AddressSanitizer. No ring reaches a retired, freed,
foreign or gated queue. The delivery threads kept ringing while the
session thread slept (a slow DESTROY_QUEUE): rings during the sleeps 2830
under TSan, 29100 under ASan. Longest wait for the lock 137 us under TSan,
38 us under ASan. test-kfd-session covers the nowait path on the real KFD
session code: written, never lower, refused from DESTROY_QUEUE on, -EFAULT
after a GPU fault. test-dext-compute-production covers publish, owner,
gate and retire on destroy and on client close. test-hsa-power-transport
covers the runtime's synchronous form and each answer.
2026-10-06 15:39:53 -07:00
..