From: Wen Gu <guwen@linux.alibaba.com>
To: "David Woodhouse" <dwmw2@infradead.org>,
"Richard Cochran" <richardcochran@gmail.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"John Stultz" <jstultz@google.com>,
"Thomas Gleixner" <tglx@kernel.org>,
"Stephen Boyd" <sboyd@kernel.org>,
"Anna-Maria Behnsen" <anna-maria@linutronix.de>,
"Frederic Weisbecker" <frederic@kernel.org>,
"Shuah Khan" <shuah@kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>,
"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
"Arnd Bergmann" <arnd@arndb.de>,
"Miroslav Lichvar" <mlichvar@redhat.com>,
"Julien Ridoux" <ridouxj@amazon.com>,
"Ryan Luu" <rluu@amazon.com>,
linux-kernel@vger.kernel.org
Cc: David Woodhouse <dwmw@amazon.co.uk>
Subject: Re: [RFC PATCH v3 10/10] kernel/time: Add /dev/vmclock_host miscdev
Date: Thu, 21 May 2026 14:29:46 +0800 [thread overview]
Message-ID: <d923d603-b500-4b99-a23a-de76f285f487@linux.alibaba.com> (raw)
In-Reply-To: <20260520135207.37826-11-dwmw2@infradead.org>
On 2026/5/20 21:33, David Woodhouse wrote:
> +/*
> + * Called from pvclock_gtod_notify on every timekeeping update.
> + * Only does real work when ntp_tick or skew_delta changes.
> + */
> +static int vmclock_host_notify(struct notifier_block *nb,
> + unsigned long was_set, void *data)
> +{
<...>
> +
> + /* Compute time tuple: C = A + ntp_error + time_offset */
> + ns = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
> + sec = tk->xtime_sec + tk->tai_offset;
> + ns += tk->ntp_error >> (tk->tkr_mono.shift + tk->ntp_error_shift);
> + ns += ntp_get_time_offset_ns(tk->id);
> +
> + while (ns < 0) {
> + ns += NSEC_PER_SEC;
> + sec--;
> + }
> + while (ns >= NSEC_PER_SEC) {
> + ns -= NSEC_PER_SEC;
> + sec++;
> + }
> +
> + counter_value = tk->tkr_mono.cycle_last;
> + hi = div64_u64_rem((u64)ns << 32, 1000000000ULL, &rem);
> + time_frac = (hi << 32) | div64_u64(rem << 32, 1000000000ULL);
> +
> + clock_status = !(ntp_get_status() & STA_UNSYNC) ?
> + VMCLOCK_STATUS_SYNCHRONIZED : VMCLOCK_STATUS_FREERUNNING;
> +
> + /* Prepare le values */
> + le_counter_value = cpu_to_le64(counter_value);
> + le_time_sec = cpu_to_le64(sec);
> + le_time_frac = cpu_to_le64(time_frac);
> + le_period_frac = cpu_to_le64(cached_period_frac);
> + period_shift = cached_period_shift;
> +
> + /* Update page under seqcount */
> + WRITE_ONCE(clk->seq_count, cpu_to_le32(
> + le32_to_cpu(READ_ONCE(clk->seq_count)) + 1));
> + smp_wmb();
> +
> + clk->counter_id = counter_id;
> + clk->counter_value = le_counter_value;
> + clk->time_sec = le_time_sec;
> + clk->time_frac_sec = le_time_frac;
> + if (period_changed) {
> + clk->counter_period_frac_sec = le_period_frac;
> + clk->counter_period_shift = period_shift;
> + }
> + clk->clock_status = clock_status;
> +
> + /* Set leap second indicator from NTP time_state */
> + switch (ntp_get_time_state()) {
> + case TIME_INS:
> + clk->leap_indicator = VMCLOCK_LEAP_PRE_POS;
> + break;
> + case TIME_DEL:
> + clk->leap_indicator = VMCLOCK_LEAP_PRE_NEG;
> + break;
> + case TIME_OOP:
> + clk->leap_indicator = VMCLOCK_LEAP_POS;
> + break;
> + case TIME_WAIT:
> + clk->leap_indicator = (ntp_get_status() & STA_DEL) ?
> + VMCLOCK_LEAP_POST_NEG : VMCLOCK_LEAP_POST_POS;
> + break;
> + default:
> + clk->leap_indicator = VMCLOCK_LEAP_NONE;
> + break;
> + }
> +
> + /* Export as TAI if tai_offset is known, otherwise UTC */
> + if (tk->tai_offset) {
> + clk->time_type = VMCLOCK_TIME_TAI;
> + clk->tai_offset_sec = cpu_to_le16((s16)tk->tai_offset);
I think this should be cpu_to_le16(-(s16)tk->tai_offset)?
vmclock_set_tk_reference() in Patch 9 treats clk->tai_offset_sec as
a (UTC - TAI) offset, so the sign here probably needs to be inverted.
> + clk->flags = cpu_to_le64(VMCLOCK_FLAG_TAI_OFFSET_VALID |
> + VMCLOCK_FLAG_TIME_MONOTONIC |
> + VMCLOCK_FLAG_NOTIFICATION_PRESENT);
> + } else {
> + clk->time_type = VMCLOCK_TIME_UTC;
> + clk->tai_offset_sec = 0;
> + clk->flags = cpu_to_le64(VMCLOCK_FLAG_TIME_MONOTONIC |
> + VMCLOCK_FLAG_NOTIFICATION_PRESENT);
> + }
> +
> + smp_wmb();
> + WRITE_ONCE(clk->seq_count, cpu_to_le32(
> + le32_to_cpu(READ_ONCE(clk->seq_count)) + 1));
> +
> + wake_up_interruptible(&vmclock_wait);
> + return NOTIFY_DONE;
> +}
next prev parent reply other threads:[~2026-05-21 6:30 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 13:33 [RFC PATCH v3 00/10] timekeeping: Fix drift tracking precision and add feed-forward discipline via vmclock David Woodhouse
2026-05-20 13:33 ` [RFC PATCH v3 01/10] MAINTAINERS: Add Miroslav as timekeeping reviewer David Woodhouse
2026-05-20 23:28 ` John Stultz
2026-05-20 13:33 ` [RFC PATCH v3 02/10] timekeeping: Remove xtime_remainder from ntp_error accumulation David Woodhouse
2026-05-22 11:41 ` David Woodhouse
2026-05-29 23:21 ` John Stultz
2026-05-30 10:51 ` David Woodhouse
2026-05-20 13:33 ` [RFC PATCH v3 03/10] timekeeping: Account for monotonicity adjustment in ntp_error David Woodhouse
2026-05-20 23:27 ` John Stultz
2026-05-20 23:36 ` David Woodhouse
2026-05-20 13:33 ` [RFC PATCH v3 04/10] timekeeping: Guard against divide-by-zero in timekeeping_adjust David Woodhouse
2026-05-20 23:29 ` John Stultz
2026-05-20 13:33 ` [RFC PATCH v3 05/10] timekeeping: Drive time_offset skew via per-tick ntp_error transfer David Woodhouse
2026-05-20 13:33 ` [RFC PATCH v3 06/10] ntp: Convert adjtime() to use time_offset instead of tick_length inflation David Woodhouse
2026-05-20 13:33 ` [RFC PATCH v3 07/10] ntp: Remove tick_length_base, use tick_length directly David Woodhouse
2026-05-20 13:33 ` [RFC PATCH v3 08/10] timekeeping: Add absolute reference for feed-forward clock discipline David Woodhouse
2026-05-20 13:33 ` [RFC PATCH v3 09/10] ptp_vmclock: Feed reference to timekeeping for feed-forward discipline David Woodhouse
2026-05-20 13:33 ` [RFC PATCH v3 10/10] kernel/time: Add /dev/vmclock_host miscdev David Woodhouse
2026-05-21 6:29 ` Wen Gu [this message]
2026-05-28 16:18 ` David Woodhouse
2026-05-23 11:49 ` [RFC PATCH v3 00/10] timekeeping: Fix drift tracking precision and add feed-forward discipline via vmclock 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=d923d603-b500-4b99-a23a-de76f285f487@linux.alibaba.com \
--to=guwen@linux.alibaba.com \
--cc=andrew+netdev@lunn.ch \
--cc=anna-maria@linutronix.de \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=dwmw2@infradead.org \
--cc=dwmw@amazon.co.uk \
--cc=edumazet@google.com \
--cc=frederic@kernel.org \
--cc=jstultz@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mlichvar@redhat.com \
--cc=pabeni@redhat.com \
--cc=peterz@infradead.org \
--cc=richardcochran@gmail.com \
--cc=ridouxj@amazon.com \
--cc=rluu@amazon.com \
--cc=sboyd@kernel.org \
--cc=shuah@kernel.org \
--cc=tglx@kernel.org \
--cc=thomas.weissschuh@linutronix.de \
/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®