drm/amdgpu: pass the device to the multi ring reset helpers
Subsystems (2)
PATCH v4 1/13 drm/amdgpu: pass the device to the multi ring reset helpers
amdgpu_multi_ring_reset_helper_begin() and _end() take the device from the guilty ring. A reset triggered by a hung user queue has no guilty kernel ring, so pass the device explicitly and allow a NULL guilty ring.
No functional change.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 14 ++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 6 ++++-- 3 files changed, 14 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +2 -2
@@ -465,11 +465,11 @@ int amdgpu_device_ip_soft_reset(struct amdgpu_ring *guilty_ring, ring_type_mask =amdgpu_ring_mask_from_ip (ip_type);amdgpu_device_lock_reset_domain (adev->reset_domain); -amdgpu_multi_ring_reset_helper_begin (ring_type_mask, guilty_ring, guilty_fence); +amdgpu_multi_ring_reset_helper_begin (adev, ring_type_mask, guilty_ring, guilty_fence); r = ip_block->version->funcs->soft_reset (ip_block); - r =amdgpu_multi_ring_reset_helper_end (ring_type_mask, guilty_ring, r); + r =amdgpu_multi_ring_reset_helper_end (adev, ring_type_mask, guilty_ring, r);amdgpu_device_unlock_reset_domain (adev->reset_domain);if (r) {
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +8 -6
@@ -919,8 +919,9 @@ int amdgpu_ring_reset_helper_end(struct amdgpu_ring *ring,/** * amdgpu_multi_ring_reset_helper_begin() - Prepare multiple rings for a reset. * +* @adev: amdgpu device * @ring_type_mask: Bitmask of affected ring types -* @guilty_ring: The ring which is guilty of causing a reset. +* @guilty_ring: The ring which is guilty of causing a reset, or NULL. * @guilty_fence: The fence which didn't signal on the guilty ring. * * Useful when performing a GPU reset method that affects
@@ -938,11 +939,11 @@ int amdgpu_ring_reset_helper_end(struct amdgpu_ring *ring,* After the reset is complete, the caller should then call * amdgpu_multi_ring_reset_helper_end() to restore the rings. */ -void amdgpu_multi_ring_reset_helper_begin (const u32 ring_type_mask, +void amdgpu_multi_ring_reset_helper_begin (struct amdgpu_device *adev, +const u32 ring_type_mask,struct amdgpu_ring *guilty_ring,struct amdgpu_fence *guilty_fence) { -struct amdgpu_device *adev = guilty_ring->adev;struct amdgpu_fence *ring_guilty_fence;struct amdgpu_ring *ring;bool rings_busy;
@@ -1034,8 +1035,9 @@ void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask,/** * amdgpu_multi_ring_reset_helper_end() - Prepare multiple rings for a reset. * +* @adev: amdgpu device * @ring_type_mask: Bitmask of affected ring types -* @guilty_ring: The ring which is guilty of causing a reset. +* @guilty_ring: The ring which is guilty of causing a reset, or NULL. * @ret: Return code from the reset function. * * After calling amdgpu_multi_ring_reset_helper_begin()
@@ -1046,10 +1048,10 @@ void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask,* be called to restore preemption state, but it won't attempt to * fully restore the ring contents. */ -int amdgpu_multi_ring_reset_helper_end (const u32 ring_type_mask, +int amdgpu_multi_ring_reset_helper_end (struct amdgpu_device *adev, +const u32 ring_type_mask,struct amdgpu_ring *guilty_ring,int ret) { -struct amdgpu_device *adev = guilty_ring->adev;struct amdgpu_ring *ring;int i, r;
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +4 -2
@@ -637,10 +637,12 @@ void amdgpu_ring_reset_helper_begin(struct amdgpu_ring *ring, struct amdgpu_fence *guilty_fence);int amdgpu_ring_reset_helper_end (struct amdgpu_ring *ring,struct amdgpu_fence *guilty_fence); -void amdgpu_multi_ring_reset_helper_begin (const u32 ring_type_mask, +void amdgpu_multi_ring_reset_helper_begin (struct amdgpu_device *adev, +const u32 ring_type_mask,struct amdgpu_ring *guilty_ring,struct amdgpu_fence *guilty_fence); -int amdgpu_multi_ring_reset_helper_end (const u32 ring_type_mask, +int amdgpu_multi_ring_reset_helper_end (struct amdgpu_device *adev, +const u32 ring_type_mask,struct amdgpu_ring *guilty_ring,int ret);bool amdgpu_ring_is_reset_type_supported (struct amdgpu_ring *ring,u32 reset_type);
Signature · 1 line
2.50.1
PATCH v4 2/13 drm/amdgpu/ring: During multi-queue reset, only call begin helper if needed
From: Timur Kristóf <[email protected]>
This is necessary to make soft reset work after a failed queue reset. Otherwise the ring reset begin helper would clear out the guilty fence and the backed up ring contents.
v2: skip the begin helper only for the guilty ring already backed up by
the failed ring reset, and keep backing up the other rings (Jesse).
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +3 -1
@@ -1027,8 +1027,10 @@ void amdgpu_multi_ring_reset_helper_begin(struct amdgpu_device *adev,* Backup current contents of the ring. * The helper takes care to only reemit unsignalled fences * so we don't have to worry about that here. +* A failed ring reset of the same job already backed it up. */ -amdgpu_ring_reset_helper_begin (ring, ring_guilty_fence); +if (ring != guilty_ring || ring->guilty_fence != guilty_fence) +amdgpu_ring_reset_helper_begin (ring, ring_guilty_fence); } }
Signature · 1 line
2.50.1
Re: [PATCH v4 02/13] drm/amdgpu/ring: During multi-queue reset, only call begin helper if needed
Hi Timur, Jesse,
A test result from gfx6 (Southern Islands), where no ring reset runs before the IP block soft reset. I found and tested this with the help of an AI assistant, on my own laptop.
Machine: Radeon R5 M330/M430 (Hainan, 1002:6660) beside a Carrizo iGPU.
Test: a plain Vulkan program with one compute dispatch that runs past the 2 s lockup timeout (a counted ALU loop, no bad memory access), then one short job to see whether the context was marked lost.
On 7.3.1 as released, one such job puts the ring into this loop until a reboot, every 3.45 s (a WebGPU page did the same: 1,449 timeouts of one sequence number):
amdgpu 0000:03:00.0: ring gfx timeout, signaled seq=30, emitted seq=31 amdgpu 0000:03:00.0: Starting gfx_v6_0 IP block soft reset amdgpu 0000:03:00.0: Successful gfx_v6_0 IP block soft reset amdgpu 0000:03:00.0: [drm] device wedged, but no recovery needed
The devcoredumps show why: after the first soft reset the replayed stream is consumed (Rptr == Wptr) but the fence is not written within the next 2 s; at the next timeout the backup helper sees the same guilty fence, clears ring->guilty_fence and backs up nothing, and amdgpu_multi_ring_reset_helper_end() passes that NULL on, so nothing ever completes the fence.
With this patch (v4 02/13) on 7.3.1, same program, same machine:
- two 8 s jobs: 2 timeouts each, then nothing more;
- one 60 s job: 3 timeouts, the job ended 10.8 s after it was submitted. In all three the next submission returned VK_ERROR_DEVICE_LOST, nothing was left in D state, and the session kept running.
For comparison, v3 02/15 ("complete the guilty fence at the end of a multi ring reset") on the same 7.3.1: 2 timeouts for each 8 s job, 1 for the 60 s job (ended after 3.4 s), the same result otherwise.
So on this chip both end the loop. One run of each case; I backported only this patch's single hunk (01/13 not needed for it to apply).
I can send the test program and the dumps if they are useful.
Thanks,
Daniel
Re: [PATCH v4 02/13] drm/amdgpu/ring: During multi-queue reset, only call begin helper if needed
In reply to Jesse ZhangQuoted 6 lines · Jesse Zhang
From: Timur Kristóf <[email protected]>
This is necessary to make soft reset work after a failed queue reset. Otherwise the ring reset begin helper would clear out the guilty fence and the backed up ring contents.
Quoted 7 lines
v2: skip the begin helper only for the guilty ring already backed up by
the failed ring reset, and keep backing up the other rings (Jesse).Signed-off-by Timur Kristóf <[email protected]>Signed-off-by Jesse Zhang <[email protected]>
Thanks for including this patch.
Considering that this fixes a real issue with repeated soft reset, I recommend adding a Fixes tag to this commit:
Quoted 27 lines
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -1027,8 +1027,10 @@ void amdgpu_multi_ring_reset_helper_begin(struct amdgpu_device *adev, * Backup current contents of the ring. * The helper takes care to only reemit unsignalledfences
* so we don't have to worry about that here.drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1
-0+* A failed ring reset of the same job already backed it up.
*/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-1- amdgpu_ring_reset_helper_begin(ring,
ring_guilty_fence);drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1
-0+ if (ring != guilty_ring || ring->guilty_fence !=
guilty_fence)drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1
-0+ amdgpu_ring_reset_helper_begin(ring,
ring_guilty_fence);
}
}
PATCH v4 3/13 drm/amdgpu: add an engine scope to the IP block soft reset
In reply to Jesse ZhangSome IP blocks have engines the hardware can reset on their own, eg. the graphics and compute engines of the GFX IP. Add an optional soft_reset_engine() callback, which resets the engine of a ring type and recovers its user queues. amdgpu_device_ip_soft_reset() uses it instead of soft_reset(), and then only stops and replays the rings of that type, holding the reset domain for read: KFD can still add and remove queues on the other engines.
A hung user queue has no kernel ring, so amdgpu_device_ip_soft_reset() now takes the device and the ring type, and an optional guilty ring and user queue.
v3: New patch, replaces the separate engine reset type and helper
(Timur).
v4: Fold the engine reset into amdgpu_device_ip_soft_reset(), and take
the ring type instead of a new engine enum (Timur).
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c | 59 ++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h | 7 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 3 +- drivers/gpu/drm/amd/include/amd_shared.h | 6 +++ 4 files changed, 52 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +39 -20
@@ -421,8 +421,11 @@ static u32 amdgpu_ring_mask_from_ip(const enum amd_ip_block_type ip_type)/** * amdgpu_device_ip_soft_reset() - Perform a graceful soft reset on an IP block. * -* @guilty_ring: The ring which is guilty of causing a reset. -* @guilty_fence: The fence which didn't signal. +* @adev: amdgpu device +* @ring_type: The type of the ring or user queue that hung. +* @guilty_ring: The ring which is guilty of causing a reset, or NULL. +* @guilty_fence: The fence which didn't signal on @guilty_ring. +* @guilty_queue: The user queue which is guilty of causing a reset, or NULL. * * IP block soft reset is used when attempting to recover * from a GPU hang in a situation where a more fine grained
@@ -430,55 +433,71 @@ static u32 amdgpu_ring_mask_from_ip(const enum amd_ip_block_type ip_type)* resets all rings that belong to the same device IP block * and re-initializes the device IP block. * +* IP blocks implementing soft_reset_engine() only reset the engine of +* @ring_type and its rings, and recover its user queues. +* * The reset is handled gracefully, meaning that we try to * minimize collateral damage (ie. avoid rejecting non-guilty jobs) * as well as back up and restore the contents of all rings * so that the system can move on from the hang. */ -int amdgpu_device_ip_soft_reset (struct amdgpu_ring *guilty_ring, -struct amdgpu_fence *guilty_fence) +int amdgpu_device_ip_soft_reset (struct amdgpu_device *adev, +enum amdgpu_ring_type ring_type, +struct amdgpu_ring *guilty_ring, +struct amdgpu_fence *guilty_fence, +struct amdgpu_usermode_queue *guilty_queue) { -struct amdgpu_device *adev = guilty_ring->adev; +const struct amd_ip_funcs *funcs;struct amdgpu_ip_block *ip_block;enum amd_ip_block_type ip_type;u32 ring_type_mask; +bool engine;int r; - ip_type =amdgpu_ip_from_ring (guilty_ring->funcs->type); + ip_type =amdgpu_ip_from_ring (ring_type); ip_block =amdgpu_device_ip_get_ip_block (adev, ip_type);if (unlikely (!ip_block)) { -dev_warn (adev->dev,"IP block not found for ring %s\n" , - guilty_ring->name); +dev_warn (adev->dev,"IP block not found for ring type %d\n" , + ring_type);return -EOPNOTSUPP ; } -if (!ip_block->version->funcs->soft_reset) { + funcs = ip_block->version->funcs; + engine = funcs->soft_reset_engine; +if (!engine && (!funcs->soft_reset || !guilty_ring)) {dev_warn (adev->dev,"IP block soft reset not supported on %s\n" , - ip_block->version->funcs->name); + funcs->name);return -EOPNOTSUPP ; } -dev_err (adev->dev,"Starting %s IP block soft reset\n" , - ip_block->version->funcs->name); - - ring_type_mask =amdgpu_ring_mask_from_ip (ip_type); +dev_err (adev->dev,"Starting %s IP block soft reset\n" , funcs->name); -amdgpu_device_lock_reset_domain (adev->reset_domain); +/* An engine reset leaves the others running: let KFD add/remove queues. */ +if (engine) { + ring_type_mask =BIT (ring_type); +down_read (&adev->reset_domain->sem); + }else { + ring_type_mask =amdgpu_ring_mask_from_ip (ip_type); +amdgpu_device_lock_reset_domain (adev->reset_domain); + }amdgpu_multi_ring_reset_helper_begin (adev, ring_type_mask, guilty_ring, guilty_fence); - r = ip_block->version->funcs->soft_reset (ip_block); + r = engine ? funcs->soft_reset_engine (ip_block, ring_type, guilty_queue) : + funcs->soft_reset (ip_block); r =amdgpu_multi_ring_reset_helper_end (adev, ring_type_mask, guilty_ring, r); -amdgpu_device_unlock_reset_domain (adev->reset_domain); +if (engine) +up_read (&adev->reset_domain->sem); +else +amdgpu_device_unlock_reset_domain (adev->reset_domain);if (r) {dev_err (adev->dev,"Failed %s IP block soft reset: %d\n" , - ip_block->version->funcs->name, r); + funcs->name, r);return r; } -dev_err (adev->dev,"Successful %s IP block soft reset\n" , - ip_block->version->funcs->name); +dev_err (adev->dev,"Successful %s IP block soft reset\n" , funcs->name);return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h +5 -2
@@ -158,7 +158,10 @@ int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev, enum amd_ip_block_type block_type);bool amdgpu_device_ip_is_valid (struct amdgpu_device *adev,enum amd_ip_block_type block_type); -int amdgpu_device_ip_soft_reset (struct amdgpu_ring *guilty_ring, -struct amdgpu_fence *guilty_fence); +int amdgpu_device_ip_soft_reset (struct amdgpu_device *adev, +enum amdgpu_ring_type ring_type, +struct amdgpu_ring *guilty_ring, +struct amdgpu_fence *guilty_fence, +struct amdgpu_usermode_queue *guilty_queue);#endif /* __AMDGPU_IP_H__ */
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +2 -1
@@ -154,7 +154,8 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)/* Attempt an IP block soft reset, if supported. */ if (amdgpu_gpu_recovery &&amdgpu_ring_is_reset_type_supported (ring,AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET )) { - r =amdgpu_device_ip_soft_reset (ring, job->hw_fence); + r =amdgpu_device_ip_soft_reset (adev, ring->funcs->type, ring, + job->hw_fence,NULL );if (!r) {atomic_inc (&ring->adev->gpu_reset_counter);drm_dev_wedged_event (adev_to_drm (adev),DRM_WEDGE_RECOVERY_NONE , info);
drivers/gpu/drm/amd/include/amd_shared.h +6 -0
@@ -29,6 +29,7 @@#define AMD_MAX_USEC_TIMEOUT 1000000/* 1000 ms */ struct amdgpu_ip_block ; +struct amdgpu_usermode_queue ;/*
@@ -421,6 +422,7 @@ enum DC_DEBUG_MASK { };enum amd_dpm_forced_level ; +enum amdgpu_ring_type ;/** * struct amd_ip_funcs - general hooks for managing amdgpu IP Blocks
@@ -441,6 +443,7 @@ enum amd_dpm_forced_level;* @complete: handles IP specific changes after resume * @wait_for_idle: poll for idle * @soft_reset: soft reset the IP block +* @soft_reset_engine: soft reset the engine of a ring type and its user queues * @set_clockgating_state: enable/disable cg for the IP block * @set_powergating_state: enable/disable pg for the IP block * @get_clockgating_state: get current clockgating status
@@ -469,6 +472,9 @@ struct amd_ip_funcs {void (*complete)(struct amdgpu_ip_block *ip_block);int (*wait_for_idle)(struct amdgpu_ip_block *ip_block);int (*soft_reset)(struct amdgpu_ip_block *ip_block); +int (*soft_reset_engine)(struct amdgpu_ip_block *ip_block, +enum amdgpu_ring_type ring_type, +struct amdgpu_usermode_queue *guilty_queue);int (*set_clockgating_state)(struct amdgpu_ip_block *ip_block,enum amd_clockgating_state state); int (*set_powergating_state)(struct amdgpu_ip_block *ip_block,
Signature · 1 line
2.50.1
Re: [PATCH v4 03/13] drm/amdgpu: add an engine scope to the IP block soft reset
Quoted 18 lines · Jesse Zhang
Some IP blocks have engines the hardware can reset on their own, eg. the graphics and compute engines of the GFX IP. Add an optional
soft_reset_engine()callback, which resets the engine of a ring type and
recovers its user queues.amdgpu_device_ip_soft_reset()uses it instead
ofsoft_reset(), and then only stops and replays the rings of that type,
holding the reset domain for read: KFD can still add and remove queues
on the other engines.A hung user queue has no kernel ring, so
amdgpu_device_ip_soft_reset()
now takes the device and the ring type, and an optional guilty ring and
user queue.
Quoted 8 lines
v3: New patch, replaces the separate engine reset type and helper (Timur).
v4: Fold the engine reset intoamdgpu_device_ip_soft_reset(), and take
the ring type instead of a new engine enum (Timur).Suggested-by Timur Kristóf <[email protected]>Signed-off-by Jesse Zhang <[email protected]>
Quoted 221 lines
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c | 59 ++++++++++++++++------ --
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h | 7 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 3 +-drivers/gpu/drm/amd/include/amd_shared.h| 6 +++4 files changed, 52 insertions(+), 23 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +0
-0@@ -421,8 +421,11 @@ static u32 amdgpu_ring_mask_from_ip(const enum amd_ip_block_type ip_type) /*** amdgpu_device_ip_soft_reset() - Perform a graceful soft reset on an IP block.
*
- * @guilty_ring: The ring which is guilty of causing a reset.
- * @guilty_fence: The fence which didn't signal.
+ * @adev: amdgpu device
+ * @ring_type: The type of the ring or user queue that hung.
+ * @guilty_ring: The ring which is guilty of causing a reset, or NULL.
+ * @guilty_fence: The fence which didn't signal on @guilty_ring.
+ * @guilty_queue: The user queue which is guilty of causing a reset, or NULL.
*
* IP block soft reset is used when attempting to recover
* from a GPU hang in a situation where a more fine graineddrivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-0@@ -430,55 +433,71 @@ static u32 amdgpu_ring_mask_from_ip(const enum amd_ip_block_type ip_type) * resets all rings that belong to the same device IP block * and re-initializes the device IP block. * + * IP blocks implementing soft_reset_engine() only reset the engineof
+ * @ring_type and its rings, and recover its user queues.
+ *
* The reset is handled gracefully, meaning that we try to
* minimize collateral damage (ie. avoid rejecting non-guilty jobs)
* as well as back up and restore the contents of all rings
* so that the system can move on from the hang.
*/drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +5
-2-int amdgpu_device_ip_soft_reset (struct amdgpu_ring *guilty_ring, -struct amdgpu_fence *guilty_fence) +int amdgpu_device_ip_soft_reset (struct amdgpu_device *adev, +enum amdgpu_ring_type ring_type, +struct amdgpu_ring *guilty_ring, +struct amdgpu_fence *guilty_fence, + struct amdgpu_usermode_queue
*guilty_queue)
{drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-1-struct amdgpu_device *adev = guilty_ring->adev; +const struct amd_ip_funcs *funcs;struct
amdgpu_ip_block*ip_block;
enumamd_ip_block_typeip_type;
u32ring_type_mask;drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-0+bool engine;int r;
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-1- ip_type =amdgpu_ip_from_ring (guilty_ring->funcs->type); + ip_type =amdgpu_ip_from_ring (ring_type);
ip_block=amdgpu_device_ip_get_ip_block(adev, ip_type);
if (unlikely(!ip_block)) {drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +0
-1- dev_warn(adev->dev, "IP block not found for ring%s\n",
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-1- guilty_ring->name); + dev_warn(adev->dev, "IP block not found for ringtype %d\n",
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-0+ ring_type);return
-EOPNOTSUPP;
}drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +3
-1-if (!ip_block->version->funcs->soft_reset) { + funcs = ip_block->version->funcs; + engine = funcs->soft_reset_engine; +if (!engine && (!funcs->soft_reset || !guilty_ring)) {dev_warn(adev->dev, "IP block soft reset not supported on %s\n",
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-1- ip_block->version->funcs->name); + funcs->name);return
-EOPNOTSUPP;
}drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-4-dev_err (adev->dev,"Starting %s IP block soft reset\n" , - ip_block->version->funcs->name); - - ring_type_mask =amdgpu_ring_mask_from_ip (ip_type); + dev_err(adev->dev, "Starting %s IP block soft reset\n",
funcs->name);drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-1-amdgpu_device_lock_reset_domain (adev->reset_domain); +/* An engine reset leaves the others running: let KFD add/remove queues. */
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +7
-0+if (engine) { + ring_type_mask =BIT (ring_type); +down_read (&adev->reset_domain->sem); + }else { + ring_type_mask =amdgpu_ring_mask_from_ip (ip_type); +amdgpu_device_lock_reset_domain (adev->reset_domain); + }
amdgpu_multi_ring_reset_helper_begin(adev, ring_type_mask, guilty_ring, guilty_fence);drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-1- r = ip_block->version->funcs->soft_reset (ip_block); + r = engine ? funcs->soft_reset_engine(ip_block, ring_type,
guilty_queue) :drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-0+ funcs->soft_reset(ip_block);
r =amdgpu_multi_ring_reset_helper_end(adev, ring_type_mask, guilty_ring, r);drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +4
-1-amdgpu_device_unlock_reset_domain (adev->reset_domain); +if (engine) +up_read (&adev->reset_domain->sem); +else + amdgpu_device_unlock_reset_domain(adev-Quoted 1 line
reset_domain);
if (r) {
dev_err(adev->dev, "Failed %s IP block soft reset:
%d\n",drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-1- ip_block->version->funcs->name, r); + funcs->name, r);return r;
}drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-2-dev_err (adev->dev,"Successful %s IP block soft reset\n" , - ip_block->version->funcs->name); + dev_err(adev->dev, "Successful %s IP block soft reset\n",
funcs->name);
return 0;
}drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h +0
-0@@ -158,7 +158,10 @@ int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,enum
amd_ip_block_typeblock_type);
boolamdgpu_device_ip_is_valid(struct amdgpu_device *adev, enum amd_ip_block_type block_type);drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h +5
-2-int amdgpu_device_ip_soft_reset (struct amdgpu_ring *guilty_ring, -struct amdgpu_fence *guilty_fence); +int amdgpu_device_ip_soft_reset (struct amdgpu_device *adev, +enum amdgpu_ring_type ring_type, +struct amdgpu_ring *guilty_ring, +struct amdgpu_fence *guilty_fence, + struct amdgpu_usermode_queue
*guilty_queue);
#endif /*__AMDGPU_IP_H__*/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0@@ -154,7 +154,8 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) /* Attempt an IP block soft reset, if supported. */if (
amdgpu_gpu_recovery&&amdgpu_ring_is_reset_type_supported(ring, AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET)) {drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-1- r = amdgpu_device_ip_soft_reset(ring, job-Quoted 1 line
hw_fence);drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1
-0+ r = amdgpu_device_ip_soft_reset(adev, ring->funcs-Quoted 1 line
type, ring,
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1
-0+ job->hw_fence,NULL);
if (!r) {atomic_inc(&ring->adev->gpu_reset_counter);drm_dev_wedged_event(adev_to_drm(adev), DRM_WEDGE_RECOVERY_NONE, info);drivers/gpu/drm/amd/include/amd_shared.h +0
-0@@ -29,6 +29,7 @@
#defineAMD_MAX_USEC_TIMEOUT1000000 /* 1000 ms */
structamdgpu_ip_block;
+structamdgpu_usermode_queue;
/*drivers/gpu/drm/amd/include/amd_shared.h +0
-0@@ -421,6 +422,7 @@ enum DC_DEBUG_MASK { };
enumamd_dpm_forced_level;
+enumamdgpu_ring_type;
/**
* structamd_ip_funcs- general hooks for managing amdgpu IP Blocksdrivers/gpu/drm/amd/include/amd_shared.h +1
-0@@ -441,6 +443,7 @@ enum amd_dpm_forced_level; * @complete: handles IP specific changes after resume * @wait_for_idle: poll for idle * @soft_reset: soft reset the IP block + * @soft_reset_engine: soft reset the engine of a ring type and itsuser queues
* @set_clockgating_state: enable/disable cg for the IP block
* @set_powergating_state: enable/disable pg for the IP block
* @get_clockgating_state: get current clockgating statusdrivers/gpu/drm/amd/include/amd_shared.h +3
-0@@ -469,6 +472,9 @@ struct amd_ip_funcs { void (*complete)(struct amdgpu_ip_block *ip_block); int (*wait_for_idle)(struct amdgpu_ip_block *ip_block); int (*soft_reset)(struct amdgpu_ip_block *ip_block); +int (*soft_reset_engine)(struct amdgpu_ip_block *ip_block, +enum amdgpu_ring_type ring_type, +struct amdgpu_usermode_queue *guilty_queue);int (*set_clockgating_state)(struct
amdgpu_ip_block*ip_block,
enumamd_clockgating_statestate);
int (*set_powergating_state)(structamdgpu_ip_block*ip_block,
PATCH v4 4/13 drm/amdgpu/gfx: add callbacks to save and restore a gfx HQD
In reply to Jesse ZhangA gfx engine reset clears the HQD registers of the gfx queues, including the only copy of the ring position of the queues MES didn't preempt. MES doesn't save them in the MQD either when the engine hangs.
Add struct amdgpu_gfx_saved_hqd for that state, and gfx callbacks for the gfx IP, which knows its registers and the layout of its MQD:
- save_hqd() saves the state of the gfx HQD of a doorbell;
- restore_hqd() writes it into the MQD after the reset, for MES to load it into the HQD when it maps the queue again.
v4: Rename to save_hqd()/restore_hqd() and struct amdgpu_gfx_saved_hqd
(Timur).
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +22 -0
@@ -345,6 +345,17 @@ struct amdgpu_gfx_shadow_info {u32 eop_alignment; }; +/* State of a gfx HQD that a gfx engine reset clears. */ +struct amdgpu_gfx_saved_hqd { +u32 doorbell_index; +u64 mqd_addr;/* the MQD loaded in the HQD */ +bool on_hqd; +u64 wptr; +u32 offset; +u32 csmd_rptr; +bool connected;/* the queue the pipe executes */ +}; +struct amdgpu_gfx_funcs {/* get the gpu clock counter */ uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
@@ -376,6 +387,17 @@ struct amdgpu_gfx_funcs {/* find the gfx HQD slot (me/pipe/queue) for a doorbell */ bool (*detect_hung_queue)(struct amdgpu_device *adev,u32 doorbell_index,u32 *me,u32 *pipe,u32 *queue); +/* save the state of the gfx HQD of a doorbell, if it has one */ +bool (*save_hqd)(struct amdgpu_device *adev,u32 doorbell_index, +struct amdgpu_gfx_saved_hqd *hqd); +/* +* write the HQD state saved by save_hqd() into a gfx MQD, for MES to +* load it into the HQD when it maps the queue again; +* true if the work up to hqd->wptr was dropped +*/ +bool (*restore_hqd)(struct amdgpu_device *adev,void *mqd, +u32 ring_size, +const struct amdgpu_gfx_saved_hqd *hqd); };struct sq_work {
Signature · 1 line
2.50.1
Re: [PATCH v4 04/13] drm/amdgpu/gfx: add callbacks to save and restore a gfx HQD
Quoted 12 lines · Jesse Zhang
A gfx engine reset clears the HQD registers of the gfx queues, including
the only copy of the ring position of the queues MES didn't preempt. MES doesn't save them in the MQD either when the engine hangs.Add struct
amdgpu_gfx_saved_hqdfor that state, and gfx callbacks for the gfx IP, which knows its registers and the layout of its MQD:
-save_hqd()saves the state of the gfx HQD of a doorbell;
-restore_hqd()writes it into the MQD after the reset, for MES to load
it into the HQD when it maps the queue again.
Quoted 5 lines
v4: Rename to save_hqd()/restore_hqd() and struct
amdgpu_gfx_saved_hqd
(Timur).Signed-off-by Jesse Zhang <[email protected]>
Quoted 50 lines
---
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 22 ++++++++++++++++++++++1 file changed, 22 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0
-0@@ -345,6 +345,17 @@ struct amdgpu_gfx_shadow_info { u32 eop_alignment; };drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +11
-0+/* State of a gfx HQD that a gfx engine reset clears. */ +struct amdgpu_gfx_saved_hqd { +u32 doorbell_index; +u64 mqd_addr;/* the MQD loaded in the HQD */ +bool on_hqd; +u64 wptr; +u32 offset; +u32 csmd_rptr; +bool connected;/* the queue the pipe executes */ +}; +struct
amdgpu_gfx_funcs{
/* get the gpu clock counter */
uint64_t(*get_gpu_clock_counter)(structamdgpu_device*adev);drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0
-0@@ -376,6 +387,17 @@ struct amdgpu_gfx_funcs { /* find the gfx HQD slot (me/pipe/queue) for a doorbell */bool (*detect_hung_queue)(struct
amdgpu_device*adev, u32doorbell_index,
u32 *me, u32 *pipe, u32 *queue);drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +1
-0+/* save the state of the gfx HQD of a doorbell, if it has one */
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +1
-0+ bool (*save_hqd)(struct amdgpu_device *adev, u32
doorbell_index,drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3
-0+ struct amdgpu_gfx_saved_hqd *hqd); +/* +* write the HQD state saved by save_hqd() into a gfx MQD, for MES to
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +6
-0+* load it into the HQD when it maps the queue again; +* true if the work up to hqd->wptr was dropped +*/ +bool (*restore_hqd)(struct amdgpu_device *adev,void *mqd, + u32 ring_size, + const struct amdgpu_gfx_saved_hqd *hqd);};
structsq_work{
PATCH v4 5/13 drm/amdgpu/gfx12: save and restore a gfx HQD
In reply to Jesse ZhangImplement the gfx callbacks to save and restore a gfx HQD for gfx12:
- save_hqd() saves the HQD offset, CSMD read pointer and write pointer of the gfx HQD of a doorbell, and whether the queue is the one connected to its pipe;
- restore_hqd() writes them into the MQD after a reset, for MES to map the queue again where it was. A queue switched out of the pipe resumes from the preemption status the PFP saved in its MQD, also in the middle of an IB. The queue the pipe was executing has its state in the PFP, which the reset cleared: it restarts after the work submitted so far instead, and that work is dropped.
v4: Rename to save_hqd()/restore_hqd() (Timur).
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 83 ++++++++++++++++++++++++++ 1 file changed, 83 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +83 -0
@@ -274,6 +274,11 @@ static void gfx_v12_0_set_imu_funcs(struct amdgpu_device *adev);static int gfx_v12_0_get_cu_info (struct amdgpu_device *adev,struct amdgpu_cu_info *cu_info);static uint64_t gfx_v12_0_get_gpu_clock_counter (struct amdgpu_device *adev); +static bool gfx_v12_0_save_hqd (struct amdgpu_device *adev,u32 doorbell_index, +struct amdgpu_gfx_saved_hqd *hqd); +static bool gfx_v12_0_restore_hqd (struct amdgpu_device *adev,void *m, +u32 ring_size, +const struct amdgpu_gfx_saved_hqd *hqd);static void gfx_v12_0_select_se_sh (struct amdgpu_device *adev,u32 se_num,u32 sh_num,u32 instance,int xcc_id);static u32 gfx_v12_0_get_wgp_active_bitmap_per_sh (struct amdgpu_device *adev);
@@ -962,6 +967,8 @@ static const struct amdgpu_gfx_funcs gfx_v12_0_gfx_funcs = { .update_perfmon_mgcg = &gfx_v12_0_update_perf_clk, .get_gfx_shadow_info = &gfx_v12_0_get_gfx_shadow_info, .get_hdp_flush_mask = &amdgpu_gfx_get_hdp_flush_mask, + .save_hqd = &gfx_v12_0_save_hqd, + .restore_hqd = &gfx_v12_0_restore_hqd, };static int gfx_v12_0_gpu_early_init (struct amdgpu_device *adev)
@@ -3853,6 +3860,82 @@ static int gfx_v12_0_wait_for_idle(struct amdgpu_ip_block *ip_block)return -ETIMEDOUT ; } +#define GFX12_HPD_QUEUE_STATE_CONNECTED_MIN 3 +#define GFX12_HPD_QUEUE_STATE_CONNECTED_MAX 15 + +static bool gfx_v12_0_save_hqd (struct amdgpu_device *adev,u32 doorbell_index, +struct amdgpu_gfx_saved_hqd *hqd) +{ +u32 me, pipe, queue, status, state; + +memset (hqd,0 ,sizeof (*hqd)); + hqd->doorbell_index = doorbell_index; +if (!gfx_v12_0_detect_hung_queue (adev, doorbell_index, &me, &pipe, &queue)) +return true; + +amdgpu_gfx_off_ctrl (adev, false); +mutex_lock (&adev->srbm_mutex); +soc24_grbm_select (adev, me, pipe, queue,0 ); + hqd->on_hqd =RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_ACTIVE) & +CP_GFX_HQD_ACTIVE__ACTIVE_MASK ; +if (!hqd->on_hqd) + goto out; + hqd->mqd_addr =RREG32_SOC15 (GC ,0 , regCP_GFX_MQD_BASE_ADDR) | + (u64 )RREG32_SOC15 (GC ,0 , regCP_GFX_MQD_BASE_ADDR_HI) <<32 ; + hqd->offset =RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_OFFSET); + hqd->csmd_rptr =RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_CSMD_RPTR); + hqd->wptr =RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_WPTR) | + (u64 )RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_WPTR_HI) <<32 ; + status =RREG32_SOC15 (GC ,0 , regCP_GFX_HPD_STATUS0); + state =REG_GET_FIELD (status,CP_GFX_HPD_STATUS0 ,QUEUE_STATE ); + hqd->connected = + state >=GFX12_HPD_QUEUE_STATE_CONNECTED_MIN && + state <=GFX12_HPD_QUEUE_STATE_CONNECTED_MAX && +REG_GET_FIELD (status,CP_GFX_HPD_STATUS0 ,MAPPED_QUEUE ) == queue; +out: +soc24_grbm_select (adev,0 ,0 ,0 ,0 ); +mutex_unlock (&adev->srbm_mutex); +amdgpu_gfx_off_ctrl (adev, true); + +return true; +} + +static bool gfx_v12_0_restore_hqd (struct amdgpu_device *adev,void *m, +u32 ring_size, +const struct amdgpu_gfx_saved_hqd *hqd) +{ +struct v12_gfx_mqd *mqd = m; +u32 wptr =lower_32_bits (hqd->wptr) & ((ring_size >>2 ) -1 ); +u32 *status; + +/* +* MQD dwords 32-41 (reserved_32..41) are the PFP preemption status, +* mcbp_status_pfp: the offset and chained IB size and address of IB1 +* (32-35) and IB2 (36-39), rb_preempt (40: preempted in the ring) and +* completion_status (41: 0 IB not started, 1 preempted inside an IB, +* 2 IB completed, 3 IB resumed). The PFP saves it when the queue is +* switched out of the pipe and resumes from it when the queue runs +* again, at the HQD offset. That survives the reset for a queue that +* was switched out. The queue the pipe executed has its state in the +* PFP, which the reset cleared: restart it at the write pointer with +* no IB to resume, and drop its work in flight. +*/ +if (hqd->connected) { + mqd->cp_gfx_hqd_offset = wptr; + mqd->cp_gfx_hqd_csmd_rptr = wptr; +for (status = &mqd->reserved_32; status <= &mqd->reserved_41; status++) + *status =0 ; + }else { + mqd->cp_gfx_hqd_offset = hqd->offset; + mqd->cp_gfx_hqd_csmd_rptr = hqd->csmd_rptr; + } + mqd->cp_gfx_hqd_wptr =lower_32_bits (hqd->wptr); + mqd->cp_gfx_hqd_wptr_hi =upper_32_bits (hqd->wptr); + mqd->cp_gfx_hqd_active =0 ; + +return hqd->connected; +} +static uint64_t gfx_v12_0_get_gpu_clock_counter (struct amdgpu_device *adev) {uint64_t clock =0 ;
Signature · 1 line
2.50.1
Re: [PATCH v4 05/13] drm/amdgpu/gfx12: save and restore a gfx HQD
Quoted 16 lines · Jesse Zhang
Implement the gfx callbacks to save and restore a gfx HQD for gfx12:
-save_hqd()saves the HQD offset, CSMD read pointer and write pointer
of the gfx HQD of a doorbell, and whether the queue is the one connected to its pipe;
-restore_hqd()writes them into the MQD after a reset, for MES to map
the queue again where it was. A queue switched out of the pipe resumes
from the preemption status the PFP saved in its MQD, also in the middle of an IB. The queue the pipe was executing has its state in the
PFP, which the reset cleared: it restarts after the work submitted so
far instead, and that work is dropped.
Quoted 3 lines
v4: Rename to save_hqd()/restore_hqd() (Timur).
Signed-off-by Jesse Zhang <[email protected]>
The code looks good, though I didn't test the series yet on GFX12 yet.
Quoted 146 lines
---
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 83
++++++++++++++++++++++++++1 file changed, 83 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +0
-0@@ -274,6 +274,11 @@ static void gfx_v12_0_set_imu_funcs(struct amdgpu_device *adev); static int gfx_v12_0_get_cu_info(struct amdgpu_device *adev, struct amdgpu_cu_info *cu_info);static
uint64_tgfx_v12_0_get_gpu_clock_counter(struct amdgpu_device *adev);
+static bool gfx_v12_0_save_hqd(structamdgpu_device*adev, u32doorbell_index,drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+ struct amdgpu_gfx_saved_hqd *hqd); +static bool gfx_v12_0_restore_hqd(struct amdgpu_device *adev, void*m,
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+ u32 ring_size, + const struct amdgpu_gfx_saved_hqd*hqd);
static void gfx_v12_0_select_se_sh(structamdgpu_device*adev, u32se_num,
u32sh_num, u32 instance, intxcc_id);
static u32gfx_v12_0_get_wgp_active_bitmap_per_sh(struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0@@ -962,6 +967,8 @@ static const struct amdgpu_gfx_funcs gfx_v12_0_gfx_funcs = { .update_perfmon_mgcg = &gfx_v12_0_update_perf_clk, .get_gfx_shadow_info = &gfx_v12_0_get_gfx_shadow_info, .get_hdp_flush_mask = &amdgpu_gfx_get_hdp_flush_mask, + .save_hqd = &gfx_v12_0_save_hqd, + .restore_hqd = &gfx_v12_0_restore_hqd, };
static intgfx_v12_0_gpu_early_init(struct amdgpu_device *adev)drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +0
-0@@ -3853,6 +3860,82 @@ static int gfx_v12_0_wait_for_idle(struct amdgpu_ip_block *ip_block) return -ETIMEDOUT; }drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4
-0+#define GFX12_HPD_QUEUE_STATE_CONNECTED_MIN 3 +#define GFX12_HPD_QUEUE_STATE_CONNECTED_MAX 15 + +static bool gfx_v12_0_save_hqd(struct amdgpu_device *adev, u32
doorbell_index,drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +7
-0+ struct amdgpu_gfx_saved_hqd *hqd) +{ + u32 me, pipe, queue, status, state; + + memset(hqd, 0, sizeof(*hqd)); + hqd->doorbell_index = doorbell_index; + if (!gfx_v12_0_detect_hung_queue(adev, doorbell_index, &me,&pipe, &queue))
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +10
-0+return true; + +amdgpu_gfx_off_ctrl (adev, false); +mutex_lock (&adev->srbm_mutex); +soc24_grbm_select (adev, me, pipe, queue,0 ); + hqd->on_hqd =RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_ACTIVE) & + CP_GFX_HQD_ACTIVE__ACTIVE_MASK; +if (!hqd->on_hqd) + goto out; + hqd->mqd_addr =RREG32_SOC15 (GC ,0 , regCP_GFX_MQD_BASE_ADDR)|
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0+ (u64)RREG32_SOC15(GC, 0,
regCP_GFX_MQD_BASE_ADDR_HI) << 32;drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+ hqd->offset =RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_OFFSET); + hqd->csmd_rptr = RREG32_SOC15(GC, 0,
regCP_GFX_HQD_CSMD_RPTR);drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+ hqd->wptr =RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_WPTR) | + (u64)RREG32_SOC15(GC, 0, regCP_GFX_HQD_WPTR_HI)<< 32;
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+ status =RREG32_SOC15 (GC ,0 , regCP_GFX_HPD_STATUS0); + state = REG_GET_FIELD(status, CP_GFX_HPD_STATUS0,
QUEUE_STATE);drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4
-0+ hqd->connected = + state >=GFX12_HPD_QUEUE_STATE_CONNECTED_MIN && + state <=GFX12_HPD_QUEUE_STATE_CONNECTED_MAX && + REG_GET_FIELD(status, CP_GFX_HPD_STATUS0,
MAPPED_QUEUE) == queue;drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +9
-0+out: +soc24_grbm_select (adev,0 ,0 ,0 ,0 ); +mutex_unlock (&adev->srbm_mutex); +amdgpu_gfx_off_ctrl (adev, true); + +return true; +} + +static bool gfx_v12_0_restore_hqd(struct amdgpu_device *adev, void*m,
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+ u32 ring_size, + const struct amdgpu_gfx_saved_hqd*hqd)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +3
-0+{ +struct v12_gfx_mqd *mqd = m; + u32 wptr = lower_32_bits(hqd->wptr) & ((ring_size >> 2) -1);
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4
-0+u32 *status; + +/* +* MQD dwords 32-41 (reserved_32..41) are the PFP preemption status,
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0+* mcbp_status_pfp: the offset and chained IB size and address of IB1
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0+* (32-35) and IB2 (36-39), rb_preempt (40: preempted in the ring) and
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0+* completion_status (41: 0 IB not started, 1 preempted inside an IB,
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0+* 2 IB completed, 3 IB resumed). The PFP saves it when the queue is
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0+* switched out of the pipe and resumes from it when the queue runs
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0+* again, at the HQD offset. That survives the reset for a queue that
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0+* was switched out. The queue the pipe executed has its state in the
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0+* PFP, which the reset cleared: restart it at the write pointer with
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +6
-0+* no IB to resume, and drop its work in flight. +*/ + if (hqd->connected) { + mqd->cp_gfx_hqd_offset = wptr; + mqd->cp_gfx_hqd_csmd_rptr = wptr; + for (status = &mqd->reserved_32; status <= &mqd-Quoted 1 line
reserved_41; status++)drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +12
-0+ *status =0 ; + }else { + mqd->cp_gfx_hqd_offset = hqd->offset; + mqd->cp_gfx_hqd_csmd_rptr = hqd->csmd_rptr; + } + mqd->cp_gfx_hqd_wptr =lower_32_bits (hqd->wptr); + mqd->cp_gfx_hqd_wptr_hi =upper_32_bits (hqd->wptr); + mqd->cp_gfx_hqd_active =0 ; + +return hqd->connected; +} +static
uint64_tgfx_v12_0_get_gpu_clock_counter(struct amdgpu_device *adev)
{
uint64_tclock = 0;
PATCH v4 6/13 drm/amdgpu/gfx11: save and restore a gfx HQD
In reply to Jesse ZhangImplement the gfx callbacks to save and restore a gfx HQD for gfx11:
- save_hqd() saves the HQD offset, CSMD read pointer and write pointer of the gfx HQD of a doorbell, and whether the queue is the one connected to its pipe;
- restore_hqd() writes them into the MQD after a reset, for MES to map the queue again where it was. A queue switched out of the pipe resumes from the preemption status the PFP saved in its MQD, also in the middle of an IB. The queue the pipe was executing has its state in the PFP, which the reset cleared: it restarts after the work submitted so far instead, and that work is dropped.
v4: Rename to save_hqd()/restore_hqd() (Timur).
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 83 ++++++++++++++++++++++++++ 1 file changed, 83 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +83 -0
@@ -365,6 +365,11 @@ static void gfx_v11_0_unset_safe_mode(struct amdgpu_device *adev, int xcc_id);static void gfx_v11_0_update_spm_vmid (struct amdgpu_device *adev,int xcc_id,unsigned int vmid);static void gfx_v11_0_userq_priv_fault_work (struct work_struct *work); +static bool gfx_v11_0_save_hqd (struct amdgpu_device *adev,u32 doorbell_index, +struct amdgpu_gfx_saved_hqd *hqd); +static bool gfx_v11_0_restore_hqd (struct amdgpu_device *adev,void *m, +u32 ring_size, +const struct amdgpu_gfx_saved_hqd *hqd);static void gfx_v11_0_update_perf_clk (struct amdgpu_device *adev,bool enable);
@@ -1150,6 +1155,8 @@ static const struct amdgpu_gfx_funcs gfx_v11_0_gfx_funcs = { .get_gfx_shadow_info = &gfx_v11_0_get_gfx_shadow_info, .get_hdp_flush_mask = &amdgpu_gfx_get_hdp_flush_mask, .detect_hung_queue = &gfx_v11_0_detect_hung_queue, + .save_hqd = &gfx_v11_0_save_hqd, + .restore_hqd = &gfx_v11_0_restore_hqd, };static int gfx_v11_0_gpu_early_init (struct amdgpu_device *adev)
@@ -6770,6 +6777,82 @@ static void gfx_v11_0_emit_mem_sync(struct amdgpu_ring *ring)amdgpu_ring_write (ring, gcr_cntl);/* GCR_CNTL */ } +#define GFX11_HPD_QUEUE_STATE_CONNECTED_MIN 3 +#define GFX11_HPD_QUEUE_STATE_CONNECTED_MAX 15 + +static bool gfx_v11_0_save_hqd (struct amdgpu_device *adev,u32 doorbell_index, +struct amdgpu_gfx_saved_hqd *hqd) +{ +u32 me, pipe, queue, status, state; + +memset (hqd,0 ,sizeof (*hqd)); + hqd->doorbell_index = doorbell_index; +if (!gfx_v11_0_detect_hung_queue (adev, doorbell_index, &me, &pipe, &queue)) +return true; + +amdgpu_gfx_off_ctrl (adev, false); +mutex_lock (&adev->srbm_mutex); +soc21_grbm_select (adev, me, pipe, queue,0 ); + hqd->on_hqd =RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_ACTIVE) & +CP_GFX_HQD_ACTIVE__ACTIVE_MASK ; +if (!hqd->on_hqd) + goto out; + hqd->mqd_addr =RREG32_SOC15 (GC ,0 , regCP_GFX_MQD_BASE_ADDR) | + (u64 )RREG32_SOC15 (GC ,0 , regCP_GFX_MQD_BASE_ADDR_HI) <<32 ; + hqd->offset =RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_OFFSET); + hqd->csmd_rptr =RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_CSMD_RPTR); + hqd->wptr =RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_WPTR) | + (u64 )RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_WPTR_HI) <<32 ; + status =RREG32_SOC15 (GC ,0 , regCP_GFX_HPD_STATUS0); + state =REG_GET_FIELD (status,CP_GFX_HPD_STATUS0 ,QUEUE_STATE ); + hqd->connected = + state >=GFX11_HPD_QUEUE_STATE_CONNECTED_MIN && + state <=GFX11_HPD_QUEUE_STATE_CONNECTED_MAX && +REG_GET_FIELD (status,CP_GFX_HPD_STATUS0 ,MAPPED_QUEUE ) == queue; +out: +soc21_grbm_select (adev,0 ,0 ,0 ,0 ); +mutex_unlock (&adev->srbm_mutex); +amdgpu_gfx_off_ctrl (adev, true); + +return true; +} + +static bool gfx_v11_0_restore_hqd (struct amdgpu_device *adev,void *m, +u32 ring_size, +const struct amdgpu_gfx_saved_hqd *hqd) +{ +struct v11_gfx_mqd *mqd = m; +u32 wptr =lower_32_bits (hqd->wptr) & ((ring_size >>2 ) -1 ); +u32 *status; + +/* +* MQD dwords 32-41 (reserved_32..41) are the PFP preemption status, +* mcbp_status_pfp: the offset and chained IB size and address of IB1 +* (32-35) and IB2 (36-39), rb_preempt (40: preempted in the ring) and +* completion_status (41: 0 IB not started, 1 preempted inside an IB, +* 2 IB completed, 3 IB resumed). The PFP saves it when the queue is +* switched out of the pipe and resumes from it when the queue runs +* again, at the HQD offset. That survives the reset for a queue that +* was switched out. The queue the pipe executed has its state in the +* PFP, which the reset cleared: restart it at the write pointer with +* no IB to resume, and drop its work in flight. +*/ +if (hqd->connected) { + mqd->cp_gfx_hqd_offset = wptr; + mqd->cp_gfx_hqd_csmd_rptr = wptr; +for (status = &mqd->reserved_32; status <= &mqd->reserved_41; status++) + *status =0 ; + }else { + mqd->cp_gfx_hqd_offset = hqd->offset; + mqd->cp_gfx_hqd_csmd_rptr = hqd->csmd_rptr; + } + mqd->cp_gfx_hqd_wptr =lower_32_bits (hqd->wptr); + mqd->cp_gfx_hqd_wptr_hi =upper_32_bits (hqd->wptr); + mqd->cp_gfx_hqd_active =0 ; + +return hqd->connected; +} +static int gfx_v11_0_reset_kgq (struct amdgpu_ring *ring,unsigned int vmid,struct amdgpu_fence *timedout_fence)
Signature · 1 line
2.50.1
Re: [PATCH v4 06/13] drm/amdgpu/gfx11: save and restore a gfx HQD
Quoted 16 lines · Jesse Zhang
Implement the gfx callbacks to save and restore a gfx HQD for gfx11:
-save_hqd()saves the HQD offset, CSMD read pointer and write pointer
of the gfx HQD of a doorbell, and whether the queue is the one connected to its pipe;
-restore_hqd()writes them into the MQD after a reset, for MES to map
the queue again where it was. A queue switched out of the pipe resumes
from the preemption status the PFP saved in its MQD, also in the middle of an IB. The queue the pipe was executing has its state in the
PFP, which the reset cleared: it restarts after the work submitted so
far instead, and that work is dropped.
Quoted 3 lines
v4: Rename to save_hqd()/restore_hqd() (Timur).
Signed-off-by Jesse Zhang <[email protected]>
Quoted 143 lines
---
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 83
++++++++++++++++++++++++++1 file changed, 83 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -365,6 +365,11 @@ static void gfx_v11_0_unset_safe_mode(struct amdgpu_device *adev, int xcc_id); static void gfx_v11_0_update_spm_vmid(struct amdgpu_device *adev,int xcc_id, unsigned int vmid);static void
gfx_v11_0_userq_priv_fault_work(struct work_struct *work);
+static bool gfx_v11_0_save_hqd(structamdgpu_device*adev, u32doorbell_index,drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+ struct amdgpu_gfx_saved_hqd *hqd); +static bool gfx_v11_0_restore_hqd(struct amdgpu_device *adev, void*m,
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+ u32 ring_size, + const struct amdgpu_gfx_saved_hqd*hqd);
static voidgfx_v11_0_update_perf_clk(struct amdgpu_device *adev, bool enable);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0@@ -1150,6 +1155,8 @@ static const struct amdgpu_gfx_funcs gfx_v11_0_gfx_funcs = { .get_gfx_shadow_info = &gfx_v11_0_get_gfx_shadow_info, .get_hdp_flush_mask = &amdgpu_gfx_get_hdp_flush_mask, .detect_hung_queue = &gfx_v11_0_detect_hung_queue, + .save_hqd = &gfx_v11_0_save_hqd, + .restore_hqd = &gfx_v11_0_restore_hqd, };
static intgfx_v11_0_gpu_early_init(struct amdgpu_device *adev)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6770,6 +6777,82 @@ static void gfx_v11_0_emit_mem_sync(struct amdgpu_ring *ring)
amdgpu_ring_write(ring, gcr_cntl); /*GCR_CNTL*/ }drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0+#define GFX11_HPD_QUEUE_STATE_CONNECTED_MIN 3 +#define GFX11_HPD_QUEUE_STATE_CONNECTED_MAX 15 + +static bool gfx_v11_0_save_hqd(struct amdgpu_device *adev, u32
doorbell_index,drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +7
-0+ struct amdgpu_gfx_saved_hqd *hqd) +{ + u32 me, pipe, queue, status, state; + + memset(hqd, 0, sizeof(*hqd)); + hqd->doorbell_index = doorbell_index; + if (!gfx_v11_0_detect_hung_queue(adev, doorbell_index, &me,&pipe, &queue))
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+return true; + +amdgpu_gfx_off_ctrl (adev, false); +mutex_lock (&adev->srbm_mutex); +soc21_grbm_select (adev, me, pipe, queue,0 ); + hqd->on_hqd =RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_ACTIVE) & + CP_GFX_HQD_ACTIVE__ACTIVE_MASK; +if (!hqd->on_hqd) + goto out; + hqd->mqd_addr =RREG32_SOC15 (GC ,0 , regCP_GFX_MQD_BASE_ADDR)|
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+ (u64)RREG32_SOC15(GC, 0,
regCP_GFX_MQD_BASE_ADDR_HI) << 32;drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+ hqd->offset =RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_OFFSET); + hqd->csmd_rptr = RREG32_SOC15(GC, 0,
regCP_GFX_HQD_CSMD_RPTR);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+ hqd->wptr =RREG32_SOC15 (GC ,0 , regCP_GFX_HQD_WPTR) | + (u64)RREG32_SOC15(GC, 0, regCP_GFX_HQD_WPTR_HI)<< 32;
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+ status =RREG32_SOC15 (GC ,0 , regCP_GFX_HPD_STATUS0); + state = REG_GET_FIELD(status, CP_GFX_HPD_STATUS0,
QUEUE_STATE);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0+ hqd->connected = + state >=GFX11_HPD_QUEUE_STATE_CONNECTED_MIN && + state <=GFX11_HPD_QUEUE_STATE_CONNECTED_MAX && + REG_GET_FIELD(status, CP_GFX_HPD_STATUS0,
MAPPED_QUEUE) == queue;drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +9
-0+out: +soc21_grbm_select (adev,0 ,0 ,0 ,0 ); +mutex_unlock (&adev->srbm_mutex); +amdgpu_gfx_off_ctrl (adev, true); + +return true; +} + +static bool gfx_v11_0_restore_hqd(struct amdgpu_device *adev, void*m,
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+ u32 ring_size, + const struct amdgpu_gfx_saved_hqd*hqd)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3
-0+{ +struct v11_gfx_mqd *mqd = m; + u32 wptr = lower_32_bits(hqd->wptr) & ((ring_size >> 2) -1);
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0+u32 *status; + +/* +* MQD dwords 32-41 (reserved_32..41) are the PFP preemption status,
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+* mcbp_status_pfp: the offset and chained IB size and address of IB1
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+* (32-35) and IB2 (36-39), rb_preempt (40: preempted in the ring) and
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+* completion_status (41: 0 IB not started, 1 preempted inside an IB,
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+* 2 IB completed, 3 IB resumed). The PFP saves it when the queue is
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+* switched out of the pipe and resumes from it when the queue runs
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+* again, at the HQD offset. That survives the reset for a queue that
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+* was switched out. The queue the pipe executed has its state in the
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+* PFP, which the reset cleared: restart it at the write pointer with
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6
-0+* no IB to resume, and drop its work in flight. +*/ + if (hqd->connected) { + mqd->cp_gfx_hqd_offset = wptr; + mqd->cp_gfx_hqd_csmd_rptr = wptr; + for (status = &mqd->reserved_32; status <= &mqd-Quoted 1 line
reserved_41; status++)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +12
-0+ *status =0 ; + }else { + mqd->cp_gfx_hqd_offset = hqd->offset; + mqd->cp_gfx_hqd_csmd_rptr = hqd->csmd_rptr; + } + mqd->cp_gfx_hqd_wptr =lower_32_bits (hqd->wptr); + mqd->cp_gfx_hqd_wptr_hi =upper_32_bits (hqd->wptr); + mqd->cp_gfx_hqd_active =0 ; + +return hqd->connected; +} +static int gfx_v11_0_reset_kgq(struct
amdgpu_ring*ring, unsigned int vmid,
structamdgpu_fence*timedout_fence)
PATCH v4 7/13 drm/amdgpu/userq: add a helper to signal the fences of a queue up to a point
In reply to Jesse ZhangThe fence value of a user queue is the write pointer of the queue when the work was submitted. amdgpu_userq_fence_driver_force_completion() signals all the fences of a queue, as after a reset that dropped all its work.
Add amdgpu_userq_fence_driver_force_completion_with_seqno(), which only signals the fences of the work up to a write pointer, with an error, for a reset that drops only part of the work of a queue: the work submitted after that write pointer still runs.
--- .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 31 +++++++++++++++++++ .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.h | 2 ++ 2 files changed, 33 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +31 -0
@@ -460,6 +460,37 @@ amdgpu_userq_fence_driver_force_completion(struct amdgpu_usermode_queue *userq) } } +/* +* Signal the fences of @userq with a seqno up to @seqno with -ECANCELED, eg. +* when a reset dropped the work that would have signaled them. +*/ +void +amdgpu_userq_fence_driver_force_completion_with_seqno (struct amdgpu_usermode_queue *userq, +u64 seqno) +{ +struct amdgpu_userq_fence_driver *fence_drv = userq->fence_drv; +struct amdgpu_userq_fence *fence; +unsigned long flags; + +if (!fence_drv) +return ; + +spin_lock_irqsave (&fence_drv->fence_list_lock, flags); +list_for_each_entry (fence, &fence_drv->fences, link) { +if (fence->base.seqno > seqno) +break ; +spin_lock (dma_fence_spinlock (&fence->base)); +if (!dma_fence_is_signaled_locked (&fence->base)) +dma_fence_set_error (&fence->base, -ECANCELED ); +spin_unlock (dma_fence_spinlock (&fence->base)); + } +if (amdgpu_userq_fence_read (fence_drv) < seqno) +amdgpu_userq_fence_write (fence_drv, seqno); +spin_unlock_irqrestore (&fence_drv->fence_list_lock, flags); + +amdgpu_userq_fence_driver_process (fence_drv); +} +int amdgpu_userq_signal_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) {
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.h +2 -0
@@ -65,6 +65,8 @@ int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,void amdgpu_userq_fence_driver_free (struct amdgpu_usermode_queue *userq);int amdgpu_userq_fence_driver_process (struct amdgpu_userq_fence_driver *fence_drv);void amdgpu_userq_fence_driver_force_completion (struct amdgpu_usermode_queue *userq); +void amdgpu_userq_fence_driver_force_completion_with_seqno (struct amdgpu_usermode_queue *userq, +u64 seqno);void amdgpu_userq_fence_driver_destroy (struct kref *ref);int amdgpu_userq_signal_ioctl (struct drm_device *dev,void *data,struct drm_file *filp);
Signature · 1 line
2.50.1
Re: [PATCH v4 07/13] drm/amdgpu/userq: add a helper to signal the fences of a queue up to a point
Quoted 15 lines · Jesse Zhang
The fence value of a user queue is the write pointer of the queue when
the work was submitted.amdgpu_userq_fence_driver_force_completion()signals all the fences of a queue, as after a reset that dropped all its
work.Add
amdgpu_userq_fence_driver_force_completion_with_seqno(), which only
signals the fences of the work up to a write pointer, with an error, for
a reset that drops only part of the work of a queue: the work submitted
after that write pointer still runs.
Quoted 1 line
Signed-off-by Jesse Zhang <[email protected]>
Quoted 75 lines
---
.../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 31
+++++++++++++++++++
.../gpu/drm/amd/amdgpu/amdgpu_userq_fence.h | 2 ++2 files changed, 33 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +0
-0@@ -460,6 +460,37 @@
amdgpu_userq_fence_driver_force_completion(struct amdgpu_usermode_queue *userq)
}
}
+/*
+ * Signal the fences of @userq with a seqno up to @seqno with - ECANCELED, eg.
+ * when a reset dropped the work that would have signaled them.
+ */drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +2
-0+void +amdgpu_userq_fence_driver_force_completion_with_seqno(struct
amdgpu_usermode_queue*userq,drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +3
-0+ u64 seqno) +{ + struct amdgpu_userq_fence_driver *fence_drv = userq-Quoted 1 line
fence_drv;drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +13
-0+struct amdgpu_userq_fence *fence; +unsigned long flags; + +if (!fence_drv) +return ; + +spin_lock_irqsave (&fence_drv->fence_list_lock, flags); +list_for_each_entry (fence, &fence_drv->fences, link) { +if (fence->base.seqno > seqno) +break ; +spin_lock (dma_fence_spinlock (&fence->base)); +if (!dma_fence_is_signaled_locked (&fence->base)) + dma_fence_set_error(&fence->base, -ECANCELED);
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +9
-0+spin_unlock (dma_fence_spinlock (&fence->base)); + } +if (amdgpu_userq_fence_read (fence_drv) < seqno) +amdgpu_userq_fence_write (fence_drv, seqno); +spin_unlock_irqrestore (&fence_drv->fence_list_lock, flags); + +amdgpu_userq_fence_driver_process (fence_drv); +} +int
amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
{drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.h +0
-0@@ -65,6 +65,8 @@ int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,void
amdgpu_userq_fence_driver_free(struct amdgpu_usermode_queue *userq);
intamdgpu_userq_fence_driver_process(struct amdgpu_userq_fence_driver *fence_drv);
voidamdgpu_userq_fence_driver_force_completion(struct amdgpu_usermode_queue *userq);
+void amdgpu_userq_fence_driver_force_completion_with_seqno(structamdgpu_usermode_queue*userq,drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.h +1
-0+ u64seqno);
voidamdgpu_userq_fence_driver_destroy(struct kref *ref); intamdgpu_userq_signal_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
PATCH v4 8/13 drm/amdgpu/userq: add helpers to keep the user queues of one engine across a reset
In reply to Jesse ZhangAn engine reset, eg. of the gfx engine, only resets the queues of one engine of the GFX IP; the queues of the other engines aren't reset. amdgpu_userq_pre_reset() and amdgpu_userq_post_reset() handle all the user queues for a full reset. Add separate helpers for the queues of one engine, which keep them in the state they had:
- amdgpu_userq_save_hqds(), called after the MES suspend, saves the HQD of the mapped queues still on a HQD: the reset clears their HQD, and MES couldn't preempt them into their MQD. The queues MES preempted have their state in their MQD already.
- amdgpu_userq_restore_hqds(), called after the reset but before MES resumes, unmaps those queues, writes the saved HQD into their MQD and maps them again: MES doesn't map a queue whose HQD the reset cleared again on its own. The queues keep their state and their work, except the one the pipe executed: its work in flight depends on pipe state the reset cleared, it is dropped and its fences signaled. The queue that hung, if any, is unmapped and hung.
- amdgpu_userq_clear_hqds() drops the saved HQDs for the full reset that follows a failed engine reset.
The helpers walk the queues and unmap and map them as amdgpu_userq_pre_reset() and amdgpu_userq_post_reset() do. The saved HQDs are kept in the gfx IP, in saved_gfx_hqds[], and matched to a queue by its doorbell and MQD address.
v2: Drop the user queue reset lock and the walk over the queues of one
type (Christian).
v4: Rename the helpers and the saved HQD array (Timur).
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 107 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 4 + 3 files changed, 114 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -0
@@ -515,6 +515,9 @@ struct amdgpu_gfx {/* reset mask */ uint32_t gfx_supported_reset; +/* HQDs of the gfx user queues, saved by an engine reset */ +struct amdgpu_gfx_saved_hqd saved_gfx_hqds[AMDGPU_MAX_GFX_QUEUES ]; +u32 num_saved_gfx_hqds;uint32_t compute_supported_reset;/* gfx off */
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +107 -0
110 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +4 -0
@@ -181,6 +181,10 @@ int amdgpu_userq_start_sched_for_enforce_isolation(struct amdgpu_device *adev,void amdgpu_userq_reset_work (struct work_struct *work);void amdgpu_userq_pre_reset (struct amdgpu_device *adev);int amdgpu_userq_post_reset (struct amdgpu_device *adev,bool vram_lost); +void amdgpu_userq_save_hqds (struct amdgpu_device *adev,u32 queue_type); +void amdgpu_userq_restore_hqds (struct amdgpu_device *adev,u32 queue_type, +struct amdgpu_usermode_queue *guilty); +void amdgpu_userq_clear_hqds (struct amdgpu_device *adev,u32 queue_type);void amdgpu_userq_start_hang_detect_work (struct amdgpu_usermode_queue *queue);void amdgpu_userq_process_fence_irq (struct amdgpu_device *adev,u32 doorbell);
Signature · 1 line
2.50.1
Re: [PATCH v4 08/13] drm/amdgpu/userq: add helpers to keep the user queues of one engine across a reset
Quoted 33 lines · Jesse Zhang
An engine reset, eg. of the gfx engine, only resets the queues of one engine of the GFX IP; the queues of the other engines aren't reset.
amdgpu_userq_pre_reset()andamdgpu_userq_post_reset()handle all the user queues for a full reset. Add separate helpers for the queues of one
engine, which keep them in the state they had:-
amdgpu_userq_save_hqds(), called after the MES suspend, saves the HQD
of the mapped queues still on a HQD: the reset clears their HQD, and
MES couldn't preempt them into their MQD. The queues MES preempted have their state in their MQD already.
-amdgpu_userq_restore_hqds(), called after the reset but before MES resumes, unmaps those queues, writes the saved HQD into their MQD and
maps them again: MES doesn't map a queue whose HQD the reset cleared
again on its own. The queues keep their state and their work, except
the one the pipe executed: its work in flight depends on pipe state the reset cleared, it is dropped and its fences signaled. The queue that hung, if any, is unmapped and hung.
-amdgpu_userq_clear_hqds()drops the saved HQDs for the full reset that
follows a failed engine reset.The helpers walk the queues and unmap and map them as
amdgpu_userq_pre_reset()andamdgpu_userq_post_reset()do. The saved HQDs are kept in the gfx IP, in saved_gfx_hqds[], and matched to a queue
by its doorbell and MQD address.
Quoted 6 lines
v2: Drop the user queue reset lock and the walk over the queues of one
type (Christian).
v4: Rename the helpers and the saved HQD array (Timur).Signed-off-by Jesse Zhang <[email protected]>
Quoted 189 lines
---
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 3 +drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c| 107
++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 4 +3 files changed, 114 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +0
-0@@ -515,6 +515,9 @@ struct amdgpu_gfx {
/* reset mask */
uint32_tgfx_supported_reset;drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +2
-0+/* HQDs of the gfx user queues, saved by an engine reset */ + struct
amdgpu_gfx_saved_hqdsaved_gfx_hqds[AMDGPU_MAX_GFX_QUEUES];drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +1
-0+u32 num_saved_gfx_hqds;uint32_t
compute_supported_reset;
/* gfx off */drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0@@ -1594,3 +1594,110 @@ int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost)
return ret;
}drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +3
-0+ +/** +* amdgpu_userq_save_hqds - save the HQDs of the user queues before an engine reset
+ * @adev: amdgpu device
+ * @queue_type: AMDGPU_HW_IP_* type of the queues on the reset engine
+ */
+voidamdgpu_userq_save_hqds(struct amdgpu_device *adev, u32 queue_type)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +11
-0+{ +struct amdgpu_gfx_saved_hqd hqd; +struct amdgpu_usermode_queue *queue; +unsigned long queue_id; + + adev->gfx.num_saved_gfx_hqds =0 ; +if (!adev->gfx.funcs->save_hqd) +return ; + +xa_for_each (&adev->userq_doorbell_xa, queue_id, queue) { + if (adev->gfx.num_saved_gfx_hqds >=
AMDGPU_MAX_GFX_QUEUES)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +5
-0+break ; +if (queue->queue_type != queue_type || + queue->state != AMDGPU_USERQ_STATE_MAPPED) +continue ; + if (adev->gfx.funcs->save_hqd(adev, queue-Quoted 1 line
doorbell_index, &hqd) &&drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-0+ hqd.on_hqd) + adev->gfx.saved_gfx_hqds[adev-Quoted 1 line
gfx.num_saved_gfx_hqds++] = hqd;
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +13
-0+ } +} + +static struct amdgpu_gfx_saved_hqd * +amdgpu_userq_find_saved_hqd (struct amdgpu_device *adev, + struct amdgpu_usermode_queue *queue) +{ +struct amdgpu_gfx_saved_hqd *hqd; +u32 i; + +for (i =0 ; i < adev->gfx.num_saved_gfx_hqds; i++) { + hqd = &adev->gfx.saved_gfx_hqds[i]; +/* Check the MQD too: a new queue may reuse the doorbell. */
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +9
-0+if (hqd->doorbell_index == queue->doorbell_index && + hqd->mqd_addr == queue->mqd.gpu_addr) +return hqd; + } +return NULL ; +} + +/** +* amdgpu_userq_restore_hqds - restore the user queues after an engine reset
+ * @adev: amdgpu device
+ * @queue_type: AMDGPU_HW_IP_* type of the queues on the reset engine
+ * @guilty: the queue that hung, or NULL
+ *
+ * MES doesn't map a queue whose HQD the reset cleared again on its
own: unmap
+ * it from MES, restore its MQD, and map it again.
+ */
+void amdgpu_userq_restore_hqds(structamdgpu_device*adev, u32queue_type,drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +3
-0+ struct amdgpu_usermode_queue *guilty) +{ + const struct amdgpu_userq_funcs *userq_funcs = adev-Quoted 1 line
userq_funcs[queue_type];
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +13
-0+struct amdgpu_usermode_queue *queue; +struct amdgpu_gfx_saved_hqd *hqd; +unsigned long queue_id; +int r; + +xa_for_each (&adev->userq_doorbell_xa, queue_id, queue) { +if (queue->queue_type != queue_type || + queue->state != AMDGPU_USERQ_STATE_MAPPED) +continue ; + +if (queue == guilty) { + userq_funcs->unmap (queue); + amdgpu_userq_fence_driver_force_completion(queue);
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-0+ trace_amdgpu_userq_state_changed(queue,
AMDGPU_USERQ_STATE_HUNG);drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10
-0+ queue->state =AMDGPU_USERQ_STATE_HUNG ; +continue ; + } + + hqd =amdgpu_userq_find_saved_hqd (adev, queue); +if (!hqd) +continue ; + + userq_funcs->unmap (queue); + if (adev->gfx.funcs->restore_hqd(adev, queue-Quoted 1 line
mqd.cpu_ptr,
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-0+ queue->userq_prop-Quoted 1 line
queue_size,drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-0+ hqd)) + amdgpu_userq_fence_driver_force_completion_with_seqno(queue,
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-0+hqd->wptr);drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +3
-0+ r = userq_funcs->map (queue); +if (r) { + dev_err(adev->dev, "Failed to remap userqueue %llu: %d\n",
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-0+ queue->doorbell_index, r); + amdgpu_userq_fence_driver_force_completion(queue);
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-0+ trace_amdgpu_userq_state_changed(queue,
AMDGPU_USERQ_STATE_HUNG);drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +8
-0+ queue->state =AMDGPU_USERQ_STATE_HUNG ; + } + } + adev->gfx.num_saved_gfx_hqds =0 ; +} + +/** +* amdgpu_userq_clear_hqds - drop the saved HQDs after a failed engine reset
+ * @adev: amdgpu device
+ * @queue_type: AMDGPU_HW_IP_* type of the queues on the reset engine
+ */
+voidamdgpu_userq_clear_hqds(struct amdgpu_device *adev, u32 queue_type)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +3
-0+{ + adev->gfx.num_saved_gfx_hqds =0 ; +}drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +0
-0@@ -181,6 +181,10 @@ intamdgpu_userq_start_sched_for_enforce_isolation(struct
amdgpu_device*adev,
voidamdgpu_userq_reset_work(struct work_struct *work); voidamdgpu_userq_pre_reset(struct amdgpu_device *adev); intamdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost);
+voidamdgpu_userq_save_hqds(struct amdgpu_device *adev, u32 queue_type);
+void amdgpu_userq_restore_hqds(structamdgpu_device*adev, u32queue_type,drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1
-0+ struct amdgpu_usermode_queue*guilty);
+voidamdgpu_userq_clear_hqds(struct amdgpu_device *adev, u32 queue_type);
voidamdgpu_userq_start_hang_detect_work(struct amdgpu_usermode_queue *queue);
voidamdgpu_userq_process_fence_irq(struct amdgpu_device *adev, u32 doorbell);
PATCH v4 9/13 drm/amdgpu/gfx12: add a gfx engine soft reset
In reply to Jesse ZhangSome hangs leave the gfx streaming engine of the CP front-end stuck, eg. waiting for packet data that never arrives. Neither a queue nor a pipe reset can stop it, so they end in a full GPU reset.
Implement soft_reset_engine() for the graphics engine: halt PFP/ME, pulse GRBM_SOFT_RESET.SOFT_RESET_CPF/CPG with CP_SOFT_RESET_CNTL.GFX_ONLY_SOFT_RESET and GFX_HQD_REG_RESET, restart PFP/ME and map the kernel gfx queue again.
MEC, MES and the compute queues keep running. The MES lock is held across the pulse, as MES fetches its queues through CPF, and the CP DMA is drained around it, as a request in flight leaves the ME busy.
MES is suspended meanwhile, and the gfx user queues the reset clears are saved and restored around it. If the CP doesn't go idle, the reset fails and a full reset follows.
v4: Implement soft_reset_engine() directly instead of a reset_engine gfx
callback (Timur).
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 129 +++++++++++++++++++++++++ 1 file changed, 129 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +129 -0
@@ -3860,6 +3860,134 @@ static int gfx_v12_0_wait_for_idle(struct amdgpu_ip_block *ip_block)return -ETIMEDOUT ; } +/* The CP DMA and the interfaces its memory requests go through */ +#define GFX12_CP_STAT_MEM_BUSY (CP_STAT__DMA_BUSY_MASK | \ + CP_STAT__TCIU_BUSY_MASK | \ + CP_STAT__RCIU_BUSY_MASK | \ + CP_STAT__UTCL2IU_BUSY_MASK) + +/* Reset CPF/CPG, PFP/ME and the gfx HQDs, then boot PFP/ME again. */ +static int gfx_v12_0_soft_reset_gfx_cp (struct amdgpu_device *adev) +{ +u32 tmp, cntl, me_cntl, ib_control; +int i; + +amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); +/* MES fetches its queues through CPF: keep it out of the reset. */ +amdgpu_mes_lock (&adev->mes); + + me_cntl =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + ib_control =RREG32_SOC15 (GC ,0 , regCP_PFP_IB_CONTROL);/* cleared by the reset */ + + tmp =REG_SET_FIELD (me_cntl,CP_ME_CNTL ,ME_HALT ,1 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,1 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +udelay (50 ); + +/* A CP DMA in flight during the reset leaves the ME busy after it. */ +for (i =0 ; i < adev->usec_timeout; i++) { +if (!(RREG32_SOC15 (GC ,0 , regCP_STAT) &GFX12_CP_STAT_MEM_BUSY )) +break ; +udelay (1 ); + } + +/* GFX_ONLY keeps compute and MES out; CPF alone leaves the stream stuck. */ + cntl =RREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL); + tmp =REG_SET_FIELD (cntl,CP_SOFT_RESET_CNTL ,GFX_ONLY_SOFT_RESET ,1 ); + tmp =REG_SET_FIELD (tmp,CP_SOFT_RESET_CNTL ,GFX_HQD_REG_RESET ,1 ); +WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, tmp); + + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPF ,1 ); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPG ,1 ); +WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); +udelay (50 ); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPF ,0 ); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPG ,0 ); +WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + +WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, cntl); + +/* The halted PFP stays busy: only wait for the memory requests. */ +for (i =0 ; i < adev->usec_timeout; i++) { +if (!(RREG32_SOC15 (GC ,0 , regCP_STAT) &GFX12_CP_STAT_MEM_BUSY )) +break ; +udelay (1 ); + } +amdgpu_mes_unlock (&adev->mes); + +gfx_v12_0_set_pfp_ucode_start_addr (adev); +gfx_v12_0_set_me_ucode_start_addr (adev); + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,CE_HALT , +REG_GET_FIELD (me_cntl,CP_ME_CNTL ,CE_HALT )); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +WREG32_SOC15 (GC ,0 , regCP_PFP_IB_CONTROL, ib_control); +amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); + + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,ME_HALT ,0 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,0 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +for (i =0 ; i < adev->usec_timeout; i++) { +if (!RREG32_SOC15 (GC ,0 , regCP_STAT)) +return 0 ; +udelay (1 ); + } +return -ETIMEDOUT ; +} + +static int gfx_v12_0_soft_reset_engine (struct amdgpu_ip_block *ip_block, +enum amdgpu_ring_type ring_type, +struct amdgpu_usermode_queue *guilty_queue) +{ +struct amdgpu_device *adev = ip_block->adev; +int i, r; + +if (ring_type !=AMDGPU_RING_TYPE_GFX ) +return -EOPNOTSUPP ; + +mutex_lock (&adev->gfx.mec.reset_mutex); +amdgpu_gfx_off_ctrl (adev, false); + +/* A hung gfx stream can keep MES from suspending: reset anyway. */ +amdgpu_mes_suspend (adev,0 ); +amdgpu_userq_save_hqds (adev,AMDGPU_HW_IP_GFX ); + + r =gfx_v12_0_soft_reset_gfx_cp (adev); +if (r) { +dev_err (adev->dev,"gfx CP still busy after reset, CP_STAT 0x%08x\n" , +RREG32_SOC15 (GC ,0 , regCP_STAT)); + goto fail; + } + +/* The reset cleared the HQD of the kernel gfx queue: map it again. */ + r =amdgpu_gfx_disable_kgq (adev,0 ); +if (r) + goto fail; +for (i =0 ; i < adev->gfx.num_gfx_rings; i++) +amdgpu_gfx_mqd_reset_restore (&adev->gfx.gfx_ring[i]); + r =amdgpu_gfx_enable_kgq (adev,0 ); +if (!r) + r =gfx_v12_0_cp_gfx_start (adev); +if (r) + goto fail; + +amdgpu_userq_restore_hqds (adev,AMDGPU_HW_IP_GFX , guilty_queue); + r =amdgpu_mes_resume (adev,0 ); + goto out; + +fail: +amdgpu_userq_clear_hqds (adev,AMDGPU_HW_IP_GFX ); +amdgpu_mes_resume (adev,0 ); +out: +amdgpu_gfx_off_ctrl (adev, true); +mutex_unlock (&adev->gfx.mec.reset_mutex); +return r; +} +#define GFX12_HPD_QUEUE_STATE_CONNECTED_MIN 3#define GFX12_HPD_QUEUE_STATE_CONNECTED_MAX 15
@@ -5375,6 +5503,7 @@ static const struct amd_ip_funcs gfx_v12_0_ip_funcs = { .suspend = gfx_v12_0_suspend, .resume = gfx_v12_0_resume, .wait_for_idle = gfx_v12_0_wait_for_idle, + .soft_reset_engine = gfx_v12_0_soft_reset_engine, .set_clockgating_state = gfx_v12_0_set_clockgating_state, .set_powergating_state = gfx_v12_0_set_powergating_state, .get_clockgating_state = gfx_v12_0_get_clockgating_state,
Signature · 1 line
2.50.1
Re: [PATCH v4 09/13] drm/amdgpu/gfx12: add a gfx engine soft reset
Quoted 90 lines · Jesse Zhang
Some hangs leave the gfx streaming engine of the CP front-end stuck, eg.
waiting for packet data that never arrives. Neither a queue nor a pipe
reset can stop it, so they end in a full GPU reset.Implement
soft_reset_engine()for the graphics engine: halt PFP/ME, pulse GRBM_SOFT_RESET.SOFT_RESET_CPF/CPG with CP_SOFT_RESET_CNTL.GFX_ONLY_SOFT_RESET andGFX_HQD_REG_RESET, restart PFP/ME and map the kernel gfx queue again.
MEC, MES and the compute queues keep running. The MES lock is held across
the pulse, as MES fetches its queues through CPF, and the CP DMA is drained around it, as a request in flight leaves the ME busy.MES is suspended meanwhile, and the gfx user queues the reset clears are
saved and restored around it. If the CP doesn't go idle, the reset fails
and a full reset follows.v4: Implement
soft_reset_engine()directly instead of areset_enginegfx
callback (Timur).Signed-off-by Jesse Zhang <[email protected]>---
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 129
+++++++++++++++++++++++++1 file changed, 129 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +0
-0@@ -3860,6 +3860,134 @@ static int gfx_v12_0_wait_for_idle(struct amdgpu_ip_block *ip_block) return -ETIMEDOUT; }drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +7
-0+/* The CP DMA and the interfaces its memory requests go through */ +#define GFX12_CP_STAT_MEM_BUSY (CP_STAT__DMA_BUSY_MASK | \ + CP_STAT__TCIU_BUSY_MASK | \ + CP_STAT__RCIU_BUSY_MASK | \ + CP_STAT__UTCL2IU_BUSY_MASK) + +/* Reset CPF/CPG, PFP/ME and the gfx HQDs, then boot PFP/ME again. */
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +7
-0+static int gfx_v12_0_soft_reset_gfx_cp (struct amdgpu_device *adev) +{ +u32 tmp, cntl, me_cntl, ib_control; +int i; + +amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); +/* MES fetches its queues through CPF: keep it out of the reset. */
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4
-0+amdgpu_mes_lock (&adev->mes); + + me_cntl =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + ib_control = RREG32_SOC15(GC, 0,
regCP_PFP_IB_CONTROL); /* cleared by the reset */drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +7
-0+ + tmp =REG_SET_FIELD (me_cntl,CP_ME_CNTL ,ME_HALT ,1 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,1 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +udelay (50 ); + +/* A CP DMA in flight during the reset leaves the ME busy after it. */
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+for (i =0 ; i < adev->usec_timeout; i++) { + if (!(RREG32_SOC15(GC, 0, regCP_STAT) &
GFX12_CP_STAT_MEM_BUSY))drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +5
-0+break ; +udelay (1 ); + } + +/* GFX_ONLY keeps compute and MES out; CPF alone leaves the stream stuck. */
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+ cntl =RREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL); + tmp = REG_SET_FIELD(cntl, CP_SOFT_RESET_CNTL,
GFX_ONLY_SOFT_RESET, 1);drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0+ tmp = REG_SET_FIELD(tmp, CP_SOFT_RESET_CNTL,
GFX_HQD_REG_RESET, 1);drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4
-0+WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, tmp); + + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF,1);
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0+ tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPG,
Quoted 1 line
1);
I still think that this needs the SOFT_RESET_GFX bit too.
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET);
This should be moved below the delay.
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+udelay (50 ); + tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF,0);
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0+ tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPG,0);
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +6
-0+WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + +WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, cntl); + +/* The halted PFP stays busy: only wait for the memory requests. */
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+for (i =0 ; i < adev->usec_timeout; i++) { + if (!(RREG32_SOC15(GC, 0, regCP_STAT) &
GFX12_CP_STAT_MEM_BUSY))
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c static int gfx_v12_0_wait_for_idle(struct amdgpu_ip_block *ip_block) · line 3919
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4
-0+break ; +udelay (1 ); + } +amdgpu_mes_unlock (&adev->mes);
We should clear the CP_VMID_RESET register here, same as we do on GFX11. It makes no sense for the CP to be doing a VMID reset while we are soft-resetting it.
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +6
-0+ +gfx_v12_0_set_pfp_ucode_start_addr (adev); +gfx_v12_0_set_me_ucode_start_addr (adev); + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT, + REG_GET_FIELD(me_cntl, CP_ME_CNTL,
CE_HALT));drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +WREG32_SOC15 (GC ,0 , regCP_PFP_IB_CONTROL, ib_control);
Why is it important to restore the CP_PFP_IB_CONTROL register? The kernel driver currently never writes this register, isn't the default value good enough?
Quoted 83 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +15
-0+amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); + + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,ME_HALT ,0 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,0 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +for (i =0 ; i < adev->usec_timeout; i++) { +if (!RREG32_SOC15 (GC ,0 , regCP_STAT)) +return 0 ; +udelay (1 ); + } +return -ETIMEDOUT ; +} + +static int gfx_v12_0_soft_reset_engine(struct amdgpu_ip_block
*ip_block,drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0+ enum amdgpu_ring_type
ring_type,drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0+ struct amdgpu_usermode_queue
*guilty_queue)drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +11
-0+{ +struct amdgpu_device *adev = ip_block->adev; +int i, r; + +if (ring_type !=AMDGPU_RING_TYPE_GFX ) +return -EOPNOTSUPP ; + +mutex_lock (&adev->gfx.mec.reset_mutex); +amdgpu_gfx_off_ctrl (adev, false); + +/* A hung gfx stream can keep MES from suspending: reset anyway. */
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +6
-0+amdgpu_mes_suspend (adev,0 ); +amdgpu_userq_save_hqds (adev,AMDGPU_HW_IP_GFX ); + + r =gfx_v12_0_soft_reset_gfx_cp (adev); +if (r) { + dev_err(adev->dev, "gfx CP still busy after reset,
CP_STAT0x%08x\n",drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +5
-0+ RREG32_SOC15(GC, 0, regCP_STAT)); + goto fail; + } + +/* The reset cleared the HQD of the kernel gfx queue: map it again. */
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +5
-0+ r =amdgpu_gfx_disable_kgq (adev,0 ); +if (r) + goto fail; +for (i =0 ; i < adev->gfx.num_gfx_rings; i++) + amdgpu_gfx_mqd_reset_restore(&adev-Quoted 1 line
gfx.gfx_ring[i]);
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +7
-0+ r =amdgpu_gfx_enable_kgq (adev,0 ); +if (!r) + r =gfx_v12_0_cp_gfx_start (adev); +if (r) + goto fail; + + amdgpu_userq_restore_hqds(adev, AMDGPU_HW_IP_GFX,
guilty_queue);drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +12
-0+ r =amdgpu_mes_resume (adev,0 ); + goto out; + +fail: +amdgpu_userq_clear_hqds (adev,AMDGPU_HW_IP_GFX ); +amdgpu_mes_resume (adev,0 ); +out: +amdgpu_gfx_off_ctrl (adev, true); +mutex_unlock (&adev->gfx.mec.reset_mutex); +return r; +} +#define
GFX12_HPD_QUEUE_STATE_CONNECTED_MIN3
#defineGFX12_HPD_QUEUE_STATE_CONNECTED_MAX15drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0@@ -5375,6 +5503,7 @@ static const struct amd_ip_funcs gfx_v12_0_ip_funcs = { .suspend = gfx_v12_0_suspend, .resume = gfx_v12_0_resume, .wait_for_idle = gfx_v12_0_wait_for_idle, + .soft_reset_engine = gfx_v12_0_soft_reset_engine, .set_clockgating_state = gfx_v12_0_set_clockgating_state, .set_powergating_state = gfx_v12_0_set_powergating_state,.get_clockgating_state =
gfx_v12_0_get_clockgating_state,
RE: [PATCH v4 09/13] drm/amdgpu/gfx12: add a gfx engine soft reset
AMD General
Quoted 124 lines
-----Original Message-----
From: Timur Kristóf <[email protected]>
Sent: Thursday, November 19, 2026 7:43 PM
To: Zhang, Jesse(Jie) <[email protected]>; amd- [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Mario Sopena-Novales <[email protected]>; Rastogi, Manu <[email protected]>; Zhu, Jiongyu (Joey) <[email protected]>
Subject: Re: [PATCH v4 09/13] drm/amdgpu/gfx12: add a gfx engine soft resetQuoted 8 lines · Jesse Zhang
Some hangs leave the gfx streaming engine of the CP front-end stuck, eg.
waiting for packet data that never arrives. Neither a queue nor a pipe reset can stop it, so they end in a full GPU reset.Implement
soft_reset_engine()for the graphics engine: halt PFP/ME, pulse GRBM_SOFT_RESET.SOFT_RESET_CPF/CPG with CP_SOFT_RESET_CNTL.GFX_ONLY_SOFT_RESET andGFX_HQD_REG_RESET,restart
Quoted 25 lines
PFP/ME and map the kernel gfx queue again.
MEC, MES and the compute queues keep running. The MES lock is held across the pulse, as MES fetches its queues through CPF, and the CP DMA is drained around it, as a request in flight leaves the ME busy.MES is suspended meanwhile, and the gfx user queues the reset clears are saved and restored around it. If the CP doesn't go idle, the reset fails and a full reset follows.
v4: Implement
soft_reset_engine()directly instead of areset_enginegfx
callback (Timur).Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 129 +++++++++++++++++++++++++ 1 file changed, 129 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +0
-0drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c static int gfx_v12_0_wait_for_idle(struct · line 3865
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0@@ -3860,6 +3860,134 @@ static int gfx_v12_0_wait_for_idle(struct amdgpu_ip_block *ip_block)return -ETIMEDOUT ; } +/* The CP DMA and the interfaces its memory requests go through */ +#define GFX12_CP_STAT_MEM_BUSY (CP_STAT__DMA_BUSY_MASK | \Quoted 44 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +11
-0+ CP_STAT__TCIU_BUSY_MASK | \ + CP_STAT__RCIU_BUSY_MASK | \ + CP_STAT__UTCL2IU_BUSY_MASK) + +/* Reset CPF/CPG, PFP/ME and the gfx HQDs, then boot PFP/ME again. */ +static int gfx_v12_0_soft_reset_gfx_cp (struct amdgpu_device *adev) { +u32 tmp, cntl, me_cntl, ib_control; +int i; + +amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); +/* MES fetches its queues through CPF: keep it out of the reset. */
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4
-0+amdgpu_mes_lock (&adev->mes); + + me_cntl =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + ib_control = RREG32_SOC15(GC, 0,
regCP_PFP_IB_CONTROL); /* cleared by the reset */drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +7
-0+ + tmp =REG_SET_FIELD (me_cntl,CP_ME_CNTL ,ME_HALT ,1 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,1 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +udelay (50 ); + +/* A CP DMA in flight during the reset leaves the ME busy after it. */
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+for (i =0 ; i < adev->usec_timeout; i++) { + if (!(RREG32_SOC15(GC, 0, regCP_STAT) &
GFX12_CP_STAT_MEM_BUSY))drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +5
-0+break ; +udelay (1 ); + } + +/* GFX_ONLY keeps compute and MES out; CPF alone leaves the stream stuck. */
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+ cntl =RREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL); + tmp = REG_SET_FIELD(cntl, CP_SOFT_RESET_CNTL,
GFX_ONLY_SOFT_RESET, 1);
+ tmp = REG_SET_FIELD(tmp,CP_SOFT_RESET_CNTL,GFX_HQD_REG_RESET, 1);drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4
-0+WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, tmp); + + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF,Quoted 3 lines
1);
+ tmp = REG_SET_FIELD(tmp,GRBM_SOFT_RESET,SOFT_RESET_CPG,
1);I still think that this needs the
SOFT_RESET_GFXbit too.drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET);This should be moved below the delay.
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+udelay (50 ); + tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF,0);
+ tmp = REG_SET_FIELD(tmp,GRBM_SOFT_RESET,SOFT_RESET_CPG,
0);drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +6
-0+WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + +WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, cntl); + +/* The halted PFP stays busy: only wait for the memory requests. */
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+for (i =0 ; i < adev->usec_timeout; i++) { + if (!(RREG32_SOC15(GC, 0, regCP_STAT) &
GFX12_CP_STAT_MEM_BUSY))
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c static int gfx_v12_0_wait_for_idle(struct amdgpu_ip_block *ip_block) · line 3919
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4
-0+break ; +udelay (1 ); + } +amdgpu_mes_unlock (&adev->mes);We should clear the
CP_VMID_RESETregister here, same as we do on GFX11. It makes no sense for the CP to be doing a VMID reset while we are soft- resetting it.
Agreed, Thanks Timer and will update it.
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +6
-0+ +gfx_v12_0_set_pfp_ucode_start_addr (adev); +gfx_v12_0_set_me_ucode_start_addr (adev); + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT, + REG_GET_FIELD(me_cntl, CP_ME_CNTL,
CE_HALT));drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-0+WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +WREG32_SOC15 (GC ,0 , regCP_PFP_IB_CONTROL, ib_control);
Quoted 3 lines
Why is it important to restore the
CP_PFP_IB_CONTROLregister?
The kernel driver currently never writes this register, isn't the default value good enough?
It isn't needed. Will drops it.
Thanks
Jesse
Quoted 84 lines
Quoted 84 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +15
-0+amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); + + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,ME_HALT ,0 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,0 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +for (i =0 ; i < adev->usec_timeout; i++) { +if (!RREG32_SOC15 (GC ,0 , regCP_STAT)) +return 0 ; +udelay (1 ); + } +return -ETIMEDOUT ; +} + +static int gfx_v12_0_soft_reset_engine(struct amdgpu_ip_block
*ip_block,
+ enumamdgpu_ring_typering_type,
+ structamdgpu_usermode_queue*guilty_queue)drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +11
-0+{ +struct amdgpu_device *adev = ip_block->adev; +int i, r; + +if (ring_type !=AMDGPU_RING_TYPE_GFX ) +return -EOPNOTSUPP ; + +mutex_lock (&adev->gfx.mec.reset_mutex); +amdgpu_gfx_off_ctrl (adev, false); + +/* A hung gfx stream can keep MES from suspending: reset anyway. */
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +6
-0+amdgpu_mes_suspend (adev,0 ); +amdgpu_userq_save_hqds (adev,AMDGPU_HW_IP_GFX ); + + r =gfx_v12_0_soft_reset_gfx_cp (adev); +if (r) { + dev_err(adev->dev, "gfx CP still busy after reset,
CP_STAT0x%08x\n",drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +5
-0+ RREG32_SOC15(GC, 0, regCP_STAT)); + goto fail; + } + +/* The reset cleared the HQD of the kernel gfx queue: map it again. */
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +5
-0+ r =amdgpu_gfx_disable_kgq (adev,0 ); +if (r) + goto fail; +for (i =0 ; i < adev->gfx.num_gfx_rings; i++) + amdgpu_gfx_mqd_reset_restore(&adev-Quoted 1 line
gfx.gfx_ring[i]);
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +7
-0+ r =amdgpu_gfx_enable_kgq (adev,0 ); +if (!r) + r =gfx_v12_0_cp_gfx_start (adev); +if (r) + goto fail; + + amdgpu_userq_restore_hqds(adev, AMDGPU_HW_IP_GFX,
guilty_queue);drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +13
-0+ r =amdgpu_mes_resume (adev,0 ); + goto out; + +fail: +amdgpu_userq_clear_hqds (adev,AMDGPU_HW_IP_GFX ); +amdgpu_mes_resume (adev,0 ); +out: +amdgpu_gfx_off_ctrl (adev, true); +mutex_unlock (&adev->gfx.mec.reset_mutex); +return r; +} +#define GFX12_HPD_QUEUE_STATE_CONNECTED_MIN 3#define GFX12_HPD_QUEUE_STATE_CONNECTED_MAX 15@@ -5375,6 +5503,7 @@ static const struct amd_ip_funcs gfx_v12_0_ip_funcs = { .suspend = gfx_v12_0_suspend, .resume = gfx_v12_0_resume, .wait_for_idle = gfx_v12_0_wait_for_idle, + .soft_reset_engine = gfx_v12_0_soft_reset_engine, .set_clockgating_state = gfx_v12_0_set_clockgating_state, .set_powergating_state = gfx_v12_0_set_powergating_state,.get_clockgating_state =
gfx_v12_0_get_clockgating_state,
PATCH v4 10/13 drm/amdgpu/gfx11: add a gfx engine soft reset
In reply to Jesse ZhangImplement soft_reset_engine() for the graphics engine of gfx11, as for gfx12, with two differences:
- clear CP_VMID_RESET: a VMID reset the hung PFP didn't handle survives the CPF/CPG reset;
- boot PFP/ME with CP_PFP_IB_CONTROL cleared and restore it afterwards:
set, it makes the F32 PFP of the APUs resume from power gating and wait for a clear state that never comes.
The CPF/CPG reset already puts PFP/ME back at their firmware start address, so unhalting them restarts the RS64 and F32 firmware alike.
v4: Implement soft_reset_engine() directly instead of a reset_engine gfx
callback, drop gfx_v11_0_restart_gfx_rs64(), and boot with CP_PFP_IB_CONTROL cleared for the F32 firmware (Timur).
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 134 +++++++++++++++++++++++++ 1 file changed, 134 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +134 -0
@@ -6777,6 +6777,139 @@ static void gfx_v11_0_emit_mem_sync(struct amdgpu_ring *ring)amdgpu_ring_write (ring, gcr_cntl);/* GCR_CNTL */ } +/* The CP DMA and the interfaces its memory requests go through */ +#define GFX11_CP_STAT_MEM_BUSY (CP_STAT__DMA_BUSY_MASK | \ + CP_STAT__TCIU_BUSY_MASK | \ + CP_STAT__RCIU_BUSY_MASK | \ + CP_STAT__UTCL2IU_BUSY_MASK) + +/* Reset CPF/CPG, PFP/ME and the gfx HQDs, then boot PFP/ME again. */ +static int gfx_v11_0_soft_reset_gfx_cp (struct amdgpu_device *adev) +{ +u32 tmp, cntl, me_cntl, ib_control; +int i; + +amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); +/* MES fetches its queues through CPF: keep it out of the reset. */ +amdgpu_mes_lock (&adev->mes); + + me_cntl =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + ib_control =RREG32_SOC15 (GC ,0 , regCP_PFP_IB_CONTROL);/* cleared by the reset */ + + tmp =REG_SET_FIELD (me_cntl,CP_ME_CNTL ,ME_HALT ,1 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,1 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +udelay (50 ); + +/* A CP DMA in flight during the reset leaves the ME busy after it. */ +for (i =0 ; i < adev->usec_timeout; i++) { +if (!(RREG32_SOC15 (GC ,0 , regCP_STAT) &GFX11_CP_STAT_MEM_BUSY )) +break ; +udelay (1 ); + } + +/* GFX_ONLY keeps compute and MES out; CPF alone leaves the stream stuck. */ + cntl =RREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL); + tmp =REG_SET_FIELD (cntl,CP_SOFT_RESET_CNTL ,GFX_ONLY_SOFT_RESET ,1 ); + tmp =REG_SET_FIELD (tmp,CP_SOFT_RESET_CNTL ,GFX_HQD_REG_RESET ,1 ); +WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, tmp); + + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPF ,1 ); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPG ,1 ); +WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); +udelay (50 ); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPF ,0 ); + tmp =REG_SET_FIELD (tmp,GRBM_SOFT_RESET ,SOFT_RESET_CPG ,0 ); +WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + +WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, cntl); + +/* The halted PFP stays busy: only wait for the memory requests. */ +for (i =0 ; i < adev->usec_timeout; i++) { +if (!(RREG32_SOC15 (GC ,0 , regCP_STAT) &GFX11_CP_STAT_MEM_BUSY )) +break ; +udelay (1 ); + } +/* A VMID reset the hung PFP didn't handle survives the reset. */ +WREG32_SOC15 (GC ,0 , regCP_VMID_RESET,0 ); +amdgpu_mes_unlock (&adev->mes); + + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,CE_HALT , +REG_GET_FIELD (me_cntl,CP_ME_CNTL ,CE_HALT )); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); + +/* +* Boot with CP_PFP_IB_CONTROL cleared: set, it makes the F32 PFP resume +* from power gating and wait for a clear state that never comes. +*/ + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,ME_HALT ,0 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,0 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +for (i =0 ; i < adev->usec_timeout; i++) { +if (!RREG32_SOC15 (GC ,0 , regCP_STAT)) +break ; +udelay (1 ); + } +WREG32_SOC15 (GC ,0 , regCP_PFP_IB_CONTROL, ib_control); + +return i < adev->usec_timeout ?0 : -ETIMEDOUT ; +} + +static int gfx_v11_0_soft_reset_engine (struct amdgpu_ip_block *ip_block, +enum amdgpu_ring_type ring_type, +struct amdgpu_usermode_queue *guilty_queue) +{ +struct amdgpu_device *adev = ip_block->adev; +int i, r; + +if (ring_type !=AMDGPU_RING_TYPE_GFX ) +return -EOPNOTSUPP ; + +mutex_lock (&adev->gfx.mec.reset_mutex); +amdgpu_gfx_off_ctrl (adev, false); + +/* A hung gfx stream can keep MES from suspending: reset anyway. */ +amdgpu_mes_suspend (adev,0 ); +amdgpu_userq_save_hqds (adev,AMDGPU_HW_IP_GFX ); + + r =gfx_v11_0_soft_reset_gfx_cp (adev); +if (r) { +dev_err (adev->dev,"gfx CP still busy after reset, CP_STAT 0x%08x\n" , +RREG32_SOC15 (GC ,0 , regCP_STAT)); + goto fail; + } + +/* The reset cleared the HQD of the kernel gfx queue: map it again. */ + r =amdgpu_gfx_disable_kgq (adev,0 ); +if (r) + goto fail; +for (i =0 ; i < adev->gfx.num_gfx_rings; i++) +amdgpu_gfx_mqd_reset_restore (&adev->gfx.gfx_ring[i]); + r =amdgpu_gfx_enable_kgq (adev,0 ); +if (!r) + r =gfx_v11_0_cp_gfx_start (adev); +if (r) + goto fail; + +amdgpu_userq_restore_hqds (adev,AMDGPU_HW_IP_GFX , guilty_queue); + r =amdgpu_mes_resume (adev,0 ); + goto out; + +fail: +amdgpu_userq_clear_hqds (adev,AMDGPU_HW_IP_GFX ); +amdgpu_mes_resume (adev,0 ); +out: +amdgpu_gfx_off_ctrl (adev, true); +mutex_unlock (&adev->gfx.mec.reset_mutex); +return r; +} +#define GFX11_HPD_QUEUE_STATE_CONNECTED_MIN 3#define GFX11_HPD_QUEUE_STATE_CONNECTED_MAX 15
@@ -7045,6 +7178,7 @@ static const struct amd_ip_funcs gfx_v11_0_ip_funcs = { .suspend = gfx_v11_0_suspend, .resume = gfx_v11_0_resume, .wait_for_idle = gfx_v11_0_wait_for_idle, + .soft_reset_engine = gfx_v11_0_soft_reset_engine, .soft_reset = gfx_v11_0_soft_reset, .set_clockgating_state = gfx_v11_0_set_clockgating_state, .set_powergating_state = gfx_v11_0_set_powergating_state,
Signature · 1 line
2.50.1
Re: [PATCH v4 10/13] drm/amdgpu/gfx11: add a gfx engine soft reset
Quoted 52 lines · Jesse Zhang
Implement
soft_reset_engine()for the graphics engine of gfx11, as for
gfx12, with two differences:
- clearCP_VMID_RESET: a VMID reset the hung PFP didn't handle survives
the CPF/CPG reset;
- boot PFP/ME withCP_PFP_IB_CONTROLcleared and restore it afterwards:
set, it makes the F32 PFP of the APUs resume from power gating and wait
for a clear state that never comes.The CPF/CPG reset already puts PFP/ME back at their firmware start address, so unhalting them restarts the RS64 and F32 firmware alike.
v4: Implement
soft_reset_engine()directly instead of areset_enginegfx
callback, dropgfx_v11_0_restart_gfx_rs64(), and boot withCP_PFP_IB_CONTROLcleared for the F32 firmware (Timur).Signed-off-by Jesse Zhang <[email protected]>---
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 134
+++++++++++++++++++++++++1 file changed, 134 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6777,6 +6777,139 @@ static void gfx_v11_0_emit_mem_sync(struct amdgpu_ring *ring)
amdgpu_ring_write(ring, gcr_cntl); /*GCR_CNTL*/ }drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +7
-0+/* The CP DMA and the interfaces its memory requests go through */ +#define GFX11_CP_STAT_MEM_BUSY (CP_STAT__DMA_BUSY_MASK | \ + CP_STAT__TCIU_BUSY_MASK | \ + CP_STAT__RCIU_BUSY_MASK | \ + CP_STAT__UTCL2IU_BUSY_MASK) + +/* Reset CPF/CPG, PFP/ME and the gfx HQDs, then boot PFP/ME again. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +7
-0+static int gfx_v11_0_soft_reset_gfx_cp (struct amdgpu_device *adev) +{ +u32 tmp, cntl, me_cntl, ib_control; +int i; + +amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); +/* MES fetches its queues through CPF: keep it out of the reset. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static void gfx_v11_0_emit_mem_sync(struct amdgpu_ring *ring) · line 6794
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+amdgpu_mes_lock (&adev->mes);
I wonder if we should lock the SRBM mutex here. What do you think?
Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3
-0+ + me_cntl =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + ib_control = RREG32_SOC15(GC, 0,
regCP_PFP_IB_CONTROL); /* cleared by the reset */drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +7
-0+ + tmp =REG_SET_FIELD (me_cntl,CP_ME_CNTL ,ME_HALT ,1 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,1 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +udelay (50 ); + +/* A CP DMA in flight during the reset leaves the ME busy after it. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+for (i =0 ; i < adev->usec_timeout; i++) { + if (!(RREG32_SOC15(GC, 0, regCP_STAT) &
GFX11_CP_STAT_MEM_BUSY))drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+break ; +udelay (1 ); + } + +/* GFX_ONLY keeps compute and MES out; CPF alone leaves the stream stuck. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+ cntl =RREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL); + tmp = REG_SET_FIELD(cntl, CP_SOFT_RESET_CNTL,
GFX_ONLY_SOFT_RESET, 1);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+ tmp = REG_SET_FIELD(tmp, CP_SOFT_RESET_CNTL,
GFX_HQD_REG_RESET, 1);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0+WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, tmp); + + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF,1);
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+ tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPG,
Quoted 1 line
1);
I just tested this on Strix Halo (GFX11.5).
We need to set the SOFT_RESET_GFX bit here in order to reset the fixed- function graphics pipeline. Otherwise this can't recover from cases when the fixed-function pipeline hangs, for example a buggy NGG shader.
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET);
This line should be moved below the delay.
Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+udelay (50 ); + tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF,0);
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+ tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPG,0);
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6
-0+WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + +WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, cntl); + +/* The halted PFP stays busy: only wait for the memory requests. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+for (i =0 ; i < adev->usec_timeout; i++) { + if (!(RREG32_SOC15(GC, 0, regCP_STAT) &
GFX11_CP_STAT_MEM_BUSY))drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0+break ; +udelay (1 ); + } +/* A VMID reset the hung PFP didn't handle survives the reset. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static void gfx_v11_0_emit_mem_sync(struct amdgpu_ring *ring) · line 6837
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+WREG32_SOC15 (GC ,0 , regCP_VMID_RESET,0 );
Does this introduce a race condition between per-queue resets and the soft reset? I mean, what happens if we are doing a queue reset on a compute queue at the same time while this function is resetting the GFX engine?
Quoted 98 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+amdgpu_mes_unlock (&adev->mes); + + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT, + REG_GET_FIELD(me_cntl, CP_ME_CNTL,
CE_HALT));drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); + +/* +* Boot with CP_PFP_IB_CONTROL cleared: set, it makes the F32 PFP resume
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+* from power gating and wait for a clear state that never comes.
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +16
-0+*/ + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,ME_HALT ,0 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,0 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +for (i =0 ; i < adev->usec_timeout; i++) { +if (!RREG32_SOC15 (GC ,0 , regCP_STAT)) +break ; +udelay (1 ); + } +WREG32_SOC15 (GC ,0 , regCP_PFP_IB_CONTROL, ib_control); + +return i < adev->usec_timeout ?0 : -ETIMEDOUT ; +} + +static int gfx_v11_0_soft_reset_engine(struct amdgpu_ip_block
*ip_block,drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+ enum amdgpu_ring_type
ring_type,drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+ struct amdgpu_usermode_queue
*guilty_queue)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +11
-0+{ +struct amdgpu_device *adev = ip_block->adev; +int i, r; + +if (ring_type !=AMDGPU_RING_TYPE_GFX ) +return -EOPNOTSUPP ; + +mutex_lock (&adev->gfx.mec.reset_mutex); +amdgpu_gfx_off_ctrl (adev, false); + +/* A hung gfx stream can keep MES from suspending: reset anyway. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6
-0+amdgpu_mes_suspend (adev,0 ); +amdgpu_userq_save_hqds (adev,AMDGPU_HW_IP_GFX ); + + r =gfx_v11_0_soft_reset_gfx_cp (adev); +if (r) { + dev_err(adev->dev, "gfx CP still busy after reset,
CP_STAT0x%08x\n",drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+ RREG32_SOC15(GC, 0, regCP_STAT)); + goto fail; + } + +/* The reset cleared the HQD of the kernel gfx queue: map it again. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+ r =amdgpu_gfx_disable_kgq (adev,0 ); +if (r) + goto fail; +for (i =0 ; i < adev->gfx.num_gfx_rings; i++) + amdgpu_gfx_mqd_reset_restore(&adev-Quoted 1 line
gfx.gfx_ring[i]);
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +7
-0+ r =amdgpu_gfx_enable_kgq (adev,0 ); +if (!r) + r =gfx_v11_0_cp_gfx_start (adev); +if (r) + goto fail; + + amdgpu_userq_restore_hqds(adev, AMDGPU_HW_IP_GFX,
guilty_queue);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +12
-0+ r =amdgpu_mes_resume (adev,0 ); + goto out; + +fail: +amdgpu_userq_clear_hqds (adev,AMDGPU_HW_IP_GFX ); +amdgpu_mes_resume (adev,0 ); +out: +amdgpu_gfx_off_ctrl (adev, true); +mutex_unlock (&adev->gfx.mec.reset_mutex); +return r; +} +#define
GFX11_HPD_QUEUE_STATE_CONNECTED_MIN3
#defineGFX11_HPD_QUEUE_STATE_CONNECTED_MAX15drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0@@ -7045,6 +7178,7 @@ static const struct amd_ip_funcs gfx_v11_0_ip_funcs = { .suspend = gfx_v11_0_suspend, .resume = gfx_v11_0_resume, .wait_for_idle = gfx_v11_0_wait_for_idle, + .soft_reset_engine = gfx_v11_0_soft_reset_engine, .soft_reset = gfx_v11_0_soft_reset, .set_clockgating_state = gfx_v11_0_set_clockgating_state,.set_powergating_state =
gfx_v11_0_set_powergating_state,
RE: [PATCH v4 10/13] drm/amdgpu/gfx11: add a gfx engine soft reset
AMD General
Quoted 50 lines
-----Original Message-----
From: Timur Kristóf <[email protected]>
Sent: Thursday, November 19, 2026 7:47 PM
To: Zhang, Jesse(Jie) <[email protected]>; amd- [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Mario Sopena-Novales <[email protected]>; Rastogi, Manu <[email protected]>; Zhu, Jiongyu (Joey) <[email protected]>
Subject: Re: [PATCH v4 10/13] drm/amdgpu/gfx11: add a gfx engine soft resetQuoted 31 lines · Jesse Zhang
Implement
soft_reset_engine()for the graphics engine of gfx11, as for gfx12, with two differences:
- clearCP_VMID_RESET: a VMID reset the hung PFP didn't handle survives
the CPF/CPG reset;
- boot PFP/ME withCP_PFP_IB_CONTROLcleared and restore it afterwards:
set, it makes the F32 PFP of the APUs resume from power gating and
wait
for a clear state that never comes.The CPF/CPG reset already puts PFP/ME back at their firmware start address, so unhalting them restarts the RS64 and F32 firmware alike.
v4: Implement
soft_reset_engine()directly instead of areset_enginegfx
callback, dropgfx_v11_0_restart_gfx_rs64(), and boot withCP_PFP_IB_CONTROLcleared for the F32 firmware (Timur).Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 134 +++++++++++++++++++++++++ 1 file changed, 134 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static void gfx_v11_0_emit_mem_sync(struct · line 6782
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0@@ -6777,6 +6777,139 @@ static void gfx_v11_0_emit_mem_sync(struct amdgpu_ring *ring)amdgpu_ring_write (ring ,gcr_cntl );/* GCR_CNTL */ } +/* The CP DMA and the interfaces its memory requests go through */ +#define GFX11_CP_STAT_MEM_BUSY (CP_STAT__DMA_BUSY_MASK | \
Quoted 16 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +11
-0+ CP_STAT__TCIU_BUSY_MASK | \ + CP_STAT__RCIU_BUSY_MASK | \ + CP_STAT__UTCL2IU_BUSY_MASK) + +/* Reset CPF/CPG, PFP/ME and the gfx HQDs, then boot PFP/ME again. */ +static int gfx_v11_0_soft_reset_gfx_cp (struct amdgpu_device *adev) { +u32 tmp, cntl, me_cntl, ib_control; +int i; + +amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); +/* MES fetches its queues through CPF: keep it out of the Quoted 2 lines
reset. */
+amdgpu_mes_lock(&adev->mes);I wonder if we should lock the SRBM mutex here. What do you think?
I don't think it's needed: none of the registers written here are banked by GRBM_GFX_CNTL (CP_ME_CNTL, CP_SOFT_RESET_CNTL, GRBM_SOFT_RESET, CP_STAT, CP_VMID_RESET). If we take it anyway, it must come after the MES lock, as mes_v11_0_reset_queue_mmio() takes srbm_mutex with the MES lock held.
Quoted 31 lines
Quoted 31 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3
-0+ + me_cntl =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + ib_control = RREG32_SOC15(GC, 0,
regCP_PFP_IB_CONTROL); /* cleared by the reset */drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +7
-0+ + tmp =REG_SET_FIELD (me_cntl,CP_ME_CNTL ,ME_HALT ,1 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,1 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +udelay (50 ); + +/* A CP DMA in flight during the reset leaves the ME busy after it. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+for (i =0 ; i < adev->usec_timeout; i++) { + if (!(RREG32_SOC15(GC, 0, regCP_STAT) &
GFX11_CP_STAT_MEM_BUSY))drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+break ; +udelay (1 ); + } + +/* GFX_ONLY keeps compute and MES out; CPF alone leaves the stream stuck. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+ cntl =RREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL); + tmp = REG_SET_FIELD(cntl, CP_SOFT_RESET_CNTL,
GFX_ONLY_SOFT_RESET, 1);
+ tmp = REG_SET_FIELD(tmp,CP_SOFT_RESET_CNTL,GFX_HQD_REG_RESET, 1);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0+WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, tmp); + + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF,
Quoted 8 lines
Quoted 3 lines
1);
+ tmp = REG_SET_FIELD(tmp,GRBM_SOFT_RESET,SOFT_RESET_CPG,
1);I just tested this on Strix Halo (GFX11.5).
We need to set theSOFT_RESET_GFXbit here in order to reset the fixed- function graphics pipeline. Otherwise this can't recover from cases when the fixed-function pipeline hangs, for example a buggy NGG shader.
The case I tested was a bad-length (oversize) packet hang in the CP. CPF/CPG reset alone recovers it. Adding SOFT_RESET_GFX also brings the gfx CP back, but then SDMA times out and recovery escalates to MODE1.
This suggests that the current sequence needs additional recovery work when SOFT_RESET_GFX is included. It doesn't establish how your NGG case should be handled. Could we keep the CP-only reset or gpu reset for the buggy NGG recovers, and use a broader reset if that recovery fails?
Quoted 23 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET);This line should be moved below the delay.
Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+udelay (50 ); + tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF,0);
+ tmp = REG_SET_FIELD(tmp,GRBM_SOFT_RESET,SOFT_RESET_CPG,
0);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6
-0+WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + +WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, cntl); + +/* The halted PFP stays busy: only wait for the memory requests. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+for (i =0 ; i < adev->usec_timeout; i++) { + if (!(RREG32_SOC15(GC, 0, regCP_STAT) &
GFX11_CP_STAT_MEM_BUSY))drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+break ; +udelay (1 );
Quoted 8 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+ } +/* A VMID reset the hung PFP didn't handle survives the reset. */
+WREG32_SOC15(GC, 0, regCP_VMID_RESET, 0);Does this introduce a race condition between per-queue resets and the soft reset? I mean, what happens if we are doing a queue reset on a compute queue at the same time while this function is resetting the GFX engine?
They don't run at the same time: the engine reset holds gfx.mec.reset_mutex, like amdgpu_gfx_reset_mes_compute() and amdgpu_gfx_reset_mes_gfx() do, and the single MES/MMIO queue resets (amdgpu_mes_reset_legacy_queue(), amdgpu_mes_reset_queue_mmio()) take the MES lock, which is held across the pulse. GFX_ONLY_SOFT_RESET also keeps the compute HQDs out of the pulse.
Jesse
Quoted 98 lines
Quoted 98 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+amdgpu_mes_unlock (&adev->mes); + + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT, + REG_GET_FIELD(me_cntl, CP_ME_CNTL,
CE_HALT));drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); + +/* +* Boot with CP_PFP_IB_CONTROL cleared: set, it makes the F32 PFP resume
+ * from power gating and wait for a clear state that never
comes.drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +15
-0+*/ + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,ME_HALT ,0 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,0 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +for (i =0 ; i < adev->usec_timeout; i++) { +if (!RREG32_SOC15 (GC ,0 , regCP_STAT)) +break ; +udelay (1 ); + } +WREG32_SOC15 (GC ,0 , regCP_PFP_IB_CONTROL, ib_control); + +return i < adev->usec_timeout ?0 : -ETIMEDOUT ; } + +static int gfx_v11_0_soft_reset_engine(struct amdgpu_ip_block
*ip_block,
+ enumamdgpu_ring_typering_type,
+ structamdgpu_usermode_queue*guilty_queue)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +11
-0+{ +struct amdgpu_device *adev = ip_block->adev; +int i, r; + +if (ring_type !=AMDGPU_RING_TYPE_GFX ) +return -EOPNOTSUPP ; + +mutex_lock (&adev->gfx.mec.reset_mutex); +amdgpu_gfx_off_ctrl (adev, false); + +/* A hung gfx stream can keep MES from suspending: reset anyway. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6
-0+amdgpu_mes_suspend (adev,0 ); +amdgpu_userq_save_hqds (adev,AMDGPU_HW_IP_GFX ); + + r =gfx_v11_0_soft_reset_gfx_cp (adev); +if (r) { + dev_err(adev->dev, "gfx CP still busy after reset,
CP_STAT0x%08x\n",drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+ RREG32_SOC15(GC, 0, regCP_STAT)); + goto fail; + } + +/* The reset cleared the HQD of the kernel gfx queue: map it again. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+ r =amdgpu_gfx_disable_kgq (adev,0 ); +if (r) + goto fail; +for (i =0 ; i < adev->gfx.num_gfx_rings; i++) + amdgpu_gfx_mqd_reset_restore(&adev-Quoted 1 line
gfx.gfx_ring[i]);
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +7
-0+ r =amdgpu_gfx_enable_kgq (adev,0 ); +if (!r) + r =gfx_v11_0_cp_gfx_start (adev); +if (r) + goto fail; + + amdgpu_userq_restore_hqds(adev, AMDGPU_HW_IP_GFX,
guilty_queue);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +13
-0+ r =amdgpu_mes_resume (adev,0 ); + goto out; + +fail: +amdgpu_userq_clear_hqds (adev,AMDGPU_HW_IP_GFX ); +amdgpu_mes_resume (adev,0 ); +out: +amdgpu_gfx_off_ctrl (adev, true); +mutex_unlock (&adev->gfx.mec.reset_mutex); +return r; +} +#define GFX11_HPD_QUEUE_STATE_CONNECTED_MIN 3#define GFX11_HPD_QUEUE_STATE_CONNECTED_MAX 15@@ -7045,6 +7178,7 @@ static const struct amd_ip_funcs gfx_v11_0_ip_funcs = { .suspend = gfx_v11_0_suspend, .resume = gfx_v11_0_resume, .wait_for_idle = gfx_v11_0_wait_for_idle, + .soft_reset_engine = gfx_v11_0_soft_reset_engine, .soft_reset = gfx_v11_0_soft_reset, .set_clockgating_state = gfx_v11_0_set_clockgating_state,.set_powergating_state =
gfx_v11_0_set_powergating_state,
Re: [PATCH v4 10/13] drm/amdgpu/gfx11: add a gfx engine soft reset
Quoted 79 lines · Jesse(Jie)
AMD General
Quoted 69 lines
-----Original Message-----
From: Timur Kristóf <[email protected]>
Sent: Thursday, November 19, 2026 7:47 PM
To: Zhang, Jesse(Jie) <[email protected]>; amd- [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian
<[email protected]>; Lazar, Lijo <[email protected]>; Mario Sopena-Novales <[email protected]>; Rastogi, Manu <[email protected]>; Zhu, Jiongyu (Joey) <[email protected]>
Subject: Re: [PATCH v4 10/13] drm/amdgpu/gfx11: add a gfx engine soft resetQuoted 41 lines · Jesse Zhang
Implement
soft_reset_engine()for the graphics engine of gfx11, as for
gfx12, with two differences:
- clearCP_VMID_RESET: a VMID reset the hung PFP didn't handle survives
the CPF/CPG reset;
- boot PFP/ME withCP_PFP_IB_CONTROLcleared and restore it afterwards:
set, it makes the F32 PFP of the APUs resume from power gating and
wait
for a clear state that never comes.The CPF/CPG reset already puts PFP/ME back at their firmware start
address, so unhalting them restarts the RS64 and F32 firmware alike.v4: Implement
soft_reset_engine()directly instead of areset_engine
gfx
callback, dropgfx_v11_0_restart_gfx_rs64(), and boot withCP_PFP_IB_CONTROLcleared for the F32 firmware (Timur).Signed-off-by Jesse Zhang <[email protected]>---
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 134
+++++++++++++++++++++++++1 file changed, 134 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6777,6 +6777,139 @@ static voidgfx_v11_0_emit_mem_sync(struct
amdgpu_ring*ring)
amdgpu_ring_write(ring, gcr_cntl); /*GCR_CNTL*/ }Quoted 3 lines
+/* The CP DMA and the interfaces its memory requests go through */
+#defineGFX11_CP_STAT_MEM_BUSY(
CP_STAT__DMA_BUSY_MASK| \Quoted 10 lines
+
CP_STAT__TCIU_BUSY_MASK| \
+CP_STAT__RCIU_BUSY_MASK| \
+CP_STAT__UTCL2IU_BUSY_MASK)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+ +/* Reset CPF/CPG, PFP/ME and the gfx HQDs, then boot PFP/ME again.
*/
+static intgfx_v11_0_soft_reset_gfx_cp(struct amdgpu_device *adev){
+ u32 tmp, cntl,me_cntl,ib_control;Quoted 8 lines
Quoted 6 lines
+ int i;
+
+amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
+ /* MES fetches its queues through CPF: keep it out of the reset. */
+amdgpu_mes_lock(&adev->mes);I wonder if we should lock the SRBM mutex here. What do you think?
Quoted 8 lines
I don't think it's needed: none of the registers written here are banked
byGRBM_GFX_CNTL(CP_ME_CNTL,CP_SOFT_RESET_CNTL,GRBM_SOFT_RESET,CP_STAT,CP_VMID_RESET). If we take it anyway, it must come after the MES
lock, asmes_v11_0_reset_queue_mmio()takessrbm_mutexwith the MES lock
held.
I see. That sounds OK to me, then.
Quoted 44 lines
Quoted 35 lines
Quoted 35 lines
+
+me_cntl=RREG32_SOC15(GC, 0, regCP_ME_CNTL); +ib_control=RREG32_SOC15(GC, 0, regCP_PFP_IB_CONTROL); /* cleared by the reset */drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +7
-0+ + tmp = REG_SET_FIELD(me_cntl, CP_ME_CNTL, ME_HALT, 1); + tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, PFP_HALT, 1); + WREG32_SOC15(GC, 0, regCP_ME_CNTL, tmp); + udelay(50); + + /* A CP DMA in flight during the reset leaves the ME busyafter it. */
+ for (i = 0; i <adev->usec_timeout; i++) {
+ if (!(RREG32_SOC15(GC, 0,regCP_STAT) &GFX11_CP_STAT_MEM_BUSY))
+ break;
+ udelay(1);
+ }
+
+ /*GFX_ONLYkeeps compute and MES out; CPF alone leaves the stream stuck. */
+ cntl =RREG32_SOC15(GC, 0, regCP_SOFT_RESET_CNTL); + tmp =REG_SET_FIELD(cntl, CP_SOFT_RESET_CNTL, GFX_ONLY_SOFT_RESET, 1);
+ tmp =REG_SET_FIELD(tmp, CP_SOFT_RESET_CNTL, GFX_HQD_REG_RESET, 1);
+WREG32_SOC15(GC, 0, regCP_SOFT_RESET_CNTL, tmp); +
+ tmp =RREG32_SOC15(GC, 0, regGRBM_SOFT_RESET);
+ tmp =REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF, 1);
+ tmp = REG_SET_FIELD(tmp,GRBM_SOFT_RESET,SOFT_RESET_CPG,Quoted 8 lines
Quoted 1 line
1);
I just tested this on Strix Halo (GFX11.5).
We need to set theSOFT_RESET_GFXbit here in order to reset the fixed-
function graphics pipeline. Otherwise this can't recover from cases when the
fixed-function pipeline hangs, for example a buggy NGG shader.
Quoted 4 lines
The case I tested was a bad-length (oversize) packet hang in the CP. CPF/CPG reset
alone recovers it. AddingSOFT_RESET_GFXalso brings the gfx CP back, but then SDMA times out and recovery escalates to MODE1.
I tested this on Strix Halo, and I didn't see an issue with SDMA. Which GPU did you test on and how did you reproduce this?
I don't see any reason why SOFT_RESET_GFX would affect the SDMA. As far as I know the SDMA would be the SOFT_RESET_SDMA0/1 bits. Could you explain more what is happening?
Is there a different alternative besides SOFT_RESET_GFX to reset the fixed-function graphics pipeline?
Quoted 7 lines
This suggests that the current sequence needs additional recovery work
whenSOFT_RESET_GFXis included. It doesn't establish how your NGG case
should be handled. Could we keep the CP-only reset or gpu reset for the buggy NGG
recovers, and use a broader reset if that recovery fails?
The GFX engine reset should be able to recover from any errors that can happen on graphics. If that is not possible, we can discuss what is a good alternative.
I think first we need to understand why the SDMA was affected in your testing (and see we can fix it), then we can come back to this question.
Quoted 36 lines
Quoted 27 lines
Quoted 4 lines
+
WREG32_SOC15(GC, 0, regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15(GC, 0, regGRBM_SOFT_RESET);This line should be moved below the delay.
Quoted 20 lines
+ udelay(50);
+ tmp =REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF, 0);
+ tmp =REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPG, 0);
+WREG32_SOC15(GC, 0, regGRBM_SOFT_RESET, tmp);
+ tmp =RREG32_SOC15(GC, 0, regGRBM_SOFT_RESET);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0+ + WREG32_SOC15(GC, 0, regCP_SOFT_RESET_CNTL, cntl); + + /* The halted PFP stays busy: only wait for the memoryrequests. */
+ for (i = 0; i <adev->usec_timeout; i++) {
+ if (!(RREG32_SOC15(GC, 0,regCP_STAT) &GFX11_CP_STAT_MEM_BUSY))
+ break;
+ udelay(1);
+ }
+ /* A VMID reset the hung PFP didn't handle survives the reset. */Quoted 8 lines
Quoted 1 line
+
WREG32_SOC15(GC, 0, regCP_VMID_RESET, 0);Does this introduce a race condition between per-queue resets and the soft
reset? I mean, what happens if we are doing a queue reset on a compute
queue at the same time while this function is resetting the GFX engine?
Quoted 8 lines
They don't run at the same time: the engine reset holds gfx.mec.reset_mutex, like
amdgpu_gfx_reset_mes_compute()andamdgpu_gfx_reset_mes_gfx()do, and the single MES/MMIO queue resets (amdgpu_mes_reset_legacy_queue(),amdgpu_mes_reset_queue_mmio()) take the
MES lock, which is held across the pulse.GFX_ONLY_SOFT_RESETalso keeps
the compute HQDs out of the pulse.
Sounds good. Thanks for the explanation.
Quoted 100 lines
Jesse
Quoted 98 lines
Quoted 98 lines
+
amdgpu_mes_unlock(&adev->mes);
+
+ tmp =RREG32_SOC15(GC, 0, regCP_ME_CNTL);
+ tmp = REG_SET_FIELD(tmp,CP_ME_CNTL,CE_HALT,
+REG_GET_FIELD(me_cntl, CP_ME_CNTL, CE_HALT));
+WREG32_SOC15(GC, 0, regCP_ME_CNTL, tmp);
+amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
+
+ /*
+ * Boot withCP_PFP_IB_CONTROLcleared: set, it makes the F32 PFP resume
+ * from power gating and wait for a clear state that never comes.
+ */
+ tmp =RREG32_SOC15(GC, 0, regCP_ME_CNTL);
+ tmp =REG_SET_FIELD(tmp, CP_ME_CNTL, ME_HALT, 0); + tmp =REG_SET_FIELD(tmp, CP_ME_CNTL, PFP_HALT, 0); +WREG32_SOC15(GC, 0, regCP_ME_CNTL, tmp);
+ for (i = 0; i <adev->usec_timeout; i++) {
+ if (!RREG32_SOC15(GC, 0,regCP_STAT))
+ break;
+ udelay(1);
+ }
+WREG32_SOC15(GC, 0, regCP_PFP_IB_CONTROL, ib_control);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0+ + return i < adev->usec_timeout ? 0 : -ETIMEDOUT; } + +static int gfx_v11_0_soft_reset_engine(struct amdgpu_ip_block
*ip_block,
+ enumamdgpu_ring_typering_type,
+ structamdgpu_usermode_queue*guilty_queue)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +11
-0+{ + struct amdgpu_device *adev = ip_block->adev; + int i, r; + + if (ring_type != AMDGPU_RING_TYPE_GFX) + return -EOPNOTSUPP; + + mutex_lock(&adev->gfx.mec.reset_mutex); + amdgpu_gfx_off_ctrl(adev, false); + + /* A hung gfx stream can keep MES from suspending: resetanyway. */
+amdgpu_mes_suspend(adev, 0);
+amdgpu_userq_save_hqds(adev, AMDGPU_HW_IP_GFX);
+
+ r =gfx_v11_0_soft_reset_gfx_cp(adev);
+ if (r) {
+ dev_err(adev->dev, "gfx CP still busy after reset,CP_STAT0x%08x\n",
+RREG32_SOC15(GC, 0, regCP_STAT)); + goto fail;
+ }
+
+ /* The reset cleared the HQD of the kernel gfx queue: map it again. */
+ r =amdgpu_gfx_disable_kgq(adev, 0);
+ if (r)
+ goto fail;
+ for (i = 0; i <adev->gfx.num_gfx_rings; i++)
+ amdgpu_gfx_mqd_reset_restore(&adev-Quoted 1 line
gfx.gfx_ring[i]);
+ r =
amdgpu_gfx_enable_kgq(adev, 0);
+ if (!r)
+ r =gfx_v11_0_cp_gfx_start(adev); + if (r)
+ goto fail;
+
+amdgpu_userq_restore_hqds(adev, AMDGPU_HW_IP_GFX, guilty_queue);
+ r =amdgpu_mes_resume(adev, 0);
+ goto out;drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+ +fail: + amdgpu_userq_clear_hqds(adev, AMDGPU_HW_IP_GFX); + amdgpu_mes_resume(adev, 0); +out: + amdgpu_gfx_off_ctrl(adev, true); + mutex_unlock(&adev->gfx.mec.reset_mutex); + return r; +} +#define GFX11_HPD_QUEUE_STATE_CONNECTED_MIN 3 #define GFX11_HPD_QUEUE_STATE_CONNECTED_MAX 15
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0@@ -7045,6 +7178,7 @@ static const struct amd_ip_funcs gfx_v11_0_ip_funcs = { .suspend = gfx_v11_0_suspend, .resume = gfx_v11_0_resume, .wait_for_idle = gfx_v11_0_wait_for_idle, + .soft_reset_engine = gfx_v11_0_soft_reset_engine, .soft_reset = gfx_v11_0_soft_reset, .set_clockgating_state = gfx_v11_0_set_clockgating_state,.set_powergating_state =
gfx_v11_0_set_powergating_state,
RE: [PATCH v4 10/13] drm/amdgpu/gfx11: add a gfx engine soft reset
AMD General
Quoted 140 lines
-----Original Message-----
From: Timur Kristóf <[email protected]>
Sent: Monday, November 23, 2026 6:21 PM
To: Zhang, Jesse(Jie) <[email protected]>; amd- [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Mario Sopena-Novales <[email protected]>; Rastogi, Manu <[email protected]>; Zhu, Jiongyu (Joey) <[email protected]>
Subject: Re: [PATCH v4 10/13] drm/amdgpu/gfx11: add a gfx engine soft resetQuoted 10 lines · Jesse(Jie)
AMD General
Quoted 8 lines
-----Original Message-----
From: Timur Kristóf <[email protected]>
Sent: Thursday, November 19, 2026 7:47 PM
To: Zhang, Jesse(Jie) <[email protected]>; amd- [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Mario Sopena-NovalesQuoted 32 lines
Quoted 32 lines
Rastogi, Manu <[email protected]>; Zhu, Jiongyu (Joey) <[email protected]>
Subject: Re: [PATCH v4 10/13] drm/amdgpu/gfx11: add a gfx engine soft resetQuoted 26 lines · Jesse Zhang
Implement
soft_reset_engine()for the graphics engine of gfx11, as for gfx12, with two differences:
- clearCP_VMID_RESET: a VMID reset the hung PFP didn't handle survives
the CPF/CPG reset;
- boot PFP/ME withCP_PFP_IB_CONTROLcleared and restore it afterwards:
set, it makes the F32 PFP of the APUs resume from power gating
and wait
for a clear state that never comes.The CPF/CPG reset already puts PFP/ME back at their firmware start address, so unhalting them restarts the RS64 and F32 firmware alike.
v4: Implement
soft_reset_engine()directly instead of areset_enginegfx
callback, dropgfx_v11_0_restart_gfx_rs64(), and boot withCP_PFP_IB_CONTROLcleared for the F32 firmware (Timur).Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 134 +++++++++++++++++++++++++ 1 file changed, 134 insertions(+)Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static void
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -6777,6 +6777,139 @@ static voidgfx_v11_0_emit_mem_sync(struct
Quoted 26 lines
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static void · line 6783
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0amdgpu_ring *ring)amdgpu_ring_write (ring ,gcr_cntl );/* GCR_CNTL */ } +/* The CP DMA and the interfaces its memory requests go through */ +#define GFX11_CP_STAT_MEM_BUSY (CP_STAT__DMA_BUSY_MASK | \Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+CP_STAT__TCIU_BUSY_MASK | \ +CP_STAT__RCIU_BUSY_MASK | \ + CP_STAT__UTCL2IU_BUSY_MASK) + +/* Reset CPF/CPG, PFP/ME and the gfx HQDs, then boot PFP/ME again.
*/
+static intgfx_v11_0_soft_reset_gfx_cp(struct amdgpu_device *adev){
+ u32 tmp, cntl,me_cntl,ib_control;Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0+int i; + +amdgpu_gfx_rlc_enter_safe_mode (adev,0 ); +/* MES fetches its queues through CPF: keep it out of the reset. */
+amdgpu_mes_lock(&adev->mes);I wonder if we should lock the SRBM mutex here. What do you think?
Quoted 5 lines
I don't think it's needed: none of the registers written here are banked by
GRBM_GFX_CNTL(CP_ME_CNTL,CP_SOFT_RESET_CNTL,GRBM_SOFT_RESET,CP_STAT,CP_VMID_RESET). If we take it anyway, it must come after the MES lock, asmes_v11_0_reset_queue_mmio()takessrbm_mutexwith the MES lock held.I see. That sounds OK to me, then.
Quoted 44 lines
Quoted 43 lines
Quoted 33 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3
-0+ + me_cntl =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + ib_control = RREG32_SOC15(GC, 0,
regCP_PFP_IB_CONTROL); /* cleared by the reset */drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +7
-0+ + tmp =REG_SET_FIELD (me_cntl,CP_ME_CNTL ,ME_HALT ,1 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,1 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +udelay (50 ); + +/* A CP DMA in flight during the reset leaves the ME busy after it. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+for (i =0 ; i < adev->usec_timeout; i++) { + if (!(RREG32_SOC15(GC, 0, regCP_STAT) &
GFX11_CP_STAT_MEM_BUSY))drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+break ; +udelay (1 ); + } + +/* GFX_ONLY keeps compute and MES out; CPF alone leaves the stream stuck. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+ cntl =RREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL); + tmp = REG_SET_FIELD(cntl, CP_SOFT_RESET_CNTL,
GFX_ONLY_SOFT_RESET, 1);
+ tmp = REG_SET_FIELD(tmp,CP_SOFT_RESET_CNTL,GFX_HQD_REG_RESET, 1);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0+WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, tmp); + + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF,Quoted 3 lines
1);
+ tmp = REG_SET_FIELD(tmp,GRBM_SOFT_RESET,SOFT_RESET_CPG,
1);I just tested this on Strix Halo (GFX11.5).
We need to set theSOFT_RESET_GFXbit here in order to reset the fixed-
function graphics pipeline. Otherwise this can't recover from cases when the fixed-function pipeline hangs, for example a buggy NGG shader.
Quoted 8 lines
Quoted 4 lines
The case I tested was a bad-length (oversize) packet hang in the CP. CPF/CPG reset
alone recovers it. AddingSOFT_RESET_GFXalso brings the gfx CP back, but then SDMA times out and recovery escalates to MODE1.I tested this on Strix Halo, and I didn't see an issue with SDMA. Which GPU did you test on and how did you reproduce this?
Navi48 and Navi31. The reproducer is IGT amd_queue_reset amdgpu-GFX-CMD_STREAM_EXEC_INVALID_PACKET_LENGTH_OVERSIZE: the queue reset fails on it and the engine reset recovers it. A HIP stress test runs on the KFD side at the same time.
Quoted 4 lines
I don't see any reason why
SOFT_RESET_GFXwould affect the SDMA. As far as I know the SDMA would be the SOFT_RESET_SDMA0/1 bits. Could you explain more what is happening?
My guess is that the reset drops requests in flight in the blocks it resets, which other clients then wait for, but I can't confirm it without the hardware documentation. Will check this with CP team.
Quoted 3 lines
Is there a different alternative besides
SOFT_RESET_GFXto reset the fixed- function graphics pipeline?
Not in GRBM_SOFT_RESET as far as I can see.
Quoted 10 lines
Quoted 6 lines
This suggests that the current sequence needs additional recovery work when
SOFT_RESET_GFXis included. It doesn't establish how your NGG case should be handled. Could we keep the CP-only reset or gpu reset for the buggy NGG recovers, and use a broader reset if that recovery fails?The GFX engine reset should be able to recover from any errors that can happen on graphics. If that is not possible, we can discuss what is a good alternative.
Agreed that this is the goal.
Quoted 148 lines
I think first we need to understand why the SDMA was affected in your testing (and see we can fix it), then we can come back to this question.
Quoted 34 lines
Quoted 25 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET);This line should be moved below the delay.
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+udelay (50 ); + tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF,0);
+ tmp = REG_SET_FIELD(tmp,GRBM_SOFT_RESET,SOFT_RESET_CPG,
0);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6
-0+WREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET, tmp); + tmp =RREG32_SOC15 (GC ,0 , regGRBM_SOFT_RESET); + +WREG32_SOC15 (GC ,0 , regCP_SOFT_RESET_CNTL, cntl); + +/* The halted PFP stays busy: only wait for the memory requests. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0+for (i =0 ; i < adev->usec_timeout; i++) { + if (!(RREG32_SOC15(GC, 0, regCP_STAT) &
GFX11_CP_STAT_MEM_BUSY))drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3
-0+break ; +udelay (1 ); + }Quoted 8 lines
Quoted 3 lines
+ /* A VMID reset the hung PFP didn't handle survives the
reset. */
+WREG32_SOC15(GC, 0, regCP_VMID_RESET, 0);Does this introduce a race condition between per-queue resets and the soft reset? I mean, what happens if we are doing a queue reset on a compute queue at the same time while this function is resetting the GFX engine?
Quoted 4 lines
They don't run at the same time: the engine reset holds gfx.mec.reset_mutex, like
amdgpu_gfx_reset_mes_compute()andamdgpu_gfx_reset_mes_gfx()do, and the single MES/MMIO queue resets (amdgpu_mes_reset_legacy_queue(),amdgpu_mes_reset_queue_mmio())take
Quoted 2 lines
the MES lock, which is held across the pulse.
GFX_ONLY_SOFT_RESETalso keeps the compute HQDs out of the pulse.Sounds good. Thanks for the explanation.
Quoted 100 lines
Jesse
Quoted 98 lines
Quoted 98 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+amdgpu_mes_unlock (&adev->mes); + + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT, + REG_GET_FIELD(me_cntl, CP_ME_CNTL,
CE_HALT));drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +amdgpu_gfx_rlc_exit_safe_mode (adev,0 ); + +/* +* Boot with CP_PFP_IB_CONTROL cleared: set, it makes the F32 PFP resume
+ * from power gating and wait for a clear state that never
comes.drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +15
-0+*/ + tmp =RREG32_SOC15 (GC ,0 , regCP_ME_CNTL); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,ME_HALT ,0 ); + tmp =REG_SET_FIELD (tmp,CP_ME_CNTL ,PFP_HALT ,0 ); +WREG32_SOC15 (GC ,0 , regCP_ME_CNTL, tmp); +for (i =0 ; i < adev->usec_timeout; i++) { +if (!RREG32_SOC15 (GC ,0 , regCP_STAT)) +break ; +udelay (1 ); + } +WREG32_SOC15 (GC ,0 , regCP_PFP_IB_CONTROL, ib_control); + +return i < adev->usec_timeout ?0 : -ETIMEDOUT ; } + +static int gfx_v11_0_soft_reset_engine(struct amdgpu_ip_block
*ip_block,
+ enumamdgpu_ring_typering_type,
+ structamdgpu_usermode_queue*guilty_queue)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +11
-0+{ +struct amdgpu_device *adev = ip_block->adev; +int i, r; + +if (ring_type !=AMDGPU_RING_TYPE_GFX ) +return -EOPNOTSUPP ; + +mutex_lock (&adev->gfx.mec.reset_mutex); +amdgpu_gfx_off_ctrl (adev, false); + +/* A hung gfx stream can keep MES from suspending: reset anyway. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6
-0+amdgpu_mes_suspend (adev,0 ); +amdgpu_userq_save_hqds (adev,AMDGPU_HW_IP_GFX ); + + r =gfx_v11_0_soft_reset_gfx_cp (adev); +if (r) { + dev_err(adev->dev, "gfx CP still busy after reset,
CP_STAT0x%08x\n",drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+ RREG32_SOC15(GC, 0, regCP_STAT)); + goto fail; + } + +/* The reset cleared the HQD of the kernel gfx queue: map it again. */
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5
-0+ r =amdgpu_gfx_disable_kgq (adev,0 ); +if (r) + goto fail; +for (i =0 ; i < adev->gfx.num_gfx_rings; i++) + amdgpu_gfx_mqd_reset_restore(&adev-Quoted 1 line
gfx.gfx_ring[i]);
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +7
-0+ r =amdgpu_gfx_enable_kgq (adev,0 ); +if (!r) + r =gfx_v11_0_cp_gfx_start (adev); +if (r) + goto fail; + + amdgpu_userq_restore_hqds(adev, AMDGPU_HW_IP_GFX,
guilty_queue);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +13
-0+ r =amdgpu_mes_resume (adev,0 ); + goto out; + +fail: +amdgpu_userq_clear_hqds (adev,AMDGPU_HW_IP_GFX ); +amdgpu_mes_resume (adev,0 ); +out: +amdgpu_gfx_off_ctrl (adev, true); +mutex_unlock (&adev->gfx.mec.reset_mutex); +return r; +} +#define GFX11_HPD_QUEUE_STATE_CONNECTED_MIN 3#define GFX11_HPD_QUEUE_STATE_CONNECTED_MAX 15@@ -7045,6 +7178,7 @@ static const struct amd_ip_funcs gfx_v11_0_ip_funcs = { .suspend = gfx_v11_0_suspend, .resume = gfx_v11_0_resume, .wait_for_idle = gfx_v11_0_wait_for_idle, + .soft_reset_engine = gfx_v11_0_soft_reset_engine, .soft_reset = gfx_v11_0_soft_reset, .set_clockgating_state = gfx_v11_0_set_clockgating_state,.set_powergating_state =
gfx_v11_0_set_powergating_state,
PATCH v4 11/13 drm/amdgpu/userq: reset the gfx engine when a gfx user queue reset fails
In reply to Jesse ZhangWhen neither the queue nor the pipe reset recovered a gfx user queue, fall back to a soft reset of the gfx engine before a full reset, when the GFX IP supports it. A hung kernel gfx queue gets there through the IP block soft reset of the job timeout handler; a user queue has no kernel ring, so call amdgpu_device_ip_soft_reset() directly, with the gfx ring type and no guilty ring.
The hung queue can't be unmapped before the reset: pass it to the engine reset, which unmaps it once the reset cleared its HQD, and hangs it, while the other gfx user queues keep their state.
v4: Call amdgpu_device_ip_soft_reset(), which now takes the ring type
(Timur).
--- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 27 +++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +24 -3
@@ -235,11 +235,25 @@ int mes_userq_reset_hw(struct amdgpu_usermode_queue *queue,return 0 ; } +/* The hung queue can't be unmapped now: the engine reset unmaps it after. */ +static int mes_userq_reset_gfx_engine (struct amdgpu_usermode_queue *queue) +{ +return amdgpu_device_ip_soft_reset (queue->userq_mgr->adev, +AMDGPU_RING_TYPE_GFX ,NULL ,NULL , queue); +} + +static bool mes_userq_gfx_engine_reset_supported (struct amdgpu_device *adev) +{ +return adev->gfx.gfx_supported_reset & +AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET ; +} +int mes_userq_reset (struct amdgpu_usermode_queue *queue) {struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr;struct amdgpu_device *adev = uq_mgr->adev;struct mes_reset_queue_input queue_input; +int r;/* already reset by an earlier job's hang-detect; just signal and bail */ if (queue->state ==AMDGPU_USERQ_STATE_HUNG )
@@ -248,8 +262,10 @@ int mes_userq_reset(struct amdgpu_usermode_queue *queue)/* A GFX pipe reset also affects the kernel rings on that pipe. */ if (queue->queue_type ==AMDGPU_HW_IP_GFX && adev->gfx.funcs->detect_hung_queue && -amdgpu_gfx_me_pipe_reset_supported (adev)) -return amdgpu_gfx_reset_mes_gfx (adev,NULL ,NULL , queue,0 , true); +amdgpu_gfx_me_pipe_reset_supported (adev)) { + r =amdgpu_gfx_reset_mes_gfx (adev,NULL ,NULL , queue,0 , true); + goto out; + }memset (&queue_input,0x0 ,sizeof (struct mes_reset_queue_input )); queue_input.doorbell_offset = queue->doorbell_index;
@@ -277,7 +293,12 @@ int mes_userq_reset(struct amdgpu_usermode_queue *queue) } } -return mes_userq_reset_hw (queue, &queue_input); + r =mes_userq_reset_hw (queue, &queue_input); +out: +if (r && queue->queue_type ==AMDGPU_HW_IP_GFX && +mes_userq_gfx_engine_reset_supported (adev)) + r =mes_userq_reset_gfx_engine (queue); +return r; } int mes_userq_reset_queue(struct amdgpu_device *adev,
Signature · 1 line
2.50.1
Re: [PATCH v4 11/13] drm/amdgpu/userq: reset the gfx engine when a gfx user queue reset fails
Quoted 13 lines · Jesse Zhang
When neither the queue nor the pipe reset recovered a gfx user queue, fall back to a soft reset of the gfx engine before a full reset, when the GFX IP supports it. A hung kernel gfx queue gets there through the
IP block soft reset of the job timeout handler; a user queue has no kernel ring, so callamdgpu_device_ip_soft_reset()directly, with the gfx ring type and no guilty ring.The hung queue can't be unmapped before the reset: pass it to the engine
reset, which unmaps it once the reset cleared its HQD, and hangs it, while the other gfx user queues keep their state.
Quoted 4 lines
v4: Call
amdgpu_device_ip_soft_reset(), which now takes the ring type (Timur).Signed-off-by Jesse Zhang <[email protected]>
Quoted 75 lines
---
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 27 +++++++++++++++++++- --1 file changed, 24 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0
-0@@ -235,11 +235,25 @@ int mes_userq_reset_hw(struct amdgpu_usermode_queue *queue, return 0; }
+/* The hung queue can't be unmapped now: the engine reset unmaps it after. */
+static intmes_userq_reset_gfx_engine(struct amdgpu_usermode_queue *queue)drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +3
-0+{ + return amdgpu_device_ip_soft_reset(queue->userq_mgr->adev, + AMDGPU_RING_TYPE_GFX,NULL, NULL, queue);
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +3
-0+} + +static bool mes_userq_gfx_engine_reset_supported(struct
amdgpu_device*adev)drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +5
-0+{ +return adev->gfx.gfx_supported_reset & + AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET; +} +int
mes_userq_reset(struct amdgpu_usermode_queue *queue){
structamdgpu_userq_mgr*uq_mgr=queue->userq_mgr; structamdgpu_device*adev =uq_mgr->adev; structmes_reset_queue_inputqueue_input;drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1
-0+int r;
/* already reset by an earlier job's hang-detect; just signal and bail */
if (queue->state==AMDGPU_USERQ_STATE_HUNG)drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0
-0@@ -248,8 +262,10 @@ int mes_userq_reset(struct amdgpu_usermode_queue *queue) /* A GFX pipe reset also affects the kernel rings on thatpipe. */
if (queue->queue_type==AMDGPU_HW_IP_GFX&&adev->gfx.funcs->detect_hung_queue&&drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0
-2- amdgpu_gfx_me_pipe_reset_supported(adev)) - return amdgpu_gfx_reset_mes_gfx(adev, NULL, NULL,queue, 0, true);
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2
-0+ amdgpu_gfx_me_pipe_reset_supported(adev)) { + r = amdgpu_gfx_reset_mes_gfx(adev, NULL, NULL,queue, 0, true);
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2
-0+ goto out; + }
memset(&queue_input, 0x0, sizeof(struct mes_reset_queue_input)); queue_input.doorbell_offset =queue->doorbell_index;drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0
-0@@ -277,7 +293,12 @@ int mes_userq_reset(struct amdgpu_usermode_queue *queue) } }drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +6
-1-return mes_userq_reset_hw (queue, &queue_input); + r =mes_userq_reset_hw (queue, &queue_input); +out: +if (r && queue->queue_type ==AMDGPU_HW_IP_GFX && + mes_userq_gfx_engine_reset_supported(adev)) + r =mes_userq_reset_gfx_engine (queue); +return r;}
int mes_userq_reset_queue(structamdgpu_device*adev,
PATCH v4 12/13 drm/amdgpu/gfx12: enable the gfx engine soft reset
In reply to Jesse ZhangReport AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET for the gfx rings with MES, which the reset uses to map the kernel gfx queue again. Not on SR-IOV VFs.
The kernel gfx queue and gfx user queue resets then fall back to a soft reset of the gfx engine before a full reset.
v4: The soft_reset_engine() callback is set by the patch that adds it.
No async gfx ring check: they are always used now.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +5 -0
@@ -1593,6 +1593,11 @@ static int gfx_v12_0_sw_init(struct amdgpu_ip_block *ip_block)break ; } +/* The reset remaps the kernel gfx queue through MES. */ +if (!amdgpu_sriov_vf (adev) && adev->enable_mes && + !adev->debug_disable_ip_block_soft_reset) + adev->gfx.gfx_supported_reset |=AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET ; +if (!adev->enable_mes_kiq) { r =amdgpu_gfx_kiq_init (adev,GFX12_MEC_HPD_SIZE ,0 );if (r) {
Signature · 1 line
2.50.1
Re: [PATCH v4 12/13] drm/amdgpu/gfx12: enable the gfx engine soft reset
Quoted 9 lines · Jesse Zhang
Report
AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESETfor the gfx rings with MES,
which the reset uses to map the kernel gfx queue again. Not on SR-IOV VFs.The kernel gfx queue and gfx user queue resets then fall back to a soft
reset of the gfx engine before a full reset.
Quoted 5 lines
v4: The
soft_reset_engine()callback is set by the patch that adds it.
No async gfx ring check: they are always used now.Signed-off-by Jesse Zhang <[email protected]>
Quoted 24 lines
---
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 5 +++++1 file changed, 5 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +0
-0@@ -1593,6 +1593,11 @@ static int gfx_v12_0_sw_init(struct amdgpu_ip_block *ip_block) break; }drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4
-0+/* The reset remaps the kernel gfx queue through MES. */ +if (!amdgpu_sriov_vf (adev) && adev->enable_mes && + !adev->debug_disable_ip_block_soft_reset) + adev->gfx.gfx_supported_reset |=
AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET;
+
if (!adev->enable_mes_kiq) {
r =amdgpu_gfx_kiq_init(adev, GFX12_MEC_HPD_SIZE, 0);
if (r) {
PATCH v4 13/13 drm/amdgpu/gfx11: enable the gfx engine soft reset
In reply to Jesse ZhangReport AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET for the gfx rings with MES, which the reset uses to map the kernel gfx queue again. Not on SR-IOV VFs.
The kernel gfx queue and gfx user queue resets then fall back to a soft reset of the gfx engine before a full reset. The IP block soft reset of gfx11 only resets the gfx engine then; the whole IP block soft_reset() isn't used.
v4: Not limited to the RS64 firmware anymore, the reset restarts the F32
PFP and ME of the APUs too (Timur). The soft_reset_engine() callback is set by the patch that adds it. No async gfx ring check: they are always used now.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5 -0
@@ -1941,6 +1941,11 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block)break ; } +/* The reset remaps the kernel gfx queue through MES. */ +if (!amdgpu_sriov_vf (adev) && adev->enable_mes && + !adev->debug_disable_ip_block_soft_reset) + adev->gfx.gfx_supported_reset |=AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET ; +if (!adev->enable_mes_kiq) { r =amdgpu_gfx_kiq_init (adev,GFX11_MEC_HPD_SIZE ,0 );if (r) {
Signature · 1 line
2.50.1
Re: [PATCH v4 13/13] drm/amdgpu/gfx11: enable the gfx engine soft reset
Quoted 21 lines · Jesse Zhang
Report
AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESETfor the gfx rings with MES,
which the reset uses to map the kernel gfx queue again. Not on SR-IOV VFs.The kernel gfx queue and gfx user queue resets then fall back to a soft
reset of the gfx engine before a full reset. The IP block soft reset of
gfx11 only resets the gfx engine then; the whole IP blocksoft_reset()
isn't used.v4: Not limited to the RS64 firmware anymore, the reset restarts the F32
PFP and ME of the APUs too (Timur). Thesoft_reset_engine()callback
is set by the patch that adds it. No async gfx ring check: they are
always used now.
Quoted 1 line
Signed-off-by Jesse Zhang <[email protected]>
Quoted 24 lines
---
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 5 +++++1 file changed, 5 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -1941,6 +1941,11 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block) break; }drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0+/* The reset remaps the kernel gfx queue through MES. */ +if (!amdgpu_sriov_vf (adev) && adev->enable_mes && + !adev->debug_disable_ip_block_soft_reset) + adev->gfx.gfx_supported_reset |=
AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET;
+
if (!adev->enable_mes_kiq) {
r =amdgpu_gfx_kiq_init(adev, GFX11_MEC_HPD_SIZE, 0);
if (r) {
AMD General
Ping on the series
Quoted 130 lines
-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Thursday, November 5, 2026 11:06 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; [email protected]; Mario Sopena-Novales <[email protected]>; Rastogi, Manu <[email protected]>; Zhu, Jiongyu (Joey) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH v4 01/13] drm/amdgpu: pass the device to the multi ring reset helpers
amdgpu_multi_ring_reset_helper_begin()and_end()take the device from the guilty ring. A reset triggered by a hung user queue has no guilty kernel ring, so pass the device explicitly and allow a NULL guilty ring.No functional change.
Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 14 ++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 6 ++++-- 3 files changed, 14 insertions(+), 10 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +4
-2@@ -465,11 +465,11 @@ int amdgpu_device_ip_soft_reset(structamdgpu_ring *guilty_ring, ring_type_mask =amdgpu_ring_mask_from_ip (ip_type);amdgpu_device_lock_reset_domain (adev->reset_domain); -amdgpu_multi_ring_reset_helper_begin (ring_type_mask, guilty_ring, guilty_fence); +amdgpu_multi_ring_reset_helper_begin (adev, ring_type_mask, +guilty_ring, guilty_fence); r = ip_block->version->funcs->soft_reset (ip_block); - r =amdgpu_multi_ring_reset_helper_end (ring_type_mask, guilty_ring, r); + r =amdgpu_multi_ring_reset_helper_end (adev, ring_type_mask, +guilty_ring, r);amdgpu_device_unlock_reset_domain (adev->reset_domain);if (r) {drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -919,8 +919,9 @@ int amdgpu_ring_reset_helper_end(struct amdgpu_ring *ring,/** * amdgpu_multi_ring_reset_helper_begin() - Prepare multiple rings for a reset.
*
+ * @adev: amdgpu device
* @ring_type_mask: Bitmask of affected ring types
- * @guilty_ring: The ring which is guilty of causing a reset.
+ * @guilty_ring: The ring which is guilty of causing a reset, or NULL.
* @guilty_fence: The fence which didn't signal on the guilty ring. *
* Useful when performing a GPU reset method that affects @@ -938,11
+939,11 @@ int amdgpu_ring_reset_helper_end(structamdgpu_ring*ring,
* After the reset is complete, the caller should then call
*amdgpu_multi_ring_reset_helper_end()to restore the rings. */drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +2
-1-void amdgpu_multi_ring_reset_helper_begin (const u32 ring_type_mask, +void amdgpu_multi_ring_reset_helper_begin (struct amdgpu_device *adev, +const u32 ring_type_mask,struct amdgpu_ring *guilty_ring,struct amdgpu_fence *guilty_fence){
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +2
-2-struct amdgpu_device *adev = guilty_ring->adev;struct amdgpu_fence *ring_guilty_fence;struct amdgpu_ring *ring;bool rings_busy;@@ -1034,8 +1035,9 @@ void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask,/** * amdgpu_multi_ring_reset_helper_end() - Prepare multiple rings for a reset. * +* @adev: amdgpu device * @ring_type_mask: Bitmask of affected ring types -* @guilty_ring: The ring which is guilty of causing a reset. +* @guilty_ring: The ring which is guilty of causing a reset, or NULL. * @ret: Return code from the reset function. * * After calling
amdgpu_multi_ring_reset_helper_begin()drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +2
-2@@ -1046,10 +1048,10 @@ voidamdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask, * be called to restore preemption state, but it won't attempt to * fully restore the ring contents. */ -int amdgpu_multi_ring_reset_helper_end (const u32 ring_type_mask, +int amdgpu_multi_ring_reset_helper_end (struct amdgpu_device *adev, +const u32 ring_type_mask,struct amdgpu_ring *guilty_ring,int ret) { -struct amdgpu_device *adev = guilty_ring->adev;struct amdgpu_ring *ring;int i, r;drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +4
-1@@ -637,10 +637,12 @@ void amdgpu_ring_reset_helper_begin(structamdgpu_ring *ring, struct amdgpu_fence *guilty_fence); intamdgpu_ring_reset_helper_end (struct amdgpu_ring *ring, struct amdgpu_fence *guilty_fence); -void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask, +void amdgpu_multi_ring_reset_helper_begin(struct amdgpu_device *adev, +const u32 ring_type_mask,struct amdgpu_ring *guilty_ring,struct amdgpu_fence *guilty_fence); -int amdgpu_multi_ring_reset_helper_end (const u32 ring_type_mask, +int amdgpu_multi_ring_reset_helper_end (struct amdgpu_device *adev, +const u32 ring_type_mask,struct amdgpu_ring *guilty_ring,int ret);bool amdgpu_ring_is_reset_type_supported(struct
amdgpu_ring*ring,u32 reset_type);--
2.50.1
Quoted 3 lines · Jesse(Jie)
AMD General
Ping on the series
Hi Jesse,
I apologize for the late reply. I'm reviewing the new version too, just need some time to finish my review.
Best regards,
Timur
Quoted 154 lines
Quoted 154 lines
-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Thursday, November 5, 2026 11:06 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian
<[email protected]>; Lazar, Lijo <[email protected]>; [email protected]; Mario Sopena-Novales <[email protected]>; Rastogi, Manu <[email protected]>; Zhu, Jiongyu (Joey) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH v4 01/13] drm/amdgpu: pass the device to the multi ring
reset helpers
amdgpu_multi_ring_reset_helper_begin()and_end()take the device from the
guilty ring. A reset triggered by a hung user queue has no guilty kernel ring, so
pass the device explicitly and allow a NULL guilty ring.No functional change.
Signed-off-by Jesse Zhang <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c | 4 ++--drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c| 14 ++++++++------drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h| 6 ++++--3 files changed, 14 insertions(+), 10 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +2
-2@@ -465,11 +465,11 @@ int amdgpu_device_ip_soft_reset(structamdgpu_ring *guilty_ring, ring_type_mask = amdgpu_ring_mask_from_ip(ip_type); amdgpu_device_lock_reset_domain(adev->reset_domain); - amdgpu_multi_ring_reset_helper_begin(ring_type_mask, guilty_ring, guilty_fence); + amdgpu_multi_ring_reset_helper_begin(adev, ring_type_mask, +guilty_ring, guilty_fence); r = ip_block->version->funcs->soft_reset(ip_block); - r = amdgpu_multi_ring_reset_helper_end(ring_type_mask,
guilty_ring, r);
+ r =amdgpu_multi_ring_reset_helper_end(adev, ring_type_mask, +guilty_ring, r);amdgpu_device_unlock_reset_domain(adev->reset_domain);if (r) {
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -919,8 +919,9 @@ int amdgpu_ring_reset_helper_end(struct amdgpu_ring *ring, /*** amdgpu_multi_ring_reset_helper_begin() - Prepare multiple rings for a
reset.
*
+ * @adev: amdgpu device
* @ring_type_mask: Bitmask of affected ring types
- * @guilty_ring: The ring which is guilty of causing a reset.
+ * @guilty_ring: The ring which is guilty of causing a reset, or NULL.
* @guilty_fence: The fence which didn't signal on the guilty ring.
*
* Useful when performing a GPU reset method that affects @@ - 938,11
+939,11 @@ int amdgpu_ring_reset_helper_end(structamdgpu_ring*ring,
* After the reset is complete, the caller should then call
*amdgpu_multi_ring_reset_helper_end()to restore the rings. */
-void amdgpu_multi_ring_reset_helper_begin(const u32ring_type_mask,
+void amdgpu_multi_ring_reset_helper_begin(structamdgpu_device*adev,
+ const u32ring_type_mask, structamdgpu_ring*guilty_ring,
structamdgpu_fence*guilty_fence)
{
- structamdgpu_device*adev =guilty_ring->adev; structamdgpu_fence*ring_guilty_fence;
structamdgpu_ring*ring;
boolrings_busy;drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -1034,8 +1035,9 @@ void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask, /*** amdgpu_multi_ring_reset_helper_end() - Prepare multiple rings for a reset.
*
+ * @adev: amdgpu device
* @ring_type_mask: Bitmask of affected ring types
- * @guilty_ring: The ring which is guilty of causing a reset.
+ * @guilty_ring: The ring which is guilty of causing a reset, or NULL.
* @ret: Return code from the reset function.
*
* After callingamdgpu_multi_ring_reset_helper_begin()drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +2
-1@@ -1046,10 +1048,10 @@ voidamdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask, * be called to restore preemption state, but it won't attempt to * fully restore the ring contents. */ -int amdgpu_multi_ring_reset_helper_end(const u32 ring_type_mask, +int amdgpu_multi_ring_reset_helper_end(struct amdgpu_device *adev, + const u32 ring_type_mask,struct
amdgpu_ring*guilty_ring, int ret) {
- structamdgpu_device*adev =guilty_ring->adev; structamdgpu_ring*ring;
int i, r;drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +0
-0@@ -637,10 +637,12 @@ void amdgpu_ring_reset_helper_begin(struct amdgpu_ring *ring,struct
amdgpu_fence*guilty_fence); intamdgpu_ring_reset_helper_end(struct amdgpu_ring *ring, struct amdgpu_fence *guilty_fence); -void
amdgpu_multi_ring_reset_helper_begin(const u32ring_type_mask, +void amdgpu_multi_ring_reset_helper_begin(structamdgpu_device*adev,
+ const u32ring_type_mask, structamdgpu_ring*guilty_ring,
structamdgpu_fence*guilty_fence);drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2
-1-int amdgpu_multi_ring_reset_helper_end(const u32 ring_type_mask, +int amdgpu_multi_ring_reset_helper_end(struct amdgpu_device *adev, + const u32 ring_type_mask,struct
amdgpu_ring*guilty_ring, int ret);
boolamdgpu_ring_is_reset_type_supported(struct amdgpu_ring *ring, u32 reset_type); --
2.50.1
Quoted 9 lines · Jesse Zhang
amdgpu_multi_ring_reset_helper_begin()and_end()take the device from
the guilty ring. A reset triggered by a hung user queue has no guilty kernel ring, so pass the device explicitly and allow a NULL guilty ring.No functional change.
Signed-off-by Jesse Zhang <[email protected]>
Quoted 122 lines
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c | 4 ++--drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c| 14 ++++++++------drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h| 6 ++++--3 files changed, 14 insertions(+), 10 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +0
-0@@ -465,11 +465,11 @@ int amdgpu_device_ip_soft_reset(structamdgpu_ring *guilty_ring, ring_type_mask = amdgpu_ring_mask_from_ip(ip_type);
amdgpu_device_lock_reset_domain(adev->reset_domain);drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +0
-1- amdgpu_multi_ring_reset_helper_begin(ring_type_mask,
guilty_ring,guilty_fence);drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-0+ amdgpu_multi_ring_reset_helper_begin(adev, ring_type_mask,
guilty_ring,guilty_fence);
r =ip_block->version->funcs->soft_reset(ip_block);drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +0
-1- r = amdgpu_multi_ring_reset_helper_end(ring_type_mask,
guilty_ring, r);drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-0+ r = amdgpu_multi_ring_reset_helper_end(adev, ring_type_mask,
guilty_ring, r);amdgpu_device_unlock_reset_domain(adev->reset_domain);
if (r) {drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -919,8 +919,9 @@ int amdgpu_ring_reset_helper_end(struct amdgpu_ring *ring, /*** amdgpu_multi_ring_reset_helper_begin() - Prepare multiple rings for a reset.
*
+ * @adev: amdgpu device
* @ring_type_mask: Bitmask of affected ring types
- * @guilty_ring: The ring which is guilty of causing a reset.
+ * @guilty_ring: The ring which is guilty of causing a reset, or NULL.
* @guilty_fence: The fence which didn't signal on the guilty ring. *
* Useful when performing a GPU reset method that affectsdrivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +2
-1@@ -938,11 +939,11 @@ int amdgpu_ring_reset_helper_end(structamdgpu_ring *ring, * After the reset is complete, the caller should then call * amdgpu_multi_ring_reset_helper_end() to restore the rings. */ -void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask, +void amdgpu_multi_ring_reset_helper_begin(struct amdgpu_device *adev, + const u32 ring_type_mask,struct
amdgpu_ring*guilty_ring,
structamdgpu_fence*guilty_fence)
{drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-1-struct amdgpu_device *adev = guilty_ring->adev;struct
amdgpu_fence*ring_guilty_fence;
structamdgpu_ring*ring;
boolrings_busy;drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -1034,8 +1035,9 @@ void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask, /*** amdgpu_multi_ring_reset_helper_end() - Prepare multiple rings for a reset.
*
+ * @adev: amdgpu device
* @ring_type_mask: Bitmask of affected ring types
- * @guilty_ring: The ring which is guilty of causing a reset.
+ * @guilty_ring: The ring which is guilty of causing a reset, or NULL.
* @ret: Return code from the reset function.
*
* After callingamdgpu_multi_ring_reset_helper_begin()drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +2
-1@@ -1046,10 +1048,10 @@ voidamdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask, * be called to restore preemption state, but it won't attempt to * fully restore the ring contents. */ -int amdgpu_multi_ring_reset_helper_end(const u32 ring_type_mask, +int amdgpu_multi_ring_reset_helper_end(struct amdgpu_device *adev, + const u32 ring_type_mask,struct
amdgpu_ring*guilty_ring, int ret)
{drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-1-struct amdgpu_device *adev = guilty_ring->adev;struct
amdgpu_ring*ring;
int i, r;drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +0
-0@@ -637,10 +637,12 @@ void amdgpu_ring_reset_helper_begin(struct amdgpu_ring *ring,struct
amdgpu_fence*guilty_fence);
intamdgpu_ring_reset_helper_end(struct amdgpu_ring *ring, struct amdgpu_fence *guilty_fence);drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1
-1-void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask, +void amdgpu_multi_ring_reset_helper_begin(struct amdgpu_device*adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1
-0+ const u32 ring_type_mask,struct
amdgpu_ring*guilty_ring,
structamdgpu_fence*guilty_fence);drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2
-1-int amdgpu_multi_ring_reset_helper_end(const u32 ring_type_mask, +int amdgpu_multi_ring_reset_helper_end(struct amdgpu_device *adev, + const u32 ring_type_mask,struct
amdgpu_ring*guilty_ring, int ret);
boolamdgpu_ring_is_reset_type_supported(struct amdgpu_ring *ring, u32 reset_type);