Skip to contentSkip to conversation

drm/amdgpu: Explicit sync for GEM VA operations

PATCH In review Friedrich Vock 4 participants 10 messages Aug 19, 2024 – Feb 6, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover drm/amdgpu: Explicit sync for GEM VA operations

In Vulkan, it is the application's responsibility to perform adequate synchronization before a sparse unmap, replace or BO destroy operation. This adds an option to AMDGPU_VA_OPs to disable redundant implicit sync that happens on sparse unmap or replace operations.

This has seen a significant improvement in stutter in Forza Horizon 5 and Forza Horizon 4. (As games that had significant issues in sparse binding related stutter).

Userspace changes for this new version can be found at [1][2], and a kernel branch containing these patches can be found at [3].

[1] https://gitlab.freedesktop.org/pixelcluster/drm/-/commits/vm-explicit-sync
[2] https://gitlab.freedesktop.org/pixelcluster/mesa/-/commits/vm-explicit-sync
[3] https://gitlab.freedesktop.org/pixelcluster/linux/-/commits/amdgpu-vm-explicit-sync

v3 changes:
- Rebased onto current amd-staging-drm-next
- Added option to wait for drm_syncobjs instead of executing immediately

Tatsuyuki Ishi (3):
drm/amdgpu: Don't implicit sync PRT maps.
drm/amdgpu: Add optional explicit sync fences for GEM operations. drm/amdgpu: Bump amdgpu driver version.

 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c       |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       | 76 ++++++++++++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h    | 23 +++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h     |  6 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_umsch_mm.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 68 +++++++++++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        | 30 ++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c    | 12 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c     |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c   |  9 +++
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c          | 18 ++---
 include/uapi/drm/amdgpu_drm.h                 |  7 ++
 14 files changed, 194 insertions(+), 66 deletions(-)

--
2.46.0

#1 lore raw

PATCH v3 1/3 drm/amdgpu: Don't implicit sync PRT maps.

From: Tatsuyuki Ishi <[email protected]>

These are considered map operations rather than unmap, and there is no point of doing implicit synchronization here.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
index bcb729094521..a4fc24dff04d 100644
@@ -994,7 +994,7 @@ int amdgpu_vm_update_range(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	/* Implicitly sync to command submissions in the same VM before
 	 * unmapping. Sync to moving fences before mapping.
 	 */
-	if (!(flags & AMDGPU_PTE_VALID))
+	if (!(flags & (AMDGPU_PTE_VALID | AMDGPU_PTE_PRT)))
 		sync_mode = AMDGPU_SYNC_EQ_OWNER;
 	else
 		sync_mode = AMDGPU_SYNC_EXPLICIT;

--
2.46.0

#2 lore raw

PATCH v3 2/3 drm/amdgpu: Add optional explicit sync fences for GEM operations.

In reply to Friedrich Vock

From: Tatsuyuki Ishi <[email protected]>

In Vulkan, it is the application's responsibility to perform adequate synchronization before a sparse unmap, replace or BO destroy operation. Until now, the kernel applied the same rule as implicitly-synchronized APIs like OpenGL, which with per-VM BOs made page table updates stall the queue completely. The newly added AMDGPU_VM_EXPLICIT_SYNC flag allows drivers to opt-out of this behavior, while still ensuring adequate implicit sync happens for kernel-initiated updates (e.g. BO moves).

When using explicit sync, we record a set of fences to explicitly wait for in each mapping. To avoid increasing the mapping struct's size, this is union-ized with the interval tree field which is unused after the unmap.

The reason this is done with a GEM ioctl flag, instead of being a VM / context global setting, is that the current libdrm implementation shares the DRM handle even between different kind of drivers (radeonsi vs radv).

---
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c       |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       | 76 ++++++++++++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h    | 23 +++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h     |  6 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_umsch_mm.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 68 +++++++++++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        | 30 ++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c    | 12 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c     |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c   |  9 +++
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c          | 18 ++---
 include/uapi/drm/amdgpu_drm.h                 | 11 +++
 13 files changed, 196 insertions(+), 65 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -1
index 6d5fd371d5ce..543396b52ebb 100644
@@ -1265,7 +1265,7 @@ static int unmap_bo_from_gpuvm(struct kgd_mem *mem,
 		return -EBUSY;
 	}
 
-	amdgpu_vm_bo_unmap(adev, bo_va, entry->va);
+	amdgpu_vm_bo_unmap(adev, bo_va, entry->va, NULL);
 
 	amdgpu_vm_clear_freed(adev, vm, &bo_va->last_pt_update);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c +1 -1
index cfdf558b48b6..9cba44ecde90 100644
@@ -121,7 +121,7 @@ int amdgpu_unmap_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		}
 	}
 
-	r = amdgpu_vm_bo_unmap(adev, bo_va, csa_addr);
+	r = amdgpu_vm_bo_unmap(adev, bo_va, csa_addr, NULL);
 	if (r) {
 		DRM_ERROR("failed to do bo_unmap on static CSA, err=%d\n", r);
 		goto error;
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +64 -12

148 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +22 -1
index d7e27957013f..cef3b2937ec3 100644
@@ -60,6 +60,12 @@ struct amdgpu_bo_param {
 	int8_t				xcp_id_plus1;
 };
 
+struct amdgpu_bo_unmap_sync {
+	struct kref ref;
+	uint64_t wait_fence_count;
+	struct dma_fence *wait_fences[];
+};
+
 /* bo virtual addresses in a vm */
 struct amdgpu_bo_va_mapping {
 	struct amdgpu_bo_va		*bo_va;
@@ -67,7 +73,15 @@ struct amdgpu_bo_va_mapping {
 	struct rb_node			rb;
 	uint64_t			start;
 	uint64_t			last;
-	uint64_t			__subtree_last;
+	union {
+		uint64_t __subtree_last;
+		/* For freed mappings only: Optional
+		 * set of dma_fences to wait on before freeing the
+		 * mapping. If NULL, the fences from the
+		 * BO's resv object are used instead.
+		 */
+		struct amdgpu_bo_unmap_sync *unmap_sync;
+	};
 	uint64_t			offset;
 	uint64_t			flags;
 };
@@ -168,6 +182,13 @@ struct amdgpu_mem_stats {
 	uint64_t requested_gtt;
 };
 
+static inline void amdgpu_bo_unmap_sync_destroy(struct kref *ref)
+{
+	struct amdgpu_bo_unmap_sync *sync =
+		container_of(ref, struct amdgpu_bo_unmap_sync, ref);
+	kfree(sync);
+}
+
 static inline struct amdgpu_bo *ttm_to_amdgpu_bo(struct ttm_buffer_object *tbo)
 {
 	return container_of(tbo, struct amdgpu_bo, tbo);
drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +4 -2
index 2fd1bfb35916..152125976c97 100644
@@ -276,6 +276,7 @@ TRACE_EVENT(amdgpu_vm_bo_unmap,
 			     __field(long, last)
 			     __field(u64, offset)
 			     __field(u64, flags)
+			     __field(bool, explicit_sync)
 			     ),
 
 	    TP_fast_assign(
@@ -284,10 +285,11 @@ TRACE_EVENT(amdgpu_vm_bo_unmap,
 			   __entry->last = mapping->last;
 			   __entry->offset = mapping->offset;
 			   __entry->flags = mapping->flags;
+			   __entry->explicit_sync = !!mapping->unmap_sync;
 			   ),
-	    TP_printk("bo=%p, start=%lx, last=%lx, offset=%010llx, flags=%llx",
+	    TP_printk("bo=%p, start=%lx, last=%lx, offset=%010llx, flags=%llx, explicit_sync=%d",
 		      __entry->bo, __entry->start, __entry->last,
-		      __entry->offset, __entry->flags)
+		      __entry->offset, __entry->flags, __entry->explicit_sync)
 );
 
 DECLARE_EVENT_CLASS(amdgpu_vm_mapping,
drivers/gpu/drm/amd/amdgpu/amdgpu_umsch_mm.c +1 -1
index 6162582d0aa2..3def5b0aee35 100644
@@ -166,7 +166,7 @@ static int unmap_ring_data(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	}
 
 
-	r = amdgpu_vm_bo_unmap(adev, bo_va, addr);
+	r = amdgpu_vm_bo_unmap(adev, bo_va, addr, NULL);
 	if (r)
 		goto out_unlock;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +46 -22

193 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +16 -14
index 046949c4b695..3cd9eab9e57a 100644
@@ -43,6 +43,7 @@ struct amdgpu_job;
 struct amdgpu_bo_list_entry;
 struct amdgpu_bo_vm;
 struct amdgpu_mem_stats;
+struct amdgpu_bo_unmap_sync;
 
 /*
  * GPUVM handling
@@ -304,7 +305,8 @@ struct amdgpu_vm_update_params {
 
 struct amdgpu_vm_update_funcs {
 	int (*map_table)(struct amdgpu_bo_vm *bo);
-	int (*prepare)(struct amdgpu_vm_update_params *p, struct dma_resv *resv,
+	int (*prepare)(struct amdgpu_vm_update_params *p,
+		       struct amdgpu_bo_unmap_sync *sync, struct dma_resv *resv,
 		       enum amdgpu_sync_mode sync_mode);
 	int (*update)(struct amdgpu_vm_update_params *p,
 		      struct amdgpu_bo_vm *bo, uint64_t pe, uint64_t addr,
@@ -505,13 +507,14 @@ int amdgpu_vm_flush_compute_tlb(struct amdgpu_device *adev,
 void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base,
 			    struct amdgpu_vm *vm, struct amdgpu_bo *bo);
 int amdgpu_vm_update_range(struct amdgpu_device *adev, struct amdgpu_vm *vm,
-			   bool immediate, bool unlocked, bool flush_tlb, bool allow_override,
-			   struct dma_resv *resv, uint64_t start, uint64_t last,
-			   uint64_t flags, uint64_t offset, uint64_t vram_base,
+			   bool immediate, bool unlocked, bool flush_tlb,
+			   bool allow_override,
+			   struct amdgpu_bo_unmap_sync *sync, struct dma_resv *resv,
+			   uint64_t start, uint64_t last, uint64_t flags,
+			   uint64_t offset, uint64_t vram_base,
 			   struct ttm_resource *res, dma_addr_t *pages_addr,
 			   struct dma_fence **fence);
-int amdgpu_vm_bo_update(struct amdgpu_device *adev,
-			struct amdgpu_bo_va *bo_va,
+int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
 			bool clear);
 bool amdgpu_vm_evictable(struct amdgpu_bo *bo);
 void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
@@ -527,15 +530,14 @@ int amdgpu_vm_bo_map(struct amdgpu_device *adev,
 		     uint64_t addr, uint64_t offset,
 		     uint64_t size, uint64_t flags);
 int amdgpu_vm_bo_replace_map(struct amdgpu_device *adev,
-			     struct amdgpu_bo_va *bo_va,
-			     uint64_t addr, uint64_t offset,
-			     uint64_t size, uint64_t flags);
-int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
-		       struct amdgpu_bo_va *bo_va,
-		       uint64_t addr);
+			     struct amdgpu_bo_va *bo_va, uint64_t addr,
+			     uint64_t offset, uint64_t size, uint64_t flags,
+			     struct amdgpu_bo_unmap_sync *sync);
+int amdgpu_vm_bo_unmap(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
+		       uint64_t addr, struct amdgpu_bo_unmap_sync *sync);
 int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,
-				struct amdgpu_vm *vm,
-				uint64_t saddr, uint64_t size);
+				struct amdgpu_vm *vm, uint64_t saddr,
+				uint64_t size, struct amdgpu_bo_unmap_sync *sync);
 struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm,
 							 uint64_t addr);
 void amdgpu_vm_bo_trace_cs(struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c +11 -1
index 3895bd7d176a..d97d6ab29c5f 100644
@@ -46,12 +46,22 @@ static int amdgpu_vm_cpu_map_table(struct amdgpu_bo_vm *table)
  * Negativ errno, 0 for success.
  */
 static int amdgpu_vm_cpu_prepare(struct amdgpu_vm_update_params *p,
+				 struct amdgpu_bo_unmap_sync *sync,
 				 struct dma_resv *resv,
 				 enum amdgpu_sync_mode sync_mode)
 {
-	if (!resv)
+	uint64_t i;
+	int r;
+
+	if (!sync && !resv)
 		return 0;
 
+	for (i = 0; sync && i < sync->wait_fence_count; ++i) {
+		r = dma_fence_wait(sync->wait_fences[i], false);
+		if (r)
+			return r;
+	}
+
 	return amdgpu_bo_sync_wait_resv(p->adev, resv, sync_mode, p->vm, true);
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +1 -1
index e39d6e7643bf..715c78e9b9bb 100644
@@ -403,7 +403,7 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	params.vm = vm;
 	params.immediate = immediate;
 
-	r = vm->update_funcs->prepare(&params, NULL, AMDGPU_SYNC_EXPLICIT);
+	r = vm->update_funcs->prepare(&params, NULL, NULL, AMDGPU_SYNC_EXPLICIT);
 	if (r)
 		goto exit;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +9 -0
index 9b748d7058b5..1d2ba17457ea 100644
@@ -84,10 +84,12 @@ static int amdgpu_vm_sdma_alloc_job(struct amdgpu_vm_update_params *p,
  * Negativ errno, 0 for success.
  */
 static int amdgpu_vm_sdma_prepare(struct amdgpu_vm_update_params *p,
+				  struct amdgpu_bo_unmap_sync *unmap_sync,
 				  struct dma_resv *resv,
 				  enum amdgpu_sync_mode sync_mode)
 {
 	struct amdgpu_sync sync;
+	uint64_t i;
 	int r;
 
 	r = amdgpu_vm_sdma_alloc_job(p, 0);
@@ -98,6 +100,13 @@ static int amdgpu_vm_sdma_prepare(struct amdgpu_vm_update_params *p,
 		return 0;
 
 	amdgpu_sync_create(&sync);
+
+	for (i = 0; unmap_sync && i < unmap_sync->wait_fence_count; ++i) {
+		r = amdgpu_sync_fence(&sync, unmap_sync->wait_fences[i]);
+		if (r)
+			return r;
+	}
+
 	r = amdgpu_sync_resv(p->adev, &sync, resv, sync_mode, p->vm);
 	if (!r)
 		r = amdgpu_sync_push_to_job(&sync, p->job);
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +9 -9
index 10b1a1f64198..09f9e310e838 100644
@@ -1282,9 +1282,9 @@ svm_range_unmap_from_gpu(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 
 	pr_debug("[0x%llx 0x%llx]\n", start, last);
 
-	return amdgpu_vm_update_range(adev, vm, false, true, true, false, NULL, start,
-				      last, init_pte_value, 0, 0, NULL, NULL,
-				      fence);
+	return amdgpu_vm_update_range(adev, vm, false, true, true, false, NULL,
+				      NULL, start, last, init_pte_value, 0, 0,
+				      NULL, NULL, fence);
 }
 
 static int
@@ -1389,12 +1389,12 @@ svm_range_map_to_gpu(struct kfd_process_device *pdd, struct svm_range *prange,
 		 * different memory partition based on fpfn/lpfn, we should use
 		 * same vm_manager.vram_base_offset regardless memory partition.
 		 */
-		r = amdgpu_vm_update_range(adev, vm, false, false, flush_tlb, true,
-					   NULL, last_start, prange->start + i,
-					   pte_flags,
-					   (last_start - prange->start) << PAGE_SHIFT,
-					   bo_adev ? bo_adev->vm_manager.vram_base_offset : 0,
-					   NULL, dma_addr, &vm->last_update);
+		r = amdgpu_vm_update_range(
+			adev, vm, false, false, flush_tlb, true, NULL, NULL,
+			last_start, prange->start + i, pte_flags,
+			(last_start - prange->start) << PAGE_SHIFT,
+			bo_adev ? bo_adev->vm_manager.vram_base_offset : 0,
+			NULL, dma_addr, &vm->last_update);
 
 		for (j = last_start - prange->start; j <= i; j++)
 			dma_addr[j] |= last_domain;
include/uapi/drm/amdgpu_drm.h +11 -0
index 3e488b0119eb..720f6784cb8b 100644
@@ -577,6 +577,8 @@ struct drm_amdgpu_gem_op {
 #define AMDGPU_VM_MTYPE_RW		(5 << 5)
 /* don't allocate MALL */
 #define AMDGPU_VM_PAGE_NOALLOC		(1 << 9)
+/* use explicit sync fences instead of implicitly syncing */
+#define AMDGPU_VM_EXPLICIT_SYNC		(1 << 10)
 
 struct drm_amdgpu_gem_va {
 	/** GEM object handle */
@@ -592,6 +594,15 @@ struct drm_amdgpu_gem_va {
 	__u64 offset_in_bo;
 	/** Specify mapping size. Must be correctly aligned. */
 	__u64 map_size;
+	/**
+	 * Number of explicit-sync syncobjs. Ignored if flags does not include
+	 * AMDGPU_VM_EXPLICIT_SYNC.
+	 */
+	__u64 syncobj_count;
+	/** Pointer to an array of syncobj_count timeline points for each syncobj. */
+	__u64 sync_points;
+	/** Pointer to an array of DRM syncobj handles to explicitly wait for.. */
+	__u64 syncobjs;
 };
 
 #define AMDGPU_HW_IP_GFX          0

--
2.46.0

#3 lore raw

PATCH v3 3/3 drm/amdgpu: Bump amdgpu driver version.

In reply to Friedrich Vock

From: Tatsuyuki Ishi <[email protected]>

For detection of the new explicit sync functionality without having to try the ioctl.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
index b9529948f2b2..7fdd73be0a87 100644
@@ -118,9 +118,10 @@
  * - 3.57.0 - Compute tunneling on GFX10+
  * - 3.58.0 - Add GFX12 DCC support
  * - 3.59.0 - Add AMDGPU_IDS_FLAGS_MODE_PF, AMDGPU_IDS_FLAGS_MODE_VF & AMDGPU_IDS_FLAGS_MODE_PT
+ * - 3.60.0 - Add AMDGPU_VM_EXPLICIT_SYNC flag for GEM operations.
  */
 #define KMS_DRIVER_MAJOR	3
-#define KMS_DRIVER_MINOR	59
+#define KMS_DRIVER_MINOR	60
 #define KMS_DRIVER_PATCHLEVEL	0
 
 /*

--
2.46.0

maintainer
#4 lore raw
In reply to Friedrich Vock

Am 19.08.24 um 09:21 schrieb Friedrich Vock:

Quoted 8 lines

In Vulkan, it is the application's responsibility to perform adequate synchronization before a sparse unmap, replace or BO destroy operation. This adds an option to AMDGPU_VA_OPs to disable redundant implicit sync that happens on sparse unmap or replace operations.

This has seen a significant improvement in stutter in Forza Horizon 5 and Forza Horizon 4. (As games that had significant issues in sparse binding related stutter).

Looks pretty good, I have Shashank and his team working on the similar patches ever since Bas initially came up with it since we need it for user queues as well.

Shashank can you take a look at the UAPI? Of hand looks pretty similar to what we have done as well, doesn't it?

For the internal implementation in the VM I'm currently working on a bug fix for the KFD team, so this is subject to change anyway. Going to keep this requirement here in mind while doing that, whatever implementation we end up with we probably need to re-base it anyway.

Regards,
Christian.

Quoted 36 lines

Userspace changes for this new version can be found at [1][2], and a kernel branch containing these patches can be found at [3].

[1] https://gitlab.freedesktop.org/pixelcluster/drm/-/commits/vm-explicit-sync
[2] https://gitlab.freedesktop.org/pixelcluster/mesa/-/commits/vm-explicit-sync
[3] https://gitlab.freedesktop.org/pixelcluster/linux/-/commits/amdgpu-vm-explicit-sync

v3 changes:
- Rebased onto current amd-staging-drm-next
- Added option to wait for drm_syncobjs instead of executing immediately

Tatsuyuki Ishi (3):
drm/amdgpu: Don't implicit sync PRT maps.
drm/amdgpu: Add optional explicit sync fences for GEM operations. drm/amdgpu: Bump amdgpu driver version.

  .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c       |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  3 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       | 76 ++++++++++++++++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h    | 23 +++++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h     |  6 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_umsch_mm.c  |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 68 +++++++++++------
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        | 30 ++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c    | 12 ++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c     |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c   |  9 +++
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c          | 18 ++---
  include/uapi/drm/amdgpu_drm.h                 |  7 ++
  14 files changed, 194 insertions(+), 66 deletions(-)

--
2.46.0

#5 lore raw

Hey Christian,

Quoted 6 lines · Christian König

Am 19.08.24 um 09:21 schrieb Friedrich Vock:

Quoted 5 lines

In Vulkan, it is the application's responsibility to perform adequate synchronization before a sparse unmap, replace or BO destroy operation. This adds an option to AMDGPU_VA_OPs to disable redundant implicit sync that happens on sparse unmap or replace operations.

Quoted 8 lines
Quoted 3 lines

This has seen a significant improvement in stutter in Forza Horizon 5 and Forza Horizon 4. (As games that had significant issues in sparse binding related stutter).

Looks pretty good, I have Shashank and his team working on the similar patches ever since Bas initially came up with it since we need it for user queues as well.

Shashank can you take a look at the UAPI? Of hand looks pretty similar to what we have done as well, doesn't it?

I had a quick look and yes it does look very similar to what we have done in VM_IOCTL for UQ BO sync.

- Shashank

Quoted 42 lines

For the internal implementation in the VM I'm currently working on a bug fix for the KFD team, so this is subject to change anyway. Going to keep this requirement here in mind while doing that, whatever implementation we end up with we probably need to re-base it anyway.

Regards,
Christian.

Quoted 36 lines

Userspace changes for this new version can be found at [1][2], and a kernel branch containing these patches can be found at [3].

[1] https://gitlab.freedesktop.org/pixelcluster/drm/-/commits/vm-explicit-sync
[2] https://gitlab.freedesktop.org/pixelcluster/mesa/-/commits/vm-explicit-sync
[3] https://gitlab.freedesktop.org/pixelcluster/linux/-/commits/amdgpu-vm-explicit-sync

v3 changes:
- Rebased onto current amd-staging-drm-next
- Added option to wait for drm_syncobjs instead of executing immediately

Tatsuyuki Ishi (3):
   drm/amdgpu: Don't implicit sync PRT maps.
   drm/amdgpu: Add optional explicit sync fences for GEM operations. drm/amdgpu: Bump amdgpu driver version.

  .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  2 +-

  drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c       |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  3 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       | 76 ++++++++++++++++---

  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h    | 23 +++++- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h     |  6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_umsch_mm.c  |  2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 68 +++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        | 30 ++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c    | 12 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c     |  2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c   |  9 +++ drivers/gpu/drm/amd/amdkfd/kfd_svm.c          | 18 ++--- include/uapi/drm/amdgpu_drm.h                 |  7 ++

  14 files changed, 194 insertions(+), 66 deletions(-)
Signature · 1 line
2.46.0
#6 lore raw
In reply to Christian König

Hi,

Quoted 14 lines · Christian König

Am 19.08.24 um 09:21 schrieb Friedrich Vock:

Quoted 8 lines

In Vulkan, it is the application's responsibility to perform adequate synchronization before a sparse unmap, replace or BO destroy operation. This adds an option to AMDGPU_VA_OPs to disable redundant implicit sync that happens on sparse unmap or replace operations.

This has seen a significant improvement in stutter in Forza Horizon 5 and Forza Horizon 4. (As games that had significant issues in sparse binding related stutter).

Looks pretty good, I have Shashank and his team working on the similar patches ever since Bas initially came up with it since we need it for user queues as well.

Quoted 7 lines

Shashank can you take a look at the UAPI? Of hand looks pretty similar to what we have done as well, doesn't it?

For the internal implementation in the VM I'm currently working on a bug fix for the KFD team, so this is subject to change anyway. Going to keep this requirement here in mind while doing that, whatever implementation we end up with we probably need to re-base it anyway.

Bumping this again - it's been quite a while, what became of that KFD bugfix and the userqueue stuff? It'd be nice to finally make progress here, whether it's using the user queue interface you worked on or a re-spin of this. Maybe it's possible to split this off from the rest of the userqueue stuff and merge it beforehand if you're reasonably certain about how the uapi should look? Let me know.

Thanks,
Friedrich

Quoted 44 lines

Regards,
Christian.

Quoted 40 lines

Userspace changes for this new version can be found at [1][2], and a kernel
branch containing these patches can be found at [3].

[1] https://gitlab.freedesktop.org/pixelcluster/drm/-/commits/vm-
explicit-sync
[2] https://gitlab.freedesktop.org/pixelcluster/mesa/-/commits/vm-
explicit-sync
[3] https://gitlab.freedesktop.org/pixelcluster/linux/-/commits/
amdgpu-vm-explicit-sync

v3 changes:
- Rebased onto current amd-staging-drm-next
- Added option to wait for drm_syncobjs instead of executing immediately

Tatsuyuki Ishi (3):
   drm/amdgpu: Don't implicit sync PRT maps.
   drm/amdgpu: Add optional explicit sync fences for GEM operations. drm/amdgpu: Bump amdgpu driver version.

  .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  2 +-

  drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c       |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  3 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       | 76 ++++++++++++++++---

  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h    | 23 +++++- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h     |  6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_umsch_mm.c  |  2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 68 +++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        | 30 ++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c    | 12 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c     |  2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c   |  9 +++ drivers/gpu/drm/amd/amdkfd/kfd_svm.c          | 18 ++--- include/uapi/drm/amdgpu_drm.h                 |  7 ++

  14 files changed, 194 insertions(+), 66 deletions(-)

--
2.46.0

maintainer
#7 lore raw

Hi Friedrich,

adding Alex.

Am 04.02.25 um 13:32 schrieb Friedrich Vock:

Quoted 25 lines

Hi,

Quoted 14 lines · Christian König

Am 19.08.24 um 09:21 schrieb Friedrich Vock:

Quoted 8 lines

In Vulkan, it is the application's responsibility to perform adequate synchronization before a sparse unmap, replace or BO destroy operation. This adds an option to AMDGPU_VA_OPs to disable redundant implicit sync that happens on sparse unmap or replace operations.

This has seen a significant improvement in stutter in Forza Horizon 5 and Forza Horizon 4. (As games that had significant issues in sparse binding related stutter).

Looks pretty good, I have Shashank and his team working on the similar patches ever since Bas initially came up with it since we need it for user queues as well.

Quoted 7 lines

Shashank can you take a look at the UAPI? Of hand looks pretty similar to what we have done as well, doesn't it?

For the internal implementation in the VM I'm currently working on a bug fix for the KFD team, so this is subject to change anyway. Going to keep this requirement here in mind while doing that, whatever implementation we end up with we probably need to re-base it anyway.

Quoted 6 lines

Bumping this again - it's been quite a while, what became of that KFD bugfix and the userqueue stuff? It'd be nice to finally make progress here, whether it's using the user queue interface you worked on or a re-spin of this. Maybe it's possible to split this off from the rest of the userqueue stuff and merge it beforehand if you're reasonably certain about how the uapi should look? Let me know.

That is merged into amd-staging-drm-next for quite a while now, but we only defined the interface and dropped all optimizations to initially get it upstream.

@Alex IIRC we pushed the KFD part upstream already, but the userqueue part is still waiting for the final firmware release, right?

Regards,
Christian.

Quoted 51 lines

Thanks,
Friedrich

Quoted 46 lines

Regards,
Christian.

Quoted 42 lines

Userspace changes for this new version can be found at [1][2], and a kernel
branch containing these patches can be found at [3].

[1] https://gitlab.freedesktop.org/pixelcluster/drm/-/commits/vm-
explicit-sync
[2] https://gitlab.freedesktop.org/pixelcluster/mesa/-/commits/vm-
explicit-sync
[3] https://gitlab.freedesktop.org/pixelcluster/linux/-/commits/
amdgpu-vm-explicit-sync

v3 changes:
- Rebased onto current amd-staging-drm-next
- Added option to wait for drm_syncobjs instead of executing immediately

Tatsuyuki Ishi (3):
   drm/amdgpu: Don't implicit sync PRT maps.
   drm/amdgpu: Add optional explicit sync fences for GEM operations. drm/amdgpu: Bump amdgpu driver version.

  .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  2 +-

  drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c       |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  3 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       | 76 

++++++++++++++++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h    | 23 +++++- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h     |  6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_umsch_mm.c  |  2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 68 +++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        | 30 ++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c    | 12 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c     |  2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c   |  9 +++ drivers/gpu/drm/amd/amdkfd/kfd_svm.c          | 18 ++--- include/uapi/drm/amdgpu_drm.h                 |  7 ++

  14 files changed, 194 insertions(+), 66 deletions(-)
Signature · 1 line
2.46.0
#8 lore raw
Quoted 38 lines · Christian König

Hi Friedrich,

adding Alex.

Am 04.02.25 um 13:32 schrieb Friedrich Vock:

Quoted 25 lines

Hi,

Quoted 14 lines · Christian König

Am 19.08.24 um 09:21 schrieb Friedrich Vock:

Quoted 8 lines

In Vulkan, it is the application's responsibility to perform adequate synchronization before a sparse unmap, replace or BO destroy operation. This adds an option to AMDGPU_VA_OPs to disable redundant implicit sync that happens on sparse unmap or replace operations.

This has seen a significant improvement in stutter in Forza Horizon 5 and Forza Horizon 4. (As games that had significant issues in sparse binding related stutter).

Looks pretty good, I have Shashank and his team working on the similar patches ever since Bas initially came up with it since we need it for user queues as well.

Quoted 7 lines

Shashank can you take a look at the UAPI? Of hand looks pretty similar to what we have done as well, doesn't it?

For the internal implementation in the VM I'm currently working on a bug fix for the KFD team, so this is subject to change anyway. Going to keep this requirement here in mind while doing that, whatever implementation we end up with we probably need to re-base it anyway.

Quoted 6 lines

Bumping this again - it's been quite a while, what became of that KFD bugfix and the userqueue stuff? It'd be nice to finally make progress here, whether it's using the user queue interface you worked on or a re-spin of this. Maybe it's possible to split this off from the rest of the userqueue stuff and merge it beforehand if you're reasonably certain about how the uapi should look? Let me know.

Quoted 6 lines

That is merged into amd-staging-drm-next for quite a while now, but we only defined the interface and dropped all optimizations to initially get it upstream.

@Alex IIRC we pushed the KFD part upstream already, but the userqueue part is still waiting for the final firmware release, right?

Correct.

Alex

Quoted 56 lines

Regards,
Christian.

Quoted 51 lines

Thanks,
Friedrich

Quoted 46 lines

Regards,
Christian.

Quoted 42 lines

Userspace changes for this new version can be found at [1][2], and a kernel
branch containing these patches can be found at [3].

[1] https://gitlab.freedesktop.org/pixelcluster/drm/-/commits/vm-
explicit-sync
[2] https://gitlab.freedesktop.org/pixelcluster/mesa/-/commits/vm-
explicit-sync
[3] https://gitlab.freedesktop.org/pixelcluster/linux/-/commits/
amdgpu-vm-explicit-sync

v3 changes:
- Rebased onto current amd-staging-drm-next
- Added option to wait for drm_syncobjs instead of executing immediately

Tatsuyuki Ishi (3):
drm/amdgpu: Don't implicit sync PRT maps.
drm/amdgpu: Add optional explicit sync fences for GEM operations. drm/amdgpu: Bump amdgpu driver version.

  .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c       |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  3 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       | 76
++++++++++++++++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h    | 23 +++++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h     |  6 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_umsch_mm.c  |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 68 +++++++++++------
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        | 30 ++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c    | 12 ++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c     |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c   |  9 +++
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c          | 18 ++---
  include/uapi/drm/amdgpu_drm.h                 |  7 ++
  14 files changed, 194 insertions(+), 66 deletions(-)

--
2.46.0

#9 lore raw
Quoted 9 lines · Alex Deucher
Quoted 8 lines · Christian König

Hi Friedrich,

adding Alex.

Am 04.02.25 um 13:32 schrieb Friedrich Vock:

Quoted 2 lines

Hi,

<snip>

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

Bumping this again - it's been quite a while, what became of that KFD bugfix and the userqueue stuff? It'd be nice to finally make progress here, whether it's using the user queue interface you worked on or a re-spin of this. Maybe it's possible to split this off from the rest of the userqueue stuff and merge it beforehand if you're reasonably certain about how the uapi should look? Let me know.

Quoted 8 lines
Quoted 6 lines

That is merged into amd-staging-drm-next for quite a while now, but we only defined the interface and dropped all optimizations to initially get it upstream.

@Alex IIRC we pushed the KFD part upstream already, but the userqueue part is still waiting for the final firmware release, right?

Correct.

Right. Any rough timeline for when we can expect that firmware to release?

Thanks,
Friedrich

Quoted 59 lines

Alex

Quoted 56 lines

Regards,
Christian.

Quoted 51 lines

Thanks,
Friedrich

Quoted 46 lines

Regards,
Christian.

Quoted 42 lines

Userspace changes for this new version can be found at [1][2], and a kernel
branch containing these patches can be found at [3].

[1] https://gitlab.freedesktop.org/pixelcluster/drm/-/commits/vm-
explicit-sync
[2] https://gitlab.freedesktop.org/pixelcluster/mesa/-/commits/vm-
explicit-sync
[3] https://gitlab.freedesktop.org/pixelcluster/linux/-/commits/
amdgpu-vm-explicit-sync

v3 changes:
- Rebased onto current amd-staging-drm-next
- Added option to wait for drm_syncobjs instead of executing immediately

Tatsuyuki Ishi (3):
drm/amdgpu: Don't implicit sync PRT maps.
drm/amdgpu: Add optional explicit sync fences for GEM operations. drm/amdgpu: Bump amdgpu driver version.

   .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  2 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c       |  2 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  3 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       | 76
++++++++++++++++---
   drivers/gpu/drm/amd/amdgpu/amdgpu_object.h    | 23 +++++-
   drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h     |  6 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_umsch_mm.c  |  2 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        | 68 +++++++++++------
   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h        | 30 ++++----
   drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c    | 12 ++-
   drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c     |  2 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c   |  9 +++
   drivers/gpu/drm/amd/amdkfd/kfd_svm.c          | 18 ++---
   include/uapi/drm/amdgpu_drm.h                 |  7 ++
   14 files changed, 194 insertions(+), 66 deletions(-)

--
2.46.0