From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95600311977; Mon, 11 May 2026 16:05:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778515542; cv=none; b=km/FdUNkPoVTO3mEQKEEy/kpSqPuCWDsQtuXrKEKYjfWA+161lL+R8AknGAL7Q/5Qc4yoAXVGkNVMujBESsvSk1akeZEhqYcABw0O3iqNu6yTNZd1+QM7GUtrG/1xr1dFFXmA/OiyqPbIRzvu8G7sMENzVieu+63QKU6Zq83bJQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778515542; c=relaxed/simple; bh=jxP9amh2tC50kwk8NDUkRIAwZHVes3F7TVXTGePVNSA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=PoolFxj0thLJv00v3uKjdUzV+axkpr7BRomI9LINlKsSX0r1d7QfkFW5U06OSxB/E107SIlNSdYrPbNJLU9DfknDN8uEmJaZ8DFTq1jACH7KDDgX6LFsaPqq0U+HO0NUNHt6jCn3fpJwUKNufvkb8Qg2qPS4db6NIRP18M3z48g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Tz6KNEer; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Tz6KNEer" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A93E0C2BCB0; Mon, 11 May 2026 16:05:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778515542; bh=jxP9amh2tC50kwk8NDUkRIAwZHVes3F7TVXTGePVNSA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Tz6KNEerTe4bzhVIoZ+tO4UgYi6Tva0hOTHQVUeA7DkEvabXPdarzlZyV+ywtVczI NZ3PJ/BIiRoJpOhFH+z1/LV/BsAa/fxSFmT6ofIM8SBVyg/HFanI/gex9Hl+yXxebo drKdE0DeWm1XfF7DXhSA6ZM1h8ecQBLUES6CqY78nHLLkE8K3DVXkHjkoaa5La/84/ yME4kt2v/FjC3vP09WEOL2PxlEzDWWtZ7kHhhdSx6yXl+rJC1/Otuy5tHX9NGz5Gwq NZQ+jQ9CkWJQ9dAO7HMcC7EqOtH1Gcx+teK1cuE1z7gM7ioAUcu0odcydNMRm9EV/w JUmA3tCtLfnUw== Message-ID: <8803be15-1e64-4a97-a5b6-cf2b97eea38c@kernel.org> Date: Mon, 11 May 2026 18:05:39 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/4] media: uvcvideo: Fix dev_sof filtering in hw timestamp To: Laurent Pinchart , Ricardo Ribalda Cc: Mauro Carvalho Chehab , Tomasz Figa , Sergey Senozhatsky , Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20260323-uvc-hwtimestamp-v1-0-aa42e3865204@chromium.org> <20260323-uvc-hwtimestamp-v1-1-aa42e3865204@chromium.org> <20260511154629.GB3043805@killaraus.ideasonboard.com> From: Hans de Goede Content-Language: en-US, nl In-Reply-To: <20260511154629.GB3043805@killaraus.ideasonboard.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi, On 11-May-26 17:46, Laurent Pinchart wrote: > Hi Ricardo, > > Thank you for the patch. > > On Mon, Mar 23, 2026 at 01:10:28PM +0000, Ricardo Ribalda wrote: >> To avoid filling the clock circular buffer with duplicated data we only >> add it if the new value sof is different than the last added sof. >> >> The issue is that we compare the unprocess sof with the processed sof. >> If there is a sof_offset, or UVC_QUIRK_INVALID_DEVICE_SOF is enabled, >> the comparison will not work as expected. >> >> This patch moves the comparison to the right place. >> >> Fixes: 141270bd95d4 ("media: uvcvideo: Refactor clock circular buffer") >> Cc: stable@vger.kernel.org >> Signed-off-by: Ricardo Ribalda >> --- >> drivers/media/usb/uvc/uvc_video.c | 19 ++++++++++--------- >> 1 file changed, 10 insertions(+), 9 deletions(-) >> >> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c >> index 40c76c051da2..6786ca38fe5e 100644 >> --- a/drivers/media/usb/uvc/uvc_video.c >> +++ b/drivers/media/usb/uvc/uvc_video.c >> @@ -583,16 +583,7 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, >> if (!has_scr) >> return; >> >> - /* >> - * To limit the amount of data, drop SCRs with an SOF identical to the >> - * previous one. This filtering is also needed to support UVC 1.5, where >> - * all the data packets of the same frame contains the same SOF. In that >> - * case only the first one will match the host_sof. >> - */ >> sample.dev_sof = get_unaligned_le16(&data[header_size - 2]); >> - if (sample.dev_sof == stream->clock.last_sof) >> - return; >> - >> sample.dev_stc = get_unaligned_le32(&data[header_size - 6]); >> >> /* >> @@ -664,6 +655,16 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, >> } >> >> sample.dev_sof = (sample.dev_sof + stream->clock.sof_offset) & 2047; >> + >> + /* >> + * To limit the amount of data, drop SCRs with an SOF identical to the >> + * previous one. This filtering is also needed to support UVC 1.5, where >> + * all the data packets of the same frame contains the same SOF. In that >> + * case only the first one will match the host_sof. >> + */ >> + if (sample.dev_sof == stream->clock.last_sof) >> + return; >> + > > We will now uncondtionally call some potentially more expensive > operations, in particular usb_get_current_frame_number(). Wouldn't it be > better to store the unprocessed SOF in the sample in addition to the > processed SOF, to allow early comparison ? While reviewing 4/4 I just came to the same conclusion, uvc_video_get_time() is also expensive and unnecessary unless we actually end up doing the uvc_video_clock_add_sample(). Moving the uvc_video_get_time() to below the check is a straight-forward change. Regards, Hans > >> uvc_video_clock_add_sample(&stream->clock, &sample); >> stream->clock.last_sof = sample.dev_sof; >> } >> >