KFD fixes
Subsystems (3)
cover KFD fixes
Patches 1 and 2 should be OK for drm-fixes. Patch 1 in particular is important as it fixes VM faults in applications that rely on scratch memory.
Patches 3 and 4 are based on recently upstreamed GPUVM changes for dGPUs and should be applied to the same drm-next branch if it's not too late.
Felix Kuehling (4):
drm/amdkfd: Fix scratch memory with HWS enabled drm/amdkfd: Deallocate SDMA queues correctly drm/amdgpu: Fix acquiring VM on large-BAR systems drm/amdkfd: Use ordered workqueue to restore processes
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 3 +-- .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 20 ++++++++++----- drivers/gpu/drm/amd/amdkfd/kfd_module.c | 6 ++++- drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c | 3 +-- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 30 +++++++++++++++++++--- 6 files changed, 48 insertions(+), 16 deletions(-)
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): 1521833436-31511-1-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org
PATCH 1/4 drm/amdkfd: Fix scratch memory with HWS enabled
Program sh_hidden_private_base_vmid correctly in the map-process PM4 packet.
--- drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c +1 -2
@@ -188,8 +188,7 @@ static int pm_create_map_process(struct packet_manager *pm, uint32_t *buffer, packet->sh_mem_ape1_base = qpd->sh_mem_ape1_base; packet->sh_mem_ape1_limit = qpd->sh_mem_ape1_limit; -/* TODO: scratch support */ - packet->sh_hidden_private_base_vmid =0 ; + packet->sh_hidden_private_base_vmid = qpd->sh_hidden_private_base; packet->gds_addr_lo =lower_32_bits (qpd->gds_context_area); packet->gds_addr_hi =upper_32_bits (qpd->gds_context_area);
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/4 drm/amdkfd: Deallocate SDMA queues correctly
In reply to a message not in the archiveDeallocate SDMA queues during abnormal process termination and when queue creation fails after the SDMA allocation.
--- .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +14 -6
@@ -1058,13 +1058,13 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q,pr_warn ("Can't create new usermode queue because %d queues were already created\n" , dqm->total_queue_count); retval = -EPERM ; - goto out; + goto out_unlock; }if (q->properties.type ==KFD_QUEUE_TYPE_SDMA ) { retval =allocate_sdma_queue (dqm, &q->sdma_id);if (retval) - goto out; + goto out_unlock; q->properties.sdma_queue_id = q->sdma_id /CIK_SDMA_QUEUES_PER_ENGINE ; q->properties.sdma_engine_id =
@@ -1075,7 +1075,7 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q,if (!mqd) { retval = -ENOMEM ; - goto out; + goto out_deallocate_sdma_queue; }/* * Eviction state logic: we only mark active queues as evicted
@@ -1093,7 +1093,7 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q, retval = mqd->init_mqd (mqd, &q->mqd, &q->mqd_mem_obj, &q->gart_mqd_addr, &q->properties);if (retval) - goto out; + goto out_deallocate_sdma_queue;list_add (&q->list, &qpd->queues_list); qpd->queue_count++;
@@ -1114,7 +1114,13 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q,pr_debug ("Total of %d queues are accountable so far\n" , dqm->total_queue_count); -out: +mutex_unlock (&dqm->lock); +return retval; + +out_deallocate_sdma_queue: +if (q->properties.type ==KFD_QUEUE_TYPE_SDMA ) +deallocate_sdma_queue (dqm, q->sdma_id); +out_unlock:mutex_unlock (&dqm->lock);return retval; }
@@ -1433,8 +1439,10 @@ static int process_termination_cpsch(struct device_queue_manager *dqm,/* Clear all user mode queues */ list_for_each_entry (q, &qpd->queues_list, list) { -if (q->properties.type ==KFD_QUEUE_TYPE_SDMA ) +if (q->properties.type ==KFD_QUEUE_TYPE_SDMA ) { dqm->sdma_queue_count--; +deallocate_sdma_queue (dqm, q->sdma_id); + }if (q->properties.is_active) dqm->queue_count--;
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/4 drm/amdgpu: Fix acquiring VM on large-BAR systems
In reply to a message not in the archiveOn large-BAR systems the VM page tables for compute are accessed by the CPU. Always allow CPU access to the page directory so that it can be used later by the CPU when a VM is converted to a compute VM.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -2
@@ -2406,8 +2406,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (vm->use_cpu_for_update) flags |=AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ;else - flags |= (AMDGPU_GEM_CREATE_NO_CPU_ACCESS | -AMDGPU_GEM_CREATE_SHADOW ); + flags |=AMDGPU_GEM_CREATE_SHADOW ; size =amdgpu_vm_bo_size (adev, adev->vm_manager.root_level); r = amdgpu_bo_create(adev, size, align, true, AMDGPU_GEM_DOMAIN_VRAM,
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): 1521833436-31511-4-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org
Christian König
NAKRe: [PATCH 3/4] drm/amdgpu: Fix acquiring VM on large-BAR systems
Am 23.03.2018 um 20:30 schrieb Felix Kuehling:
Quoted 3 lines
On large-BAR systems the VM page tables for compute are accessed by the CPU. Always allow CPU access to the page directory so that it can be used later by the CPU when a VM is converted to a compute VM.
NAK, that means we initial place the PD in the visible are for GFX which is not desired (not much of an issue for Vega/Raven, but bad for older generations).
Better to clear the flag later on and set the AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED and then re-validate.
Regards,
Christian.
Quoted 11 lines
Signed-off-by Felix Kuehling <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 2412
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-2@@ -2406,8 +2406,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (vm->use_cpu_for_update) flags |=AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED ;else - flags |= (AMDGPU_GEM_CREATE_NO_CPU_ACCESS | -AMDGPU_GEM_CREATE_SHADOW ); + flags |=AMDGPU_GEM_CREATE_SHADOW ; size =amdgpu_vm_bo_size (adev, adev->vm_manager.root_level); r = amdgpu_bo_create(adev, size, align, true, AMDGPU_GEM_DOMAIN_VRAM,
_______________________________________________
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): 54d8848f-67ca-d611-48cc-d75699190be0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH 3/4] drm/amdgpu: Fix acquiring VM on large-BAR systems
Quoted 8 lines · Christian König
Am 23.03.2018 um 20:30 schrieb Felix Kuehling:
Quoted 3 lines
On large-BAR systems the VM page tables for compute are accessed by the CPU. Always allow CPU access to the page directory so that it can be used later by the CPU when a VM is converted to a compute VM.
NAK, that means we initial place the PD in the visible are for GFX which is not desired (not much of an issue for Vega/Raven, but bad for older generations).
I'm not setting AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED. Doesn't that mean the buffer can be placed in invisible VRAM initially?
Quoted 3 lines
Better to clear the flag later on and set the
AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIREDand then re-validate.
The AMDGPU_GEM_CREATE_NO_CPU_ACCESS seems to mean "this BO must never be CPU mapped". Clearing that flag later kind of defeats the purpose of making such a declaration at allocation time. If I know that the buffer may need CPU access at some point in the future, I figured I shouldn't set the flag in the first place.
FWIW, I didn't see any example of the AMDGPU_GEM_CREATE_NO_CPU_ACCESS flag ever being removed from an existing BO.
Regards,
Felix
Quoted 10 lines
Regards,
Christian.Quoted 6 lines
Signed-off-by Felix Kuehling <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 17 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -2406,8 +2406,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, if (vm->use_cpu_for_update) flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;Quoted 7 lines
else
- flags |= (AMDGPU_GEM_CREATE_NO_CPU_ACCESS|
-AMDGPU_GEM_CREATE_SHADOW);
+ flags |=AMDGPU_GEM_CREATE_SHADOW;
size =amdgpu_vm_bo_size(adev, adev->vm_manager.root_level); r = amdgpu_bo_create(adev, size, align, true,AMDGPU_GEM_DOMAIN_VRAM,
_______________________________________________
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): 6a4ec8be-6044-f5ac-8e2f-d8aa0fc024cc-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 3/4] drm/amdgpu: Fix acquiring VM on large-BAR systems
Am 23.03.2018 um 20:53 schrieb Felix Kuehling:
Quoted 10 lines · Christian König
Quoted 7 lines
Am 23.03.2018 um 20:30 schrieb Felix Kuehling:
Quoted 3 lines
On large-BAR systems the VM page tables for compute are accessed by the CPU. Always allow CPU access to the page directory so that it can be used later by the CPU when a VM is converted to a compute VM.
NAK, that means we initial place the PD in the visible are for GFX which is not desired (not much of an issue for Vega/Raven, but bad for older generations).
I'm not setting
AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED. Doesn't that mean the buffer can be placed in invisible VRAM initially?
The difference is the preference. When AMDGPU_GEM_CREATE_NO_CPU_ACCESS is set we try to place it initially in invisible VRAM.
Since VM page directories have a low chance of being evicted it will just stick in visible VRAM when it was placed initially there.
Quoted 7 lines
Quoted 2 lines
Better to clear the flag later on and set the
AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIREDand then re-validate.The
AMDGPU_GEM_CREATE_NO_CPU_ACCESSseems to mean "this BO must never be CPU mapped". Clearing that flag later kind of defeats the purpose of making such a declaration at allocation time. If I know that the buffer may need CPU access at some point in the future, I figured I shouldn't set the flag in the first place.
Correct, but that only counts for userspace because userspace can't modify the flags :)
If I remember correctly we also enforce it in the mmap IOCTL that the flag isn't set, but that doesn't really matter for the kernel.
At least the AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED flag is cleared and set all the time in the kernel (but not for VM page tables).
Quoted 2 lines
FWIW, I didn't see any example of the
AMDGPU_GEM_CREATE_NO_CPU_ACCESSflag ever being removed from an existing BO.
Yeah, but that should be harmless as far as I can see.
If you want to avoid the move of the page directory on large BAR systems when switching a VM from GFX to compute we can also initially create the BO in the system domain.
Thinking about that a bit more that is probably a good idea anyway because it avoids using VRAM by just opening the device.
Regards,
Christian.
Quoted 24 lines
Regards,
FelixQuoted 20 lines
Regards,
Christian.Quoted 17 lines
Signed-off-by Felix Kuehling <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-2@@ -2406,8 +2406,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, if (vm->use_cpu_for_update) flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; else - flags |= (AMDGPU_GEM_CREATE_NO_CPU_ACCESS | - AMDGPU_GEM_CREATE_SHADOW);
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0+ flags |= AMDGPU_GEM_CREATE_SHADOW; size = amdgpu_vm_bo_size(adev, adev->vm_manager.root_level); r = amdgpu_bo_create(adev, size, align, true,
AMDGPU_GEM_DOMAIN_VRAM,_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
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): 14a96025-b9ee-93e3-69e0-ab0b2f364691-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH 3/4] drm/amdgpu: Fix acquiring VM on large-BAR systems
Am 2018-03-24 um 04:34 AM schrieb Christian König:
Quoted 6 lines
Am 23.03.2018 um 20:53 schrieb Felix Kuehling:
Quoted 5 lines · Christian König
Quoted 4 lines
Am 23.03.2018 um 20:30 schrieb Felix Kuehling:
Quoted 3 lines
On large-BAR systems the VM page tables for compute are accessed by the CPU. Always allow CPU access to the page directory so that it can be used later by the CPU when a VM is converted to a compute VM.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
NAK, that means we initial place the PD in the visible are for GFX which is not desired (not much of an issue for Vega/Raven, but bad for older generations).
I'm not setting
AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED. Doesn't that mean the buffer can be placed in invisible VRAM initially?The difference is the preference. When
AMDGPU_GEM_CREATE_NO_CPU_ACCESSis set we try to place it initially in invisible VRAM.
Where is that done? I'm looking at amdgpu_ttm_placement_from_domain. It only looks at AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED. It does not consider the AMDGPU_GEM_CREATE_NO_CPU_ACCESS flag. So creating the BO without AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED should have the intended effect of placing the BO into invisible VRAM initially.
As far as I can tell, my patch does not change the initial placement. It only allows the BO to be kmapped later.
Quoted 12 lines
Since VM page directories have a low chance of being evicted it will just stick in visible VRAM when it was placed initially there.
Quoted 7 lines
Quoted 2 lines
Better to clear the flag later on and set the
AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIREDand then re-validate.The
AMDGPU_GEM_CREATE_NO_CPU_ACCESSseems to mean "this BO must never be CPU mapped". Clearing that flag later kind of defeats the purpose of making such a declaration at allocation time. If I know that the buffer may need CPU access at some point in the future, I figured I shouldn't set the flag in the first place.
Quoted 8 lines
Correct, but that only counts for userspace because userspace can't modify the flags :)
If I remember correctly we also enforce it in the mmap IOCTL that the flag isn't set, but that doesn't really matter for the kernel.
At least the
AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIREDflag is cleared and set all the time in the kernel (but not for VM page tables).
Right, I see it being set while pinning. But page tables don't usually get pinned.
Quoted 4 lines
Quoted 3 lines
FWIW, I didn't see any example of the
AMDGPU_GEM_CREATE_NO_CPU_ACCESSflag ever being removed from an existing BO.
Quoted 8 lines
Yeah, but that should be harmless as far as I can see.
If you want to avoid the move of the page directory on large BAR systems when switching a VM from GFX to compute we can also initially create the BO in the system domain.
Thinking about that a bit more that is probably a good idea anyway because it avoids using VRAM by just opening the device.
Sure, I'd do that as a separate change because it actually changes the initial placement, whereas my patch did not (as far as I can tell).
Regards,
Felix
Quoted 37 lines
Regards,
Christian.Quoted 24 lines
Regards,
FelixQuoted 20 lines
Regards,
Christian.Quoted 17 lines
Signed-off-by Felix Kuehling <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -2406,8 +2406,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, if (vm->use_cpu_for_update) flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;else
- flags |= (AMDGPU_GEM_CREATE_NO_CPU_ACCESS| -AMDGPU_GEM_CREATE_SHADOW);Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
+ flags |=
AMDGPU_GEM_CREATE_SHADOW;
size =amdgpu_vm_bo_size(adev, adev->vm_manager.root_level); r = amdgpu_bo_create(adev, size, align, true,AMDGPU_GEM_DOMAIN_VRAM,_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 4 lines
_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
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): 694f9b1e-9c06-b4ed-6f08-2c2d1201ab3f-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH 3/4] drm/amdgpu: Fix acquiring VM on large-BAR systems
Am 26.03.2018 um 03:31 schrieb Felix Kühling:
Quoted 10 lines
Am 2018-03-24 um 04:34 AM schrieb Christian König:
Quoted 9 lines
Am 23.03.2018 um 20:53 schrieb Felix Kuehling:
Quoted 8 lines · Christian König
Quoted 7 lines
Am 23.03.2018 um 20:30 schrieb Felix Kuehling:
Quoted 3 lines
On large-BAR systems the VM page tables for compute are accessed by the CPU. Always allow CPU access to the page directory so that it can be used later by the CPU when a VM is converted to a compute VM.
NAK, that means we initial place the PD in the visible are for GFX which is not desired (not much of an issue for Vega/Raven, but bad for older generations).
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
I'm not setting
AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED. Doesn't that mean the buffer can be placed in invisible VRAM initially?The difference is the preference. When
AMDGPU_GEM_CREATE_NO_CPU_ACCESSis set we try to place it initially in invisible VRAM.Where is that done? I'm looking at
amdgpu_ttm_placement_from_domain. It only looks atAMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED.
Of course! I have to apologize, my memory fooled me and I mixed up the handling of two flags.
Didn't had the chance on the weekend to actually double check the code, but you're absolutely right.
Quoted 9 lines
[SNIP]
Quoted 6 lines
If you want to avoid the move of the page directory on large BAR systems when switching a VM from GFX to compute we can also initially create the BO in the system domain.
Thinking about that a bit more that is probably a good idea anyway because it avoids using VRAM by just opening the device.
Sure, I'd do that as a separate change because it actually changes the initial placement, whereas my patch did not (as far as I can tell).
Yeah, indeed. Creating the BO in the system domain would also simplify the eviction double check dance.
Anyway this patch is Reviewed-by: Christian König <[email protected]> and sorry for the noise.
Regards,
Christian.
Quoted 44 lines
Regards,
FelixQuoted 38 lines
Regards,
Christian.Quoted 23 lines
Regards,
FelixQuoted 20 lines
Regards,
Christian.Quoted 17 lines
Signed-off-by Felix Kuehling <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-2@@ -2406,8 +2406,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, if (vm->use_cpu_for_update) flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; else - flags |= (AMDGPU_GEM_CREATE_NO_CPU_ACCESS | - AMDGPU_GEM_CREATE_SHADOW);Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0+ flags |= AMDGPU_GEM_CREATE_SHADOW; size = amdgpu_vm_bo_size(adev, adev->vm_manager.root_level); r = amdgpu_bo_create(adev, size, align, true,
AMDGPU_GEM_DOMAIN_VRAM,_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/4 drm/amdkfd: Use ordered workqueue to restore processes
In reply to a message not in the archiveRestoring multiple processes concurrently can lead to live-locks where each process prevents the other from validating all its BOs.
--- drivers/gpu/drm/amd/amdkfd/kfd_module.c | 6 +++++- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 30 ++++++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_module.c +5 -1
@@ -133,7 +133,9 @@ static int __init kfd_module_init(void)if (err <0 ) goto err_topology; -kfd_process_create_wq (); + err =kfd_process_create_wq (); +if (err <0 ) + goto err_create_wq;kfd_debugfs_init ();
@@ -143,6 +145,8 @@ static int __init kfd_module_init(void)return 0 ; +err_create_wq: +kfd_topology_shutdown (); err_topology:kfd_chardev_exit (); err_ioctl:
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -1
@@ -674,7 +674,7 @@ struct amdkfd_ioctl_desc {const char *name; }; -void kfd_process_create_wq (void ); +int kfd_process_create_wq (void );void kfd_process_destroy_wq (void );struct kfd_process *kfd_create_process (struct file *filep);struct kfd_process *kfd_get_process (const struct task_struct *);
drivers/gpu/drm/amd/amdkfd/kfd_process.c +26 -4
@@ -48,8 +48,17 @@ static DEFINE_MUTEX(kfd_processes_mutex);DEFINE_SRCU (kfd_processes_srcu); +/* For process termination handling */ static struct workqueue_struct *kfd_process_wq; +/* Ordered, single-threaded workqueue for restoring evicted +* processes. Restoring multiple processes concurrently under memory +* pressure can lead to processes blocking each other from validating +* their BOs and result in a live-lock situation where processes +* remain evicted indefinitely. +*/ +static struct workqueue_struct *kfd_restore_wq; +static struct kfd_process *find_process (const struct task_struct *thread);static void kfd_process_ref_release (struct kref *ref); static struct kfd_process *create_process(const struct task_struct *thread,
@@ -59,10 +68,19 @@ static void evict_process_worker(struct work_struct *work);static void restore_process_worker (struct work_struct *work); -void kfd_process_create_wq (void ) +int kfd_process_create_wq (void ) {if (!kfd_process_wq) kfd_process_wq =alloc_workqueue ("kfd_process_wq" ,0 ,0 ); +if (!kfd_restore_wq) + kfd_restore_wq =alloc_ordered_workqueue ("kfd_restore_wq" ,0 ); + +if (!kfd_restore_wq || !kfd_restore_wq) { +kfd_process_destroy_wq (); +return -ENOMEM ; + } + +return 0 ; }void kfd_process_destroy_wq (void )
@@ -71,6 +89,10 @@ void kfd_process_destroy_wq(void)destroy_workqueue (kfd_process_wq); kfd_process_wq =NULL ; } +if (kfd_restore_wq) { +destroy_workqueue (kfd_restore_wq); + kfd_restore_wq =NULL ; + } } static void kfd_process_free_gpuvm(struct kgd_mem *mem,
@@ -869,7 +891,7 @@ static void evict_process_worker(struct work_struct *work)dma_fence_signal (p->ef);dma_fence_put (p->ef); p->ef =NULL ; -schedule_delayed_work (&p->restore_work, +queue_delayed_work (kfd_restore_wq, &p->restore_work,msecs_to_jiffies (PROCESS_RESTORE_TIME_MS ));pr_debug ("Finished evicting pasid %d\n" , p->pasid);
@@ -918,7 +940,7 @@ static void restore_process_worker(struct work_struct *work)if (ret) {pr_debug ("Failed to restore BOs of pasid %d, retry after %d ms\n" , p->pasid,PROCESS_BACK_OFF_TIME_MS ); - ret =schedule_delayed_work (&p->restore_work, + ret =queue_delayed_work (kfd_restore_wq, &p->restore_work,msecs_to_jiffies (PROCESS_BACK_OFF_TIME_MS ));WARN (!ret,"reschedule restore work failed\n" );return ;
@@ -957,7 +979,7 @@ int kfd_resume_all_processes(void)int ret =0 , idx =srcu_read_lock (&kfd_processes_srcu);hash_for_each_rcu (kfd_processes_table, temp, p, kfd_processes) { -if (!schedule_delayed_work (&p->restore_work,0 )) { +if (!queue_delayed_work (kfd_restore_wq, &p->restore_work,0 )) {pr_err ("Restore process %d failed during resume\n" , p->pasid); ret = -EFAULT ;
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): 1521833436-31511-5-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org
Oded Gabbay
Reviewed-byRe: [PATCH 4/4] drm/amdkfd: Use ordered workqueue to restore processes
Quoted 73 lines · Felix Kuehling
Restoring multiple processes concurrently can lead to live-locks where each process prevents the other from validating all its BOs.
Signed-off-by Felix Kuehling <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_module.c | 6 +++++- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 30 ++++++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_module.c +5
-1@@ -133,7 +133,9 @@ static int __init kfd_module_init(void)if (err <0 ) goto err_topology; -kfd_process_create_wq (); + err =kfd_process_create_wq (); +if (err <0 ) + goto err_create_wq;kfd_debugfs_init ();@@ -143,6 +145,8 @@ static int __init kfd_module_init(void)return 0 ; +err_create_wq: +kfd_topology_shutdown (); err_topology:kfd_chardev_exit (); err_ioctl:drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1
-1@@ -674,7 +674,7 @@ struct amdkfd_ioctl_desc {const char *name; }; -void kfd_process_create_wq (void ); +int kfd_process_create_wq (void );void kfd_process_destroy_wq (void );struct kfd_process *kfd_create_process (struct file *filep);struct kfd_process *kfd_get_process (const struct task_struct *);drivers/gpu/drm/amd/amdkfd/kfd_process.c +9
-0@@ -48,8 +48,17 @@ static DEFINE_MUTEX(kfd_processes_mutex);DEFINE_SRCU (kfd_processes_srcu); +/* For process termination handling */ static struct workqueue_struct *kfd_process_wq; +/* Ordered, single-threaded workqueue for restoring evicted +* processes. Restoring multiple processes concurrently under memory +* pressure can lead to processes blocking each other from validating +* their BOs and result in a live-lock situation where processes +* remain evicted indefinitely. +*/ +static struct workqueue_struct *kfd_restore_wq; +static struct kfd_process *find_process (const struct task_struct *thread);static void kfd_process_ref_release (struct kref *ref); static struct kfd_process *create_process(const struct task_struct *thread,@@ -59,10 +68,19 @@ static void evict_process_worker(struct work_struct *work);static void restore_process_worker (struct work_struct *work);
drivers/gpu/drm/amd/amdkfd/kfd_process.c static void evict_process_worker(struct work_struct *work); · line 78
Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +5
-1-void kfd_process_create_wq (void ) +int kfd_process_create_wq (void ) {if (!kfd_process_wq) kfd_process_wq =alloc_workqueue ("kfd_process_wq" ,0 ,0 ); +if (!kfd_restore_wq) + kfd_restore_wq =alloc_ordered_workqueue ("kfd_restore_wq" ,0 ); + +if (!kfd_restore_wq || !kfd_restore_wq) {
Should be
if (!kfd_process_wq|| !kfd_restore_wq) {
Quoted 48 lines
drivers/gpu/drm/amd/amdkfd/kfd_process.c +12
-4+kfd_process_destroy_wq (); +return -ENOMEM ; + } + +return 0 ; }void kfd_process_destroy_wq (void )@@ -71,6 +89,10 @@ void kfd_process_destroy_wq(void)destroy_workqueue (kfd_process_wq); kfd_process_wq =NULL ; } +if (kfd_restore_wq) { +destroy_workqueue (kfd_restore_wq); + kfd_restore_wq =NULL ; + } } static void kfd_process_free_gpuvm(struct kgd_mem *mem,@@ -869,7 +891,7 @@ static void evict_process_worker(struct work_struct *work)dma_fence_signal (p->ef);dma_fence_put (p->ef); p->ef =NULL ; -schedule_delayed_work (&p->restore_work, +queue_delayed_work (kfd_restore_wq, &p->restore_work,msecs_to_jiffies (PROCESS_RESTORE_TIME_MS ));pr_debug ("Finished evicting pasid %d\n" , p->pasid);@@ -918,7 +940,7 @@ static void restore_process_worker(struct work_struct *work)if (ret) {pr_debug ("Failed to restore BOs of pasid %d, retry after %d ms\n" , p->pasid,PROCESS_BACK_OFF_TIME_MS ); - ret =schedule_delayed_work (&p->restore_work, + ret =queue_delayed_work (kfd_restore_wq, &p->restore_work,msecs_to_jiffies (PROCESS_BACK_OFF_TIME_MS ));WARN (!ret,"reschedule restore work failed\n" );return ;@@ -957,7 +979,7 @@ int kfd_resume_all_processes(void)int ret =0 , idx =srcu_read_lock (&kfd_processes_srcu);hash_for_each_rcu (kfd_processes_table, temp, p, kfd_processes) { -if (!schedule_delayed_work (&p->restore_work,0 )) { +if (!queue_delayed_work (kfd_restore_wq, &p->restore_work,0 )) {pr_err ("Restore process %d failed during resume\n" , p->pasid); ret = -EFAULT ; --
Quoted 2 lines
2.7.4
I fixed the comment above. No need to resend.
This patch is:
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx