mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
With amdgpu_gpu_recovery off, a job on a hung ring never completed and every wait on it lasted forever (build 241). Recovery is now upstream's default: a job that times out resets its queue (amdgpu_job_timedout -> ring->funcs->reset: a MES queue reset for compute and gfx, an SDMA queue reset), the guilty job's fence gets -ETIME, its context reports the reset (AMDGPU_CTX_QUERY2_FLAGS_RESET) and refuses further work, and the work queued behind it from other contexts runs. A device reset (mode1 on gfx12, after a failed queue reset, on a ring without one, or requested by KFD or a user queue) needs platform work not done yet over Thunderbolt: the PCI configuration's restore with its BARs, MSI-X, client BAR mappings in the reset window. Until then (rt_recovery_full_reset_available), rt/recovery.h turns every request for one into what Linux ends in when a reset fails: the device wedges. The DRM device is unplugged (new requests fail with -ENODEV), hardware access and bus mastering stop, every ring's fences complete with -ECANCELED and keep completing, and KFD's waiters get its reset event. Nothing waits forever and nothing loops on resets. rt_recovery_attach hooks this in after the probe without changing upstream: each scheduler's timeout handler and each queue reset are wrapped (upstream's run unchanged inside; every recovery handler runs on the reset domain's one ordered queue), and the KFD and user-queue reset works are redirected to the wedge. Each queue reset that succeeds, and the wedge, advance a reset generation. The driver publishes it as QueryInfo "LRST" (generation, wedged and VRAM-lost flags, queue resets, VRAM-lost counter, last result), sets MLG_SESSION_FLAG_GPU_WEDGED in the session state, logs both as unified-log events, and the host app and read-driver-log.py say to power-cycle the GPU when it is wedged. The CS fixture resets queues as MES does (fx_ring_reset, with a ring test that runs on the engine). queue_reset_check hangs a compute job: the timeout fires, the queue resets without a device reset, another process's job behind it runs, the guilty context reports the reset and refuses work, a new context works and the generation advances. wedge_check (a process of its own) makes the queue reset fail: the device wedges, blocked work and a wait with no deadline end, new requests fail with -ENODEV, and no device reset is tried. ttm_evict_check's stalled move now ends with an SDMA queue reset.
172 lines
4.7 KiB
C
172 lines
4.7 KiB
C
#include <assert.h>
|
|
#include <linux/errno.h>
|
|
#include <string.h>
|
|
#include <linux/init.h>
|
|
#include <rt/bootstrap.h>
|
|
|
|
static char trace[32];
|
|
static unsigned int trace_len;
|
|
static int fail_stage;
|
|
static int recursive_result;
|
|
static int retained_probe;
|
|
static unsigned int memory_init_calls;
|
|
int linuxu_sysinfo_init(void)
|
|
{
|
|
++memory_init_calls;
|
|
return fail_stage == 7 ? -ENODEV : 0;
|
|
}
|
|
int rt_pci_has_retained_probe(void) { return retained_probe; }
|
|
int amdgpu_runtime_pm = -1;
|
|
int amdgpu_ras_enable = -1;
|
|
unsigned int amdgpu_ras_mask = ~0U;
|
|
unsigned int amdgpu_debug_mask;
|
|
int amdgpu_num_kcq;
|
|
int amdgpu_rebar = -1;
|
|
unsigned int amdgpu_pp_feature_mask = 0xfff7bfff; /* upstream default */
|
|
int amdgpu_gpu_recovery = 0; /* the bootstrap must set upstream's default */
|
|
int amdgpu_dc = -1; /* upstream default */
|
|
static int expect_dc;
|
|
int linuxu_timer_service_init(void) { return fail_stage == 5 ? -EAGAIN : 0; }
|
|
static unsigned int workqueue_init_calls;
|
|
int linuxu_workqueue_init(void)
|
|
{
|
|
++workqueue_init_calls;
|
|
return fail_stage == 8 ? -EAGAIN : 0;
|
|
}
|
|
|
|
static void event(char c)
|
|
{
|
|
assert(trace_len < sizeof(trace) - 1);
|
|
trace[trace_len++] = c;
|
|
trace[trace_len] = '\0';
|
|
}
|
|
|
|
static int gpu_buddy_module_init(void)
|
|
{
|
|
event('B');
|
|
return fail_stage == 6 ? -ENOMEM : 0;
|
|
}
|
|
static void gpu_buddy_module_exit(void) { event('b'); }
|
|
|
|
static int drm_core_init(void)
|
|
{
|
|
event('D');
|
|
if (fail_stage == 4)
|
|
recursive_result = linuxu_driver_bootstrap();
|
|
return fail_stage == 1 ? -EIO : 0;
|
|
}
|
|
static void drm_core_exit(void) { event('d'); }
|
|
static int drm_sched_fence_slab_init(void)
|
|
{
|
|
event('S');
|
|
return fail_stage == 2 ? -ENOMEM : 0;
|
|
}
|
|
static void drm_sched_fence_slab_fini(void) { event('s'); }
|
|
static int amdgpu_init(void)
|
|
{
|
|
event('A');
|
|
assert(amdgpu_runtime_pm == 0);
|
|
assert(amdgpu_rebar == 0);
|
|
assert(amdgpu_ras_enable == 0);
|
|
assert(amdgpu_ras_mask == 0);
|
|
/* GFXOFF (PP_GFXOFF_MASK) is cleared; other PP features are kept. */
|
|
assert(amdgpu_pp_feature_mask == (0xfff7bfffu & ~0x8000u));
|
|
assert(amdgpu_gpu_recovery == -1);
|
|
assert(amdgpu_dc == expect_dc);
|
|
return fail_stage == 3 ? -ENODEV : 0;
|
|
}
|
|
static void amdgpu_exit(void) { event('a'); }
|
|
|
|
module_init(drm_core_init);
|
|
module_exit(drm_core_exit);
|
|
module_init(gpu_buddy_module_init);
|
|
module_exit(gpu_buddy_module_exit);
|
|
module_init(drm_sched_fence_slab_init);
|
|
module_exit(drm_sched_fence_slab_fini);
|
|
module_init(amdgpu_init);
|
|
module_exit(amdgpu_exit);
|
|
|
|
static void reset(int stage)
|
|
{
|
|
fail_stage = stage;
|
|
trace_len = 0;
|
|
trace[0] = '\0';
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
assert(trace_len == 0); /* linking the modules does not start them */
|
|
assert(memory_init_calls == 0);
|
|
reset(7);
|
|
assert(linuxu_driver_bootstrap() == -ENODEV);
|
|
assert(memory_init_calls == 1);
|
|
assert(trace_len == 0);
|
|
linuxu_driver_shutdown();
|
|
assert(trace_len == 0);
|
|
|
|
reset(5);
|
|
assert(linuxu_driver_bootstrap() == -EAGAIN);
|
|
assert(trace_len == 0);
|
|
assert(workqueue_init_calls == 0);
|
|
|
|
/* System workqueues exist before any module init can queue work. */
|
|
reset(8);
|
|
assert(linuxu_driver_bootstrap() == -EAGAIN);
|
|
assert(workqueue_init_calls == 1);
|
|
assert(trace_len == 0);
|
|
|
|
reset(6);
|
|
assert(linuxu_driver_bootstrap() == -ENOMEM);
|
|
assert(strcmp(trace, "B") == 0);
|
|
linuxu_driver_shutdown();
|
|
assert(strcmp(trace, "B") == 0);
|
|
|
|
reset(1);
|
|
assert(linuxu_driver_bootstrap() == -EIO);
|
|
assert(strcmp(trace, "BDb") == 0);
|
|
linuxu_driver_shutdown();
|
|
assert(strcmp(trace, "BDb") == 0);
|
|
|
|
reset(2);
|
|
assert(linuxu_driver_bootstrap() == -ENOMEM);
|
|
assert(strcmp(trace, "BDSdb") == 0);
|
|
|
|
reset(3);
|
|
amdgpu_runtime_pm = -1;
|
|
assert(linuxu_driver_bootstrap() == -ENODEV);
|
|
assert(strcmp(trace, "BDSAsdb") == 0);
|
|
|
|
/* Display is off unless requested; the request restores upstream's
|
|
* amdgpu.dc default and cannot change while the modules run. */
|
|
assert(!linuxu_driver_display_enabled());
|
|
reset(3);
|
|
assert(linuxu_driver_set_display(1) == 0);
|
|
assert(linuxu_driver_display_enabled());
|
|
expect_dc = -1;
|
|
assert(linuxu_driver_bootstrap() == -ENODEV);
|
|
assert(linuxu_driver_set_display(0) == 0);
|
|
expect_dc = 0;
|
|
|
|
reset(4);
|
|
assert(linuxu_driver_bootstrap() == 0);
|
|
assert(linuxu_driver_set_display(1) == -EBUSY);
|
|
assert(!linuxu_driver_display_enabled());
|
|
assert(recursive_result == -EBUSY);
|
|
assert(strcmp(trace, "BDSA") == 0);
|
|
assert(linuxu_driver_bootstrap() == -EALREADY);
|
|
assert(strcmp(trace, "BDSA") == 0);
|
|
retained_probe = 1;
|
|
unsigned int memory_calls_before_retention = memory_init_calls;
|
|
linuxu_driver_shutdown();
|
|
assert(strcmp(trace, "BDSA") == 0);
|
|
assert(linuxu_driver_bootstrap() == -EBUSY);
|
|
assert(memory_init_calls == memory_calls_before_retention);
|
|
assert(strcmp(trace, "BDSA") == 0);
|
|
retained_probe = 0;
|
|
linuxu_driver_shutdown();
|
|
assert(strcmp(trace, "BDSAasdb") == 0);
|
|
linuxu_driver_shutdown();
|
|
assert(strcmp(trace, "BDSAasdb") == 0);
|
|
return 0;
|
|
}
|