drm/amdgpu/kfd: Add shared SDMA reset functionality with callback support
Subsystems (2)
PATCH v7 1/9 drm/amdgpu/kfd: Add shared SDMA reset functionality with callback support
From: "[email protected]" <[email protected]>
This patch introduces shared SDMA reset functionality between AMDGPU and KFD. The implementation includes the following key changes:
1. Added amdgpu_sdma_reset_queue:
- Resets a specific SDMA queue by instance ID.
- Invokes registered pre-reset and post-reset callbacks to allow KFD and AMDGPU to save/restore their state during the reset process.
2. Added amdgpu_set_on_reset_callbacks:
- Allows KFD and AMDGPU to register callback functions for pre-reset and post-reset operations.
- Callbacks are stored in a global linked list and invoked in the correct order during SDMA reset.
This patch ensures that both AMDGPU and KFD can handle SDMA reset events gracefully, with proper state saving and restoration. It also provides a flexible callback mechanism for future extensions.
v2: fix CamelCase and put the SDMA helper into amdgpu_sdma.c (Alex)
v3: rename the amdgpu_register_on_reset_callbacks function to
amdgpu_sdma_register_on_reset_callbacks
move global reset_callback_list to struct amdgpu_sdma (Alex)
v4: Update the reset callback function description and
rename the reset function to amdgpu_sdma_reset_engine (Alex)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 73 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 11 ++++ drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 2 +- 3 files changed, 85 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +73 -0
@@ -460,3 +460,76 @@ void amdgpu_sdma_sysfs_reset_mask_fini(struct amdgpu_device *adev)device_remove_file (adev->dev, &dev_attr_sdma_reset_mask); } } + +/** +* amdgpu_sdma_register_on_reset_callbacks - Register SDMA reset callbacks +* @funcs: Pointer to the callback structure containing pre_reset and post_reset functions +* +* This function allows KFD and AMDGPU to register their own callbacks for handling +* pre-reset and post-reset operations for engine reset. These are needed because engine +* reset will stop all queues on that engine. +*/ +void amdgpu_sdma_register_on_reset_callbacks (struct amdgpu_device *adev,struct sdma_on_reset_funcs *funcs) +{ +if (!funcs) +return ; + +/* Initialize the list node in the callback structure */ +INIT_LIST_HEAD (&funcs->list); + +/* Add the callback structure to the global list */ +list_add_tail (&funcs->list, &adev->sdma.reset_callback_list); +} + +/** +* amdgpu_sdma_reset_engine - Reset a specific SDMA engine +* @adev: Pointer to the AMDGPU device +* @instance_id: ID of the SDMA engine instance to reset +* +* This function performs the following steps: +* 1. Calls all registered pre_reset callbacks to allow KFD and AMDGPU to save their state. +* 2. Resets the specified SDMA engine instance. +* 3. Calls all registered post_reset callbacks to allow KFD and AMDGPU to restore their state. +* +* Returns: 0 on success, or a negative error code on failure. +*/ +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id) +{ +struct sdma_on_reset_funcs *funcs; +int ret; + +/* Invoke all registered pre_reset callbacks */ +list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) { +if (funcs->pre_reset) { + ret = funcs->pre_reset (adev, instance_id); +if (ret) { +dev_err (adev->dev, +"beforeReset callback failed for instance %u: %d\n" , + instance_id, ret); +return ret; + } + } + } + +/* Perform the SDMA reset for the specified instance */ + ret =amdgpu_dpm_reset_sdma (adev,1 << instance_id); +if (ret) { +dev_err (adev->dev,"Failed to reset SDMA instance %u\n" , instance_id); +return ret; + } + +/* Invoke all registered post_reset callbacks */ +list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) { +if (funcs->post_reset) { + ret = funcs->post_reset (adev, instance_id); +if (ret) { +dev_err (adev->dev, +"afterReset callback failed for instance %u: %d\n" , + instance_id, ret); +return ret; + } + } + } + +return 0 ; +}
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +11 -0
@@ -98,6 +98,13 @@ struct amdgpu_sdma_ras {struct amdgpu_ras_block_object ras_block; }; +struct sdma_on_reset_funcs { +int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id); +int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id); +/* Linked list node to store this structure in a list; */ +struct list_head list; +}; +struct amdgpu_sdma {struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES ];struct amdgpu_irq_src trap_irq;
@@ -118,6 +125,7 @@ struct amdgpu_sdma {struct amdgpu_sdma_ras *ras;uint32_t *ip_dump;uint32_t supported_reset; +struct list_head reset_callback_list; };/*
@@ -157,6 +165,9 @@ struct amdgpu_buffer_funcs { uint32_t byte_count); }; +void amdgpu_sdma_register_on_reset_callbacks (struct amdgpu_device *adev,struct sdma_on_reset_funcs *funcs); +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id); +#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer (adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -1
@@ -1477,7 +1477,7 @@ static int sdma_v4_4_2_sw_init(struct amdgpu_ip_block *ip_block) r =amdgpu_sdma_sysfs_reset_mask_init (adev);if (r)return r; - +INIT_LIST_HEAD (&adev->sdma.reset_callback_list);return r; }
Signature · 1 line
2.25.1
PATCH v7 2/9 drm/amdgpu/sdma: Refactor SDMA reset functionality and add callback support
From: "[email protected]" <[email protected]>
This patch refactors the SDMA reset functionality in the sdma_v4_4_2 driver to improve modularity and support shared usage between AMDGPU and KFD. The changes include:
1. **Refactored SDMA Reset Logic**:
- Split the sdma_v4_4_2_reset_queue function into two separate functions:
- sdma_v4_4_2_stop_queue: Stops the SDMA queue before reset.
- sdma_v4_4_2_restore_queue: Restores the SDMA queue after reset.
- These functions are now used as callbacks for the shared reset mechanism.
2. **Added Callback Support**:
- Introduced a new structure sdma_v4_4_2_reset_funcs to hold the stop and restore callbacks.
- Added sdma_v4_4_2_set_reset_funcs to register these callbacks with the shared reset mechanism using amdgpu_set_on_reset_callbacks.
3. **Fixed Reset Queue Function**:
- Modified sdma_v4_4_2_reset_queue to use the shared amdgpu_sdma_reset_queue function, ensuring consistency across the driver.
This patch ensures that SDMA reset functionality is more modular, reusable, and aligned with the shared reset mechanism between AMDGPU and KFD.
v2: Renamed sdma_v4_4_2_set_reset_funcs to sdma_v4_4_2_set_engine_reset_funcs.
Renamed sdma_v4_4_2_reset_funcs to sdma_v4_4_2_engine_reset_funcs.(Alex)
--- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 32 +++++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +28 -4
@@ -105,6 +105,7 @@ static void sdma_v4_4_2_set_buffer_funcs(struct amdgpu_device *adev);static void sdma_v4_4_2_set_vm_pte_funcs (struct amdgpu_device *adev);static void sdma_v4_4_2_set_irq_funcs (struct amdgpu_device *adev);static void sdma_v4_4_2_set_ras_funcs (struct amdgpu_device *adev); +static void sdma_v4_4_2_set_engine_reset_funcs (struct amdgpu_device *adev);static u32 sdma_v4_4_2_get_reg_offset (struct amdgpu_device *adev,u32 instance,u32 offset)
@@ -1330,6 +1331,7 @@ static int sdma_v4_4_2_early_init(struct amdgpu_ip_block *ip_block)sdma_v4_4_2_set_vm_pte_funcs (adev);sdma_v4_4_2_set_irq_funcs (adev);sdma_v4_4_2_set_ras_funcs (adev); +sdma_v4_4_2_set_engine_reset_funcs (adev);return 0 ; }
@@ -1605,8 +1607,14 @@ static int sdma_v4_4_2_soft_reset(struct amdgpu_ip_block *ip_block)static int sdma_v4_4_2_reset_queue (struct amdgpu_ring *ring,unsigned int vmid) {struct amdgpu_device *adev = ring->adev; -int i, r; +u32 id =GET_INST (SDMA0 , ring->me); +return amdgpu_sdma_reset_engine (adev, id); +} + +static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev,uint32_t instance_id) +{u32 inst_mask; +struct amdgpu_ring *ring = &adev->sdma.instance[instance_id].ring;if (amdgpu_sriov_vf (adev))return -EINVAL ;
@@ -1617,10 +1625,16 @@ static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)if (adev->sdma.has_page_queue)sdma_v4_4_2_inst_page_stop (adev, inst_mask); - r =amdgpu_dpm_reset_sdma (adev,1 <<GET_INST (SDMA0 , ring->me)); -if (r) -return r; +return 0 ; +} +static int sdma_v4_4_2_restore_queue (struct amdgpu_device *adev,uint32_t instance_id) +{ +int i; +u32 inst_mask; +struct amdgpu_ring *ring = &adev->sdma.instance[instance_id].ring; + + inst_mask =1 << ring->me;udelay (50 );for (i =0 ; i < adev->usec_timeout; i++) {
@@ -1638,6 +1652,16 @@ static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)return sdma_v4_4_2_inst_start (adev, inst_mask, true); } +static struct sdma_on_reset_funcs sdma_v4_4_2_engine_reset_funcs = { + .pre_reset = sdma_v4_4_2_stop_queue, + .post_reset = sdma_v4_4_2_restore_queue, +}; + +static void sdma_v4_4_2_set_engine_reset_funcs (struct amdgpu_device *adev) +{ +amdgpu_sdma_register_on_reset_callbacks (adev, &sdma_v4_4_2_engine_reset_funcs); +} + static int sdma_v4_4_2_set_trap_irq_state(struct amdgpu_device *adev, struct amdgpu_irq_src *source, unsigned type,
Signature · 1 line
2.25.1
PATCH v7 3/9 drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization
In reply to [email protected]From: "[email protected]" <[email protected]>
This commit introduces a caller parameter to the amdgpu_sdma_reset_instance function to differentiate between reset requests originating from the KGD and KFD.
This change ensures proper synchronization between KGD and KFD during SDMA resets.
If the caller is KFD, the function now acquires and releases the scheduler lock (ring->sched.job_list_lock) to protect the SDMA queue during the reset.
These changes prevent race conditions and ensure safe SDMA reset operations when initiated by KFD, improving system stability and reliability.
V2: replace the ring_lock with the existed the scheduler
locks for the queues (ring->sched) on the sdma engine.(Alex)
v3: call drm_sched_wqueue_stop() rather than job_list_lock.
If a GPU ring reset was already initiated for one ring at amdgpu_job_timedout, skip resetting that ring and call drm_sched_wqueue_stop()
for the other rings (Alex)
replace the common lock (sdma_reset_lock) with DQM lock to
to resolve reset races between the two driver sections during KFD eviction.(Jon)
Rename the caller to Reset_src and
Change AMDGPU_RESET_SRC_SDMA_KGD/KFD to AMDGPU_RESET_SRC_SDMA_HWS/RING (Jon)
v4: restart the wqueue if the reset was successful,
or fall back to a full adapter reset. (Alex)
move definition of reset source to enumeration AMDGPU_RESET_SRCS, and check reset src in amdgpu_sdma_reset_instance (Jon)
v5: Call amdgpu_amdkfd_suspend/resume at the start/end of reset function respectively under !SRC_HWS
conditions only (Jon)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 65 ++++++++++++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 6 +-- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 8 +-- 4 files changed, 67 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +2 -0
@@ -43,6 +43,8 @@ enum AMDGPU_RESET_SRCS {AMDGPU_RESET_SRC_MES ,AMDGPU_RESET_SRC_HWS ,AMDGPU_RESET_SRC_USER , +AMDGPU_RESET_SRC_SDMA_RING , + AMDGPU_RESET_SRC_SDMA_HWS, }; struct amdgpu_reset_context {
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +57 -8
110 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +3 -3
@@ -99,8 +99,8 @@ struct amdgpu_sdma_ras { };struct sdma_on_reset_funcs { -int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id); -int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id); +int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id,int src); +int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id,int src);/* Linked list node to store this structure in a list; */ struct list_head list; };
@@ -166,7 +166,7 @@ struct amdgpu_buffer_funcs { };void amdgpu_sdma_register_on_reset_callbacks (struct amdgpu_device *adev,struct sdma_on_reset_funcs *funcs); -int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id); +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id,int src);#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer (adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +5 -3
@@ -30,6 +30,7 @@#include "amdgpu_xcp.h" #include "amdgpu_ucode.h" #include "amdgpu_trace.h" +#include "amdgpu_reset.h" #include "sdma/sdma_4_4_2_offset.h" #include "sdma/sdma_4_4_2_sh_mask.h"
@@ -1480,6 +1481,7 @@ static int sdma_v4_4_2_sw_init(struct amdgpu_ip_block *ip_block)if (r)return r;INIT_LIST_HEAD (&adev->sdma.reset_callback_list); +return r; }
@@ -1608,10 +1610,10 @@ static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid) {struct amdgpu_device *adev = ring->adev;u32 id =GET_INST (SDMA0 , ring->me); -return amdgpu_sdma_reset_engine (adev, id); +return amdgpu_sdma_reset_engine (adev, id,AMDGPU_RESET_SRC_SDMA_RING ); } -static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev,uint32_t instance_id) +static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev,uint32_t instance_id,int src) {u32 inst_mask;struct amdgpu_ring *ring = &adev->sdma.instance[instance_id].ring;
@@ -1628,7 +1630,7 @@ static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev, uint32_t instance_return 0 ; } -static int sdma_v4_4_2_restore_queue (struct amdgpu_device *adev,uint32_t instance_id) +static int sdma_v4_4_2_restore_queue (struct amdgpu_device *adev,uint32_t instance_id,int src) {int i;u32 inst_mask;
Signature · 1 line
2.25.1
Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization
Quoted 94 lines · On 2/13/2025 11:17 AM, [email protected] wrote:
From: "[email protected]" <[email protected]>
This commit introduces a caller parameter to the
amdgpu_sdma_reset_instancefunction to differentiate between reset requests originating from the KGD and KFD.
This change ensures proper synchronization between KGD and KFD during SDMA resets.If the caller is KFD, the function now acquires and releases the scheduler lock (
ring->sched.job_list_lock) to protect the SDMA queue during the reset.These changes prevent race conditions and ensure safe SDMA reset operations when initiated by KFD, improving system stability and reliability.
V2: replace the
ring_lockwith the existed the schedulerlocks for the queues (ring->sched) on the sdma engine.(Alex)v3: call
drm_sched_wqueue_stop()rather thanjob_list_lock.
If a GPU ring reset was already initiated for one ring atamdgpu_job_timedout, skip resetting that ring and calldrm_sched_wqueue_stop()
for the other rings (Alex)replace the common lock (
sdma_reset_lock) with DQM lock to
to resolve reset races between the two driver sections during KFD eviction.(Jon)Rename the caller to
Reset_srcand
Change AMDGPU_RESET_SRC_SDMA_KGD/KFD to AMDGPU_RESET_SRC_SDMA_HWS/RING (Jon)
v4: restart the wqueue if the reset was successful,
or fall back to a full adapter reset. (Alex)move definition of reset source to enumeration
AMDGPU_RESET_SRCS, and check reset src inamdgpu_sdma_reset_instance(Jon)v5: Call amdgpu_amdkfd_suspend/resume at the start/end of reset function respectively under !SRC_HWS
conditions only (Jon)Suggested-by Alex Deucher <[email protected]>Suggested-by Jiadong Zhu <[email protected]>Suggested-by Jonathan Kim <[email protected]>Signed-off-by Jesse Zhang <[email protected]>Reviewed-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 65 ++++++++++++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 6 +-- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 8 +-- 4 files changed, 67 insertions(+), 14 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +2
-0@@ -43,6 +43,8 @@ enum AMDGPU_RESET_SRCS {AMDGPU_RESET_SRC_MES ,AMDGPU_RESET_SRC_HWS ,AMDGPU_RESET_SRC_USER , +AMDGPU_RESET_SRC_SDMA_RING , + AMDGPU_RESET_SRC_SDMA_HWS, }; struct amdgpu_reset_context {drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +9
-2@@ -25,6 +25,7 @@#include "amdgpu.h" #include "amdgpu_sdma.h" #include "amdgpu_ras.h" +#include "amdgpu_reset.h" #define AMDGPU_CSA_SDMA_SIZE 64/* SDMA CSA reside in the 3rd page of CSA */ @@ -485,6 +486,7 @@ void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct* amdgpu_sdma_reset_engine - Reset a specific SDMA engine * @adev: Pointer to the AMDGPU device * @instance_id: ID of the SDMA engine instance to reset +* @src: The source of reset function (KGD or KFD) * * This function performs the following steps: * 1. Calls all registered pre_reset callbacks to allow KFD and AMDGPU to save their state. @@ -493,20 +495,49 @@ void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct* * Returns: 0 on success, or a negative error code on failure. */ -int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id) +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id,int src) {struct sdma_on_reset_funcs *funcs; -int ret; +int ret =0 ; +struct amdgpu_sdma_instance *sdma_instance = &adev->sdma.instance[instance_id];; +struct amdgpu_ring *gfx_ring = &sdma_instance->ring; +struct amdgpu_ring *page_ring = &sdma_instance->page; +bool gfx_sched_stopped = false, page_sched_stopped = false; +
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct · line 516
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +10
-0+/* Check if the reset source is valid for SDMA ring reset */ +if (src !=AMDGPU_RESET_SRC_SDMA_RING && src !=AMDGPU_RESET_SRC_HWS ) +return -EINVAL ; + +/* Suspend KFD if the reset source is not SDMA_HWS. +* prevent the destruction of in-flight healthy user queue packets and +* avoid race conditions between KFD and KGD during the reset process. +*/ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_suspend (adev, false);
It this has to be done here, what's the idea behind registering a separate pre/post callback for KFD initiated resets?
Thanks,
Lijo
Quoted 139 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +38
-6+ +/* Stop the scheduler's work queue for the GFX and page rings if they are running. +* This ensures that no new tasks are submitted to the queues while +* the reset is in progress. +*/ +if (!amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_stop (&gfx_ring->sched); + gfx_sched_stopped = true;; + } + +if (adev->sdma.has_page_queue && !amdgpu_ring_sched_ready (page_ring)) { +drm_sched_wqueue_stop (&page_ring->sched); + page_sched_stopped = true; + }/* Invoke all registered pre_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->pre_reset) { - ret = funcs->pre_reset (adev, instance_id); + ret = funcs->pre_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"beforeReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } }@@ -515,21 +546,39 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id) ret =amdgpu_dpm_reset_sdma (adev,1 << instance_id);if (ret) {dev_err (adev->dev,"Failed to reset SDMA instance %u\n" , instance_id); -return ret; + goto exit; }/* Invoke all registered post_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->post_reset) { - ret = funcs->post_reset (adev, instance_id); + ret = funcs->post_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"afterReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } } -return 0 ; +exit: +/* Restart the scheduler's work queue for the GFX and page rings +* if they were stopped by this function. This allows new tasks +* to be submitted to the queues after the reset is complete. +*/ +if (ret) { +if (gfx_sched_stopped &&amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_start (&gfx_ring->sched); + } +if (page_sched_stopped &&amdgpu_ring_sched_ready (page_ring)) { +drm_sched_wqueue_start (&page_ring->sched); + } + } + +/* Resume KFD if the reset source is not SDMA_HWS */ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_resume (adev, false); + +return ret; }drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +3
-3@@ -99,8 +99,8 @@ struct amdgpu_sdma_ras { };struct sdma_on_reset_funcs { -int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id); -int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id); +int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id,int src); +int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id,int src);/* Linked list node to store this structure in a list; */ struct list_head list; };@@ -166,7 +166,7 @@ struct amdgpu_buffer_funcs { };void amdgpu_sdma_register_on_reset_callbacks (struct amdgpu_device *adev,struct sdma_on_reset_funcs *funcs); -int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id); +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id,int src);#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer (adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +5
-3@@ -30,6 +30,7 @@#include "amdgpu_xcp.h" #include "amdgpu_ucode.h" #include "amdgpu_trace.h" +#include "amdgpu_reset.h" #include "sdma/sdma_4_4_2_offset.h" #include "sdma/sdma_4_4_2_sh_mask.h" @@ -1480,6 +1481,7 @@ static int sdma_v4_4_2_sw_init(struct amdgpu_ip_block *ip_block)if (r)return r;INIT_LIST_HEAD (&adev->sdma.reset_callback_list); +return r; }@@ -1608,10 +1610,10 @@ static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid) {struct amdgpu_device *adev = ring->adev;u32 id =GET_INST (SDMA0 , ring->me); -return amdgpu_sdma_reset_engine (adev, id); +return amdgpu_sdma_reset_engine (adev, id,AMDGPU_RESET_SRC_SDMA_RING ); } -static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev,uint32_t instance_id) +static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev,uint32_t instance_id,int src) {u32 inst_mask;struct amdgpu_ring *ring = &adev->sdma.instance[instance_id].ring;@@ -1628,7 +1630,7 @@ static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev, uint32_t instance_return 0 ; } -static int sdma_v4_4_2_restore_queue (struct amdgpu_device *adev,uint32_t instance_id) +static int sdma_v4_4_2_restore_queue (struct amdgpu_device *adev,uint32_t instance_id,int src) {int i;u32 inst_mask;
RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization
[AMD Official Use Only - AMD Internal Distribution Only]
Hi Lijo,
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, February 18, 2025 11:36 AM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization
Quoted 100 lines · On 2/13/2025 11:17 AM, [email protected] wrote:
From: "[email protected]" <[email protected]>
This commit introduces a caller parameter to the
amdgpu_sdma_reset_instancefunction to differentiate between reset requests originating from the KGD and KFD. This change ensures proper synchronization between KGD and KFD during SDMA resets.If the caller is KFD, the function now acquires and releases the scheduler lock (
ring->sched.job_list_lock) to protect the SDMA queue during the reset.These changes prevent race conditions and ensure safe SDMA reset operations when initiated by KFD, improving system stability and reliability.
V2: replace the
ring_lockwith the existed the schedulerlocks for the queues (ring->sched) on the sdma engine.(Alex)v3: call
drm_sched_wqueue_stop()rather thanjob_list_lock.
If a GPU ring reset was already initiated for one ring atamdgpu_job_timedout, skip resetting that ring and calldrm_sched_wqueue_stop()
for the other rings (Alex)replace the common lock (
sdma_reset_lock) with DQM lock to to resolve reset races between the two driver sections during KFD
eviction.(Jon)Rename the caller to
Reset_srcand Change AMDGPU_RESET_SRC_SDMA_KGD/KFD to
AMDGPU_RESET_SRC_SDMA_HWS/RING (Jon)
v4: restart the wqueue if the reset was successful,
or fall back to a full adapter reset. (Alex)move definition of reset source to enumeration
AMDGPU_RESET_SRCS, and check reset src inamdgpu_sdma_reset_instance(Jon)v5: Call amdgpu_amdkfd_suspend/resume at the start/end of reset function respectively under !SRC_HWS
conditions only (Jon)Suggested-by Alex Deucher <[email protected]>Suggested-by Jiadong Zhu <[email protected]>Suggested-by Jonathan Kim <[email protected]>Signed-off-by Jesse Zhang <[email protected]>Reviewed-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 65 ++++++++++++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 6 +-- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 8 +-- 4 files changed, 67 insertions(+), 14 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +2
-0@@ -43,6 +43,8 @@ enum AMDGPU_RESET_SRCS {AMDGPU_RESET_SRC_MES ,AMDGPU_RESET_SRC_HWS ,AMDGPU_RESET_SRC_USER , +AMDGPU_RESET_SRC_SDMA_RING , + AMDGPU_RESET_SRC_SDMA_HWS, }; struct amdgpu_reset_context {drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1
-0@@ -25,6 +25,7 @@#include "amdgpu.h" #include "amdgpu_sdma.h" #include "amdgpu_ras.h" +#include "amdgpu_reset.h" #define AMDGPU_CSA_SDMA_SIZE 64 /* SDMA CSA reside in the 3rd page of CSA */ @@ -485,6 +486,7 @@ voidamdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, struct
*amdgpu_sdma_reset_engine- Reset a specific SDMA engine
* @adev: Pointer to the AMDGPU device
* @instance_id: ID of the SDMA engine instance to reset
+ * @src: The source of reset function (KGD or KFD)
*
* This function performs the following steps:
* 1. Calls all registeredpre_resetcallbacks to allow KFD and AMDGPU to save their state.drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +8
-2@@ -493,20 +495,49 @@ void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct* * Returns: 0 on success, or a negative error code on failure. */ -int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t instance_id) +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t +instance_id,int src) {struct sdma_on_reset_funcs *funcs; -int ret; +int ret =0 ; +struct amdgpu_sdma_instance *sdma_instance = &adev->sdma.instance[instance_id];; +struct amdgpu_ring *gfx_ring = &sdma_instance->ring; +struct amdgpu_ring *page_ring = &sdma_instance->page; +bool gfx_sched_stopped = false, page_sched_stopped = false; +
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct · line 518
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +10
-0+/* Check if the reset source is valid for SDMA ring reset */ +if (src !=AMDGPU_RESET_SRC_SDMA_RING && src !=AMDGPU_RESET_SRC_HWS ) +return -EINVAL ; + +/* Suspend KFD if the reset source is not SDMA_HWS. +* prevent the destruction of in-flight healthy user queue packets and +* avoid race conditions between KFD and KGD during the reset process. +*/ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_suspend (adev, false);
It this has to be done here, what's the idea behind registering a separate pre/post callback for KFD initiated resets?
Register pre/post reset callbacks to allow KFD and AMDGPU to save/restore their state. Jon will complete the kfd pre/post callbacks.
Maybe he will integrate KFD pause/resume into the kfd pre-reset/post-reset callback system Or call them directly. Both suit me.
Thanks
Jesse
Thanks,
Lijo
Quoted 150 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +38
-6+ +/* Stop the scheduler's work queue for the GFX and page rings if they are running. +* This ensures that no new tasks are submitted to the queues while +* the reset is in progress. +*/ +if (!amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_stop (&gfx_ring->sched); + gfx_sched_stopped = true;; + } + +if (adev->sdma.has_page_queue && !amdgpu_ring_sched_ready (page_ring)) { +drm_sched_wqueue_stop (&page_ring->sched); + page_sched_stopped = true; + }/* Invoke all registered pre_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->pre_reset) { - ret = funcs->pre_reset (adev, instance_id); + ret = funcs->pre_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"beforeReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } }@@ -515,21 +546,39 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id) ret =amdgpu_dpm_reset_sdma (adev,1 << instance_id);if (ret) {dev_err (adev->dev,"Failed to reset SDMA instance %u\n" , instance_id); -return ret; + goto exit; }/* Invoke all registered post_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->post_reset) { - ret = funcs->post_reset (adev, instance_id); + ret = funcs->post_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"afterReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } } -return 0 ; +exit: +/* Restart the scheduler's work queue for the GFX and page rings +* if they were stopped by this function. This allows new tasks +* to be submitted to the queues after the reset is complete. +*/ +if (ret) { +if (gfx_sched_stopped &&amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_start (&gfx_ring->sched); + } +if (page_sched_stopped &&amdgpu_ring_sched_ready (page_ring)) { +drm_sched_wqueue_start (&page_ring->sched); + } + } + +/* Resume KFD if the reset source is not SDMA_HWS */ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_resume (adev, false); + +return ret; }drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +3
-2@@ -99,8 +99,8 @@ struct amdgpu_sdma_ras { };struct sdma_on_reset_funcs { -int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id); -int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id); +int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id,int src); +int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id, +int src);/* Linked list node to store this structure in a list; */ struct list_head list; };@@ -166,7 +166,7 @@ struct amdgpu_buffer_funcs { };void amdgpu_sdma_register_on_reset_callbacks (struct amdgpu_device *adev,struct sdma_on_reset_funcs *funcs); -int
amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2
-0+int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t +instance_id,int src);#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t)(adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t)) #define
amdgpu_emit_fill_buffer(adev, ib, s, d, b)(adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b)) diff --gita/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.cb/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
index29a123be90b7..50a086264792100644drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +8
-3@@ -30,6 +30,7 @@#include "amdgpu_xcp.h" #include "amdgpu_ucode.h" #include "amdgpu_trace.h" +#include "amdgpu_reset.h" #include "sdma/sdma_4_4_2_offset.h" #include "sdma/sdma_4_4_2_sh_mask.h" @@ -1480,6 +1481,7 @@ static int sdma_v4_4_2_sw_init(struct amdgpu_ip_block *ip_block)if (r)return r;INIT_LIST_HEAD (&adev->sdma.reset_callback_list); +return r; }@@ -1608,10 +1610,10 @@ static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid) {struct amdgpu_device *adev = ring->adev;u32 id =GET_INST (SDMA0 , ring->me); -return amdgpu_sdma_reset_engine (adev, id); +return amdgpu_sdma_reset_engine (adev, id, +AMDGPU_RESET_SRC_SDMA_RING ); } -static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev, uint32_t instance_id) +static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev, +uint32_t instance_id,int src) {u32 inst_mask;struct amdgpu_ring *ring = &adev->sdma.instance[instance_id].ring;@@ -1628,7 +1630,7 @@ static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev, uint32_t instance_return 0 ; } -static int sdma_v4_4_2_restore_queue (struct amdgpu_device *adev, uint32_t instance_id) +static int sdma_v4_4_2_restore_queue (struct amdgpu_device *adev, +uint32_t instance_id,int src) {int i;u32 inst_mask;
RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization
In reply to Lazar, Lijo[Public]
Quoted 132 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, February 17, 2025 10:36 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 3 lines · On 2/13/2025 11:17 AM, [email protected] wrote:
From: "[email protected]" <[email protected]>
This commit introduces a caller parameter to the
amdgpu_sdma_reset_instancefunction to differentiate
Quoted 2 lines
between reset requests originating from the KGD and KFD.
This change ensures proper synchronization between KGD and KFD during SDMAresets.
Quoted 2 lines
If the caller is KFD, the function now acquires and releases the scheduler lock
(
ring->sched.job_list_lock)Quoted 13 lines
to protect the SDMA queue during the reset.
These changes prevent race conditions and ensure safe SDMA reset operations when initiated by KFD, improving system stability and reliability.
V2: replace the
ring_lockwith the existed the schedulerlocks for the queues (ring->sched) on the sdma engine.(Alex)v3: call
drm_sched_wqueue_stop()rather thanjob_list_lock.
If a GPU ring reset was already initiated for one ring atamdgpu_job_timedout, skip resetting that ring and calldrm_sched_wqueue_stop()
for the other rings (Alex)Quoted 5 lines
replace the common lock (
sdma_reset_lock) with DQM lock to
to resolve reset races between the two driver sections during KFD eviction.(Jon)Rename the caller to
Reset_srcand
Change AMDGPU_RESET_SRC_SDMA_KGD/KFD toAMDGPU_RESET_SRC_SDMA_HWS/RING (Jon)
Quoted 7 lines
v4: restart the wqueue if the reset was successful,
or fall back to a full adapter reset. (Alex)move definition of reset source to enumeration
AMDGPU_RESET_SRCS, and check reset src inamdgpu_sdma_reset_instance(Jon)v5: Call amdgpu_amdkfd_suspend/resume at the start/end of reset function
respectively under !SRC_HWS
Quoted 7 lines
conditions only (Jon)
Suggested-by Alex Deucher <[email protected]>Suggested-by Jiadong Zhu <[email protected]>Suggested-by Jonathan Kim <[email protected]>Signed-off-by Jesse Zhang <[email protected]>Reviewed-by Alex Deucher <[email protected]>Review
Quoted 8 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 65 ++++++++++++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 6 +-- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 8 +-- 4 files changed, 67 insertions(+), 14 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_reset.hReview
Quoted 13 lines
index
4d9b9701139b..5b86e12ff9fe100644drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +2
-0@@ -43,6 +43,8 @@ enum AMDGPU_RESET_SRCS {AMDGPU_RESET_SRC_MES ,AMDGPU_RESET_SRC_HWS ,AMDGPU_RESET_SRC_USER , +AMDGPU_RESET_SRC_SDMA_RING , + AMDGPU_RESET_SRC_SDMA_HWS, }; struct amdgpu_reset_context {(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.cdrivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct
Quoted 12 lines
index
fe39198307ec..808c7112ef10100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1
-0@@ -25,6 +25,7 @@#include "amdgpu.h" #include "amdgpu_sdma.h" #include "amdgpu_ras.h" +#include "amdgpu_reset.h" #define AMDGPU_CSA_SDMA_SIZE 64/* SDMA CSA reside in the 3rd page of CSA */ @@ -485,6 +486,7 @@ void amdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structdrivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1
-0* amdgpu_sdma_reset_engine - Reset a specific SDMA engine * @adev: Pointer to the AMDGPU device * @instance_id: ID of the SDMA engine instance to reset +* @src: The source of reset function (KGD or KFD) * * This function performs the following steps: * 1. Calls all registered pre_reset callbacks to allow KFD and AMDGPU to save their state.
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +0
-0@@ -493,20 +495,49 @@ void amdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structdrivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +0
-1* * Returns: 0 on success, or a negative error code on failure. */ -int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct · line 498
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1
-0+int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id, int src)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +8
-1{ struct sdma_on_reset_funcs *funcs; -int ret; + int ret = 0; + struct amdgpu_sdma_instance *sdma_instance = &adev- sdma.instance[instance_id];; + struct amdgpu_ring *gfx_ring = &sdma_instance->ring; + struct amdgpu_ring *page_ring = &sdma_instance->page; + bool gfx_sched_stopped = false, page_sched_stopped = false; + + /* Check if the reset source is valid for SDMA ring reset */ + if (src != AMDGPU_RESET_SRC_SDMA_RING && src !=
AMDGPU_RESET_SRC_HWS)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct · line 516
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +8
-0+return -EINVAL ; + +/* Suspend KFD if the reset source is not SDMA_HWS. +* prevent the destruction of in-flight healthy user queue packets and +* avoid race conditions between KFD and KGD during the reset process. +*/ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_suspend (adev, false);
Quoted 2 lines
It this has to be done here, what's the idea behind registering a separate pre/post callback for KFD initiated resets?
The problem is that for SDMA v5.x and below, a single soft reset call will reset all queues on the target SDMA engine.
If the KGD calls the reset, a transient KFD suspend/resume around the reset will guarantee that healthy user queues survive the reset.
If the KFD calls the reset, it will only do so during preemption failure, and we don't want to suspend and resume the KFD again when the KFD calls this function.
The KFD needs to call this common function to not disturb GFX and paging queues for the same reason KGD resets need to be wary of KFD queues.
In the case of preemption failure and a KFD initiated reset, the KFD is holding the device wide preemption lock, so if the KGD is trying to reset as well, it will have to wait on its own KFD suspend call until the KFD is done its own reset.
I think SDMA6+ can target specific queues via MMIO reg writes, but I see in the KGD code that soft_reset for SDMA 6+ does a sweep of all engines so we would still need to keep KFD queues safe (I'm not familiar with this chunk of the code or the need for sweeping all engines on the KGD side). So I'm not sure if Jesse had concerns about potential multiple calls being made in other parts of the code and maybe this was some way to simplify things.
Either way, not sure if it's simpler to drop the reset source param and have the KGD remember to unconditionally KFD suspend/resume around the soft reset call for each IP version, or keep the reset source param here so that we only have to remember to do this once.
Jon
Quoted 162 lines
Thanks,
Lijodrivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct · line 519
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +2
-0+ +/* Stop the scheduler's work queue for the GFX and page rings if they are running.
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +9
-0+* This ensures that no new tasks are submitted to the queues while +* the reset is in progress. +*/ +if (!amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_stop (&gfx_ring->sched); + gfx_sched_stopped = true;; + } + + if (adev->sdma.has_page_queue&& !amdgpu_ring_sched_ready(page_ring)) {
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c int amdgpu_sdma_reset_engine(struct amdgpu_device
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +5
-2+drm_sched_wqueue_stop (&page_ring->sched); + page_sched_stopped = true; + }/* Invoke all registered pre_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->pre_reset) { - ret = funcs->pre_reset (adev, instance_id); + ret = funcs->pre_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"beforeReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } }}drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +0
-0@@ -515,21 +546,39 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device*adev,
uint32_tinstance_id)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id)
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +0
-0ret =amdgpu_dpm_reset_sdma (adev,1 << instance_id);if (ret) { dev_err(adev->dev, "Failed to reset SDMA instance %u\n",
instance_id);Review
Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +22
-4-return ret; + goto exit; }/* Invoke all registered post_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->post_reset) { - ret = funcs->post_reset (adev, instance_id); + ret = funcs->post_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"afterReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } } -return 0 ; +exit: +/* Restart the scheduler's work queue for the GFX and page rings +* if they were stopped by this function. This allows new tasks +* to be submitted to the queues after the reset is complete. +*/ +if (ret) { +if (gfx_sched_stopped &&amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_start (&gfx_ring->sched); + } +if (page_sched_stopped &&amdgpu_ring_sched_ready (page_ring)) { +drm_sched_wqueue_start (&page_ring->sched); + } + } + +/* Resume KFD if the reset source is not SDMA_HWS */ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_resume (adev, false); + +return ret; }(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.hQuoted 15 lines
index
f91d75848557..2ef2da772254100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2
-2@@ -99,8 +99,8 @@ struct amdgpu_sdma_ras { };struct sdma_on_reset_funcs { -int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id); -int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id); +int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id,int src); +int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id,int src);/* Linked list node to store this structure in a list; */ struct list_head list; };drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { · line 168
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0@@ -166,7 +166,7 @@ struct amdgpu_buffer_funcs { }; void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev,struct
sdma_on_reset_funcs*funcs);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-1-int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1
-0+int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id, int src);Review
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)- mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer (adev, ib, s, d, b) (adev)->mman.buffer_funcs-
emit_fill_buffer((ib), (s), (d), (b))(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.cdrivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_sw_init(struct
Quoted 12 lines
index
29a123be90b7..50a086264792100644drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0@@ -30,6 +30,7 @@#include "amdgpu_xcp.h" #include "amdgpu_ucode.h" #include "amdgpu_trace.h" +#include "amdgpu_reset.h" #include "sdma/sdma_4_4_2_offset.h" #include "sdma/sdma_4_4_2_sh_mask.h" @@ -1480,6 +1481,7 @@ static int sdma_v4_4_2_sw_init(struct
amdgpu_ip_block*ip_block)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0if (r)return r;INIT_LIST_HEAD (&adev->sdma.reset_callback_list); +return r; }@@ -1608,10 +1610,10 @@ static int sdma_v4_4_2_reset_queue(struct
amdgpu_ring*ring, unsigned int vmid)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-1{struct amdgpu_device *adev = ring->adev;u32 id =GET_INST (SDMA0 , ring->me); -return amdgpu_sdma_reset_engine (adev, id); + return amdgpu_sdma_reset_engine(adev, id,
AMDGPU_RESET_SRC_SDMA_RING);drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct · line 1614
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1} -static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev, uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct · line 1616
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0+static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev, uint32_t
instance_id, int src)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_stop_queue(struct
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-0{u32 inst_mask;struct amdgpu_ring *ring = &adev->sdma.instance[instance_id].ring;@@ -1628,7 +1630,7 @@ static int sdma_v4_4_2_stop_queue(struct
amdgpu_device*adev,uint32_tinstance_drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev, uint32_t instance_
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1return 0 ; } -static int sdma_v4_4_2_restore_queue(struct amdgpu_device *adev, uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_stop_queue(struct · line 1633
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0+static int sdma_v4_4_2_restore_queue(struct amdgpu_device *adev, uint32_t
instance_id, int src)Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-0{int i;u32 inst_mask;
Deucher, Alexander
maintainerRE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization
[Public]
Quoted 168 lines
-----Original Message-----
From: Kim, Jonathan <[email protected]>
Sent: Tuesday, February 18, 2025 12:42 PM
To: Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization[Public]
Quoted 40 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, February 17, 2025 10:36 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 4 lines · On 2/13/2025 11:17 AM, [email protected] wrote:
From: "[email protected]" <[email protected]>
This commit introduces a caller parameter to the
amdgpu_sdma_reset_instancefunction to differentiate
Quoted 3 lines
between reset requests originating from the KGD and KFD. This change ensures proper synchronization between KGD and KFD during SDMA
resets.
Quoted 3 lines
If the caller is KFD, the function now acquires and releases the scheduler lock
(
ring->sched.job_list_lock)Quoted 13 lines
to protect the SDMA queue during the reset.
These changes prevent race conditions and ensure safe SDMA reset operations when initiated by KFD, improving system stability and reliability.
V2: replace the
ring_lockwith the existed the schedulerlocks for the queues (ring->sched) on the sdma engine.(Alex)v3: call
drm_sched_wqueue_stop()rather thanjob_list_lock.
If a GPU ring reset was already initiated for one ring atamdgpu_job_timedout, skip resetting that ring and calldrm_sched_wqueue_stop()
for the other rings (Alex)Quoted 11 lines
Quoted 6 lines
replace the common lock (
sdma_reset_lock) with DQM lock to to resolve reset races between the two driver sections during KFD
eviction.(Jon)Rename the caller to
Reset_srcand
Change AMDGPU_RESET_SRC_SDMA_KGD/KFD toAMDGPU_RESET_SRC_SDMA_HWS/RING (Jon)
Quoted 4 lines
v4: restart the wqueue if the reset was successful,
or fall back to a full adapter reset. (Alex)move definition of reset source to enumeration
AMDGPU_RESET_SRCS,and
Quoted 89 lines
Quoted 4 lines
check reset src in
amdgpu_sdma_reset_instance(Jon)v5: Call amdgpu_amdkfd_suspend/resume at the start/end of reset function
respectively under !SRC_HWS
Quoted 7 lines
conditions only (Jon)
Suggested-by Alex Deucher <[email protected]>Suggested-by Jiadong Zhu <[email protected]>Suggested-by Jonathan Kim <[email protected]>Signed-off-by Jesse Zhang <[email protected]>Reviewed-by Alex Deucher <[email protected]>Review
Quoted 8 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 65 ++++++++++++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 6 +-- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 8 +-- 4 files changed, 67 insertions(+), 14 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_reset.hReview
Quoted 13 lines
index
4d9b9701139b..5b86e12ff9fe100644drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +2
-0@@ -43,6 +43,8 @@ enum AMDGPU_RESET_SRCS {AMDGPU_RESET_SRC_MES ,AMDGPU_RESET_SRC_HWS ,AMDGPU_RESET_SRC_USER , +AMDGPU_RESET_SRC_SDMA_RING , + AMDGPU_RESET_SRC_SDMA_HWS, }; struct amdgpu_reset_context {(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.cQuoted 11 lines
index
fe39198307ec..808c7112ef10100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1
-0@@ -25,6 +25,7 @@#include "amdgpu.h" #include "amdgpu_sdma.h" #include "amdgpu_ras.h" +#include "amdgpu_reset.h" #define AMDGPU_CSA_SDMA_SIZE 64 /* SDMA CSA reside in the 3rd page of CSA */ @@ -485,6 +486,7 @@Quoted 1 line
void amdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 8 lines
*
amdgpu_sdma_reset_engine- Reset a specific SDMA engine
* @adev: Pointer to the AMDGPU device
* @instance_id: ID of the SDMA engine instance to reset
+ * @src: The source of reset function (KGD or KFD)
*
* This function performs the following steps:
* 1. Calls all registeredpre_resetcallbacks to allow KFD and
AMDGPU to savetheir state.
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +0
-0@@ -493,20 +495,49 @@ voidamdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 4 lines
*
* Returns: 0 on success, or a negative error code on failure. */
-int amdgpu_sdma_reset_engine(structamdgpu_device*adev,uint32_t
instance_id)Quoted 1 line
+int amdgpu_sdma_reset_engine(struct
amdgpu_device*adev,uint32_t
instance_id, int src)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct
Quoted 12 lines
{ struct sdma_on_reset_funcs *funcs;drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +2
-1-int ret; +int ret =0 ; + struct amdgpu_sdma_instance *sdma_instance = &adev-sdma.instance[instance_id];;
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +6
-0+struct amdgpu_ring *gfx_ring = &sdma_instance->ring; +struct amdgpu_ring *page_ring = &sdma_instance->page; +bool gfx_sched_stopped = false, page_sched_stopped = false; + +/* Check if the reset source is valid for SDMA ring reset */ + if (src != AMDGPU_RESET_SRC_SDMA_RING && src !=
AMDGPU_RESET_SRC_HWS)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct · line 516
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +8
-0+return -EINVAL ; + +/* Suspend KFD if the reset source is not SDMA_HWS. +* prevent the destruction of in-flight healthy user queue packets and +* avoid race conditions between KFD and KGD during the reset process. +*/ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_suspend (adev, false);Quoted 2 lines
It this has to be done here, what's the idea behind registering a separate pre/post callback for KFD initiated resets?
The problem is that for SDMA v5.x and below, a single soft reset call will reset all queues on the target SDMA engine.
If the KGD calls the reset, a transient KFD suspend/resume around the reset will guarantee that healthy user queues survive the reset.
If the KFD calls the reset, it will only do so during preemption failure, and we don't want to suspend and resume the KFD again when the KFD calls this function. The KFD needs to call this common function to not disturb GFX and paging queues for the same reason KGD resets need to be wary of KFD queues.
In the case of preemption failure and a KFD initiated reset, the KFD is holding the device wide preemption lock, so if the KGD is trying to reset as well, it will have to wait on its own KFD suspend call until the KFD is done its own reset.
Quoted 10 lines
I think SDMA6+ can target specific queues via MMIO reg writes, but I see in the KGD code that
soft_resetfor SDMA 6+ does a sweep of all engines so we would still need to keep KFD queues safe (I'm not familiar with this chunk of the code or the need for sweeping all engines on the KGD side).
So I'm not sure if Jesse had concerns about potential multiple calls being made in other parts of the code and maybe this was some way to simplify things. Either way, not sure if it's simpler to drop the reset source param and have the KGD remember to unconditionally KFD suspend/resume around the soft reset call for each IP version, or keep the reset source param here so that we only have to remember to do this once.
Could KFD keep track of whether the hang was detected by KFD or KGD? E.g., if KFD detects the hang when suspending queues, it could set a flag and then KFD could include a call to amdgpu_amdkfd_suspend() in its pre_reset callback that would depend on the value of that flag. At that point I don't think we'd need the src parameter any more.
Alex
Quoted 173 lines
Jon
Quoted 169 lines
Thanks,
Lijodrivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-0+ +/* Stop the scheduler's work queue for the GFX and page rings if +they are running.
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +9
-0+* This ensures that no new tasks are submitted to the queues while +* the reset is in progress. +*/ +if (!amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_stop (&gfx_ring->sched); + gfx_sched_stopped = true;; + } + + if (adev->sdma.has_page_queue&& !amdgpu_ring_sched_ready(page_ring)) {
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +5
-2+drm_sched_wqueue_stop (&page_ring->sched); + page_sched_stopped = true; + }/* Invoke all registered pre_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->pre_reset) { - ret = funcs->pre_reset (adev, instance_id); + ret = funcs->pre_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"beforeReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } }@@ -515,21 +546,39 @@ int amdgpu_sdma_reset_engine(structQuoted 1 line
amdgpu_device*adev,
uint32_tinstance_id)Quoted 3 lines
ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id); if (ret) { dev_err(adev->dev, "Failed to reset SDMA instance %u\n",
instance_id);Review
Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +22
-4-return ret; + goto exit; }/* Invoke all registered post_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->post_reset) { - ret = funcs->post_reset (adev, instance_id); + ret = funcs->post_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"afterReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } } -return 0 ; +exit: +/* Restart the scheduler's work queue for the GFX and page rings +* if they were stopped by this function. This allows new tasks +* to be submitted to the queues after the reset is complete. +*/ +if (ret) { +if (gfx_sched_stopped &&amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_start (&gfx_ring->sched); + } +if (page_sched_stopped &&amdgpu_ring_sched_ready (page_ring)) { +drm_sched_wqueue_start (&page_ring->sched); + } + } + +/* Resume KFD if the reset source is not SDMA_HWS */ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_resume (adev, false); + +return ret; }(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.hQuoted 15 lines
index
f91d75848557..2ef2da772254100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +3
-2@@ -99,8 +99,8 @@ struct amdgpu_sdma_ras { };struct sdma_on_reset_funcs { -int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id); -int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id); +int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id,int src); +int (*post_reset)(struct amdgpu_device *adev,uint32_t + instance_id,int src);/* Linked list node to store this structure in a list; */ struct list_head list; };drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 168
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0@@ -166,7 +166,7 @@ struct amdgpu_buffer_funcs { }; void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev,struct
sdma_on_reset_funcs*funcs);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-1-int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1
-0+int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id, int src);Review
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)- mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer (adev, ib, s, d, b)(adev)->mman.buffer_funcs-
emit_fill_buffer((ib), (s), (d), (b))(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.cdrivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_sw_init(struct
Quoted 12 lines
index
29a123be90b7..50a086264792100644drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0@@ -30,6 +30,7 @@#include "amdgpu_xcp.h" #include "amdgpu_ucode.h" #include "amdgpu_trace.h" +#include "amdgpu_reset.h" #include "sdma/sdma_4_4_2_offset.h" #include "sdma/sdma_4_4_2_sh_mask.h" @@ -1480,6 +1481,7 @@ static int sdma_v4_4_2_sw_init(struct
amdgpu_ip_block*ip_block)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0if (r)return r;INIT_LIST_HEAD (&adev->sdma.reset_callback_list); +return r; }@@ -1608,10 +1610,10 @@ static int sdma_v4_4_2_reset_queue(struct
amdgpu_ring*ring, unsigned int vmid)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-1{struct amdgpu_device *adev = ring->adev;u32 id =GET_INST (SDMA0 , ring->me); -return amdgpu_sdma_reset_engine (adev, id); + return amdgpu_sdma_reset_engine(adev, id,
AMDGPU_RESET_SRC_SDMA_RING);Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1} -static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_stop_queue(struct
Quoted 5 lines
{
u32inst_mask;
structamdgpu_ring*ring =
&adev->sdma.instance[instance_id].ring;drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-0@@ -1628,7 +1630,7 @@ static int sdma_v4_4_2_stop_queue(struct
amdgpu_device*adev,uint32_tinstance_Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1return 0 ; } -static int sdma_v4_4_2_restore_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_restore_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)Quoted 3 lines
{ int i; u32 inst_mask;
RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization
[Public]
Quoted 194 lines
-----Original Message-----
From: Deucher, Alexander <[email protected]>
Sent: Wednesday, February 19, 2025 12:39 PM
To: Kim, Jonathan <[email protected]>; Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization[Public]
Quoted 10 lines
-----Original Message-----
From: Kim, Jonathan <[email protected]>
Sent: Tuesday, February 18, 2025 12:42 PM
To: Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 39 lines
[Public]
Quoted 37 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, February 17, 2025 10:36 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 4 lines · On 2/13/2025 11:17 AM, [email protected] wrote:
From: "[email protected]" <[email protected]>
This commit introduces a caller parameter to the
amdgpu_sdma_reset_instancefunction to differentiate
Quoted 3 lines
between reset requests originating from the KGD and KFD. This change ensures proper synchronization between KGD and KFD during SDMA
resets.
Quoted 3 lines
If the caller is KFD, the function now acquires and releases the scheduler lock
(
ring->sched.job_list_lock)Quoted 10 lines
to protect the SDMA queue during the reset.
These changes prevent race conditions and ensure safe SDMA reset operations when initiated by KFD, improving system stability and reliability.
V2: replace the
ring_lockwith the existed the schedulerlocks for the queues (ring->sched) on the sdma engine.(Alex)v3: call
drm_sched_wqueue_stop()rather thanjob_list_lock.
If a GPU ring reset was already initiated for one ring at
amdgpu_job_timedout,Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
skip resetting that ring and call
drm_sched_wqueue_stop()for the other rings (Alex)replace the common lock (
sdma_reset_lock) with DQM lock to to resolve reset races between the two driver sections during KFD
eviction.(Jon)Quoted 24 lines
Quoted 7 lines
Quoted 2 lines
Rename the caller to
Reset_srcand
Change AMDGPU_RESET_SRC_SDMA_KGD/KFD toAMDGPU_RESET_SRC_SDMA_HWS/RING (Jon)
Quoted 4 lines
v4: restart the wqueue if the reset was successful,
or fall back to a full adapter reset. (Alex)move definition of reset source to enumeration
AMDGPU_RESET_SRCS,and
Quoted 16 lines
Quoted 4 lines
check reset src in
amdgpu_sdma_reset_instance(Jon)v5: Call amdgpu_amdkfd_suspend/resume at the start/end of reset function
respectively under !SRC_HWS
Quoted 11 lines
conditions only (Jon)
Suggested-by Alex Deucher <[email protected]>Suggested-by Jiadong Zhu <[email protected]>Suggested-by Jonathan Kim <[email protected]>Signed-off-by Jesse Zhang <[email protected]>Reviewed-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h | 2 +
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c| 65 ++++++++++++++++++++---drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h|
Quoted 88 lines
Quoted 73 lines
Review
Quoted 4 lines
6 +--
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c| 8 +--4 files changed, 67 insertions(+), 14 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_reset.hReview
Quoted 13 lines
index
4d9b9701139b..5b86e12ff9fe100644drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +2
-0@@ -43,6 +43,8 @@ enum AMDGPU_RESET_SRCS {AMDGPU_RESET_SRC_MES ,AMDGPU_RESET_SRC_HWS ,AMDGPU_RESET_SRC_USER , +AMDGPU_RESET_SRC_SDMA_RING , + AMDGPU_RESET_SRC_SDMA_HWS, }; struct amdgpu_reset_context {(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.cQuoted 11 lines
index
fe39198307ec..808c7112ef10100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1
-0@@ -25,6 +25,7 @@#include "amdgpu.h" #include "amdgpu_sdma.h" #include "amdgpu_ras.h" +#include "amdgpu_reset.h" #define AMDGPU_CSA_SDMA_SIZE 64 /* SDMA CSA reside in the 3rd page of CSA */ @@ -485,6 +486,7 @@Quoted 1 line
void amdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 8 lines
*
amdgpu_sdma_reset_engine- Reset a specific SDMA engine
* @adev: Pointer to the AMDGPU device
* @instance_id: ID of the SDMA engine instance to reset
+ * @src: The source of reset function (KGD or KFD)
*
* This function performs the following steps:
* 1. Calls all registeredpre_resetcallbacks to allow KFD and
AMDGPU to savetheir state.
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +0
-0@@ -493,20 +495,49 @@ voidamdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 4 lines
*
* Returns: 0 on success, or a negative error code on failure. */
-int amdgpu_sdma_reset_engine(structamdgpu_device*adev,uint32_t
instance_id)Quoted 1 line
+int amdgpu_sdma_reset_engine(struct
amdgpu_device*adev,uint32_t
instance_id, int src)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct
Quoted 12 lines
{ struct sdma_on_reset_funcs *funcs;drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +2
-1-int ret; +int ret =0 ; + struct amdgpu_sdma_instance *sdma_instance = &adev-sdma.instance[instance_id];;
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +6
-0+struct amdgpu_ring *gfx_ring = &sdma_instance->ring; +struct amdgpu_ring *page_ring = &sdma_instance->page; +bool gfx_sched_stopped = false, page_sched_stopped = false; + +/* Check if the reset source is valid for SDMA ring reset */ + if (src != AMDGPU_RESET_SRC_SDMA_RING && src !=
AMDGPU_RESET_SRC_HWS)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct · line 516
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +8
-0+return -EINVAL ; + +/* Suspend KFD if the reset source is not SDMA_HWS. +* prevent the destruction of in-flight healthy user queue packets and +* avoid race conditions between KFD and KGD during the reset process. +*/ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_suspend (adev, false);Quoted 2 lines
It this has to be done here, what's the idea behind registering a separate pre/post callback for KFD initiated resets?
The problem is that for SDMA v5.x and below, a single soft reset call will reset all queues on the target SDMA engine.
If the KGD calls the reset, a transient KFD suspend/resume around the reset will guarantee that healthy user queues survive the reset.
If the KFD calls the reset, it will only do so during preemption failure, and we don't want to suspend and resume the KFD again when the KFD calls this function. The KFD needs to call this common function to not disturb GFX and paging queues for the same reason KGD resets need to be wary of KFD queues.
In the case of preemption failure and a KFD initiated reset, the KFD is holding the device wide preemption lock, so if the KGD is trying to reset as well, it will have to wait on its own KFD suspend call until the KFD is done its own reset.Quoted 7 lines
I think SDMA6+ can target specific queues via MMIO reg writes, but I see in the KGD code that
soft_resetfor SDMA 6+ does a sweep of all engines so we would still need to keep KFD queues safe (I'm not familiar with this chunk of the code or the need for sweeping all engines on the KGD side).
So I'm not sure if Jesse had concerns about potential multiple calls being made in other parts of the code and maybe this was some way to simplify things. Either way, not sure if it's simpler to drop the reset source param and have theKGD
Quoted 3 lines
remember to unconditionally KFD suspend/resume around the soft reset call for each IP version, or keep the reset source param here so that we only have to remember to do this once.
Quoted 5 lines
Could KFD keep track of whether the hang was detected by KFD or KGD? E.g., if KFD detects the hang when suspending queues, it could set a flag and then KFD could include a call to
amdgpu_amdkfd_suspend()in itspre_resetcallback that would depend on the value of that flag. At that point I don't think we'd need the src parameter any more.
Hmmm. Something similar to GPU resets?
The thing about GPU resets is that the KFD could just detect the flag, schedule an event then carry on knowing the driver is going to die and re-init at some point. SDMA resets are different because the KFD would call back into the common KGD call immediately because it wants to fix things right away, and the KGD has to ensure the KFD is quiesced in any case.
So any flag would have to be locked as well in the KFD pre/post calls. Which means we'd probably have to conditionally lock it based on a new reset context that the KGD would have to supply anyways.
This was the main reason why I wanted to simplify things by leveraging a conditional suspend/resume call in the common interface.
Maybe I'm not looking at things clearly atm, but if feels like we're pushing the complication from one part of the driver into another.
If we really don't like the idea of adding flags, maybe we can just add a param "bool suspend_user_queues" to the common interface?
Then maybe it's clearer that the KGD, as a reset requester, wants to be careful of destroying in-flight user queues while the KFD doesn't care about this for its own needs (since it's already in post-preemption recovery).
Jon
Quoted 178 lines
Alex
Quoted 173 lines
Jon
Quoted 169 lines
Thanks,
Lijodrivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-0+ +/* Stop the scheduler's work queue for the GFX and page rings if +they are running.
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +9
-0+* This ensures that no new tasks are submitted to the queues while +* the reset is in progress. +*/ +if (!amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_stop (&gfx_ring->sched); + gfx_sched_stopped = true;; + } + + if (adev->sdma.has_page_queue&& !amdgpu_ring_sched_ready(page_ring)) {
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +5
-2+drm_sched_wqueue_stop (&page_ring->sched); + page_sched_stopped = true; + }/* Invoke all registered pre_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->pre_reset) { - ret = funcs->pre_reset (adev, instance_id); + ret = funcs->pre_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"beforeReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } }@@ -515,21 +546,39 @@ int amdgpu_sdma_reset_engine(structQuoted 1 line
amdgpu_device*adev,
uint32_tinstance_id)Quoted 3 lines
ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id); if (ret) { dev_err(adev->dev, "Failed to reset SDMA instance %u\n",
instance_id);Review
Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +22
-4-return ret; + goto exit; }/* Invoke all registered post_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->post_reset) { - ret = funcs->post_reset (adev, instance_id); + ret = funcs->post_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"afterReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } } -return 0 ; +exit: +/* Restart the scheduler's work queue for the GFX and page rings +* if they were stopped by this function. This allows new tasks +* to be submitted to the queues after the reset is complete. +*/ +if (ret) { +if (gfx_sched_stopped &&amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_start (&gfx_ring->sched); + } +if (page_sched_stopped &&amdgpu_ring_sched_ready (page_ring)) { +drm_sched_wqueue_start (&page_ring->sched); + } + } + +/* Resume KFD if the reset source is not SDMA_HWS */ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_resume (adev, false); + +return ret; }(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.hQuoted 15 lines
index
f91d75848557..2ef2da772254100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +3
-2@@ -99,8 +99,8 @@ struct amdgpu_sdma_ras { };struct sdma_on_reset_funcs { -int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id); -int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id); +int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id,int src); +int (*post_reset)(struct amdgpu_device *adev,uint32_t + instance_id,int src);/* Linked list node to store this structure in a list; */ struct list_head list; };drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 168
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0@@ -166,7 +166,7 @@ struct amdgpu_buffer_funcs { }; void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev,struct
sdma_on_reset_funcs*funcs);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-1-int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1
-0+int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id, int src);Review
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)- mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer (adev, ib, s, d, b)(adev)->mman.buffer_funcs-
emit_fill_buffer((ib), (s), (d), (b))(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.cdrivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_sw_init(struct
Quoted 12 lines
index
29a123be90b7..50a086264792100644drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0@@ -30,6 +30,7 @@#include "amdgpu_xcp.h" #include "amdgpu_ucode.h" #include "amdgpu_trace.h" +#include "amdgpu_reset.h" #include "sdma/sdma_4_4_2_offset.h" #include "sdma/sdma_4_4_2_sh_mask.h" @@ -1480,6 +1481,7 @@ static int sdma_v4_4_2_sw_init(struct
amdgpu_ip_block*ip_block)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0if (r)return r;INIT_LIST_HEAD (&adev->sdma.reset_callback_list); +return r; }@@ -1608,10 +1610,10 @@ static int sdma_v4_4_2_reset_queue(struct
amdgpu_ring*ring, unsigned int vmid)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-1{struct amdgpu_device *adev = ring->adev;u32 id =GET_INST (SDMA0 , ring->me); -return amdgpu_sdma_reset_engine (adev, id); + return amdgpu_sdma_reset_engine(adev, id,
AMDGPU_RESET_SRC_SDMA_RING);Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1} -static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_stop_queue(struct
Quoted 5 lines
{
u32inst_mask;
structamdgpu_ring*ring =
&adev->sdma.instance[instance_id].ring;drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-0@@ -1628,7 +1630,7 @@ static int sdma_v4_4_2_stop_queue(struct
amdgpu_device*adev,uint32_tinstance_Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1return 0 ; } -static int sdma_v4_4_2_restore_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_restore_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)Quoted 3 lines
{ int i; u32 inst_mask;
Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization
Quoted 210 lines · Jonathan
[Public]
Quoted 194 lines
-----Original Message-----
From: Deucher, Alexander <[email protected]>
Sent: Wednesday, February 19, 2025 12:39 PM
To: Kim, Jonathan <[email protected]>; Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization[Public]
Quoted 10 lines
-----Original Message-----
From: Kim, Jonathan <[email protected]>
Sent: Tuesday, February 18, 2025 12:42 PM
To: Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 39 lines
[Public]
Quoted 37 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, February 17, 2025 10:36 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 4 lines · On 2/13/2025 11:17 AM, [email protected] wrote:
From: "[email protected]" <[email protected]>
This commit introduces a caller parameter to the
amdgpu_sdma_reset_instancefunction to differentiate
Quoted 3 lines
between reset requests originating from the KGD and KFD. This change ensures proper synchronization between KGD and KFD during SDMA
resets.
Quoted 3 lines
If the caller is KFD, the function now acquires and releases the scheduler lock
(
ring->sched.job_list_lock)Quoted 10 lines
to protect the SDMA queue during the reset.
These changes prevent race conditions and ensure safe SDMA reset operations when initiated by KFD, improving system stability and reliability.
V2: replace the
ring_lockwith the existed the schedulerlocks for the queues (ring->sched) on the sdma engine.(Alex)v3: call
drm_sched_wqueue_stop()rather thanjob_list_lock.
If a GPU ring reset was already initiated for one ring at
amdgpu_job_timedout,Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
skip resetting that ring and call
drm_sched_wqueue_stop()for the other rings (Alex)replace the common lock (
sdma_reset_lock) with DQM lock to to resolve reset races between the two driver sections during KFD
eviction.(Jon)Quoted 24 lines
Quoted 7 lines
Quoted 2 lines
Rename the caller to
Reset_srcand
Change AMDGPU_RESET_SRC_SDMA_KGD/KFD toAMDGPU_RESET_SRC_SDMA_HWS/RING (Jon)
Quoted 4 lines
v4: restart the wqueue if the reset was successful,
or fall back to a full adapter reset. (Alex)move definition of reset source to enumeration
AMDGPU_RESET_SRCS,and
Quoted 16 lines
Quoted 4 lines
check reset src in
amdgpu_sdma_reset_instance(Jon)v5: Call amdgpu_amdkfd_suspend/resume at the start/end of reset function
respectively under !SRC_HWS
Quoted 11 lines
conditions only (Jon)
Suggested-by Alex Deucher <[email protected]>Suggested-by Jiadong Zhu <[email protected]>Suggested-by Jonathan Kim <[email protected]>Signed-off-by Jesse Zhang <[email protected]>Reviewed-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h | 2 +
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c| 65 ++++++++++++++++++++---drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h|
Quoted 88 lines
Quoted 73 lines
Review
Quoted 4 lines
6 +--
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c| 8 +--4 files changed, 67 insertions(+), 14 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_reset.hReview
Quoted 13 lines
index
4d9b9701139b..5b86e12ff9fe100644drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +2
-0@@ -43,6 +43,8 @@ enum AMDGPU_RESET_SRCS {AMDGPU_RESET_SRC_MES ,AMDGPU_RESET_SRC_HWS ,AMDGPU_RESET_SRC_USER , +AMDGPU_RESET_SRC_SDMA_RING , + AMDGPU_RESET_SRC_SDMA_HWS, }; struct amdgpu_reset_context {(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.cQuoted 11 lines
index
fe39198307ec..808c7112ef10100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1
-0@@ -25,6 +25,7 @@#include "amdgpu.h" #include "amdgpu_sdma.h" #include "amdgpu_ras.h" +#include "amdgpu_reset.h" #define AMDGPU_CSA_SDMA_SIZE 64 /* SDMA CSA reside in the 3rd page of CSA */ @@ -485,6 +486,7 @@Quoted 1 line
void amdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 8 lines
*
amdgpu_sdma_reset_engine- Reset a specific SDMA engine
* @adev: Pointer to the AMDGPU device
* @instance_id: ID of the SDMA engine instance to reset
+ * @src: The source of reset function (KGD or KFD)
*
* This function performs the following steps:
* 1. Calls all registeredpre_resetcallbacks to allow KFD and
AMDGPU to savetheir state.
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +0
-0@@ -493,20 +495,49 @@ voidamdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 4 lines
*
* Returns: 0 on success, or a negative error code on failure. */
-int amdgpu_sdma_reset_engine(structamdgpu_device*adev,uint32_t
instance_id)Quoted 1 line
+int amdgpu_sdma_reset_engine(struct
amdgpu_device*adev,uint32_t
instance_id, int src)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct
Quoted 12 lines
{ struct sdma_on_reset_funcs *funcs;drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +2
-1-int ret; +int ret =0 ; + struct amdgpu_sdma_instance *sdma_instance = &adev-sdma.instance[instance_id];;
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +6
-0+struct amdgpu_ring *gfx_ring = &sdma_instance->ring; +struct amdgpu_ring *page_ring = &sdma_instance->page; +bool gfx_sched_stopped = false, page_sched_stopped = false; + +/* Check if the reset source is valid for SDMA ring reset */ + if (src != AMDGPU_RESET_SRC_SDMA_RING && src !=
AMDGPU_RESET_SRC_HWS)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct · line 516
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +8
-0+return -EINVAL ; + +/* Suspend KFD if the reset source is not SDMA_HWS. +* prevent the destruction of in-flight healthy user queue packets and +* avoid race conditions between KFD and KGD during the reset process. +*/ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_suspend (adev, false);Quoted 2 lines
It this has to be done here, what's the idea behind registering a separate pre/post callback for KFD initiated resets?
The problem is that for SDMA v5.x and below, a single soft reset call will reset all queues on the target SDMA engine.
If the KGD calls the reset, a transient KFD suspend/resume around the reset will guarantee that healthy user queues survive the reset.
If the KFD calls the reset, it will only do so during preemption failure, and we don't want to suspend and resume the KFD again when the KFD calls this function. The KFD needs to call this common function to not disturb GFX and paging queues for the same reason KGD resets need to be wary of KFD queues.
In the case of preemption failure and a KFD initiated reset, the KFD is holding the device wide preemption lock, so if the KGD is trying to reset as well, it will have to wait on its own KFD suspend call until the KFD is done its own reset.Quoted 7 lines
I think SDMA6+ can target specific queues via MMIO reg writes, but I see in the KGD code that
soft_resetfor SDMA 6+ does a sweep of all engines so we would still need to keep KFD queues safe (I'm not familiar with this chunk of the code or the need for sweeping all engines on the KGD side).
So I'm not sure if Jesse had concerns about potential multiple calls being made in other parts of the code and maybe this was some way to simplify things. Either way, not sure if it's simpler to drop the reset source param and have theKGD
Quoted 3 lines
remember to unconditionally KFD suspend/resume around the soft reset call for each IP version, or keep the reset source param here so that we only have to remember to do this once.
Quoted 5 lines
Could KFD keep track of whether the hang was detected by KFD or KGD? E.g., if KFD detects the hang when suspending queues, it could set a flag and then KFD could include a call to
amdgpu_amdkfd_suspend()in itspre_resetcallback that would depend on the value of that flag. At that point I don't think we'd need the src parameter any more.Hmmm. Something similar to GPU resets?
The thing about GPU resets is that the KFD could just detect the flag, schedule an event then carry on knowing the driver is going to die and re-init at some point. SDMA resets are different because the KFD would call back into the common KGD call immediately because it wants to fix things right away, and the KGD has to ensure the KFD is quiesced in any case.
So any flag would have to be locked as well in the KFD pre/post calls. Which means we'd probably have to conditionally lock it based on a new reset context that the KGD would have to supply anyways.
This was the main reason why I wanted to simplify things by leveraging a conditional suspend/resume call in the common interface.
Maybe I'm not looking at things clearly atm, but if feels like we're pushing the complication from one part of the driver into another.
Quoted 3 lines
If we really don't like the idea of adding flags, maybe we can just add a param "bool
suspend_user_queues" to the common interface?
Then maybe it's clearer that the KGD, as a reset requester, wants to be careful of destroying in-flight user queues while the KFD doesn't care about this for its own needs (since it's already in post-preemption recovery).
Having the src for a parameter is fine with me. It just seemed logical to keep it in KFD since presumably KFD would have detected this condition after calling amdgpu_amdkfd_suspend() itself so it would know whether it would need to be called based on its own state so it would know what to do in its pre and post reset hooks already. I guess we also stop the kernel queues explicitly in the same function so it makes sense to do the same for KFD.
Alex
Quoted 181 lines
Jon
Quoted 178 lines
Alex
Quoted 173 lines
Jon
Quoted 169 lines
Thanks,
Lijodrivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-0+ +/* Stop the scheduler's work queue for the GFX and page rings if +they are running.
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +9
-0+* This ensures that no new tasks are submitted to the queues while +* the reset is in progress. +*/ +if (!amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_stop (&gfx_ring->sched); + gfx_sched_stopped = true;; + } + + if (adev->sdma.has_page_queue&& !amdgpu_ring_sched_ready(page_ring)) {
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +5
-2+drm_sched_wqueue_stop (&page_ring->sched); + page_sched_stopped = true; + }/* Invoke all registered pre_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->pre_reset) { - ret = funcs->pre_reset (adev, instance_id); + ret = funcs->pre_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"beforeReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } }@@ -515,21 +546,39 @@ int amdgpu_sdma_reset_engine(structQuoted 1 line
amdgpu_device*adev,
uint32_tinstance_id)Quoted 3 lines
ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id); if (ret) { dev_err(adev->dev, "Failed to reset SDMA instance %u\n",
instance_id);Review
Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +22
-4-return ret; + goto exit; }/* Invoke all registered post_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->post_reset) { - ret = funcs->post_reset (adev, instance_id); + ret = funcs->post_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"afterReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } } -return 0 ; +exit: +/* Restart the scheduler's work queue for the GFX and page rings +* if they were stopped by this function. This allows new tasks +* to be submitted to the queues after the reset is complete. +*/ +if (ret) { +if (gfx_sched_stopped &&amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_start (&gfx_ring->sched); + } +if (page_sched_stopped &&amdgpu_ring_sched_ready (page_ring)) { +drm_sched_wqueue_start (&page_ring->sched); + } + } + +/* Resume KFD if the reset source is not SDMA_HWS */ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_resume (adev, false); + +return ret; }(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.hQuoted 15 lines
index
f91d75848557..2ef2da772254100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +3
-2@@ -99,8 +99,8 @@ struct amdgpu_sdma_ras { };struct sdma_on_reset_funcs { -int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id); -int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id); +int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id,int src); +int (*post_reset)(struct amdgpu_device *adev,uint32_t + instance_id,int src);/* Linked list node to store this structure in a list; */ struct list_head list; };drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 168
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0@@ -166,7 +166,7 @@ struct amdgpu_buffer_funcs { }; void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev,struct
sdma_on_reset_funcs*funcs);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-1-int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1
-0+int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id, int src);Review
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)- mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer (adev, ib, s, d, b)(adev)->mman.buffer_funcs-
emit_fill_buffer((ib), (s), (d), (b))(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.cdrivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_sw_init(struct
Quoted 12 lines
index
29a123be90b7..50a086264792100644drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0@@ -30,6 +30,7 @@#include "amdgpu_xcp.h" #include "amdgpu_ucode.h" #include "amdgpu_trace.h" +#include "amdgpu_reset.h" #include "sdma/sdma_4_4_2_offset.h" #include "sdma/sdma_4_4_2_sh_mask.h" @@ -1480,6 +1481,7 @@ static int sdma_v4_4_2_sw_init(struct
amdgpu_ip_block*ip_block)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0if (r)return r;INIT_LIST_HEAD (&adev->sdma.reset_callback_list); +return r; }@@ -1608,10 +1610,10 @@ static int sdma_v4_4_2_reset_queue(struct
amdgpu_ring*ring, unsigned int vmid)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-1{struct amdgpu_device *adev = ring->adev;u32 id =GET_INST (SDMA0 , ring->me); -return amdgpu_sdma_reset_engine (adev, id); + return amdgpu_sdma_reset_engine(adev, id,
AMDGPU_RESET_SRC_SDMA_RING);Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1} -static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_stop_queue(struct
Quoted 5 lines
{
u32inst_mask;
structamdgpu_ring*ring =
&adev->sdma.instance[instance_id].ring;drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-0@@ -1628,7 +1630,7 @@ static int sdma_v4_4_2_stop_queue(struct
amdgpu_device*adev,uint32_tinstance_Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1return 0 ; } -static int sdma_v4_4_2_restore_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_restore_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)Quoted 3 lines
{ int i; u32 inst_mask;
Kim, Jonathan
Acked-byRE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization
[Public]
Quoted 254 lines
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, February 19, 2025 6:09 PM
To: Kim, Jonathan <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; amd- [email protected]; Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 7 lines · Jonathan
[Public]
Quoted 4 lines
-----Original Message-----
From: Deucher, Alexander <[email protected]>
Sent: Wednesday, February 19, 2025 12:39 PM
To: Kim, Jonathan <[email protected]>; Lazar, LijoQuoted 20 lines
Quoted 20 lines
Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization[Public]
Quoted 12 lines
-----Original Message-----
From: Kim, Jonathan <[email protected]>
Sent: Tuesday, February 18, 2025 12:42 PM
To: Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization[Public]
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, February 17, 2025 10:36 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>;Zhu,
Quoted 38 lines
Quoted 38 lines
Quoted 22 lines
Quoted 22 lines
Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 4 lines · On 2/13/2025 11:17 AM, [email protected] wrote:
From: "[email protected]" <[email protected]>
This commit introduces a caller parameter to the
amdgpu_sdma_reset_instancefunction to differentiate
Quoted 3 lines
between reset requests originating from the KGD and KFD. This change ensures proper synchronization between KGD and KFD during SDMA
resets.
Quoted 3 lines
If the caller is KFD, the function now acquires and releases the scheduler lock
(
ring->sched.job_list_lock)Quoted 2 lines
to protect the SDMA queue during the reset.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
These changes prevent race conditions and ensure safe SDMA reset operations when initiated by KFD, improving system stability and reliability.
V2: replace the
ring_lockwith the existed the schedulerlocks for the queues (ring->sched) on the sdma engine.(Alex)v3: call
drm_sched_wqueue_stop()rather thanjob_list_lock.
If a GPU ring reset was already initiated for one ring at
amdgpu_job_timedout,Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
skip resetting that ring and call
drm_sched_wqueue_stop()for the other rings (Alex)replace the common lock (
sdma_reset_lock) with DQM lock to to resolve reset races between the two driver sections during KFD
eviction.(Jon)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Rename the caller to
Reset_srcand
Change AMDGPU_RESET_SRC_SDMA_KGD/KFD toAMDGPU_RESET_SRC_SDMA_HWS/RING (Jon)
Quoted 4 lines
v4: restart the wqueue if the reset was successful,
or fall back to a full adapter reset. (Alex)move definition of reset source to enumeration
AMDGPU_RESET_SRCS,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
and
Quoted 7 lines
Quoted 4 lines
check reset src in
amdgpu_sdma_reset_instance(Jon)v5: Call amdgpu_amdkfd_suspend/resume at the start/end of reset function
respectively under !SRC_HWS
Quoted 2 lines
conditions only (Jon)
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Suggested-by Alex Deucher <[email protected]>Suggested-by Jiadong Zhu <[email protected]>Suggested-by Jonathan Kim <[email protected]>Signed-off-by Jesse Zhang <[email protected]>Reviewed-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h | 2 +
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c| 65
++++++++++++++++++++---
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.hQuoted 64 lines
Quoted 64 lines
|
Quoted 63 lines
Quoted 63 lines
Review
Quoted 4 lines
6 +--
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c| 8 +--4 files changed, 67 insertions(+), 14 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_reset.hReview
Quoted 13 lines
index
4d9b9701139b..5b86e12ff9fe100644drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +2
-0@@ -43,6 +43,8 @@ enum AMDGPU_RESET_SRCS {AMDGPU_RESET_SRC_MES ,AMDGPU_RESET_SRC_HWS ,AMDGPU_RESET_SRC_USER , +AMDGPU_RESET_SRC_SDMA_RING , + AMDGPU_RESET_SRC_SDMA_HWS, }; struct amdgpu_reset_context {(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.cQuoted 11 lines
index
fe39198307ec..808c7112ef10100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1
-0@@ -25,6 +25,7 @@#include "amdgpu.h" #include "amdgpu_sdma.h" #include "amdgpu_ras.h" +#include "amdgpu_reset.h" #define AMDGPU_CSA_SDMA_SIZE 64 /* SDMA CSA reside in the 3rd page of CSA */ @@ -485,6 +486,7 @@Quoted 1 line
void amdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 8 lines
*
amdgpu_sdma_reset_engine- Reset a specific SDMA engine
* @adev: Pointer to the AMDGPU device
* @instance_id: ID of the SDMA engine instance to reset
+ * @src: The source of reset function (KGD or KFD)
*
* This function performs the following steps:
* 1. Calls all registeredpre_resetcallbacks to allow KFD and
AMDGPU to savetheir state.
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +0
-0@@ -493,20 +495,49 @@ voidamdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 4 lines
*
* Returns: 0 on success, or a negative error code on failure. */
-int amdgpu_sdma_reset_engine(structamdgpu_device*adev,uint32_t
instance_id)Quoted 1 line
+int amdgpu_sdma_reset_engine(struct
amdgpu_device*adev,uint32_t
instance_id, int src)Quoted 12 lines
{ struct sdma_on_reset_funcs *funcs;drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +2
-1-int ret; +int ret =0 ; + struct amdgpu_sdma_instance *sdma_instance = &adev-sdma.instance[instance_id];;
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +6
-0+struct amdgpu_ring *gfx_ring = &sdma_instance->ring; +struct amdgpu_ring *page_ring = &sdma_instance->page; +bool gfx_sched_stopped = false, page_sched_stopped = false; + +/* Check if the reset source is valid for SDMA ring reset */ + if (src != AMDGPU_RESET_SRC_SDMA_RING && src !=Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
AMDGPU_RESET_SRC_HWS)Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +5
-0+return -EINVAL ; + +/* Suspend KFD if the reset source is not SDMA_HWS. +* prevent the destruction of in-flight healthy user queue packets and +* avoid race conditions between KFD and KGD during the reset process.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct · line 516
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-0+*/ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_suspend (adev, false);It this has to be done here, what's the idea behind registering a separate pre/post callback for KFD initiated resets?
The problem is that for SDMA v5.x and below, a single soft reset call will reset
all
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
queues on the target SDMA engine.
If the KGD calls the reset, a transient KFD suspend/resume around the resetwill
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
guarantee that healthy user queues survive the reset.
If the KFD calls the reset, it will only do so during preemption failure, and wedon't
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
want to suspend and resume the KFD again when the KFD calls this function. The KFD needs to call this common function to not disturb GFX and paging
queues
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
for the same reason KGD resets need to be wary of KFD queues.
In the case of preemption failure and a KFD initiated reset, the KFD is holdingthe
Quoted 1 line
Quoted 1 line
Quoted 1 line
device wide preemption lock, so if the KGD is trying to reset as well, it will have
to
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
wait on its own KFD suspend call until the KFD is done its own reset.
I think SDMA6+ can target specific queues via MMIO reg writes, but I see in
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
KGD code that
soft_resetfor SDMA 6+ does a sweep of all engines so wewould
Quoted 1 line
Quoted 1 line
Quoted 1 line
still need to keep KFD queues safe (I'm not familiar with this chunk of the code
or
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
the need for sweeping all engines on the KGD side).
So I'm not sure if Jesse had concerns about potential multiple calls being madein
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
other parts of the code and maybe this was some way to simplify things. Either way, not sure if it's simpler to drop the reset source param and have the
KGD
Quoted 1 line
remember to unconditionally KFD suspend/resume around the soft reset call
for
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
each IP version, or keep the reset source param here so that we only have to remember to do this once.
Could KFD keep track of whether the hang was detected by KFD or KGD? E.g.,
if
Quoted 3 lines
Quoted 3 lines
KFD detects the hang when suspending queues, it could set a flag and then KFD could include a call to
amdgpu_amdkfd_suspend()in itspre_resetcallback that would depend on the value of that flag. At that point I don't think we'd need thesrc
Quoted 4 lines
Quoted 1 line
parameter any more.
Hmmm. Something similar to GPU resets?
The thing about GPU resets is that the KFD could just detect the flag, schedule anevent then carry on knowing the driver is going to die and re-init at some point.
Quoted 1 line
SDMA resets are different because the KFD would call back into the common KGD
call immediately because it wants to fix things right away, and the KGD has to ensure the KFD is quiesced in any case.
Quoted 1 line
So any flag would have to be locked as well in the KFD pre/post calls. Which
means we'd probably have to conditionally lock it based on a new reset context that the KGD would have to supply anyways.
Quoted 1 line
This was the main reason why I wanted to simplify things by leveraging a
conditional suspend/resume call in the common interface.
Quoted 1 line
Maybe I'm not looking at things clearly atm, but if feels like we're pushing the
complication from one part of the driver into another.
Quoted 2 lines
If we really don't like the idea of adding flags, maybe we can just add a param "bool
suspend_user_queues" to the common interface?Quoted 1 line
Then maybe it's clearer that the KGD, as a reset requester, wants to be careful of
destroying in-flight user queues while the KFD doesn't care about this for its own needs (since it's already in post-preemption recovery).
Quoted 1 line
Quoted 5 lines
Having the src for a parameter is fine with me. It just seemed logical to keep it in KFD since presumably KFD would have detected this condition after calling
amdgpu_amdkfd_suspend()itself so it would know whether it would need to be called based on its own state so it would know what to do in its pre and post reset hooks already.
The case of successful KFD suspend during reset isn't really a concern since the KFD cannot get into a preemption failure at this point. It's the corner case when the KFD suspend fails on a KGD initiated reset because of a user queue hang and KFD has to reset through the KGD call again. In this case, KFD suspend from the KGD initiated reset is in limbo and this initial suspend call is holding the lock for all KFD processes. The KGD is still forced to pass some sort of SDMA reset trigger hint to the KFD when it calls suspend (or pre-reset) for this corner case. Otherwise, the KFD will deadlock on the on its own recall of the reset function when it hits the KFD processes lock again during kgd2kfd_suspend. So we're stuck either way with the KGD still having to pass something to the KFD (new reset context, bool, flag hint etc ...) if we want to avoid this deadlock.
Quoted 2 lines
I guess we also stop the kernel queues explicitly in the same function so it makes sense to do the same for KFD.
Yep. We definitely want to minimize reset damage from either caller (KFD or KGD).
I kind of look at it like the rest of the amdgpu_device_reset/suspend/resume calls that need to consider the KFD as well.
I think I'm fine with just passing a bool suspend_user_queues here to do the conditional KFD suspend/resume instead of coming up with new reset source context(s). That way we don't have to force callers to use extra long strings in their calls that have no use anywhere else.
They can just pass true/false according to their needs.
With that fixed, this patch is:
Jon
Quoted 186 lines
Alex
Quoted 82 lines
Jon
Quoted 80 lines
Alex
Quoted 76 lines
Jon
Quoted 73 lines
Thanks,
Lijodrivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-0+ +/* Stop the scheduler's work queue for the GFX and page rings if +they are running.
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, struct
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +9
-0+* This ensures that no new tasks are submitted to the queues while +* the reset is in progress. +*/ +if (!amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_stop (&gfx_ring->sched); + gfx_sched_stopped = true;; + } + + if (adev->sdma.has_page_queue&& !amdgpu_ring_sched_ready(page_ring)) {
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +5
-2+drm_sched_wqueue_stop (&page_ring->sched); + page_sched_stopped = true; + }/* Invoke all registered pre_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->pre_reset) { - ret = funcs->pre_reset (adev, instance_id); + ret = funcs->pre_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"beforeReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } }@@ -515,21 +546,39 @@ int amdgpu_sdma_reset_engine(structQuoted 1 line
amdgpu_device*adev,
uint32_tinstance_id)Quoted 3 lines
ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id); if (ret) { dev_err(adev->dev, "Failed to reset SDMA instance %u\n",
instance_id);Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +13
-4-return ret; + goto exit; }/* Invoke all registered post_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->post_reset) { - ret = funcs->post_reset (adev, instance_id); + ret = funcs->post_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"afterReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } } -return 0 ; +exit: +/* Restart the scheduler's work queue for the GFX and page rings +* if they were stopped by this function. This allows new tasks +* to be submitted to the queues after the reset is complete. +*/ +if (ret) { +if (gfx_sched_stopped &&amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_start (&gfx_ring->sched); + } + if (page_sched_stopped &&
amdgpu_ring_sched_ready(page_ring)) {Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Review
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +9
-0+drm_sched_wqueue_start (&page_ring->sched); + } + } + +/* Resume KFD if the reset source is not SDMA_HWS */ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_resume (adev, false); + +return ret; }(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.hQuoted 5 lines
index
f91d75848557..2ef2da772254100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0@@ -99,8 +99,8 @@ struct amdgpu_sdma_ras { };Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_sdma_ras {
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1
-2struct sdma_on_reset_funcs { -int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id); -int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id); + int (*pre_reset)(struct amdgpu_device *adev, uint32_t instance_id, intsrc);
Quoted 78 lines
Quoted 77 lines
Quoted 76 lines
Quoted 75 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 168
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2
-0+int (*post_reset)(struct amdgpu_device *adev,uint32_t + instance_id,int src);/* Linked list node to store this structure in a list; */ struct list_head list; };@@ -166,7 +166,7 @@ struct amdgpu_buffer_funcs { }; void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev,struct
sdma_on_reset_funcs*funcs);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-1-int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1
-0+int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id, int src);Review
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)- mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer (adev, ib, s, d, b)(adev)->mman.buffer_funcs-
emit_fill_buffer((ib), (s), (d), (b))(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.cdrivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_sw_init(struct
Quoted 12 lines
index
29a123be90b7..50a086264792100644drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0@@ -30,6 +30,7 @@#include "amdgpu_xcp.h" #include "amdgpu_ucode.h" #include "amdgpu_trace.h" +#include "amdgpu_reset.h" #include "sdma/sdma_4_4_2_offset.h" #include "sdma/sdma_4_4_2_sh_mask.h" @@ -1480,6 +1481,7 @@ static int sdma_v4_4_2_sw_init(struct
amdgpu_ip_block*ip_block)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0if (r)return r;INIT_LIST_HEAD (&adev->sdma.reset_callback_list); +return r; }@@ -1608,10 +1610,10 @@ static int sdma_v4_4_2_reset_queue(struct
amdgpu_ring*ring, unsigned int vmid)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct amdgpu_ring *ring, unsigned int vmid)
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-1{struct amdgpu_device *adev = ring->adev;u32 id =GET_INST (SDMA0 , ring->me); -return amdgpu_sdma_reset_engine (adev, id); + return amdgpu_sdma_reset_engine(adev, id,
AMDGPU_RESET_SRC_SDMA_RING);Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1} -static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_stop_queue(struct
Quoted 5 lines
{
u32inst_mask;
structamdgpu_ring*ring =
&adev->sdma.instance[instance_id].ring;drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-0@@ -1628,7 +1630,7 @@ static int sdma_v4_4_2_stop_queue(struct
amdgpu_device*adev,uint32_tinstance_Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1return 0 ; } -static int sdma_v4_4_2_restore_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_restore_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)Quoted 3 lines
{ int i; u32 inst_mask;
Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization
Quoted 262 lines · Jonathan
[Public]
Quoted 254 lines
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, February 19, 2025 6:09 PM
To: Kim, Jonathan <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; amd- [email protected]; Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 7 lines · Jonathan
[Public]
Quoted 4 lines
-----Original Message-----
From: Deucher, Alexander <[email protected]>
Sent: Wednesday, February 19, 2025 12:39 PM
To: Kim, Jonathan <[email protected]>; Lazar, LijoQuoted 20 lines
Quoted 20 lines
Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization[Public]
Quoted 12 lines
-----Original Message-----
From: Kim, Jonathan <[email protected]>
Sent: Tuesday, February 18, 2025 12:42 PM
To: Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization[Public]
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, February 17, 2025 10:36 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>;Zhu,
Quoted 38 lines
Quoted 38 lines
Quoted 22 lines
Quoted 22 lines
Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 4 lines · On 2/13/2025 11:17 AM, [email protected] wrote:
From: "[email protected]" <[email protected]>
This commit introduces a caller parameter to the
amdgpu_sdma_reset_instancefunction to differentiate
Quoted 3 lines
between reset requests originating from the KGD and KFD. This change ensures proper synchronization between KGD and KFD during SDMA
resets.
Quoted 3 lines
If the caller is KFD, the function now acquires and releases the scheduler lock
(
ring->sched.job_list_lock)Quoted 2 lines
to protect the SDMA queue during the reset.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
These changes prevent race conditions and ensure safe SDMA reset operations when initiated by KFD, improving system stability and reliability.
V2: replace the
ring_lockwith the existed the schedulerlocks for the queues (ring->sched) on the sdma engine.(Alex)v3: call
drm_sched_wqueue_stop()rather thanjob_list_lock.
If a GPU ring reset was already initiated for one ring at
amdgpu_job_timedout,Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
skip resetting that ring and call
drm_sched_wqueue_stop()for the other rings (Alex)replace the common lock (
sdma_reset_lock) with DQM lock to to resolve reset races between the two driver sections during KFD
eviction.(Jon)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Rename the caller to
Reset_srcand
Change AMDGPU_RESET_SRC_SDMA_KGD/KFD toAMDGPU_RESET_SRC_SDMA_HWS/RING (Jon)
Quoted 4 lines
v4: restart the wqueue if the reset was successful,
or fall back to a full adapter reset. (Alex)move definition of reset source to enumeration
AMDGPU_RESET_SRCS,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
and
Quoted 7 lines
Quoted 4 lines
check reset src in
amdgpu_sdma_reset_instance(Jon)v5: Call amdgpu_amdkfd_suspend/resume at the start/end of reset function
respectively under !SRC_HWS
Quoted 2 lines
conditions only (Jon)
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Suggested-by Alex Deucher <[email protected]>Suggested-by Jiadong Zhu <[email protected]>Suggested-by Jonathan Kim <[email protected]>Signed-off-by Jesse Zhang <[email protected]>Reviewed-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h | 2 +
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c| 65
++++++++++++++++++++---
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.hQuoted 64 lines
Quoted 64 lines
|
Quoted 63 lines
Quoted 63 lines
Review
Quoted 4 lines
6 +--
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c| 8 +--4 files changed, 67 insertions(+), 14 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_reset.hReview
Quoted 13 lines
index
4d9b9701139b..5b86e12ff9fe100644drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +2
-0@@ -43,6 +43,8 @@ enum AMDGPU_RESET_SRCS {AMDGPU_RESET_SRC_MES ,AMDGPU_RESET_SRC_HWS ,AMDGPU_RESET_SRC_USER , +AMDGPU_RESET_SRC_SDMA_RING , + AMDGPU_RESET_SRC_SDMA_HWS, }; struct amdgpu_reset_context {(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.cQuoted 11 lines
index
fe39198307ec..808c7112ef10100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1
-0@@ -25,6 +25,7 @@#include "amdgpu.h" #include "amdgpu_sdma.h" #include "amdgpu_ras.h" +#include "amdgpu_reset.h" #define AMDGPU_CSA_SDMA_SIZE 64 /* SDMA CSA reside in the 3rd page of CSA */ @@ -485,6 +486,7 @@Quoted 1 line
void amdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 8 lines
*
amdgpu_sdma_reset_engine- Reset a specific SDMA engine
* @adev: Pointer to the AMDGPU device
* @instance_id: ID of the SDMA engine instance to reset
+ * @src: The source of reset function (KGD or KFD)
*
* This function performs the following steps:
* 1. Calls all registeredpre_resetcallbacks to allow KFD and
AMDGPU to savetheir state.
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +0
-0@@ -493,20 +495,49 @@ voidamdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 4 lines
*
* Returns: 0 on success, or a negative error code on failure. */
-int amdgpu_sdma_reset_engine(structamdgpu_device*adev,uint32_t
instance_id)Quoted 1 line
+int amdgpu_sdma_reset_engine(struct
amdgpu_device*adev,uint32_t
instance_id, int src)Quoted 12 lines
{ struct sdma_on_reset_funcs *funcs;drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +2
-1-int ret; +int ret =0 ; + struct amdgpu_sdma_instance *sdma_instance = &adev-sdma.instance[instance_id];;
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +6
-0+struct amdgpu_ring *gfx_ring = &sdma_instance->ring; +struct amdgpu_ring *page_ring = &sdma_instance->page; +bool gfx_sched_stopped = false, page_sched_stopped = false; + +/* Check if the reset source is valid for SDMA ring reset */ + if (src != AMDGPU_RESET_SRC_SDMA_RING && src !=Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
AMDGPU_RESET_SRC_HWS)Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +5
-0+return -EINVAL ; + +/* Suspend KFD if the reset source is not SDMA_HWS. +* prevent the destruction of in-flight healthy user queue packets and +* avoid race conditions between KFD and KGD during the reset process.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-0+*/ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_suspend (adev, false);It this has to be done here, what's the idea behind registering a separate pre/post callback for KFD initiated resets?
The problem is that for SDMA v5.x and below, a single soft reset call will reset
all
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
queues on the target SDMA engine.
If the KGD calls the reset, a transient KFD suspend/resume around the resetwill
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
guarantee that healthy user queues survive the reset.
If the KFD calls the reset, it will only do so during preemption failure, and wedon't
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
want to suspend and resume the KFD again when the KFD calls this function. The KFD needs to call this common function to not disturb GFX and paging
queues
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
for the same reason KGD resets need to be wary of KFD queues.
In the case of preemption failure and a KFD initiated reset, the KFD is holdingthe
Quoted 1 line
Quoted 1 line
Quoted 1 line
device wide preemption lock, so if the KGD is trying to reset as well, it will have
to
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
wait on its own KFD suspend call until the KFD is done its own reset.
I think SDMA6+ can target specific queues via MMIO reg writes, but I see in
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
KGD code that
soft_resetfor SDMA 6+ does a sweep of all engines so wewould
Quoted 1 line
Quoted 1 line
Quoted 1 line
still need to keep KFD queues safe (I'm not familiar with this chunk of the code
or
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
the need for sweeping all engines on the KGD side).
So I'm not sure if Jesse had concerns about potential multiple calls being madein
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
other parts of the code and maybe this was some way to simplify things. Either way, not sure if it's simpler to drop the reset source param and have the
KGD
Quoted 1 line
remember to unconditionally KFD suspend/resume around the soft reset call
for
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
each IP version, or keep the reset source param here so that we only have to remember to do this once.
Could KFD keep track of whether the hang was detected by KFD or KGD? E.g.,
if
Quoted 3 lines
Quoted 3 lines
KFD detects the hang when suspending queues, it could set a flag and then KFD could include a call to
amdgpu_amdkfd_suspend()in itspre_resetcallback that would depend on the value of that flag. At that point I don't think we'd need thesrc
Quoted 4 lines
Quoted 1 line
parameter any more.
Hmmm. Something similar to GPU resets?
The thing about GPU resets is that the KFD could just detect the flag, schedule anevent then carry on knowing the driver is going to die and re-init at some point.
Quoted 1 line
SDMA resets are different because the KFD would call back into the common KGD
call immediately because it wants to fix things right away, and the KGD has to ensure the KFD is quiesced in any case.
Quoted 1 line
So any flag would have to be locked as well in the KFD pre/post calls. Which
means we'd probably have to conditionally lock it based on a new reset context that the KGD would have to supply anyways.
Quoted 1 line
This was the main reason why I wanted to simplify things by leveraging a
conditional suspend/resume call in the common interface.
Quoted 1 line
Maybe I'm not looking at things clearly atm, but if feels like we're pushing the
complication from one part of the driver into another.
Quoted 2 lines
If we really don't like the idea of adding flags, maybe we can just add a param "bool
suspend_user_queues" to the common interface?Quoted 1 line
Then maybe it's clearer that the KGD, as a reset requester, wants to be careful of
destroying in-flight user queues while the KFD doesn't care about this for its own needs (since it's already in post-preemption recovery).
Quoted 1 line
Quoted 5 lines
Having the src for a parameter is fine with me. It just seemed logical to keep it in KFD since presumably KFD would have detected this condition after calling
amdgpu_amdkfd_suspend()itself so it would know whether it would need to be called based on its own state so it would know what to do in its pre and post reset hooks already.
Quoted 7 lines
The case of successful KFD suspend during reset isn't really a concern since the KFD cannot get into a preemption failure at this point. It's the corner case when the KFD suspend fails on a KGD initiated reset because of a user queue hang and KFD has to reset through the KGD call again. In this case, KFD suspend from the KGD initiated reset is in limbo and this initial suspend call is holding the lock for all KFD processes. The KGD is still forced to pass some sort of SDMA reset trigger hint to the KFD when it calls suspend (or pre-reset) for this corner case. Otherwise, the KFD will deadlock on the on its own recall of the reset function when it hits the KFD processes lock again during
kgd2kfd_suspend. So we're stuck either way with the KGD still having to pass something to the KFD (new reset context, bool, flag hint etc ...) if we want to avoid this deadlock.
The reason why I asked about making use of pre-reset KFD callback is -
Ideally, this is a reset of one instance of SDMA instance (even though it's termed as queue reset). What amdgpu_amdkfd_suspend() is doing seem to affect all processes running on all instances. Basically on a system with 8 or 16 SDMA instances, this is not really making sense if it's going to affect all other processes.
Is that really required? Or, is it like KFD can identify the processes using the user queues of that particular instance (pre-reset passes instance) and only suspend them?
Thanks,
Lijo
Quoted 200 lines
Quoted 2 lines
I guess we also stop the kernel queues explicitly in the same function so it makes sense to do the same for KFD.
Yep. We definitely want to minimize reset damage from either caller (KFD or KGD).
I kind of look at it like the rest of the amdgpu_device_reset/suspend/resume calls that need to consider the KFD as well.
I think I'm fine with just passing a boolsuspend_user_queueshere to do the conditional KFD suspend/resume instead of coming up with new reset source context(s). That way we don't have to force callers to use extra long strings in their calls that have no use anywhere else.
They can just pass true/false according to their needs.With that fixed, this patch is:
Acked-by Jonathan Kim <[email protected]>Jon
Quoted 186 lines
Alex
Quoted 82 lines
Jon
Quoted 80 lines
Alex
Quoted 76 lines
Jon
Quoted 73 lines
Thanks,
Lijodrivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-0+ +/* Stop the scheduler's work queue for the GFX and page rings if +they are running.
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +9
-0+* This ensures that no new tasks are submitted to the queues while +* the reset is in progress. +*/ +if (!amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_stop (&gfx_ring->sched); + gfx_sched_stopped = true;; + } + + if (adev->sdma.has_page_queue&& !amdgpu_ring_sched_ready(page_ring)) {
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +5
-2+drm_sched_wqueue_stop (&page_ring->sched); + page_sched_stopped = true; + }/* Invoke all registered pre_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->pre_reset) { - ret = funcs->pre_reset (adev, instance_id); + ret = funcs->pre_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"beforeReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } }@@ -515,21 +546,39 @@ int amdgpu_sdma_reset_engine(structQuoted 1 line
amdgpu_device*adev,
uint32_tinstance_id)Quoted 3 lines
ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id); if (ret) { dev_err(adev->dev, "Failed to reset SDMA instance %u\n",
instance_id);Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +13
-4-return ret; + goto exit; }/* Invoke all registered post_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->post_reset) { - ret = funcs->post_reset (adev, instance_id); + ret = funcs->post_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"afterReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } } -return 0 ; +exit: +/* Restart the scheduler's work queue for the GFX and page rings +* if they were stopped by this function. This allows new tasks +* to be submitted to the queues after the reset is complete. +*/ +if (ret) { +if (gfx_sched_stopped &&amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_start (&gfx_ring->sched); + } + if (page_sched_stopped &&
amdgpu_ring_sched_ready(page_ring)) {Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Review
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +9
-0+drm_sched_wqueue_start (&page_ring->sched); + } + } + +/* Resume KFD if the reset source is not SDMA_HWS */ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_resume (adev, false); + +return ret; }(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.hQuoted 5 lines
index
f91d75848557..2ef2da772254100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0@@ -99,8 +99,8 @@ struct amdgpu_sdma_ras { };Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_sdma_ras { }; · line 101
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1
-2struct sdma_on_reset_funcs { -int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id); -int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id); + int (*pre_reset)(struct amdgpu_device *adev, uint32_t instance_id, intsrc);
Quoted 78 lines
Quoted 77 lines
Quoted 76 lines
Quoted 75 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 168
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2
-0+int (*post_reset)(struct amdgpu_device *adev,uint32_t + instance_id,int src);/* Linked list node to store this structure in a list; */ struct list_head list; };@@ -166,7 +166,7 @@ struct amdgpu_buffer_funcs { }; void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev,struct
sdma_on_reset_funcs*funcs);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-1-int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1
-0+int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id, int src);Review
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)- mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer (adev, ib, s, d, b)(adev)->mman.buffer_funcs-
emit_fill_buffer((ib), (s), (d), (b))(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.cdrivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_sw_init(struct
Quoted 12 lines
index
29a123be90b7..50a086264792100644drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0@@ -30,6 +30,7 @@#include "amdgpu_xcp.h" #include "amdgpu_ucode.h" #include "amdgpu_trace.h" +#include "amdgpu_reset.h" #include "sdma/sdma_4_4_2_offset.h" #include "sdma/sdma_4_4_2_sh_mask.h" @@ -1480,6 +1481,7 @@ static int sdma_v4_4_2_sw_init(struct
amdgpu_ip_block*ip_block)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0if (r)return r;INIT_LIST_HEAD (&adev->sdma.reset_callback_list); +return r; }@@ -1608,10 +1610,10 @@ static int sdma_v4_4_2_reset_queue(struct
amdgpu_ring*ring, unsigned int vmid)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct · line 1613
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-1{struct amdgpu_device *adev = ring->adev;u32 id =GET_INST (SDMA0 , ring->me); -return amdgpu_sdma_reset_engine (adev, id); + return amdgpu_sdma_reset_engine(adev, id,
AMDGPU_RESET_SRC_SDMA_RING);Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1} -static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_stop_queue(struct
Quoted 5 lines
{
u32inst_mask;
structamdgpu_ring*ring =
&adev->sdma.instance[instance_id].ring;drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-0@@ -1628,7 +1630,7 @@ static int sdma_v4_4_2_stop_queue(struct
amdgpu_device*adev,uint32_tinstance_Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1return 0 ; } -static int sdma_v4_4_2_restore_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_restore_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)Quoted 3 lines
{ int i; u32 inst_mask;
RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization
[Public]
Quoted 304 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, February 19, 2025 10:18 PM
To: Kim, Jonathan <[email protected]>; Alex Deucher <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; [email protected]; Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 9 lines · Jonathan
[Public]
Quoted 7 lines
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, February 19, 2025 6:09 PM
To: Kim, Jonathan <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; amd- [email protected]; Kuehling, Felix <[email protected]>; Zhu,Jiadong
Quoted 5 lines
Quoted 5 lines
<[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationOn Wed, Feb 19, 2025 at 3:29 PM Kim, Jonathan <[email protected]>
Quoted 185 lines · wrote:
Quoted 185 lines
Quoted 7 lines
[Public]
Quoted 4 lines
-----Original Message-----
From: Deucher, Alexander <[email protected]>
Sent: Wednesday, February 19, 2025 12:39 PM
To: Kim, Jonathan <[email protected]>; Lazar, LijoQuoted 20 lines
Quoted 20 lines
Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization[Public]
Quoted 12 lines
-----Original Message-----
From: Kim, Jonathan <[email protected]>
Sent: Tuesday, February 18, 2025 12:42 PM
To: Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization[Public]
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, February 17, 2025 10:36 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>;Zhu,
Quoted 38 lines
Quoted 38 lines
Quoted 22 lines
Quoted 22 lines
Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 4 lines · On 2/13/2025 11:17 AM, [email protected] wrote:
From: "[email protected]" <[email protected]>
This commit introduces a caller parameter to the
amdgpu_sdma_reset_instancefunction to differentiate
Quoted 3 lines
between reset requests originating from the KGD and KFD. This change ensures proper synchronization between KGD and KFD during SDMA
resets.
Quoted 3 lines
If the caller is KFD, the function now acquires and releases the scheduler lock
(
ring->sched.job_list_lock)Quoted 2 lines
to protect the SDMA queue during the reset.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
These changes prevent race conditions and ensure safe SDMA reset operations when initiated by KFD, improving system stability and reliability.
V2: replace the
ring_lockwith the existed the schedulerlocks for the queues (ring->sched) on the sdma engine.(Alex)v3: call
drm_sched_wqueue_stop()rather thanjob_list_lock.
If a GPU ring reset was already initiated for one ring at
amdgpu_job_timedout,Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
skip resetting that ring and call
drm_sched_wqueue_stop()for the other rings (Alex)replace the common lock (
sdma_reset_lock) with DQM lock to to resolve reset races between the two driver sections during KFD
eviction.(Jon)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Rename the caller to
Reset_srcand
Change AMDGPU_RESET_SRC_SDMA_KGD/KFD toAMDGPU_RESET_SRC_SDMA_HWS/RING (Jon)
Quoted 4 lines
v4: restart the wqueue if the reset was successful,
or fall back to a full adapter reset. (Alex)move definition of reset source to enumeration
AMDGPU_RESET_SRCS,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
and
Quoted 7 lines
Quoted 4 lines
check reset src in
amdgpu_sdma_reset_instance(Jon)v5: Call amdgpu_amdkfd_suspend/resume at the start/end of reset function
respectively under !SRC_HWS
Quoted 2 lines
conditions only (Jon)
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Suggested-by Alex Deucher <[email protected]>Suggested-by Jiadong Zhu <[email protected]>Suggested-by Jonathan Kim <[email protected]>Signed-off-by Jesse Zhang <[email protected]>Reviewed-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h | 2 +
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c| 65
++++++++++++++++++++---
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.hQuoted 64 lines
Quoted 64 lines
|
Quoted 63 lines
Quoted 63 lines
Review
Quoted 4 lines
6 +--
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c| 8 +--4 files changed, 67 insertions(+), 14 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_reset.hReview
Quoted 13 lines
index
4d9b9701139b..5b86e12ff9fe100644drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +2
-0@@ -43,6 +43,8 @@ enum AMDGPU_RESET_SRCS {AMDGPU_RESET_SRC_MES ,AMDGPU_RESET_SRC_HWS ,AMDGPU_RESET_SRC_USER , +AMDGPU_RESET_SRC_SDMA_RING , + AMDGPU_RESET_SRC_SDMA_HWS, }; struct amdgpu_reset_context {(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.cQuoted 11 lines
index
fe39198307ec..808c7112ef10100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1
-0@@ -25,6 +25,7 @@#include "amdgpu.h" #include "amdgpu_sdma.h" #include "amdgpu_ras.h" +#include "amdgpu_reset.h" #define AMDGPU_CSA_SDMA_SIZE 64 /* SDMA CSA reside in the 3rd page of CSA */ @@ -485,6 +486,7 @@Quoted 1 line
void amdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 8 lines
*
amdgpu_sdma_reset_engine- Reset a specific SDMA engine
* @adev: Pointer to the AMDGPU device
* @instance_id: ID of the SDMA engine instance to reset
+ * @src: The source of reset function (KGD or KFD)
*
* This function performs the following steps:
* 1. Calls all registeredpre_resetcallbacks to allow KFD and
AMDGPU to savetheir state.
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +0
-0@@ -493,20 +495,49 @@ voidamdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 4 lines
*
* Returns: 0 on success, or a negative error code on failure. */
-int amdgpu_sdma_reset_engine(structamdgpu_device*adev,uint32_t
instance_id)Quoted 1 line
+int amdgpu_sdma_reset_engine(struct
amdgpu_device*adev,uint32_t
instance_id, int src)Quoted 12 lines
{ struct sdma_on_reset_funcs *funcs;drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +2
-1-int ret; +int ret =0 ; + struct amdgpu_sdma_instance *sdma_instance = &adev-sdma.instance[instance_id];;
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +6
-0+struct amdgpu_ring *gfx_ring = &sdma_instance->ring; +struct amdgpu_ring *page_ring = &sdma_instance->page; +bool gfx_sched_stopped = false, page_sched_stopped = false; + +/* Check if the reset source is valid for SDMA ring reset */ + if (src != AMDGPU_RESET_SRC_SDMA_RING && src !=Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
AMDGPU_RESET_SRC_HWS)Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +5
-0+return -EINVAL ; + +/* Suspend KFD if the reset source is not SDMA_HWS. +* prevent the destruction of in-flight healthy user queue packets and +* avoid race conditions between KFD and KGD during the reset process.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-0+*/ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_suspend (adev, false);It this has to be done here, what's the idea behind registering a separate pre/post callback for KFD initiated resets?
The problem is that for SDMA v5.x and below, a single soft reset call will reset
all
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
queues on the target SDMA engine.
If the KGD calls the reset, a transient KFD suspend/resume around the resetwill
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
guarantee that healthy user queues survive the reset.
If the KFD calls the reset, it will only do so during preemption failure, and weQuoted 8 lines
Quoted 8 lines
don't
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
want to suspend and resume the KFD again when the KFD calls this function. The KFD needs to call this common function to not disturb GFX and paging
queues
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
for the same reason KGD resets need to be wary of KFD queues.
In the case of preemption failure and a KFD initiated reset, the KFD is holdingthe
Quoted 1 line
Quoted 1 line
Quoted 1 line
device wide preemption lock, so if the KGD is trying to reset as well, it will
have
Quoted 8 lines
Quoted 8 lines
to
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
wait on its own KFD suspend call until the KFD is done its own reset.
I think SDMA6+ can target specific queues via MMIO reg writes, but I see in
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
KGD code that
soft_resetfor SDMA 6+ does a sweep of all engines so wewould
Quoted 1 line
Quoted 1 line
Quoted 1 line
still need to keep KFD queues safe (I'm not familiar with this chunk of the
code
Quoted 3 lines
Quoted 3 lines
or
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
the need for sweeping all engines on the KGD side).
So I'm not sure if Jesse had concerns about potential multiple calls beingmade
Quoted 3 lines
Quoted 3 lines
in
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
other parts of the code and maybe this was some way to simplify things. Either way, not sure if it's simpler to drop the reset source param and have
the
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
KGD
Quoted 1 line
remember to unconditionally KFD suspend/resume around the soft reset call
for
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
each IP version, or keep the reset source param here so that we only have to remember to do this once.
Could KFD keep track of whether the hang was detected by KFD or KGD?
E.g.,
Quoted 2 lines
Quoted 2 lines
if
Quoted 1 line
Quoted 1 line
KFD detects the hang when suspending queues, it could set a flag and then
KFD
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
could include a call to
amdgpu_amdkfd_suspend()in itspre_resetcallback that would depend on the value of that flag. At that point I don't think we'd need thesrc
Quoted 4 lines
Quoted 1 line
parameter any more.
Hmmm. Something similar to GPU resets?
The thing about GPU resets is that the KFD could just detect the flag, schedulean
Quoted 2 lines
Quoted 2 lines
event then carry on knowing the driver is going to die and re-init at some point.
Quoted 1 line
SDMA resets are different because the KFD would call back into the common
KGD
Quoted 1 line
Quoted 1 line
call immediately because it wants to fix things right away, and the KGD has to
ensure
Quoted 3 lines
Quoted 3 lines
the KFD is quiesced in any case.
Quoted 1 line
So any flag would have to be locked as well in the KFD pre/post calls. Which
means we'd probably have to conditionally lock it based on a new reset context
that
Quoted 7 lines
Quoted 7 lines
the KGD would have to supply anyways.
Quoted 1 line
This was the main reason why I wanted to simplify things by leveraging a
conditional suspend/resume call in the common interface.
Quoted 1 line
Maybe I'm not looking at things clearly atm, but if feels like we're pushing the
complication from one part of the driver into another.
Quoted 2 lines
If we really don't like the idea of adding flags, maybe we can just add a param
"bool
Quoted 2 lines
Quoted 2 lines
suspend_user_queues" to the common interface?Quoted 1 line
Then maybe it's clearer that the KGD, as a reset requester, wants to be careful
of
Quoted 11 lines
Quoted 9 lines
destroying in-flight user queues while the KFD doesn't care about this for its own needs (since it's already in post-preemption recovery).
Quoted 1 line
Having the src for a parameter is fine with me. It just seemed logical to keep it in KFD since presumably KFD would have detected this condition after calling
amdgpu_amdkfd_suspend()itself so it would know whether it would need to be called based on its own state so it would know what to do in its pre and post reset hooks already.The case of successful KFD suspend during reset isn't really a concern since the
KFD cannot get into a preemption failure at this point.
Quoted 1 line
It's the corner case when the KFD suspend fails on a KGD initiated reset because
of a user queue hang and KFD has to reset through the KGD call again.
Quoted 1 line
In this case, KFD suspend from the KGD initiated reset is in limbo and this initial
suspend call is holding the lock for all KFD processes.
Quoted 1 line
The KGD is still forced to pass some sort of SDMA reset trigger hint to the KFD
when it calls suspend (or pre-reset) for this corner case.
Quoted 1 line
Otherwise, the KFD will deadlock on the on its own recall of the reset function
when it hits the KFD processes lock again during
kgd2kfd_suspend.Quoted 1 line
So we're stuck either way with the KGD still having to pass something to the KFD
(new reset context, bool, flag hint etc ...) if we want to avoid this deadlock.
Quoted 1 line
Quoted 7 lines
The reason why I asked about making use of pre-reset KFD callback is -
Ideally, this is a reset of one instance of SDMA instance (even though it's termed as queue reset). What
amdgpu_amdkfd_suspend()is doing seem to affect all processes running on all instances. Basically on a system with 8 or 16 SDMA instances, this is not really making sense if it's going to affect all other processes.
F32 HWS devices quiesce the entire device on runlist update anyways so I don't really see any performance savings there.
RS64 HWS devices per-queue remove/suspend but that means save/restore is overall more efficient anyways.
The KFD will have to quiesce the device prior to queue reset on RS64 HWS devices via the MES suspend_all call as well because the KFD doesn't know the cause of an MES hang apriori regardless of the queue on remove_queue request.
"Not really making sense" only "doesn't really make sense" if there's a strict performance requirement for reset handling.
What's the benchmark requirement here?
If there isn't one, then having the KGD do new reset_context baton pass in pre-reset to a new KFD suspend/resume to filter suspend by SW queues by assigned engine id, then locking out all processes from doing a KFD queue creation on the targeted engine (because we'd have to prevent user space from creating new queues that could enqueue that engine during reset) before we do a reset seems not only like a huge waste of time but potentially creates an explosion of more corner cases to deal with. So a single bool param here to trigger conditional device quiescence that temporarily locks out KFD activity during reset for safety, though crude and simple, seems reasonable enough to get the job done.
If there is a target reset handling benchmark that I don't know about (and I'd be curious to know about it ... and optimization again would probably only apply to RS64 HWS devices ...), then maybe doing an engine id filter is a follow-on scope to consider.
Jon
Quoted 213 lines
Is that really required? Or, is it like KFD can identify the processes using the user queues of that particular instance (pre-reset passes instance) and only suspend them?
Thanks,
LijoQuoted 4 lines
Quoted 2 lines
I guess we also stop the kernel queues explicitly in the same function so it makes sense to do the same for KFD.
Yep. We definitely want to minimize reset damage from either caller (KFD or
KGD).
Quoted 1 line
I kind of look at it like the rest of the amdgpu_device_reset/suspend/resume calls
that need to consider the KFD as well.
Quoted 1 line
I think I'm fine with just passing a bool
suspend_user_queueshere to do theconditional KFD suspend/resume instead of coming up with new reset source context(s).
Quoted 1 line
That way we don't have to force callers to use extra long strings in their calls that
have no use anywhere else.
Quoted 193 lines
They can just pass true/false according to their needs.
With that fixed, this patch is:
Acked-by Jonathan Kim <[email protected]>Jon
Quoted 186 lines
Alex
Quoted 82 lines
Jon
Quoted 80 lines
Alex
Quoted 76 lines
Jon
Quoted 73 lines
Thanks,
Lijodrivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-0+ +/* Stop the scheduler's work queue for the GFX and page rings if +they are running.
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +9
-0+* This ensures that no new tasks are submitted to the queues while +* the reset is in progress. +*/ +if (!amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_stop (&gfx_ring->sched); + gfx_sched_stopped = true;; + } + + if (adev->sdma.has_page_queue&& !amdgpu_ring_sched_ready(page_ring)) {
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +5
-2+drm_sched_wqueue_stop (&page_ring->sched); + page_sched_stopped = true; + }/* Invoke all registered pre_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->pre_reset) { - ret = funcs->pre_reset (adev, instance_id); + ret = funcs->pre_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"beforeReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } }@@ -515,21 +546,39 @@ int amdgpu_sdma_reset_engine(structQuoted 1 line
amdgpu_device*adev,
uint32_tinstance_id)Quoted 3 lines
ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id); if (ret) { dev_err(adev->dev, "Failed to reset SDMA instance %u\n",
instance_id);Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +13
-4-return ret; + goto exit; }/* Invoke all registered post_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->post_reset) { - ret = funcs->post_reset (adev, instance_id); + ret = funcs->post_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"afterReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } } -return 0 ; +exit: +/* Restart the scheduler's work queue for the GFX and page rings +* if they were stopped by this function. This allows new tasks +* to be submitted to the queues after the reset is complete. +*/ +if (ret) { +if (gfx_sched_stopped &&amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_start (&gfx_ring->sched); + } + if (page_sched_stopped &&
amdgpu_ring_sched_ready(page_ring)) {Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Review
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +9
-0+drm_sched_wqueue_start (&page_ring->sched); + } + } + +/* Resume KFD if the reset source is not SDMA_HWS */ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_resume (adev, false); + +return ret; }(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.hQuoted 5 lines
index
f91d75848557..2ef2da772254100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0@@ -99,8 +99,8 @@ struct amdgpu_sdma_ras { };Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_sdma_ras { }; · line 101
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1
-2struct sdma_on_reset_funcs { -int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id); -int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id); + int (*pre_reset)(struct amdgpu_device *adev, uint32_t instance_id, intsrc);
Quoted 78 lines
Quoted 77 lines
Quoted 76 lines
Quoted 75 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 168
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2
-0+int (*post_reset)(struct amdgpu_device *adev,uint32_t + instance_id,int src);/* Linked list node to store this structure in a list; */ struct list_head list; };@@ -166,7 +166,7 @@ struct amdgpu_buffer_funcs { }; void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev,struct
sdma_on_reset_funcs*funcs);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-1-int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1
-0+int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id, int src);Review
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)- mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer (adev, ib, s, d, b)(adev)->mman.buffer_funcs-
emit_fill_buffer((ib), (s), (d), (b))(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.cdrivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_sw_init(struct
Quoted 12 lines
index
29a123be90b7..50a086264792100644drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0@@ -30,6 +30,7 @@#include "amdgpu_xcp.h" #include "amdgpu_ucode.h" #include "amdgpu_trace.h" +#include "amdgpu_reset.h" #include "sdma/sdma_4_4_2_offset.h" #include "sdma/sdma_4_4_2_sh_mask.h" @@ -1480,6 +1481,7 @@ static int sdma_v4_4_2_sw_init(struct
amdgpu_ip_block*ip_block)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0if (r)return r;INIT_LIST_HEAD (&adev->sdma.reset_callback_list); +return r; }@@ -1608,10 +1610,10 @@ static int sdma_v4_4_2_reset_queue(struct
amdgpu_ring*ring, unsigned int vmid)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct · line 1613
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-1{struct amdgpu_device *adev = ring->adev;u32 id =GET_INST (SDMA0 , ring->me); -return amdgpu_sdma_reset_engine (adev, id); + return amdgpu_sdma_reset_engine(adev, id,
AMDGPU_RESET_SRC_SDMA_RING);Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1} -static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_stop_queue(struct
Quoted 5 lines
{
u32inst_mask;
structamdgpu_ring*ring =
&adev->sdma.instance[instance_id].ring;drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-0@@ -1628,7 +1630,7 @@ static int sdma_v4_4_2_stop_queue(struct
amdgpu_device*adev,uint32_tinstance_Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1return 0 ; } -static int sdma_v4_4_2_restore_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_restore_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)Quoted 3 lines
{ int i; u32 inst_mask;
Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization
Quoted 314 lines · Jonathan
[Public]
Quoted 304 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, February 19, 2025 10:18 PM
To: Kim, Jonathan <[email protected]>; Alex Deucher <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; [email protected]; Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 9 lines · Jonathan
[Public]
Quoted 7 lines
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, February 19, 2025 6:09 PM
To: Kim, Jonathan <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; amd- [email protected]; Kuehling, Felix <[email protected]>; Zhu,Jiadong
Quoted 5 lines
Quoted 5 lines
<[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationOn Wed, Feb 19, 2025 at 3:29 PM Kim, Jonathan <[email protected]>
Quoted 185 lines · wrote:
Quoted 185 lines
Quoted 7 lines
[Public]
Quoted 4 lines
-----Original Message-----
From: Deucher, Alexander <[email protected]>
Sent: Wednesday, February 19, 2025 12:39 PM
To: Kim, Jonathan <[email protected]>; Lazar, LijoQuoted 20 lines
Quoted 20 lines
Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization[Public]
Quoted 12 lines
-----Original Message-----
From: Kim, Jonathan <[email protected]>
Sent: Tuesday, February 18, 2025 12:42 PM
To: Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization[Public]
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, February 17, 2025 10:36 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>;Zhu,
Quoted 38 lines
Quoted 38 lines
Quoted 22 lines
Quoted 22 lines
Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 4 lines · On 2/13/2025 11:17 AM, [email protected] wrote:
From: "[email protected]" <[email protected]>
This commit introduces a caller parameter to the
amdgpu_sdma_reset_instancefunction to differentiate
Quoted 3 lines
between reset requests originating from the KGD and KFD. This change ensures proper synchronization between KGD and KFD during SDMA
resets.
Quoted 3 lines
If the caller is KFD, the function now acquires and releases the scheduler lock
(
ring->sched.job_list_lock)Quoted 2 lines
to protect the SDMA queue during the reset.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
These changes prevent race conditions and ensure safe SDMA reset operations when initiated by KFD, improving system stability and reliability.
V2: replace the
ring_lockwith the existed the schedulerlocks for the queues (ring->sched) on the sdma engine.(Alex)v3: call
drm_sched_wqueue_stop()rather thanjob_list_lock.
If a GPU ring reset was already initiated for one ring at
amdgpu_job_timedout,Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
skip resetting that ring and call
drm_sched_wqueue_stop()for the other rings (Alex)replace the common lock (
sdma_reset_lock) with DQM lock to to resolve reset races between the two driver sections during KFD
eviction.(Jon)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Rename the caller to
Reset_srcand
Change AMDGPU_RESET_SRC_SDMA_KGD/KFD toAMDGPU_RESET_SRC_SDMA_HWS/RING (Jon)
Quoted 4 lines
v4: restart the wqueue if the reset was successful,
or fall back to a full adapter reset. (Alex)move definition of reset source to enumeration
AMDGPU_RESET_SRCS,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
and
Quoted 7 lines
Quoted 4 lines
check reset src in
amdgpu_sdma_reset_instance(Jon)v5: Call amdgpu_amdkfd_suspend/resume at the start/end of reset function
respectively under !SRC_HWS
Quoted 2 lines
conditions only (Jon)
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Suggested-by Alex Deucher <[email protected]>Suggested-by Jiadong Zhu <[email protected]>Suggested-by Jonathan Kim <[email protected]>Signed-off-by Jesse Zhang <[email protected]>Reviewed-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h | 2 +
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c| 65
++++++++++++++++++++---
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.hQuoted 64 lines
Quoted 64 lines
|
Quoted 63 lines
Quoted 63 lines
Review
Quoted 4 lines
6 +--
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c| 8 +--4 files changed, 67 insertions(+), 14 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_reset.hReview
Quoted 13 lines
index
4d9b9701139b..5b86e12ff9fe100644drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +2
-0@@ -43,6 +43,8 @@ enum AMDGPU_RESET_SRCS {AMDGPU_RESET_SRC_MES ,AMDGPU_RESET_SRC_HWS ,AMDGPU_RESET_SRC_USER , +AMDGPU_RESET_SRC_SDMA_RING , + AMDGPU_RESET_SRC_SDMA_HWS, }; struct amdgpu_reset_context {(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.cQuoted 11 lines
index
fe39198307ec..808c7112ef10100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1
-0@@ -25,6 +25,7 @@#include "amdgpu.h" #include "amdgpu_sdma.h" #include "amdgpu_ras.h" +#include "amdgpu_reset.h" #define AMDGPU_CSA_SDMA_SIZE 64 /* SDMA CSA reside in the 3rd page of CSA */ @@ -485,6 +486,7 @@Quoted 1 line
void amdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 8 lines
*
amdgpu_sdma_reset_engine- Reset a specific SDMA engine
* @adev: Pointer to the AMDGPU device
* @instance_id: ID of the SDMA engine instance to reset
+ * @src: The source of reset function (KGD or KFD)
*
* This function performs the following steps:
* 1. Calls all registeredpre_resetcallbacks to allow KFD and
AMDGPU to savetheir state.
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +0
-0@@ -493,20 +495,49 @@ voidamdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 4 lines
*
* Returns: 0 on success, or a negative error code on failure. */
-int amdgpu_sdma_reset_engine(structamdgpu_device*adev,uint32_t
instance_id)Quoted 1 line
+int amdgpu_sdma_reset_engine(struct
amdgpu_device*adev,uint32_t
instance_id, int src)Quoted 12 lines
{ struct sdma_on_reset_funcs *funcs;drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +2
-1-int ret; +int ret =0 ; + struct amdgpu_sdma_instance *sdma_instance = &adev-sdma.instance[instance_id];;
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +6
-0+struct amdgpu_ring *gfx_ring = &sdma_instance->ring; +struct amdgpu_ring *page_ring = &sdma_instance->page; +bool gfx_sched_stopped = false, page_sched_stopped = false; + +/* Check if the reset source is valid for SDMA ring reset */ + if (src != AMDGPU_RESET_SRC_SDMA_RING && src !=Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
AMDGPU_RESET_SRC_HWS)Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +5
-0+return -EINVAL ; + +/* Suspend KFD if the reset source is not SDMA_HWS. +* prevent the destruction of in-flight healthy user queue packets and +* avoid race conditions between KFD and KGD during the reset process.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-0+*/ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_suspend (adev, false);It this has to be done here, what's the idea behind registering a separate pre/post callback for KFD initiated resets?
The problem is that for SDMA v5.x and below, a single soft reset call will reset
all
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
queues on the target SDMA engine.
If the KGD calls the reset, a transient KFD suspend/resume around the resetwill
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
guarantee that healthy user queues survive the reset.
If the KFD calls the reset, it will only do so during preemption failure, and weQuoted 8 lines
Quoted 8 lines
don't
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
want to suspend and resume the KFD again when the KFD calls this function. The KFD needs to call this common function to not disturb GFX and paging
queues
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
for the same reason KGD resets need to be wary of KFD queues.
In the case of preemption failure and a KFD initiated reset, the KFD is holdingthe
Quoted 1 line
Quoted 1 line
Quoted 1 line
device wide preemption lock, so if the KGD is trying to reset as well, it will
have
Quoted 8 lines
Quoted 8 lines
to
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
wait on its own KFD suspend call until the KFD is done its own reset.
I think SDMA6+ can target specific queues via MMIO reg writes, but I see in
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
KGD code that
soft_resetfor SDMA 6+ does a sweep of all engines so wewould
Quoted 1 line
Quoted 1 line
Quoted 1 line
still need to keep KFD queues safe (I'm not familiar with this chunk of the
code
Quoted 3 lines
Quoted 3 lines
or
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
the need for sweeping all engines on the KGD side).
So I'm not sure if Jesse had concerns about potential multiple calls beingmade
Quoted 3 lines
Quoted 3 lines
in
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
other parts of the code and maybe this was some way to simplify things. Either way, not sure if it's simpler to drop the reset source param and have
the
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
KGD
Quoted 1 line
remember to unconditionally KFD suspend/resume around the soft reset call
for
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
each IP version, or keep the reset source param here so that we only have to remember to do this once.
Could KFD keep track of whether the hang was detected by KFD or KGD?
E.g.,
Quoted 2 lines
Quoted 2 lines
if
Quoted 1 line
Quoted 1 line
KFD detects the hang when suspending queues, it could set a flag and then
KFD
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
could include a call to
amdgpu_amdkfd_suspend()in itspre_resetcallback that would depend on the value of that flag. At that point I don't think we'd need thesrc
Quoted 4 lines
Quoted 1 line
parameter any more.
Hmmm. Something similar to GPU resets?
The thing about GPU resets is that the KFD could just detect the flag, schedulean
Quoted 2 lines
Quoted 2 lines
event then carry on knowing the driver is going to die and re-init at some point.
Quoted 1 line
SDMA resets are different because the KFD would call back into the common
KGD
Quoted 1 line
Quoted 1 line
call immediately because it wants to fix things right away, and the KGD has to
ensure
Quoted 3 lines
Quoted 3 lines
the KFD is quiesced in any case.
Quoted 1 line
So any flag would have to be locked as well in the KFD pre/post calls. Which
means we'd probably have to conditionally lock it based on a new reset context
that
Quoted 7 lines
Quoted 7 lines
the KGD would have to supply anyways.
Quoted 1 line
This was the main reason why I wanted to simplify things by leveraging a
conditional suspend/resume call in the common interface.
Quoted 1 line
Maybe I'm not looking at things clearly atm, but if feels like we're pushing the
complication from one part of the driver into another.
Quoted 2 lines
If we really don't like the idea of adding flags, maybe we can just add a param
"bool
Quoted 2 lines
Quoted 2 lines
suspend_user_queues" to the common interface?Quoted 1 line
Then maybe it's clearer that the KGD, as a reset requester, wants to be careful
of
Quoted 11 lines
Quoted 9 lines
destroying in-flight user queues while the KFD doesn't care about this for its own needs (since it's already in post-preemption recovery).
Quoted 1 line
Having the src for a parameter is fine with me. It just seemed logical to keep it in KFD since presumably KFD would have detected this condition after calling
amdgpu_amdkfd_suspend()itself so it would know whether it would need to be called based on its own state so it would know what to do in its pre and post reset hooks already.The case of successful KFD suspend during reset isn't really a concern since the
KFD cannot get into a preemption failure at this point.
Quoted 1 line
It's the corner case when the KFD suspend fails on a KGD initiated reset because
of a user queue hang and KFD has to reset through the KGD call again.
Quoted 1 line
In this case, KFD suspend from the KGD initiated reset is in limbo and this initial
suspend call is holding the lock for all KFD processes.
Quoted 1 line
The KGD is still forced to pass some sort of SDMA reset trigger hint to the KFD
when it calls suspend (or pre-reset) for this corner case.
Quoted 1 line
Otherwise, the KFD will deadlock on the on its own recall of the reset function
when it hits the KFD processes lock again during
kgd2kfd_suspend.Quoted 1 line
So we're stuck either way with the KGD still having to pass something to the KFD
(new reset context, bool, flag hint etc ...) if we want to avoid this deadlock.
Quoted 1 line
Quoted 7 lines
The reason why I asked about making use of pre-reset KFD callback is -
Ideally, this is a reset of one instance of SDMA instance (even though it's termed as queue reset). What
amdgpu_amdkfd_suspend()is doing seem to affect all processes running on all instances. Basically on a system with 8 or 16 SDMA instances, this is not really making sense if it's going to affect all other processes.
Quoted 9 lines
F32 HWS devices quiesce the entire device on runlist update anyways so I don't really see any performance savings there.
RS64 HWS devices per-queue remove/suspend but that means save/restore is overall more efficient anyways.
The KFD will have to quiesce the device prior to queue reset on RS64 HWS devices via the MESsuspend_allcall as well because the KFD doesn't know the cause of an MES hang apriori regardless of the queue onremove_queuerequest.
"Not really making sense" only "doesn't really make sense" if there's a strict performance requirement for reset handling.
What's the benchmark requirement here?
If there isn't one, then having the KGD do newreset_contextbaton pass in pre-reset to a new KFD suspend/resume to filter suspend by SW queues by assigned engine id, then locking out all processes from doing a KFD queue creation on the targeted engine (because we'd have to prevent user space from creating new queues that could enqueue that engine during reset) before we do a reset seems not only like a huge waste of time but potentially creates an explosion of more corner cases to deal with. So a single bool param here to trigger conditional device quiescence that temporarily locks out KFD activity during reset for safety, though crude and simple, seems reasonable enough to get the job done.
If there is a target reset handling benchmark that I don't know about (and I'd be curious to know about it ... and optimization again would probably only apply to RS64 HWS devices ...), then maybe doing an engine id filter is a follow-on scope to consider.
My thinking is -
Doing a targeted queue or engine reset doesn't affect other processes which are not making use of the queue or engine (a similar thing is done during poison consumption on some SOCs where only the affected processes get unmapped leaving other running processes unaffected). This may have more significance when there are multiple partitions on the device. I guess F32 HWS in co-operative dispatch mode also just affects the particular partition and not the entire device.
Engine/Queue reset is comparatively faster than doing a device-wide reset.
Alex may be able to provide better details.
Thanks,
Lijo
Quoted 215 lines
Jon
Quoted 213 lines
Is that really required? Or, is it like KFD can identify the processes using the user queues of that particular instance (pre-reset passes instance) and only suspend them?
Thanks,
LijoQuoted 4 lines
Quoted 2 lines
I guess we also stop the kernel queues explicitly in the same function so it makes sense to do the same for KFD.
Yep. We definitely want to minimize reset damage from either caller (KFD or
KGD).
Quoted 1 line
I kind of look at it like the rest of the amdgpu_device_reset/suspend/resume calls
that need to consider the KFD as well.
Quoted 1 line
I think I'm fine with just passing a bool
suspend_user_queueshere to do theconditional KFD suspend/resume instead of coming up with new reset source context(s).
Quoted 1 line
That way we don't have to force callers to use extra long strings in their calls that
have no use anywhere else.
Quoted 193 lines
They can just pass true/false according to their needs.
With that fixed, this patch is:
Acked-by Jonathan Kim <[email protected]>Jon
Quoted 186 lines
Alex
Quoted 82 lines
Jon
Quoted 80 lines
Alex
Quoted 76 lines
Jon
Quoted 73 lines
Thanks,
Lijodrivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-0+ +/* Stop the scheduler's work queue for the GFX and page rings if +they are running.
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +9
-0+* This ensures that no new tasks are submitted to the queues while +* the reset is in progress. +*/ +if (!amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_stop (&gfx_ring->sched); + gfx_sched_stopped = true;; + } + + if (adev->sdma.has_page_queue&& !amdgpu_ring_sched_ready(page_ring)) {
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +5
-2+drm_sched_wqueue_stop (&page_ring->sched); + page_sched_stopped = true; + }/* Invoke all registered pre_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->pre_reset) { - ret = funcs->pre_reset (adev, instance_id); + ret = funcs->pre_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"beforeReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } }@@ -515,21 +546,39 @@ int amdgpu_sdma_reset_engine(structQuoted 1 line
amdgpu_device*adev,
uint32_tinstance_id)Quoted 3 lines
ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id); if (ret) { dev_err(adev->dev, "Failed to reset SDMA instance %u\n",
instance_id);Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +13
-4-return ret; + goto exit; }/* Invoke all registered post_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->post_reset) { - ret = funcs->post_reset (adev, instance_id); + ret = funcs->post_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"afterReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } } -return 0 ; +exit: +/* Restart the scheduler's work queue for the GFX and page rings +* if they were stopped by this function. This allows new tasks +* to be submitted to the queues after the reset is complete. +*/ +if (ret) { +if (gfx_sched_stopped &&amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_start (&gfx_ring->sched); + } + if (page_sched_stopped &&
amdgpu_ring_sched_ready(page_ring)) {Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Review
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +9
-0+drm_sched_wqueue_start (&page_ring->sched); + } + } + +/* Resume KFD if the reset source is not SDMA_HWS */ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_resume (adev, false); + +return ret; }(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.hQuoted 5 lines
index
f91d75848557..2ef2da772254100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0@@ -99,8 +99,8 @@ struct amdgpu_sdma_ras { };Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_sdma_ras { }; · line 101
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1
-2struct sdma_on_reset_funcs { -int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id); -int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id); + int (*pre_reset)(struct amdgpu_device *adev, uint32_t instance_id, intsrc);
Quoted 78 lines
Quoted 77 lines
Quoted 76 lines
Quoted 75 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 168
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2
-0+int (*post_reset)(struct amdgpu_device *adev,uint32_t + instance_id,int src);/* Linked list node to store this structure in a list; */ struct list_head list; };@@ -166,7 +166,7 @@ struct amdgpu_buffer_funcs { }; void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev,struct
sdma_on_reset_funcs*funcs);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-1-int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1
-0+int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id, int src);Review
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)- mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer (adev, ib, s, d, b)(adev)->mman.buffer_funcs-
emit_fill_buffer((ib), (s), (d), (b))(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.cdrivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_sw_init(struct
Quoted 12 lines
index
29a123be90b7..50a086264792100644drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0@@ -30,6 +30,7 @@#include "amdgpu_xcp.h" #include "amdgpu_ucode.h" #include "amdgpu_trace.h" +#include "amdgpu_reset.h" #include "sdma/sdma_4_4_2_offset.h" #include "sdma/sdma_4_4_2_sh_mask.h" @@ -1480,6 +1481,7 @@ static int sdma_v4_4_2_sw_init(struct
amdgpu_ip_block*ip_block)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0if (r)return r;INIT_LIST_HEAD (&adev->sdma.reset_callback_list); +return r; }@@ -1608,10 +1610,10 @@ static int sdma_v4_4_2_reset_queue(struct
amdgpu_ring*ring, unsigned int vmid)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_reset_queue(struct · line 1613
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-1{struct amdgpu_device *adev = ring->adev;u32 id =GET_INST (SDMA0 , ring->me); -return amdgpu_sdma_reset_engine (adev, id); + return amdgpu_sdma_reset_engine(adev, id,
AMDGPU_RESET_SRC_SDMA_RING);Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1} -static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_stop_queue(struct
Quoted 5 lines
{
u32inst_mask;
structamdgpu_ring*ring =
&adev->sdma.instance[instance_id].ring;drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-0@@ -1628,7 +1630,7 @@ static int sdma_v4_4_2_stop_queue(struct
amdgpu_device*adev,uint32_tinstance_Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1return 0 ; } -static int sdma_v4_4_2_restore_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_restore_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)Quoted 3 lines
{ int i; u32 inst_mask;
RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronization
[Public]
Quoted 380 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, February 20, 2025 1:30 AM
To: Kim, Jonathan <[email protected]>; Alex Deucher <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; [email protected]; Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 41 lines · Jonathan
[Public]
Quoted 39 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Wednesday, February 19, 2025 10:18 PM
To: Kim, Jonathan <[email protected]>; Alex Deucher <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; [email protected]; Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 9 lines · Jonathan
[Public]
Quoted 7 lines
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, February 19, 2025 6:09 PM
To: Kim, Jonathan <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; amd- [email protected]; Kuehling, Felix <[email protected]>; Zhu,Jiadong
Quoted 5 lines
Quoted 5 lines
<[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationOn Wed, Feb 19, 2025 at 3:29 PM Kim, Jonathan <[email protected]>
Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 7 lines
[Public]
Quoted 4 lines
-----Original Message-----
From: Deucher, Alexander <[email protected]>
Sent: Wednesday, February 19, 2025 12:39 PM
To: Kim, Jonathan <[email protected]>; Lazar, LijoQuoted 1 line
Quoted 1 line
Zhang, Jesse(Jie) <[email protected]>; amd-
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Cc: Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and resetcaller
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
parameter for SDMA reset synchronization
[Public]
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
-----Original Message-----
From: Kim, Jonathan <[email protected]>
Sent: Tuesday, February 18, 2025 12:42 PM
To: Lazar, Lijo <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Zhu, Jiadong <[email protected]>
Subject: RE: [PATCH V7 3/9] drm/amdgpu: Add common lock and resetcaller
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
parameter for SDMA reset synchronization
[Public]
Quoted 6 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, February 17, 2025 10:36 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling,Felix
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
<[email protected]>; Kim, Jonathan
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Zhu,
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Jiadong <[email protected]>
Subject: Re: [PATCH V7 3/9] drm/amdgpu: Add common lock and reset caller parameter for SDMA reset synchronizationQuoted 4 lines · On 2/13/2025 11:17 AM, [email protected] wrote:
From: "[email protected]" <[email protected]>
This commit introduces a caller parameter to the
amdgpu_sdma_reset_instancefunction to differentiate
Quoted 3 lines
between reset requests originating from the KGD and KFD. This change ensures proper synchronization between KGD and KFD during SDMA
resets.
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
If the caller is KFD, the function now acquires and releases the scheduler lock
(
ring->sched.job_list_lock)Quoted 4 lines
to protect the SDMA queue during the reset.
These changes prevent race conditions and ensure safe SDMA reset operations when initiated by KFD, improving system stability and
reliability.
Quoted 111 lines
Quoted 111 lines
Quoted 111 lines
Quoted 111 lines
Quoted 14 lines
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
V2: replace the
ring_lockwith the existed the schedulerlocks for the queues (ring->sched) on the sdma engine.(Alex)v3: call
drm_sched_wqueue_stop()rather thanjob_list_lock.
If a GPU ring reset was already initiated for one ring at
amdgpu_job_timedout,Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
skip resetting that ring and call
drm_sched_wqueue_stop()for the other rings (Alex)replace the common lock (
sdma_reset_lock) with DQM lock to to resolve reset races between the two driver sections during KFD
eviction.(Jon)Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Rename the caller to
Reset_srcand
Change AMDGPU_RESET_SRC_SDMA_KGD/KFD toAMDGPU_RESET_SRC_SDMA_HWS/RING (Jon)
Quoted 4 lines
v4: restart the wqueue if the reset was successful,
or fall back to a full adapter reset. (Alex)move definition of reset source to enumeration
AMDGPU_RESET_SRCS,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
and
Quoted 7 lines
Quoted 4 lines
check reset src in
amdgpu_sdma_reset_instance(Jon)v5: Call amdgpu_amdkfd_suspend/resume at the start/end of reset function
respectively under !SRC_HWS
Quoted 2 lines
conditions only (Jon)
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Suggested-by Alex Deucher <[email protected]>Suggested-by Jiadong Zhu <[email protected]>Suggested-by Jonathan Kim <[email protected]>Signed-off-by Jesse Zhang <[email protected]>Reviewed-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h | 2 +
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c| 65
++++++++++++++++++++---
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.hQuoted 64 lines
Quoted 64 lines
|
Quoted 63 lines
Quoted 63 lines
Review
Quoted 4 lines
6 +--
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c| 8 +--4 files changed, 67 insertions(+), 14 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_reset.hReview
Quoted 13 lines
index
4d9b9701139b..5b86e12ff9fe100644drivers/gpu/drm/amd/amdgpu/amdgpu_reset.h +2
-0@@ -43,6 +43,8 @@ enum AMDGPU_RESET_SRCS {AMDGPU_RESET_SRC_MES ,AMDGPU_RESET_SRC_HWS ,AMDGPU_RESET_SRC_USER , +AMDGPU_RESET_SRC_SDMA_RING , + AMDGPU_RESET_SRC_SDMA_HWS, }; struct amdgpu_reset_context {(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.cQuoted 11 lines
index
fe39198307ec..808c7112ef10100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +1
-0@@ -25,6 +25,7 @@#include "amdgpu.h" #include "amdgpu_sdma.h" #include "amdgpu_ras.h" +#include "amdgpu_reset.h" #define AMDGPU_CSA_SDMA_SIZE 64 /* SDMA CSA reside in the 3rd page of CSA */ @@ -485,6 +486,7 @@Quoted 1 line
void amdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 8 lines
*
amdgpu_sdma_reset_engine- Reset a specific SDMA engine
* @adev: Pointer to the AMDGPU device
* @instance_id: ID of the SDMA engine instance to reset
+ * @src: The source of reset function (KGD or KFD)
*
* This function performs the following steps:
* 1. Calls all registeredpre_resetcallbacks to allow KFD and
AMDGPU to savetheir state.
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +0
-0@@ -493,20 +495,49 @@ voidamdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_device*adev, structQuoted 4 lines
*
* Returns: 0 on success, or a negative error code on failure. */
-int amdgpu_sdma_reset_engine(structamdgpu_device*adev,uint32_t
instance_id)Quoted 1 line
+int amdgpu_sdma_reset_engine(struct
amdgpu_device*adev,uint32_t
instance_id, int src)Quoted 12 lines
{ struct sdma_on_reset_funcs *funcs;drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +2
-1-int ret; +int ret =0 ; + struct amdgpu_sdma_instance *sdma_instance = &adev-sdma.instance[instance_id];;
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +6
-0+struct amdgpu_ring *gfx_ring = &sdma_instance->ring; +struct amdgpu_ring *page_ring = &sdma_instance->page; +bool gfx_sched_stopped = false, page_sched_stopped = false; + +/* Check if the reset source is valid for SDMA ring reset */ + if (src != AMDGPU_RESET_SRC_SDMA_RING && src !=Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
AMDGPU_RESET_SRC_HWS)Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +5
-0+return -EINVAL ; + +/* Suspend KFD if the reset source is not SDMA_HWS. +* prevent the destruction of in-flight healthy user queue packets and +* avoid race conditions between KFD and KGD during the reset process.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-0+*/ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_suspend (adev, false);It this has to be done here, what's the idea behind registering a separate pre/post callback for KFD initiated resets?
The problem is that for SDMA v5.x and below, a single soft reset call will
reset
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
all
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
queues on the target SDMA engine.
If the KGD calls the reset, a transient KFD suspend/resume around thereset
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
will
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
guarantee that healthy user queues survive the reset.
If the KFD calls the reset, it will only do so during preemption failure, andwe
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
don't
Quoted 1 line
Quoted 1 line
Quoted 1 line
want to suspend and resume the KFD again when the KFD calls this
function.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
The KFD needs to call this common function to not disturb GFX and
paging
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
queues
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
for the same reason KGD resets need to be wary of KFD queues. In the case of preemption failure and a KFD initiated reset, the KFD is
holding
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
device wide preemption lock, so if the KGD is trying to reset as well, it will
have
Quoted 4 lines
Quoted 4 lines
to
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
wait on its own KFD suspend call until the KFD is done its own reset.
I think SDMA6+ can target specific queues via MMIO reg writes, but I see
in
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
KGD code that
soft_resetfor SDMA 6+ does a sweep of all engines so wewould
Quoted 1 line
Quoted 1 line
Quoted 1 line
still need to keep KFD queues safe (I'm not familiar with this chunk of the
code
Quoted 3 lines
Quoted 3 lines
or
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
the need for sweeping all engines on the KGD side).
So I'm not sure if Jesse had concerns about potential multiple calls beingQuoted 7 lines
Quoted 7 lines
made
Quoted 3 lines
Quoted 3 lines
in
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
other parts of the code and maybe this was some way to simplify things. Either way, not sure if it's simpler to drop the reset source param and have
the
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
KGD
Quoted 1 line
remember to unconditionally KFD suspend/resume around the soft reset
call
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
for
Quoted 1 line
Quoted 1 line
Quoted 1 line
each IP version, or keep the reset source param here so that we only have
to
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
remember to do this once.
Could KFD keep track of whether the hang was detected by KFD or KGD?
E.g.,
Quoted 2 lines
Quoted 2 lines
if
Quoted 1 line
Quoted 1 line
KFD detects the hang when suspending queues, it could set a flag and then
KFD
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
could include a call to
amdgpu_amdkfd_suspend()in itspre_resetcallbackthat
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
would depend on the value of that flag. At that point I don't think we'd need
the
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
src
Quoted 4 lines
Quoted 1 line
parameter any more.
Hmmm. Something similar to GPU resets?
The thing about GPU resets is that the KFD could just detect the flag,schedule
Quoted 8 lines
Quoted 8 lines
an
Quoted 2 lines
Quoted 2 lines
event then carry on knowing the driver is going to die and re-init at some point.
Quoted 1 line
SDMA resets are different because the KFD would call back into the common
KGD
Quoted 1 line
Quoted 1 line
call immediately because it wants to fix things right away, and the KGD has to
ensure
Quoted 2 lines
Quoted 2 lines
the KFD is quiesced in any case.
Quoted 1 line
So any flag would have to be locked as well in the KFD pre/post calls.
Which
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
means we'd probably have to conditionally lock it based on a new reset context
that
Quoted 2 lines
Quoted 2 lines
the KGD would have to supply anyways.
Quoted 1 line
This was the main reason why I wanted to simplify things by leveraging a
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
conditional suspend/resume call in the common interface.
Quoted 1 line
Maybe I'm not looking at things clearly atm, but if feels like we're pushing the
complication from one part of the driver into another.
Quoted 2 lines
If we really don't like the idea of adding flags, maybe we can just add a param
"bool
Quoted 2 lines
Quoted 2 lines
suspend_user_queues" to the common interface?Quoted 1 line
Then maybe it's clearer that the KGD, as a reset requester, wants to be
careful
Quoted 2 lines
Quoted 2 lines
of
Quoted 1 line
Quoted 1 line
destroying in-flight user queues while the KFD doesn't care about this for its
own
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
needs (since it's already in post-preemption recovery).
Quoted 1 line
Having the src for a parameter is fine with me. It just seemed logical to keep it in KFD since presumably KFD would have detected this condition after calling
amdgpu_amdkfd_suspend()itself so it would know whether it would need to be called based on its own state so it would know what to do in its pre and post reset hooks already.The case of successful KFD suspend during reset isn't really a concern since
the
Quoted 2 lines
Quoted 2 lines
KFD cannot get into a preemption failure at this point.
Quoted 1 line
It's the corner case when the KFD suspend fails on a KGD initiated reset
because
Quoted 8 lines
Quoted 8 lines
of a user queue hang and KFD has to reset through the KGD call again.
Quoted 1 line
In this case, KFD suspend from the KGD initiated reset is in limbo and this initial
suspend call is holding the lock for all KFD processes.
Quoted 1 line
The KGD is still forced to pass some sort of SDMA reset trigger hint to the KFD
when it calls suspend (or pre-reset) for this corner case.
Quoted 1 line
Otherwise, the KFD will deadlock on the on its own recall of the reset function
when it hits the KFD processes lock again during
kgd2kfd_suspend.Quoted 1 line
So we're stuck either way with the KGD still having to pass something to the
KFD
Quoted 5 lines
Quoted 5 lines
(new reset context, bool, flag hint etc ...) if we want to avoid this deadlock.
Quoted 1 line
The reason why I asked about making use of pre-reset KFD callback is -
Quoted 7 lines
Quoted 5 lines
Ideally, this is a reset of one instance of SDMA instance (even though it's termed as queue reset). What
amdgpu_amdkfd_suspend()is doing seem to affect all processes running on all instances. Basically on a system with 8 or 16 SDMA instances, this is not really making sense if it's going to affect all other processes.F32 HWS devices quiesce the entire device on runlist update anyways so I don't
really see any performance savings there.
Quoted 1 line
RS64 HWS devices per-queue remove/suspend but that means save/restore is
overall more efficient anyways.
Quoted 1 line
The KFD will have to quiesce the device prior to queue reset on RS64 HWS
devices via the MES
suspend_allcall as well because the KFD doesn't know the cause of an MES hang apriori regardless of the queue onremove_queuerequest.Quoted 1 line
"Not really making sense" only "doesn't really make sense" if there's a strict
performance requirement for reset handling.
Quoted 2 lines
What's the benchmark requirement here?
If there isn't one, then having the KGD do newreset_contextbaton pass in pre-reset to a new KFD suspend/resume to filter suspend by SW queues by assigned engine id, then locking out all processes from doing a KFD queue creation on the targeted engine (because we'd have to prevent user space from creating new queues that could enqueue that engine during reset) before we do a reset seems not only like a huge waste of time but potentially creates an explosion of more corner cases to deal with.
Quoted 1 line
So a single bool param here to trigger conditional device quiescence that
temporarily locks out KFD activity during reset for safety, though crude and simple, seems reasonable enough to get the job done.
Quoted 1 line
If there is a target reset handling benchmark that I don't know about (and I'd be
curious to know about it ... and optimization again would probably only apply to RS64 HWS devices ...), then maybe doing an engine id filter is a follow-on scope to consider.
Quoted 1 line
My thinking is -
Quoted 7 lines
Doing a targeted queue or engine reset doesn't affect other processes which are not making use of the queue or engine (a similar thing is done during poison consumption on some SOCs where only the affected processes get unmapped leaving other running processes unaffected). This may have more significance when there are multiple partitions on the device. I guess F32 HWS in co-operative dispatch mode also just affects the particular partition and not the entire device.
By that argument, GPU reset is inefficient as well.
KFD suspend currently will suspend in 2 ways:
1) Remove all running work off the system (evict all processes regardless of logical or physical device)
2) Lock out all future incoming work on the entire socket.
A KFD logical partition suspend (or even aligning the current scope of points 1 & 2 for all reset/suspend cases) sounds like something outside the purpose of this series and a project on its own. Without anyway for the KGD to safeguard healthy KFD user queues, then I would say the KGD shouldn't be doing any engine resets at all.
I'm for pushing this patch as a solution (maybe temporary) since the main goal is to minimize reset damage. Reset speed seems like a follow-on optimization.
I don't know what the likelihood (or the possibility) of a DoS attack is when it comes to bad actors in kernel queues, but the offending app should get eventually evicted somehow. At least that's what happens in ROCm for user queues.
Jon
Quoted 229 lines
Engine/Queue reset is comparatively faster than doing a device-wide reset.
Alex may be able to provide better details.
Thanks,
LijoQuoted 15 lines
Jon
Quoted 14 lines
Is that really required? Or, is it like KFD can identify the processes using the user queues of that particular instance (pre-reset passes instance) and only suspend them?
Thanks,
LijoQuoted 4 lines
Quoted 2 lines
I guess we also stop the kernel queues explicitly in the same function so it makes sense to do the same for KFD.
Yep. We definitely want to minimize reset damage from either caller (KFD or
KGD).
Quoted 1 line
I kind of look at it like the rest of the amdgpu_device_reset/suspend/resume
calls
Quoted 5 lines
Quoted 5 lines
that need to consider the KFD as well.
Quoted 1 line
I think I'm fine with just passing a bool
suspend_user_queueshere to do theconditional KFD suspend/resume instead of coming up with new reset source context(s).
Quoted 1 line
That way we don't have to force callers to use extra long strings in their calls
that
Quoted 82 lines
Quoted 82 lines
have no use anywhere else.
Quoted 81 lines
They can just pass true/false according to their needs.
With that fixed, this patch is:
Acked-by Jonathan Kim <[email protected]>Jon
Quoted 74 lines
Alex
Quoted 71 lines
Jon
Quoted 69 lines
Alex
Quoted 65 lines
Jon
Quoted 62 lines
Thanks,
Lijodrivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-0+ +/* Stop the scheduler's work queue for the GFX and page rings if +they are running.
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +9
-0+* This ensures that no new tasks are submitted to the queues while +* the reset is in progress. +*/ +if (!amdgpu_ring_sched_ready (gfx_ring)) { +drm_sched_wqueue_stop (&gfx_ring->sched); + gfx_sched_stopped = true;; + } + + if (adev->sdma.has_page_queue&& !amdgpu_ring_sched_ready(page_ring)) {
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +5
-2+drm_sched_wqueue_stop (&page_ring->sched); + page_sched_stopped = true; + }/* Invoke all registered pre_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->pre_reset) { - ret = funcs->pre_reset (adev, instance_id); + ret = funcs->pre_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"beforeReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } }@@ -515,21 +546,39 @@ int amdgpu_sdma_reset_engine(structQuoted 1 line
amdgpu_device*adev,
uint32_tinstance_id)Quoted 3 lines
ret = amdgpu_dpm_reset_sdma(adev, 1 << instance_id); if (ret) { dev_err(adev->dev, "Failed to reset SDMA instance %u\n",
instance_id);Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-3-return ret; + goto exit; }/* Invoke all registered post_reset callbacks */ list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) {if (funcs->post_reset) { - ret = funcs->post_reset (adev, instance_id); + ret = funcs->post_reset (adev, instance_id, src);if (ret) {dev_err (adev->dev,"afterReset callback failed for instance %u: %d\n" , instance_id, ret); -return ret; + goto exit; } } }Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +7
-1-return 0 ; +exit: +/* Restart the scheduler's work queue for the GFX and page rings +* if they were stopped by this function. This allows new tasks +* to be submitted to the queues after the reset is complete. +*/ +if (ret) { + if (gfx_sched_stopped &&
amdgpu_ring_sched_ready(gfx_ring)) {Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +3
-0+drm_sched_wqueue_start (&gfx_ring->sched); + } + if (page_sched_stopped &&
amdgpu_ring_sched_ready(page_ring)) {Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Review
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +9
-0+drm_sched_wqueue_start (&page_ring->sched); + } + } + +/* Resume KFD if the reset source is not SDMA_HWS */ +if (src !=AMDGPU_RESET_SRC_SDMA_HWS ) +amdgpu_amdkfd_resume (adev, false); + +return ret; }(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.hQuoted 5 lines
index
f91d75848557..2ef2da772254100644drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0@@ -99,8 +99,8 @@ struct amdgpu_sdma_ras { };Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_sdma_ras { }; · line 101
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1
-2struct sdma_on_reset_funcs { -int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id); -int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id); + int (*pre_reset)(struct amdgpu_device *adev, uint32_t instance_id,int
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
src);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 167
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +2
-0+int (*post_reset)(struct amdgpu_device *adev,uint32_t + instance_id,int src);/* Linked list node to store this structure in a list; */ struct list_head list; };@@ -166,7 +166,7 @@ struct amdgpu_buffer_funcs { }; void amdgpu_sdma_register_on_reset_callbacks(struct
amdgpu_deviceQuoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 168
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0*adev,struct
sdma_on_reset_funcs*funcs);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-1-int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h struct amdgpu_buffer_funcs { }; · line 169
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1
-0+int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t
instance_id, int src);Review
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +0
-0#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)- mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer (adev, ib, s, d, b)(adev)->mman.buffer_funcs-
emit_fill_buffer((ib), (s), (d), (b))(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.cdrivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_sw_init(struct
Quoted 12 lines
index
29a123be90b7..50a086264792100644drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0@@ -30,6 +30,7 @@#include "amdgpu_xcp.h" #include "amdgpu_ucode.h" #include "amdgpu_trace.h" +#include "amdgpu_reset.h" #include "sdma/sdma_4_4_2_offset.h" #include "sdma/sdma_4_4_2_sh_mask.h" @@ -1480,6 +1481,7 @@ static int sdma_v4_4_2_sw_init(struct
amdgpu_ip_block*ip_block)Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-0if (r)return r;INIT_LIST_HEAD (&adev->sdma.reset_callback_list); +return r; }@@ -1608,10 +1610,10 @@ static intsdma_v4_4_2_reset_queue(struct
Quoted 37 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 35 lines
Quoted 34 lines
Quoted 33 lines
amdgpu_ring*ring, unsigned int vmid)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int · line 1613
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-1{struct amdgpu_device *adev = ring->adev;u32 id =GET_INST (SDMA0 , ring->me); -return amdgpu_sdma_reset_engine (adev, id); + return amdgpu_sdma_reset_engine(adev, id,
AMDGPU_RESET_SRC_SDMA_RING);Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1} -static int sdma_v4_4_2_stop_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_stop_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c static int sdma_v4_4_2_stop_queue(struct
Quoted 5 lines
{
u32inst_mask;
structamdgpu_ring*ring =
&adev->sdma.instance[instance_id].ring;drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-0@@ -1628,7 +1630,7 @@ static int sdma_v4_4_2_stop_queue(struct
amdgpu_device*adev,uint32_tinstance_Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +0
-1return 0 ; } -static int sdma_v4_4_2_restore_queue(struct amdgpu_device *adev,
uint32_t
instance_id)drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +2
-0+static int sdma_v4_4_2_restore_queue (struct amdgpu_device *adev, +uint32_t
instance_id, int src)Quoted 3 lines
{ int i; u32 inst_mask;
PATCH v7 4/9 drm/amdgpu: Introduce cached_rptr and is_guilty callback in amdgpu_ring
In reply to [email protected]From: "[email protected]" <[email protected]>
This patch introduces the following changes:
- Add cached_rptr to the amdgpu_ring structure to store the read pointer before a reset.
- Add is_guilty callback to the amdgpu_ring_funcs structure to check if a ring is guilty of causing a timeout.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 3 +++ 2 files changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +2 -0
@@ -342,6 +342,8 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, ring->buf_mask = (ring->ring_size /4 ) -1 ; ring->ptr_mask = ring->funcs->support_64bit_ptrs ?0xffffffffffffffff : ring->buf_mask; +/* Initialize cached_rptr to 0 */ + ring->cached_rptr =0 ;/* Allocate ring buffer */ if (ring->is_mes_queue) {
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +3 -0
@@ -237,6 +237,7 @@ struct amdgpu_ring_funcs {void (*patch_de)(struct amdgpu_ring *ring,unsigned offset);int (*reset)(struct amdgpu_ring *ring,unsigned int vmid);void (*emit_cleaner_shader)(struct amdgpu_ring *ring); +bool (*is_guilty)(struct amdgpu_ring *ring); };struct amdgpu_ring {
@@ -306,6 +307,8 @@ struct amdgpu_ring {bool is_sw_ring;unsigned int entry_index; +/* store the cached rptr to restore after reset */ +uint64_t cached_rptr; };
Signature · 1 line
2.25.1
PATCH v7 5/9 drm/amdgpu: Update amdgpu_job_timedout to check if the ring is guilty
In reply to [email protected]From: "[email protected]" <[email protected]>
This patch updates the amdgpu_job_timedout function to check if the ring is actually guilty of causing the timeout. If not, it skips error handling and fence completion.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +10 -0
@@ -101,6 +101,16 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)/* Effectively the job is aborted as the device is gone */ return DRM_GPU_SCHED_STAT_ENODEV ; } +/* Check if the ring is actually guilty of causing the timeout. +* If not, skip error handling and fence completion. +*/ +if (amdgpu_gpu_recovery && ring->funcs->is_guilty) { +if (!ring->funcs->is_guilty (ring)) { +dev_err (adev->dev,"ring %s timeout, but not guilty\n" , + s_job->sched->name); + goto exit; + } + }/* * Do the coredump immediately after a job timeout to get a very
Signature · 1 line
2.25.1
Deucher, Alexander
maintainerRE: [PATCH V7 5/9] drm/amdgpu: Update amdgpu_job_timedout to check if the ring is guilty
[Public]
Quoted 12 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Thursday, February 13, 2025 12:47 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Deucher, Alexander <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH V7 5/9] drm/amdgpu: Updateamdgpu_job_timedoutto check if the ring is guilty
Quoted 6 lines
From: "[email protected]" <[email protected]>
This patch updates the
amdgpu_job_timedoutfunction to check if the ring is actually guilty of causing the timeout. If not, it skips error handling and fence completion.
Thinking about this more, I'm not sure if this is the right approach. If we detect a timeout on a kernel ring, we still want to do the reset, but we don't want to kill the job if it's not guilty. This approach makes sense if we have all kernel rings as we'll eventually get the timeout on the other ring and the reset will eventually get triggered. But if the hang is on a KFD queue, it won't get noticed until we attempt to preempt the user queues for some other reason which may take a while. How about the following instead. We move the is_guilty check down into the queue reset area. Something like this:
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +10 -3
@@ -130,8 +130,6 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)amdgpu_vm_put_task_info (ti); } -dma_fence_set_error (&s_job->s_fence->finished, -ETIME ); -/* attempt a per ring reset */ if (amdgpu_gpu_recovery && ring->funcs->reset) {
@@ -146,13 +144,22 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)if (amdgpu_ring_sched_ready (ring))drm_sched_stop (&ring->sched, s_job);atomic_inc (&ring->adev->gpu_reset_counter); -amdgpu_fence_driver_force_completion (ring); +if (ring->funcs->is_guilty) { +if (ring->funcs->is_guilty (ring)) { +dma_fence_set_error (&s_job->s_fence->finished, -ETIME ); +amdgpu_fence_driver_force_completion (ring); + } + }else { +amdgpu_fence_driver_force_completion (ring); +dma_fence_set_error (&s_job->s_fence->finished, -ETIME ); + }if (amdgpu_ring_sched_ready (ring))drm_sched_start (&ring->sched,0 ); goto exit; }dev_err (adev->dev,"Ring %s reset failure\n" , ring->sched.name); } +dma_fence_set_error (&s_job->s_fence->finished, -ETIME );if (amdgpu_device_should_recover_gpu (ring->adev)) {struct amdgpu_reset_context reset_context;
Quoted 31 lines
Suggested-by Alex Deucher <[email protected]>Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +10
-0@@ -101,6 +101,16 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)/* Effectively the job is aborted as the device is gone */ return DRM_GPU_SCHED_STAT_ENODEV; } +/* Check if the ring is actually guilty of causing the timeout. +* If not, skip error handling and fence completion. +*/ +if (amdgpu_gpu_recovery && ring->funcs->is_guilty) { +if (!ring->funcs->is_guilty (ring)) { +dev_err (adev->dev,"ring %s timeout, but not guilty\n" , + s_job->sched->name); + goto exit; + } + }/* * Do the coredump immediately after a job timeout to get a very
--
2.25.1
Deucher, Alexander
maintainerRE: [PATCH V7 5/9] drm/amdgpu: Update amdgpu_job_timedout to check if the ring is guilty
[Public]
Quoted 80 lines
-----Original Message-----
From: Deucher, Alexander
Sent: Wednesday, February 19, 2025 6:27 PM
To: [email protected]; [email protected]
Cc: Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: RE: [PATCH V7 5/9] drm/amdgpu: Updateamdgpu_job_timedoutto check if the ring is guiltyQuoted 8 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Thursday, February 13, 2025 12:47 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Deucher, AlexanderQuoted 10 lines
Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH V7 5/9] drm/amdgpu: Updateamdgpu_job_timedoutto check if the ring is guiltyFrom: "[email protected]" <[email protected]>
This patch updates the
amdgpu_job_timedoutfunction to check if the ring is actually guilty of causing the timeout. If not, it skips error handling and fence completion.Thinking about this more, I'm not sure if this is the right approach. If we detect a timeout on a kernel ring, we still want to do the reset, but we don't want to kill the job if it's not guilty. This approach makes sense if we have all kernel rings as we'll eventually get the timeout on the other ring and the reset will eventually get triggered. But if the hang is on a KFD queue, it won't get noticed until we attempt to preempt the user queues for some other reason which may take a while. How about the following instead. We move the
is_guiltycheck down into the queue reset area. Something like this:drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-2@@ -130,8 +130,6 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)amdgpu_vm_put_task_info (ti); } -dma_fence_set_error (&s_job->s_fence->finished, -ETIME ); -/* attempt a per ring reset */ if (amdgpu_gpu_recovery &&ring->funcs->reset) {drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +10
-1@@ -146,13 +144,22 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) if (amdgpu_ring_sched_ready(ring)) drm_sched_stop(&ring->sched, s_job);atomic_inc (&ring->adev->gpu_reset_counter); -amdgpu_fence_driver_force_completion (ring); +if (ring->funcs->is_guilty) { +if (ring->funcs->is_guilty (ring)) { +dma_fence_set_error (&s_job->s_fence- >finished, -ETIME); +amdgpu_fence_driver_force_completion (ring); + } + }else { +amdgpu_fence_driver_force_completion (ring); +dma_fence_set_error (&s_job->s_fence->finished, -ETIME ); + }if (amdgpu_ring_sched_ready (ring))drm_sched_start (&ring->sched,0 ); goto exit; }dev_err (adev->dev,"Ring %s reset failure\n" , ring->sched.name); } +dma_fence_set_error (&s_job->s_fence->finished, -ETIME );
Quoted 3 lines
if (amdgpu_device_should_recover_gpu(ring->adev)) {
struct amdgpu_reset_context reset_context;Actually something like the attached patch. Need to call is_guilty before reset.
Alex
Quoted 29 lines
Quoted 29 lines
Suggested-by Alex Deucher <[email protected]>Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +10
-0@@ -101,6 +101,16 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)/* Effectively the job is aborted as the device is gone */ return DRM_GPU_SCHED_STAT_ENODEV; } +/* Check if the ring is actually guilty of causing the timeout. +* If not, skip error handling and fence completion. +*/ +if (amdgpu_gpu_recovery && ring->funcs->is_guilty) { +if (!ring->funcs->is_guilty (ring)) { +dev_err (adev->dev,"ring %s timeout, but not guilty\n" , + s_job->sched->name); + goto exit; + } + }
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0/* * Do the coredump immediately after a job timeout to get a very
--
2.25.1
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +17 -3
@@ -130,29 +130,43 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)amdgpu_vm_put_task_info (ti); } -dma_fence_set_error (&s_job->s_fence->finished, -ETIME ); -/* attempt a per ring reset */ if (amdgpu_gpu_recovery && ring->funcs->reset) { +bool is_guilty; +dev_err (adev->dev,"Starting %s ring reset\n" , s_job->sched->name);/* stop the scheduler, but don't mess with the * bad job yet because if ring reset fails * we'll fall back to full GPU reset. */ drm_sched_wqueue_stop (&ring->sched); + +/* for engine resets, we need to reset the engine, +* but individual queues may be unaffected. +* check here to make sure the accounting is correct. +*/ +if (ring->funcs->is_guilty) + is_guilty = ring->funcs->is_guilty (ring); +else + is_guilty = true; + r =amdgpu_ring_reset (ring, job->vmid);if (!r) {if (amdgpu_ring_sched_ready (ring))drm_sched_stop (&ring->sched, s_job);atomic_inc (&ring->adev->gpu_reset_counter); -amdgpu_fence_driver_force_completion (ring); +if (is_guilty) { +amdgpu_fence_driver_force_completion (ring); +dma_fence_set_error (&s_job->s_fence->finished, -ETIME ); + }if (amdgpu_ring_sched_ready (ring))drm_sched_start (&ring->sched,0 ); goto exit; }dev_err (adev->dev,"Ring %s reset failure\n" , ring->sched.name); } +dma_fence_set_error (&s_job->s_fence->finished, -ETIME );if (amdgpu_device_should_recover_gpu (ring->adev)) {struct amdgpu_reset_context reset_context;
RE: [PATCH V7 5/9] drm/amdgpu: Update amdgpu_job_timedout to check if the ring is guilty
[Public]
-----Original Message-----
From: Deucher, Alexander <[email protected]>
Sent: Thursday, February 20, 2025 10:22 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: RE: [PATCH V7 5/9] drm/amdgpu: Update amdgpu_job_timedout to check if the ring is guilty
[Public]
Quoted 75 lines
-----Original Message-----
From: Deucher, Alexander
Sent: Wednesday, February 19, 2025 6:27 PM
To: [email protected]; [email protected]
Cc: Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: RE: [PATCH V7 5/9] drm/amdgpu: Updateamdgpu_job_timedoutto check if the ring is guiltyQuoted 8 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Thursday, February 13, 2025 12:47 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Deucher, AlexanderQuoted 10 lines
Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH V7 5/9] drm/amdgpu: Updateamdgpu_job_timedoutto check if the ring is guiltyFrom: "[email protected]" <[email protected]>
This patch updates the
amdgpu_job_timedoutfunction to check if the ring is actually guilty of causing the timeout. If not, it skips error handling and fence completion.Thinking about this more, I'm not sure if this is the right approach.
If we detect a timeout on a kernel ring, we still want to do the
reset, but we don't want to kill the job if it's not guilty. This
approach makes sense if we have all kernel rings as we'll eventually
get the timeout on the other ring and the reset will eventually get
triggered. But if the hang is on a KFD queue, it won't get noticed
until we attempt to preempt the user queues for some other reason
which may take a while. How about the following instead. We move theis_guiltycheck down into the queue reset area. Something like this:drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-2@@ -130,8 +130,6 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)amdgpu_vm_put_task_info (ti); } -dma_fence_set_error (&s_job->s_fence->finished, -ETIME ); -/* attempt a per ring reset */ if (amdgpu_gpu_recovery &&ring->funcs->reset) {drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +11
-1@@ -146,13 +144,22 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) if (amdgpu_ring_sched_ready(ring)) drm_sched_stop(&ring->sched, s_job);atomic_inc (&ring->adev->gpu_reset_counter); -amdgpu_fence_driver_force_completion (ring); +if (ring->funcs->is_guilty) { +if (ring->funcs->is_guilty (ring)) { + +dma_fence_set_error (&s_job->s_fence- >finished, -ETIME); +amdgpu_fence_driver_force_completion (ring); + } + }else { +amdgpu_fence_driver_force_completion (ring); + +dma_fence_set_error (&s_job->s_fence->finished, -ETIME ); + }
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static enum drm_gpu_sched_stat · line 172
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1
-0if (amdgpu_ring_sched_ready (ring))drm_sched_start (&ring->sched,0 ); goto exit; }dev_err (adev->dev,"Ring %s reset failure\n" , ring->sched.name); } +dma_fence_set_error (&s_job->s_fence->finished, -ETIME );if (amdgpu_device_should_recover_gpu (ring->adev)) {struct amdgpu_reset_context reset_context;
Actually something like the attached patch. Need to call is_guilty before reset.
Thanks Alex, will update before pushing to drm-next
Jesse
Alex
Quoted 33 lines
Quoted 33 lines
Suggested-by Alex Deucher <[email protected]>Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +10
-0@@ -101,6 +101,16 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)/* Effectively the job is aborted as the device is gone */ return DRM_GPU_SCHED_STAT_ENODEV; } +/* Check if the ring is actually guilty of causing the timeout. +* If not, skip error handling and fence completion. +*/ +if (amdgpu_gpu_recovery && ring->funcs->is_guilty) { +if (!ring->funcs->is_guilty (ring)) { +dev_err (adev->dev,"ring %s timeout, but not guilty\n" , + s_job->sched->name); + goto exit; + } + }/* * Do the coredump immediately after a job timeout to get a very
--
2.25.1
PATCH v7 6/9 drm/amdgpu/sdma: Introduce is_guilty callbacks for sdma GFX and PAGE rings
In reply to [email protected]From: "[email protected]" <[email protected]>
This patch introduces the is_guilty callbacks for the GFX and PAGE rings. These callbacks check if a ring is guilty of causing a timeout or error.
--- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +30 -0
@@ -1606,6 +1606,34 @@ static int sdma_v4_4_2_soft_reset(struct amdgpu_ip_block *ip_block)return 0 ; } +static bool sdma_v4_4_2_is_queue_selected (struct amdgpu_device *adev,uint32_t instance_id,bool is_page_queue) +{ +uint32_t reg_offset = is_page_queue ? regSDMA_PAGE_CONTEXT_STATUS : regSDMA_GFX_CONTEXT_STATUS; +uint32_t context_status =RREG32 (sdma_v4_4_2_get_reg_offset (adev, instance_id, reg_offset)); + +/* Check if the SELECTED bit is set */ +return (context_status &SDMA_GFX_CONTEXT_STATUS__SELECTED_MASK ) !=0 ; +} + +static bool sdma_v4_4_2_ring_is_guilty (struct amdgpu_ring *ring) +{ +struct amdgpu_device *adev = ring->adev; +uint32_t instance_id = ring->me; + +return sdma_v4_4_2_is_queue_selected (adev, instance_id, false); +} + +static bool sdma_v4_4_2_page_ring_is_guilty (struct amdgpu_ring *ring) +{ +struct amdgpu_device *adev = ring->adev; +uint32_t instance_id = ring->me; + +if (!adev->sdma.has_page_queue) +return false; + +return sdma_v4_4_2_is_queue_selected (adev, instance_id, true); +} +static int sdma_v4_4_2_reset_queue (struct amdgpu_ring *ring,unsigned int vmid) {struct amdgpu_device *adev = ring->adev;
@@ -2055,6 +2083,7 @@ static const struct amdgpu_ring_funcs sdma_v4_4_2_ring_funcs = { .emit_reg_wait = sdma_v4_4_2_ring_emit_reg_wait, .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper, .reset = sdma_v4_4_2_reset_queue, + .is_guilty = sdma_v4_4_2_ring_is_guilty, };static const struct amdgpu_ring_funcs sdma_v4_4_2_page_ring_funcs = {
@@ -2086,6 +2115,7 @@ static const struct amdgpu_ring_funcs sdma_v4_4_2_page_ring_funcs = { .emit_wreg = sdma_v4_4_2_ring_emit_wreg, .emit_reg_wait = sdma_v4_4_2_ring_emit_reg_wait, .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper, + .is_guilty = sdma_v4_4_2_page_ring_is_guilty, };static void sdma_v4_4_2_set_ring_funcs (struct amdgpu_device *adev)
Signature · 1 line
2.25.1
PATCH v7 7/9 drm/amdgpu: Improve SDMA reset logic with guilty queue tracking
In reply to [email protected]From: "[email protected]" <[email protected]>
This patch includes the remaining improvements to the SDMA reset logic:
- Added gfx_guilty and page_guilty flags to track guilty queues.
- Updated the reset and resume functions to handle the guilty state.
- Cached the rptr before reset.
v2:
1.replace the caller with a guilty bool.
If the queue is the guilty one, set the rptr and wptr to the saved wptr value, else, set the rptr and wptr to the saved rptr value. (Alex)
2. cache the rptr before the reset. (Alex)
v3: Keeping intermediate variables like u64 rwptr simplifies resotre rptr/wptr.(Lijo)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 6 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 3 ++ drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 66 +++++++++++++++++++----- 3 files changed, 61 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +5 -1
@@ -475,6 +475,10 @@ void amdgpu_sdma_register_on_reset_callbacks(struct amdgpu_device *adev, structif (!funcs)return ; +/* Ensure the reset_callback_list is initialized */ +if (!adev->sdma.reset_callback_list.next) { +INIT_LIST_HEAD (&adev->sdma.reset_callback_list); + }/* Initialize the list node in the callback structure */ INIT_LIST_HEAD (&funcs->list);
@@ -521,7 +525,7 @@ int amdgpu_sdma_reset_engine(struct amdgpu_device *adev, uint32_t instance_id, i*/ if (!amdgpu_ring_sched_ready (gfx_ring)) {drm_sched_wqueue_stop (&gfx_ring->sched); - gfx_sched_stopped = true;; + gfx_sched_stopped = true; }if (adev->sdma.has_page_queue && !amdgpu_ring_sched_ready (page_ring)) {
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +3 -0
@@ -126,6 +126,9 @@ struct amdgpu_sdma {uint32_t *ip_dump;uint32_t supported_reset;struct list_head reset_callback_list; +/* track guilty state of GFX and PAGE queues */ +bool gfx_guilty; +bool page_guilty; };/*
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +53 -13
138 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v7 8/9 drm/amdgpu: Add reset function pointer for SDMA v4.4.2 page ring
In reply to [email protected]From: "[email protected]" <[email protected]>
This patch adds a reset function pointer to the SDMA v4.4.2 page ring functionality. The new function pointer reset is set to sdma_v4_4_2_reset_queue, which is responsible for resetting the SDMA queue.
Changes:
- Add reset function pointer to sdma_v4_4_2_page_ring_funcs.
--- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -0
@@ -2155,6 +2155,7 @@ static const struct amdgpu_ring_funcs sdma_v4_4_2_page_ring_funcs = { .emit_wreg = sdma_v4_4_2_ring_emit_wreg, .emit_reg_wait = sdma_v4_4_2_ring_emit_reg_wait, .emit_reg_write_reg_wait = amdgpu_ring_emit_reg_write_reg_wait_helper, + .reset = sdma_v4_4_2_reset_queue, .is_guilty = sdma_v4_4_2_page_ring_is_guilty, };
Signature · 1 line
2.25.1
PATCH 1/1 drm/amdgpu: Update SDMA scheduler mask handling to include page queue
In reply to [email protected]From: "[email protected]" <[email protected]>
This patch updates the SDMA scheduler mask handling to include the page queue if it exists. The scheduler mask is calculated based on the number of SDMA instances and the presence of the page queue. The mask is updated to reflect the state of both the SDMA gfx ring and the page queue.
Changes:
- Add handling for the SDMA page queue in amdgpu_debugfs_sdma_sched_mask_set.
- Update scheduler mask calculations to include the page queue.
- Modify amdgpu_debugfs_sdma_sched_mask_get to return the correct mask value.
This change is necessary to verify multiple queues (SDMA gfx queue + page queue) and ensure proper scheduling and state management for SDMA instances.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 55 +++++++++++++++++++++--- 1 file changed, 48 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +48 -7
@@ -356,23 +356,44 @@ int amdgpu_sdma_ras_sw_init(struct amdgpu_device *adev)static int amdgpu_debugfs_sdma_sched_mask_set (void *data,u64 val) {struct amdgpu_device *adev = (struct amdgpu_device *)data; -u32 i; +u32 i, num_ring;u64 mask =0 ; -struct amdgpu_ring *ring; +struct amdgpu_ring *ring, *page =NULL ;if (!adev)return -ENODEV ; - mask =BIT_ULL (adev->sdma.num_instances) -1 ; +/* Determine the number of rings per SDMA instance +* (1 for sdma gfx ring, 2 if page queue exists) +*/ +if (adev->sdma.has_page_queue) + num_ring =2 ; +else + num_ring =1 ; + +/* Calculate the maximum possible mask value +* based on the number of SDMA instances and rings +*/ + mask =BIT_ULL (adev->sdma.num_instances * num_ring) -1 ; +if ((val & mask) ==0 )return -EINVAL ;for (i =0 ; i < adev->sdma.num_instances; ++i) { ring = &adev->sdma.instance[i].ring; -if (val &BIT_ULL (i)) +if (adev->sdma.has_page_queue) + page = &adev->sdma.instance[i].page; +if (val &BIT_ULL (i * num_ring)) ring->sched.ready = true;else ring->sched.ready = false; + +if (page) { +if (val &BIT_ULL (i * num_ring +1 )) + page->sched.ready = true; +else + page->sched.ready = false; + } }/* publish sched.ready flag update effective immediately across smp */ smp_rmb ();
@@ -382,16 +403,36 @@ static int amdgpu_debugfs_sdma_sched_mask_set(void *data, u64 val)static int amdgpu_debugfs_sdma_sched_mask_get (void *data,u64 *val) {struct amdgpu_device *adev = (struct amdgpu_device *)data; -u32 i; +u32 i, num_ring;u64 mask =0 ; -struct amdgpu_ring *ring; +struct amdgpu_ring *ring, *page =NULL ;if (!adev)return -ENODEV ; + +/* Determine the number of rings per SDMA instance +* (1 for sdma gfx ring, 2 if page queue exists) +*/ +if (adev->sdma.has_page_queue) + num_ring =2 ; +else + num_ring =1 ; +for (i =0 ; i < adev->sdma.num_instances; ++i) { ring = &adev->sdma.instance[i].ring; +if (adev->sdma.has_page_queue) + page = &adev->sdma.instance[i].page; +if (ring->sched.ready) - mask |=1 << i; + mask |=1 << (i * num_ring); +else + mask &= ~(1 << (i * num_ring)); + +if (page && page->sched.ready) { + mask |=1 << (i * num_ring +1 ); + }else { + mask &= ~(1 << (i * num_ring +1 )); + } } *val = mask;
Signature · 1 line
2.25.1
[AMD Official Use Only - AMD Internal Distribution Only]
Ping on this series?
Jesse
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Thursday, February 13, 2025 1:47 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Deucher, Alexander <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH v7 1/9] drm/amdgpu/kfd: Add shared SDMA reset functionality with callback support
From: "[email protected]" <[email protected]>
This patch introduces shared SDMA reset functionality between AMDGPU and KFD. The implementation includes the following key changes:
1. Added amdgpu_sdma_reset_queue:
- Resets a specific SDMA queue by instance ID.
- Invokes registered pre-reset and post-reset callbacks to allow KFD and AMDGPU to save/restore their state during the reset process.
2. Added amdgpu_set_on_reset_callbacks:
- Allows KFD and AMDGPU to register callback functions for pre-reset and post-reset operations.
- Callbacks are stored in a global linked list and invoked in the correct order during SDMA reset.
This patch ensures that both AMDGPU and KFD can handle SDMA reset events gracefully, with proper state saving and restoration. It also provides a flexible callback mechanism for future extensions.
v2: fix CamelCase and put the SDMA helper into amdgpu_sdma.c (Alex)
v3: rename the amdgpu_register_on_reset_callbacks function to
amdgpu_sdma_register_on_reset_callbacks
move global reset_callback_list to struct amdgpu_sdma (Alex)
v4: Update the reset callback function description and
rename the reset function to amdgpu_sdma_reset_engine (Alex)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 73 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 11 ++++ drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 2 +- 3 files changed, 85 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +73 -0
@@ -460,3 +460,76 @@ void amdgpu_sdma_sysfs_reset_mask_fini(struct amdgpu_device *adev)device_remove_file (adev->dev, &dev_attr_sdma_reset_mask); } } + +/** +* amdgpu_sdma_register_on_reset_callbacks - Register SDMA reset +callbacks +* @funcs: Pointer to the callback structure containing pre_reset and +post_reset functions +* +* This function allows KFD and AMDGPU to register their own callbacks +for handling +* pre-reset and post-reset operations for engine reset. These are +needed because engine +* reset will stop all queues on that engine. +*/ +void amdgpu_sdma_register_on_reset_callbacks (struct amdgpu_device +*adev,struct sdma_on_reset_funcs *funcs) { +if (!funcs) +return ; + +/* Initialize the list node in the callback structure */ +INIT_LIST_HEAD (&funcs->list); + +/* Add the callback structure to the global list */ +list_add_tail (&funcs->list, &adev->sdma.reset_callback_list); } + +/** +* amdgpu_sdma_reset_engine - Reset a specific SDMA engine +* @adev: Pointer to the AMDGPU device +* @instance_id: ID of the SDMA engine instance to reset +* +* This function performs the following steps: +* 1. Calls all registered pre_reset callbacks to allow KFD and AMDGPU to save their state. +* 2. Resets the specified SDMA engine instance. +* 3. Calls all registered post_reset callbacks to allow KFD and AMDGPU to restore their state. +* +* Returns: 0 on success, or a negative error code on failure. +*/ +int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t +instance_id) { +struct sdma_on_reset_funcs *funcs; +int ret; + +/* Invoke all registered pre_reset callbacks */ +list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) { +if (funcs->pre_reset) { + ret = funcs->pre_reset (adev, instance_id); +if (ret) { +dev_err (adev->dev, +"beforeReset callback failed for instance %u: %d\n" , + instance_id, ret); +return ret; + } + } + } + +/* Perform the SDMA reset for the specified instance */ + ret =amdgpu_dpm_reset_sdma (adev,1 << instance_id); +if (ret) { +dev_err (adev->dev,"Failed to reset SDMA instance %u\n" , instance_id); +return ret; + } + +/* Invoke all registered post_reset callbacks */ +list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) { +if (funcs->post_reset) { + ret = funcs->post_reset (adev, instance_id); +if (ret) { +dev_err (adev->dev, +"afterReset callback failed for instance %u: %d\n" , + instance_id, ret); +return ret; + } + } + }
+
+ return 0;
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +13 -0
@@ -98,6 +98,13 @@ struct amdgpu_sdma_ras {struct amdgpu_ras_block_object ras_block; }; +struct sdma_on_reset_funcs { +int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id); +int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id); +/* Linked list node to store this structure in a list; */ +struct list_head list; +}; +struct amdgpu_sdma {struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES ];struct amdgpu_irq_src trap_irq;
@@ -118,6 +125,7 @@ struct amdgpu_sdma {struct amdgpu_sdma_ras *ras;uint32_t *ip_dump;uint32_t supported_reset; +struct list_head reset_callback_list; };/*
@@ -157,6 +165,9 @@ struct amdgpu_buffer_funcs { uint32_t byte_count); }; +void amdgpu_sdma_register_on_reset_callbacks (struct amdgpu_device +*adev,struct sdma_on_reset_funcs *funcs);int +amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t +instance_id); +#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)->mman.buffer_funcs->emit_copy_buffer((ib), (s), (d), (b), (t)) #define amdgpu_emit_fill_buffer(adev, ib, s, d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -1
@@ -1477,7 +1477,7 @@ static int sdma_v4_4_2_sw_init(struct amdgpu_ip_block *ip_block) r =amdgpu_sdma_sysfs_reset_mask_init (adev);if (r)return r; - +INIT_LIST_HEAD (&adev->sdma.reset_callback_list);return r; }
--
2.25.1
[Public]
Patches 1-2 and 4-9 are:
For patch 3, I don't have a strong preference.
Alex
Quoted 199 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Thursday, February 13, 2025 12:47 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>; Zhu, Jiadong <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Deucher, Alexander <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH v7 1/9] drm/amdgpu/kfd: Add shared SDMA reset functionality with callback supportFrom: "[email protected]" <[email protected]>
This patch introduces shared SDMA reset functionality between AMDGPU and KFD.
The implementation includes the following key changes:1. Added
amdgpu_sdma_reset_queue:
- Resets a specific SDMA queue by instance ID.
- Invokes registered pre-reset and post-reset callbacks to allow KFD and
AMDGPU
to save/restore their state during the reset process.2. Added
amdgpu_set_on_reset_callbacks:
- Allows KFD and AMDGPU to register callback functions for pre-reset and post-reset operations.
- Callbacks are stored in a global linked list and invoked in the correct order during SDMA reset.This patch ensures that both AMDGPU and KFD can handle SDMA reset events gracefully, with proper state saving and restoration. It also provides a flexible callback mechanism for future extensions.
v2: fix CamelCase and put the SDMA helper into
amdgpu_sdma.c(Alex)v3: rename the
amdgpu_register_on_reset_callbacksfunction to
amdgpu_sdma_register_on_reset_callbacks
move globalreset_callback_listto structamdgpu_sdma(Alex)v4: Update the reset callback function description and
rename the reset function toamdgpu_sdma_reset_engine(Alex)Suggested-by Alex Deucher <[email protected]>Suggested-by Jiadong Zhu <[email protected]>Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 73 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h | 11 ++++ drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 2 +- 3 files changed, 85 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +31
-0@@ -460,3 +460,76 @@ void amdgpu_sdma_sysfs_reset_mask_fini(struct amdgpu_device *adev) device_remove_file(adev->dev, &dev_attr_sdma_reset_mask); } } + +/** +* amdgpu_sdma_register_on_reset_callbacks - Register SDMA reset +callbacks +* @funcs: Pointer to the callback structure containing pre_reset and +post_reset functions +* +* This function allows KFD and AMDGPU to register their own callbacks +for handling +* pre-reset and post-reset operations for engine reset. These are +needed because engine +* reset will stop all queues on that engine. +*/ +void amdgpu_sdma_register_on_reset_callbacks (struct amdgpu_device +*adev,struct sdma_on_reset_funcs *funcs) { +if (!funcs) +return ; + +/* Initialize the list node in the callback structure */ +INIT_LIST_HEAD (&funcs->list); + +/* Add the callback structure to the global list */ +list_add_tail (&funcs->list, &adev->sdma.reset_callback_list); } + +/** +* amdgpu_sdma_reset_engine - Reset a specific SDMA engine +* @adev: Pointer to the AMDGPU device +* @instance_id: ID of the SDMA engine instance to reset +* +* This function performs the following steps: +* 1. Calls all registered pre_reset callbacks to allow KFD and AMDGPU to save their state.
+ * 2. Resets the specified SDMA engine instance.
+ * 3. Calls all registeredpost_resetcallbacks to allow KFD and AMDGPU to restore their state.
+ *
+ * Returns: 0 on success, or a negative error code on failure.
+ */drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +22
-0+int amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t +instance_id) { +struct sdma_on_reset_funcs *funcs; +int ret; + +/* Invoke all registered pre_reset callbacks */ +list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) { +if (funcs->pre_reset) { + ret = funcs->pre_reset (adev, instance_id); +if (ret) { +dev_err (adev->dev, +"beforeReset callback failed for instance %u: %d\n" , + instance_id, ret); +return ret; + } + } + } + +/* Perform the SDMA reset for the specified instance */ + ret =amdgpu_dpm_reset_sdma (adev,1 << instance_id); +if (ret) { + dev_err(adev->dev, "Failed to reset SDMA instance %u\n",
instance_id);drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +18
-0+return ret; + } + +/* Invoke all registered post_reset callbacks */ +list_for_each_entry (funcs, &adev->sdma.reset_callback_list, list) { +if (funcs->post_reset) { + ret = funcs->post_reset (adev, instance_id); +if (ret) { +dev_err (adev->dev, +"afterReset callback failed for instance %u: %d\n" , + instance_id, ret); +return ret; + } + } + } + +return 0 ; +}drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +13
-0@@ -98,6 +98,13 @@ struct amdgpu_sdma_ras {struct amdgpu_ras_block_object ras_block; }; +struct sdma_on_reset_funcs { +int (*pre_reset)(struct amdgpu_device *adev,uint32_t instance_id); +int (*post_reset)(struct amdgpu_device *adev,uint32_t instance_id); +/* Linked list node to store this structure in a list; */ +struct list_head list; +}; +struct amdgpu_sdma {struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES ];struct amdgpu_irq_src trap_irq;@@ -118,6 +125,7 @@ struct amdgpu_sdma {struct amdgpu_sdma_ras *ras;uint32_t *ip_dump;uint32_t supported_reset; +struct list_head reset_callback_list; };/* @@ -157,6 +165,9 @@ struct amdgpu_buffer_funcs { uint32_t byte_count); }; +void amdgpu_sdma_register_on_reset_callbacks (struct amdgpu_device +*adev,struct sdma_on_reset_funcs *funcs);int +amdgpu_sdma_reset_engine (struct amdgpu_device *adev,uint32_t +instance_id); +#define amdgpu_emit_copy_buffer (adev, ib, s, d, b, t) (adev)->mman.buffer_funcs-Quoted 1 line
emit_copy_buffer((ib), (s), (d), (b), (t))#define amdgpu_emit_fill_buffer(adev, ib, s,d, b) (adev)->mman.buffer_funcs->emit_fill_buffer((ib), (s), (d), (b))
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1
-2@@ -1477,7 +1477,7 @@ static int sdma_v4_4_2_sw_init(struct amdgpu_ip_block *ip_block) r =amdgpu_sdma_sysfs_reset_mask_init (adev);if (r)return r; - +INIT_LIST_HEAD (&adev->sdma.reset_callback_list);return r; } --2.25.1