Message ID | 20231106-uvc-event-v3-1-c2d2fdaa2e2c@chromium.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2575868vqu; Mon, 6 Nov 2023 03:01:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IF2XWi6bbrFPBQAeGx8id53GzDMjNFRpVSli22vabIzVI+juziTV+TcNuRZvTvhOkWFFML9 X-Received: by 2002:a05:6a20:6a09:b0:138:2fb8:6c48 with SMTP id p9-20020a056a206a0900b001382fb86c48mr25718972pzk.8.1699268499527; Mon, 06 Nov 2023 03:01:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699268499; cv=none; d=google.com; s=arc-20160816; b=Oy+RPLdlAw74p1sea/h8UPJqZoa5tY7CNNc15bT3FZzV0Z8rRdARWbcUOO3qmmfQzl 9JQePTz1c6CdJSOUbbUR+80vjRhDJNqd5IxxzM3GPaeQrzb7UdxImSQogPHhM/RlhjR5 SP5px1uYyAGChbmFrDs9TccGlTd83uPBq/i6zDT7s5sj5+nSd82AAoyOkIN6SSpk6cUT esM2qhiFNyrp02LSLb+PQ0WTyLWiljBrzh5GfHnr/ey0IDbHi3nwWh7WYpUSiGvZn5Nq M4B+T+xszno70emJgEf+FLzPMHkY6HqQnGkkZ4g8xxfePoz2tUxPsDJNMaDE2aCrB5x5 S3mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=i8Lc9yhYdHhhQyrx1NZSXf9nwg/wEFSRP4DUBdcsGag=; fh=juUYT8HK8LGpjZXsXX23mnx6oe4bv7mQPkb8s5QbVrc=; b=cPK9/Hl3WNM9RprhNF/Mqdv+I4rPGnity/9tab+64nCht/eQy/mMXlv2o+++kQDCIZ aEfwrK9C80uriTLSdAk9hxONx0bA1czWxY147Om3UW5xN066nRzHQQa56sFqaKKKGGeD ElvqsO/qU5WC/dWc37hVS+CM/KRBt0/j522Fj0iGc6B5y50H5GxEsCtHTytKtCiaBX2f 5HCZrZrLidukLwmJ0qYIW3fW/DgAwKUXaKsoeEtoSrjVOcKA/RbtrWMCDhOd9oIqGmKJ O86wOFBWCcENWryBFpzEZDURywXcYTOJr44rqd/Ib7cHxxwmnrn7thTBazMDAtRKuDOq agWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FiTrByRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id jx5-20020a170903138500b001cc32df8ecesi7383388plb.513.2023.11.06.03.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:01:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FiTrByRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 75F55808E8E5; Mon, 6 Nov 2023 03:01:35 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231348AbjKFLA6 (ORCPT <rfc822;jaysivo@gmail.com> + 36 others); Mon, 6 Nov 2023 06:00:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231230AbjKFLA4 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 6 Nov 2023 06:00:56 -0500 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29B72D69 for <linux-kernel@vger.kernel.org>; Mon, 6 Nov 2023 03:00:51 -0800 (PST) Received: by mail-qk1-x733.google.com with SMTP id af79cd13be357-7789cb322deso282240385a.3 for <linux-kernel@vger.kernel.org>; Mon, 06 Nov 2023 03:00:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1699268449; x=1699873249; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=i8Lc9yhYdHhhQyrx1NZSXf9nwg/wEFSRP4DUBdcsGag=; b=FiTrByRLW/8vJfATcUPWsChwGVkH6eyJeGKrUuSrXCLrNiZghNCqKTJZ0tdkr19due zrYUc5KWMmXhqQ0FeAc2a79NR7NMiFqIhhlPUq20Vl1L68eEGaawpGpijncQ6YJK+Z70 J5UOViZ+UDty4kb6liEiiR1k09mkWasmMaPxk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699268449; x=1699873249; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=i8Lc9yhYdHhhQyrx1NZSXf9nwg/wEFSRP4DUBdcsGag=; b=fO+G11OCUIwBh/yqabN4PfE356HfUHBr6EyHn0XC/7HYzgvVP+LzE4IB/Ay5iBDGPF PVi3G0JsTjKGw94TfvO1rCCNM/ADCOs7dXb1R/Tgr5/o8IrDmoyB2w/+SbDvMjCL6X6w Uze2NiIVVWftLUO9b6UnEhQBhQydAuHeha/PV7L+8ggFLZWaxNGDWZkSbsBGCSXT1x9W 31lBjF9l+X+2PlVMBZuoOBMnZPykso+n/YdqfRqxvUfdfoxRh3qeziajFzOn50ksh0Ns OxVw5Dr48Od7Jan4VjQIvIEQTNUrkMV1bvHdtVjiRGnM/BtLDl4VfnZEKJVg9lcLtSrq viag== X-Gm-Message-State: AOJu0Yws4PdJyZAKUmG76fP3kY0udGwr2EwHh7EH+P8QlKtOi2mbLn8k HeBftstesCNNecOPcE6zdO7Ydg== X-Received: by 2002:a05:620a:2908:b0:76c:e2db:42b0 with SMTP id m8-20020a05620a290800b0076ce2db42b0mr34443254qkp.64.1699268449628; Mon, 06 Nov 2023 03:00:49 -0800 (PST) Received: from denia.c.googlers.com (112.49.199.35.bc.googleusercontent.com. [35.199.49.112]) by smtp.gmail.com with ESMTPSA id e15-20020a05620a12cf00b0076eee688a95sm3208519qkl.0.2023.11.06.03.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:00:49 -0800 (PST) From: Ricardo Ribalda <ribalda@chromium.org> Date: Mon, 06 Nov 2023 11:00:30 +0000 Subject: [PATCH v3] media: uvcvideo: Implement V4L2_EVENT_FRAME_SYNC MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231106-uvc-event-v3-1-c2d2fdaa2e2c@chromium.org> X-B4-Tracking: v=1; b=H4sIAE3HSGUC/22Nyw7CIBREf6VhLYZHROvK/zAueFwKSQsNtETT9 N+l3WiMyzOZM7OgDMlDRtdmQQmKzz6GCvzQIO1k6AB7UxkxwjgljOC5aAwFwoQNN1QpZbRiFtW +khmwSjJoV40w930NxwTWP/eD+6Oy83mK6bX/Fbql/6YLxRRzJSWB1or2xG7apTj4eTjG1KFtq LCPTIn4llmVz+YCXFhiLBU/8rqubxbOayb3AAAA To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>, Mauro Carvalho Chehab <mchehab@kernel.org>, Ricardo Ribalda <ribalda@chromium.org> Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Esker Wong <esker@chromium.org> X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 groat.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 06 Nov 2023 03:01:35 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781812166490629617 X-GMAIL-MSGID: 1781812166490629617 |
Series |
[v3] media: uvcvideo: Implement V4L2_EVENT_FRAME_SYNC
|
|
Commit Message
Ricardo Ribalda
Nov. 6, 2023, 11 a.m. UTC
Add support for the frame_sync event, so user-space can become aware earlier of new frames. Suggested-by: Esker Wong <esker@chromium.org> Tested-by: Esker Wong <esker@chromium.org> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> --- We have measured a latency of around 30msecs between frame sync and dqbuf. --- Changes in v3: - Sent wrong patch as v2 sorry :S - Link to v2: https://lore.kernel.org/r/20231106-uvc-event-v2-1-7d8e36f0df16@chromium.org Changes in v2: - Suggested by Laurent. Split sequence++ and event init. - Link to v1: https://lore.kernel.org/r/20231020-uvc-event-v1-1-3baa0e9f6952@chromium.org --- drivers/media/usb/uvc/uvc_v4l2.c | 2 ++ drivers/media/usb/uvc/uvc_video.c | 7 +++++++ 2 files changed, 9 insertions(+) --- base-commit: ce55c22ec8b223a90ff3e084d842f73cfba35588 change-id: 20231020-uvc-event-d3d1bbbdcb2f Best regards,
Comments
Hi Ricardo, Sorry, I missed the whole discussion for the v2 patch. I've now read it and will reply here. On 11/6/23 12:00, Ricardo Ribalda wrote: > Add support for the frame_sync event, so user-space can become aware > earlier of new frames. I don't think this describes why you want this. Specifically, you want to use this to measure latency inside the driver between the arrival of the first USB packet and the time the buffer is dequeued. And this is presumably meant for debugging/measuring, but not for normal capturing. Right? Based on the discussion it looks like everyone is OK with this for the BULK case, and V4L2_EVENT_FRAME_SYNC makes sense to me there. You want to see the sequence number in the event, and the description of the event matches what happens. The problem is the ISOC case where it is debatable if this adds anything. Perhaps in the ISOC case this event shouldn't be supported? Unless you can show that it does provide useful information in the ISOC case. I didn't see that in the v2 discussion, but I might have missed it. Regards, Hans > > Suggested-by: Esker Wong <esker@chromium.org> > Tested-by: Esker Wong <esker@chromium.org> > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> > --- > We have measured a latency of around 30msecs between frame sync > and dqbuf. > --- > Changes in v3: > - Sent wrong patch as v2 sorry :S > - Link to v2: https://lore.kernel.org/r/20231106-uvc-event-v2-1-7d8e36f0df16@chromium.org > > Changes in v2: > - Suggested by Laurent. Split sequence++ and event init. > - Link to v1: https://lore.kernel.org/r/20231020-uvc-event-v1-1-3baa0e9f6952@chromium.org > --- > drivers/media/usb/uvc/uvc_v4l2.c | 2 ++ > drivers/media/usb/uvc/uvc_video.c | 7 +++++++ > 2 files changed, 9 insertions(+) > > diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c > index f4988f03640a..9f3fb5fd2375 100644 > --- a/drivers/media/usb/uvc/uvc_v4l2.c > +++ b/drivers/media/usb/uvc/uvc_v4l2.c > @@ -1352,6 +1352,8 @@ static int uvc_ioctl_subscribe_event(struct v4l2_fh *fh, > switch (sub->type) { > case V4L2_EVENT_CTRL: > return v4l2_event_subscribe(fh, sub, 0, &uvc_ctrl_sub_ev_ops); > + case V4L2_EVENT_FRAME_SYNC: > + return v4l2_event_subscribe(fh, sub, 0, NULL); > default: > return -EINVAL; > } > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c > index 28dde08ec6c5..6a9410133908 100644 > --- a/drivers/media/usb/uvc/uvc_video.c > +++ b/drivers/media/usb/uvc/uvc_video.c > @@ -1073,9 +1073,16 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, > * that discontinuous sequence numbers always indicate lost frames. > */ > if (stream->last_fid != fid) { > + struct v4l2_event event = { > + .type = V4L2_EVENT_FRAME_SYNC, > + }; > + > stream->sequence++; > if (stream->sequence) > uvc_video_stats_update(stream); > + > + event.u.frame_sync.frame_sequence = stream->sequence; > + v4l2_event_queue(&stream->vdev, &event); > } > > uvc_video_clock_decode(stream, buf, data, len); > > --- > base-commit: ce55c22ec8b223a90ff3e084d842f73cfba35588 > change-id: 20231020-uvc-event-d3d1bbbdcb2f > > Best regards,
Hi Hans On Tue, 21 Nov 2023 at 11:37, Hans Verkuil <hverkuil@xs4all.nl> wrote: > > Hi Ricardo, > > Sorry, I missed the whole discussion for the v2 patch. I've now read it and > will reply here. > > On 11/6/23 12:00, Ricardo Ribalda wrote: > > Add support for the frame_sync event, so user-space can become aware > > earlier of new frames. Will fix the description in the next version thanks! > > I don't think this describes why you want this. Specifically, you want to use > this to measure latency inside the driver between the arrival of the first USB > packet and the time the buffer is dequeued. > > And this is presumably meant for debugging/measuring, but not for normal > capturing. Right? > > Based on the discussion it looks like everyone is OK with this for the BULK > case, and V4L2_EVENT_FRAME_SYNC makes sense to me there. You want to see the > sequence number in the event, and the description of the event matches what > happens. > > The problem is the ISOC case where it is debatable if this adds anything. > > Perhaps in the ISOC case this event shouldn't be supported? Unless you can > show that it does provide useful information in the ISOC case. I didn't see > that in the v2 discussion, but I might have missed it. There are the following times - t_exposure: Time when the exposure happens. We can get it from v4l2_buffer.timestamp based on the hw timestamp - t_usb_first: Time when the first usb frame arrives at the usb host. We cannot get it (or better said.. I do not know how to get it) - t_urb: Time when the first urb is processed by the driver. Implemented as V4L2_EVENT_FRAME_SYNC in this driver - t_dqbuf: Time when the buffer can be dequeded by userspace. Implemented a timestamp in userspace when the syscall finishes. What we would like to measure is (t_dqbuf-t_usb_first), but we cannot obtain t_usb_first. (t_urb-t_usb_first) is relatively small so it can be ignored: For ISO the max we have measured is 1.8 msec vs 31 msec (t_dqbuf-t_urb) (t_urb-t_usb_first) is also always constant. If you are measuring trends, you do not care about an offset. There are two proposed alternatives to this patch: - that we use (t_dqbuf-t_exposure), but that measurement is dependent on the exposure time, so we cannot use that measurement. - use ftrace: but we will have to use different userspace methods for every driver, which defeats the purpose of V4L2_EVENT_FRAME_SYNC, and the metric will be as "bad" as the current proposal. If you are curious you can take a look at a trace here: https://ui.perfetto.dev/#!/?s=061a0fb7ebb0333e5dcbe35f487c18980e8e00a6e1b227c98d5e2569163924e0 Thanks! > > Regards, > > Hans > > > > > Suggested-by: Esker Wong <esker@chromium.org> > > Tested-by: Esker Wong <esker@chromium.org> > > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> > > --- > > We have measured a latency of around 30msecs between frame sync > > and dqbuf. > > --- > > Changes in v3: > > - Sent wrong patch as v2 sorry :S > > - Link to v2: https://lore.kernel.org/r/20231106-uvc-event-v2-1-7d8e36f0df16@chromium.org > > > > Changes in v2: > > - Suggested by Laurent. Split sequence++ and event init. > > - Link to v1: https://lore.kernel.org/r/20231020-uvc-event-v1-1-3baa0e9f6952@chromium.org > > --- > > drivers/media/usb/uvc/uvc_v4l2.c | 2 ++ > > drivers/media/usb/uvc/uvc_video.c | 7 +++++++ > > 2 files changed, 9 insertions(+) > > > > diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c > > index f4988f03640a..9f3fb5fd2375 100644 > > --- a/drivers/media/usb/uvc/uvc_v4l2.c > > +++ b/drivers/media/usb/uvc/uvc_v4l2.c > > @@ -1352,6 +1352,8 @@ static int uvc_ioctl_subscribe_event(struct v4l2_fh *fh, > > switch (sub->type) { > > case V4L2_EVENT_CTRL: > > return v4l2_event_subscribe(fh, sub, 0, &uvc_ctrl_sub_ev_ops); > > + case V4L2_EVENT_FRAME_SYNC: > > + return v4l2_event_subscribe(fh, sub, 0, NULL); > > default: > > return -EINVAL; > > } > > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c > > index 28dde08ec6c5..6a9410133908 100644 > > --- a/drivers/media/usb/uvc/uvc_video.c > > +++ b/drivers/media/usb/uvc/uvc_video.c > > @@ -1073,9 +1073,16 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, > > * that discontinuous sequence numbers always indicate lost frames. > > */ > > if (stream->last_fid != fid) { > > + struct v4l2_event event = { > > + .type = V4L2_EVENT_FRAME_SYNC, > > + }; > > + > > stream->sequence++; > > if (stream->sequence) > > uvc_video_stats_update(stream); > > + > > + event.u.frame_sync.frame_sequence = stream->sequence; > > + v4l2_event_queue(&stream->vdev, &event); > > } > > > > uvc_video_clock_decode(stream, buf, data, len); > > > > --- > > base-commit: ce55c22ec8b223a90ff3e084d842f73cfba35588 > > change-id: 20231020-uvc-event-d3d1bbbdcb2f > > > > Best regards, > -- Ricardo Ribalda
diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index f4988f03640a..9f3fb5fd2375 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1352,6 +1352,8 @@ static int uvc_ioctl_subscribe_event(struct v4l2_fh *fh, switch (sub->type) { case V4L2_EVENT_CTRL: return v4l2_event_subscribe(fh, sub, 0, &uvc_ctrl_sub_ev_ops); + case V4L2_EVENT_FRAME_SYNC: + return v4l2_event_subscribe(fh, sub, 0, NULL); default: return -EINVAL; } diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 28dde08ec6c5..6a9410133908 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1073,9 +1073,16 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, * that discontinuous sequence numbers always indicate lost frames. */ if (stream->last_fid != fid) { + struct v4l2_event event = { + .type = V4L2_EVENT_FRAME_SYNC, + }; + stream->sequence++; if (stream->sequence) uvc_video_stats_update(stream); + + event.u.frame_sync.frame_sequence = stream->sequence; + v4l2_event_queue(&stream->vdev, &event); } uvc_video_clock_decode(stream, buf, data, len);