From: Hans de Goede <hansg@kernel.org>
To: Ricardo Ribalda <ribalda@chromium.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Tomasz Figa <tfiga@chromium.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Yunke Cao <yunkec@google.com>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 5/6] media: uvcvideo: Do not add samples if dev_sof has not changed
Date: Mon, 18 May 2026 11:02:07 +0200 [thread overview]
Message-ID: <b5995c59-5413-4705-90ae-8a153fd34f09@kernel.org> (raw)
In-Reply-To: <20260513-uvc-hwtimestamp-v3-5-7a64838b0b02@chromium.org>
Hi,
On 13-May-26 1:49 PM, Ricardo Ribalda wrote:
> We only save relevant samples into the circular buffer. If the data is
> very similar to the previous one, exit early, this allows us to avoid
> some expensive operations such as usb_get_current_frame_number().
>
> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
Regards,
Hans
> ---
> drivers/media/usb/uvc/uvc_video.c | 16 +++++++++++-----
> drivers/media/usb/uvc/uvcvideo.h | 3 ++-
> 2 files changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index 63850b779e24..6794031cd0fb 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -524,7 +524,7 @@ static void uvc_video_clock_add_sample(struct uvc_clock *clock,
>
> spin_lock_irqsave(&clock->lock, flags);
>
> - if (clock->count > 0 && clock->last_sof > sample->dev_sof) {
> + if (clock->count > 0 && clock->last_sof_processed > sample->dev_sof) {
> /*
> * Remove data from the circular buffer that is older than the
> * last SOF overflow. We only support one SOF overflow per
> @@ -599,7 +599,12 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf,
> if (!has_scr)
> return;
>
> - sample.dev_sof = get_unaligned_le16(&data[header_size - 2]);
> + sample.dev_sof = get_unaligned_le16(&data[header_size - 2]) & 2047;
> + /* If the sample SOF is identical to the previous one, quit early. */
> + if (stream->clock.last_sof_raw == sample.dev_sof)
> + return;
> + stream->clock.last_sof_raw = sample.dev_sof;
> +
> sample.dev_stc = get_unaligned_le32(&data[header_size - 6]);
>
> /*
> @@ -678,19 +683,20 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf,
> * 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 (sof_diff(sample.dev_sof, stream->clock.last_sof) <=
> + if (sof_diff(sample.dev_sof, stream->clock.last_sof_processed) <=
> (UVC_MIN_HW_TIMESTAMP_DIFF / stream->clock.size))
> return;
>
> uvc_video_clock_add_sample(&stream->clock, &sample);
> - stream->clock.last_sof = sample.dev_sof;
> + stream->clock.last_sof_processed = sample.dev_sof;
> }
>
> static void uvc_video_clock_reset(struct uvc_clock *clock)
> {
> clock->head = 0;
> clock->count = 0;
> - clock->last_sof = -1;
> + clock->last_sof_processed = -1;
> + clock->last_sof_raw = -1;
> clock->last_sof_overflow = -1;
> clock->sof_offset = -1;
> }
> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> index 4ba35727e954..b6bcee4a222f 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -522,7 +522,8 @@ struct uvc_streaming {
> unsigned int size;
> unsigned int last_sof_overflow;
>
> - u16 last_sof;
> + u16 last_sof_processed;
> + u16 last_sof_raw;
> u16 sof_offset;
>
> u8 last_scr[6];
>
next prev parent reply other threads:[~2026-05-18 9:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 11:49 [PATCH v3 0/6] media: uvcvideo: Fixes for hw timestamping Ricardo Ribalda
2026-05-13 11:49 ` [PATCH v3 1/6] media: uvcvideo: Fix dev_sof filtering in hw timestamp Ricardo Ribalda
2026-05-13 11:49 ` [PATCH v3 2/6] media: uvcvideo: Use hw timestaming if the clock buffer is full Ricardo Ribalda
2026-05-13 11:49 ` [PATCH v3 3/6] media: uvcvideo: Relax the constrains for interpolating the hw clock Ricardo Ribalda
2026-05-13 11:49 ` [PATCH v3 4/6] media: uvcvideo: Do not add clock samples with small sof delta Ricardo Ribalda
2026-05-13 11:51 ` Ricardo Ribalda
2026-05-13 11:49 ` [PATCH v3 5/6] media: uvcvideo: Do not add samples if dev_sof has not changed Ricardo Ribalda
2026-05-18 9:02 ` Hans de Goede [this message]
2026-05-13 11:49 ` [PATCH v3 6/6] media: uvcvideo: Only do uvc_video_get_time() if needed Ricardo Ribalda
2026-05-14 9:37 ` Yunke Cao
2026-05-18 9:02 ` Hans de Goede
2026-05-18 9:06 ` [PATCH v3 0/6] media: uvcvideo: Fixes for hw timestamping Hans de Goede
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b5995c59-5413-4705-90ae-8a153fd34f09@kernel.org \
--to=hansg@kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=ribalda@chromium.org \
--cc=senozhatsky@chromium.org \
--cc=tfiga@chromium.org \
--cc=yunkec@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®