AMDGPU patches for the drm_exec context
Subsystems (5)
Hey Alex,
any objections to merge those patches through drm-misc-next? If not can you give me an rb for them?
Thanks,
Christian.
PATCH 1/6 drm: execution context for GEM buffers v6
This adds the infrastructure for an execution context for GEM buffers which is similar to the existing TTMs execbuf util and intended to replace it in the long term.
The basic functionality is that we abstracts the necessary loop to lock many different GEM buffers with automated deadlock and duplicate handling.
v2: drop xarray and use dynamic resized array instead, the locking
overhead is unecessary and measurable.
v3: drop duplicate tracking, radeon is really the only one needing that.
v4: fixes issues pointed out by Danilo, some typos in comments and a
helper for lock arrays of GEM objects.
v5: some suggestions by Boris Brezillon, especially just use one retry
macro, drop loop in prepare_array, use flags instead of bool
v6: minor changes suggested by Thomas, Boris and Danilo
--- Documentation/gpu/drm-mm.rst | 12 ++ drivers/gpu/drm/Kconfig | 6 + drivers/gpu/drm/Makefile | 2 + drivers/gpu/drm/drm_exec.c | 333 +++++++++++++++++++++++++++++++++++ include/drm/drm_exec.h | 121 +++++++++++++ 5 files changed, 474 insertions(+) create mode 100644 drivers/gpu/drm/drm_exec.c create mode 100644 include/drm/drm_exec.h
Documentation/gpu/drm-mm.rst +12 -0
@@ -493,6 +493,18 @@ DRM Sync Objects .. kernel-doc:: drivers/gpu/drm/drm_syncobj.c :export: +DRM Execution context +===================== + +.. kernel-doc:: drivers/gpu/drm/drm_exec.c + :doc: Overview + +.. kernel-doc:: include/drm/drm_exec.h + :internal: + +.. kernel-doc:: drivers/gpu/drm/drm_exec.c + :export: + GPU Scheduler =============
drivers/gpu/drm/Kconfig +6 -0
@@ -194,6 +194,12 @@ config DRM_TTM GPU memory types. Will be enabled automatically if a device driver uses it. +config DRM_EXEC + tristate + depends on DRM + help + Execution context for command submissions + config DRM_BUDDY tristate depends on DRM
drivers/gpu/drm/Makefile +2 -0
@@ -78,6 +78,8 @@ obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o # # Memory-management helpers # +# +obj-$(CONFIG_DRM_EXEC) += drm_exec.o obj-$(CONFIG_DRM_BUDDY) += drm_buddy.o
drivers/gpu/drm/drm_exec.c new file +333 -0
333 lines not on this page · raw message
include/drm/drm_exec.h new file +121 -0
121 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 2/6 drm: add drm_exec selftests v4
In reply to Christian KönigExercise at least all driver facing functions of this new component.
v2: add array test as well
v3: some kunit cleanups
v4: more tests and cleanups
--- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/tests/Makefile | 3 +- drivers/gpu/drm/tests/drm_exec_test.c | 159 ++++++++++++++++++++++++++ 3 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/tests/drm_exec_test.c
drivers/gpu/drm/Kconfig +1 -0
@@ -80,6 +80,7 @@ config DRM_KUNIT_TEST select DRM_BUDDY select DRM_EXPORT_FOR_TESTS if m select DRM_KUNIT_TEST_HELPERS + select DRM_EXEC default KUNIT_ALL_TESTS help This builds unit tests for DRM. This option is not useful for
drivers/gpu/drm/tests/Makefile +2 -1
@@ -17,6 +17,7 @@ obj-$(CONFIG_DRM_KUNIT_TEST) += \ drm_modes_test.o \ drm_plane_helper_test.o \ drm_probe_helper_test.o \ - drm_rect_test.o + drm_rect_test.o \ + drm_exec_test.o CFLAGS_drm_mm_test.o := $(DISABLE_STRUCTLEAK_PLUGIN)
drivers/gpu/drm/tests/drm_exec_test.c new file +159 -0
159 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 3/6 drm/amdkfd: switch over to using drm_exec v2
In reply to Christian KönigAvoids quite a bit of logic and kmalloc overhead.
v2: fix multiple problems pointed out by Felix
--- drivers/gpu/drm/amd/amdgpu/Kconfig | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 5 +- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 299 +++++++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 18 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 + drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 45 ++- 6 files changed, 162 insertions(+), 210 deletions(-)
drivers/gpu/drm/amd/amdgpu/Kconfig +1 -0
@@ -21,6 +21,7 @@ config DRM_AMDGPU select INTERVAL_TREE select DRM_BUDDY select DRM_SUBALLOC_HELPER + select DRM_EXEC # amdgpu depends on ACPI_VIDEO when ACPI is enabled, for select to work # ACPI_VIDEO's dependencies must also be selected. select INPUT if ACPI
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -3
@@ -25,6 +25,7 @@#ifndef AMDGPU_AMDKFD_H_INCLUDED #define AMDGPU_AMDKFD_H_INCLUDED +#include <linux/list.h> #include <linux/types.h> #include <linux/mm.h> #include <linux/kthread.h>
@@ -32,7 +33,6 @@#include <linux/mmu_notifier.h> #include <linux/memremap.h> #include <kgd_kfd_interface.h> -#include <drm/ttm/ttm_execbuf_util.h> #include "amdgpu_sync.h" #include "amdgpu_vm.h" #include "amdgpu_xcp.h"
@@ -71,8 +71,7 @@ struct kgd_mem {struct hmm_range *range;struct list_head attachments;/* protected by amdkfd_process_info.lock */ -struct ttm_validate_buffer validate_list; -struct ttm_validate_buffer resv_list; +struct list_head validate_list;uint32_t domain;unsigned int mapped_to_gpu_memory;uint64_t va;
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +115 -184
464 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +18 -0
@@ -34,6 +34,7 @@#include <drm/amdgpu_drm.h> #include <drm/drm_drv.h> #include <drm/ttm/ttm_tt.h> +#include <drm/drm_exec.h> #include "amdgpu.h" #include "amdgpu_trace.h" #include "amdgpu_amdkfd.h"
@@ -360,6 +361,23 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,list_add (&entry->tv.head, validated); } +/** +* amdgpu_vm_lock_pd - lock PD in drm_exec +* +* @vm: vm providing the BOs +* @exec: drm execution context +* @num_fences: number of extra fences to reserve +* +* Lock the VM root PD in the DRM execution context. +*/ +int amdgpu_vm_lock_pd (struct amdgpu_vm *vm,struct drm_exec *exec, +unsigned int num_fences) +{ +/* We need at least two fences for the VM PD/PT updates */ +return drm_exec_prepare_obj (exec, &vm->root.bo->tbo.base, +2 + num_fences); +} +/** * amdgpu_vm_move_to_lru_tail - move all BOs to the end of LRU *
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4 -0
@@ -36,6 +36,8 @@#include "amdgpu_ring.h" #include "amdgpu_ids.h" +struct drm_exec ; +struct amdgpu_bo_va ;struct amdgpu_job ;struct amdgpu_bo_list_entry ;
@@ -399,6 +401,8 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);void amdgpu_vm_get_pd_bo (struct amdgpu_vm *vm,struct list_head *validated,struct amdgpu_bo_list_entry *entry); +int amdgpu_vm_lock_pd (struct amdgpu_vm *vm,struct drm_exec *exec, +unsigned int num_fences);bool amdgpu_vm_ready (struct amdgpu_vm *vm);uint64_t amdgpu_vm_generation (struct amdgpu_device *adev,struct amdgpu_vm *vm); int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +22 -23
75 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 4/6 drm/amdgpu: use drm_exec for GEM and CSA handling
In reply to Christian KönigStart using the new component here as well.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c | 78 +++++++++++------------- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 80 ++++++++++++------------- 2 files changed, 71 insertions(+), 87 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c +34 -44
@@ -22,6 +22,8 @@* * Author: [email protected] */ +#include <drm/drm_exec.h> +#include "amdgpu.h" uint64_t amdgpu_csa_vaddr (struct amdgpu_device *adev)
@@ -65,31 +67,25 @@ int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm, struct amdgpu_bo *bo, struct amdgpu_bo_va **bo_va, uint64_t csa_addr, uint32_t size) { - struct ww_acquire_ctx ticket; -struct list_head list; -struct amdgpu_bo_list_entry pd; -struct ttm_validate_buffer csa_tv; + struct drm_exec exec;int r; -INIT_LIST_HEAD (&list); -INIT_LIST_HEAD (&csa_tv.head); - csa_tv.bo = &bo->tbo; - csa_tv.num_shared =1 ; - -list_add (&csa_tv.head, &list); -amdgpu_vm_get_pd_bo (vm, &list, &pd); - - r =ttm_eu_reserve_buffers (&ticket, &list, true,NULL ); -if (r) { -DRM_ERROR ("failed to reserve CSA,PD BOs: err=%d\n" , r); -return r; +drm_exec_init (&exec,DRM_EXEC_INTERRUPTIBLE_WAIT ); + drm_exec_until_all_locked(&exec) { + r =amdgpu_vm_lock_pd (vm, &exec,0 ); +if (likely (!r)) + r =drm_exec_lock_obj (&exec, &bo->tbo.base); +drm_exec_retry_on_contention (&exec); +if (unlikely (r)) { +DRM_ERROR ("failed to reserve CSA,PD BOs: err=%d\n" , r); + goto error; + } } *bo_va =amdgpu_vm_bo_add (adev, vm, bo);if (!*bo_va) { -ttm_eu_backoff_reservation (&ticket, &list); -DRM_ERROR ("failed to create bo_va for static CSA\n" ); -return -ENOMEM ; + r = -ENOMEM ; + goto error; } r = amdgpu_vm_bo_map(adev, *bo_va, csa_addr, 0, size,
@@ -99,48 +95,42 @@ int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (r) {DRM_ERROR ("failed to do bo_map on static CSA, err=%d\n" , r);amdgpu_vm_bo_del (adev, *bo_va); -ttm_eu_backoff_reservation (&ticket, &list); -return r; + goto error; } -ttm_eu_backoff_reservation (&ticket, &list); -return 0 ; +error: +drm_exec_fini (&exec); +return r; }int amdgpu_unmap_static_csa (struct amdgpu_device *adev,struct amdgpu_vm *vm,struct amdgpu_bo *bo,struct amdgpu_bo_va *bo_va,uint64_t csa_addr) { -struct ww_acquire_ctx ticket; -struct list_head list; -struct amdgpu_bo_list_entry pd; -struct ttm_validate_buffer csa_tv; +struct drm_exec exec;int r; -INIT_LIST_HEAD (&list); -INIT_LIST_HEAD (&csa_tv.head); - csa_tv.bo = &bo->tbo; - csa_tv.num_shared =1 ; - -list_add (&csa_tv.head, &list); -amdgpu_vm_get_pd_bo (vm, &list, &pd); - - r =ttm_eu_reserve_buffers (&ticket, &list, true,NULL ); -if (r) { -DRM_ERROR ("failed to reserve CSA,PD BOs: err=%d\n" , r); -return r; +drm_exec_init (&exec,DRM_EXEC_INTERRUPTIBLE_WAIT ); + drm_exec_until_all_locked(&exec) { + r =amdgpu_vm_lock_pd (vm, &exec,0 ); +if (likely (!r)) + r =drm_exec_lock_obj (&exec, &bo->tbo.base); +drm_exec_retry_on_contention (&exec); +if (unlikely (r)) { +DRM_ERROR ("failed to reserve CSA,PD BOs: err=%d\n" , r); + goto error; + } } r =amdgpu_vm_bo_unmap (adev, bo_va, csa_addr);if (r) {DRM_ERROR ("failed to do bo_unmap on static CSA, err=%d\n" , r); -ttm_eu_backoff_reservation (&ticket, &list); -return r; + goto error; }amdgpu_vm_bo_del (adev, bo_va); -ttm_eu_backoff_reservation (&ticket, &list); - -return 0 ; +error: +drm_exec_fini (&exec); +return r; }
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +37 -43
144 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 4/6] drm/amdgpu: use drm_exec for GEM and CSA handling
Quoted 19 lines · Christian König
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-5@@ -728,36 +723,37 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,return -EINVAL ; } -INIT_LIST_HEAD (&list); -INIT_LIST_HEAD (&duplicates);if ((args->operation !=AMDGPU_VA_OP_CLEAR ) && !(args->flags &AMDGPU_VM_PAGE_PRT )) { gobj =drm_gem_object_lookup (filp, args->handle);if (gobj ==NULL )return -ENOENT ; abo =gem_to_amdgpu_bo (gobj); - tv.bo = &abo->tbo; -if (abo->flags &AMDGPU_GEM_CREATE_VM_ALWAYS_VALID ) - tv.num_shared =1 ;
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, · line 737
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-4-else - tv.num_shared =0 ; -list_add (&tv.head, &list); }else { gobj =NULL ; abo =NULL ; } -amdgpu_vm_get_pd_bo (&fpriv->vm, &list, &vm_pd); +drm_exec_init (&exec,DRM_EXEC_INTERRUPTIBLE_WAIT );
Sorry, I missed this last time, but this needs to allow duplicates as well or mapping always_valid BOs doesn't work.
Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +15
-8+ drm_exec_until_all_locked(&exec) { +if (gobj) { + r =drm_exec_lock_obj (&exec, gobj); +drm_exec_retry_on_contention (&exec); +if (unlikely (r)) + goto error; + } - r =ttm_eu_reserve_buffers (&ticket, &list, true, &duplicates); -if (r) - goto error_unref; + r =amdgpu_vm_lock_pd (&fpriv->vm, &exec,2 ); +drm_exec_retry_on_contention (&exec); +if (unlikely (r)) + goto error; + }if (abo) { bo_va =amdgpu_vm_bo_find (&fpriv->vm, abo);if (!bo_va) { r = -ENOENT ; - goto error_backoff; + goto error; } }else if (args->operation !=AMDGPU_VA_OP_CLEAR ) { bo_va = fpriv->prt_va;@@ -794,10 +790,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,amdgpu_gem_va_update_vm (adev, &fpriv->vm, bo_va, args->operation); -error_backoff: -ttm_eu_backoff_reservation (&ticket, &list); - -error_unref: +error: +drm_exec_fini (&exec);drm_gem_object_put (gobj);return r; }
PATCH 5/6 drm/amdgpu: use drm_exec for MES testing
In reply to Christian KönigStart using the new component here as well.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 90 ++++++++++++------------- 1 file changed, 43 insertions(+), 47 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +43 -47
@@ -22,6 +22,7 @@*/ #include <linux/firmware.h> +#include <drm/drm_exec.h> #include "amdgpu_mes.h" #include "amdgpu.h"
@@ -1168,34 +1169,31 @@ int amdgpu_mes_ctx_map_meta_data(struct amdgpu_device *adev, struct amdgpu_mes_ctx_data *ctx_data) {struct amdgpu_bo_va *bo_va; -struct ww_acquire_ctx ticket; -struct list_head list; -struct amdgpu_bo_list_entry pd; -struct ttm_validate_buffer csa_tv;struct amdgpu_sync sync; +struct drm_exec exec;int r;amdgpu_sync_create (&sync); -INIT_LIST_HEAD (&list); -INIT_LIST_HEAD (&csa_tv.head); - csa_tv.bo = &ctx_data->meta_data_obj->tbo; - csa_tv.num_shared =1 ; - -list_add (&csa_tv.head, &list); -amdgpu_vm_get_pd_bo (vm, &list, &pd); - - r =ttm_eu_reserve_buffers (&ticket, &list, true,NULL ); -if (r) { -DRM_ERROR ("failed to reserve meta data BO: err=%d\n" , r); -return r; +drm_exec_init (&exec,0 ); + drm_exec_until_all_locked(&exec) { + r =drm_exec_lock_obj (&exec, + &ctx_data->meta_data_obj->tbo.base); +drm_exec_retry_on_contention (&exec); +if (unlikely (r)) + goto error_fini_exec; + + r =amdgpu_vm_lock_pd (vm, &exec,0 ); +drm_exec_retry_on_contention (&exec); +if (unlikely (r)) + goto error_fini_exec; } bo_va =amdgpu_vm_bo_add (adev, vm, ctx_data->meta_data_obj);if (!bo_va) { -ttm_eu_backoff_reservation (&ticket, &list);DRM_ERROR ("failed to create bo_va for meta data BO\n" ); -return -ENOMEM ; + r = -ENOMEM ; + goto error_fini_exec; } r = amdgpu_vm_bo_map(adev, bo_va, ctx_data->meta_data_gpu_addr, 0,
@@ -1205,33 +1203,35 @@ int amdgpu_mes_ctx_map_meta_data(struct amdgpu_device *adev,if (r) {DRM_ERROR ("failed to do bo_map on meta data, err=%d\n" , r); - goto error; + goto error_del_bo_va; } r =amdgpu_vm_bo_update (adev, bo_va, false);if (r) {DRM_ERROR ("failed to do vm_bo_update on meta data\n" ); - goto error; + goto error_del_bo_va; }amdgpu_sync_fence (&sync, bo_va->last_pt_update); r =amdgpu_vm_update_pdes (adev, vm, false);if (r) {DRM_ERROR ("failed to update pdes on meta data\n" ); - goto error; + goto error_del_bo_va; }amdgpu_sync_fence (&sync, vm->last_update);amdgpu_sync_wait (&sync, false); -ttm_eu_backoff_reservation (&ticket, &list); +drm_exec_fini (&exec);amdgpu_sync_free (&sync); ctx_data->meta_data_va = bo_va;return 0 ; -error: +error_del_bo_va:amdgpu_vm_bo_del (adev, bo_va); -ttm_eu_backoff_reservation (&ticket, &list); + +error_fini_exec: +drm_exec_fini (&exec);amdgpu_sync_free (&sync);return r; }
@@ -1242,34 +1242,30 @@ int amdgpu_mes_ctx_unmap_meta_data(struct amdgpu_device *adev,struct amdgpu_bo_va *bo_va = ctx_data->meta_data_va;struct amdgpu_bo *bo = ctx_data->meta_data_obj;struct amdgpu_vm *vm = bo_va->base.vm; -struct amdgpu_bo_list_entry vm_pd; -struct list_head list, duplicates; -struct dma_fence *fence =NULL ; -struct ttm_validate_buffer tv; -struct ww_acquire_ctx ticket; -long r =0 ; - -INIT_LIST_HEAD (&list); -INIT_LIST_HEAD (&duplicates); - - tv.bo = &bo->tbo; - tv.num_shared =2 ; -list_add (&tv.head, &list); - -amdgpu_vm_get_pd_bo (vm, &list, &vm_pd); - - r =ttm_eu_reserve_buffers (&ticket, &list, false, &duplicates); -if (r) { -dev_err (adev->dev,"leaking bo va because " -"we fail to reserve bo (%ld)\n" , r); -return r; +struct dma_fence *fence; +struct drm_exec exec; +long r; + +drm_exec_init (&exec,0 ); + drm_exec_until_all_locked(&exec) { + r =drm_exec_lock_obj (&exec, + &ctx_data->meta_data_obj->tbo.base); +drm_exec_retry_on_contention (&exec); +if (unlikely (r)) + goto out_unlock; + + r =amdgpu_vm_lock_pd (vm, &exec,0 ); +drm_exec_retry_on_contention (&exec); +if (unlikely (r)) + goto out_unlock; }amdgpu_vm_bo_del (adev, bo_va);if (!amdgpu_vm_ready (vm)) goto out_unlock; - r =dma_resv_get_singleton (bo->tbo.base.resv,DMA_RESV_USAGE_BOOKKEEP , &fence); + r =dma_resv_get_singleton (bo->tbo.base.resv,DMA_RESV_USAGE_BOOKKEEP , + &fence);if (r) goto out_unlock;if (fence) {
@@ -1288,7 +1284,7 @@ int amdgpu_mes_ctx_unmap_meta_data(struct amdgpu_device *adev, out_unlock:if (unlikely (r <0 ))dev_err (adev->dev,"failed to clear page tables (%ld)\n" , r); -ttm_eu_backoff_reservation (&ticket, &list); +drm_exec_fini (&exec);return r; }
Signature · 1 line
2.34.1
PATCH 6/6 drm/amdgpu: use the new drm_exec object for CS v2
In reply to Christian KönigUse the new component here as well and remove the old handling.
v2: drop dupplicate handling
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 - drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 71 ++----- drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h | 5 +- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 211 +++++++++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.h | 7 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 22 -- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 3 - 7 files changed, 116 insertions(+), 204 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -1
@@ -53,7 +53,6 @@#include <drm/ttm/ttm_bo.h> #include <drm/ttm/ttm_placement.h> -#include <drm/ttm/ttm_execbuf_util.h> #include <drm/amdgpu_drm.h> #include <drm/drm_gem.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +20 -51
109 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h +1 -4
@@ -23,7 +23,6 @@#ifndef __AMDGPU_BO_LIST_H__#define __AMDGPU_BO_LIST_H__ -#include <drm/ttm/ttm_execbuf_util.h> #include <drm/amdgpu_drm.h> struct hmm_range ;
@@ -36,7 +35,7 @@ struct amdgpu_bo_va;struct amdgpu_fpriv ;struct amdgpu_bo_list_entry { -struct ttm_validate_buffer tv; +struct amdgpu_bo *bo;struct amdgpu_bo_va *bo_va;uint32_t priority;struct page **user_pages;
@@ -60,8 +59,6 @@ struct amdgpu_bo_list {int amdgpu_bo_list_get (struct amdgpu_fpriv *fpriv,int id,struct amdgpu_bo_list **result); -void amdgpu_bo_list_get_list (struct amdgpu_bo_list *list, -struct list_head *validated);void amdgpu_bo_list_put (struct amdgpu_bo_list *list);int amdgpu_bo_create_list_entry_array (struct drm_amdgpu_bo_list_in *in,struct drm_amdgpu_bo_list_entry **info_param);
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +92 -119
403 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.h +3 -4
@@ -24,6 +24,7 @@#define __AMDGPU_CS_H__#include <linux/ww_mutex.h> +#include <drm/drm_exec.h> #include "amdgpu_job.h" #include "amdgpu_bo_list.h"
@@ -62,11 +63,9 @@ struct amdgpu_cs_parser {struct amdgpu_job *gang_leader;/* buffer objects */ -struct ww_acquire_ctx ticket; +struct drm_exec exec;struct amdgpu_bo_list *bo_list;struct amdgpu_mn *mn; -struct amdgpu_bo_list_entry vm_pd; -struct list_head validated;struct dma_fence *fence;uint64_t bytes_moved_threshold;uint64_t bytes_moved_vis_threshold;
@@ -74,7 +73,7 @@ struct amdgpu_cs_parser {uint64_t bytes_moved_vis;/* user fence */ -struct amdgpu_bo_list_entry uf_entry; +struct amdgpu_bo *uf_bo;unsigned num_post_deps;struct amdgpu_cs_post_dep *post_deps;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -22
@@ -339,28 +339,6 @@ void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base,amdgpu_vm_bo_evicted (base); } -/** -* amdgpu_vm_get_pd_bo - add the VM PD to a validation list -* -* @vm: vm providing the BOs -* @validated: head of validation list -* @entry: entry to add -* -* Add the page directory to the list of BOs to -* validate for command submission. -*/ -void amdgpu_vm_get_pd_bo (struct amdgpu_vm *vm, -struct list_head *validated, -struct amdgpu_bo_list_entry *entry) -{ - entry->priority =0 ; - entry->tv.bo = &vm->root.bo->tbo; -/* Two for VM updates, one for TTM and one for the CS job */ - entry->tv.num_shared =4 ; - entry->user_pages =NULL ; -list_add (&entry->tv.head, validated); -} -/** * amdgpu_vm_lock_pd - lock PD in drm_exec *
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -3
@@ -398,9 +398,6 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);int amdgpu_vm_make_compute (struct amdgpu_device *adev,struct amdgpu_vm *vm);void amdgpu_vm_release_compute (struct amdgpu_device *adev,struct amdgpu_vm *vm);void amdgpu_vm_fini (struct amdgpu_device *adev,struct amdgpu_vm *vm); -void amdgpu_vm_get_pd_bo (struct amdgpu_vm *vm, -struct list_head *validated, -struct amdgpu_bo_list_entry *entry);int amdgpu_vm_lock_pd (struct amdgpu_vm *vm,struct drm_exec *exec,unsigned int num_fences);bool amdgpu_vm_ready (struct amdgpu_vm *vm);
Signature · 1 line
2.34.1
Re: [PATCH 6/6] drm/amdgpu: use the new drm_exec object for CS v2
Quoted 16 lines · Christian König
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +6
-6@@ -958,18 +904,57 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, e->user_invalidated = userpage_invalidated; } - r =ttm_eu_reserve_buffers (&p->ticket, &p->validated, true, - &duplicates); -if (unlikely (r !=0 )) { -if (r != -ERESTARTSYS ) -DRM_ERROR ("ttm_eu_reserve_buffers failed.\n" ); - goto out_free_user_pages; + drm_exec_until_all_locked(&p->exec) { + r =amdgpu_vm_lock_pd (&fpriv->vm, &p->exec,1 + p->gang_size); +drm_exec_retry_on_contention (&p->exec); +if (unlikely (r)) + goto out_free_user_pages; +
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, · line 922
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +10
-0+amdgpu_bo_list_for_each_entry (e, p->bo_list) { +/* One fence for TTM and one for each CS job */ + r =drm_exec_prepare_obj (&p->exec, &e->bo->tbo.base, +1 + p->gang_size); +drm_exec_retry_on_contention (&p->exec); +if (unlikely (r)) + goto out_free_user_pages; + + e->bo_va =amdgpu_vm_bo_find (vm, e->bo); + e->range =NULL ;
Still leaking.
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +9
-0+ } + +if (p->uf_bo) { + r =drm_exec_prepare_obj (&p->exec, &p->uf_bo->tbo.base, +1 + p->gang_size); +drm_exec_retry_on_contention (&p->exec); +if (unlikely (r)) + goto out_free_user_pages; + } }
Re: [PATCH 6/6] drm/amdgpu: use the new drm_exec object for CS v2
Am 29.06.23 um 10:20 schrieb Tatsuyuki Ishi:
Quoted 20 lines · Christian König
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +9
-5@@ -958,18 +904,57 @@ static int amdgpu_cs_parser_bos(structamdgpu_cs_parser *p, e->user_invalidated = userpage_invalidated; } - r = ttm_eu_reserve_buffers(&p->ticket, &p->validated, true, - &duplicates); - if (unlikely(r != 0)) { - if (r != -ERESTARTSYS) - DRM_ERROR("ttm_eu_reserve_buffers failed.\n"); - goto out_free_user_pages; + drm_exec_until_all_locked(&p->exec) { + r = amdgpu_vm_lock_pd(&fpriv->vm, &p->exec, 1 + p->gang_size); + drm_exec_retry_on_contention(&p->exec); + if (unlikely(r)) + goto out_free_user_pages; + + amdgpu_bo_list_for_each_entry(e, p->bo_list) { + /* One fence for TTM and one for each CS job */ + r = drm_exec_prepare_obj(&p->exec, &e->bo->tbo.base,
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, · line 922
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +7
-0+ 1 + p->gang_size); + drm_exec_retry_on_contention(&p->exec); + if (unlikely(r)) + goto out_free_user_pages; + + e->bo_va = amdgpu_vm_bo_find(vm, e->bo); + e->range = NULL;Still leaking.
Scratching my head, I though I fixed this.
Thanks for pointing this out,
Christian.
Quoted 11 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +9
-0+ } + + if (p->uf_bo) { + r = drm_exec_prepare_obj(&p->exec, &p->uf_bo->tbo.base, + 1 + p->gang_size); + drm_exec_retry_on_contention(&p->exec); + if (unlikely(r)) + goto out_free_user_pages; + } }