From: Jacob Keller <jacob.e.keller@intel.com>
To: Harshitha Ramamurthy <hramamurthy@google.com>, <netdev@vger.kernel.org>
Cc: <joshwash@google.com>, <andrew+netdev@lunn.ch>,
<davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<pabeni@redhat.com>, <richardcochran@gmail.com>,
<jstultz@google.com>, <tglx@kernel.org>, <sboyd@kernel.org>,
<willemb@google.com>, <nktgrg@google.com>, <jfraker@google.com>,
<ziweixiao@google.com>, <maolson@google.com>,
<jordanrhee@google.com>, <thostet@google.com>,
<alok.a.tiwari@oracle.com>, <pkaligineedi@google.com>,
<horms@kernel.org>, <dwmw2@infradead.org>, <yyd@google.com>,
<jefrogers@google.com>, <linux-kernel@vger.kernel.org>,
Naman Gulati <namangulati@google.com>
Subject: Re: [PATCH net-next v6 3/3] gve: implement PTP gettimex64
Date: Thu, 7 May 2026 14:23:22 -0700 [thread overview]
Message-ID: <4fb57921-33a6-4ab3-a0a8-9b8c3a48fd24@intel.com> (raw)
In-Reply-To: <20260507211304.3046526-4-hramamurthy@google.com>
On 5/7/2026 2:13 PM, Harshitha Ramamurthy wrote:
> From: Jordan Rhee <jordanrhee@google.com>
>
> Enable chrony and phc2sys to synchronize system clock to NIC clock.
>
> Two paths are implemented: a precise path using system counter values
> sampled by the device, and a fallback path using system counter values
> sampled in the driver using ptp_read_system_prets()/postts().
>
> To use the precise path, the current system clocksource must match the
> units returned by the device, which on x86 is X86_TSC and on ARM64 is
> ARM_ARCH_COUNTER. The clockid requested for the cross-timestamp must
> be either CLOCK_REALTIME or CLOCK_MONOTONIC_RAW. These conditions hold
> by default on GCP VMs using Chrony, so we expect the precise path to be
> used the vast majority of the time. If the system clocksource is changed
> to kvm-clock, it activates the fallback path. Ethtool counters have been
> added to count how many times each path is used.
>
> The uncertainty window in the precise path is typically around 1-2us,
> while in the fallback path is around 60-80us.
>
> Stub implementions of adjfine and adjtime are added to avoid NULL
> dereference when phc2sys tries to adjust the clock.
>
> Cc: John Stultz <jstultz@google.com>
> Cc: Thomas Gleixner <tglx@kernel.org>
> Cc: Stephen Boyd <sboyd@kernel.org>
> Cc: David Woodhouse <dwmw2@infradead.org>
> Reviewed-by: Willem de Bruijn <willemb@google.com>
> Reviewed-by: Kevin Yang <yyd@google.com>
> Reviewed-by: Naman Gulati <namangulati@google.com>
> Signed-off-by: Jordan Rhee <jordanrhee@google.com>
> Signed-off-by: Harshitha Ramamurthy <hramamurthy@google.com>
> ---
> Changes in v6:
> - Added a fallback to driver-sampled time sandwich that is used when
> the following conditions are not met:
> - The system clock source is X86_TSC or ARM_ARCH_COUNTER
> - The requested clockid is CLOCK_REALTIME or CLOCK_MONOTONIC_RAW
> - The architecture is x86 or ARM64
> - Added ethtool statistics to count how many cross-timestamps used the
> precise path versus fallback path.
> - Fixed printf format specifier.
> - Added stub implementions of adjtime and adjfine to prevent NULL
> dereference when phc2sys tries to adjust clock.
All excellent improvements.
> - Moved system time snapshot back to gve_ptp_gettimex64() so we can get the
> current system clock source from it. It is OK for it to not be inside
> the mutex or retry loop because lock contention and retries should be
> extremely rare, and chrony filters out bad samples.
>
I'm a bit worried about this part, but if I understand, it would only
affect the fallback variant anyways since the clock samples are taken in
the host in the precise/fast path.
> Changes in v5:
> - Reformulate retry loop in terms of total timeout (Jakub Kicinski)
>
> Changes in v3:
> - Take system time snapshot inside the mutex
> - Return -EOPNOTSUPP if cross-timestamp is requested on an arch other
> than x86 or arm64
>
> Changes in v2:
> - fix compilation warning on ARM by casting cycles_t to u64
> ---
> drivers/net/ethernet/google/gve/gve.h | 8 +
> drivers/net/ethernet/google/gve/gve_adminq.h | 4 +-
> drivers/net/ethernet/google/gve/gve_ethtool.c | 3 +
> drivers/net/ethernet/google/gve/gve_ptp.c | 237 +++++++++++++++++-
> 4 files changed, 243 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/net/ethernet/google/gve/gve.h b/drivers/net/ethernet/google/gve/gve.h
> index 7b69d0cfc0d5..4de3ce60060e 100644
> --- a/drivers/net/ethernet/google/gve/gve.h
> +++ b/drivers/net/ethernet/google/gve/gve.h
> @@ -880,6 +880,14 @@ struct gve_priv {
> u32 stats_report_trigger_cnt; /* count of device-requested stats-reports since last reset */
> u32 suspend_cnt; /* count of times suspended */
> u32 resume_cnt; /* count of times resumed */
> + /* count of cross-timestamps attempted using system timestamps
> + * from the AQ command
> + */
> + u32 ptp_precise_xtstamps;
> + /* count of cross-timestamps attempted using system timestamps sampled
> + * by the driver
> + */
Helpful for analyzing when its not working. Nice!
> +static int gve_cycles_to_clock_fn(ktime_t *device_time,
> + struct system_counterval_t *system_counterval,
> + void *ctx)
> +{
> + struct gve_cycles_to_clock_callback_ctx *context = ctx;
> +
> + *device_time = 0;
> +
> + system_counterval->cycles = context->cycles;
> + system_counterval->use_nsecs = false;
> +
> + if (IS_ENABLED(CONFIG_X86))
> + system_counterval->cs_id = CSID_X86_TSC;
> + else if (IS_ENABLED(CONFIG_ARM64))
> + system_counterval->cs_id = CSID_ARM_ARCH_COUNTER;
> + else
No single kernel can be compiled for both CONFIG_X86 *and* CONFIG_ARM64
simultaneously, so there is no need to check in sequence and an
exclusive if/else path is fine. Ok.
> +
> +static bool
> +gve_can_use_system_ts_from_device(enum clocksource_ids system_clock_source,
> + clockid_t clockid)
> +{
> + if (clockid != CLOCK_REALTIME && clockid != CLOCK_MONOTONIC_RAW)
> + return false;
> +
> + /* If the system clock source matches the system clock
> + * returned by the AdminQ command, we can use the system
> + * timestamps returned by the device, otherwise we have to
> + * fall back to sampling system time from the host which
> + * is less accurate.
> + */
> + if (IS_ENABLED(CONFIG_X86))
> + return system_clock_source == CSID_X86_TSC;
> + else if (IS_ENABLED(CONFIG_ARM64))
> + return system_clock_source == CSID_ARM_ARCH_COUNTER;
> +
This feels a bit duplicated to me, since you have the same check
elsewhere. Would it make sense to pull this to its own function check?
Its short enough I think that is only warranted if you have a true
(non-nit) cause to make a v7.
Thus:
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
next prev parent reply other threads:[~2026-05-07 21:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-07 21:13 [PATCH net-next v6 0/3] gve: add support for PTP gettimex64 Harshitha Ramamurthy
2026-05-07 21:13 ` [PATCH net-next v6 1/3] gve: skip error logging for retryable AdminQ commands Harshitha Ramamurthy
2026-05-07 21:14 ` Jacob Keller
2026-05-10 4:31 ` Jordan Rhee
2026-05-07 21:13 ` [PATCH net-next v6 2/3] gve: make nic clock reads thread safe Harshitha Ramamurthy
2026-05-07 21:15 ` Jacob Keller
2026-05-07 21:13 ` [PATCH net-next v6 3/3] gve: implement PTP gettimex64 Harshitha Ramamurthy
2026-05-07 21:23 ` Jacob Keller [this message]
2026-05-08 17:43 ` Jordan Rhee
2026-05-08 21:53 ` Jacob Keller
2026-05-10 4:54 ` Jordan Rhee
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=4fb57921-33a6-4ab3-a0a8-9b8c3a48fd24@intel.com \
--to=jacob.e.keller@intel.com \
--cc=alok.a.tiwari@oracle.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=dwmw2@infradead.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=hramamurthy@google.com \
--cc=jefrogers@google.com \
--cc=jfraker@google.com \
--cc=jordanrhee@google.com \
--cc=joshwash@google.com \
--cc=jstultz@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maolson@google.com \
--cc=namangulati@google.com \
--cc=netdev@vger.kernel.org \
--cc=nktgrg@google.com \
--cc=pabeni@redhat.com \
--cc=pkaligineedi@google.com \
--cc=richardcochran@gmail.com \
--cc=sboyd@kernel.org \
--cc=tglx@kernel.org \
--cc=thostet@google.com \
--cc=willemb@google.com \
--cc=yyd@google.com \
--cc=ziweixiao@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