From: Nicolas Dufresne <nicolas.dufresne@collabora.com>
To: Siddharth Vadapalli <s-vadapalli@ti.com>
Cc: mchehab@kernel.org, jai.luthra@linux.dev,
detlev.casanova@collabora.com, hverkuil+cisco@kernel.org,
sakari.ailus@linux.intel.com, richard.leitner@linux.dev,
jackson.lee@chipsnmedia.com, linux-media@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, devarsht@ti.com,
vigneshr@ti.com, srk@ti.com
Subject: Re: [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture
Date: Wed, 02 Dec 2026 09:09:45 -0500 [thread overview]
Message-ID: <b9c3da26f4875cb7c06a0ba31f56b8099cf654b3.camel@collabora.com> (raw)
In-Reply-To: <d075c74a-a16e-4eac-8079-a9ffbfb7e613@ti.com>
[-- Attachment #1: Type: text/plain, Size: 9005 bytes --]
Hi,
Le mercredi 02 décembre 2026 à 11:26 +0530, Siddharth Vadapalli a écrit :
> 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
That is correct, though you can signal fences from other context too, IRQ
was an example. I had in mind as reference some display controller, that
had N configurable line IRQ. Typically, polling + sub-frame make sense for
slicing such as slice encoding, where you will have at most 16 slices per
frame, with frames being 4K or more worth of raw data.
>
> 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)
Can you explain the real use case where the CPU will actually keep up with
polling and waking up every 10 lines? This is ~0.5ms, or over 2000 wake per
second. The CPU scheduling latency will reach the roof. I don't think
either your design or fences is applicable here.
>
> 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.
Its only a tiny lighter then fences, with the difference that with the V4L2
events nothing happens ahead of the critical point. The overhead is inside
your realtime slices. I think you want a different mechanism then V4L2
event here. One where you don't hammer the kernel CPU scheduler so much.
> 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.
Unfortunately, with the information you provided, I'm not entirely
convinced its a proper API for the task. Of course, I'm just one co-
maintainer, and not entirely focus on acquisition, so Sakari, Laurent, feel
free to overrule me here. I'm obviously playing the devil advocate, with
the concern that if we commit to yet another API in V4L2, we should make
sure we don't do trade-of where a better solution may exist.
So base this additional data, I think we should seek inspiration in the
real-time audio pipelines, but with frame signalling in mind. Your use case
is based on predictable timing, which is how your kernel work. That your HW
does not do SOF directly is unfortunate, but you already said you can
figure it out with hrtimer. It basically mean you can already generate an
accurate timesamp of this and you know the acquisition rate (just like
audio). The SOF is earlier then when you can start processing, so it would
be the perfect time to calculate the deadlines for your frame. These
deadlines can be passed to an RT thread (or non-RT if you don't have a use
case for not being late or very fixed latency), and your process will
simply use the deadlines to decide when to batch the work while maintaining
desired latency. You endup removing VIDIOC calls from your processing loop,
which removes context switches.
Nicolas
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-12-02 14:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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-12-02 14:09 ` Nicolas Dufresne [this message]
2026-12-03 5:04 ` 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b9c3da26f4875cb7c06a0ba31f56b8099cf654b3.camel@collabora.com \
--to=nicolas.dufresne@collabora.com \
--cc=detlev.casanova@collabora.com \
--cc=devarsht@ti.com \
--cc=hverkuil+cisco@kernel.org \
--cc=jackson.lee@chipsnmedia.com \
--cc=jai.luthra@linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=richard.leitner@linux.dev \
--cc=s-vadapalli@ti.com \
--cc=sakari.ailus@linux.intel.com \
--cc=srk@ti.com \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox