From: "Gjorgji Rosikopulos (Consultant)" <gjorgji.rosikopulos@oss.qualcomm.com>
To: Loic Poulain <loic.poulain@oss.qualcomm.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
Bryan O'Donoghue <bryan.odonoghue@linaro.org>,
Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH v2 1/7] media: v4l2-event: Allow drivers to provide the event timestamp
Date: Fri, 27 Nov 2026 09:07:19 +0200 [thread overview]
Message-ID: <cb9ab22a-50d1-4740-a88c-198b60f896d8@oss.qualcomm.com> (raw)
In-Reply-To: <CAFEp6-07goPSX=fEOmQziXTvSoSt7-FebXAtB9xfavTXB6-Ryg@mail.gmail.com>
On 11/26/2026 5:15 PM, Loic Poulain wrote:
> On Thu, Nov 26, 2026 at 8:52 AM Gjorgji Rosikopulos (Consultant)
> <gjorgji.rosikopulos@oss.qualcomm.com> wrote:
>>
>>
>>
>> On 11/26/2026 9:00 AM, Gjorgji Rosikopulos (Consultant) wrote:
>>> Hi Loic,
>>>
>>> Apart from hw timestamp propagation some other comments.
>>>
>>> On 11/25/2026 12:19 PM, Loic Poulain wrote:
>>>> The timestamp reported to userspace for a V4L2 event is taken when the
>>>> event is queued, which for an event signalling a hardware occurrence is
>>>> only as good as the latency between the two. A CSI decoder able to latch
>>>> the start-of-frame against the system counter knows that time to within a
>>>> few microseconds, whereas the interrupt handler that gets to queue the
>>>> event can be hundreds of microseconds late and is not consistent about
>>>> it.
>>>>
>>>> Take the timestamp from the event when the driver filled it in, falling
>>>> back to the current time when the field is cleared. Drivers have had no
>>>> reason to set it so far, and every in-tree caller either uses a
>>>> designated initialiser or memsets the event, so the field reads as zero
>>>> everywhere today.
>>>>
>>>> Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
>>>> ---
>>>> drivers/media/v4l2-core/v4l2-event.c | 20 ++++++++++++++++++--
>>>> include/media/v4l2-event.h | 9 ++++++++-
>>>> 2 files changed, 26 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/drivers/media/v4l2-core/v4l2-event.c b/drivers/media/v4l2-core/v4l2-event.c
>>>> index 9dd2aaa95a67406bda3a257325442888895ed088..a35646c3a5c89febeb072d691ffd7853d9af714a 100644
>>>> --- a/drivers/media/v4l2-core/v4l2-event.c
>>>> +++ b/drivers/media/v4l2-core/v4l2-event.c
>>>> @@ -150,6 +150,22 @@ static void __v4l2_event_queue_fh(struct v4l2_fh *fh,
>>>> wake_up_all(&fh->wait);
>>>> }
>>>>
>>>> +/*
>>>> + * Hardware able to timestamp the event itself reports that time in the event,
>>>> + * which is more accurate than the moment the driver gets to queue it. Fall
>>>> + * back to the current time for the drivers that leave the field cleared.
>>>> + */
>>>> +static u64 v4l2_event_ts(const struct v4l2_event *ev)
>>>> +{
>>>> + struct timespec64 ts = {
>>>> + .tv_sec = ev->timestamp.tv_sec,
>>>> + .tv_nsec = ev->timestamp.tv_nsec,
>>>> + };
>>>> + u64 ns = timespec64_to_ns(&ts);
>>>> +
>>>> + return ns ? ns : ktime_get_ns();
>>>> +}
>>>> +
>>>> void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev)
>>>> {
>>>> struct v4l2_fh *fh;
>>>> @@ -159,7 +175,7 @@ void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev)
>>>> if (vdev == NULL)
>>>> return;
>>>>
>>>> - ts = ktime_get_ns();
>>>> + ts = v4l2_event_ts(ev);
>>>
>>> The documentation states that:
>>>
>>> "In order to queue events to video device, drivers should call:
>>>
>>> v4l2_event_queue (vdev, ev)
>>>
>>> The driver’s only responsibility is to fill in the type and the data fields.
>>> The other fields will be filled in by V4L2. All other fields are filled from the v4l2. "
>>>
>>> So here we are changing the driver-api. I am sure that there are drivers
>>> which does not set initialize the whole event struct. This will introduce new bugs with
>>> some uninitiated data send to userspace as timestamp.
>
> No, at least none have uninitialized value, this is mentioned in the
> commit message, so this should not break anything.
Yes it does not break for the currently up-streamed drivers. But anyway
it is changing the driver API we need to be careful for this and proper
description in the driver-api documentation. So it is also not clear
whether this is the timestamp when the event is recieved by the hw
or when the event is enqueued to the event queue. So my opinion is
that everything should be well documented.
~Gjorgji
>
>> My opinion is that similar to frame_sequence (which is different from event.sequence)
>> to add frame_timestamp in the frame_sync data field. Whether that is monotonic timestamp
>> or specific camera hw based timestamp is yet to be specified and decided.
>
> Yes, but we're not changing that here. The reported timestamp remains
> a monotonic system timestamp.
>
> Linux provides a hardware abstraction layer, and in this case we're
> reporting a SOF event, which is fundamentally a hardware/bus event. If
> a driver can provide a more accurate monotonic timestamp for that
> event than the generic framework helper, I believe the API should
> allow it.
>
> The goal is simply to give userspace a timestamp that more accurately
> reflects when the event actually occurred. If that level of accuracy
> is not required, there would be little value in providing event
> timestamps at all, as userspace could just read the event and obtain
> the current monotonic time itself.
>
> Accurate timestamps allow downstream elements of the video pipeline to
> make better decisions. For example, they provide a more precise
> inter-frame interval and effective frame rate, and enable derived
> measurements such as object velocity or motion estimation to be
> computed more accurately.
I Agree that the real timestamp of the frame_sync event is needed,
i think there is no disagreement on that. It is actually how we provide
that to userspace.
>
> That said, I understand this point is somewhat controversial. Since it
> is not a hard dependency, I can drop this patch from the series. We'll
> still apply the timestamp to the frame itself.
This more sense since the timestamp of the frame is well documented.
And anyways the frame is what it travels to the encoders and other elements
in the pipeline and needed a real timestamp.
~Gjorgji
>
> Regards,
> Loic
>
>>
>>>
>>> ~Gjorgji
>>>
>>>>
>>>> spin_lock_irqsave(&vdev->fh_lock, flags);
>>>>
>>>> @@ -173,7 +189,7 @@ EXPORT_SYMBOL_GPL(v4l2_event_queue);
>>>> void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev)
>>>> {
>>>> unsigned long flags;
>>>> - u64 ts = ktime_get_ns();
>>>> + u64 ts = v4l2_event_ts(ev);
>>>>
>>>> spin_lock_irqsave(&fh->vdev->fh_lock, flags);
>>>> __v4l2_event_queue_fh(fh, ev, ts);
>>>> diff --git a/include/media/v4l2-event.h b/include/media/v4l2-event.h
>>>> index 3a0e2588361cf451b3dbfc63dfab99550d13cf6a..076f788e0469ae4666c60344e5ea73a698352134 100644
>>>> --- a/include/media/v4l2-event.h
>>>> +++ b/include/media/v4l2-event.h
>>>> @@ -102,6 +102,11 @@ int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event,
>>>> * .. note::
>>>> * The driver's only responsibility is to fill in the type and the data
>>>> * fields. The other fields will be filled in by V4L2.
>>>> + *
>>>> + * Drivers whose hardware timestamps the event more accurately than the
>>>> + * moment the driver gets to handle it may also fill in the timestamp
>>>> + * field, as a CLOCK_MONOTONIC time. It is left alone if non-zero, so such
>>>> + * drivers must zero-initialize the whole &struct v4l2_event.
>>>> */
>>>> void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev);
>>>>
>>>> @@ -116,7 +121,9 @@ void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev);
>>>> *
>>>> * .. note::
>>>> * The driver's only responsibility is to fill in the type and the data
>>>> - * fields. The other fields will be filled in by V4L2.
>>>> + * fields. The other fields will be filled in by V4L2. As for
>>>> + * v4l2_event_queue(), a non-zero timestamp field is taken as the
>>>> + * CLOCK_MONOTONIC time of the event.
>>>> */
>>>> void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev);
>>>>
>>>>
>>>
>>
next prev parent reply other threads:[~2026-11-27 7:07 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 10:19 [PATCH v2 0/7] media: qcom: camss: Report the hardware SOF timestamp Loic Poulain
2026-11-25 10:19 ` [PATCH v2 1/7] media: v4l2-event: Allow drivers to provide the event timestamp Loic Poulain
2026-11-25 12:29 ` Gjorgji Rosikopulos (Consultant)
2026-11-25 12:58 ` Vladimir Zapolskiy
2026-11-25 19:21 ` Gjorgji Rosikopulos (Consultant)
2026-11-25 13:21 ` Loic Poulain
2026-11-25 19:39 ` Vladimir Zapolskiy
2026-11-25 19:53 ` Gjorgji Rosikopulos (Consultant)
2026-11-25 20:50 ` Loic Poulain
2026-11-26 7:00 ` Gjorgji Rosikopulos (Consultant)
2026-11-26 7:52 ` Gjorgji Rosikopulos (Consultant)
2026-11-26 15:15 ` Loic Poulain
2026-11-27 7:07 ` Gjorgji Rosikopulos (Consultant) [this message]
2026-11-25 10:19 ` [PATCH v2 2/7] media: qcom: camss: csid: Add an operation to read the SOF timestamp Loic Poulain
2026-11-25 12:04 ` Gjorgji Rosikopulos (Consultant)
2026-11-25 12:06 ` Gjorgji Rosikopulos (Consultant)
2026-11-25 13:18 ` Loic Poulain
2026-11-25 15:01 ` Gjorgji Rosikopulos (Consultant)
2026-11-25 16:21 ` Loic Poulain
2026-11-25 17:23 ` Gjorgji Rosikopulos (Consultant)
2026-11-26 9:25 ` Loic Poulain
2026-11-25 10:19 ` [PATCH v2 3/7] media: qcom: camss: csid-340: Report the hardware " Loic Poulain
2026-11-25 10:19 ` [PATCH v2 4/7] media: camss: Define timestamp registers for csid-gen2 Loic Poulain
2026-11-25 10:19 ` [PATCH v2 5/7] media: camss: csid-gen2: Report the hardware SOF timestamp Loic Poulain
2026-11-25 10:19 ` [PATCH v2 6/7] media: qcom: camss: Timestamp buffers at start of frame Loic Poulain
2026-11-25 10:19 ` [PATCH v2 7/7] media: qcom: camss: Tell userspace we're using start-of-frame timestamps Loic Poulain
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=cb9ab22a-50d1-4740-a88c-198b60f896d8@oss.qualcomm.com \
--to=gjorgji.rosikopulos@oss.qualcomm.com \
--cc=bryan.odonoghue@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=loic.poulain@oss.qualcomm.com \
--cc=mchehab@kernel.org \
--cc=vladimir.zapolskiy@linaro.org \
/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®