Skip to contentSkip to conversation

drm/vc4: Clean-up the BO seqnos

PATCH Superseded Maíra Canal 2 participants 8 messages Dec 6, 2024

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Maíra Canal

author reviewer
#0 lore raw

cover drm/vc4: Clean-up the BO seqnos

This series introduces a series of clean-ups in BO reservations for the VC4 driver. Currently, VC4 uses shared fences to track BO reservations as several other DRM devices. But apart from the DMA reservation objects, VC4 also attaches seqnos to its BOs with the intention to track if the job that uses such BO has finished.

The seqno tracking system was introduced before the DMA reservation objects and we ended up lefting it in the code after DMA resv was introduced. This is redundant, as we can perfectly track the end of a job with a fence. Therefore, this series focuses on eliminating the seqnos from the BO.

This series introduces a series of clean-ups for BO reservations in the VC4 driver. Currently, VC4 uses shared fences to track BO reservations, similar to many other DRM devices. However, in addition to DMA reservation objects, VC4 has been maintaining a separate seqno tracking system for BOs to track job completion.

The seqno tracking system was implemented before DMA reservation objects and was left in the code after DMA reservation's introduction. This approach is now redundant, as job completion can be effectively tracked using fences. Consequently, this series focuses on eliminating seqnos from the BO implementation.

Patch Breakdown
===============

* Patch #1: Uses the DRM GEM implementation of drm_gem_lock_reservations() and drm_gem_unlock_reservations() to replace the open-coded implementation of this functions by VC4. A straightforward change with no functional changes.

* Patch #2: Implements the VC4 wait BO IOCTL using DMA reservations. The new implementation closely mirrors the V3D approach and removes the IOCTL's dependency on BO sequence numbers.

* Patch #3: The central piece of this patchset. It removes bo->seqno, bo->write_seqno, and exec->bin_dep_seqno from the driver. As the seqno tracking system is redundant, its deletion is relatively straightforward. The only notable change is vc4_async_set_fence_cb(), which now uses dma_fence_add_callback() to add the VC4 callback.

* Patch #4: Deletes the now-unused function vc4_queue_seqno_cb().

Best Regards,
- Maíra

Maíra Canal (4):
drm/vc4: Use drm_gem_lock_reservations() instead of hard-coding drm/vc4: Use DMA Resv to implement VC4 wait BO IOCTL drm/vc4: Remove BOs seqnos
drm/vc4: Remove vc4_queue_seqno_cb()

 drivers/gpu/drm/vc4/vc4_crtc.c     |  22 ++---
 drivers/gpu/drm/vc4/vc4_drv.h      |  26 ++---
 drivers/gpu/drm/vc4/vc4_gem.c      | 147 ++++++-----------------------
 drivers/gpu/drm/vc4/vc4_validate.c |  11 ---
 4 files changed, 48 insertions(+), 158 deletions(-)
Signature · 1 line
2.47.1
author reviewer
#1 lore raw

PATCH 1/4 drm/vc4: Use `drm_gem_lock_reservations()` instead of hard-coding

Instead of creating internal copies of drm_gem_lock_reservations() and drm_gem_unlock_reservations(), use the functions provided by DRM GEM.

---
 drivers/gpu/drm/vc4/vc4_gem.c | 66 ++++-------------------------------
 1 file changed, 6 insertions(+), 60 deletions(-)
drivers/gpu/drm/vc4/vc4_gem.c +6 -60
index 22bccd69eb62..2e5477b1c73a 100644
@@ -578,19 +578,6 @@ vc4_update_bo_seqnos(struct vc4_exec_info *exec, uint64_t seqno)
 	}
 }
 
-static void
-vc4_unlock_bo_reservations(struct drm_device *dev,
-			   struct vc4_exec_info *exec,
-			   struct ww_acquire_ctx *acquire_ctx)
-{
-	int i;
-
-	for (i = 0; i < exec->bo_count; i++)
-		dma_resv_unlock(exec->bo[i]->resv);
-
-	ww_acquire_fini(acquire_ctx);
-}
-
 /* Takes the reservation lock on all the BOs being referenced, so that
  * at queue submit time we can update the reservations.
  *
@@ -603,54 +590,12 @@ vc4_lock_bo_reservations(struct drm_device *dev,
 			 struct vc4_exec_info *exec,
 			 struct ww_acquire_ctx *acquire_ctx)
 {
-	int contended_lock = -1;
 	int i, ret;
 	struct drm_gem_object *bo;
 
-	ww_acquire_init(acquire_ctx, &reservation_ww_class);
-
-retry:
-	if (contended_lock != -1) {
-		bo = exec->bo[contended_lock];
-		ret = dma_resv_lock_slow_interruptible(bo->resv, acquire_ctx);
-		if (ret) {
-			ww_acquire_done(acquire_ctx);
-			return ret;
-		}
-	}
-
-	for (i = 0; i < exec->bo_count; i++) {
-		if (i == contended_lock)
-			continue;
-
-		bo = exec->bo[i];
-
-		ret = dma_resv_lock_interruptible(bo->resv, acquire_ctx);
-		if (ret) {
-			int j;
-
-			for (j = 0; j < i; j++) {
-				bo = exec->bo[j];
-				dma_resv_unlock(bo->resv);
-			}
-
-			if (contended_lock != -1 && contended_lock >= i) {
-				bo = exec->bo[contended_lock];
-
-				dma_resv_unlock(bo->resv);
-			}
-
-			if (ret == -EDEADLK) {
-				contended_lock = i;
-				goto retry;
-			}
-
-			ww_acquire_done(acquire_ctx);
-			return ret;
-		}
-	}
-
-	ww_acquire_done(acquire_ctx);
+	ret = drm_gem_lock_reservations(exec->bo, exec->bo_count, acquire_ctx);
+	if (ret)
+		return ret;
 
 	/* Reserve space for our shared (read-only) fence references,
 	 * before we commit the CL to the hardware.
@@ -660,7 +605,8 @@ vc4_lock_bo_reservations(struct drm_device *dev,
 
 		ret = dma_resv_reserve_fences(bo->resv, 1);
 		if (ret) {
-			vc4_unlock_bo_reservations(dev, exec, acquire_ctx);
+			drm_gem_unlock_reservations(exec->bo, exec->bo_count,
+						    acquire_ctx);
 			return ret;
 		}
 	}
@@ -708,7 +654,7 @@ vc4_queue_submit(struct drm_device *dev, struct vc4_exec_info *exec,
 
 	vc4_update_bo_seqnos(exec, seqno);
 
-	vc4_unlock_bo_reservations(dev, exec, acquire_ctx);
+	drm_gem_unlock_reservations(exec->bo, exec->bo_count, acquire_ctx);
 
 	list_add_tail(&exec->head, &vc4->bin_job_list);
 
Signature · 1 line
2.47.1
author reviewer
#2 lore raw

PATCH 2/4 drm/vc4: Use DMA Resv to implement VC4 wait BO IOCTL

In reply to Maíra Canal

As the BOs used by VC4 have DMA Reservation Objects attached to it, there is no need to use seqnos wait for the BOs availability. Instead, we can use dma_gem_dma_resv_wait().

---
 drivers/gpu/drm/vc4/vc4_drv.h | 10 ++++++++++
 drivers/gpu/drm/vc4/vc4_gem.c | 31 +++++++++++++++++++------------
 2 files changed, 29 insertions(+), 12 deletions(-)
drivers/gpu/drm/vc4/vc4_drv.h +10 -0
index 4a078ffd9f82..03ed40ab9a93 100644
@@ -924,6 +924,16 @@ struct vc4_validated_shader_info {
 						   (Wmax))
 #define wait_for(COND, MS)		_wait_for((COND), (MS) * 1000, 10, 1000)
 
+static inline unsigned long nsecs_to_jiffies_timeout(const u64 n)
+{
+	/* nsecs_to_jiffies64() does not guard against overflow */
+	if ((NSEC_PER_SEC % HZ) != 0 &&
+	    div_u64(n, NSEC_PER_SEC) >= MAX_JIFFY_OFFSET / HZ)
+		return MAX_JIFFY_OFFSET;
+
+	return min_t(u64, MAX_JIFFY_OFFSET, nsecs_to_jiffies64(n) + 1);
+}
+
 /* vc4_bo.c */
 struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size);
 struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size,
drivers/gpu/drm/vc4/vc4_gem.c +19 -12
index 2e5477b1c73a..256af016ade0 100644
@@ -1022,11 +1022,13 @@ int
 vc4_wait_bo_ioctl(struct drm_device *dev, void *data,
 		  struct drm_file *file_priv)
 {
-	struct vc4_dev *vc4 = to_vc4_dev(dev);
 	int ret;
+	struct vc4_dev *vc4 = to_vc4_dev(dev);
 	struct drm_vc4_wait_bo *args = data;
-	struct drm_gem_object *gem_obj;
-	struct vc4_bo *bo;
+	unsigned long timeout_jiffies =
+		nsecs_to_jiffies_timeout(args->timeout_ns);
+	ktime_t start = ktime_get();
+	u64 delta_ns;
 
 	if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4))
 		return -ENODEV;
@@ -1034,17 +1036,22 @@ vc4_wait_bo_ioctl(struct drm_device *dev, void *data,
 	if (args->pad != 0)
 		return -EINVAL;
 
-	gem_obj = drm_gem_object_lookup(file_priv, args->handle);
-	if (!gem_obj) {
-		DRM_DEBUG("Failed to look up GEM BO %d\n", args->handle);
-		return -EINVAL;
-	}
-	bo = to_vc4_bo(gem_obj);
+	ret = drm_gem_dma_resv_wait(file_priv, args->handle,
+				    true, timeout_jiffies);
 
-	ret = vc4_wait_for_seqno_ioctl_helper(dev, bo->seqno,
-					      &args->timeout_ns);
+	/* Decrement the user's timeout, in case we got interrupted
+	 * such that the ioctl will be restarted.
+	 */
+	delta_ns = ktime_to_ns(ktime_sub(ktime_get(), start));
+	if (delta_ns < args->timeout_ns)
+		args->timeout_ns -= delta_ns;
+	else
+		args->timeout_ns = 0;
+
+	/* Asked to wait beyond the jiffy/scheduler precision? */
+	if (ret == -ETIME && args->timeout_ns)
+		ret = -EAGAIN;
 
-	drm_gem_object_put(gem_obj);
 	return ret;
 }
 
Signature · 1 line
2.47.1
author reviewer
#3 lore raw

PATCH 3/4 drm/vc4: Remove BOs seqnos

In reply to Maíra Canal

bo->seqno, bo->write_seqno, and exec->bin_dep_seqno are leftovers from a time when VC4 didn't support DMA Reservation Objects. When they were introduced, it made sense to think about tracking the correspondence between the BOs and the jobs through the job's seqno.

This is no longer needed, as VC4 already has support for DMA Reservation Objects and attaches the "job done" fence to the BOs.

---
 drivers/gpu/drm/vc4/vc4_crtc.c     | 22 +++++++++++-----------
 drivers/gpu/drm/vc4/vc4_drv.h      | 13 -------------
 drivers/gpu/drm/vc4/vc4_gem.c      | 18 ++----------------
 drivers/gpu/drm/vc4/vc4_validate.c | 11 -----------
 4 files changed, 13 insertions(+), 51 deletions(-)
drivers/gpu/drm/vc4/vc4_crtc.c +11 -11
index bfa25efa5db2..1b9b54286a6e 100644
@@ -919,10 +919,11 @@ vc4_async_page_flip_complete(struct vc4_async_flip_state *flip_state)
 	kfree(flip_state);
 }
 
-static void vc4_async_page_flip_seqno_complete(struct vc4_seqno_cb *cb)
+static void vc4_async_page_flip_seqno_complete(struct dma_fence *fence,
+					       struct dma_fence_cb *cb)
 {
 	struct vc4_async_flip_state *flip_state =
-		container_of(cb, struct vc4_async_flip_state, cb.seqno);
+		container_of(cb, struct vc4_async_flip_state, cb.fence);
 	struct vc4_bo *bo = NULL;
 
 	if (flip_state->old_fb) {
@@ -961,16 +962,15 @@ static int vc4_async_set_fence_cb(struct drm_device *dev,
 {
 	struct drm_framebuffer *fb = flip_state->fb;
 	struct drm_gem_dma_object *dma_bo = drm_fb_dma_get_gem_obj(fb, 0);
+	dma_fence_func_t async_page_flip_complete_function;
 	struct vc4_dev *vc4 = to_vc4_dev(dev);
 	struct dma_fence *fence;
 	int ret;
 
-	if (vc4->gen == VC4_GEN_4) {
-		struct vc4_bo *bo = to_vc4_bo(&dma_bo->base);
-
-		return vc4_queue_seqno_cb(dev, &flip_state->cb.seqno, bo->seqno,
-					  vc4_async_page_flip_seqno_complete);
-	}
+	if (vc4->gen == VC4_GEN_4)
+		async_page_flip_complete_function = vc4_async_page_flip_seqno_complete;
+	else
+		async_page_flip_complete_function = vc4_async_page_flip_fence_complete;
 
 	ret = dma_resv_get_singleton(dma_bo->base.resv, DMA_RESV_USAGE_READ, &fence);
 	if (ret)
@@ -978,14 +978,14 @@ static int vc4_async_set_fence_cb(struct drm_device *dev,
 
 	/* If there's no fence, complete the page flip immediately */
 	if (!fence) {
-		vc4_async_page_flip_fence_complete(fence, &flip_state->cb.fence);
+		async_page_flip_complete_function(fence, &flip_state->cb.fence);
 		return 0;
 	}
 
 	/* If the fence has already been completed, complete the page flip */
 	if (dma_fence_add_callback(fence, &flip_state->cb.fence,
-				   vc4_async_page_flip_fence_complete))
-		vc4_async_page_flip_fence_complete(fence, &flip_state->cb.fence);
+				   async_page_flip_complete_function))
+		async_page_flip_complete_function(fence, &flip_state->cb.fence);
 
 	return 0;
 }
drivers/gpu/drm/vc4/vc4_drv.h +0 -13
index 03ed40ab9a93..ff8048991030 100644
@@ -247,16 +247,6 @@ struct vc4_dev {
 struct vc4_bo {
 	struct drm_gem_dma_object base;
 
-	/* seqno of the last job to render using this BO. */
-	uint64_t seqno;
-
-	/* seqno of the last job to use the RCL to write to this BO.
-	 *
-	 * Note that this doesn't include binner overflow memory
-	 * writes.
-	 */
-	uint64_t write_seqno;
-
 	bool t_format;
 
 	/* List entry for the BO's position in either
@@ -695,9 +685,6 @@ struct vc4_exec_info {
 	/* Sequence number for this bin/render job. */
 	uint64_t seqno;
 
-	/* Latest write_seqno of any BO that binning depends on. */
-	uint64_t bin_dep_seqno;
-
 	struct dma_fence *fence;
 
 	/* Last current addresses the hardware was processing when the
drivers/gpu/drm/vc4/vc4_gem.c +2 -16
index 256af016ade0..879d9fdfff22 100644
@@ -552,27 +552,19 @@ vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec)
 }
 
 static void
-vc4_update_bo_seqnos(struct vc4_exec_info *exec, uint64_t seqno)
+vc4_attach_fences(struct vc4_exec_info *exec)
 {
 	struct vc4_bo *bo;
 	unsigned i;
 
 	for (i = 0; i < exec->bo_count; i++) {
 		bo = to_vc4_bo(exec->bo[i]);
-		bo->seqno = seqno;
-
 		dma_resv_add_fence(bo->base.base.resv, exec->fence,
 				   DMA_RESV_USAGE_READ);
 	}
 
-	list_for_each_entry(bo, &exec->unref_list, unref_head) {
-		bo->seqno = seqno;
-	}
-
 	for (i = 0; i < exec->rcl_write_bo_count; i++) {
 		bo = to_vc4_bo(&exec->rcl_write_bo[i]->base);
-		bo->write_seqno = seqno;
-
 		dma_resv_add_fence(bo->base.base.resv, exec->fence,
 				   DMA_RESV_USAGE_WRITE);
 	}
@@ -652,7 +644,7 @@ vc4_queue_submit(struct drm_device *dev, struct vc4_exec_info *exec,
 	if (out_sync)
 		drm_syncobj_replace_fence(out_sync, exec->fence);
 
-	vc4_update_bo_seqnos(exec, seqno);
+	vc4_attach_fences(exec);
 
 	drm_gem_unlock_reservations(exec->bo, exec->bo_count, acquire_ctx);
 
@@ -850,12 +842,6 @@ vc4_get_bcl(struct drm_device *dev, struct vc4_exec_info *exec)
 			goto fail;
 	}
 
-	/* Block waiting on any previous rendering into the CS's VBO,
-	 * IB, or textures, so that pixels are actually written by the
-	 * time we try to read them.
-	 */
-	ret = vc4_wait_for_seqno(dev, exec->bin_dep_seqno, ~0ull, true);
-
 fail:
 	kvfree(temp);
 	return ret;
drivers/gpu/drm/vc4/vc4_validate.c +0 -11
index 5bf134968ade..1e7bdda55698 100644
@@ -284,9 +284,6 @@ validate_indexed_prim_list(VALIDATE_ARGS)
 	if (!ib)
 		return -EINVAL;
 
-	exec->bin_dep_seqno = max(exec->bin_dep_seqno,
-				  to_vc4_bo(&ib->base)->write_seqno);
-
 	if (offset > ib->base.size ||
 	    (ib->base.size - offset) / index_size < length) {
 		DRM_DEBUG("IB access overflow (%d + %d*%d > %zd)\n",
@@ -738,11 +735,6 @@ reloc_tex(struct vc4_exec_info *exec,
 
 	*validated_p0 = tex->dma_addr + p0;
 
-	if (is_cs) {
-		exec->bin_dep_seqno = max(exec->bin_dep_seqno,
-					  to_vc4_bo(&tex->base)->write_seqno);
-	}
-
 	return true;
  fail:
 	DRM_INFO("Texture p0 at %d: 0x%08x\n", sample->p_offset[0], p0);
@@ -904,9 +896,6 @@ validate_gl_shader_rec(struct drm_device *dev,
 		uint32_t stride = *(uint8_t *)(pkt_u + o + 5);
 		uint32_t max_index;
 
-		exec->bin_dep_seqno = max(exec->bin_dep_seqno,
-					  to_vc4_bo(&vbo->base)->write_seqno);
-
 		if (state->addr & 0x8)
 			stride |= (*(uint32_t *)(pkt_u + 100 + i * 4)) & ~0xff;
 
Signature · 1 line
2.47.1
author reviewer
#4 lore raw

PATCH 4/4 drm/vc4: Remove `vc4_queue_seqno_cb()`

In reply to Maíra Canal

The function vc4_queue_seqno_cb() is no longer needed, as we are using DMA Reservation Objects to track BOs. Using DMA Resv, we can use dma_fence_add_callback() to perform the async page flip.

---
 drivers/gpu/drm/vc4/vc4_drv.h |  3 ---
 drivers/gpu/drm/vc4/vc4_gem.c | 32 --------------------------------
 2 files changed, 35 deletions(-)
drivers/gpu/drm/vc4/vc4_drv.h +0 -3
index ff8048991030..7e23363d008f 100644
@@ -1022,9 +1022,6 @@ void vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec);
 int vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno,
 		       uint64_t timeout_ns, bool interruptible);
 void vc4_job_handle_completed(struct vc4_dev *vc4);
-int vc4_queue_seqno_cb(struct drm_device *dev,
-		       struct vc4_seqno_cb *cb, uint64_t seqno,
-		       void (*func)(struct vc4_seqno_cb *cb));
 int vc4_gem_madvise_ioctl(struct drm_device *dev, void *data,
 			  struct drm_file *file_priv);
 
drivers/gpu/drm/vc4/vc4_gem.c +0 -32
index 879d9fdfff22..8acfc301529b 100644
@@ -927,38 +927,6 @@ vc4_job_handle_completed(struct vc4_dev *vc4)
 	spin_unlock_irqrestore(&vc4->job_lock, irqflags);
 }
 
-static void vc4_seqno_cb_work(struct work_struct *work)
-{
-	struct vc4_seqno_cb *cb = container_of(work, struct vc4_seqno_cb, work);
-
-	cb->func(cb);
-}
-
-int vc4_queue_seqno_cb(struct drm_device *dev,
-		       struct vc4_seqno_cb *cb, uint64_t seqno,
-		       void (*func)(struct vc4_seqno_cb *cb))
-{
-	struct vc4_dev *vc4 = to_vc4_dev(dev);
-	unsigned long irqflags;
-
-	if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4))
-		return -ENODEV;
-
-	cb->func = func;
-	INIT_WORK(&cb->work, vc4_seqno_cb_work);
-
-	spin_lock_irqsave(&vc4->job_lock, irqflags);
-	if (seqno > vc4->finished_seqno) {
-		cb->seqno = seqno;
-		list_add_tail(&cb->work.entry, &vc4->seqno_cb_list);
-	} else {
-		schedule_work(&cb->work);
-	}
-	spin_unlock_irqrestore(&vc4->job_lock, irqflags);
-
-	return 0;
-}
-
 /* Scheduled when any job has been completed, this walks the list of
  * jobs that had completed and unrefs their BOs and frees their exec
  * structs.
Signature · 1 line
2.47.1
#5 lore raw
In reply to Maíra Canal

Am 06.12.24 um 14:12 schrieb Maíra Canal:

Quoted 17 lines

This series introduces a series of clean-ups in BO reservations for the VC4 driver. Currently, VC4 uses shared fences to track BO reservations as several other DRM devices. But apart from the DMA reservation objects, VC4 also attaches seqnos to its BOs with the intention to track if the job that uses such BO has finished.

The seqno tracking system was introduced before the DMA reservation objects and we ended up lefting it in the code after DMA resv was introduced. This is redundant, as we can perfectly track the end of a job with a fence. Therefore, this series focuses on eliminating the seqnos from the BO.

This series introduces a series of clean-ups for BO reservations in the VC4 driver. Currently, VC4 uses shared fences to track BO reservations, similar to many other DRM devices. However, in addition to DMA reservation objects, VC4 has been maintaining a separate seqno tracking system for BOs to track job completion.

Quoted 5 lines

The seqno tracking system was implemented before DMA reservation objects and was left in the code after DMA reservation's introduction. This approach is now redundant, as job completion can be effectively tracked using fences. Consequently, this series focuses on eliminating seqnos from the BO implementation.

Just FYI, you duplicated the text somehow :)

Quoted 8 lines

Patch Breakdown
===============

* Patch #1: Uses the DRM GEM implementation of drm_gem_lock_reservations() and drm_gem_unlock_reservations() to replace the open-coded implementation of this functions by VC4. A straightforward change with no functional changes.

I actually pushed to remove drm_gem_lock_reservations() in favor of using the drm_exec object.

It would be nice if you could use that one instead.

Regards,
Christian.

Quoted 28 lines

* Patch #2: Implements the VC4 wait BO IOCTL using DMA reservations. The new implementation closely mirrors the V3D approach and removes the IOCTL's dependency on BO sequence numbers.

* Patch #3: The central piece of this patchset. It removes bo->seqno, bo->write_seqno, and exec->bin_dep_seqno from the driver. As the seqno tracking system is redundant, its deletion is relatively straightforward. The only notable change is vc4_async_set_fence_cb(), which now uses dma_fence_add_callback() to add the VC4 callback.

* Patch #4: Deletes the now-unused function vc4_queue_seqno_cb().

Best Regards,
- Maíra

Maíra Canal (4):
drm/vc4: Use drm_gem_lock_reservations() instead of hard-coding drm/vc4: Use DMA Resv to implement VC4 wait BO IOCTL drm/vc4: Remove BOs seqnos
drm/vc4: Remove vc4_queue_seqno_cb()

  drivers/gpu/drm/vc4/vc4_crtc.c     |  22 ++---
  drivers/gpu/drm/vc4/vc4_drv.h      |  26 ++---
  drivers/gpu/drm/vc4/vc4_gem.c      | 147 ++++++-----------------------
  drivers/gpu/drm/vc4/vc4_validate.c |  11 ---
  4 files changed, 48 insertions(+), 158 deletions(-)
author reviewer
#6 lore raw
Quoted 18 lines · Christian König

Am 06.12.24 um 14:12 schrieb Maíra Canal:

Quoted 17 lines

This series introduces a series of clean-ups in BO reservations for the VC4 driver. Currently, VC4 uses shared fences to track BO reservations as several other DRM devices. But apart from the DMA reservation objects, VC4 also attaches seqnos to its BOs with the intention to track if the job that uses such BO has finished.

The seqno tracking system was introduced before the DMA reservation objects and we ended up lefting it in the code after DMA resv was introduced. This is redundant, as we can perfectly track the end of a job with a fence. Therefore, this series focuses on eliminating the seqnos from the BO.

This series introduces a series of clean-ups for BO reservations in the VC4 driver. Currently, VC4 uses shared fences to track BO reservations, similar to many other DRM devices. However, in addition to DMA reservation objects, VC4 has been maintaining a separate seqno tracking system for BOs to track job completion.

Quoted 7 lines
Quoted 5 lines

The seqno tracking system was implemented before DMA reservation objects and was left in the code after DMA reservation's introduction. This approach is now redundant, as job completion can be effectively tracked using fences. Consequently, this series focuses on eliminating seqnos from the BO implementation.

Just FYI, you duplicated the text somehow :)

Oops, that's a non-native English-speaker trying to write a v2 of a paragraph :)

Quoted 5 lines
Quoted 5 lines

Patch Breakdown
===============

Quoted 8 lines
Quoted 4 lines

* Patch #1: Uses the DRM GEM implementation of drm_gem_lock_reservations() and drm_gem_unlock_reservations() to replace the open-coded implementation of this functions by VC4. A straightforward change with no functional changes.

I actually pushed to remove drm_gem_lock_reservations() in favor of using the drm_exec object.

It would be nice if you could use that one instead.

Okay, I'll use DRM exec in the next version. I'd appreciate if you could take a look at the patches that remove the BOs seqnos.

Thanks for comments!

Best Regards,
- Maíra

Quoted 33 lines

Regards,
Christian.

Quoted 28 lines

* Patch #2: Implements the VC4 wait BO IOCTL using DMA reservations. The new implementation closely mirrors the V3D approach and removes the IOCTL's dependency on BO sequence numbers.

* Patch #3: The central piece of this patchset. It removes bo->seqno, bo->write_seqno, and exec->bin_dep_seqno from the driver. As the seqno tracking system is redundant, its deletion is relatively straightforward. The only notable change is vc4_async_set_fence_cb(), which now uses dma_fence_add_callback() to add the VC4 callback.

* Patch #4: Deletes the now-unused function vc4_queue_seqno_cb().

Best Regards,
- Maíra

Maíra Canal (4):
   drm/vc4: Use drm_gem_lock_reservations() instead of hard-coding drm/vc4: Use DMA Resv to implement VC4 wait BO IOCTL drm/vc4: Remove BOs seqnos
   drm/vc4: Remove vc4_queue_seqno_cb()

  drivers/gpu/drm/vc4/vc4_crtc.c     |  22 ++--- drivers/gpu/drm/vc4/vc4_drv.h      |  26 ++--- drivers/gpu/drm/vc4/vc4_gem.c      | 147 ++++++----------------------- drivers/gpu/drm/vc4/vc4_validate.c |  11 ---

  4 files changed, 48 insertions(+), 158 deletions(-)
#7 lore raw

Am 06.12.24 um 16:11 schrieb Maíra Canal:

Quoted 40 lines · Christian König
Quoted 18 lines

Am 06.12.24 um 14:12 schrieb Maíra Canal:

Quoted 17 lines

This series introduces a series of clean-ups in BO reservations for the VC4 driver. Currently, VC4 uses shared fences to track BO reservations as several other DRM devices. But apart from the DMA reservation objects, VC4 also attaches seqnos to its BOs with the intention to track if the job that uses such BO has finished.

The seqno tracking system was introduced before the DMA reservation objects and we ended up lefting it in the code after DMA resv was introduced. This is redundant, as we can perfectly track the end of a job with a fence. Therefore, this series focuses on eliminating the seqnos from the BO.

This series introduces a series of clean-ups for BO reservations in the VC4 driver. Currently, VC4 uses shared fences to track BO reservations, similar to many other DRM devices. However, in addition to DMA reservation objects, VC4 has been maintaining a separate seqno tracking system for BOs to track job completion.

Quoted 7 lines
Quoted 5 lines

The seqno tracking system was implemented before DMA reservation objects and was left in the code after DMA reservation's introduction. This approach is now redundant, as job completion can be effectively tracked using fences. Consequently, this series focuses on eliminating seqnos from the BO implementation.

Just FYI, you duplicated the text somehow :)

Oops, that's a non-native English-speaker trying to write a v2 of a paragraph :)

Quoted 10 lines
Quoted 9 lines

Patch Breakdown
===============

* Patch #1: Uses the DRM GEM implementation of drm_gem_lock_reservations() and drm_gem_unlock_reservations() to replace the open-coded implementation of this functions by VC4. A straightforward change with no functional changes.

Quoted 6 lines
Quoted 3 lines

I actually pushed to remove drm_gem_lock_reservations() in favor of using the drm_exec object.

It would be nice if you could use that one instead.

Okay, I'll use DRM exec in the next version. I'd appreciate if you could take a look at the patches that remove the BOs seqnos.

Of hand it looks good to me, e.g. no problematic usages for the objects defined by DMA-buf, e.g. dma_resv and dma_fence.

But I have absolutely zero experience with the VC4 code base, so I can't say anything about that.

Regards,
Christian.

Quoted 41 lines

Thanks for comments!

Best Regards,
- Maíra

Quoted 34 lines

Regards,
Christian.

Quoted 29 lines

* Patch #2: Implements the VC4 wait BO IOCTL using DMA reservations. The new implementation closely mirrors the V3D approach and removes the IOCTL's dependency on BO sequence numbers.

* Patch #3: The central piece of this patchset. It removes bo->seqno, bo->write_seqno, and exec->bin_dep_seqno from the driver. As the seqno tracking system is redundant, its deletion is relatively straightforward. The only notable change is vc4_async_set_fence_cb(), which now uses dma_fence_add_callback() to add the VC4 callback.

* Patch #4: Deletes the now-unused function vc4_queue_seqno_cb().

Best Regards,
- Maíra

Maíra Canal (4):
   drm/vc4: Use drm_gem_lock_reservations() instead of hard-coding drm/vc4: Use DMA Resv to implement VC4 wait BO IOCTL drm/vc4: Remove BOs seqnos
   drm/vc4: Remove vc4_queue_seqno_cb()

  drivers/gpu/drm/vc4/vc4_crtc.c     |  22 ++---
  drivers/gpu/drm/vc4/vc4_drv.h      |  26 ++---
  drivers/gpu/drm/vc4/vc4_gem.c      | 147
++++++-----------------------
  drivers/gpu/drm/vc4/vc4_validate.c |  11 ---

  4 files changed, 48 insertions(+), 158 deletions(-)