Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] media: Add V4L2_EVENT_BUF_PROGRESS and use it in j721e-csi2rx
@ 2026-11-29 13:28 Siddharth Vadapalli
  2026-11-29 13:28 ` [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture Siddharth Vadapalli
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Siddharth Vadapalli @ 2026-11-29 13:28 UTC (permalink / raw)
  To: mchehab, jai.luthra, nicolas.dufresne, detlev.casanova,
	hverkuil+cisco, sakari.ailus, richard.leitner, jackson.lee
  Cc: linux-media, linux-arm-kernel, devarsht, vigneshr, srk,
	s-vadapalli

Hello,

This series adds support for processing sub-frames of a capture buffer
before the whole buffer has been captured, in order to reduce the latency
of video pipelines by a large part of a frame period.

A capture buffer is only returned by VIDIOC_DQBUF once the whole frame has
been captured, and no generic mechanism exists to tell userspace how much
of the buffer has been written. The series adds:

1. V4L2_EVENT_BUF_PROGRESS, a generic event which reports the number of
   bytes from the start of a buffer that have been written so far.
2. V4L2_CID_BUF_PROGRESS_SIZE and V4L2_CID_BUF_PROGRESS_INTERVAL, which
   select the granularity of the event in lines and the interval at which
   a driver that has to sample the progress does so.
3. Support in the TI J721E CSI2RX driver. A single DMA descriptor is used
   for each frame, which only completes at the end of the frame. Hence,
   the progress is sampled periodically using dmaengine_tx_status() from
   a high resolution timer.

The vb2 buffer life cycle is not changed. A buffer is still returned by
VIDIOC_DQBUF at the end of the frame, and the last event for a buffer that
completed successfully is queued before that.

Series is based on linux-next tagged next-20261127.

Series has been tested on the AM62A7-SK board with the AM62Ax SoC of
Texas Instruments connected to the OV5640 Sensor.

Timestamping the v4l2 EVENTS without sub-frames enabled shows about 33
milliseconds of interval between frames corresponding to the 30 FPS
frame-rate for a 1280x720 resolution. Enabling sub-frames with each
sub-frame being 10 lines and the polling interval for HRTIMERS being
100 microseconds using the following commands:
v4l2-ctl -d /dev/video3 --set-ctrl=buffer_progress_size=10
v4l2-ctl -d /dev/video3 --set-ctrl=buffer_progress_interval=100
shows each sub-frame being queued to the v4l2 event queue every
258 microseconds on average (with a total of 72 such sub-frames
i.e. 720 / 10) resulting in the entire frame now being queued by
18.5 milliseconds and a blanking period of 14.8 milliseconds.
This not only proves sub-frame queueing to v4l2 event queue but also
shows that the OV5640 sensor which also supports 60 FPS seems to have
the frame ready by about 18.5 milliseconds even when operating at 30 FPS.

Early processing of the sub-frames by userspace applications not only
reduce the latency but also provide a safe guard-band when the Sensor has
a blanking period as seen in the specific experimental setup described
above. Given the benefits and the use-cases that can be enabled with this
series, I hope to receive feedback on the implementation with the
objective of eventually having it supported in Mainline Linux.

Regards,
Siddharth.

Siddharth Vadapalli (3):
  media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture
  media: v4l2-ctrls: Add buffer progress controls for sub-frame
    functionality
  media: ti: j721e-csi2rx: Generate capture-progress events for
    sub-frames

 .../userspace-api/media/v4l/control.rst       |  21 ++
 .../media/v4l/videodev2.h.rst.exceptions      |   1 +
 .../media/v4l/vidioc-dqevent.rst              |  74 ++++++
 .../platform/ti/j721e-csi2rx/j721e-csi2rx.c   | 251 +++++++++++++++++-
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |   2 +
 include/uapi/linux/v4l2-controls.h            |   5 +-
 include/uapi/linux/videodev2.h                |  18 ++
 7 files changed, 366 insertions(+), 6 deletions(-)

-- 
2.56.0



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture
  2026-11-29 13:28 [PATCH 0/3] media: Add V4L2_EVENT_BUF_PROGRESS and use it in j721e-csi2rx Siddharth Vadapalli
@ 2026-11-29 13:28 ` Siddharth Vadapalli
  2026-11-30 15:21   ` Nicolas Dufresne
  2026-11-29 13:28 ` [PATCH 2/3] media: v4l2-ctrls: Add buffer progress controls for sub-frame functionality Siddharth Vadapalli
  2026-11-29 13:28 ` [PATCH 3/3] media: ti: j721e-csi2rx: Generate capture-progress events for sub-frames Siddharth Vadapalli
  2 siblings, 1 reply; 8+ messages in thread
From: Siddharth Vadapalli @ 2026-11-29 13:28 UTC (permalink / raw)
  To: mchehab, jai.luthra, nicolas.dufresne, detlev.casanova,
	hverkuil+cisco, sakari.ailus, richard.leitner, jackson.lee
  Cc: linux-media, linux-arm-kernel, devarsht, vigneshr, srk,
	s-vadapalli

A capture buffer is only returned by VIDIOC_DQBUF once the whole frame
has been captured. For low latency pipelines that want to start processing
sub-frames (group of lines in a frame), there is currently no way to
identify how much of the capture buffer has been filled. This results in a
fixed latency overhead corresponding to the frame-rate because the
processing can only start after the entire frame has been captured.

Add V4L2_EVENT_BUF_PROGRESS, which reports the number of bytes from the
start of a buffer that have been written so far, thereby allowing
subscribers to determine the valid portion of the capture buffer and
start processing the valid sub-frame. When a buffer is completed
successfully, the last event for it is queued before the buffer is
returned by VIDIOC_DQBUF, so a subscriber can determine the end-of-frame
from that event alone.

The event payload has space reserved for future extensions. The bytesused
field is only defined for queues of a single-planar buffer type. This event
is generic and does not depend on the format.

Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
---
 .../media/v4l/videodev2.h.rst.exceptions      |  1 +
 .../media/v4l/vidioc-dqevent.rst              | 74 +++++++++++++++++++
 include/uapi/linux/videodev2.h                | 18 +++++
 3 files changed, 93 insertions(+)

diff --git a/Documentation/userspace-api/media/v4l/videodev2.h.rst.exceptions b/Documentation/userspace-api/media/v4l/videodev2.h.rst.exceptions
index 6182b4e2d2ee..b02f5dd07cab 100644
--- a/Documentation/userspace-api/media/v4l/videodev2.h.rst.exceptions
+++ b/Documentation/userspace-api/media/v4l/videodev2.h.rst.exceptions
@@ -524,6 +524,7 @@ replace define V4L2_EVENT_CTRL event-type
 replace define V4L2_EVENT_FRAME_SYNC event-type
 replace define V4L2_EVENT_SOURCE_CHANGE event-type
 replace define V4L2_EVENT_MOTION_DET event-type
+replace define V4L2_EVENT_BUF_PROGRESS event-type
 replace define V4L2_EVENT_PRIVATE_START event-type
 
 replace define V4L2_EVENT_CTRL_CH_VALUE ctrl-changes-flags
diff --git a/Documentation/userspace-api/media/v4l/vidioc-dqevent.rst b/Documentation/userspace-api/media/v4l/vidioc-dqevent.rst
index 8db103760930..1421ccadab8e 100644
--- a/Documentation/userspace-api/media/v4l/vidioc-dqevent.rst
+++ b/Documentation/userspace-api/media/v4l/vidioc-dqevent.rst
@@ -64,6 +64,9 @@ call.
     * - struct :c:type:`v4l2_event_motion_det`
       - ``motion_det``
       - Event data for event V4L2_EVENT_MOTION_DET.
+    * - struct :c:type:`v4l2_event_buf_progress`
+      - ``buf_progress``
+      - Event data for event ``V4L2_EVENT_BUF_PROGRESS``.
     * - struct :c:type:`v4l2_event_src_change`
       - ``src_change``
       - Event data for event V4L2_EVENT_SOURCE_CHANGE.
@@ -182,6 +185,50 @@ call.
 	the regions changes. This event has a struct
 	:c:type:`v4l2_event_motion_det`
 	associated with it.
+    * - ``V4L2_EVENT_BUF_PROGRESS``
+      - 7
+      - Triggered while a capture buffer is being filled, to report how many
+	bytes from its start have already been written. This allows the
+	leading part of a frame to be processed before the buffer is ready
+	to be dequeued. This event has a struct
+	:c:type:`v4l2_event_buf_progress`
+	associated with it.
+
+	Events are only generated by drivers that support them, and only
+	while the ``V4L2_CID_BUF_PROGRESS_SIZE`` control is non-zero (see
+	:ref:`User Controls <control>`).
+
+	Within one buffer, the ``bytesused`` field only grows. When a buffer
+	is completed successfully, the last event for it, with ``bytesused``
+	equal to the ``bytesused`` of the buffer, is queued before the
+	buffer is returned by :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>`. This last
+	event is always queued, even if fewer than
+	``V4L2_CID_BUF_PROGRESS_SIZE`` lines were written since the previous
+	event.
+
+	No last event is guaranteed for a buffer that is returned with the
+	``V4L2_BUF_FLAG_ERROR`` flag set, or for a buffer that is returned
+	because streaming was stopped with
+	:ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`. Events that were queued
+	for such a buffer have to be ignored. Applications must therefore
+	consider :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` as the authoritative
+	indication of the state of a buffer.
+
+	Events are dropped, oldest first, when the application does not
+	dequeue them in time. Lost events can be detected by a gap in the
+	``sequence`` field of struct :c:type:`v4l2_event`, which is not
+	related to the ``sequence`` field of struct
+	:c:type:`v4l2_event_buf_progress`. Applications must be prepared
+	for intermediate values of ``bytesused`` to be skipped.
+
+	The buffer remains owned by the driver until it is dequeued, and the
+	driver does not perform any cache maintenance on the part of the
+	buffer that was reported. An application that reads that part before
+	the buffer is dequeued must make sure that its mapping is coherent
+	with DMA, which is not the case for memory allocated with
+	``V4L2_MEMORY_FLAG_NON_COHERENT``. For buffers with memory type
+	``V4L2_MEMORY_DMABUF``, cache management is the responsibility of
+	the exporter of the buffer.
     * - ``V4L2_EVENT_PRIVATE_START``
       - 0x08000000
       - Base event number for driver-private events.
@@ -309,6 +356,33 @@ call.
 	automatically assigned to the default region 0.
 
 
+.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
+
+.. c:type:: v4l2_event_buf_progress
+
+.. flat-table:: struct v4l2_event_buf_progress
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u32
+      - ``index``
+      - The index of the buffer that is being filled.
+    * - __u32
+      - ``sequence``
+      - The sequence number the buffer will be dequeued with.
+    * - __u32
+      - ``bytesused``
+      - The number of bytes from the start of the buffer that have been
+	written so far. This field is only defined for queues of a
+	single-planar buffer type. A driver that generates this event on a
+	multi-planar queue has to document the meaning of this field.
+    * - __u32
+      - ``reserved``\ [5]
+      - Reserved for future extensions. Drivers must set the array to
+	zero.
+
+
 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}|
 
 .. _ctrl-changes-flags:
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 5373dba640fa..a019f481167e 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -2558,6 +2558,7 @@ struct v4l2_streamparm {
 #define V4L2_EVENT_FRAME_SYNC			4
 #define V4L2_EVENT_SOURCE_CHANGE		5
 #define V4L2_EVENT_MOTION_DET			6
+#define V4L2_EVENT_BUF_PROGRESS		7
 #define V4L2_EVENT_PRIVATE_START		0x08000000
 
 /* Payload for V4L2_EVENT_VSYNC */
@@ -2611,6 +2612,22 @@ struct v4l2_event_motion_det {
 	__u32 region_mask;
 };
 
+/**
+ * struct v4l2_event_buf_progress - buffer fill progress event
+ * @index:		index of the buffer that is being filled.
+ * @sequence:		sequence number the buffer will be dequeued with.
+ * @bytesused:		number of bytes from the start of the buffer that
+ *			have been written so far.
+ * @reserved:		reserved for future extensions, drivers must set
+ *			the array to zero.
+ */
+struct v4l2_event_buf_progress {
+	__u32 index;
+	__u32 sequence;
+	__u32 bytesused;
+	__u32 reserved[5];
+};
+
 struct v4l2_event {
 	__u32				type;
 	union {
@@ -2619,6 +2636,7 @@ struct v4l2_event {
 		struct v4l2_event_frame_sync	frame_sync;
 		struct v4l2_event_src_change	src_change;
 		struct v4l2_event_motion_det	motion_det;
+		struct v4l2_event_buf_progress	buf_progress;
 		__u8				data[64];
 	} u;
 	__u32				pending;
-- 
2.56.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] media: v4l2-ctrls: Add buffer progress controls for sub-frame functionality
  2026-11-29 13:28 [PATCH 0/3] media: Add V4L2_EVENT_BUF_PROGRESS and use it in j721e-csi2rx Siddharth Vadapalli
  2026-11-29 13:28 ` [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture Siddharth Vadapalli
@ 2026-11-29 13:28 ` Siddharth Vadapalli
  2026-11-29 13:28 ` [PATCH 3/3] media: ti: j721e-csi2rx: Generate capture-progress events for sub-frames Siddharth Vadapalli
  2 siblings, 0 replies; 8+ messages in thread
From: Siddharth Vadapalli @ 2026-11-29 13:28 UTC (permalink / raw)
  To: mchehab, jai.luthra, nicolas.dufresne, detlev.casanova,
	hverkuil+cisco, sakari.ailus, richard.leitner, jackson.lee
  Cc: linux-media, linux-arm-kernel, devarsht, vigneshr, srk,
	s-vadapalli

The V4L2_EVENT_BUF_PROGRESS event is generated whenever N lines in a
capture buffer are ready to be consumed by a subscriber. Two controls
associated with this event are:
1. Number of lines 'N' after which the event should be generated.
2. Interval 'I' at which the buffer progress has to be queried by the
   driver to detect the readiness of the next 'N' lines.

Hence, add V4L2_CID_BUF_PROGRESS_SIZE and V4L2_CID_BUF_PROGRESS_INTERVAL
controls which respectively correspond to the controls described above.

Since the event is generated by the capture DMA engine and not by the
image source, the controls are not specific to cameras. Hence, add them to
the user control class instead of the camera control class.

Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
---
 .../userspace-api/media/v4l/control.rst       | 21 +++++++++++++++++++
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |  2 ++
 include/uapi/linux/v4l2-controls.h            |  5 ++++-
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/Documentation/userspace-api/media/v4l/control.rst b/Documentation/userspace-api/media/v4l/control.rst
index 19372bb32c4b..7dcf7c80a0d8 100644
--- a/Documentation/userspace-api/media/v4l/control.rst
+++ b/Documentation/userspace-api/media/v4l/control.rst
@@ -316,6 +316,27 @@ Control IDs
     set the alpha component value of all pixels for further processing
     in the device.
 
+``V4L2_CID_BUF_PROGRESS_SIZE`` ``(integer)``
+    Granularity of the :ref:`V4L2_EVENT_BUF_PROGRESS <event-type>` event, in
+    lines. While a capture buffer is being filled, the driver queues the
+    event each time at least this many additional complete lines have been
+    written to it. The event that reports the completion of the buffer is
+    always queued, even if fewer lines were written since the previous
+    event. If the value is not smaller than the height of the frame, the
+    only event that is queued for a buffer is the one that reports its
+    completion. The value 0, which is the default, disables the event. The
+    control is only supported by drivers that generate the event, and its
+    value cannot be changed while the device is streaming.
+
+``V4L2_CID_BUF_PROGRESS_INTERVAL`` ``(integer)``
+    Interval, in microseconds, at which a driver that has to sample the
+    progress of the buffer being filled does so for the
+    :ref:`V4L2_EVENT_BUF_PROGRESS <event-type>` event. A shorter interval
+    reduces the delay between lines being written and the event being
+    queued, at the cost of a higher CPU load. The control is only supported
+    by drivers that have to sample the progress, and its value cannot be
+    changed while the device is streaming.
+
 ``V4L2_CID_LASTP1``
     End of the predefined control IDs (currently
     ``V4L2_CID_ALPHA_COMPONENT`` + 1).
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
index e062f2088490..e9bbe40e8d33 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
@@ -831,6 +831,8 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_ALPHA_COMPONENT:		return "Alpha Component";
 	case V4L2_CID_COLORFX_CBCR:		return "Color Effects, CbCr";
 	case V4L2_CID_COLORFX_RGB:              return "Color Effects, RGB";
+	case V4L2_CID_BUF_PROGRESS_SIZE:	return "Buffer Progress Size";
+	case V4L2_CID_BUF_PROGRESS_INTERVAL:	return "Buffer Progress Interval";
 
 	/*
 	 * Codec controls
diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
index d17e41d51d2e..4e05f63bcf12 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -110,8 +110,11 @@ enum v4l2_colorfx {
 #define V4L2_CID_COLORFX_CBCR			(V4L2_CID_BASE+42)
 #define V4L2_CID_COLORFX_RGB			(V4L2_CID_BASE+43)
 
+#define V4L2_CID_BUF_PROGRESS_SIZE		(V4L2_CID_BASE+44)
+#define V4L2_CID_BUF_PROGRESS_INTERVAL		(V4L2_CID_BASE+45)
+
 /* last CID + 1 */
-#define V4L2_CID_LASTP1                         (V4L2_CID_BASE+44)
+#define V4L2_CID_LASTP1                         (V4L2_CID_BASE+46)
 
 /* USER-class private control IDs */
 
-- 
2.56.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] media: ti: j721e-csi2rx: Generate capture-progress events for sub-frames
  2026-11-29 13:28 [PATCH 0/3] media: Add V4L2_EVENT_BUF_PROGRESS and use it in j721e-csi2rx Siddharth Vadapalli
  2026-11-29 13:28 ` [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture Siddharth Vadapalli
  2026-11-29 13:28 ` [PATCH 2/3] media: v4l2-ctrls: Add buffer progress controls for sub-frame functionality Siddharth Vadapalli
@ 2026-11-29 13:28 ` Siddharth Vadapalli
  2 siblings, 0 replies; 8+ messages in thread
From: Siddharth Vadapalli @ 2026-11-29 13:28 UTC (permalink / raw)
  To: mchehab, jai.luthra, nicolas.dufresne, detlev.casanova,
	hverkuil+cisco, sakari.ailus, richard.leitner, jackson.lee
  Cc: linux-media, linux-arm-kernel, devarsht, vigneshr, srk,
	s-vadapalli

A capture buffer is only returned to userspace once the whole frame has
been captured. For low latency use-cases, generate capture-progress events
(V4L2_EVENT_BUF_PROGRESS) to allow userspace applications to consume and
start processing sub-frames.

Since a single DMA descriptor is associated with an entire video frame,
completion of descriptors queued to DMA cannot be an indicator of the
readiness of sub-frames. Hence, use the standard dmaengine_tx_status()
dmaengine API to query progress of the capture. Additionally, use the
High Resolution Timers in Linux to trigger the query periodically.

The number of lines in a sub-frame for which the capture-progress event
has to be generated is set using V4L2_CID_BUF_PROGRESS_SIZE. If number
of lines is set to '0', the capture-progress event is disabled. For a
valid value of the number of lines in a sub-frame, the event is generated.
Similarly, the interval at which the capture-progress has to be sampled
is set using V4L2_CID_BUF_PROGRESS_INTERVAL, which is limited to a minimum
of 100 microseconds to bound the CPU load that userspace can cause.

The parameters are sampled at the start and cannot be modified in the
middle of streaming. They can however be modified when streaming is not in
progress.

Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
---
 .../platform/ti/j721e-csi2rx/j721e-csi2rx.c   | 251 +++++++++++++++++-
 1 file changed, 246 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
index ba7abb723da6..79d2118301fe 100644
--- a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
+++ b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
@@ -10,6 +10,7 @@
 
 #include <linux/bitfield.h>
 #include <linux/dmaengine.h>
+#include <linux/hrtimer.h>
 #include <linux/module.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
@@ -18,7 +19,9 @@
 
 #include <media/cadence/cdns-csi2rx.h>
 #include <media/mipi-csi2.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-device.h>
+#include <media/v4l2-event.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-mc.h>
 #include <media/videobuf2-dma-contig.h>
@@ -66,6 +69,11 @@
 
 #define CSI2RX_BRIDGE_SOURCE_PAD	1
 
+#define TI_CSI2RX_PROGRESS_EVENTS		32
+#define TI_CSI2RX_PROGRESS_INTERVAL_MIN	100
+#define TI_CSI2RX_PROGRESS_INTERVAL_MAX	5000
+#define TI_CSI2RX_PROGRESS_INTERVAL_DEF	200
+
 struct ti_csi2rx_fmt {
 	u32				fourcc;	/* Four character code. */
 	u32				code;	/* Mbus code. */
@@ -79,6 +87,7 @@ struct ti_csi2rx_buffer {
 	struct vb2_v4l2_buffer		vb;
 	struct list_head		list;
 	struct ti_csi2rx_ctx		*ctx;
+	dma_cookie_t			cookie;
 };
 
 enum ti_csi2rx_dma_state {
@@ -100,6 +109,16 @@ struct ti_csi2rx_dma {
 	struct list_head		submitted;
 };
 
+struct ti_csi2rx_progress {
+	struct hrtimer			timer;
+	ktime_t				period;
+	u32				lines;
+	struct ti_csi2rx_buffer		*cur;
+	u32				last;
+	u32				base;
+	bool				have_base;
+};
+
 struct ti_csi2rx_dev;
 
 struct ti_csi2rx_ctx {
@@ -109,6 +128,10 @@ struct ti_csi2rx_ctx {
 	struct mutex			mutex; /* To serialize ioctls. */
 	struct v4l2_format		v_fmt;
 	struct ti_csi2rx_dma		dma;
+	struct ti_csi2rx_progress	progress;
+	struct v4l2_ctrl_handler	ctrl_hdl;
+	struct v4l2_ctrl		*ctrl_progress_size;
+	struct v4l2_ctrl		*ctrl_progress_interval;
 	struct media_pad		pad;
 	struct completion		drain_complete;
 	u32				sequence;
@@ -427,6 +450,20 @@ static int ti_csi2rx_enum_framesizes(struct file *file, void *fh,
 	return 0;
 }
 
+static int ti_csi2rx_subscribe_event(struct v4l2_fh *fh,
+				     const struct v4l2_event_subscription *sub)
+{
+	switch (sub->type) {
+	case V4L2_EVENT_CTRL:
+		return v4l2_ctrl_subscribe_event(fh, sub);
+	case V4L2_EVENT_BUF_PROGRESS:
+		return v4l2_event_subscribe(fh, sub, TI_CSI2RX_PROGRESS_EVENTS,
+					    NULL);
+	default:
+		return -EINVAL;
+	}
+}
+
 static const struct v4l2_ioctl_ops csi_ioctl_ops = {
 	.vidioc_querycap      = ti_csi2rx_querycap,
 	.vidioc_enum_fmt_vid_cap = ti_csi2rx_enum_fmt_vid_cap,
@@ -443,6 +480,8 @@ static const struct v4l2_ioctl_ops csi_ioctl_ops = {
 	.vidioc_expbuf        = vb2_ioctl_expbuf,
 	.vidioc_streamon      = vb2_ioctl_streamon,
 	.vidioc_streamoff     = vb2_ioctl_streamoff,
+	.vidioc_subscribe_event = ti_csi2rx_subscribe_event,
+	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
 };
 
 static const struct v4l2_file_operations csi_fops = {
@@ -728,6 +767,157 @@ static int ti_csi2rx_dma_submit_pending(struct ti_csi2rx_ctx *ctx)
 	return ret;
 }
 
+static void ti_csi2rx_progress_event(struct ti_csi2rx_buffer *buf,
+				     struct ti_csi2rx_ctx *ctx, u32 sequence,
+				     u32 bytesused)
+{
+	struct v4l2_event ev = {
+		.type = V4L2_EVENT_BUF_PROGRESS,
+		.u.buf_progress = {
+			.index = buf->vb.vb2_buf.index,
+			.sequence = sequence,
+			.bytesused = bytesused,
+		},
+	};
+
+	v4l2_event_queue(&ctx->vdev, &ev);
+}
+
+static void ti_csi2rx_progress_sample(struct ti_csi2rx_ctx *ctx,
+				      struct ti_csi2rx_buffer *buf)
+{
+	struct ti_csi2rx_progress *prog = &ctx->progress;
+	struct v4l2_pix_format *pix = &ctx->v_fmt.fmt.pix;
+	struct dma_tx_state st = { };
+	u32 bytes, lines;
+
+	if (buf != prog->cur) {
+		prog->cur = buf;
+		prog->last = 0;
+		prog->have_base = false;
+	}
+
+	if (dmaengine_tx_status(ctx->dma.chan, buf->cookie, &st) !=
+	    DMA_IN_PROGRESS)
+		return;
+
+	if (st.residue > pix->sizeimage)
+		return;
+
+	if (!prog->have_base) {
+		prog->base = st.residue;
+		prog->have_base = true;
+	}
+
+	bytes = (prog->base + pix->sizeimage - st.residue) % pix->sizeimage;
+
+	lines = bytes / pix->bytesperline;
+	lines -= lines % prog->lines;
+	if (lines <= prog->last || lines >= pix->height)
+		return;
+
+	prog->last = lines;
+	ti_csi2rx_progress_event(buf, ctx, ctx->sequence,
+				 lines * pix->bytesperline);
+}
+
+static enum hrtimer_restart ti_csi2rx_progress_timer(struct hrtimer *timer)
+{
+	struct ti_csi2rx_ctx *ctx = container_of(timer, struct ti_csi2rx_ctx,
+						 progress.timer);
+	struct ti_csi2rx_dma *dma = &ctx->dma;
+	struct ti_csi2rx_buffer *buf;
+	unsigned long flags;
+
+	spin_lock_irqsave(&dma->lock, flags);
+
+	buf = list_first_entry_or_null(&dma->submitted,
+				       struct ti_csi2rx_buffer, list);
+	if (buf && dma->state == TI_CSI2RX_DMA_ACTIVE && ctx->progress.lines)
+		ti_csi2rx_progress_sample(ctx, buf);
+
+	spin_unlock_irqrestore(&dma->lock, flags);
+
+	hrtimer_forward_now(timer, ctx->progress.period);
+
+	return HRTIMER_RESTART;
+}
+
+static void ti_csi2rx_progress_start(struct ti_csi2rx_ctx *ctx)
+{
+	struct ti_csi2rx_progress *prog = &ctx->progress;
+	u32 lines, interval;
+	unsigned long flags;
+
+	v4l2_ctrl_grab(ctx->ctrl_progress_size, true);
+	v4l2_ctrl_grab(ctx->ctrl_progress_interval, true);
+
+	lines = v4l2_ctrl_g_ctrl(ctx->ctrl_progress_size);
+	interval = v4l2_ctrl_g_ctrl(ctx->ctrl_progress_interval);
+
+	if (!lines)
+		return;
+
+	prog->period = ns_to_ktime((u64)interval * NSEC_PER_USEC);
+
+	spin_lock_irqsave(&ctx->dma.lock, flags);
+	prog->lines = lines;
+	prog->cur = NULL;
+	spin_unlock_irqrestore(&ctx->dma.lock, flags);
+
+	hrtimer_start(&prog->timer, prog->period, HRTIMER_MODE_REL_SOFT);
+}
+
+static void ti_csi2rx_progress_pause(struct ti_csi2rx_ctx *ctx)
+{
+	struct ti_csi2rx_progress *prog = &ctx->progress;
+	unsigned long flags;
+
+	hrtimer_cancel(&prog->timer);
+
+	spin_lock_irqsave(&ctx->dma.lock, flags);
+	prog->cur = NULL;
+	spin_unlock_irqrestore(&ctx->dma.lock, flags);
+}
+
+static void ti_csi2rx_progress_resume(struct ti_csi2rx_ctx *ctx)
+{
+	struct ti_csi2rx_progress *prog = &ctx->progress;
+	unsigned long flags;
+
+	spin_lock_irqsave(&ctx->dma.lock, flags);
+	if (prog->lines)
+		hrtimer_start(&prog->timer, prog->period,
+			      HRTIMER_MODE_REL_SOFT);
+	spin_unlock_irqrestore(&ctx->dma.lock, flags);
+}
+
+static void ti_csi2rx_progress_stop(struct ti_csi2rx_ctx *ctx)
+{
+	struct ti_csi2rx_progress *prog = &ctx->progress;
+	unsigned long flags;
+
+	spin_lock_irqsave(&ctx->dma.lock, flags);
+	prog->lines = 0;
+	prog->cur = NULL;
+	spin_unlock_irqrestore(&ctx->dma.lock, flags);
+
+	hrtimer_cancel(&prog->timer);
+
+	v4l2_ctrl_grab(ctx->ctrl_progress_size, false);
+	v4l2_ctrl_grab(ctx->ctrl_progress_interval, false);
+}
+
+static void ti_csi2rx_progress_done(struct ti_csi2rx_ctx *ctx,
+				    struct ti_csi2rx_buffer *buf)
+{
+	if (!ctx->progress.lines)
+		return;
+
+	ti_csi2rx_progress_event(buf, ctx, buf->vb.sequence,
+				 ctx->v_fmt.fmt.pix.sizeimage);
+}
+
 static void ti_csi2rx_dma_callback(void *param)
 {
 	struct ti_csi2rx_buffer *buf = param;
@@ -735,21 +925,23 @@ static void ti_csi2rx_dma_callback(void *param)
 	struct ti_csi2rx_dma *dma = &ctx->dma;
 	unsigned long flags;
 
+	spin_lock_irqsave(&dma->lock, flags);
+
+	WARN_ON(!list_is_first(&buf->list, &dma->submitted));
+
 	/*
 	 * TODO: Derive the sequence number from the CSI2RX frame number
 	 * hardware monitor registers.
 	 */
 	buf->vb.vb2_buf.timestamp = ktime_get_ns();
 	buf->vb.sequence = ctx->sequence++;
-
-	spin_lock_irqsave(&dma->lock, flags);
-
-	WARN_ON(!list_is_first(&buf->list, &dma->submitted));
+	ctx->progress.cur = NULL;
 
 	if (dma->state == TI_CSI2RX_DMA_DRAINING) {
 		vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
 		dma->state = TI_CSI2RX_DMA_ACTIVE;
 	} else {
+		ti_csi2rx_progress_done(ctx, buf);
 		vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
 	}
 
@@ -790,6 +982,8 @@ static int ti_csi2rx_start_dma(struct ti_csi2rx_ctx *ctx,
 	if (ret)
 		return ret;
 
+	buf->cookie = cookie;
+
 	dma_async_issue_pending(ctx->dma.chan);
 
 	return 0;
@@ -1013,6 +1207,8 @@ static int ti_csi2rx_start_streaming(struct vb2_queue *vq, unsigned int count)
 	if (ret)
 		goto err_dma;
 
+	ti_csi2rx_progress_start(ctx);
+
 	return 0;
 
 err_dma:
@@ -1033,6 +1229,8 @@ static void ti_csi2rx_stop_streaming(struct vb2_queue *vq)
 	struct ti_csi2rx_dev *csi = ctx->csi;
 	int ret;
 
+	ti_csi2rx_progress_stop(ctx);
+
 	video_device_pipeline_stop(&ctx->vdev);
 
 	ret = v4l2_subdev_disable_streams(&csi->subdev,
@@ -1297,6 +1495,8 @@ static void ti_csi2rx_cleanup_ctx(struct ti_csi2rx_ctx *ctx)
 
 	video_unregister_device(&ctx->vdev);
 
+	v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
+
 	mutex_destroy(&ctx->mutex);
 }
 
@@ -1480,6 +1680,33 @@ static int ti_csi2rx_v4l2_init(struct ti_csi2rx_dev *csi)
 	return ret;
 }
 
+static int ti_csi2rx_init_ctrls(struct ti_csi2rx_ctx *ctx)
+{
+	struct v4l2_ctrl_handler *hdl = &ctx->ctrl_hdl;
+
+	v4l2_ctrl_handler_init(hdl, 2);
+
+	ctx->ctrl_progress_size = v4l2_ctrl_new_std(hdl, NULL,
+						    V4L2_CID_BUF_PROGRESS_SIZE,
+						    0, MAX_HEIGHT_LINES, 1, 0);
+	ctx->ctrl_progress_interval =
+		v4l2_ctrl_new_std(hdl, NULL, V4L2_CID_BUF_PROGRESS_INTERVAL,
+				  TI_CSI2RX_PROGRESS_INTERVAL_MIN,
+				  TI_CSI2RX_PROGRESS_INTERVAL_MAX, 1,
+				  TI_CSI2RX_PROGRESS_INTERVAL_DEF);
+
+	if (hdl->error) {
+		int ret = hdl->error;
+
+		v4l2_ctrl_handler_free(hdl);
+		return ret;
+	}
+
+	ctx->vdev.ctrl_handler = hdl;
+
+	return 0;
+}
+
 static int ti_csi2rx_init_ctx(struct ti_csi2rx_ctx *ctx)
 {
 	struct ti_csi2rx_dev *csi = ctx->csi;
@@ -1526,11 +1753,17 @@ static int ti_csi2rx_init_ctx(struct ti_csi2rx_ctx *ctx)
 	INIT_LIST_HEAD(&ctx->dma.submitted);
 	spin_lock_init(&ctx->dma.lock);
 	ctx->dma.state = TI_CSI2RX_DMA_STOPPED;
+	hrtimer_setup(&ctx->progress.timer, ti_csi2rx_progress_timer,
+		      CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
 
-	ret = ti_csi2rx_init_dma(ctx);
+	ret = ti_csi2rx_init_ctrls(ctx);
 	if (ret)
 		return ret;
 
+	ret = ti_csi2rx_init_dma(ctx);
+	if (ret)
+		goto cleanup_ctrls;
+
 	ret = ti_csi2rx_init_vb2q(ctx);
 	if (ret)
 		goto cleanup_dma;
@@ -1539,6 +1772,8 @@ static int ti_csi2rx_init_ctx(struct ti_csi2rx_ctx *ctx)
 
 cleanup_dma:
 	dma_release_channel(ctx->dma.chan);
+cleanup_ctrls:
+	v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
 	return ret;
 }
 
@@ -1597,6 +1832,8 @@ static int ti_csi2rx_suspend(struct device *dev)
 		spin_unlock_irqrestore(&dma->lock, flags);
 
 		if (state != TI_CSI2RX_DMA_STOPPED) {
+			ti_csi2rx_progress_pause(ctx);
+
 			/* Disable source */
 			ret = v4l2_subdev_disable_streams(&csi->subdev,
 							  TI_CSI2RX_PAD_FIRST_SOURCE + ctx->idx,
@@ -1643,6 +1880,8 @@ static int ti_csi2rx_resume(struct device *dev)
 		dma = &ctx->dma;
 		spin_lock_irqsave(&dma->lock, flags);
 		if (dma->state != TI_CSI2RX_DMA_STOPPED) {
+			ctx->progress.cur = NULL;
+
 			/* Re-submit all previously submitted buffers to DMA */
 			list_for_each_entry(buf, &ctx->dma.submitted, list) {
 				ti_csi2rx_start_dma(ctx, buf);
@@ -1657,6 +1896,8 @@ static int ti_csi2rx_resume(struct device *dev)
 							 BIT(0));
 			if (ret)
 				dev_err(ctx->csi->dev, "Failed to start subdev\n");
+
+			ti_csi2rx_progress_resume(ctx);
 		} else {
 			spin_unlock_irqrestore(&dma->lock, flags);
 		}
-- 
2.56.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture
  2026-11-29 13:28 ` [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture Siddharth Vadapalli
@ 2026-11-30 15:21   ` Nicolas Dufresne
  2026-12-01  5:26     ` Siddharth Vadapalli
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Dufresne @ 2026-11-30 15:21 UTC (permalink / raw)
  To: Siddharth Vadapalli, mchehab, jai.luthra, detlev.casanova,
	hverkuil+cisco, sakari.ailus, richard.leitner, jackson.lee
  Cc: linux-media, linux-arm-kernel, devarsht, vigneshr, srk

[-- Attachment #1: Type: text/plain, Size: 1235 bytes --]

Hi,

Le dimanche 29 novembre 2026 à 18:58 +0530, Siddharth Vadapalli a écrit :
> +	The buffer remains owned by the driver until it is dequeued, and the
> +	driver does not perform any cache maintenance on the part of the
> +	buffer that was reported. An application that reads that part before
> +	the buffer is dequeued must make sure that its mapping is coherent
> +	with DMA, which is not the case for memory allocated with
> +	``V4L2_MEMORY_FLAG_NON_COHERENT``. For buffers with memory type
> +	``V4L2_MEMORY_DMABUF``, cache management is the responsibility of
> +	the exporter of the buffer.


I think outside of write-combine, which you likely use, this is completely
unusable. Its not possible to do device cache management properly without the
context the driver has.

May I propose for the event to deliver a dma fence. Then the driver that do use
device caches can spawn a worker that will signal the fence when the memory is
actually ready. On top of which, you can deliver the fence once the transfer is
proven to have started, rather then when its complet. Sub-frame, unless you only
care about really slow devices, introduce very tight timing which only dma
fences will really cover.

Nicolas

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture
  2026-11-30 15:21   ` Nicolas Dufresne
@ 2026-12-01  5:26     ` Siddharth Vadapalli
  2026-12-01 19:29       ` Nicolas Dufresne
  0 siblings, 1 reply; 8+ messages in thread
From: Siddharth Vadapalli @ 2026-12-01  5:26 UTC (permalink / raw)
  To: Nicolas Dufresne
  Cc: mchehab, jai.luthra, detlev.casanova, hverkuil+cisco,
	sakari.ailus, richard.leitner, jackson.lee, linux-media,
	linux-arm-kernel, devarsht, vigneshr, srk, s-vadapalli

On 11/30/26 8:51 PM, Nicolas Dufresne wrote:
> Hi,
> 
> Le dimanche 29 novembre 2026 à 18:58 +0530, Siddharth Vadapalli a écrit :
>> +	The buffer remains owned by the driver until it is dequeued, and the
>> +	driver does not perform any cache maintenance on the part of the
>> +	buffer that was reported. An application that reads that part before
>> +	the buffer is dequeued must make sure that its mapping is coherent
>> +	with DMA, which is not the case for memory allocated with
>> +	``V4L2_MEMORY_FLAG_NON_COHERENT``. For buffers with memory type
>> +	``V4L2_MEMORY_DMABUF``, cache management is the responsibility of
>> +	the exporter of the buffer.
> 
> 
> I think outside of write-combine, which you likely use, this is completely
> unusable. Its not possible to do device cache management properly without the
> context the driver has.

The limitation has been documented to warn users. While I agree that 
'write-combine' (pgprot_writecombine / pgprot_dmacoherent mapping on ARM64) 
is one scenario where this is usable, there is another scenario as well 
where it is usable => Hardware-Managed Coherence.

    On the J784S4 SoC from TI, the MSMC (Multicore Shared Memory 
Controller) guarantees Coherence between DMA transactions and the ARM 
Cortex-A Cores running Linux. So a partial frame transfer to RAM (System 
Memory) by DMA will also be kept in-sync with the Cortex-A Cores' view of 
memory without the need for explicit cache-management.

> 
> May I propose for the event to deliver a dma fence. Then the driver that do use

I believe that a DMA Fence defeats the purpose here given that the 
objective is to reduce the latency. Adding DMA Fence for sub-frames will 
add a latency overhead and at that point we don't get a real benefit with 
sub-frames anymore.

> device caches can spawn a worker that will signal the fence when the memory is
> actually ready. On top of which, you can deliver the fence once the transfer is
> proven to have started, rather then when its complet. Sub-frame, unless you only
> care about really slow devices, introduce very tight timing which only dma
> fences will really cover.
On platforms where sub-frames work without DMA Fences (Hardware-Managed 
Coherence or ARM64 pgprot_dmacoherent mapping), I assume that the latency 
advantage is noticeable (as documented in the cover-letter). The usage of 
DMA Fences will cover other platforms as well, but that would defeat the 
purpose of sub-frames due to higher latency. Hence, a limited support for 
sub-frames looks better despite not being supported on all platforms.

Kindly let me know what you think regarding this and please correct me in 
case I have misunderstood your proposition for the usage of DMA Fences. I 
look forward to your feedback.

Regards,
Siddharth.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture
  2026-12-01  5:26     ` Siddharth Vadapalli
@ 2026-12-01 19:29       ` Nicolas Dufresne
  2026-12-02  5:56         ` Siddharth Vadapalli
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Dufresne @ 2026-12-01 19:29 UTC (permalink / raw)
  To: Siddharth Vadapalli
  Cc: mchehab, jai.luthra, detlev.casanova, hverkuil+cisco,
	sakari.ailus, richard.leitner, jackson.lee, linux-media,
	linux-arm-kernel, devarsht, vigneshr, srk

[-- Attachment #1: Type: text/plain, Size: 2593 bytes --]

Hi Siddharth,

Le mardi 01 décembre 2026 à 10:56 +0530, Siddharth Vadapalli a écrit :
> > device caches can spawn a worker that will signal the fence when the memory is
> > actually ready. On top of which, you can deliver the fence once the transfer is
> > proven to have started, rather then when its complet. Sub-frame, unless you only
> > care about really slow devices, introduce very tight timing which only dma
> > fences will really cover.
> On platforms where sub-frames work without DMA Fences (Hardware-Managed 
> Coherence or ARM64 pgprot_dmacoherent mapping), I assume that the latency 
> advantage is noticeable (as documented in the cover-letter). The usage of 
> DMA Fences will cover other platforms as well, but that would defeat the 
> purpose of sub-frames due to higher latency. Hence, a limited support for 
> sub-frames looks better despite not being supported on all platforms.
> 
> Kindly let me know what you think regarding this and please correct me in 
> case I have misunderstood your proposition for the usage of DMA Fences. I 
> look forward to your feedback.

I really don't see your logic how DMA fence has **much higher latency**
then polling for a V4L2 event. But let's me describe from a video receiver
point of view what I had in mind:

- HW signals the start frame
- As needed, update the sub-frame signalling (e.g. if it changed)
- Emit one V4L2 event with an array of fences for each sync point

At this point, the buffer is empty, but userspace software can already
start programming the lower half of the ultra-low latency pipeline.

Software component would simply poll on the fence, like they would do for
the V4L2 event. With the benefit that each thread can have its own poll, so
you can wake directly in the thread doing the processing.

For hardware component, ideally they handle fences in the kernel. This is
true for all the GPU and NPU driver today, V4L2 is lagging behind. This
way, driver can go as far as using dma_fence_add_callback(), and trigger
the next block with the smallest possible latency really.

To continue the video reveiver:

- HW signal sync point 0 (irq), fence 0 is signalled
- ...
- HW signal sync point N, fence N is signalled

You cannot really achieve all this with just the V4L2 event alone. Remember
that this is how video games maximize their use of GPU hardware, its really
mean to achieve the best. Another aspect is that fences can be safely
shared accross process, where if you share you v4l2 device, you also give
control over it, its unsafe.

Nicolas

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture
  2026-12-01 19:29       ` Nicolas Dufresne
@ 2026-12-02  5:56         ` Siddharth Vadapalli
  0 siblings, 0 replies; 8+ messages in thread
From: Siddharth Vadapalli @ 2026-12-02  5:56 UTC (permalink / raw)
  To: Nicolas Dufresne
  Cc: mchehab, jai.luthra, detlev.casanova, hverkuil+cisco,
	sakari.ailus, richard.leitner, jackson.lee, linux-media,
	linux-arm-kernel, devarsht, vigneshr, srk, s-vadapalli

Hello Nicolas,

On 12/2/26 12:59 AM, Nicolas Dufresne wrote:
> Hi Siddharth,
> 
> Le mardi 01 décembre 2026 à 10:56 +0530, Siddharth Vadapalli a écrit :
>>> device caches can spawn a worker that will signal the fence when the memory is
>>> actually ready. On top of which, you can deliver the fence once the transfer is
>>> proven to have started, rather then when its complet. Sub-frame, unless you only
>>> care about really slow devices, introduce very tight timing which only dma
>>> fences will really cover.
>> On platforms where sub-frames work without DMA Fences (Hardware-Managed
>> Coherence or ARM64 pgprot_dmacoherent mapping), I assume that the latency
>> advantage is noticeable (as documented in the cover-letter). The usage of
>> DMA Fences will cover other platforms as well, but that would defeat the
>> purpose of sub-frames due to higher latency. Hence, a limited support for
>> sub-frames looks better despite not being supported on all platforms.
>>
>> Kindly let me know what you think regarding this and please correct me in
>> case I have misunderstood your proposition for the usage of DMA Fences. I
>> look forward to your feedback.
> 
> I really don't see your logic how DMA fence has **much higher latency**
> then polling for a V4L2 event. But let's me describe from a video receiver
> point of view what I had in mind:
> 
> - HW signals the start frame
> - As needed, update the sub-frame signalling (e.g. if it changed)
> - Emit one V4L2 event with an array of fences for each sync point
> 
> At this point, the buffer is empty, but userspace software can already
> start programming the lower half of the ultra-low latency pipeline.
> 
> Software component would simply poll on the fence, like they would do for
> the V4L2 event. With the benefit that each thread can have its own poll, so
> you can wake directly in the thread doing the processing.
> 
> For hardware component, ideally they handle fences in the kernel. This is
> true for all the GPU and NPU driver today, V4L2 is lagging behind. This
> way, driver can go as far as using dma_fence_add_callback(), and trigger
> the next block with the smallest possible latency really.
> 
> To continue the video reveiver:
> 
> - HW signal sync point 0 (irq), fence 0 is signalled
> - ...
> - HW signal sync point N, fence N is signalled
> 
> You cannot really achieve all this with just the V4L2 event alone. Remember
> that this is how video games maximize their use of GPU hardware, its really
> mean to achieve the best. Another aspect is that fences can be safely
> shared accross process, where if you share you v4l2 device, you also give
> control over it, its unsafe.
Thank you for explaining your proposition in detail. I agree that my 
earlier point about the DMA fence signaling latency was incorrect because 
the driver on the SoC (j721e-csi2rx.c) polls for DMA progress using 
HRTIMERs as a trigger to measure progress and it does _not_ get interrupts 
for sub-frame completion.

Just to be sure that I have understood it correctly, I am attempting to 
describe it below:

1. Instead of a V4L2 event every sub-frame, there should be just one event 
at the start of a new frame.
2. The event at the start of a new frame should contain an array of DMA 
Fences passed via a sync_file file-descriptor containing Fence0, Fence1, 
....until the last sub-frame is covered
3. Userspace applications can submit the DMA Fence file-descriptors to a 
Video-Processing Pipeline
4. When sub-frame X completes, the Capture Driver (CSI2RX in the case of 
this patch series) in its IRQ handler will invoke dma_fence_signal(fence_X) 
to notify completion of sub-frame X and the Video-Processing Pipeline that 
was polling on the DMA Fence for sub-frame X can start processing that 
sub-frame

If my description above is accurate, then, I would like to list a few 
reasons why the above will not work for the SoC/Hardware that I am using:
1. The Hardware doesn't support interrupts for Start-of-Frame and I have to 
rely on a HRTIMER-based approach where DMA-progress is tracked via the DMA 
Engine API (get residue from DMA State using dmaengine_tx_status() API).
2. With the number of lines in a sub-frame being small (10 lines for 
example), the number of sync-points and therefore their corresponding 
File-Descriptors for a given Frame will be large. For 1280x720 resolution 
at 30 FPS and the sub-frame size being 10 lines, it will mean 72 
sync-points per frame (i.e. sub-frames) at 30 FPS which is about 2,160 
File-Descriptors being created and destroyed every second. At 60 FPS, it 
will be even higher with a value of 4,320. Overhead here is that of 
sync_file allocation and installation involving locking. Additionally, if a 
userspace application that consumes the sync_file slows down momentarily or 
isn't scheduled for a short period, the number of FDs that are open will 
increase and lead to a ulimit exhaustion for that application/process. 
Moreover, each FD has an associated 'open' and 'close' syscall overhead as 
well so it translates to about 4,320 x 2 syscalls per second.
3. Currently, "struct v4l2_event" has a payload limit of 64 Bytes (__u8 
data[64]) which can only accommodate up to 14 Fence FDs (4 Bytes for 
Sequence + 4 Bytes for Index + 14 FDs each being 4 Bytes in size)

It appears to me that the current patch series and your proposition are 
addressing different problems:
For Coherent platforms, the current patch series is a lightweight and 
simple approach to enable sub-frames at a fine granularity to lower the 
processing latency as much as possible.
For non-Coherent platforms (not in the scope of the current patch series), 
your proposition of a DMA Fence based approach with the aforementioned 
overhead and a limited sub-frame granularity at the cost of a relatively 
higher latency is suited.

Therefore, I would like to know if the current series is acceptable with 
the predefined scope of Coherent platforms with the aim of being a 
lightweight implementation that provides high sub-frame granularity and low 
latency. Kindly let me know if you have any suggestion regarding other ways 
of implementing this while still taking advantage of Coherence and keeping 
the overhead to a minimum on such platforms.

Lastly, thank you very much for reviewing this patch and providing valuable 
feedback to improve the implementation.

Regards,
Siddharth.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-12-02  5:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 13:28 [PATCH 0/3] media: Add V4L2_EVENT_BUF_PROGRESS and use it in j721e-csi2rx Siddharth Vadapalli
2026-11-29 13:28 ` [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture Siddharth Vadapalli
2026-11-30 15:21   ` Nicolas Dufresne
2026-12-01  5:26     ` Siddharth Vadapalli
2026-12-01 19:29       ` Nicolas Dufresne
2026-12-02  5:56         ` Siddharth Vadapalli
2026-11-29 13:28 ` [PATCH 2/3] media: v4l2-ctrls: Add buffer progress controls for sub-frame functionality Siddharth Vadapalli
2026-11-29 13:28 ` [PATCH 3/3] media: ti: j721e-csi2rx: Generate capture-progress events for sub-frames Siddharth Vadapalli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox