mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
HRX on Linux keeps a queue's kernel arguments in CPU-visible VRAM and publishes them with the HDP flush register when the HSA runtime reports HSA_AMD_AGENT_INFO_HDP_FLUSH and lets the CPU at the device coarse pool. This brings that path to the Mac, where a CPU store to a GPU that stopped answering can panic the machine, so every such store is bracketed under the client's gate. patches/linux/amdgpu-mmio-remap-4k-hole.patch: the NBIO/NBIF HDP flush remap stays in the 4 KiB register hole the hardware leaves unused, whatever the host page size (upstream moved it with PAGE_SIZE and turned it off for pages over 4 KiB). KFD's own MMIO paths still refuse large pages; nothing upstream maps the page into a process. linuxu (kfd_session.c): rt_kfd_session_hdp_flush gives the host page of the register BAR holding the remap page, after checking that no register block of the device starts in the rest of it. VRAM can take a window VA, and rt_kfd_bo_make_cpu_visible pins such a buffer in the CPU-visible window: unmapped from the GPU, off the eviction fence, pinned with CPU_ACCESS_REQUIRED, the move waited for, mapped again at the same VA. rt_kfd_bo_bar_ranges reports its BAR ranges; a free unpins it first. dext (hdp_flush.h): QueryInfo MLG_QUERY_BAR_WRITES lets a KFD client opt in. It gets its gate (published, so every power transition, reset, quarantine, fault, removal and close closes it and drains), the HDP flush page as client memory, and CPU access to hostable VRAM: BOAlloc flag DEXT_COMPUTE_BO_FLAG_HOSTABLE, then BOMap pins it and hands out its BAR ranges. A client that never asks gets none of it. A retired gate is marked so the client knows it never reopens. Closes that stop the device answering (the session's close, quarantine, reset) wait up to 1 s for an open bracket. Build 265. HSA runtime: mac_hsa_bar_writes_enable, mac_hsa_bar_write_begin and mac_hsa_bar_write_end. After enable the agent reports HDP_FLUSH, the CPU agent's access to the VRAM pool is DISALLOWED_BY_DEFAULT, VRAM is allocated hostable, and hsa_amd_agents_allow_access with a CPU agent maps an allocation write combined at its own address, as ROCr does on a large-BAR device; nothing else is CPU-mapped. begin waits while the gate is held and fails once the device is gone, after replacing every BAR mapping of the process with host memory (bar_mapping_retire.h); kicks that find the GPU disconnected do the same. libmlg_drm: a transport that says the device is gone has every mapping retired the same way, so Vulkan clients' stores through mapped VRAM and doorbells land in host memory too. Tests: the session test pins hostable VRAM, checks its BAR ranges, a full window and the HDP page with and without a register block beside it; the production test enables BAR writes, maps hostable VRAM and ranges it; hsa-bar-writes checks what is reported before and after enable, the CPU grant, nested brackets, a held gate and a lost device; the gate and libmlg_drm tests check retired gates and mappings.
361 lines
19 KiB
C
361 lines
19 KiB
C
/* KFD compute sessions: one Linux process per runtime client, driving the
|
|
* unmodified upstream KFD through its own character device.
|
|
*
|
|
* A session is what a ROCr/libhsakmt process is on Linux. Opening one
|
|
* creates a linuxu process (task, mm, files), opens the KFD chardev and the
|
|
* device's DRM render node into that process's descriptor table, and then
|
|
* issues the ioctls libhsakmt issues when it opens KFD (hsaKmtOpenKFD and
|
|
* hsakmt_fmm_init_process_apertures): GET_VERSION,
|
|
* GET_PROCESS_APERTURES_NEW, ACQUIRE_VM(render fd), SET_MEMORY_POLICY and
|
|
* RUNTIME_ENABLE. Every call runs inside the process (linuxu_process_enter)
|
|
* through the registered file_operations, with its argument block in a
|
|
* per-call user VMA, so KFD's copy_from_user/copy_to_user see what they see
|
|
* on Linux.
|
|
*
|
|
* Memory is ALLOC_MEMORY_OF_GPU + MAP_MEMORY_TO_GPU at a GPU VA in the
|
|
* process's GPUVM (its own VMID while queues run). Queues are CREATE_QUEUE
|
|
* (COMPUTE_AQL) with ring, read/write pointers, EOP and context-save areas
|
|
* that are BOs of the same process, as kfd_queue_acquire_buffers requires;
|
|
* KFD's device queue manager hands them to the MES scheduler. Kicks write
|
|
* the doorbell KFD allocated, located through KFD's own doorbell mmap.
|
|
*
|
|
* Closing destroys every queue and BO, then exits the process: the mmu
|
|
* notifier release runs KFD's process teardown (exit_mm) and the KFD and
|
|
* render descriptors are closed (exit_files), as when a Linux process dies.
|
|
*
|
|
* All calls on one session are serialized by the session. A session never
|
|
* hard-codes a GPU: sizes come from the KFD topology node and apertures
|
|
* from the ioctls. Runtime: linuxu/src/amdgpu-rt/kfd_session.c. */
|
|
#ifndef LINUXU_RT_KFD_SESSION_H
|
|
#define LINUXU_RT_KFD_SESSION_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct amdgpu_device;
|
|
struct rt_compute_ctx;
|
|
struct rt_kfd_session;
|
|
struct rt_kfd_bo;
|
|
struct rt_kfd_queue;
|
|
|
|
/* 0 when @adev can back a session: KFD bound a device node to it (a GPU
|
|
* node in the KFD topology), its queue manager schedules through MES, and
|
|
* the KFD and DRM character devices are registered. -ENODEV otherwise. */
|
|
int rt_kfd_session_supported(struct amdgpu_device *adev);
|
|
|
|
/* The process-device apertures KFD reported for this device
|
|
* (GET_PROCESS_APERTURES_NEW), plus the KFD interface version. */
|
|
struct rt_kfd_apertures {
|
|
uint32_t gpu_id;
|
|
uint32_t version_major, version_minor;
|
|
uint64_t lds_base, lds_limit;
|
|
uint64_t scratch_base, scratch_limit;
|
|
uint64_t gpuvm_base, gpuvm_limit;
|
|
};
|
|
|
|
/* Queue resources KFD's topology node prescribes for one compute queue.
|
|
* slots is the number of queues a process may create on the device
|
|
* (pqm_create_queue's per-process limit). */
|
|
struct rt_kfd_queue_limits {
|
|
uint32_t slots;
|
|
uint32_t eop_bytes;
|
|
uint32_t ctx_save_bytes; /* per XCC (node cwsr_size) */
|
|
uint32_t ctl_stack_bytes;
|
|
uint32_t debug_bytes; /* per XCC (node debug_memory_size) */
|
|
uint32_t xcc_count;
|
|
uint64_t ctx_area_bytes; /* what CREATE_QUEUE validates */
|
|
uint32_t doorbell_slice_bytes;
|
|
};
|
|
|
|
/* Open a session for a client whose pid is @pid (a counter value when
|
|
* pid <= 0) and whose command name is @comm. @ctx supplies the GART-mapped
|
|
* staging the session copies VRAM through. */
|
|
int rt_kfd_session_open(struct amdgpu_device *adev, struct rt_compute_ctx *ctx,
|
|
int pid, const char *comm, struct rt_kfd_session **out);
|
|
/* Destroy every queue (DESTROY_QUEUE), free every BO (UNMAP + FREE), exit
|
|
* the process and free @s, as a Linux process that dies with live queues is
|
|
* torn down. Returns 0 after a clean close.
|
|
*
|
|
* Every wait is bounded. A queue whose DESTROY_QUEUE MES did not confirm
|
|
* (a wave that does not preempt, a slow or failed MES acknowledgement) is
|
|
* recovered as upstream recovers a hung user queue: MES detects and resets
|
|
* hung compute queues, then removes this one again (remove after reset).
|
|
* A copy that outlived its timeout is waited for once more. Only when the
|
|
* GPU still did not let go is the session kept (returns -EBUSY): every
|
|
* later call but rt_kfd_session_settle and close fails, and the caller must
|
|
* treat the device as uncertain. Closing again retries the recovery. */
|
|
int rt_kfd_session_close(struct rt_kfd_session *s);
|
|
/* Nonzero while a teardown step has not confirmed the GPU let go. */
|
|
int rt_kfd_session_uncertain(const struct rt_kfd_session *s);
|
|
/* Re-examine what made the session uncertain without closing it: wait up to
|
|
* @wait_ms for a copy that outlived its timeout and retry the recovery of
|
|
* every queue whose removal failed. Returns 0 once nothing is uncertain
|
|
* (the session works again), -EBUSY otherwise. */
|
|
int rt_kfd_session_settle(struct rt_kfd_session *s, unsigned int wait_ms);
|
|
|
|
/* The teardown step that first failed to confirm that the GPU let go of the
|
|
* session's memory, for diagnostics. */
|
|
enum rt_kfd_step {
|
|
RT_KFD_STEP_NONE = 0,
|
|
RT_KFD_STEP_COPY = 1, /* an SDMA copy did not complete in time */
|
|
RT_KFD_STEP_DESTROY_QUEUE = 2, /* DESTROY_QUEUE failed, KFD kept the queue */
|
|
RT_KFD_STEP_MES_RESET = 3, /* MES hung-queue detection/reset failed */
|
|
RT_KFD_STEP_MES_REMOVE = 4, /* MES did not remove the queue after reset */
|
|
/* A queue of a process whose GPU work faulted was still on an HQD after
|
|
* KFD evicted it and MES confirmed, and stayed there through MES's
|
|
* hung-queue reset: a GPU reset was requested. */
|
|
RT_KFD_STEP_CP_STUCK = 5,
|
|
};
|
|
/* The first failed step (RT_KFD_STEP_*) and its error, even after recovery
|
|
* succeeded; RT_KFD_STEP_NONE when no step failed. */
|
|
int rt_kfd_session_failure(const struct rt_kfd_session *s, int *error);
|
|
|
|
int rt_kfd_session_pid(const struct rt_kfd_session *s);
|
|
int rt_kfd_session_apertures(struct rt_kfd_session *s, struct rt_kfd_apertures *out);
|
|
int rt_kfd_session_queue_limits(struct rt_kfd_session *s, struct rt_kfd_queue_limits *out);
|
|
|
|
/* The client's host window: the range of process VAs the client maps its
|
|
* shared buffers at (CPU VA == GPU VA). The session offers a power-of-two
|
|
* size covering the host memory a process can map
|
|
* (rt_kfd_session_window_size); the client reserves that much of its own
|
|
* address space, aligned to the size, and sets the base once, before any
|
|
* window BO exists (@size 0: the offered size; a smaller power of two keeps
|
|
* a window the client already reserved, such as the GART window). The
|
|
* window must lie inside the GPUVM aperture and below the session's private
|
|
* range (the top quarter of the aperture). rt_kfd_session_window reports a
|
|
* zero base until it is set, and the offered size until then. */
|
|
uint64_t rt_kfd_session_window_size(struct rt_kfd_session *s);
|
|
int rt_kfd_session_set_window(struct rt_kfd_session *s, uint64_t base, uint64_t size);
|
|
int rt_kfd_session_window(struct rt_kfd_session *s, uint64_t *base, uint64_t *size);
|
|
|
|
enum rt_kfd_domain {
|
|
RT_KFD_GTT = 1,
|
|
RT_KFD_VRAM = 2,
|
|
};
|
|
/* Placement of a BO's VA. WINDOW: inside the client's host window (it is
|
|
* mapped by the client at that VA). PRIVATE: in the session's private range
|
|
* (GPU-only memory the client never maps: queue EOP/context save, scratch,
|
|
* VRAM). */
|
|
enum rt_kfd_place {
|
|
RT_KFD_PLACE_PRIVATE = 0,
|
|
RT_KFD_PLACE_WINDOW = 1,
|
|
};
|
|
struct rt_kfd_bo_info {
|
|
uint64_t va;
|
|
uint64_t size;
|
|
uint64_t handle; /* the KFD handle (gpu_id << 32 | idr) */
|
|
enum rt_kfd_domain domain;
|
|
};
|
|
/* ALLOC_MEMORY_OF_GPU at a VA the session chooses in @place, then
|
|
* MAP_MEMORY_TO_GPU on the session's device. @alignment is a power of two
|
|
* (0: the page size). GTT is coherent host memory; VRAM is device-local and
|
|
* not CPU-mapped (small BAR) until rt_kfd_bo_make_cpu_visible. VRAM placed
|
|
* in the window has a VA the client may later map at. */
|
|
int rt_kfd_bo_alloc(struct rt_kfd_session *s, uint64_t size, uint64_t alignment,
|
|
enum rt_kfd_domain domain, enum rt_kfd_place place,
|
|
struct rt_kfd_bo **out);
|
|
/* UNMAP_MEMORY_FROM_GPU + FREE_MEMORY_OF_GPU. -EBUSY while a queue of the
|
|
* session uses the BO. */
|
|
int rt_kfd_bo_free(struct rt_kfd_session *s, struct rt_kfd_bo *bo);
|
|
int rt_kfd_bo_info(struct rt_kfd_session *s, struct rt_kfd_bo *bo,
|
|
struct rt_kfd_bo_info *out);
|
|
/* Kernel-side access: GTT through the BO's pages, VRAM through SDMA copies
|
|
* between the BO's VRAM ranges and the session's staging. */
|
|
int rt_kfd_bo_read(struct rt_kfd_session *s, struct rt_kfd_bo *bo,
|
|
uint64_t offset, void *dst, size_t bytes);
|
|
int rt_kfd_bo_write(struct rt_kfd_session *s, struct rt_kfd_bo *bo,
|
|
uint64_t offset, const void *src, size_t bytes);
|
|
int rt_kfd_bo_copy(struct rt_kfd_session *s, struct rt_kfd_bo *src,
|
|
uint64_t src_offset, struct rt_kfd_bo *dst,
|
|
uint64_t dst_offset, uint64_t bytes);
|
|
/* CPU access to a VRAM BO placed in the window, as ROCr grants it with
|
|
* hsa_amd_agents_allow_access on a large-BAR device: the BO moves into the
|
|
* CPU-visible part of VRAM (the BAR window) and is pinned there until it is
|
|
* freed, so its bus ranges stay what rt_kfd_bo_bar_ranges reports. KFD
|
|
* refuses PUBLIC VRAM on a small BAR, and an unpinned BO's CPU mapping would
|
|
* go stale when TTM moves it, so the session pins it itself: it unmaps the
|
|
* BO from the GPU (UNMAP_MEMORY_FROM_GPU), takes it off the process's
|
|
* eviction fence (as KFD does for the BOs it kmaps), pins it with
|
|
* CPU_ACCESS_REQUIRED, waits for the move, and maps it again at the same VA
|
|
* (MAP_MEMORY_TO_GPU), so its page tables follow the move. Its contents are
|
|
* kept. -ENOSPC when the CPU-visible window has no room, -EBUSY while a queue
|
|
* uses the BO; idempotent. */
|
|
int rt_kfd_bo_make_cpu_visible(struct rt_kfd_session *s, struct rt_kfd_bo *bo);
|
|
/* The BAR ranges backing a BO made CPU-visible, in BO order: which BAR, the
|
|
* byte offset in it and the length (whole pages). @fn returning nonzero
|
|
* stops the walk with that value. -EINVAL for any other BO. */
|
|
int rt_kfd_bo_bar_ranges(struct rt_kfd_session *s, struct rt_kfd_bo *bo,
|
|
int (*fn)(void *arg, uint32_t bar, uint64_t offset, uint64_t bytes),
|
|
void *arg);
|
|
|
|
/* The device's HDP flush page, KFD's MMIO remap page: the 4 KiB page of the
|
|
* register BAR the NBIO remaps HDP_MEM_FLUSH_CNTL and HDP_REG_FLUSH_CNTL
|
|
* into (offsets KFD_MMIO_REMAP_HDP_MEM_FLUSH_CNTL and _REG_FLUSH_CNTL),
|
|
* which ROCr gets through KFD's MMIO mmap and reports as
|
|
* HSA_AMD_AGENT_INFO_HDP_FLUSH. A store there flushes HDP, so stores into
|
|
* VRAM through the BAR reach memory before the GPU reads it. A client maps
|
|
* whole host pages: @bar_offset is the host page that holds the remap page,
|
|
* @bytes one host page, @mem_flush and @reg_flush the registers' byte
|
|
* offsets in it. KFD's own mmap refuses host pages over 4 KiB; with them the
|
|
* rest of the host page is register space too, so the session checks that
|
|
* no register block of the device (IP discovery's base addresses) starts
|
|
* there besides the remap page and refuses with -EPERM if one does.
|
|
* -ENODEV when the device has no remap page. */
|
|
struct rt_kfd_hdp_flush {
|
|
uint32_t bar;
|
|
uint64_t bar_offset;
|
|
uint64_t bytes;
|
|
uint32_t mem_flush;
|
|
uint32_t reg_flush;
|
|
uint64_t visible_vram; /* the CPU-visible VRAM window's size */
|
|
};
|
|
int rt_kfd_session_hdp_flush(struct rt_kfd_session *s, struct rt_kfd_hdp_flush *out);
|
|
/* Whether the register blocks at dword base addresses @bases[0..@count)
|
|
* leave the host page [@page, @page + @page_bytes) of the register BAR to
|
|
* the 4 KiB remap page at @hole (byte offsets): no base lies in the page
|
|
* outside [@hole, @hole + 4096). Exposed for the host test. */
|
|
int rt_kfd_hdp_page_exclusive(const uint32_t *bases, unsigned int count, uint64_t page,
|
|
uint64_t page_bytes, uint64_t hole);
|
|
|
|
/* Walk the host pages backing a GTT BO as maximal CPU-contiguous runs, in
|
|
* BO order; @fn returning nonzero stops the walk with that value. The pages
|
|
* stay valid until rt_kfd_bo_free. -EINVAL for VRAM. */
|
|
int rt_kfd_bo_cpu_ranges(struct rt_kfd_session *s, struct rt_kfd_bo *bo,
|
|
int (*fn)(void *arg, void *cpu, uint64_t bytes), void *arg);
|
|
|
|
/* One AQL compute queue. ring, read/write pointer addresses are VAs inside
|
|
* BOs of this session: the ring BO must be exactly PAGE_ALIGN(ring_bytes)
|
|
* and the pointers inside the first GPU page of a one-page BO (KFD checks
|
|
* both). The session allocates the EOP buffer (VRAM) and the context-save
|
|
* area (GTT, header initialized as libhsakmt does) for the queue. */
|
|
struct rt_kfd_queue_desc {
|
|
struct rt_kfd_bo *ring;
|
|
uint32_t ring_bytes;
|
|
uint64_t read_pointer; /* VA */
|
|
uint64_t write_pointer; /* VA */
|
|
uint32_t priority; /* KFD queue priority, 0..15 */
|
|
};
|
|
struct rt_kfd_queue_info {
|
|
uint32_t queue_id;
|
|
uint32_t doorbell_index; /* dword index on the doorbell BAR */
|
|
uint64_t doorbell_offset; /* CREATE_QUEUE's mmap offset + byte offset */
|
|
uint64_t eop_va, ctx_save_va;
|
|
};
|
|
int rt_kfd_queue_create(struct rt_kfd_session *s, const struct rt_kfd_queue_desc *desc,
|
|
struct rt_kfd_queue **out);
|
|
/* Called after each queue creation that succeeded, outside the session
|
|
* lock (the dext sets it: rt_wptr_poll_observe). NULL: nothing. */
|
|
extern void (*rt_kfd_after_queue_create)(struct amdgpu_device *adev);
|
|
int rt_kfd_queue_info(struct rt_kfd_session *s, struct rt_kfd_queue *q,
|
|
struct rt_kfd_queue_info *out);
|
|
/* Write @value to the queue's doorbell (64-bit doorbells on SOC15). A
|
|
* value below one already written is not written again. */
|
|
int rt_kfd_queue_kick(struct rt_kfd_session *s, struct rt_kfd_queue *q, uint64_t value);
|
|
/* The same without the session lock and without sleeping: only the
|
|
* session's kick spinlock, held across the doorbell write. For a caller
|
|
* that must not sleep (the dext's delivery thread); it must keep @s and @q
|
|
* alive itself. 0, or -EAGAIN when the session lock's path must answer
|
|
* (the queue is not ringable: before its creation finished, from its
|
|
* DESTROY_QUEUE on; the session is uncertain or closing), -EFAULT once the
|
|
* process's GPU work faulted, -ERANGE for a doorbell outside the BAR. As
|
|
* on Linux, where the process writes its doorbell page itself, the value
|
|
* is not checked against the queue's write index. */
|
|
int rt_kfd_queue_kick_nowait(struct rt_kfd_session *s, struct rt_kfd_queue *q, uint64_t value);
|
|
/* The process's doorbell slice, as libhsakmt mmaps it (KFD's doorbell
|
|
* mmap): which BAR, the slice's byte offset on it and its size (one page,
|
|
* kfd_doorbell_process_slice). Every queue of the session has its doorbell
|
|
* in it, at doorbell_offset & (bytes - 1) (rt_kfd_queue_info). -ENODEV
|
|
* until the first queue mapped the slice; it then stays the session's until
|
|
* its close. */
|
|
struct rt_kfd_doorbells {
|
|
uint32_t bar;
|
|
uint64_t bar_offset;
|
|
uint64_t bytes;
|
|
};
|
|
int rt_kfd_session_doorbells(struct rt_kfd_session *s, struct rt_kfd_doorbells *out);
|
|
/* DESTROY_QUEUE, then free the queue's EOP and context-save BOs. When MES
|
|
* does not confirm the removal the queue is recovered as in
|
|
* rt_kfd_session_close; if that fails too the session becomes uncertain and
|
|
* keeps the queue, and destroying it again retries the recovery. */
|
|
int rt_kfd_queue_destroy(struct rt_kfd_session *s, struct rt_kfd_queue *q);
|
|
unsigned int rt_kfd_session_queue_count(struct rt_kfd_session *s);
|
|
|
|
/* GPU memory faults. A page fault of the process's GPU work (its PASID)
|
|
* reaches KFD's interrupt handler, which evicts every queue of the process
|
|
* and signals its memory events (kfd_set_dbg_ev_from_interrupt), as on
|
|
* Linux, where ROCr waits on such an event and reports the fault. Every
|
|
* session creates one at open (CREATE_EVENT, KFD_IOC_EVENT_MEMORY, manual
|
|
* reset). rt_kfd_session_fault returns 1 with what KFD reported once the
|
|
* process faulted, 0 while it has not, or a negative errno; it does not
|
|
* sleep. A faulted session's queues never run again: kicks fail with
|
|
* -EFAULT, and a close tears it down as any other. Other sessions and the
|
|
* device are not affected. */
|
|
struct rt_kfd_fault {
|
|
uint64_t va; /* the faulting page's GPU address */
|
|
uint32_t not_present, read_only, no_execute, imprecise;
|
|
};
|
|
int rt_kfd_session_fault(struct rt_kfd_session *s, struct rt_kfd_fault *out);
|
|
/* After a fault, KFD's eviction and its later DESTROY_QUEUE take the queues
|
|
* off MES, and MES confirms. A command processor stalled on the faulting
|
|
* access can keep running the queue on its HQD anyway, and then nothing
|
|
* else on that pipe completes. So when the fault is first seen, and again
|
|
* at close before any queue is destroyed, every compute HQD is read
|
|
* (kfd2kgd hqd_dump): one still active with one of the session's queues
|
|
* (its doorbell and MQD) is reset through MES's hung-queue reset; one that
|
|
* survives that makes the session request a GPU reset and stay uncertain,
|
|
* keeping its memory, until a settle or close finds the HQDs clear. */
|
|
|
|
/* Signal events: what an interrupt-driven wait sleeps on, as ROCr's
|
|
* interrupt signals use them through libhsakmt.
|
|
*
|
|
* rt_kfd_event_create is CREATE_EVENT (KFD_IOC_EVENT_SIGNAL, auto reset).
|
|
* The first one hands KFD the session's event page, a GTT BO in the
|
|
* session's private range that KFD maps for itself (kfd_event_page_set),
|
|
* as libhsakmt does on a dGPU. An amd_signal_t whose event_mailbox_ptr is
|
|
* @mailbox_va and whose event_id is @trigger makes the command processor
|
|
* write the mailbox and raise an interrupt when it completes the AQL packet
|
|
* that names the signal; KFD's interrupt handler then signals the event
|
|
* (kfd_signal_event_interrupt) and wakes whoever waits on it. Up to
|
|
* KFD_SIGNAL_EVENT_LIMIT events per session.
|
|
*
|
|
* A wait is WAIT_EVENTS, run on the caller's thread inside the process but
|
|
* outside the session lock, so many waits and every other call proceed
|
|
* together: rt_kfd_wait_begin registers it (the session cannot close under
|
|
* it), rt_kfd_wait_run sleeps until one event (or every event, @all)
|
|
* fires or @timeout_ms passes, then frees it. Nothing polls: the waiting
|
|
* thread runs again only for the interrupt or the timeout. Closing the
|
|
* session destroys its events, which ends every wait (result FAIL), and
|
|
* waits for them before the process exits. */
|
|
#define RT_KFD_WAIT_EVENTS_MAX 64u /* events one wait names */
|
|
#define RT_KFD_WAITS_MAX 64u /* waits at once per session */
|
|
#define RT_KFD_WAIT_MAX_MS 1000u /* longer timeouts are shortened */
|
|
struct rt_kfd_event {
|
|
uint32_t id; /* what WAIT_EVENTS, SET_EVENT, DESTROY_EVENT name */
|
|
uint32_t trigger; /* amd_signal_t.event_id */
|
|
uint64_t mailbox_va; /* amd_signal_t.event_mailbox_ptr */
|
|
};
|
|
int rt_kfd_event_create(struct rt_kfd_session *s, struct rt_kfd_event *out);
|
|
int rt_kfd_event_destroy(struct rt_kfd_session *s, uint32_t id);
|
|
/* SET_EVENT: a host-side change of a signal wakes its waiters. */
|
|
int rt_kfd_event_set(struct rt_kfd_session *s, uint32_t id);
|
|
unsigned int rt_kfd_event_count(struct rt_kfd_session *s);
|
|
|
|
struct rt_kfd_wait;
|
|
/* -EBUSY for RT_KFD_WAITS_MAX waits already, -ESHUTDOWN while closing. */
|
|
int rt_kfd_wait_begin(struct rt_kfd_session *s, const uint32_t *ids, uint32_t count,
|
|
int all, uint32_t timeout_ms, struct rt_kfd_wait **out);
|
|
/* 0 with *result KFD_IOC_WAIT_RESULT_COMPLETE (0), _TIMEOUT (1) or _FAIL
|
|
* (2, an event was destroyed), or a negative errno. */
|
|
int rt_kfd_wait_run(struct rt_kfd_wait *w, uint32_t *result);
|
|
/* Free a wait that will not run. */
|
|
void rt_kfd_wait_cancel(struct rt_kfd_wait *w);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|