drm/amdkfd: Check if there are kfd porcesses using adev by kfd_processes_count
Subsystems (3)
PATCH 1/1 drm/amdkfd: Check if there are kfd porcesses using adev by kfd_processes_count
From: Xiaogang Chen <[email protected]>
amdgpu devices")
During gpu hot-unplug need check if there are kfd porcesses still using the being removed gpu before clean resources of the device. Current driver checks if kfd_processes_table is empty. kfd processes are not terminated after removed from kfd_processes_table immediately. They are still alive and may access the device until kfd_process_wq work queue got ran.
Check kfd->kfd_processes_count value that is updated after kfd process got uninitialized when its ref becomes zero.
--- drivers/gpu/drm/amd/amdkfd/kfd_device.c | 33 +------------------------ 1 file changed, 1 insertion(+), 32 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +1 -32
@@ -1737,37 +1737,6 @@ bool kgd2kfd_vmfault_fast_path(struct amdgpu_device *adev, struct amdgpu_iv_entrreturn false; } -/* check if there is kfd process still uses adev */ -static bool kgd2kfd_check_device_idle (struct amdgpu_device *adev) -{ -struct kfd_process *p; -struct hlist_node *p_temp; -unsigned int temp; -struct kfd_node *dev; - -mutex_lock (&kfd_processes_mutex); - -if (hash_empty (kfd_processes_table)) { -mutex_unlock (&kfd_processes_mutex); -return true; - } - -/* check if there is device still use adev */ -hash_for_each_safe (kfd_processes_table, temp, p_temp, p, kfd_processes) { -for (int i =0 ; i < p->n_pdds; i++) { - dev = p->pdds[i]->dev; -if (dev->adev == adev) { -mutex_unlock (&kfd_processes_mutex); -return false; - } - } - } - -mutex_unlock (&kfd_processes_mutex); - -return true; -} -/** kgd2kfd_teardown_processes - gracefully tear down existing * kfd processes that use adev *
@@ -1800,7 +1769,7 @@ void kgd2kfd_teardown_processes(struct amdgpu_device *adev)mutex_unlock (&kfd_processes_mutex);/* wait all kfd processes use adev terminate */ -while (!kgd2kfd_check_device_idle (adev)) +while (!!atomic_read (&adev->kfd.dev->kfd_processes_count))cond_resched (); }
Signature · 1 line
2.34.1
Quoted 11 lines · Xiaogang.Chen
From: Xiaogang Chen <[email protected]>
Fixes 6cca686dfce7("drm/amdkfd: kfd driver supports hot unplug/replugamdgpu devices")
During gpu hot-unplug need check if there are kfd porcesses still using the being removed gpu before clean resources of the device. Current driver checks if
kfd_processes_tableis empty. kfd processes are not terminated after removed fromkfd_processes_tableimmediately. They are still alive and may access the device untilkfd_process_wqwork queue got ran.
Quoted 4 lines
Check
kfd->kfd_processes_countvalue that is updated after kfd process got uninitialized when its ref becomes zero.Signed-off-by Xiaogang Chen <[email protected]>
Quoted 55 lines
--- drivers/gpu/drm/amd/amdkfd/kfd_device.c | 33 +------------------------ 1 file changed, 1 insertion(+), 32 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_device.c +1
-32@@ -1737,37 +1737,6 @@ bool kgd2kfd_vmfault_fast_path(struct amdgpu_device *adev, struct amdgpu_iv_entrreturn false; } -/* check if there is kfd process still uses adev */ -static bool kgd2kfd_check_device_idle (struct amdgpu_device *adev) -{ -struct kfd_process *p; -struct hlist_node *p_temp; -unsigned int temp; -struct kfd_node *dev; - -mutex_lock (&kfd_processes_mutex); - -if (hash_empty (kfd_processes_table)) { -mutex_unlock (&kfd_processes_mutex); -return true; - } - -/* check if there is device still use adev */ -hash_for_each_safe (kfd_processes_table, temp, p_temp, p, kfd_processes) { -for (int i =0 ; i < p->n_pdds; i++) { - dev = p->pdds[i]->dev; -if (dev->adev == adev) { -mutex_unlock (&kfd_processes_mutex); -return false; - } - } - } - -mutex_unlock (&kfd_processes_mutex); - -return true; -} -/** kgd2kfd_teardown_processes - gracefully tear down existing * kfd processes that use adev * @@ -1800,7 +1769,7 @@ void kgd2kfd_teardown_processes(struct amdgpu_device *adev)mutex_unlock (&kfd_processes_mutex);/* wait all kfd processes use adev terminate */ -while (!kgd2kfd_check_device_idle (adev)) +while (!!atomic_read (&adev->kfd.dev->kfd_processes_count))cond_resched (); }