drm/amdgpu: Simplify filtering rings during IP block soft reset
Subsystems (2)
PATCH 1/2 drm/amdgpu: Simplify filtering rings during IP block soft reset
Instead of storing pointers to affected rings in an array, just iterate over all rings of the device and filter the affected rings by type using the type mask.
This is done to save memory used by the array of affected rings which was sized AMDGPU_MAX_RINGS.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c | 30 ++------------ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 53 ++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 4 +- 3 files changed, 40 insertions(+), 47 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +3 -27
@@ -481,28 +481,6 @@ static u32 amdgpu_ring_mask_from_ip(const enum amd_ip_block_type ip_type) } } -/** -* amdgpu_filter_rings() - Filter rings according to a mask. -* -* @adev: amdgpu_device pointer -* @ring_type_mask: Mask of ring types you are looking for -* @out_rings: Array of rings which is going to be filled -* @out_num_rings: Number of rings which were filtered -*/ -static void amdgpu_filter_rings (struct amdgpu_device *adev,const u32 ring_type_mask, -struct amdgpu_ring **out_rings,u32 *out_num_rings) -{ -u32 num_rings =0 ; -int i; - -for (i =0 ; i < adev->num_rings; ++i) { -if (BIT (adev->rings[i]->funcs->type) & ring_type_mask) - out_rings[num_rings++] = adev->rings[i]; - } - - *out_num_rings = num_rings; -} -/** * amdgpu_device_ip_soft_reset() - Perform a graceful soft reset on an IP block. *
@@ -524,10 +502,9 @@ int amdgpu_device_ip_soft_reset(struct amdgpu_ring *guilty_ring, struct amdgpu_fence *guilty_fence) {struct amdgpu_device *adev = guilty_ring->adev; -struct amdgpu_ring *rings[AMDGPU_MAX_RINGS ];struct amdgpu_ip_block *ip_block;enum amd_ip_block_type ip_type; -u32 num_rings, ring_type_mask; +u32 ring_type_mask;int r; ip_type =amdgpu_ip_from_ring (guilty_ring->funcs->type);
@@ -543,14 +520,13 @@ int amdgpu_device_ip_soft_reset(struct amdgpu_ring *guilty_ring, ip_block->version->funcs->name); ring_type_mask =amdgpu_ring_mask_from_ip (ip_type); -amdgpu_filter_rings (adev, ring_type_mask, rings, &num_rings);amdgpu_device_lock_reset_domain (adev->reset_domain); -amdgpu_multi_ring_reset_helper_begin (rings, num_rings, guilty_ring, guilty_fence); +amdgpu_multi_ring_reset_helper_begin (ring_type_mask, guilty_ring, guilty_fence); r = ip_block->version->funcs->soft_reset (ip_block); - r =amdgpu_multi_ring_reset_helper_end (rings, num_rings, guilty_ring, r); + r =amdgpu_multi_ring_reset_helper_end (ring_type_mask, guilty_ring, r);amdgpu_device_unlock_reset_domain (adev->reset_domain);if (r) {
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +35 -18
114 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -2
@@ -595,10 +595,10 @@ 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 (struct amdgpu_ring **rings,u32 num_rings, +void amdgpu_multi_ring_reset_helper_begin (const u32 ring_type_mask,struct amdgpu_ring *guilty_ring,struct amdgpu_fence *guilty_fence); -int amdgpu_multi_ring_reset_helper_end (struct amdgpu_ring **rings,u32 num_rings, +int amdgpu_multi_ring_reset_helper_end (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.54.0
PATCH 2/2 drm/amdgpu: Fix typos in comments for IP block soft reset
These typos were accidentally overlooked. Let's fix them now.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +4 -4
@@ -942,7 +942,7 @@ void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask,* Give some time for non-guilty rings to finish their * current submission, to try to minimize collateral damage. * -* Note that this just a best effort, but really there +* Note that this is just a best effort, but really there * is no way to really know which ring is actually responsible * because different rings may share resources, eg. a compute * ring may hog shader engines, causing a graphics ring to hang.
@@ -1003,12 +1003,12 @@ void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask,* @guilty_ring: The ring which is guilty of causing a reset. * @ret: Return code from the reset function. * -* After calling amdgpu_multi_ring_reset_helper_end() +* After calling amdgpu_multi_ring_reset_helper_begin() * and executing the actual reset method, call this * function to restore normal operation. * * In case the reset failed, this function should still -* be called to restore some state, but it won't attempt to +* 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,
@@ -1032,7 +1032,7 @@ int amdgpu_multi_ring_reset_helper_end(const u32 ring_type_mask,/* Flush HDP cache so the GPU can see the updated COND_EXEC values */ amdgpu_device_flush_hdp (adev,NULL ); -/* If the reset was unsuccessful, return without restoring anything. */ +/* If the reset was unsuccessful, return without restoring anything else. */ if (ret)return ret;
Signature · 1 line
2.54.0
Re: [PATCH 2/2] drm/amdgpu: Fix typos in comments for IP block soft reset
Quoted 36 lines · Timur Kristóf
These typos were accidentally overlooked. Let's fix them now.
Signed-off-by Timur Kristóf <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +3
-3@@ -942,7 +942,7 @@ void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask,* Give some time for non-guilty rings to finish their * current submission, to try to minimize collateral damage. * -* Note that this just a best effort, but really there +* Note that this is just a best effort, but really there * is no way to really know which ring is actually responsible * because different rings may share resources, eg. a compute * ring may hog shader engines, causing a graphics ring to hang. @@ -1003,12 +1003,12 @@ void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask,* @guilty_ring: The ring which is guilty of causing a reset. * @ret: Return code from the reset function. * -* After calling amdgpu_multi_ring_reset_helper_end() +* After calling amdgpu_multi_ring_reset_helper_begin() * and executing the actual reset method, call this * function to restore normal operation. * * In case the reset failed, this function should still -* be called to restore some state, but it won't attempt to +* 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,
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c int amdgpu_multi_ring_reset_helper_end(const u32 ring_type_mask, · line 1038
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1
-1@@ -1032,7 +1032,7 @@ int amdgpu_multi_ring_reset_helper_end(const u32 ring_type_mask,/* Flush HDP cache so the GPU can see the updated COND_EXEC values */ amdgpu_device_flush_hdp (adev,NULL ); -/* If the reset was unsuccessful, return without restoring anything. */ +/* If the reset was unsuccessful, return without restoring anything else. */ if (ret)return ret;
Regards,
Tvrtko
Mario Limonciello
AppliedRe: [PATCH 2/2] drm/amdgpu: Fix typos in comments for IP block soft reset
Quoted 52 lines · Tvrtko Ursulin
Quoted 42 lines · Timur Kristóf
These typos were accidentally overlooked. Let's fix them now.
Signed-off-by Timur Kristóf <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c| 8 ++++----1 file changed, 4 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1
-1@@ -942,7 +942,7 @@ void amdgpu_multi_ring_reset_helper_begin(constu32 ring_type_mask, * Give some time for non-guilty rings to finish their * current submission, to try to minimize collateral damage. * - * Note that this just a best effort, but really there + * Note that this is just a best effort, but really there * is no way to really know which ring is actually responsible * because different rings may share resources, eg. a compute* ring may hog shader engines, causing a graphics ring to hang.
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +2
-2@@ -1003,12 +1003,12 @@ voidamdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask, * @guilty_ring: The ring which is guilty of causing a reset. * @ret: Return code from the reset function. * -* After calling amdgpu_multi_ring_reset_helper_end() +* After calling amdgpu_multi_ring_reset_helper_begin() * and executing the actual reset method, call this * function to restore normal operation. * * In case the reset failed, this function should still -* be called to restore some state, but it won't attempt to +* 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,drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-1@@ -1032,7 +1032,7 @@ int amdgpu_multi_ring_reset_helper_end(const u32 ring_type_mask, /* Flush HDP cache so the GPU can see the updated COND_EXEC values */ amdgpu_device_flush_hdp(adev, NULL); - /* If the reset was unsuccessful, return without restoringQuoted 5 lines
anything. */
+ /* If the reset was unsuccessful, return without restoring anything else. */
if (ret)
return ret;Reviewed-by Tvrtko Ursulin <[email protected]>
Quoted 4 lines
Regards,
Tvrtko
Applied.
AMD General
Quoted 13 lines
-----Original Message-----
From: Timur Kristóf <[email protected]>
Sent: Wednesday, June 24, 2026 1:08 PM
To: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Natalie Vock <[email protected]>; Limonciello, Mario <[email protected]>; Marek Olšák <[email protected]>; Tvrtko Ursulin <[email protected]>; Lazar, Lijo <[email protected]>; Martin Roukala <[email protected]>; SHANMUGAM, SRINIVASAN <[email protected]>
Cc: Timur Kristóf <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: Simplify filtering rings during IP block soft reset
Quoted 8 lines
Instead of storing pointers to affected rings in an array, just iterate over all rings of the device and filter the affected rings by type using the type mask.
This is done to save memory used by the array of affected rings which was sized
AMDGPU_MAX_RINGS.Suggested-by Srinivasan Shanmugam <[email protected]>Signed-off-by Timur Kristóf <[email protected]>
This looks good to me.
The new logic uses the same ring_type_mask filtering condition as the old amdgpu_filter_rings() helper, but avoids the temporary AMDGPU_MAX_RINGS-sized array.
Thanks!
Srini
Quoted 237 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c | 30 ++------------ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 53 ++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 4 +- 3 files changed, 40 insertions(+), 47 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +0
-22@@ -481,28 +481,6 @@ static u32 amdgpu_ring_mask_from_ip(const enum amd_ip_block_type ip_type) } } -/** -* amdgpu_filter_rings() - Filter rings according to a mask. -* -* @adev: amdgpu_device pointer -* @ring_type_mask: Mask of ring types you are looking for -* @out_rings: Array of rings which is going to be filled -* @out_num_rings: Number of rings which were filtered -*/ -static void amdgpu_filter_rings (struct amdgpu_device *adev,const u32 ring_type_mask, -struct amdgpu_ring **out_rings,u32 *out_num_rings) -{ -u32 num_rings =0 ; -int i; - -for (i =0 ; i < adev->num_rings; ++i) { -if (BIT (adev->rings[i]->funcs->type) & ring_type_mask) - out_rings[num_rings++] = adev->rings[i]; - } - - *out_num_rings = num_rings; -} -/** *
amdgpu_device_ip_soft_reset()- Perform a graceful soft reset on an IP block. *drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-2@@ -524,10 +502,9 @@ int amdgpu_device_ip_soft_reset(struct amdgpu_ring *guilty_ring, struct amdgpu_fence *guilty_fence) {struct amdgpu_device *adev = guilty_ring->adev; -struct amdgpu_ring *rings[AMDGPU_MAX_RINGS ];struct amdgpu_ip_block *ip_block;enum amd_ip_block_type ip_type; -u32 num_rings, ring_type_mask; +u32 ring_type_mask;int r;ip_type = amdgpu_ip_from_ring(guilty_ring->funcs->type);drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +4
-3@@ -543,14 +520,13 @@ int amdgpu_device_ip_soft_reset(struct amdgpu_ring *guilty_ring, ip_block->version->funcs->name); ring_type_mask =amdgpu_ring_mask_from_ip (ip_type); -amdgpu_filter_rings (adev, ring_type_mask, rings, &num_rings);amdgpu_device_lock_reset_domain (adev->reset_domain); -amdgpu_multi_ring_reset_helper_begin (rings, num_rings, guilty_ring, guilty_fence); +amdgpu_multi_ring_reset_helper_begin (ring_type_mask, guilty_ring, +guilty_fence); r = ip_block->version->funcs->soft_reset (ip_block); - r =amdgpu_multi_ring_reset_helper_end (rings, num_rings, guilty_ring, r); + r =amdgpu_multi_ring_reset_helper_end (ring_type_mask, guilty_ring, +r);amdgpu_device_unlock_reset_domain (adev->reset_domain);if (r) {drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1
-2@@ -884,8 +884,7 @@ int amdgpu_ring_reset_helper_end(struct amdgpu_ring *ring,/** * amdgpu_multi_ring_reset_helper_begin() - Prepare multiple rings for a reset. * -* @rings: Pointer to an array of amdgpu rings that are affected. -* @num_rings: Number of rings in the array. +* @ring_type_mask: Bitmask of affected ring types * @guilty_ring: The ring which is guilty of causing a reset. * @guilty_fence: The fence which didn't signal on the guilty ring. *
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1
-1@@ -904,7 +903,7 @@ 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(struct amdgpu_ring **rings, u32 num_rings, +void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask, struct amdgpu_ring *guilty_ring,struct
amdgpu_fence*guilty_fence) { @@ -
915,8 +914,11 @@ void amdgpu_multi_ring_reset_helper_begin(structamdgpu_ring**rings, u32num_riint i; u32 t;drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +5
-2-for (i =0 ; i < num_rings; ++i) { - ring = rings[i]; +for (i =0 ; i < adev->num_rings; ++i) { + ring = adev->rings[i]; + +if (!(BIT (ring->funcs->type) & ring_type_mask)) +continue ;/* Don't accept new submissions on the ring. */ if (amdgpu_ring_sched_ready(ring) &&!drm_sched_is_stopped(&ring->sched))
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -949,8 +951,11 @@ void amdgpu_multi_ring_reset_helper_begin(struct
amdgpu_ring**rings, u32num_rirings_busy = false; /* Check if any of the non-guilty rings are busy */drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +5
-2-for (i =0 ; i < num_rings; ++i) { - ring = rings[i]; +for (i =0 ; i < adev->num_rings; ++i) { + ring = adev->rings[i]; + +if (!(BIT (ring->funcs->type) & ring_type_mask)) +continue ;if (ring == guilty_ring)continue ;@@ -966,8 +971,11 @@ void amdgpu_multi_ring_reset_helper_begin(struct
amdgpu_ring**rings, u32num_rimdelay(10); }drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +6
-2-for (i =0 ; i < num_rings; ++i) { - ring = rings[i]; +for (i =0 ; i < adev->num_rings; ++i) { + ring = adev->rings[i]; + +if (!(BIT (ring->funcs->type) & ring_type_mask)) +continue ;/* * Find guilty fences, ie. the fences that didn't signal @@ -991,8 +999,7 @@ void amdgpu_multi_ring_reset_helper_begin(struct amdgpu_ring **rings, u32
num_ri
/**
*amdgpu_multi_ring_reset_helper_end()- Prepare multiple rings for a reset. *
- * @rings: Pointer to an array of amdgpu rings that are affected.
- * @num_rings: Number of rings in the array.
+ * @ring_type_mask: Bitmask of affected ring types
* @guilty_ring: The ring which is guilty of causing a reset.
* @ret: Return code from the reset function.
*drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -1004,7 +1011,7 @@ void amdgpu_multi_ring_reset_helper_begin(struct
amdgpu_ring**rings, u32num_ri
* be called to restore some state, but it won't attempt to
* fully restore the ring contents.
*/
-int amdgpu_multi_ring_reset_helper_end(structamdgpu_ring**rings, u32num_rings,
+int amdgpu_multi_ring_reset_helper_end(const u32ring_type_mask,struct amdgpu_ring *guilty_ring, int ret) { struct amdgpu_device *adev = guilty_ring->adev; @@ -1012,8 +1019,11 @@ int amdgpu_multi_ring_reset_helper_end(struct amdgpu_ring **rings, u32 num_rings int i, r; /* Set preempt condition, rings are now allowed to execute submissions */drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +5
-2-for (i =0 ; i < num_rings; ++i) { - ring = rings[i]; +for (i =0 ; i < adev->num_rings; ++i) { + ring = adev->rings[i]; + +if (!(BIT (ring->funcs->type) & ring_type_mask)) +continue ;if (ring->funcs->init_cond_exec) amdgpu_ring_set_preempt_cond_exec(ring, true); @@ -1027,9 +1037,13 @@ int amdgpu_multi_ring_reset_helper_end(struct
amdgpu_ring**rings, u32num_ringsreturn ret; /* Restore contents of all rings */drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +6
-2-for (i =0 ; i < num_rings; ++i) { - ring = rings[i]; +for (i =0 ; i < adev->num_rings; ++i) { + ring = adev->rings[i]; + +if (!(BIT (ring->funcs->type) & ring_type_mask)) +continue ; +/* Restore contents of the ring */ r =amdgpu_ring_reset_helper_end (ring, ring->guilty_fence);if (r) { dev_err(adev->dev,@@ -1040,8 +1054,11 @@ int amdgpu_multi_ring_reset_helper_end(struct
amdgpu_ring**rings, u32num_rings} /* Accept submissions on all rings again */drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +5
-2-for (i =0 ; i < num_rings; ++i) { - ring = rings[i]; +for (i =0 ; i < adev->num_rings; ++i) { + ring = adev->rings[i]; + +if (!(BIT (ring->funcs->type) & ring_type_mask)) +continue ;if (!amdgpu_ring_sched_ready (ring))continue ;drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2
-0@@ -595,10 +595,10 @@ 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(struct amdgpu_ring **rings, u32 num_rings, +void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask,struct amdgpu_ring *guilty_ring, struct amdgpu_fence *guilty_fence); -int amdgpu_multi_ring_reset_helper_end(struct amdgpu_ring **rings, u32 num_rings, +int amdgpu_multi_ring_reset_helper_end(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.54.0
Quoted 65 lines · Timur Kristóf
Instead of storing pointers to affected rings in an array, just iterate over all rings of the device and filter the affected rings by type using the type mask.
This is done to save memory used by the array of affected rings which was sized
AMDGPU_MAX_RINGS.Suggested-by Srinivasan Shanmugam <[email protected]>Signed-off-by Timur Kristóf <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c | 30 ++------------ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 53 ++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 4 +- 3 files changed, 40 insertions(+), 47 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-25@@ -481,28 +481,6 @@ static u32 amdgpu_ring_mask_from_ip(const enum amd_ip_block_type ip_type) } } -/** -* amdgpu_filter_rings() - Filter rings according to a mask. -* -* @adev: amdgpu_device pointer -* @ring_type_mask: Mask of ring types you are looking for -* @out_rings: Array of rings which is going to be filled -* @out_num_rings: Number of rings which were filtered -*/ -static void amdgpu_filter_rings (struct amdgpu_device *adev,const u32 ring_type_mask, -struct amdgpu_ring **out_rings,u32 *out_num_rings) -{ -u32 num_rings =0 ; -int i; - -for (i =0 ; i < adev->num_rings; ++i) { -if (BIT (adev->rings[i]->funcs->type) & ring_type_mask) - out_rings[num_rings++] = adev->rings[i]; - } - - *out_num_rings = num_rings; -} -/** * amdgpu_device_ip_soft_reset() - Perform a graceful soft reset on an IP block. * @@ -524,10 +502,9 @@ int amdgpu_device_ip_soft_reset(struct amdgpu_ring *guilty_ring, struct amdgpu_fence *guilty_fence) {struct amdgpu_device *adev = guilty_ring->adev; -struct amdgpu_ring *rings[AMDGPU_MAX_RINGS ];struct amdgpu_ip_block *ip_block;enum amd_ip_block_type ip_type; -u32 num_rings, ring_type_mask; +u32 ring_type_mask;int r; ip_type =amdgpu_ip_from_ring (guilty_ring->funcs->type);@@ -543,14 +520,13 @@ int amdgpu_device_ip_soft_reset(struct amdgpu_ring *guilty_ring, ip_block->version->funcs->name); ring_type_mask =amdgpu_ring_mask_from_ip (ip_type); -amdgpu_filter_rings (adev, ring_type_mask, rings, &num_rings);
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c int amdgpu_device_ip_soft_reset(struct amdgpu_ring *guilty_ring, · line 530
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +2
-2amdgpu_device_lock_reset_domain (adev->reset_domain); -amdgpu_multi_ring_reset_helper_begin (rings, num_rings, guilty_ring, guilty_fence); +amdgpu_multi_ring_reset_helper_begin (ring_type_mask, guilty_ring, guilty_fence); r = ip_block->version->funcs->soft_reset (ip_block); - r =amdgpu_multi_ring_reset_helper_end (rings, num_rings, guilty_ring, r); + r =amdgpu_multi_ring_reset_helper_end (ring_type_mask, guilty_ring, r);amdgpu_device_unlock_reset_domain (adev->reset_domain);
Patch looks correct to me so:
I do however have some lamentations:
1)ring_type_mask is derived directly from the guilty_ring so strictly speaking is redundant as parameter to begin/end helpers.
2)
Lets consider this sequence:
ip_type = amdgpu_ip_from_ring(guilty_ring->funcs->type); ring_type_mask = amdgpu_ring_mask_from_ip(ip_type);
And expand it for say sdma:
ip_type = amdgpu_ip_from_ring(ring_type)
{
switch (ring_type) {
case AMDGPU_RING_TYPE_SDMA:
return AMD_IP_BLOCK_TYPE_SDMA;ring_mask_type = amdgpu_ring_mask_from_ip(ip_type)
{
switch (ip_type) {
case AMD_IP_BLOCK_TYPE_SDMA:
return BIT(AMDGPU_RING_TYPE_SDMA);Identity map kind of.
I am not sure it is worth it for the reset code on it's own, only if there are other places in the driver which ask the same question, but in general I am often tempted to just store those in the respective parent data structures at init time.
In this case that would be something like:
ring->ip_type - holding AMD_IP_BLOCK_TYPE_SDMA
ip_block->ring_mask - holding a bitmask mask of rings implemented
Again probably not worth the effort in this instance. I only mention it because there are similar things in the driver with much more often used invariant lookups which then waste a lot of space. For example the one I recently re-posted saves ~150KiB of .text:
Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +0
-0if (r) {drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +2
-3@@ -884,8 +884,7 @@ int amdgpu_ring_reset_helper_end(struct amdgpu_ring *ring,/** * amdgpu_multi_ring_reset_helper_begin() - Prepare multiple rings for a reset. * -* @rings: Pointer to an array of amdgpu rings that are affected. -* @num_rings: Number of rings in the array. +* @ring_type_mask: Bitmask of affected ring types * @guilty_ring: The ring which is guilty of causing a reset. * @guilty_fence: The fence which didn't signal on the guilty ring. * @@ -904,7 +903,7 @@ 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 (struct amdgpu_ring **rings,u32 num_rings, +void amdgpu_multi_ring_reset_helper_begin (const u32 ring_type_mask,struct amdgpu_ring *guilty_ring,struct amdgpu_fence *guilty_fence) {
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c void amdgpu_multi_ring_reset_helper_begin(struct amdgpu_ring **rings, u32 num_ri · line 921
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +5
-2@@ -915,8 +914,11 @@ void amdgpu_multi_ring_reset_helper_begin(struct amdgpu_ring **rings, u32 num_riint i;u32 t; -for (i =0 ; i < num_rings; ++i) { - ring = rings[i]; +for (i =0 ; i < adev->num_rings; ++i) { + ring = adev->rings[i]; + +if (!(BIT (ring->funcs->type) & ring_type_mask)) +continue ;
Another thing to consider is if adding a succint helper for the ring walks would be interesting. Ie.
amdgpu_for_each_ring(adev, ring, mask)
Regards,
Tvrtko
Quoted 111 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +28
-13/* Don't accept new submissions on the ring. */ if (amdgpu_ring_sched_ready (ring) && !drm_sched_is_stopped (&ring->sched))@@ -949,8 +951,11 @@ void amdgpu_multi_ring_reset_helper_begin(struct amdgpu_ring **rings, u32 num_ri rings_busy = false;/* Check if any of the non-guilty rings are busy */ -for (i =0 ; i < num_rings; ++i) { - ring = rings[i]; +for (i =0 ; i < adev->num_rings; ++i) { + ring = adev->rings[i]; + +if (!(BIT (ring->funcs->type) & ring_type_mask)) +continue ;if (ring == guilty_ring)continue ;@@ -966,8 +971,11 @@ void amdgpu_multi_ring_reset_helper_begin(struct amdgpu_ring **rings, u32 num_rimdelay (10 ); } -for (i =0 ; i < num_rings; ++i) { - ring = rings[i]; +for (i =0 ; i < adev->num_rings; ++i) { + ring = adev->rings[i]; + +if (!(BIT (ring->funcs->type) & ring_type_mask)) +continue ;/* * Find guilty fences, ie. the fences that didn't signal @@ -991,8 +999,7 @@ void amdgpu_multi_ring_reset_helper_begin(struct amdgpu_ring **rings, u32 num_ri/** * amdgpu_multi_ring_reset_helper_end() - Prepare multiple rings for a reset. * -* @rings: Pointer to an array of amdgpu rings that are affected. -* @num_rings: Number of rings in the array. +* @ring_type_mask: Bitmask of affected ring types * @guilty_ring: The ring which is guilty of causing a reset. * @ret: Return code from the reset function. * @@ -1004,7 +1011,7 @@ void amdgpu_multi_ring_reset_helper_begin(struct amdgpu_ring **rings, u32 num_ri* be called to restore some state, but it won't attempt to * fully restore the ring contents. */ -int amdgpu_multi_ring_reset_helper_end (struct amdgpu_ring **rings,u32 num_rings, +int amdgpu_multi_ring_reset_helper_end (const u32 ring_type_mask,struct amdgpu_ring *guilty_ring,int ret) {struct amdgpu_device *adev = guilty_ring->adev;@@ -1012,8 +1019,11 @@ int amdgpu_multi_ring_reset_helper_end(struct amdgpu_ring **rings, u32 num_ringsint i, r;/* Set preempt condition, rings are now allowed to execute submissions */ -for (i =0 ; i < num_rings; ++i) { - ring = rings[i]; +for (i =0 ; i < adev->num_rings; ++i) { + ring = adev->rings[i]; + +if (!(BIT (ring->funcs->type) & ring_type_mask)) +continue ;if (ring->funcs->init_cond_exec)amdgpu_ring_set_preempt_cond_exec (ring, true);@@ -1027,9 +1037,13 @@ int amdgpu_multi_ring_reset_helper_end(struct amdgpu_ring **rings, u32 num_ringsreturn ret;/* Restore contents of all rings */ -for (i =0 ; i < num_rings; ++i) { - ring = rings[i]; +for (i =0 ; i < adev->num_rings; ++i) { + ring = adev->rings[i]; + +if (!(BIT (ring->funcs->type) & ring_type_mask)) +continue ; +/* Restore contents of the ring */ r =amdgpu_ring_reset_helper_end (ring, ring->guilty_fence);if (r) { dev_err(adev->dev,@@ -1040,8 +1054,11 @@ int amdgpu_multi_ring_reset_helper_end(struct amdgpu_ring **rings, u32 num_rings }/* Accept submissions on all rings again */ -for (i =0 ; i < num_rings; ++i) { - ring = rings[i]; +for (i =0 ; i < adev->num_rings; ++i) { + ring = adev->rings[i]; + +if (!(BIT (ring->funcs->type) & ring_type_mask)) +continue ;if (!amdgpu_ring_sched_ready (ring))continue ;drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2
-2@@ -595,10 +595,10 @@ 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 (struct amdgpu_ring **rings,u32 num_rings, +void amdgpu_multi_ring_reset_helper_begin (const u32 ring_type_mask,struct amdgpu_ring *guilty_ring,struct amdgpu_fence *guilty_fence); -int amdgpu_multi_ring_reset_helper_end (struct amdgpu_ring **rings,u32 num_rings, +int amdgpu_multi_ring_reset_helper_end (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);
Mario Limonciello
AppliedQuoted 82 lines · Tvrtko Ursulin
Quoted 67 lines · Timur Kristóf
Instead of storing pointers to affected rings in an array, just iterate over all rings of the device and filter the affected rings by type using the type mask.
This is done to save memory used by the array of affected rings which was sized
AMDGPU_MAX_RINGS.Suggested-by Srinivasan Shanmugam <[email protected]>Signed-off-by Timur Kristóf <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c | 30 ++------------drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c| 53 ++++++++++++++++--------drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h| 4 +-3 files changed, 40 insertions(+), 47 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +0
-22@@ -481,28 +481,6 @@ static u32 amdgpu_ring_mask_from_ip(const enum amd_ip_block_type ip_type) } } -/** -* amdgpu_filter_rings() - Filter rings according to a mask. -* -* @adev: amdgpu_device pointer -* @ring_type_mask: Mask of ring types you are looking for -* @out_rings: Array of rings which is going to be filled -* @out_num_rings: Number of rings which were filtered -*/ -static void amdgpu_filter_rings (struct amdgpu_device *adev,const u32 ring_type_mask, - struct amdgpu_ring **out_rings, u32 *out_num_rings) -{ - u32 num_rings = 0; - int i; - - for (i = 0; i < adev->num_rings; ++i) { - if (BIT(adev->rings[i]->funcs->type) & ring_type_mask) - out_rings[num_rings++] = adev->rings[i]; - } - - *out_num_rings = num_rings; -} - /*** amdgpu_device_ip_soft_reset() - Perform a graceful soft reset on an IP block. *
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +1
-3@@ -524,10 +502,9 @@ int amdgpu_device_ip_soft_reset(struct amdgpu_ring *guilty_ring, struct amdgpu_fence *guilty_fence) { struct amdgpu_device *adev = guilty_ring->adev; - struct amdgpu_ring *rings[AMDGPU_MAX_RINGS]; struct amdgpu_ip_block *ip_block; enum amd_ip_block_type ip_type; - u32 num_rings, ring_type_mask; + u32 ring_type_mask; int r; ip_type = amdgpu_ip_from_ring(guilty_ring->funcs->type);@@ -543,14 +520,13 @@ int amdgpu_device_ip_soft_reset(structamdgpu_ring *guilty_ring, ip_block->version->funcs->name); ring_type_mask = amdgpu_ring_mask_from_ip(ip_type); - amdgpu_filter_rings(adev, ring_type_mask, rings, &num_rings); amdgpu_device_lock_reset_domain(adev->reset_domain);drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c int amdgpu_device_ip_soft_reset(struct · line 531
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +2
-2- amdgpu_multi_ring_reset_helper_begin(rings, num_rings, guilty_ring, guilty_fence); + amdgpu_multi_ring_reset_helper_begin(ring_type_mask, guilty_ring, guilty_fence); r = ip_block->version->funcs->soft_reset(ip_block); - r = amdgpu_multi_ring_reset_helper_end(rings, num_rings, guilty_ring, r); + r = amdgpu_multi_ring_reset_helper_end(ring_type_mask, guilty_ring, r); amdgpu_device_unlock_reset_domain(adev->reset_domain);Patch looks correct to me so:
Quoted 1 line
Reviewed-by Tvrtko Ursulin <[email protected]>
Applied.
Quoted 2 lines
I do however have some lamentations:
Feel free to follow up with any other changes on top.
Quoted 197 lines
1)
ring_type_maskis derived directly from theguilty_ringso strictly speaking is redundant as parameter to begin/end helpers.2)
Lets consider this sequence:
ip_type=amdgpu_ip_from_ring(guilty_ring->funcs->type);ring_type_mask=amdgpu_ring_mask_from_ip(ip_type);And expand it for say sdma:
ip_type=amdgpu_ip_from_ring(ring_type)
{
switch (ring_type) {
caseAMDGPU_RING_TYPE_SDMA:
returnAMD_IP_BLOCK_TYPE_SDMA;
ring_mask_type=amdgpu_ring_mask_from_ip(ip_type){
switch (ip_type) {
caseAMD_IP_BLOCK_TYPE_SDMA:
returnBIT(AMDGPU_RING_TYPE_SDMA);Identity map kind of.
I am not sure it is worth it for the reset code on it's own, only if there are other places in the driver which ask the same question, but in general I am often tempted to just store those in the respective parent data structures at init time.
In this case that would be something like:
ring->ip_type- holdingAMD_IP_BLOCK_TYPE_SDMA
ip_block->ring_mask- holding a bitmask mask of rings implementedAgain probably not worth the effort in this instance. I only mention it because there are similar things in the driver with much more often used invariant lookups which then waste a lot of space. For example the one I recently re-posted saves ~150KiB of .text:
https://lore.kernel.org/amd-gfx/20260622121034.52762-1- [email protected]/
Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +0
-0if (r) {drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1
-2@@ -884,8 +884,7 @@ int amdgpu_ring_reset_helper_end(struct amdgpu_ring *ring, /*** amdgpu_multi_ring_reset_helper_begin() - Prepare multiple rings for a reset. * -* @rings: Pointer to an array of amdgpu rings that are affected. -* @num_rings: Number of rings in the array. +* @ring_type_mask: Bitmask of affected ring types * @guilty_ring: The ring which is guilty of causing a reset. * @guilty_fence: The fence which didn't signal on the guilty ring. *
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1
-1@@ -904,7 +903,7 @@ 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(struct amdgpu_ring **rings, u32 num_rings, +void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask, struct amdgpu_ring *guilty_ring,struct
amdgpu_fence*guilty_fence) {drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -915,8 +914,11 @@ void amdgpu_multi_ring_reset_helper_begin(struct
amdgpu_ring**rings, u32num_ri
int i;Quoted 8 lines
u32 t;
- for (i = 0; i <num_rings; ++i) {
- ring = rings[i];
+ for (i = 0; i <adev->num_rings; ++i) {
+ ring = adev->rings[i];
+
+ if (!(BIT(ring->funcs->type) &ring_type_mask)) + continue;Another thing to consider is if adding a succint helper for the ring walks would be interesting. Ie.
amdgpu_for_each_ring(adev, ring, mask)
Regards,
Tvrtko
Quoted 111 lines
/* Don't accept new submissions on the ring. */
if (amdgpu_ring_sched_ready(ring)&& !drm_sched_is_stopped(&ring->sched))drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -949,8 +951,11 @@ void amdgpu_multi_ring_reset_helper_begin(struct
amdgpu_ring**rings, u32num_ri
rings_busy= false;
/* Check if any of the non-guilty rings are busy */ - for (i = 0; i <num_rings; ++i) {
- ring = rings[i];
+ for (i = 0; i <adev->num_rings; ++i) {
+ ring = adev->rings[i];
+
+ if (!(BIT(ring->funcs->type) &ring_type_mask)) + continue;
if (ring ==guilty_ring)
continue;drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -966,8 +971,11 @@ void amdgpu_multi_ring_reset_helper_begin(struct
amdgpu_ring**rings, u32num_ri
mdelay(10);
}
- for (i = 0; i <num_rings; ++i) {
- ring = rings[i];
+ for (i = 0; i <adev->num_rings; ++i) {
+ ring = adev->rings[i];
+
+ if (!(BIT(ring->funcs->type) &ring_type_mask)) + continue;
/*
* Find guilty fences, ie. the fences that didn't signaldrivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -991,8 +999,7 @@ void amdgpu_multi_ring_reset_helper_begin(struct
amdgpu_ring**rings, u32num_ri
/**
*amdgpu_multi_ring_reset_helper_end()- Prepare multiple rings for a reset. *
- * @rings: Pointer to an array of amdgpu rings that are affected.
- * @num_rings: Number of rings in the array.
+ * @ring_type_mask: Bitmask of affected ring types
* @guilty_ring: The ring which is guilty of causing a reset.
* @ret: Return code from the reset function.
*drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -1004,7 +1011,7 @@ void amdgpu_multi_ring_reset_helper_begin(struct
amdgpu_ring**rings, u32num_ri
* be called to restore some state, but it won't attempt to
* fully restore the ring contents.
*/
-int amdgpu_multi_ring_reset_helper_end(structamdgpu_ring**rings, u32num_rings,
+intamdgpu_multi_ring_reset_helper_end(const u32 ring_type_mask, struct amdgpu_ring *guilty_ring, int ret){
structamdgpu_device*adev =guilty_ring->adev;drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -1012,8 +1019,11 @@ int amdgpu_multi_ring_reset_helper_end(struct
amdgpu_ring**rings, u32num_rings
int i, r;
/* Set preempt condition, rings are now allowed to execute submissions */ - for (i = 0; i <num_rings; ++i) {
- ring = rings[i];
+ for (i = 0; i <adev->num_rings; ++i) {
+ ring = adev->rings[i];
+
+ if (!(BIT(ring->funcs->type) &ring_type_mask))
+ continue;
if (ring->funcs->init_cond_exec)amdgpu_ring_set_preempt_cond_exec(ring, true);drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -1027,9 +1037,13 @@ int amdgpu_multi_ring_reset_helper_end(struct
amdgpu_ring**rings, u32num_rings
return ret;
/* Restore contents of all rings */
- for (i = 0; i <num_rings; ++i) {
- ring = rings[i];
+ for (i = 0; i <adev->num_rings; ++i) {
+ ring = adev->rings[i];
+
+ if (!(BIT(ring->funcs->type) &ring_type_mask))
+ continue;
+ /* Restore contents of the ring */
r =amdgpu_ring_reset_helper_end(ring, ring->guilty_fence); if (r) {
dev_err(adev->dev,drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-0@@ -1040,8 +1054,11 @@ int amdgpu_multi_ring_reset_helper_end(struct
amdgpu_ring**rings, u32num_rings
}
/* Accept submissions on all rings again */ - for (i = 0; i <num_rings; ++i) {
- ring = rings[i];
+ for (i = 0; i <adev->num_rings; ++i) {
+ ring = adev->rings[i];
+
+ if (!(BIT(ring->funcs->type) &ring_type_mask)) + continue;
if (!amdgpu_ring_sched_ready(ring)) continue;drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2
-2@@ -595,10 +595,10 @@ 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 (struct amdgpu_ring **rings,u32 num_rings, +void amdgpu_multi_ring_reset_helper_begin(const u32 ring_type_mask, struct amdgpu_ring *guilty_ring, struct amdgpu_fence *guilty_fence); -int amdgpu_multi_ring_reset_helper_end(struct amdgpu_ring **rings, u32 num_rings, +int amdgpu_multi_ring_reset_helper_end(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);