From: Paolo Abeni <pabeni@redhat.com>
To: David Woodhouse <dwmw2@infradead.org>,
Richard Cochran <richardcochran@gmail.com>,
Peter Hilber <peter.hilber@opensynergy.com>,
linux-kernel@vger.kernel.org, virtualization@lists.linux.dev,
linux-arm-kernel@lists.infradead.org, linux-rtc@vger.kernel.org,
"Ridoux, Julien" <ridouxj@amazon.com>,
virtio-dev@lists.linux.dev, "Luu, Ryan" <rluu@amazon.com>,
"Chashper, David" <chashper@amazon.com>,
"Mohamed Abuelfotoh, Hazem" <abuehaze@amazon.com>
Cc: "Christopher S . Hall" <christopher.s.hall@intel.com>,
Jason Wang <jasowang@redhat.com>,
John Stultz <jstultz@google.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
netdev@vger.kernel.org, Stephen Boyd <sboyd@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
Marc Zyngier <maz@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Alessandro Zummo <a.zummo@towertech.it>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
qemu-devel <qemu-devel@nongnu.org>,
Simon Horman <horms@kernel.org>
Subject: Re: [PATCH] ptp: Add vDSO-style vmclock support
Date: Thu, 25 Jul 2024 13:20:57 +0200 [thread overview]
Message-ID: <541d338f-bffc-4393-a501-92d01e5c8edb@redhat.com> (raw)
In-Reply-To: <14d1626bc9ddae9d8ad19d3c508538d10f5a8e44.camel@infradead.org>
Hi,
Just a bunch of 'nits below
On 7/24/24 19:16, David Woodhouse wrote:
> diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c
> new file mode 100644
> index 000000000000..9c508c21c062
> --- /dev/null
> +++ b/drivers/ptp/ptp_vmclock.c
[...]
> +/*
> + * Multiply a 64-bit count by a 64-bit tick 'period' in units of seconds >> 64
> + * and add the fractional second part of the reference time.
> + *
> + * The result is a 128-bit value, the top 64 bits of which are seconds, and
> + * the low 64 bits are (seconds >> 64).
> + *
> + * If __int128 isn't available, perform the calculation 32 bits at a time to
> + * avoid overflow.
> + */
> +static inline uint64_t mul_u64_u64_shr_add_u64(uint64_t *res_hi, uint64_t delta,
> + uint64_t period, uint8_t shift,
> + uint64_t frac_sec)
Please, no 'inline' in \.c files
> +{
> + unsigned __int128 res = (unsigned __int128)delta * period;
> +
> + res >>= shift;
> + res += frac_sec;
> + *res_hi = res >> 64;
> + return (uint64_t)res;
> +}
> +
> +static inline bool tai_adjust(struct vmclock_abi *clk, uint64_t *sec)
> +{
Same here
> + if (likely(clk->time_type == VMCLOCK_TIME_UTC))
> + return true;
> +
> + if (clk->time_type == VMCLOCK_TIME_TAI &&
> + (clk->flags & VMCLOCK_FLAG_TAI_OFFSET_VALID)) {
> + if (sec)
> + *sec += clk->tai_offset_sec;
> + return true;
> + }
> + return false;
> +}
> +
> +static int vmclock_get_crosststamp(struct vmclock_state *st,
> + struct ptp_system_timestamp *sts,
> + struct system_counterval_t *system_counter,
> + struct timespec64 *tspec)
> +{
> + ktime_t deadline = ktime_add(ktime_get(), VMCLOCK_MAX_WAIT);
> + struct system_time_snapshot systime_snapshot;
> + uint64_t cycle, delta, seq, frac_sec;
> +
> +#ifdef CONFIG_X86
> + /*
> + * We'd expect the hypervisor to know this and to report the clock
> + * status as VMCLOCK_STATUS_UNRELIABLE. But be paranoid.
> + */
> + if (check_tsc_unstable())
> + return -EINVAL;
> +#endif
> +
> + while (1) {
> + seq = st->clk->seq_count & ~1ULL;
> + virt_rmb();
Please document which other barrier pair witht this one
> +
> + if (st->clk->clock_status == VMCLOCK_STATUS_UNRELIABLE)
> + return -EINVAL;
> +
> + /*
> + * When invoked for gettimex64(), fill in the pre/post system
> + * times. The simple case is when system time is based on the
> + * same counter as st->cs_id, in which case all three times
> + * will be derived from the *same* counter value.
> + *
> + * If the system isn't using the same counter, then the value
> + * from ktime_get_snapshot() will still be used as pre_ts, and
> + * ptp_read_system_postts() is called to populate postts after
> + * calling get_cycles().
> + *
> + * The conversion to timespec64 happens further down, outside
> + * the seq_count loop.
> + */
> + if (sts) {
> + ktime_get_snapshot(&systime_snapshot);
> + if (systime_snapshot.cs_id == st->cs_id) {
> + cycle = systime_snapshot.cycles;
> + } else {
> + cycle = get_cycles();
> + ptp_read_system_postts(sts);
> + }
> + } else
> + cycle = get_cycles();
Please use the brackets even for the else case
[...]
> +static int ptp_vmclock_get_time_fn(ktime_t *device_time,
> + struct system_counterval_t *system_counter,
> + void *ctx)
> +{
> + struct vmclock_state *st = ctx;
> + struct timespec64 tspec;
> + int ret;
> +
> +#ifdef SUPPORT_KVMCLOCK
> + if (READ_ONCE(st->sys_cs_id) == CSID_X86_KVM_CLK)
> + ret = vmclock_get_crosststamp_kvmclock(st, NULL, system_counter,
> + &tspec);
> + else
> +#endif
> + ret = vmclock_get_crosststamp(st, NULL, system_counter, &tspec);
> +
> + if (!ret)
> + *device_time = timespec64_to_ktime(tspec);
> +
> + return ret;
> +}
> +
> +
Please, don't add 2 consecutive blank lines.
Cheers,
Paolo
next prev parent reply other threads:[~2024-07-25 11:23 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-24 17:16 [PATCH] ptp: Add vDSO-style vmclock support David Woodhouse
2024-07-25 5:48 ` Michael S. Tsirkin
2024-07-25 9:56 ` David Woodhouse
2024-07-25 11:31 ` Daniel P. Berrangé
2024-07-25 11:53 ` David Woodhouse
2024-07-25 12:00 ` Daniel P. Berrangé
2024-07-25 12:17 ` Michael S. Tsirkin
2024-07-25 12:27 ` David Woodhouse
2024-07-25 12:29 ` Michael S. Tsirkin
2024-07-25 12:31 ` David Woodhouse
2024-07-25 12:33 ` Michael S. Tsirkin
2024-07-25 13:50 ` David Woodhouse
2024-07-25 14:11 ` Michael S. Tsirkin
2024-07-25 15:18 ` David Woodhouse
2024-07-25 16:38 ` Michael S. Tsirkin
2024-07-25 19:35 ` David Woodhouse
2024-07-25 20:50 ` Michael S. Tsirkin
2024-07-25 21:00 ` David Woodhouse
2024-07-25 21:04 ` Michael S. Tsirkin
2024-07-25 21:29 ` David Woodhouse
2024-07-25 21:47 ` Michael S. Tsirkin
2024-07-25 22:20 ` David Woodhouse
2024-07-26 6:06 ` Michael S. Tsirkin
2024-07-26 8:35 ` David Woodhouse
2024-07-26 12:52 ` Michael S. Tsirkin
2024-07-26 13:00 ` David Woodhouse
2024-07-26 13:04 ` Michael S. Tsirkin
2024-07-26 13:08 ` David Woodhouse
2024-07-26 5:09 ` Michael S. Tsirkin
2024-07-26 5:55 ` Michael S. Tsirkin
2024-07-26 8:06 ` David Woodhouse
2024-07-26 12:47 ` Michael S. Tsirkin
2024-07-26 12:51 ` David Woodhouse
2024-07-26 16:49 ` Jonathan Cameron via
2024-07-26 18:28 ` David Woodhouse
2024-07-28 10:37 ` Michael S. Tsirkin
2024-07-28 13:07 ` David Woodhouse
2024-07-28 15:23 ` Michael S. Tsirkin
2024-07-29 6:45 ` David Woodhouse
2024-07-25 5:54 ` Michael S. Tsirkin
2024-07-25 10:00 ` David Woodhouse
2024-07-25 11:20 ` Paolo Abeni [this message]
2024-07-25 11:49 ` 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=541d338f-bffc-4393-a501-92d01e5c8edb@redhat.com \
--to=pabeni@redhat.com \
--cc=a.zummo@towertech.it \
--cc=abuehaze@amazon.com \
--cc=alexandre.belloni@bootlin.com \
--cc=chashper@amazon.com \
--cc=christopher.s.hall@intel.com \
--cc=daniel.lezcano@linaro.org \
--cc=dwmw2@infradead.org \
--cc=horms@kernel.org \
--cc=jasowang@redhat.com \
--cc=jstultz@google.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@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=qemu-devel@nongnu.org \
--cc=richardcochran@gmail.com \
--cc=ridouxj@amazon.com \
--cc=rluu@amazon.com \
--cc=sboyd@kernel.org \
--cc=tglx@linutronix.de \
--cc=virtio-dev@lists.linux.dev \
--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).