From: David Woodhouse <dwmw2@infradead.org>
To: Peter Hilber <peter.hilber@opensynergy.com>,
linux-kernel@vger.kernel.org, virtualization@lists.linux.dev,
virtio-dev@lists.oasis-open.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
Richard Cochran <richardcochran@gmail.com>,
netdev@vger.kernel.org, Marc Zyngier <maz@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [RFC PATCH v3 5/7] virtio_rtc: Add PTP clocks
Date: Thu, 20 Jun 2024 15:33:06 +0100 [thread overview]
Message-ID: <01e1d19f290f49e12c67dbe8aadb8be49cc53eb4.camel@infradead.org> (raw)
In-Reply-To: <647cfef4-bcf1-4156-b6ae-b2e089778096@opensynergy.com>
[-- Attachment #1: Type: text/plain, Size: 3184 bytes --]
On Thu, 2024-06-20 at 14:01 +0200, Peter Hilber wrote:
> On 15.06.24 10:01, David Woodhouse wrote:
> > On Mon, 2023-12-18 at 08:38 +0100, Peter Hilber wrote:
> > >
> > > + ret = viortc_hw_xtstamp_params(&hw_counter, &cs_id);
> > > + if (ret)
> > > + return ret;
> > > +
> > > + ktime_get_snapshot(&history_begin);
> > > + if (history_begin.cs_id != cs_id)
> > > + return -EOPNOTSUPP;
> >
> > I think you have to call ktime_get_snapshot() anyway to get a snapshot
> > from before your crosststamp? But I still don't much like the fact that
> > you need to use it to work out which cs_id is being used.
>
> The actual cs_id check is in get_device_system_crosststamp(), where it was
> added recently [1]. So this additional check is just verifying that the
> history_begin is usable.
>
> > Shouldn't get_device_system_crosststamp() pass that to its get_time_fn
> > as a hint?
>
> This is unneeded in this case, since get_device_system_crosststamp() does
> the check already (but the driver is free to pass it through the
> get_time_fn parameter ctx).
The *check* is a different thing.
As things stand, the device has to *choose* a cs_id to use, and takes a
gamble on that check in get_device_system_crosststamp() throwing the
crosststamp away with -ENODEV because the device picked the wrong
cs_id.
That's why I'm saying it would be nicer if the core code *told* the
device what cs_id to use. Rather than just throwing it away if the
device guesses wrong.
(Yes, it would have to be considered a hint, because it could
theoretically have *changed* by the time the result is obtained, just
as with your code above.)
> >
> > On x86, you are likely to find that history_begin.cs_id is the KVM
> > clock, so this will return -EOPNOTSUPP and userspace will have to fall
> > back to PTP_SYS_OFFSET. I note the KVM PTP clock actually *converts* a
> > TSC-based crosststamp to kvmclock µs for itself, so that it can report
> > *cs_id = CSID_X86_KVM_CLK. Not sure how I feel about that though. I'm
> > inclined to suggest that it shouldn't, as anyone who wants accurate
> > timekeeping shouldn't be using the KVM clock anyway.
> >
> > But we should at least be relatively consistent about it.
>
> ATM, the driver does indeed not have TSC support (for cross-timestamping)
> enabled at all, so would always use fallback. If *not* using the KVM clock,
> I think TSC can just be enabled by adding architecture-specific code
> similar to virtio_rtc_arm.c.
>
> I am not familiar with the KVM clock, but maybe it would be sufficient to
> allow CSID_X86_KVM_CLK as well?
Sure, that's what the ptp_kvm clock does. It actually obtains a TSC
reading from the "hardware", and then manually (and unconditionally)
converts that to a kvmclock value so that it can return a clock pairing
based on CSID_X86_KVM_CLK.
Which works until the user configures the clocksource to be the TSC
instead of kvmclock, and then hits that -ENODEV check and has to do the
fallback.
We should just tell the device which cs_id to use.
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5965 bytes --]
next prev parent reply other threads:[~2024-06-20 14:33 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-18 7:38 [RFC PATCH v3 0/7] Add virtio_rtc module and related changes Peter Hilber
2023-12-18 7:38 ` [RFC PATCH v3 4/7] virtio_rtc: Add module and driver core Peter Hilber
2023-12-18 7:38 ` [RFC PATCH v3 5/7] virtio_rtc: Add PTP clocks Peter Hilber
2024-06-15 8:01 ` David Woodhouse
2024-06-20 12:01 ` Peter Hilber
2024-06-20 14:33 ` David Woodhouse [this message]
2024-03-07 14:02 ` [RFC PATCH v3 0/7] Add virtio_rtc module and related changes David Woodhouse
2024-03-08 10:32 ` Peter Hilber
2024-03-08 12:33 ` David Woodhouse
2024-03-11 18:24 ` Peter Hilber
2024-03-12 17:15 ` David Woodhouse
2024-03-13 9:45 ` Peter Hilber
2024-03-13 11:18 ` Alexandre Belloni
2024-03-13 12:29 ` David Woodhouse
2024-03-13 12:58 ` Alexandre Belloni
2024-03-13 14:06 ` David Woodhouse
2024-03-13 14:50 ` Alexandre Belloni
2024-03-13 20:12 ` Andrew Lunn
2024-03-14 9:13 ` Peter Hilber
2024-03-13 17:50 ` Peter Hilber
2024-03-13 14:15 ` Peter Hilber
2024-03-13 12:45 ` David Woodhouse
2024-03-13 17:50 ` Peter Hilber
2024-03-13 18:18 ` David Woodhouse
2024-03-14 10:13 ` Peter Hilber
2024-03-14 14:19 ` David Woodhouse
2024-03-19 13:47 ` Peter Hilber
2024-03-20 17:22 ` David Woodhouse
2024-06-15 8:40 ` David Woodhouse
2024-06-20 12:37 ` Peter Hilber
2024-06-20 16:19 ` David Woodhouse
2024-06-21 8:45 ` David Woodhouse
2024-06-25 19:01 ` [RFC PATCH v2] ptp: Add vDSO-style vmclock support David Woodhouse
2024-06-25 21:34 ` Thomas Gleixner
2024-06-25 21:48 ` David Woodhouse
2024-06-25 22:22 ` John Stultz
2024-06-26 8:32 ` David Woodhouse
2024-06-26 16:43 ` Richard Cochran
2024-06-27 13:50 ` Peter Hilber
2024-06-27 14:52 ` David Woodhouse
2024-06-28 11:33 ` Peter Hilber
2024-06-28 12:15 ` David Woodhouse
2024-06-28 16:38 ` Peter Hilber
2024-06-28 21:27 ` David Woodhouse
2024-07-01 8:57 ` David Woodhouse
2024-07-02 15:03 ` Peter Hilber
2024-07-02 16:39 ` David Woodhouse
2024-07-02 18:12 ` Peter Hilber
2024-07-02 18:40 ` David Woodhouse
2024-07-03 9:56 ` Peter Hilber
2024-07-03 10:40 ` David Woodhouse
2024-07-05 8:12 ` Peter Hilber
2024-07-05 15:02 ` David Woodhouse
2024-07-06 7:50 ` Peter Hilber
2024-06-27 16:03 ` David Woodhouse
2024-06-28 11:33 ` Peter Hilber
2024-06-28 11:41 ` David Woodhouse
2024-06-30 13:28 ` Simon Horman
2024-07-01 8:02 ` David Woodhouse
2024-07-01 15:39 ` Kees Cook
2024-07-03 8:00 ` David Woodhouse
2024-06-27 13:50 ` [RFC PATCH v3 0/7] Add virtio_rtc module and related changes Peter Hilber
2024-06-21 14:02 ` David Woodhouse
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=01e1d19f290f49e12c67dbe8aadb8be49cc53eb4.camel@infradead.org \
--to=dwmw2@infradead.org \
--cc=daniel.lezcano@linaro.org \
--cc=jasowang@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=peter.hilber@opensynergy.com \
--cc=richardcochran@gmail.com \
--cc=tglx@linutronix.de \
--cc=virtio-dev@lists.oasis-open.org \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.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;
as well as URLs for NNTP newsgroup(s).