drm/amdgpu: add gfx eviction fence helpers
Subsystems (2)
PATCH 1/1 drm/amdgpu: add gfx eviction fence helpers
This patch adds basic eviction fence framework for the gfx buffers. The idea is to:
- One eviction fence is created per gfx process, at kms_open.
- This same fence is attached to all the gem buffers created by this process.
This framework will be further used for usermode queues.
Cc Christian Koenig <[email protected]>
Cc Alex Deucher <[email protected]>
Signed-off-by Shashank Sharma <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/Makefile | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 15 +++ .../drm/amd/amdgpu/amdgpu_eviction_fence.c | 96 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 10 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 2 + 6 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c
drivers/gpu/drm/amd/amdgpu/Makefile +2 -1
@@ -80,7 +80,8 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o amdgpu_kms.o \ amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \ amdgpu_fw_attestation.o amdgpu_securedisplay.o \ amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \ - amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o + amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o \ + amdgpu_eviction_fence.o amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o
drivers/gpu/drm/amd/amdgpu/amdgpu.h +15 -0
@@ -463,6 +463,13 @@ struct amdgpu_flip_work {bool async; }; +struct amdgpu_eviction_fence { +u64 fence_ctx; +atomic_t seq; +spinlock_t lock; +struct dma_fence base; +char timeline_name[TASK_COMM_LEN ]; +};/* * file private structure
@@ -476,6 +483,7 @@ struct amdgpu_fpriv {struct mutex bo_list_lock;struct idr bo_list_handles;struct amdgpu_ctx_mgr ctx_mgr; +struct amdgpu_eviction_fence eviction_fence;/** GPU partition selection */ uint32_t xcp_id; };
@@ -1474,6 +1482,13 @@ void amdgpu_disable_vblank_kms(struct drm_crtc *crtc);int amdgpu_info_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +/* Eviction fence */ +void amdgpu_eviction_fence_create (struct amdgpu_fpriv *fpriv); +int amdgpu_eviction_fence_attach (struct amdgpu_fpriv *fpriv, +struct amdgpu_bo *bo); +void amdgpu_eviction_fence_detach (struct amdgpu_fpriv *fpriv); +void amdgpu_eviction_fence_signal (struct amdgpu_fpriv *fpriv); +/* * functions used by amdgpu_encoder.c */
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c new file +96 -0
96 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +9 -1
@@ -199,8 +199,14 @@ static int amdgpu_gem_object_open(struct drm_gem_object *obj,* but not for export, this is a different lock class that cannot lead to * circular lock dependencies. */ -if (!vm->is_compute_context || !vm->process_info) +if (!vm->is_compute_context || !vm->process_info) { +/* attach gfx eviction fence */ +if (amdgpu_eviction_fence_attach (fpriv, abo)) +DRM_DEBUG_DRIVER ("Failed to attach eviction fence to BO\n" ); +return 0 ; + } +if (!obj->import_attach || !dma_buf_is_dynamic (obj->import_attach->dmabuf))return 0 ;
@@ -236,6 +242,8 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,struct drm_exec exec;long r; +amdgpu_eviction_fence_detach (fpriv); +drm_exec_init (&exec,DRM_EXEC_IGNORE_DUPLICATES ,0 ); drm_exec_until_all_locked(&exec) { r =drm_exec_prepare_obj (&exec, &bo->tbo.base,1 );
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3 -1
@@ -1293,7 +1293,6 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)return 0 ; } -/* * Outdated mess for old drm with Xorg being in charge (void function now). */
@@ -1386,6 +1385,8 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)mutex_init (&fpriv->bo_list_lock);idr_init_base (&fpriv->bo_list_handles,1 ); +amdgpu_eviction_fence_create (fpriv); +amdgpu_ctx_mgr_init (&fpriv->ctx_mgr, adev); file_priv->driver_priv = fpriv;
@@ -1455,6 +1456,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,amdgpu_bo_unreserve (pd); } +amdgpu_eviction_fence_signal (fpriv);amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr);amdgpu_vm_fini (adev, &fpriv->vm);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2 -0
@@ -105,6 +105,8 @@ struct amdgpu_bo {struct amdgpu_vm_bo_base *vm_bo;/* Constant after initialization */ struct amdgpu_bo *parent; +/* Eviction fence attached to bo */ +struct dma_fence *eviction_fence;#ifdef CONFIG_MMU_NOTIFIER struct mmu_interval_notifier notifier;
Signature · 1 line
2.43.2