Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3559479ybh; Mon, 5 Aug 2019 21:17:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVpLsh13ekWxVBXv5vXIH6jzslPUX9O9bx9c2CieGRCEi4XJ2VpXeH856zJpKysdw/2Cgs X-Received: by 2002:a63:460d:: with SMTP id t13mr1142203pga.205.1565065025703; Mon, 05 Aug 2019 21:17:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565065025; cv=none; d=google.com; s=arc-20160816; b=DgcqTpDPLh6yGPtQoIs20gXcMW+RaUEs4A5eDoP5DHbkdGhNqQ4tVMKeNF9Gh3LyXE MqGtapq28kOm6VccG1FFiQ/EWG7UTDUiOK6bkXHgaNMGvkVIMlRc3yggELtVvRKSCtqW 9O/jyeWHB4u0JmsogLp+NaH2HQRr00eVzHx84FPEFE2j6tDuCEbCe8Wv8gOoh0i0Kj9J pRkeQSECObbfAqkGENAUvBPi3/TR//lSyuEJCp20SpeO64mieO4LU2/cqPkJjkY9xdbQ 7wlaah9zAREWkoARuYihxR7qaWcozIF7LxtgKqJceHJF402/pmXSEyUDSVO0JVuEOx1Y M0Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=pl4laxveqxbFoLVSBJBsq2q/ipMs/mfndz3RNUveMcY=; b=S2BM84DMJzc8BJrRRaH1hVHIMggQJqDkzFwzZCr5E37xtvLQ7idd9Cs2KRzKdG8lSu 2ydv2baBcden7no2g7+3YUiNmVLlwZLlZ8yR/4Xjm7G+vXQKIMcYZ4ywuKp61KEzgsD2 bwRi+qF1nD+9S2SaBJDOn/fr2za8fE90CnzbiV2sUABGM9wTqSZAR7v9CyPibaezkdAp rMS1RgIgmThMGe0ZTJhfxVifAkEWEB/8zAeHDt3cml1m+Fw0jGEUevczKYjxKeq+mdZZ vGWK5kCMnIqcp4JEmODoCDltB98FFQwtIJJPYnUAdVcbJfJCvaRAQh/foSYw1jwOhO91 Fbyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DzyWmD70; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si11349740pgn.300.2019.08.05.21.16.49; Mon, 05 Aug 2019 21:17:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DzyWmD70; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726373AbfHFEQO (ORCPT + 99 others); Tue, 6 Aug 2019 00:16:14 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:41898 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbfHFEQO (ORCPT ); Tue, 6 Aug 2019 00:16:14 -0400 Received: by mail-ed1-f67.google.com with SMTP id p15so80981316eds.8 for ; Mon, 05 Aug 2019 21:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pl4laxveqxbFoLVSBJBsq2q/ipMs/mfndz3RNUveMcY=; b=DzyWmD70Zod3tb8nY7SBaJ4s0DWTv5hzieoY1t3GEvpTHlT0z0PqeA5HuhuyPtBXeO ssFzaWqQydsNv2erkIXMw18neZsvg1hmc5NXlBGD3cK5nXU8UlbWgbWVvWG1eFtUd9J1 9chrOStlqltKvAyh1pVAZbCTr1c3uxL9tphL8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pl4laxveqxbFoLVSBJBsq2q/ipMs/mfndz3RNUveMcY=; b=Rsw7J39eC+wsxQVZ2U5j21CumiU8PtTL4j0vqXiy5zashku09+BT9NmDl8JJ9zSsRk P4TJmP8HCMaFHfmf/O90P57X4HX6qa86vvtCUKnhmWnTdf51Gtrf6NCqIHvdauGqyl/v BarSLrNOinFFRtLHPgqlJhdDbdFzB1gVAmXSjPo4b/uL5mFS+0DyZyY3WHDEdQP3HroE Dtw4LFB7Dxg6lgXPSWoiUM1eWT7B1t+y7u3G6LzjO/lQTiWhAwlF8G7G9RK6KT+hi9H7 qxFeukUUWQ6Vfb9fajiSG69ZWUk1d+G2bkIb/7lzp5WepkJA1h5mm8Ca3rHYk4ksUqeo sfsg== X-Gm-Message-State: APjAAAWWum8ig2ClQWkXhk6+vZwAJaHeEKfefcsaL4I70HqJVpdt8o2U LLeZZ6Eb26HLMf6LOpbQnBwN3HotSKlawQ== X-Received: by 2002:a17:906:154d:: with SMTP id c13mr1261405ejd.208.1565064971539; Mon, 05 Aug 2019 21:16:11 -0700 (PDT) Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com. [209.85.128.46]) by smtp.gmail.com with ESMTPSA id q13sm19724216edn.92.2019.08.05.21.16.10 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Mon, 05 Aug 2019 21:16:10 -0700 (PDT) Received: by mail-wm1-f46.google.com with SMTP id v19so74971549wmj.5 for ; Mon, 05 Aug 2019 21:16:10 -0700 (PDT) X-Received: by 2002:a1c:407:: with SMTP id 7mr1839604wme.113.1565064969579; Mon, 05 Aug 2019 21:16:09 -0700 (PDT) MIME-Version: 1.0 References: <20181017075242.21790-1-henryhsu@chromium.org> <1610184.U7oo9Z4Yep@avalon> <20190313012451.GR891@pendragon.ideasonboard.com> In-Reply-To: From: Tomasz Figa Date: Tue, 6 Aug 2019 13:15:57 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] media: uvcvideo: Add boottime clock support To: Laurent Pinchart , Kieran Bingham , Hans Verkuil Cc: Alexandru Stan , Lars-Peter Clausen , Gwendal Grignou , Heng-Ruey Hsu , Mauro Carvalho Chehab , Linux Media Mailing List , Linux Kernel Mailing List , Ricky Liang , linux-iio@vger.kernel.org, Jonathan Cameron , Hartmut Knaack , Peter Meerwald-Stadler , =?UTF-8?B?SnVuZ28gTGluICjmnpfmmI7kv4op?= Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 13, 2019 at 11:38 AM Tomasz Figa wrote: > > On Wed, Mar 13, 2019 at 10:25 AM Laurent Pinchart > wrote: > > > > Hi Tomasz, > > > > On Fri, Nov 23, 2018 at 11:46:43PM +0900, Tomasz Figa wrote: > > > On Fri, Nov 2, 2018 at 12:03 AM Lars-Peter Clausen wrote: > > > > On 11/01/2018 03:30 PM, Tomasz Figa wrote: > > > >> On Thu, Nov 1, 2018 at 11:03 PM Laurent Pinchart wrote: > > > >>> On Thursday, 18 October 2018 20:28:06 EET Alexandru M Stan wrote: > > > >>>> On Wed, Oct 17, 2018 at 9:31 PM, Tomasz Figa wrote: > > > >>>>> On Thu, Oct 18, 2018 at 5:50 AM Laurent Pinchart wrote: > > > >>>>>> On Wednesday, 17 October 2018 11:28:52 EEST Tomasz Figa wrote: > > > >>>>>>> On Wed, Oct 17, 2018 at 5:02 PM Laurent Pinchart wrote: > > > >>>>>>>> On Wednesday, 17 October 2018 10:52:42 EEST Heng-Ruey Hsu wrote: > > > >>>>>>>>> Android requires camera timestamps to be reported with > > > >>>>>>>>> CLOCK_BOOTTIME to sync timestamp with other sensor sources. > > > >>>>>>>> > > > >>>>>>>> What's the rationale behind this, why can't CLOCK_MONOTONIC work ? If > > > >>>>>>>> the monotonic clock has shortcomings that make its use impossible for > > > >>>>>>>> proper synchronization, then we should consider switching to > > > >>>>>>>> CLOCK_BOOTTIME globally in V4L2, not in selected drivers only. > > > >>>>>>> > > > >>>>>>> CLOCK_BOOTTIME includes the time spent in suspend, while > > > >>>>>>> CLOCK_MONOTONIC doesn't. I can imagine the former being much more > > > >>>>>>> useful for anything that cares about the actual, long term, time > > > >>>>>>> tracking. Especially important since suspend is a very common event on > > > >>>>>>> Android and doesn't stop the time flow there, i.e. applications might > > > >>>>>>> wake up the device to perform various tasks at necessary times. > > > >>>>>> > > > >>>>>> Sure, but this patch mentions timestamp synchronization with other > > > >>>>>> sensors, and from that point of view, I'd like to know what is wrong with > > > >>>>>> the monotonic clock if all devices use it. > > > >>>>> > > > >>>>> AFAIK the sensors mentioned there are not camera sensors, but rather > > > >>>>> things we normally put under IIO, e.g. accelerometers, gyroscopes and > > > >>>>> so on. I'm not sure how IIO deals with timestamps, but Android seems > > > >>>>> to operate in the CLOCK_BOTTIME domain. Let me add some IIO folks. > > > >>>>> > > > >>>>> Gwendal, Alexandru, do you think you could shed some light on how we > > > >>>>> handle IIO sensors timestamps across the kernel, Chrome OS and > > > >>>>> Android? > > > >>>> > > > >>>> On our devices of interest have a specialized "sensor" that comes via > > > >>>> IIO (from the EC, cros-ec-ring driver) that can be used to more > > > >>>> accurately timestamp each frame (since it's recorded with very low > > > >>>> jitter by a realtime-ish OS). In some high level userspace thing > > > >>>> (specifically the Android Camera HAL) we try to pick the best > > > >>>> timestamp from the IIO, whatever's closest to what the V4L stuff gives > > > >>>> us. > > > >>>> > > > >>>> I guess the Android convention is for sensor timestamps to be in > > > >>>> CLOCK_BOOTTIME (maybe because it likes sleeping so much). There's > > > >>>> probably no advantage to using one over the other, but the important > > > >>>> thing is that they have to be the same, otherwise the closest match > > > >>>> logic would fail. > > > >>> > > > >>> That's my understanding too, I don't think CLOCK_BOOTTIME really brings much > > > >>> benefit in this case, > > > >> > > > >> I think it does have a significant benefit. CLOCK_MONOTONIC stops when > > > >> the device is sleeping, but the sensors can still capture various > > > >> actions. We would lose the time keeping of those actions if we use > > > >> CLOCK_MONOTONIC. > > > >> > > > >>> but it's important than all timestamps use the same > > > >>> clock. The question is thus which clock we should select. Mainline mostly uses > > > >>> CLOCK_MONOTONIC, and Android CLOCK_BOOTTIME. Would you like to submit patches > > > >>> to switch Android to CLOCK_MONOTONIC ? :-) > > > >> > > > >> Is it Android using CLOCK_BOOTTIME or the sensors (IIO?). I have > > > >> almost zero familiarity with the IIO subsystem and was hoping someone > > > >> from there could comment on what time domain is used for those > > > >> sensors. > > > > > > > > IIO has the option to choose between BOOTTIME or MONOTONIC (and a few > > > > others) for the timestamp on a per device basis. > > > > > > > > There was a bit of a discussion about this a while back. See > > > > https://lkml.org/lkml/2018/7/10/432 and the following thread. > > > > > > Given that IIO supports BOOTTIME in upstream already and also the > > > important advantage of using it over MONOTONIC for systems which keep > > > capturing events during sleep, do you think we could move on with some > > > way to support it in uvcvideo or preferably V4L2 in general? > > > > I'm not opposed to that, but I don't think we should approach that from > > a UVC point of view. The issue should be addressed in V4L2, and then > > driver-specific support could be added, if needed. > > Yes, fully agreed. The purpose of sending this patch was just to start > the discussion on how to support this. > > Do you think something like a buffer flag called > V4L2_BUF_FLAG_TIMESTAMP_BOOTTIME that could be set by the userspace at > QBUF could work here? (That would change the timestamp flags > semantics, because it used to be just the information from the driver, > but shouldn't have any compatibility implications.) I suppose we would > also need some capability flag for querying purposes, possibly added > to the capability flags returned by REQBUFS/CREATE_BUFS? Any thoughts? Adding Hans and Kieran for more insight. Best regards, Tomasz