drm/amdgpu: Handle xgmi device removal and add reset wq.
Subsystems (2)
PATCH 1/2 drm/amdgpu: Handle xgmi device removal and add reset wq.
XGMI hive has some resources allocted on device init which needs to be deallocated when the device is unregistered.
Add per hive wq to allow all the nodes in hive to run resets concurently - this should speed up the total reset time to avoid breaching the PSP FW timeout.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 24 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h | 3 +++ 2 files changed, 27 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +24 -0
@@ -61,6 +61,8 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)INIT_LIST_HEAD (&tmp->device_list);mutex_init (&tmp->hive_lock); + tmp->reset_queue =alloc_workqueue ("xgmi-hive" ,WQ_UNBOUND |WQ_HIGHPRI ,0 ); +return tmp; }
@@ -135,3 +137,25 @@ int amdgpu_xgmi_add_device(struct amdgpu_device *adev)mutex_unlock (&xgmi_mutex);return ret; } + +void amdgpu_xgmi_remove_device (struct amdgpu_device *adev) +{ +struct amdgpu_hive_info *hive; + +if ((adev->asic_type <CHIP_VEGA20 ) || (adev->flags &AMD_IS_APU )) +return ; + +mutex_lock (&xgmi_mutex); + + hive =amdgpu_get_xgmi_hive (adev); +if (!hive) + goto exit; + +if (!(hive->number_devices--)) { +mutex_destroy (&hive->hive_lock); +destroy_workqueue (hive->reset_queue); + } + +exit: +mutex_unlock (&xgmi_mutex); +}
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +3 -0
@@ -30,10 +30,13 @@ struct amdgpu_hive_info {struct psp_xgmi_topology_info topology_info;int number_devices;struct mutex hive_lock; +/* hive members reset wq */ + struct workqueue_struct *reset_queue; };struct amdgpu_hive_info *amdgpu_get_xgmi_hive (struct amdgpu_device *adev);int amdgpu_xgmi_update_topology (struct amdgpu_hive_info *hive,struct amdgpu_device *adev);int amdgpu_xgmi_add_device (struct amdgpu_device *adev); +void amdgpu_xgmi_remove_device (struct amdgpu_device *adev);#endif
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1543523816-26659-1-git-send-email-andrey.grodzovsky-5C7GfCeVMHo@public.gmane.org
PATCH 2/2 drm/amdgpu: Implement concurrent asic reset for XGMI.
Use per hive wq to concurrently send reset commands to all nodes in the hive.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 33 +++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
@@ -910,7 +910,9 @@ struct amdgpu_device {bool in_gpu_reset;struct mutex lock_reset;struct amdgpu_doorbell_index doorbell_index; +int asic_reset_res; +struct work_struct xgmi_reset_work; };static inline struct amdgpu_device *amdgpu_ttm_adev (struct ttm_bo_device *bdev)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +30 -3
@@ -1861,6 +1861,9 @@ static int amdgpu_device_ip_fini(struct amdgpu_device *adev) {int i, r; +if (adev->gmc.xgmi.num_physical_nodes >1 ) +amdgpu_xgmi_remove_device (adev); +amdgpu_amdkfd_device_fini (adev);amdgpu_device_set_pg_state (adev,AMD_PG_STATE_UNGATE );
@@ -2350,6 +2353,19 @@ bool amdgpu_device_has_dc_support(struct amdgpu_device *adev)return amdgpu_device_asic_has_dc_support (adev->asic_type); } + +static void amdgpu_device_xgmi_reset_func (struct work_struct *__work) +{ +struct amdgpu_device *adev = + container_of(__work, struct amdgpu_device, xgmi_reset_work); + + adev->asic_reset_res =amdgpu_asic_reset (adev); +if (adev->asic_reset_res) +DRM_WARN ("ASIC reset failed with err r, %d for drm dev, %s" , + adev->asic_reset_res, adev->ddev->unique); +} + +/** * amdgpu_device_init - initialize the driver *
@@ -2448,6 +2464,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,INIT_DELAYED_WORK (&adev->gfx.gfx_off_delay_work, amdgpu_device_delay_enable_gfx_off); +INIT_WORK (&adev->xgmi_reset_work, amdgpu_device_xgmi_reset_func); + adev->gfx.gfx_off_req_count =1 ; adev->pm.ac_power =power_supply_is_system_supplied () >0 ? true : false;
@@ -3325,11 +3343,22 @@ static int amdgpu_do_asic_reset(struct amdgpu_hive_info *hive,*/ if (need_full_reset) {list_for_each_entry (tmp_adev, device_list_handle, gmc.xgmi.head) { - r =amdgpu_asic_reset (tmp_adev); + +/* For XGMI run all resets in parallel to speed up the process */ +if (hive && tmp_adev->gmc.xgmi.num_physical_nodes >1 ) +queue_work (hive->reset_queue, &tmp_adev->xgmi_reset_work); +else + r =amdgpu_asic_reset (tmp_adev);if (r)DRM_WARN ("ASIC reset failed with err r, %d for drm dev, %s" , r, tmp_adev->ddev->unique); } + +/* For XGMI wait for all PSP resets to complete before proceed */ +if (hive && tmp_adev->gmc.xgmi.num_physical_nodes >1 ) { +flush_workqueue (hive->reset_queue); + r = tmp_adev->asic_reset_res; + } }
@@ -3515,8 +3544,6 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,if (tmp_adev == adev)continue ; -dev_info (tmp_adev->dev,"GPU reset begin for drm dev %s!\n" , adev->ddev->unique); -amdgpu_device_lock_adev (tmp_adev); r = amdgpu_device_pre_asic_reset(tmp_adev, NULL,
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 29.11.18 um 21:36 schrieb Andrey Grodzovsky:
Quoted 6 lines
XGMI hive has some resources allocted on device init which needs to be deallocated when the device is unregistered.
Add per hive wq to allow all the nodes in hive to run resets concurently - this should speed up the total reset time to avoid breaching the PSP FW timeout.
Do you really want a workqueue? That sounds like the exact opposite of what you describe here.
E.g. a workqueue is there to serialize all work items scheduled to it.
What you most likely rather want is a work item per device which are scheduled, run in parallel and are joined back together before dropping the per hive lock.
Christian.
Quoted 54 lines
Signed-off-by Andrey Grodzovsky <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 24 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h | 3 +++ 2 files changed, 27 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +24
-0@@ -61,6 +61,8 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)INIT_LIST_HEAD (&tmp->device_list);mutex_init (&tmp->hive_lock); + tmp->reset_queue =alloc_workqueue ("xgmi-hive" ,WQ_UNBOUND |WQ_HIGHPRI ,0 ); +return tmp; }@@ -135,3 +137,25 @@ int amdgpu_xgmi_add_device(struct amdgpu_device *adev)mutex_unlock (&xgmi_mutex);return ret; } + +void amdgpu_xgmi_remove_device (struct amdgpu_device *adev) +{ +struct amdgpu_hive_info *hive; + +if ((adev->asic_type <CHIP_VEGA20 ) || (adev->flags &AMD_IS_APU )) +return ; + +mutex_lock (&xgmi_mutex); + + hive =amdgpu_get_xgmi_hive (adev); +if (!hive) + goto exit; + +if (!(hive->number_devices--)) { +mutex_destroy (&hive->hive_lock); +destroy_workqueue (hive->reset_queue); + } + +exit: +mutex_unlock (&xgmi_mutex); +}drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +0
-0@@ -30,10 +30,13 @@ struct amdgpu_hive_info {struct psp_xgmi_topology_info topology_info;int number_devices;struct mutex hive_lock;
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h struct amdgpu_hive_info { · line 42
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +3
-0+/* hive members reset wq */ + struct workqueue_struct *reset_queue; };struct amdgpu_hive_info *amdgpu_get_xgmi_hive (struct amdgpu_device *adev);int amdgpu_xgmi_update_topology (struct amdgpu_hive_info *hive,struct amdgpu_device *adev);int amdgpu_xgmi_add_device (struct amdgpu_device *adev); +void amdgpu_xgmi_remove_device (struct amdgpu_device *adev);#endif
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 03808d85-0c16-6cee-0e3a-e383969e9c98-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 11 lines · Christian König
Am 29.11.18 um 21:36 schrieb Andrey Grodzovsky:
Quoted 6 lines
XGMI hive has some resources allocted on device init which needs to be deallocated when the device is unregistered.
Add per hive wq to allow all the nodes in hive to run resets concurently - this should speed up the total reset time to avoid breaching the PSP FW timeout.
Do you really want a workqueue? That sounds like the exact opposite of what you describe here.
Quoted 7 lines
E.g. a workqueue is there to serialize all work items scheduled to it.
What you most likely rather want is a work item per device which are scheduled, run in parallel and are joined back together before dropping the per hive lock.
Christian.
As you can see in second patch that exactly how I use this wq. I define per adev work item all of which I enqueue during GPU reset routine. I believe the wq I created will processes work items in parallel since it's is served by per CPU worker thread (thread pool) while a serializing wq is
created using the 'create_singlethread_workqueue' interface which creates an ordered wq which process at most one item simultaneously. I did have my doubts about creating a dedicated wq instead of reusing existing system wide wq such as system_unbound_wq because this adds new kernel threads but eventually I opted for my own queue because there is a hard requirement from the PSP FW to complete all ASIC resets in defined finite amount
of time (1s i believe) otherwise some nodes in the XGMI hive might switch to single GPU mode due to timeout.
If I rely on system wide wq then during stress times this queue might fail to process my work items within that time limit because it's overloaded by work items from other queue clients.
Maybe I should squash the 2 changes into one to make all of this more clear ?
Andrey
Quoted 59 lines
Quoted 59 lines
Signed-off-by Andrey Grodzovsky <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c| 24 ++++++++++++++++++++++++drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h| 3 +++2 files changed, 27 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +0
-0@@ -61,6 +61,8 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev) INIT_LIST_HEAD(&tmp->device_list); mutex_init(&tmp->hive_lock);+
tmp->reset_queue=alloc_workqueue("xgmi-hive", WQ_UNBOUND | WQ_HIGHPRI, 0);
+
return tmp;
}
@@ -135,3 +137,25 @@ intamdgpu_xgmi_add_device(struct amdgpu_device *adev)
mutex_unlock(&xgmi_mutex);
return ret;
}drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +22
-0+ +void amdgpu_xgmi_remove_device (struct amdgpu_device *adev) +{ + struct amdgpu_hive_info *hive; + + if ((adev->asic_type < CHIP_VEGA20) || (adev->flags & AMD_IS_APU)) + return; + + mutex_lock(&xgmi_mutex); + + hive = amdgpu_get_xgmi_hive(adev); + if (!hive) + goto exit; + + if (!(hive->number_devices--)) { + mutex_destroy(&hive->hive_lock); + destroy_workqueue(hive->reset_queue); + } + +exit: + mutex_unlock(&xgmi_mutex); +}drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +2
-0@@ -30,10 +30,13 @@ struct amdgpu_hive_info { struct psp_xgmi_topology_info topology_info; int number_devices; struct mutex hive_lock; + /* hive members reset wq */ + struct workqueue_struct *reset_queue;
Quoted 9 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +0
-0};struct
amdgpu_hive_info*amdgpu_get_xgmi_hive(structamdgpu_device*adev);
intamdgpu_xgmi_update_topology(struct amdgpu_hive_info *hive, struct amdgpu_device *adev);
intamdgpu_xgmi_add_device(struct amdgpu_device *adev); +voidamdgpu_xgmi_remove_device(struct amdgpu_device *adev); #endif
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 52e3af85-4b94-ef26-d2b6-38d00c0b46b6-5C7GfCeVMHo@public.gmane.org
Am 30.11.18 um 16:14 schrieb Grodzovsky, Andrey:
Quoted 18 lines · Christian König
Quoted 16 lines
Am 29.11.18 um 21:36 schrieb Andrey Grodzovsky:
Quoted 6 lines
XGMI hive has some resources allocted on device init which needs to be deallocated when the device is unregistered.
Add per hive wq to allow all the nodes in hive to run resets concurently - this should speed up the total reset time to avoid breaching the PSP FW timeout.
Do you really want a workqueue? That sounds like the exact opposite of what you describe here.
E.g. a workqueue is there to serialize all work items scheduled to it.
What you most likely rather want is a work item per device which are scheduled, run in parallel and are joined back together before dropping the per hive lock.
Quoted 8 lines
Quoted 1 line
Christian.
As you can see in second patch that exactly how I use this wq. I define per adev work item all of which I enqueue during GPU reset routine. I believe the wq I created will processes work items in parallel since it's is served by per CPU worker thread (thread pool) while a serializing wq is
created using the 'create_singlethread_workqueue' interface which creates an ordered wq which process at most one item simultaneously.
That is correct, but you are still limited to one work item processed per CPU which is not necessary what you want.
Quoted 4 lines
I did have my doubts about creating a dedicated wq instead of reusing existing system wide wq such as
system_unbound_wqbecause this adds new kernel threads but eventually I opted for my own queue because there is a hard requirement from the PSP FW to complete all ASIC resets in
Quoted 8 lines
defined finite amount
of time (1s i believe) otherwise some nodes in the XGMI hive might switch to single GPU mode due to timeout.
If I rely on system wide wq then during stress times this queue might fail to process my work items within that time limit because it's overloaded by work items from other queue clients.
Maybe I should squash the 2 changes into one to make all of this more clear ?
No, that won't help. You would rather need to document that properly.
But creating a wq just for a rarely used device reset is completely overkill.
Stuff like that should go to the system_highpri_wq work queue which should make already sure that it never hits the PSP timeout.
Christian.
Quoted 60 lines
Andrey
Quoted 58 lines
Quoted 58 lines
Signed-off-by Andrey Grodzovsky <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 24 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h | 3 +++ 2 files changed, 27 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +1
-0@@ -61,6 +61,8 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev) INIT_LIST_HEAD(&tmp->device_list); mutex_init(&tmp->hive_lock); + tmp->reset_queue = alloc_workqueue("xgmi-hive", WQ_UNBOUND |WQ_HIGHPRI ,0 ); + return tmp; } @@ -135,3 +137,25 @@ int amdgpu_xgmi_add_device(struct
amdgpu_device*adev)
mutex_unlock(&xgmi_mutex);
return ret;
}drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +22
-0+ +void amdgpu_xgmi_remove_device (struct amdgpu_device *adev) +{ + struct amdgpu_hive_info *hive; + + if ((adev->asic_type < CHIP_VEGA20) || (adev->flags & AMD_IS_APU)) + return; + + mutex_lock(&xgmi_mutex); + + hive = amdgpu_get_xgmi_hive(adev); + if (!hive) + goto exit; + + if (!(hive->number_devices--)) { + mutex_destroy(&hive->hive_lock); + destroy_workqueue(hive->reset_queue); + } + +exit: + mutex_unlock(&xgmi_mutex); +}drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +2
-0@@ -30,10 +30,13 @@ struct amdgpu_hive_info { struct psp_xgmi_topology_info topology_info; int number_devices; struct mutex hive_lock; + /* hive members reset wq */ + struct workqueue_struct *reset_queue;
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h struct amdgpu_hive_info { · line 42
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +1
-0}; struct amdgpu_hive_info *amdgpu_get_xgmi_hive(structamdgpu_device *adev); int amdgpu_xgmi_update_topology(struct amdgpu_hive_info *hive,struct amdgpu_device *adev); int amdgpu_xgmi_add_device(struct amdgpu_device *adev); +void amdgpu_xgmi_remove_device (struct amdgpu_device *adev); #endif
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 03535244-a3c7-0aaa-3a1a-160a6163ed0a-5C7GfCeVMHo@public.gmane.org
Quoted 26 lines · Christian
Am 30.11.18 um 16:14 schrieb Grodzovsky, Andrey:
Quoted 17 lines · Christian König
Quoted 16 lines
Am 29.11.18 um 21:36 schrieb Andrey Grodzovsky:
Quoted 6 lines
XGMI hive has some resources allocted on device init which needs to be deallocated when the device is unregistered.
Add per hive wq to allow all the nodes in hive to run resets concurently - this should speed up the total reset time to avoid breaching the PSP FW timeout.
Do you really want a workqueue? That sounds like the exact opposite of what you describe here.
E.g. a workqueue is there to serialize all work items scheduled to it.
What you most likely rather want is a work item per device which are scheduled, run in parallel and are joined back together before dropping the per hive lock.
Quoted 8 lines
Quoted 1 line
Christian.
As you can see in second patch that exactly how I use this wq. I define per adev work item all of which I enqueue during GPU reset routine. I believe the wq I created will processes work items in parallel since it's is served by per CPU worker thread (thread pool) while a serializing wq is
created using the 'create_singlethread_workqueue' interface which creates an ordered wq which process at most one item simultaneously.
Quoted 2 lines
That is correct, but you are still limited to one work item processed per CPU which is not necessary what you want.
I was wrong to say it's single worker thread per CPU, it's actually work thread pool
per CPU, so even with single CPU in the system you get concurrency of execution.
Quoted 15 lines
Quoted 13 lines
I did have my doubts about creating a dedicated wq instead of reusing existing system wide wq such as
system_unbound_wqbecause this adds new kernel threads but eventually I opted for my own queue because there is a hard requirement from the PSP FW to complete all ASIC resets in defined finite amount
of time (1s i believe) otherwise some nodes in the XGMI hive might switch to single GPU mode due to timeout.
If I rely on system wide wq then during stress times this queue might fail to process my work items within that time limit because it's overloaded by work items from other queue clients.
Maybe I should squash the 2 changes into one to make all of this more clear ?No, that won't help. You would rather need to document that properly.
Quoted 7 lines
But creating a wq just for a rarely used device reset is completely overkill.
Stuff like that should go to the
system_highpri_wqwork queue which should make already sure that it never hits the PSP timeout.Christian.
I agree in general with that, but it looks like system_highpri_wq is 'BOUND' wq meaning it's items are
limited to the thread pool of the CPU from which they were queued only, anyway, since I mostly just wait in sleep inside PSP reset function that should be still OK.
Will try that.
Andrey
Quoted 60 lines
Quoted 60 lines
Andrey
Quoted 58 lines
Quoted 58 lines
Signed-off-by Andrey Grodzovsky <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 24 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h | 3 +++ 2 files changed, 27 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +1
-0@@ -61,6 +61,8 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev) INIT_LIST_HEAD(&tmp->device_list); mutex_init(&tmp->hive_lock); + tmp->reset_queue = alloc_workqueue("xgmi-hive", WQ_UNBOUND |WQ_HIGHPRI ,0 ); + return tmp; } @@ -135,3 +137,25 @@ int amdgpu_xgmi_add_device(struct
amdgpu_device*adev)
mutex_unlock(&xgmi_mutex);
return ret;
}drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +22
-0+ +void amdgpu_xgmi_remove_device (struct amdgpu_device *adev) +{ + struct amdgpu_hive_info *hive; + + if ((adev->asic_type < CHIP_VEGA20) || (adev->flags & AMD_IS_APU)) + return; + + mutex_lock(&xgmi_mutex); + + hive = amdgpu_get_xgmi_hive(adev); + if (!hive) + goto exit; + + if (!(hive->number_devices--)) { + mutex_destroy(&hive->hive_lock); + destroy_workqueue(hive->reset_queue); + } + +exit: + mutex_unlock(&xgmi_mutex); +}drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +2
-0@@ -30,10 +30,13 @@ struct amdgpu_hive_info { struct psp_xgmi_topology_info topology_info; int number_devices; struct mutex hive_lock; + /* hive members reset wq */ + struct workqueue_struct *reset_queue;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h struct amdgpu_hive_info { · line 42
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +1
-0}; struct amdgpu_hive_info *amdgpu_get_xgmi_hive(structamdgpu_device *adev); int amdgpu_xgmi_update_topology(struct amdgpu_hive_info *hive,struct amdgpu_device *adev); int amdgpu_xgmi_add_device(struct amdgpu_device *adev); +void amdgpu_xgmi_remove_device (struct amdgpu_device *adev); #endif
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx