From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 793EB606A31A for ; Wed, 2 Dec 2026 14:10:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=EyfbBlhA; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=ZK/UhFN2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: References:In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=JJSzPihxK58wTtujlsY8VHsUWbGQ9BoC0sHR95VlR5k=; b=EyfbBlhAS7+qmvWX6wVD+AFbK8 blNYAXhQyFNjnBG60BjfG2IeLCUo3m69KqnckMRkdBYAZsNlSpcrQ9PtHLkrerG8rEE/Yjm/Bysh3 MRJVtgHibiqKUtzkAVQxSNDixPDFTEAItvYATdlyV9/iC4Q0AGc4duqMkFCOrQmD9JPT8ME+fSs85 JAHk2OTpbFZT4aGyGI6ykrbWsKXsL6f6h003mgL5Pa0QvHybIglzNOueSzi7RFiTM3deLATv0u9Zq Iql83frdfhJNfRJxIo15YeuwXjaXWr06BaPlO6xWmKpalvXTLTYr0w8sWtALPczX+ly0nxPKMiERV TfLw2lRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYl1t-0000000BgkN-3rf7; Wed, 02 Dec 2026 14:09:53 +0000 Received: from bali.collaboradmins.com ([148.251.105.195]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYl1q-0000000BgjC-3LQh for linux-arm-kernel@lists.infradead.org; Wed, 02 Dec 2026 14:09:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1796220588; bh=JJSzPihxK58wTtujlsY8VHsUWbGQ9BoC0sHR95VlR5k=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=ZK/UhFN2WVis88EwbpaEqVeR553vAo7QEUdbMGfGZo426WqVMQL+npSD+1WPzzCS8 bUgJzwQoyKARqYZA5Vjm5B+5JkaRznBFlzEqA4Rz3kpJ3FCI1kS4je178qhsjUmDoa zON/4KQw8sRPzL0/DmkaHTEGFMKzpkBok3HI2hcGuOsPJPn8ChB4YPUczlJsAiu+sT T3QCzrVUknyiLHic8M7ykO+JJyUaWCc3ta5b1VmA6VDcoLoiOpuiVi7R3lpp2rgnhq N7VS7z0HWsK/8U1uUplo+/yMiv67S4bj9mQHB+WXOqjeXSbvjKhMlSxipksMRGA90O orThnbjCc3ZnQ== Received: from [100.64.0.214] (unknown [100.64.0.214]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange secp256r1 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: nicolas) by bali.collaboradmins.com (Postfix) with ESMTPSA id F353717E08C6; Wed, 02 Dec 2026 15:09:46 +0100 (CET) Message-ID: Subject: Re: [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture From: Nicolas Dufresne To: Siddharth Vadapalli 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 Date: Wed, 02 Dec 2026 09:09:45 -0500 In-Reply-To: References: <20261129132825.4031308-1-s-vadapalli@ti.com> <20261129132825.4031308-2-s-vadapalli@ti.com> <265be1d1-317c-4831-b5c5-d59ffdd5630f@ti.com> Autocrypt: addr=nicolas.dufresne@collabora.com; prefer-encrypt=mutual; keydata=mDMEaCN2ixYJKwYBBAHaRw8BAQdAM0EHepTful3JOIzcPv6ekHOenE1u0vDG1gdHFrChD /e0J05pY29sYXMgRHVmcmVzbmUgPG5pY29sYXNAbmR1ZnJlc25lLmNhPoicBBMWCgBEAhsDBQsJCA cCAiICBhUKCQgLAgQWAgMBAh4HAheABQkJZfd1FiEE7w1SgRXEw8IaBG8S2UGUUSlgcvQFAmibrjo CGQEACgkQ2UGUUSlgcvQlQwD/RjpU1SZYcKG6pnfnQ8ivgtTkGDRUJ8gP3fK7+XUjRNIA/iXfhXMN abIWxO2oCXKf3TdD7aQ4070KO6zSxIcxgNQFtDFOaWNvbGFzIER1ZnJlc25lIDxuaWNvbGFzLmR1Z nJlc25lQGNvbGxhYm9yYS5jb20+iJkEExYKAEECGwMFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4 AWIQTvDVKBFcTDwhoEbxLZQZRRKWBy9AUCaCyyxgUJCWX3dQAKCRDZQZRRKWBy9ARJAP96pFmLffZ smBUpkyVBfFAf+zq6BJt769R0al3kHvUKdgD9G7KAHuioxD2v6SX7idpIazjzx8b8rfzwTWyOQWHC AAS0LU5pY29sYXMgRHVmcmVzbmUgPG5pY29sYXMuZHVmcmVzbmVAZ21haWwuY29tPoiZBBMWCgBBF iEE7w1SgRXEw8IaBG8S2UGUUSlgcvQFAmibrGYCGwMFCQll93UFCwkIBwICIgIGFQoJCAsCBBYCAw ECHgcCF4AACgkQ2UGUUSlgcvRObgD/YnQjfi4+L8f4fI7p1pPMTwRTcaRdy6aqkKEmKsCArzQBAK8 bRLv9QjuqsE6oQZra/RB4widZPvphs78H0P6NmpIJ Organization: Collabora Canada Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-9CLbmZLFclHwSykJfQvw" User-Agent: Evolution 3.62.1 (3.62.1-1.fc45) X-Archived-By: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261202_060951_007192_688CA039 X-CRM114-Status: GOOD ( 56.59 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-5.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 --=-9CLbmZLFclHwSykJfQvw Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Le mercredi 02 d=C3=A9cembre 2026 =C3=A0 11:26 +0530, Siddharth Vadapalli a= =C3=A9crit=C2=A0: > Hello Nicolas, >=20 > On 12/2/26 12:59 AM, Nicolas Dufresne wrote: > > Hi Siddharth, > >=20 > > Le mardi 01 d=C3=A9cembre 2026 =C3=A0 10:56 +0530, Siddharth Vadapalli = a =C3=A9crit=C2=A0: > > > > device caches can spawn a worker that will signal the fence when th= e 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, un= less you only > > > > care about really slow devices, introduce very tight timing which o= nly dma > > > > fences will really cover. > > > On platforms where sub-frames work without DMA Fences (Hardware-Manag= ed > > > Coherence or ARM64 pgprot_dmacoherent mapping), I assume that the lat= ency > > > advantage is noticeable (as documented in the cover-letter). The usag= e 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. > > >=20 > > > Kindly let me know what you think regarding this and please correct m= e in > > > case I have misunderstood your proposition for the usage of DMA Fence= s. I > > > look forward to your feedback. > >=20 > > 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 recei= ver > > point of view what I had in mind: > >=20 > > - 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 > >=20 > > At this point, the buffer is empty, but userspace software can already > > start programming the lower half of the ultra-low latency pipeline. > >=20 > > Software component would simply poll on the fence, like they would do f= or > > 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. > >=20 > > 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 trigge= r > > the next block with the smallest possible latency really. > >=20 > > To continue the video reveiver: > >=20 > > - HW signal sync point 0 (irq), fence 0 is signalled > > - ... > > - HW signal sync point N, fence N is signalled > >=20 > > You cannot really achieve all this with just the V4L2 event alone. Reme= mber > > that this is how video games maximize their use of GPU hardware, its re= ally > > 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 gi= ve > > control over it, its unsafe. > Thank you for explaining your proposition in detail. I agree that my=20 > earlier point about the DMA fence signaling latency was incorrect because= =20 > the driver on the SoC (j721e-csi2rx.c) polls for DMA progress using=20 > HRTIMERs as a trigger to measure progress and it does _not_ get interrupt= s=20 > for sub-frame completion. >=20 > Just to be sure that I have understood it correctly, I am attempting to= =20 > describe it below: >=20 > 1. Instead of a V4L2 event every sub-frame, there should be just one even= t=20 > at the start of a new frame. > 2. The event at the start of a new frame should contain an array of DMA= =20 > Fences passed via a sync_file file-descriptor containing Fence0, Fence1,= =20 > ....until the last sub-frame is covered > 3. Userspace applications can submit the DMA Fence file-descriptors to a= =20 > Video-Processing Pipeline > 4. When sub-frame X completes, the Capture Driver (CSI2RX in the case of= =20 > this patch series) in its IRQ handler will invoke dma_fence_signal(fence_= X)=20 > to notify completion of sub-frame X and the Video-Processing Pipeline tha= t=20 > was polling on the DMA Fence for sub-frame X can start processing that= =20 > 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. >=20 > If my description above is accurate, then, I would like to list a few=20 > 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=20 > rely on a HRTIMER-based approach where DMA-progress is tracked via the DM= A=20 > 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=20 > example), the number of sync-points and therefore their corresponding=20 > File-Descriptors for a given Frame will be large. For 1280x720 resolution= =20 > at 30 FPS and the sub-frame size being 10 lines, it will mean 72=20 > sync-points per frame (i.e. sub-frames) at 30 FPS which is about 2,160= =20 > File-Descriptors being created and destroyed every second. At 60 FPS, it= =20 > will be even higher with a value of 4,320. Overhead here is that of=20 > sync_file allocation and installation involving locking. Additionally, if= a=20 > userspace application that consumes the sync_file slows down momentarily = or=20 > isn't scheduled for a short period, the number of FDs that are open will= =20 > increase and lead to a ulimit exhaustion for that application/process.= =20 > Moreover, each FD has an associated 'open' and 'close' syscall overhead a= s=20 > 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= =20 > data[64]) which can only accommodate up to 14 Fence FDs (4 Bytes for=20 > 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. >=20 > It appears to me that the current patch series and your proposition are= =20 > addressing different problems: > For Coherent platforms, the current patch series is a lightweight and=20 > simple approach to enable sub-frames at a fine granularity to lower the= =20 > 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)= ,=20 > your proposition of a DMA Fence based approach with the aforementioned= =20 > overhead and a limited sub-frame granularity at the cost of a relatively= =20 > higher latency is suited. >=20 > Therefore, I would like to know if the current series is acceptable with= =20 > the predefined scope of Coherent platforms with the aim of being a=20 > lightweight implementation that provides high sub-frame granularity and l= ow=20 > latency. Kindly let me know if you have any suggestion regarding other wa= ys=20 > of implementing this while still taking advantage of Coherence and keepin= g=20 > 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 --=-9CLbmZLFclHwSykJfQvw Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQTvDVKBFcTDwhoEbxLZQZRRKWBy9AUCaxAmqQAKCRDZQZRRKWBy 9AffAQD/N20SZPSOg9hVjTTRPzhsB38leZhr3Nwg22ZdMrPq/AEAxo4KGWDuZCNb baptxYVCuF/qsyKjzEQwN5UWjFXuGQE= =5Ley -----END PGP SIGNATURE----- --=-9CLbmZLFclHwSykJfQvw--