drm/vc4: Clean-up BO seqnos
Subsystems (3)
Maíra Canal
reviewerv3 cover drm/vc4: Clean-up BO seqnos
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 Exec to replace the open-coded implementation of the functions drm_gem_lock_reservations() and drm_gem_unlock_reservations() in the VC4 driver code. A straightforward change with no functional changes.
* Patch #2: Implements the VC4 wait BO IOCTL using DMA Resv Objects. 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.
Changes
=======
v1 -> v2: https://lore.kernel.org/dri-devel/[email protected]/T/
* [1/4] Use DRM Exec to replace the (un)lock reservation functions (Christian König)
v2 -> v3: https://lore.kernel.org/dri-devel/[email protected]/T/
* [1/4] König's A-b (Christian König)
* [2/4] s/dma_gem_dma_resv_wait/drm_gem_dma_resv_wait (Melissa Wen)
* [2/4] Use usecs_to_jiffies() to calculate the timeout in jiffies (Tvrtko Ursulin)
* [2/4] Remove -EAGAIN errno from the IOCTL (Tvrtko Ursulin)
* [3/4] s/vc4_async_page_flip_seqno_complete/vc4_async_page_flip_complete_with_cleanup (Melissa Wen)
* [3/4] Add dma_fence_put() in vc4_async_page_flip_complete_with_cleanup()
* [3/4] Maxime's R-b (Maxime Ripard)
* [4/4] Squashed to PATCH 3/4 (Melissa Wen)
* [4/4] Remove vc4->seqno_cb_list and struct vc4_seqno_cb (Tvrtko Ursulin)
Best Regards,
- Maíra
---
Maíra Canal (3):
drm/vc4: Use DRM Execution Contexts drm/vc4: Use DMA Resv to implement VC4 wait BO IOCTL drm/vc4: Remove BOs seqnos
drivers/gpu/drm/vc4/Kconfig | 1 + drivers/gpu/drm/vc4/vc4_crtc.c | 33 +++--- drivers/gpu/drm/vc4/vc4_drv.h | 27 ----- drivers/gpu/drm/vc4/vc4_gem.c | 183 ++++++----------------------- drivers/gpu/drm/vc4/vc4_validate.c | 11 -- 5 files changed, 53 insertions(+), 202 deletions(-)
Signature · 1 line
2.47.1
Maíra Canal
reviewerPATCH v3 1/3 drm/vc4: Use DRM Execution Contexts
VC4 has internal copies of drm_gem_lock_reservations() and drm_gem_unlock_reservations() within the driver. Ideally, these hard-coded functions should be replaced with the generic functions provided by DRM common code. However, instead of using the DRM GEM functions to (un)lock reservations, transition to the new DRM Execution Contexts API.
--- drivers/gpu/drm/vc4/Kconfig | 1 + drivers/gpu/drm/vc4/vc4_gem.c | 99 ++++++++--------------------------- 2 files changed, 22 insertions(+), 78 deletions(-)
drivers/gpu/drm/vc4/Kconfig +1 -0
@@ -13,6 +13,7 @@ config DRM_VC4 select DRM_DISPLAY_HDMI_HELPER select DRM_DISPLAY_HDMI_STATE_HELPER select DRM_DISPLAY_HELPER + select DRM_EXEC select DRM_KMS_HELPER select DRM_GEM_DMA_HELPER select DRM_PANEL_BRIDGE
drivers/gpu/drm/vc4/vc4_gem.c +21 -78
171 lines not on this page · raw message
Signature · 1 line
2.47.1
Maíra Canal
reviewerPATCH v3 2/3 drm/vc4: Use DMA Resv to implement VC4 wait BO IOCTL
In reply to Maíra CanalSince the BOs used by VC4 have DMA Reservation Objects attached to them, waiting for seqnos to check BO availability is unnecessary. Instead, drm_gem_dma_resv_wait() can be used.
--- drivers/gpu/drm/vc4/vc4_gem.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
drivers/gpu/drm/vc4/vc4_gem.c +14 -11
@@ -1020,8 +1020,10 @@ vc4_wait_bo_ioctl(struct drm_device *dev, void *data,struct vc4_dev *vc4 =to_vc4_dev (dev);int ret;struct drm_vc4_wait_bo *args = data; -struct drm_gem_object *gem_obj; -struct vc4_bo *bo; +unsigned long timeout_jiffies = +usecs_to_jiffies (div_u64 (args->timeout_ns,1000 )); +ktime_t start =ktime_get (); +u64 delta_ns;if (WARN_ON_ONCE (vc4->gen >VC4_GEN_4 ))return -ENODEV ;
@@ -1029,17 +1031,18 @@ 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 ; -drm_gem_object_put (gem_obj);return ret; }
Signature · 1 line
2.47.1
Maíra Canal
reviewerPATCH v3 3/3 drm/vc4: Remove BOs seqnos
In reply to Maíra Canalbo->seqno, bo->write_seqno, and exec->bin_dep_seqno are leftovers from a time when VC4 didn't support DMA Reservation Objects. Before DMA Resv was introduced, tracking the correspondence between BOs and jobs through the job's seqno made sense.
However, this is no longer needed, as VC4 now supports DMA Reservation Objects and attaches the "job done" fence to the BOs. Therefore, remove the BOs seqnos in favor of using DMA Resv Objects.
--- drivers/gpu/drm/vc4/vc4_crtc.c | 33 ++++++++--------- drivers/gpu/drm/vc4/vc4_drv.h | 27 -------------- drivers/gpu/drm/vc4/vc4_gem.c | 59 +----------------------------- drivers/gpu/drm/vc4/vc4_validate.c | 11 ------ 4 files changed, 17 insertions(+), 113 deletions(-)
drivers/gpu/drm/vc4/vc4_crtc.c +15 -18
@@ -884,11 +884,7 @@ struct vc4_async_flip_state {struct drm_framebuffer *fb;struct drm_framebuffer *old_fb;struct drm_pending_vblank_event *event; - -union { -struct dma_fence_cb fence; -struct vc4_seqno_cb seqno; - } cb; +struct dma_fence_cb cb; };/* Called when the V3D execution for the BO being flipped to is done, so that
@@ -919,10 +915,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_complete_with_cleanup (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);struct vc4_bo *bo =NULL ;if (flip_state->old_fb) {
@@ -932,6 +929,7 @@ static void vc4_async_page_flip_seqno_complete(struct vc4_seqno_cb *cb) }vc4_async_page_flip_complete (flip_state); +dma_fence_put (fence);/* * Decrement the BO usecnt in order to keep the inc/dec
@@ -950,7 +948,7 @@ static void vc4_async_page_flip_fence_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.fence); + container_of(cb, struct vc4_async_flip_state, cb);vc4_async_page_flip_complete (flip_state);dma_fence_put (fence);
@@ -961,16 +959,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_complete_with_cleanup; +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 +975,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);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); +if (dma_fence_add_callback (fence, &flip_state->cb, + async_page_flip_complete_function)) +async_page_flip_complete_function (fence, &flip_state->cb);return 0 ; }
drivers/gpu/drm/vc4/vc4_drv.h +0 -27
@@ -186,11 +186,6 @@ struct vc4_dev {*/ struct vc4_perfmon *active_perfmon; -/* List of struct vc4_seqno_cb for callbacks to be made from a -* workqueue when the given seqno is passed. -*/ -struct list_head seqno_cb_list; -/* The memory used for storing binner tile alloc, tile state, * and overflow memory allocations. This is freed when V3D * powers down.
@@ -247,16 +242,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
@@ -304,12 +289,6 @@ struct vc4_fence {#define to_vc4_fence (_fence) \ container_of_const(_fence, struct vc4_fence, base) -struct vc4_seqno_cb { -struct work_struct work; -uint64_t seqno; -void (*func)(struct vc4_seqno_cb *cb); -}; -struct vc4_v3d {struct vc4_dev *vc4;struct platform_device *pdev;
@@ -695,9 +674,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
@@ -1025,9 +1001,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 +2 -57
110 lines not on this page · raw message
drivers/gpu/drm/vc4/vc4_validate.c +0 -11
@@ -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
Quoted 24 lines · Maíra Canal
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 Exec to replace the open-coded implementation of the functions
drm_gem_lock_reservations()anddrm_gem_unlock_reservations()in the VC4 driver code. A straightforward change with no functional changes.* Patch #2: Implements the VC4 wait BO IOCTL using DMA Resv Objects. The new implementation closely mirrors the V3D approach and removes the IOCTL's dependency on BO sequence numbers.
Quoted 5 lines
* Patch #3: The central piece of this patchset. It removes
bo->seqno,bo->write_seqno, andexec->bin_dep_seqnofrom the driver. As the seqno tracking system is redundant, its deletion is relatively straightforward. The only notable change isvc4_async_set_fence_cb(), which now usesdma_fence_add_callback()to add the VC4 callback.
This series is:
Thanks!
Quoted 40 lines
Changes
=======v1 -> v2: https://lore.kernel.org/dri-devel/[email protected]/T/
* [1/4] Use DRM Exec to replace the (un)lock reservation functions (Christian König)
v2 -> v3: https://lore.kernel.org/dri-devel/[email protected]/T/
* [1/4] König's A-b (Christian König)
* [2/4] s/dma_gem_dma_resv_wait/drm_gem_dma_resv_wait (Melissa Wen)
* [2/4] Useusecs_to_jiffies()to calculate the timeout in jiffies (Tvrtko Ursulin)
* [2/4] Remove-EAGAINerrno from the IOCTL (Tvrtko Ursulin)
* [3/4] s/vc4_async_page_flip_seqno_complete/vc4_async_page_flip_complete_with_cleanup (Melissa Wen)
* [3/4] Adddma_fence_put()invc4_async_page_flip_complete_with_cleanup()
* [3/4] Maxime's R-b (Maxime Ripard)
* [4/4] Squashed to PATCH 3/4 (Melissa Wen)
* [4/4] Removevc4->seqno_cb_listandstruct vc4_seqno_cb(Tvrtko Ursulin)Best Regards,
- Maíra---
Maíra Canal (3):
drm/vc4: Use DRM Execution Contexts drm/vc4: Use DMA Resv to implement VC4 wait BO IOCTL drm/vc4: Remove BOs seqnosdrivers/gpu/drm/vc4/Kconfig | 1 + drivers/gpu/drm/vc4/vc4_crtc.c | 33 +++--- drivers/gpu/drm/vc4/vc4_drv.h | 27 ----- drivers/gpu/drm/vc4/vc4_gem.c | 183 ++++++----------------------- drivers/gpu/drm/vc4/vc4_validate.c | 11 -- 5 files changed, 53 insertions(+), 202 deletions(-)
Maíra Canal
reviewerHi Melissa,
Quoted 28 lines · Melissa Wen
Quoted 24 lines · Maíra Canal
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 Exec to replace the open-coded implementation of the functions
drm_gem_lock_reservations()anddrm_gem_unlock_reservations()in the VC4 driver code. A straightforward change with no functional changes.* Patch #2: Implements the VC4 wait BO IOCTL using DMA Resv Objects. The new implementation closely mirrors the V3D approach and removes the IOCTL's dependency on BO sequence numbers.
Quoted 8 lines
Quoted 5 lines
* Patch #3: The central piece of this patchset. It removes
bo->seqno,bo->write_seqno, andexec->bin_dep_seqnofrom the driver. As the seqno tracking system is redundant, its deletion is relatively straightforward. The only notable change isvc4_async_set_fence_cb(), which now usesdma_fence_add_callback()to add the VC4 callback.This series is:
Reviewed-by Melissa Wen <[email protected]>
Thanks for your review! The series was applied to misc/kernel.git (drm- misc-next).
Best Regards,
- Maíra
Quoted 43 lines
Thanks!
Quoted 40 lines
Changes
=======v1 -> v2: https://lore.kernel.org/dri-devel/20241206131706.203324-1- [email protected]/T/
* [1/4] Use DRM Exec to replace the (un)lock reservation functions (Christian König)
v2 -> v3: https://lore.kernel.org/dri-devel/20241212202337.381614-1- [email protected]/T/
* [1/4] König's A-b (Christian König)
* [2/4] s/dma_gem_dma_resv_wait/drm_gem_dma_resv_wait (Melissa Wen)
* [2/4] Useusecs_to_jiffies()to calculate the timeout in jiffies (Tvrtko Ursulin)
* [2/4] Remove-EAGAINerrno from the IOCTL (Tvrtko Ursulin)
* [3/4] s/vc4_async_page_flip_seqno_complete/vc4_async_page_flip_complete_with_cleanup(Melissa Wen)
* [3/4] Adddma_fence_put()invc4_async_page_flip_complete_with_cleanup()
* [3/4] Maxime's R-b (Maxime Ripard)
* [4/4] Squashed to PATCH 3/4 (Melissa Wen)
* [4/4] Removevc4->seqno_cb_listandstruct vc4_seqno_cb(Tvrtko Ursulin)Best Regards,
- Maíra---
Maíra Canal (3):
drm/vc4: Use DRM Execution Contexts drm/vc4: Use DMA Resv to implement VC4 wait BO IOCTL drm/vc4: Remove BOs seqnosdrivers/gpu/drm/vc4/Kconfig | 1 + drivers/gpu/drm/vc4/vc4_crtc.c | 33 +++--- drivers/gpu/drm/vc4/vc4_drv.h | 27 ----- drivers/gpu/drm/vc4/vc4_gem.c | 183 ++++++-----------------------
drivers/gpu/drm/vc4/vc4_validate.c| 11 --5 files changed, 53 insertions(+), 202 deletions(-)