Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp300010lqp; Wed, 12 Jun 2024 01:48:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVIhb4SctIJefQ1vWOk+l4gt1RUJfRlnAfRVmzSz1EYnW3xqMY1DyVRGyFQfikzh2eITgVC65LgAqHL+wYy/qTehDYJLvdhtHeMoqH07w== X-Google-Smtp-Source: AGHT+IFLL76W0hz6csrO5/SglKTAkhsHU1ethjD8o+yVU+mWLJzA7VYQ0pdkPsze/JXpxXJlwPng X-Received: by 2002:a17:907:72c9:b0:a6f:48b2:aac5 with SMTP id a640c23a62f3a-a6f48b2ae99mr77002466b.15.1718182130535; Wed, 12 Jun 2024 01:48:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718182130; cv=pass; d=google.com; s=arc-20160816; b=nDWZP3hhbPAAbVGRkEwOZVBI2n+6jBf5NdG+oscTEg6+0mF1kQ8wGSFlGE9VuBpz8c 1+Cvp1+4iiT1+B9NPJvIucUXMp/VlVT0yYzHsvClUNM2wXQGXl62+hDVVjrz1OLs3/oi x93BFOO7Or8Y28wzWV2WsXvSI3Dx6WsLpUW/PjcFMuiQ5S0SKJ5OESEguSeHBnPeSiPm aiRexLvyE5Os9CO74Oa29QmpWAOIo+SNX6yGdlyG2DW8jOy7ZwezZSPHdrT0TQb1YphO e8R3HyGJgr2hKk0pQYP+v4cEMOlklkEcDnikcPYQHgjFDzrvcTVvDAOvA50rXRholj9h 27Dg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=jtVbKt1Lt/6TaBr1LN7eGKLsWZLDTjib6uq4q3NlYf0=; fh=utsLL3WleJQ+pDt3ETK2A5ajK7jHaBHDCRMSwdvuVUY=; b=KC8cp0gTMPwTREXYY/bmxMPk7wlRUgVtfQ0gFk29oaQ530VgfKfZ7hjbAmNzvTuOoz 6Pk0t43W1TiUUoL3xo+C6AM3t/vxjl8Yl5MCq6nnxGYKxCv9/q4y/gX/5vPJ8Hldzyks 46VZDLHPNbqsGa8FtN+KRKMuINEarPdyjgkhoTEdU4hOcdDGCuphSxxc42xu1zmge/qF 1LpjE3Np8/AU5QUIWgxrcWiP4Mxc37Ldp1PnQx9QYXqqODI5D/gEFZfAN0etNQxv6Z7R AiTYPBtO71/a4Bjzo5tz71JfskVli4y//sOMr3IM6CHSOg48jsB5j5euFQFl7zNJc1eX pjOQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BfQtPKIb; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-211205-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211205-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6ef8623bbesi476891266b.58.2024.06.12.01.48.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 01:48:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-211205-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BfQtPKIb; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-211205-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211205-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0D9611F22253 for ; Wed, 12 Jun 2024 08:48:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E880216D4E2; Wed, 12 Jun 2024 08:48:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="BfQtPKIb" Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D32A216D305 for ; Wed, 12 Jun 2024 08:48:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718182118; cv=none; b=DfIousAbQw5SSLz37hqYQJaw5IfydHXTXGQQQFSrJYZZ4eBH5DF5ovEJOEBA69gX7CxBB1oR54k5FjH03O5iQXYXQXu0PG0KmOkFZ0tHEVi41BJU1GqtaCPMZQ+v8Tdj43szZGbNfu6Y2gR1A+EGY4tIuTp0LObOc6BKh5xMj+g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718182118; c=relaxed/simple; bh=uW3zlwozbkwBk3Q0UO6Rb/luAmvnclY7u9aDX3Hq14w=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=koGkwReUfHMr7gW8LLnNM9BYvanjXElPPHlz5FZZNEl0CLs7TdKX2glaFIYik3DiIoBBy3A0KtoaDY9yulza6OUGY35+m+h2A2pPugFTcXHjFjEYjhjPjJnvbO2BBYU2FIZMMUdPlxVxx0JFMGsIdHs+6nazV7qd21YY1nfHT/s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=BfQtPKIb; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a6ef793f4b8so481987466b.1 for ; Wed, 12 Jun 2024 01:48:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1718182114; x=1718786914; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=jtVbKt1Lt/6TaBr1LN7eGKLsWZLDTjib6uq4q3NlYf0=; b=BfQtPKIbv6wbIv3KDR67Bero1oc7umSI3o0oJ2gOxo93mPP0r9VuD4Rg99RYZa2UVi hjimtmU4xyYcFukC041DrqHYXSqdphgXD6y0jZMOXINIHvdiHicS8BV76CH6ZKkOrozB v+ur5RfrFO653cGlqlQpDmbZlqL1F8UjWGRWg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718182114; x=1718786914; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jtVbKt1Lt/6TaBr1LN7eGKLsWZLDTjib6uq4q3NlYf0=; b=KPul118hRWvPmjbMe7DPm5VoqboYHd5P0jldjTP0B0eG6QpoFwmOq+DIDnXpPZSm3L Z2mPVaYQMZSgJT54Z7RKdx2G/hyJnsmyu7FrTQsCSlEwDnkmC9Tyc5Z5OY2mcuw2HbOK FLcBT3ZGAlPDuT7GEGPn61QXl3F0HGMFdJfh/PZ8ncly12AzuYIVkgpxXQ3MdB9u0/wk Dg3wSo9zhCTWHrx+uVCH8uSoL6jisksoyF/nR0MmTTYh6eO5P85qT0avsG7QwhG5w5Zx kNtBudbW4YLIW/J+7dWMpen0aB3Mt7Er3E9AIDvcZ4/E0JlwKw81+ara7jwnkY+iwD33 3Bow== X-Forwarded-Encrypted: i=1; AJvYcCWYq4q2X1EDbowt3kWzU96fKuqQBXdBwwCnpZXG04A41oajUsHHYeDvf31qh1Qbk4kixC7HXzVZfe4moJORnOKYZgRhE3dskrAzVy3P X-Gm-Message-State: AOJu0YzmPqpsksXbn4LIgLm0dlcZL0LY71P4dQOvNgERwRx7PxYjXAyQ VbRiMuxfQ/FZ9MGKqEakJXDleiVhN8jINzwef0bQz4RqxnNW4jl6ioB4AcSiRCmEKbP+6rqE18B +/A== X-Received: by 2002:a17:907:9724:b0:a6e:f6b0:c49d with SMTP id a640c23a62f3a-a6f47d526b2mr86760766b.34.1718182114530; Wed, 12 Jun 2024 01:48:34 -0700 (PDT) Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com. [209.85.208.46]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f0e47b8f7sm518143566b.31.2024.06.12.01.48.33 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Jun 2024 01:48:33 -0700 (PDT) Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-57c68682d1aso4898093a12.3 for ; Wed, 12 Jun 2024 01:48:33 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCWOb06e9UtjRFZr4iC2G6rM75cACP/fdJHK16OOJfClD5eSUOtPsRljABZq11xcpwBsLribLh2O08g/l6LxMz4yZrJZ8vxZPOaXqCgK X-Received: by 2002:a17:906:f5a3:b0:a64:722f:4051 with SMTP id a640c23a62f3a-a6f47c07d92mr76196066b.0.1718182112798; Wed, 12 Jun 2024 01:48:32 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240323-resend-hwtimestamp-v10-0-b08e590d97c7@chromium.org> <20240323-resend-hwtimestamp-v10-4-b08e590d97c7@chromium.org> <4kck7oedsnj6kfiv7ykwsjg35qodg5bdktu5t5w3xtg2xuscto@2yh6kfdqwimc> <20240610114306.GR18479@pendragon.ideasonboard.com> <20240612074342.GA28989@pendragon.ideasonboard.com> <20240612082040.GD28989@pendragon.ideasonboard.com> In-Reply-To: <20240612082040.GD28989@pendragon.ideasonboard.com> From: Tomasz Figa Date: Wed, 12 Jun 2024 17:47:52 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v10 4/6] media: uvcvideo: Allow hw clock updates with buffers not full To: Laurent Pinchart Cc: Ricardo Ribalda , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, "hn.chen" , Hans Verkuil , Sergey Senozhatsky Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jun 12, 2024 at 5:21=E2=80=AFPM Laurent Pinchart wrote: > > On Wed, Jun 12, 2024 at 09:47:26AM +0200, Ricardo Ribalda wrote: > > On Wed, 12 Jun 2024 at 09:44, Laurent Pinchart > > wrote: > > > > > > On Wed, Jun 12, 2024 at 12:28:56PM +0900, Tomasz Figa wrote: > > > > On Mon, Jun 10, 2024 at 8:43=E2=80=AFPM Laurent Pinchart wrote: > > > > > On Wed, May 29, 2024 at 05:03:08PM +0900, Tomasz Figa wrote: > > > > > > On Sat, Mar 23, 2024 at 10:48:05AM +0000, Ricardo Ribalda wrote= : > > > > > > > With UVC 1.5 we get as little as one clock sample per frame. = Which means > > > > > > > that it takes 32 frames to move from the software timestamp t= o the > > > > > > > hardware timestamp method. > > > > > > > > > > > > > > This results in abrupt changes in the timestamping after 32 f= rames (~1 > > > > > > > second), resulting in noticeable artifacts when used for enco= ding. > > > > > > > > > > > > > > With this patch we modify the update algorithm to work with w= hatever > > > > > > > amount of values are available. > > > > > > > > > > > > > > Tested-by: HungNien Chen > > > > > > > Reviewed-by: Sergey Senozhatsky > > > > > > > Reviewed-by: Laurent Pinchart > > > > > > > Signed-off-by: Ricardo Ribalda > > > > > > > --- > > > > > > > drivers/media/usb/uvc/uvc_video.c | 16 ++++++++++++++-- > > > > > > > 1 file changed, 14 insertions(+), 2 deletions(-) > > > > > > > > > > > > > > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/medi= a/usb/uvc/uvc_video.c > > > > > > > index d6ca383f643e3..af25b9f1b53fe 100644 > > > > > > > --- a/drivers/media/usb/uvc/uvc_video.c > > > > > > > +++ b/drivers/media/usb/uvc/uvc_video.c > > > > > > > @@ -768,10 +768,10 @@ void uvc_video_clock_update(struct uvc_= streaming *stream, > > > > > > > > > > > > > > spin_lock_irqsave(&clock->lock, flags); > > > > > > > > > > > > > > - if (clock->count < clock->size) > > > > > > > + if (clock->count < 2) > > > > > > > goto done; > > > > > > > > > > > > > > - first =3D &clock->samples[clock->head]; > > > > > > > + first =3D &clock->samples[(clock->head - clock->count + c= lock->size) % clock->size]; > > > > > > > last =3D &clock->samples[(clock->head - 1 + clock->size) = % clock->size]; > > > > > > > > > > > > > > /* First step, PTS to SOF conversion. */ > > > > > > > @@ -786,6 +786,18 @@ void uvc_video_clock_update(struct uvc_s= treaming *stream, > > > > > > > if (y2 < y1) > > > > > > > y2 +=3D 2048 << 16; > > > > > > > > > > > > > > + /* > > > > > > > + * Have at least 1/4 of a second of timestamps before we > > > > > > > + * try to do any calculation. Otherwise we do not have en= ough > > > > > > > + * precision. This value was determined by running Androi= d CTS > > > > > > > + * on different devices. > > > > > > > + * > > > > > > > + * dev_sof runs at 1KHz, and we have a fixed point precis= ion of > > > > > > > + * 16 bits. > > > > > > > + */ > > > > > > > + if ((y2 - y1) < ((1000 / 4) << 16)) > > > > > > > + goto done; > > > > > > > > > > > > Not a comment for this patch directly, but... > > > > > > > > > > > > This kind of makes me wonder if we don't want to have some docu= mentation > > > > > > that specifies what the userspace can expect from the timestamp= s, so > > > > > > that this isn't changed randomly in the future breaking what wa= s fixed > > > > > > by this patch. > > > > > > > > > > I think timestamp handling should really be moved to userspace. I= t will > > > > > be easier to handle with floating-point arithmetic there. That wo= uld > > > > > have been difficult to manage for applications a while ago, but n= ow that > > > > > we have libcamera, we could implement it there. This isn't high o= n my > > > > > todo list though. > > > > > > > > While indeed that would probably be a better way to handle the comp= lex > > > > logic if we designed the driver today, we already have userspace th= at > > > > expects the timestamps to be handled correctly in the kernel. I > > > > suspect moving it to the userspace would require some core V4L2 > > > > changes to define a new timestamp handling mode, where multiple raw > > > > hardware timestamps are exposed to the userspace, instead of the hi= gh > > > > level system monotonic one. > > > > > > The uvcvideo driver already supports exposing the packet headers to > > > userspace through a metadata capture device, so I think we have all t= he > > > components we need. The only missing thing would be the implementatio= n > > > in libcamera :-) > > > > We would still have to duplicate the quirk information in libcamera > > and the kernel. > > Sure, and there will be some level of code duplication. My point is that > I believe it can be done in userspace, and while small changes to the > clock handling on the kernel side are fine, if we wanted to change the > code significantly I think it would be better moved to userspace. Okay, that sounds much more reasonable. I guess I misunderstood your original reply, sorry. Best regards, Tomasz > I > don't have plans to work on this, and I'm not requesting anyone to do so > either at this point. > > -- > Regards, > > Laurent Pinchart