mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
The driver's persistent AQL queues are legacy kernel queues MES maps; a device reset takes them with MES's state. Upstream's device recovery now carries them across: - As upstream halts the device, a DRM client of the device (the hook upstream gives everything outside amdgpu that must stop before its IPs suspend) marks every mapped queue unmapped. Kicks are refused until it is mapped again. - Once the reset has succeeded and the schedulers run again (where KFD restores its queues), before the new reset generation is published, each queue's storage block is written again with an MQD upstream builds afresh, positioned at the producer's write_dispatch_id, the reader is moved there, and the queue is mapped. Packets not finished were lost with the GPU's state; the generation tells clients. The restore writes the storage through SDMA, so it cannot run from the DRM client's resume, which precedes the schedulers' restart. - A queue that cannot be mapped again is retained, and its owner's next call freezes the session. A queue destroyed after a reset that was not followed by a restore (the device wedged) is freed without an MES unmap. The hooks run on the reset domain's thread while the owner queue serves calls, so dext_aql keeps its own list of mapped queues under a lock held only across bounded steps (MES map/unmap, storage writes), never across a wait the reset must finish. Without it a restore could write a queue a destroy had just freed. The fixture's device-reset-recovers check failed intermittently: the fixture's ASIC reset zeroed its engines' read pointers while the driver's rings kept their write pointers (the fixture's IP blocks had no resume), and an engine could also carry on mid-batch from the cleared position. The SDMA engine then executed its stale ring from the start, old fence values included; amdgpu_fence_process took the lower sequence for a wrap and signalled every pending fence, so a new client's IB ran before its page-table update and faulted. The ASIC reset now stops each engine at a packet boundary, and the fixture's GFX and SDMA blocks resume their rings at 0 as gfx_v12_0 and sdma_v7_0 do. The check now also asserts both resumes ran. Tests: test-aql-reset builds the real dext_aql.mm against a mock MES and checks restore at the producer's position, kicks refused in between, the wedged destroy, a failed restore, and the hooks on their own thread against 300 rounds of create/kick/destroy under ASan and TSan (without the lock it reports a use-after-free). The production-backend scenarios cover the hooks' installation and the freeze on a failed restore; the fixture's device-reset-recovers covers upstream's recovery running the hooks around a real reset.
101 lines
4.7 KiB
C
101 lines
4.7 KiB
C
/* DriverKit AQL ownership over upstream MES queue operations. */
|
|
#ifndef LINUXU_RT_QUEUE_H
|
|
#define LINUXU_RT_QUEUE_H
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
struct amdgpu_device;
|
|
|
|
/* Upper bound on first-MEC HQDs: the size of amdgpu's per-MEC queue bitmap
|
|
* (AMDGPU_MAX_COMPUTE_QUEUES); queue.c asserts the two agree. */
|
|
#define RT_QUEUE_MAX_SLOTS 128u
|
|
#define RT_QUEUE_MASK_WORDS (RT_QUEUE_MAX_SLOTS / 64u)
|
|
|
|
/* COMPUTE_TMPRING_SIZE's WAVES and WAVESIZE fields as the family's upstream
|
|
* gc register header defines them (all zero: family without a known
|
|
* layout, so AQL queues run without scratch). */
|
|
struct rt_tmpring_layout {
|
|
uint32_t waves_mask, waves_shift;
|
|
uint32_t wave_size_mask, wave_size_shift;
|
|
};
|
|
|
|
/* Device properties the AQL metadata and scratch setup consume, read from
|
|
* upstream's discovery results (GC IP version, gfx.config, gfx.cu_info).
|
|
* mqd_bytes is the space upstream KFD's MQD manager needs for one MQD
|
|
* (AMDGPU_MQD_SIZE_ALIGN of its mqd_size). */
|
|
struct rt_queue_geometry {
|
|
uint32_t gfx_major, gfx_minor, gfx_revision;
|
|
uint32_t engines, compute_units, waves_per_cu;
|
|
uint32_t mqd_bytes;
|
|
struct rt_tmpring_layout tmpring;
|
|
};
|
|
|
|
/* First-MEC HQD ownership as bitmaps (bit = pipe * queues_per_pipe + queue,
|
|
* as amdgpu_gfx_mec_queue_to_bit() numbers them; word = bit / 64).
|
|
* kernel_mask: upstream kernel compute rings (mec_bitmap before partition).
|
|
* mes_mask: HQDs SET_HW_RESOURCES gave the MES scheduler (KFD, user queues).
|
|
* dext_mask: legacy HQDs reserved for DriverKit AQL queues.
|
|
* kfd_mask: KFD's current cp_queue_bitmap copy (0 without KFD).
|
|
* owned_mask: dext_mask entries currently reserved.
|
|
* doorbells: dword doorbell index per dext_mask slot, 0 elsewhere. */
|
|
struct rt_queue_partition {
|
|
uint32_t pipes, queues_per_pipe;
|
|
uint64_t kernel_mask[RT_QUEUE_MASK_WORDS], mes_mask[RT_QUEUE_MASK_WORDS];
|
|
uint64_t dext_mask[RT_QUEUE_MASK_WORDS], kfd_mask[RT_QUEUE_MASK_WORDS];
|
|
uint64_t owned_mask[RT_QUEUE_MASK_WORDS];
|
|
uint32_t doorbells[RT_QUEUE_MAX_SLOTS];
|
|
};
|
|
|
|
static inline int rt_queue_mask_test(const uint64_t *mask, uint32_t slot)
|
|
{
|
|
return slot < RT_QUEUE_MAX_SLOTS && ((mask[slot / 64u] >> (slot % 64u)) & 1u);
|
|
}
|
|
|
|
/* GPU addresses and sizes of one AQL queue, in the units upstream KFD's
|
|
* struct queue_properties uses (bytes; sizes are powers of two). */
|
|
struct rt_queue_mqd {
|
|
uint64_t mqd_address;
|
|
uint64_t ring_address;
|
|
uint64_t read_pointer; /* amd_queue_t read_dispatch_id */
|
|
uint64_t write_pointer; /* amd_queue_t write_dispatch_id */
|
|
uint64_t eop_address;
|
|
uint32_t ring_bytes, eop_bytes;
|
|
};
|
|
|
|
/* -ENODEV without MES legacy-queue mapping or KFD; -EOPNOTSUPP when a
|
|
* capability the partition relies on is absent (multiple XCCs). */
|
|
int rt_queue_geometry(struct amdgpu_device *, struct rt_queue_geometry *);
|
|
/* The device part of the geometry alone (mqd_bytes 0): what AQL metadata
|
|
* and scratch need for a queue any scheduler runs, legacy HQD or not.
|
|
* -EINVAL when discovery left a count zero. */
|
|
int rt_queue_device_geometry(struct amdgpu_device *, struct rt_queue_geometry *);
|
|
/* Idempotent. Reserves the legacy HQDs no upstream ring or MES scheduler
|
|
* uses, marks them kernel-owned in mec_bitmap and removes them from KFD's
|
|
* cp_queue_bitmap. -ENOSPC when no such HQD exists. */
|
|
int rt_queue_partition(struct amdgpu_device *, struct rt_queue_partition *out);
|
|
int rt_queue_reserve(struct amdgpu_device *, uint32_t *slot, uint32_t *doorbell);
|
|
void rt_queue_release(struct amdgpu_device *, uint32_t slot);
|
|
/* Writes the AQL compute MQD for a reserved slot into mqd (mqd_bytes long,
|
|
* at least rt_queue_geometry().mqd_bytes): upstream KFD's kernel-queue MQD
|
|
* manager for this device builds it, and the legacy kernel queue fields
|
|
* (doorbell enable, inactive HQD, no CWSR, no debugger) come from amdgpu's
|
|
* own kernel compute queue MQD builder, so MES MAP_LEGACY_QUEUE receives
|
|
* what amdgpu gives it for its kernel compute rings. */
|
|
int rt_queue_build_mqd(struct amdgpu_device *, uint32_t slot, uint32_t doorbell,
|
|
const struct rt_queue_mqd *, void *mqd, size_t mqd_bytes);
|
|
/* Make the MQD that rt_queue_build_mqd wrote start at AQL packet @packet
|
|
* of a ring of @ring_bytes (a queue mapped again after a device reset
|
|
* resumes where its producer is). 0 or -EINVAL. */
|
|
int rt_queue_mqd_set_position(void *mqd, uint64_t ring_bytes, uint64_t packet);
|
|
int rt_queue_map(struct amdgpu_device *, uint32_t slot, uint32_t doorbell,
|
|
uint64_t mqd, uint64_t write_pointer);
|
|
int rt_queue_unmap(struct amdgpu_device *, uint32_t slot, uint32_t doorbell);
|
|
int rt_queue_kick(struct amdgpu_device *, uint32_t doorbell, uint64_t packet);
|
|
void rt_queue_flush(struct amdgpu_device *);
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|