Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp295566lqp; Wed, 12 Jun 2024 01:36:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX1B4qa+SHtutpdm6glERMAtZcyidqDjYP08k41MEDHR17zdQhj/VS74LWZgI3gsme4L0IW4Kt7VCe3Mf+1wfTibxdB7cbWfusJqQjCfA== X-Google-Smtp-Source: AGHT+IFtgxVJYy4XnfhPALhmkRyxsGBZv1+yG0YOH1UDnvb7+nbWdnCWgaZFW7y6lvGdOHmJ+ugS X-Received: by 2002:a05:6808:201d:b0:3d2:1f88:3e7a with SMTP id 5614622812f47-3d23e0cc875mr1361369b6e.39.1718181374195; Wed, 12 Jun 2024 01:36:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718181374; cv=pass; d=google.com; s=arc-20160816; b=izK6/C9xB0UTl9ox+t5KqxDZqf1Bfm2tR8CeJYPrFoEGIBrlMZuI1qCEg2OJFjf6y8 0m+OqcKdiwAjFM2RbIXDRSVA2MEahV2GYO0l1hxiQ8nbmDTM3Y04vZSwKq0HEu7x3wez y5hcdmWCYzkaoRQokvFZqbhqURnbYVi/4jyCMhvO/yFg6i+mgKwcZW4ZbtBEzahledjq 6qbVzWETMorQYaaUX2AeYrtXzOUHdsdztSNVy14KMv/wa1mYqEJ1H+Sbyqk8v/y5uKPs w/YN7pOjqdDayiEEAWKhDw6VKalg4d8afDsPXFcdjSE12oZAN5SppnOF6dY5UJVpZDh8 ZBig== 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=96JHV5aiT5xFVHpkcSz0cCY5wiynRMtgpF9ScNLxjE4=; fh=+hqdJe8DeFbfCXWmTr2pBhZKaI2Jo7yK3tAVubbPTs0=; b=muv5cUrCg+PiHtlusNw4kciLOtZ+4P3m4AevH1ZLsVB33A4FYYlmwrfiwYJLUKdpcC 61y3FSb9hhHZIzaNr62B8ZrmpfGZUJ3EnTcBD9SdNzC6RZ48ssZbySRWDJMQ45zFQrf7 KwOWtNVDKvaoXDx0cspyPDtldtIGmbzFVZEfgcU1YQLirLU+y4O4A1rblYqFTgWVOAWC wewgMDGi6YmAk6kTaN/4PdD4L/CUipPmtdU4oZ+p2iwtRrJ79/+yFK9Dhe51EuBFt5Mg ke/E+Ujxial3PbmgDMTm1bfefLvktiKYfVeCosY1TKNhbol1ykxuZ4ezn0X7VrKqftpL h/MA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kOqLVRCa; 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-211190-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211190-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e862406b39si7070686a12.844.2024.06.12.01.36.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 01:36:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-211190-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kOqLVRCa; 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-211190-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211190-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C44DA283149 for ; Wed, 12 Jun 2024 08:36:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 34D5616D335; Wed, 12 Jun 2024 08:36:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="kOqLVRCa" Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 F3223169ACD for ; Wed, 12 Jun 2024 08:36:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718181364; cv=none; b=k4bNnIEj2hequ7ScoLOsYLqebKNDNR5w0XmDtEbM5liS1KZUe5Y/Ouu12n91a0ybQXwI3wtO9zBU3P4Jp30pA7FH2X0c03O7kREb8v5T+Q6R6gvlDu0+Ok+ztaC4GliZjLVx5TGajXy0IA4iwxEDelnj4RsRTDn3rCwBEky6ziw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718181364; c=relaxed/simple; bh=doc3wh/NDobak9luRx8Vah60RaiI2YbRUzuglJj4iF8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=mUW0ocfVaIW/7BWxeKPQJ/V4gxJ9qWdOC0M3/m1D6jlkKa2AS5nkz/N22ey/8Ed80Kj9dQMjYFSeuZqFuMm6s3O/3apuIumoEJM8Ml7s8X+IcMGibMraULKh6SNuhRt1cQ2vQvAINFTUcQHlhePvBq5W8p+87osmJjYRs3k63HU= 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=kOqLVRCa; arc=none smtp.client-ip=209.85.218.54 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-f54.google.com with SMTP id a640c23a62f3a-a6f0c3d0792so237416266b.3 for ; Wed, 12 Jun 2024 01:36:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1718181360; x=1718786160; 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=96JHV5aiT5xFVHpkcSz0cCY5wiynRMtgpF9ScNLxjE4=; b=kOqLVRCaNQLBlIVOR5jIzBkS9kjhau9co0udjMp4HnUB+LGuYIObgPxlaKUfgL2flC 7zNphPS4K3F/24pxLCBM8ZKqvsgGJdtenIqGB9qmxLDzXw89N+pmdNZG9nokOWAvuMva vBCYwPWjtFs1sfag3of9+dnMaej/9TTeYBGhU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718181360; x=1718786160; 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=96JHV5aiT5xFVHpkcSz0cCY5wiynRMtgpF9ScNLxjE4=; b=nj4hwi/a0uPHH2lj5ph2TVkycIJltRqCK1u/74rWK6HYH8uBUjXOnsxQHCXj9O0I5N DcDPqBvgBpjcveJvJylNcIYP1dzyiNtZMHhYhHXI/q1vb+MI+9itcY0c5h00nuDX3SuB eLXTfrW75b9eBsLSo9m6lfJJD2rVuLFblZXYJ8M1sV1Vra2vwOCujvR5J9X1+rE4LCMc fAPM28eGs0mklyFV73IqDh47ZoYpFaS7+szrNMbM+VLwQZp5kTP02E5hr21NLA3+s0Fv MSVKLgYKi614A2607ElMQIqIr/8wDiVMHk2CTZx6uU26AQJEQvheIVCzIbF2shnxblnx tKiA== X-Forwarded-Encrypted: i=1; AJvYcCUKVj+mOFSASGpfJgDUvc4VNdLY6vsPBEmnzzokiucWryULRjnrRGkiibLk3qFYUpetPrefW7g7FrtaisHpFTRvVYXDHP+Vft+NKJEo X-Gm-Message-State: AOJu0Yzuv+iDuIVD5oX/igRuqFHfw72AVZNy5OimnKPus93KM7pYUqRe paiFpcroDsCuZkuWTKYstphZTqmF5PKR4UXggVRrDRjPHnctO7SfWlSLPXNfufpIDz/mwKbgRns TOA== X-Received: by 2002:a17:906:f35b:b0:a68:d2dd:e006 with SMTP id a640c23a62f3a-a6f47cbc16amr73358566b.17.1718181359648; Wed, 12 Jun 2024 01:35:59 -0700 (PDT) Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com. [209.85.218.46]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f1dd4595asm374287266b.22.2024.06.12.01.35.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Jun 2024 01:35:59 -0700 (PDT) Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a6f176c5c10so231901866b.2 for ; Wed, 12 Jun 2024 01:35:58 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCVtyDN0POm290XDfcSiAJlOnUu3a+fILtFWUAZfUYRMpXTSwZ0Fq2bgZt0De427gqUzIs78yYB7QrIe8801W4USR0CmthKIdUuPUcVP X-Received: by 2002:a17:906:741:b0:a6f:1f7b:6a8b with SMTP id a640c23a62f3a-a6f47f803fbmr63433366b.66.1718181358251; Wed, 12 Jun 2024 01:35:58 -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> In-Reply-To: <20240612074342.GA28989@pendragon.ideasonboard.com> From: Tomasz Figa Date: Wed, 12 Jun 2024 17:35:38 +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 4:44=E2=80=AFPM 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. Whic= h means > > > > > that it takes 32 frames to move from the software timestamp to th= e > > > > > hardware timestamp method. > > > > > > > > > > This results in abrupt changes in the timestamping after 32 frame= s (~1 > > > > > second), resulting in noticeable artifacts when used for encoding= . > > > > > > > > > > With this patch we modify the update algorithm to work with whate= ver > > > > > 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/media/us= b/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_stre= aming *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 + clock= ->size) % clock->size]; > > > > > last =3D &clock->samples[(clock->head - 1 + clock->size) % cl= ock->size]; > > > > > > > > > > /* First step, PTS to SOF conversion. */ > > > > > @@ -786,6 +786,18 @@ void uvc_video_clock_update(struct uvc_strea= ming *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 enough > > > > > + * precision. This value was determined by running Android CT= S > > > > > + * on different devices. > > > > > + * > > > > > + * dev_sof runs at 1KHz, and we have a fixed point precision = 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 document= ation > > > > that specifies what the userspace can expect from the timestamps, s= o > > > > that this isn't changed randomly in the future breaking what was fi= xed > > > > by this patch. > > > > > > I think timestamp handling should really be moved to userspace. It wi= ll > > > be easier to handle with floating-point arithmetic there. That would > > > have been difficult to manage for applications a while ago, but now t= hat > > > we have libcamera, we could implement it there. This isn't high on my > > > todo list though. > > > > While indeed that would probably be a better way to handle the complex > > logic if we designed the driver today, we already have userspace that > > 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 high > > 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 the > components we need. The only missing thing would be the implementation > in libcamera :-) Okay, I see. That would make it easier indeed. :) That said, we still need to provide some valid timestamps in the v4l2_buffer struct returned from DQBUF, as per the current API contract, so we can't simply remove the timestamp handling code from the kernel completely.