Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp528352rdh; Thu, 23 Nov 2023 10:22:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0MxxWhowXZTEGcOy/16BVbzQQbgTM8YhR4hf9acnXYhZdONVKHHfhcJS9j49C5Owi5lw7 X-Received: by 2002:a17:903:181:b0:1cf:6bdf:7642 with SMTP id z1-20020a170903018100b001cf6bdf7642mr306671plg.18.1700763758614; Thu, 23 Nov 2023 10:22:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700763758; cv=none; d=google.com; s=arc-20160816; b=fxJV0pEP8rxcx2ZphGslA/V19mvjzaJp27zl8RPHyEV+bJQBZL22gYL5IIm+BV9rDu 67X3F/S17BvZR8hDe64s4czaJUDwBnQNYXmZDEs8Hd70eA1TeH3sBghdbgfO+svtRwUF M0Fqc+TyAO7JVsOm731RP7kYwuAmOEUlF9TPe+ajAv399dRcBzc/Wj2fsFV9QCfTbGrJ TOT/Dq4lWRcTvO34ORi+3c3kEweglnR+PaWkqCPR5s1etOcAK9dXmf2fr+cbpEajcysf s7d+ZNE0aaMXnsXSMA4Nq+a8ikMfWf/AQYycDRtRuFiS3MCpmQctX3OLQfPxv2QDu5ej mBNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=QgSFVLXdiiVlFncJG5xnGMZmf3/Lcv/2SbxbrtDMVHM=; fh=JjHIJhRS7dTgzE5DKN2YOdrIkIrCSldrSqWl1B20vHg=; b=DmZBpRDs6X7qXB2tSYVCraP0fLoqt+D+mCnv2hs1A7TWHjeSquft83G3aq0ge8Cbdn teAIWTkK+orpdANbh6J3m5tIJOUQdKUPQl5IOWpaUDLWkeMprS4iqE4z3YeCvWddPkl6 3CFIztViz7O8aTkiaHd3rbwNCrX2LXgNaEpDhGwq5A2idRYZM6FYhN8fTiXY0BAT2+DY Nq4FHSjVErr+g/K4N7AYcpIEbqhs/OVXCStFxMn28pB7Hl3C7wZinpChTqMQrvOc7Na/ HVen4E3mbgKEfnMq+O/8T+RrbU/S9LwKzldvbcUVq4/0TvJaHeLJWcyLz8Pszbjkf1Uq PZaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ndufresne-ca.20230601.gappssmtp.com header.s=20230601 header.b=zEn7F6RB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id l13-20020a170903120d00b001cf7e523594si1644240plh.439.2023.11.23.10.22.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 10:22:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@ndufresne-ca.20230601.gappssmtp.com header.s=20230601 header.b=zEn7F6RB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 70E1F8068A01; Thu, 23 Nov 2023 10:22:35 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230156AbjKWSWJ (ORCPT + 99 others); Thu, 23 Nov 2023 13:22:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbjKWSWI (ORCPT ); Thu, 23 Nov 2023 13:22:08 -0500 Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99EA0DD for ; Thu, 23 Nov 2023 10:22:14 -0800 (PST) Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-1f5d2e4326fso674540fac.0 for ; Thu, 23 Nov 2023 10:22:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ndufresne-ca.20230601.gappssmtp.com; s=20230601; t=1700763733; x=1701368533; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=QgSFVLXdiiVlFncJG5xnGMZmf3/Lcv/2SbxbrtDMVHM=; b=zEn7F6RBkQg1dH+lgFglNvoTr4hfTWzcvCZOl7p+4Lqkb3KCsHK7DETy6Vbk9IyCzq g803IXMLZXdNZGJ8BMyh3F+8ylJc+H0XWJEg+J2WqniB4SRnRyGUdvSjBBvDUTnZRAHl s60gZPTbiC5t+oxZ7PKVLOBYUn8bjqY/9FtzoYB7RRmiC8YA1qKuzPzA25AHJOH7AfmP TTL5Ta9ikXinurYqsRo/nPF4ikjXGYRQ7LsY3rMPGpfkxlaX6xPyVnHBeo3uLCyTJs+w BKtcq/YTGjXdAWGPujZTFgoUF8Yt6k9a6uGhz5n9Il7EnMmse4KRcHSUHB0o36Hq74PM od9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700763733; x=1701368533; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=QgSFVLXdiiVlFncJG5xnGMZmf3/Lcv/2SbxbrtDMVHM=; b=PfVSQs1cguSiorypRG+BgkprVEKrS7S+u5ohEgJL63DEFY6G+ZEGwi+8WDRT4QeDPE 3IZSP9o5cBBRKh2re84Pgi2iKaJbfUAUvv7/a2JYPrsE8qa2+KDl34lVT6WI41NA1U+6 0674qs9ekptzSo/GjitFrEyAAakRn9Q1tt7kHcGEM7vCoIID6QTfStcYVJgabKEndeT8 mV3V6Ke9k+bdgHSjCB+C8PuxV1ExSDuEUAS8lK3mVrQ3RTG+eNae0cq0J17lMcUTZasp f3iTc4tvBvPhr8zQPCI79bVTtJ6o051i/zrv3iybQTfO4DbI7VU7a8a5Kp+3+oEgZxNP eryw== X-Gm-Message-State: AOJu0YyNRwKeOQ+i9o/+tgympO0C7gPIGME1AfZ4R0j7TGNOKoFX/0nL JkgOaMlcu3ePSFU9kpQd2TBfrw== X-Received: by 2002:a05:6870:c6a5:b0:1f0:597d:fe25 with SMTP id cv37-20020a056870c6a500b001f0597dfe25mr111773oab.45.1700763733463; Thu, 23 Nov 2023 10:22:13 -0800 (PST) Received: from nicolas-tpx395.localdomain ([2606:6d00:10:3ac8::7a9]) by smtp.gmail.com with ESMTPSA id d13-20020a0cf6cd000000b0067a063e606asm697875qvo.52.2023.11.23.10.22.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 10:22:12 -0800 (PST) Message-ID: Subject: Re: [PATCH v2] media: uvcvideo: Implement V4L2_EVENT_FRAME_SYNC From: Nicolas Dufresne To: Ricardo Ribalda , Laurent Pinchart Cc: Esker Wong , Kieran Bingham , Sakari Ailus , Esker Wong , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 23 Nov 2023 13:22:11 -0500 In-Reply-To: References: <20231106-uvc-event-v2-1-7d8e36f0df16@chromium.org> <03ac47742945cc04e4663b87563b47a96ed3ec1f.camel@ndufresne.ca> <20231109000327.GE21616@pendragon.ideasonboard.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 23 Nov 2023 10:22:35 -0800 (PST) Le jeudi 09 novembre 2023 =C3=A0 01:27 +0100, Ricardo Ribalda a =C3=A9crit= =C2=A0: > Hi Laurent >=20 > On Thu, 9 Nov 2023 at 01:03, Laurent Pinchart > wrote: > >=20 > > Hi Ricardo, > >=20 > > On Wed, Nov 08, 2023 at 11:46:40PM +0100, Ricardo Ribalda wrote: > > > On Wed, 8 Nov 2023 at 21:32, wrote: > > > >=20 > > > > The fact that you interpret the time from FRAME_SYNC to DQBUF (well= the > > > > READ IO notification) as the actual latency is yours of course. It > > > > assumes that the camera on the other end does not introduce other > > >=20 > > > We want to use this signal to measure how much power is used since we > > > start receiving the frame until we can use it. > > > I agree with you that the latency between capture and dqbuf should be > > > measured using the timestamp. That is not our use case here. > > >=20 > > > > source of latency (or that these are negligible). You are also goin= g to > > > > introduce a lot of jitter, since it relies on when the OS decides t= o > > > > wake up your process. > > >=20 > > > We have measured a jitter of around 2.5 msec, which is acceptable for= our needs. > > >=20 > > > > I think my opinion resides in if you can accurately *enough* implem= ent > > > > what the spec says for FRAME_SYNC then do it, otherwise just don't = lie. > > >=20 > > > What the specs says is: > > > ``` > > > Triggered immediately when the reception of a frame has begun > > > ``` > > > In my opinion, that is true for usb devices, we are triggering it as > > > soon as the transfer has started to the eyes of the driver. We cannot > > > trigger earlier than that. > > >=20 > > >=20 > > > > I think for ISO, "after the first chunk" i a small lie, but accepta= ble. > > > > But for BULK, the way it was explained is that it will be always ve= ry > > > > close to DQBUF time. and it should not emit FRAME_SYNC for this typ= e of > > > > UVC device. If it fits other events fine of course, I'm just making= a > > > > judgment on if its fits V4L2_EVENT_FRAME_SYNC or not. > > >=20 > > > nit: I believe that you have swapped iso and bulk on this description > >=20 > > I've confused the USB packet size and the UVC payload size. The latter > > is typically much bigger for bulk devices than isoc devices, but the > > former will be in similar order of magnitudes in a large number of > > cases, but not all cases. > >=20 > > The URB size is the result of the USB packet size and number of packets > > per URB. The uvcvideo driver currently sets the number of packets per > > URB to 32 at most (and lowers it if the frame size is small, or if not > > enough memory can be allocated). This could be increased or made dynami= c > > in the future, as higher speeds typically benefit from larger URB sizes= . > > The packet size differs between bulk and isoc endpoints. > >=20 > > For bulk, the packet size can be up to 512 bytes for USB 2.0 and 1024 > > bytes for USB 3.0, and the device can select a smaller size. The larges= t > > URB size (again based on the current implementation of the uvcvideo > > driver) is thus 32 KiB. > >=20 > > For isochronous the situation is more complicated. The term "packet" as > > used in the uvcvideo driver actually means all the data transferred in > > one service interval, thus made of multiple isoc packets. It is heavily > > dependent on the USB speed, and the device can advertise different > > supported sizes (which translate directly to the reserved bandwidth for > > the transfer), with the driver picking the smallest bandwidth large > > enough for the data rate required by the resolution and frame rate. The > > theoretical worst case is 1024 bytes per isoc packet * 16 isoc packets > > per burst * 6 burst per interval * 32 "packets" per URB, equal to 3 MiB= . > >=20 > > Even with the largest URB size you have witnessed of ~1 MiB, we will en= d > > up lying quite a bit if we consider the URB completion callback for the > > first URB of the frame as indicating the start of reception. > >=20 > > > > In term of accuracy, if timestamp was passed with the FRAME_SYNC ev= ent, > > > > it would not matter how fast your process the event anymore and gre= atly > > > > improve accuracy. > > >=20 > > > +1 to that. If we could easily change the uAPI for FRAME_SYNC that > > > should definitely be implemented. > > >=20 > > > > > Not to mention that the UVC timestamping requires a bit of love. > > > > >=20 > > > > > @Laurent Pinchart, @Kieran Bingham any progress reviewing :P : > > > > > https://patchwork.linuxtv.org/project/linux-media/list/?series=3D= 10083 > > > >=20 > > > > Thanks for working on this by the way, hope someone will find the t= ime > > > > to review this. The timestamps should in theory provide a jitter fr= ee > > >=20 > > > It already has a couple of Reviewed-by stamped in.... ;) > > >=20 > > > > measurement of the delay Esker is trying to measure, and if it wasn= 't > > > > of bugs (and crazy complexity) it would in the worst case match the > > > > transfer time. > > >=20 > > > Sorry to repeat myself, but just to avoid the confusion: Esker needs > > > to know how much power is used since we start receiving a frame until > > > it is available for dqbuf, not de frame latency. > >=20 > > As I think everybody is aware, the earliest notification you get on the > > CPU side is the *end* of reception of the first URB, which can possibly > > be significantly later than the start of reception of the frame. > >=20 > > Based on what I understand, the goal is to measure the CPU power > > consumption related to CPU processing of the frame. If that's the case, > > there's good and bad news. The good news is that the CPU doesn't proces= s > > the frame at all until the URB has been received (if you were to measur= e > > the power consumption of the USB host controller too, it would be a > > different story), so the delay shouldn't be a problem. The bad news is > > that I don't see how the information you're trying to get will help you= , > > as there's plenty of other things unrelated to the uvcvideo driver that > > can take CPU time while a frame is being received. That may not be any > > of my business, but from the point of view of the uvcvideo driver, I'm > > less inclined to accept a possibly significant V4L2_EVENT_FRAME_SYNC li= e > > if the use case ends up making little sense :-) >=20 > Just to add some numbers to add some context: >=20 > V4L2_EVENT_FRAME_SYNC for BULK and ISO will be delayed from: > ``` > Triggered immediately when the reception of a frame has begun > ``` > one urb. >=20 > For bulk devices this is a maximum of 0.05 msec (32KiB/600MBps) I lack a bit of knowledge on how to scale this to different devices, with different speed/framesize. My only bulk device is: https://inogeni.com/product/4k2usb3/ Which is USB 3.0, and have raw (NV12) resolution from 640x480 (max 60pfs) t= o 4K (max 30fps). What would the error look like with that ? > For 1MiB transfer isoc devices (which is the biggest we have seen), > that is 1.8 msec. > In both cases, this is smaller than the jitter to process the event > itself by userspace. >=20 > The time from V4L2_EVENT_FRAME_SYNC to DQBUF is around 30 msec. >=20 > I do not know how much delay is considered acceptable... but if we > take the delay argument to the extreme, we could say that > V4L2_EVENT_FRAME_SYNC can never be implemented, because the event will > always be delayed by something. We have v4l2_event.timestamp for all events, so the jitter to process the e= vent by userpace can be removed reliably already. Nicolas p.s. missed it earlier >=20 > >=20 > > -- > > Regards, > >=20 > > Laurent Pinchart >=20 >=20 >=20