What one AQL compute queue is made of, and why the kernel makes it five separate allocations.
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:
| buffer | size | flags | who writes it |
|---|---|---|---|
| ring | 65536 | COHERENT, EXECUTABLE | our code |
| write pointer | 4096 | COHERENT | our code |
| read pointer | 4096 | COHERENT | hardware |
| CWSR area | 19226624 | coarse | our code, then hardware |
| EOP buffer | 4096 | coarse, EXECUTABLE | hardware |
| doorbell page | 8192 | mmap 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.
| field | value |
|---|---|
| CREATE_QUEUE | nr 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.
docs/queue.mddocs/lessons.mdkfd_queue.ckfd_mqd_manager_v11.cqueues.c