redbluegreen wiki

The queue

What one AQL compute queue is made of, and why the kernel makes it five separate allocations.

our code the CP ring 64 KiB · COHERENT · EXEC 1 1 pkt 1 64-byte slots header 1 = INVALID, one packet written write pointer 4 KiB · COHERENT read pointer 4 KiB · COHERENT CWSR area header 18 MiB · coarse EOP buffer 4 KiB · coarse · EXEC doorbell page doorbell u64 8 KiB page offset = page bits + low 13 bits writes packet writes rings runs packets polls advances each buffer is its own allocation, sized exactly our code driver and hardware INVALID slot
One AQL queue is five exactly sized allocations plus a doorbell page; our code writes the packet and rings the doorbell, and the CP runs the packet.

A queue is five buffers and one ioctl.

The kernel counts bytes. Each buffer must be the start of its own allocation, and the allocation size must equal the expected size exactly. So we make five separate ALLOC calls, each sized to the byte, plus a doorbell page.

The five buffers:

  1. The ring holds the packets. Every slot starts with the header for INVALID, so a half-written packet never runs.
  2. The write pointer gets its own page. Our code advances it.
  3. The read pointer gets its own page. The hardware advances it as packets retire.
  4. The CWSR area is the context save area. Its size comes from the sysfs node properties.
  5. The EOP buffer is optional to the ioctl and required by the hardware. Without it, the first REMOVE_QUEUE hangs MES and resets the GPU.
buffersizeflags who writes it
ring65536COHERENT, EXECUTABLE our code
write pointer4096COHERENT our code
read pointer4096COHERENT hardware
CWSR area19226624coarse our code, then hardware
EOP buffer4096coarse, EXECUTABLE hardware
doorbell page8192mmap on the kfd fd our code

The doorbell is the contract.

CREATE_QUEUE returns an offset. The high bits name a doorbell page. The low bits name this queue's u64 inside that page. Writing the packet index there starts the hardware.

The CP also polls the write pointer while memory is coherent, so a packet can run without a doorbell write. Ring it anyway.

fieldvalue
CREATE_QUEUEnr 0x02, 96 bytes
doorbell_offset page bits, then the low 13 bits
CWSR size sysfs cwsr_size plus a debug region
last field pad in the 6.19 header, metadata_ring_size in 7.0

The last CREATE_QUEUE field has one name in the header on disk and another in the running kernel. Zero is correct either way.

Sources