Netdev List
 help / color / mirror / Atom feed
From: Jacob Keller <jacob.e.keller@intel.com>
To: Jordan Rhee <jordanrhee@google.com>, Jakub Kicinski <kuba@kernel.org>
Cc: Harshitha Ramamurthy <hramamurthy@google.com>,
	<netdev@vger.kernel.org>, <joshwash@google.com>,
	<andrew+netdev@lunn.ch>, <davem@davemloft.net>,
	<edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>,
	<richardcochran@gmail.com>, <willemb@google.com>,
	<nktgrg@google.com>, <jfraker@google.com>, <ziweixiao@google.com>,
	<maolson@google.com>, <thostet@google.com>,
	<jefrogers@google.com>, <alok.a.tiwari@oracle.com>,
	<yyd@google.com>, <linux-kernel@vger.kernel.org>,
	Naman Gulati <namangulati@google.com>
Subject: Re: [PATCH net-next v3 3/3] gve: implement PTP gettimex64
Date: Wed, 8 Apr 2026 15:43:40 -0700	[thread overview]
Message-ID: <093a5c92-f94c-49d6-96ea-0c76ff18f9e1@intel.com> (raw)
In-Reply-To: <CA+mzVtscZ9Dkcx8vq6MpCjNHqep3PoeuZff=o_V9usRo6eLBrw@mail.gmail.com>

On 4/6/2026 1:41 PM, Jordan Rhee wrote:
> On Fri, Apr 3, 2026 at 2:18 PM Jacob Keller <jacob.e.keller@intel.com> wrote:
>>
>> On 4/3/2026 12:44 PM, Harshitha Ramamurthy wrote:
>>> From: Jordan Rhee <jordanrhee@google.com>
>>>
>>> Enable chrony and phc2sys to synchronize system clock to NIC clock.
>>>
>>> The system cycle counters are sampled by the device to minimize the
>>> uncertainty window. If the system times are sampled in the host, the
>>> delta between pre and post readings is 100us or more due to AQ command
>>> latency. The system times returned by the device have a delta of ~1us,
>>> which enables significantly more accurate clock synchronization.
>>>
>>> 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>
>>> ---
>>
>>> +/*
>>> + * Convert a raw cycle count (e.g. from get_cycles()) to the system clock
>>> + * type specified by clockid. The system_time_snapshot must be taken before
>>> + * the cycle counter is sampled.
>>> + */
>>> +static int gve_cycles_to_timespec64(struct gve_priv *priv, clockid_t clockid,
>>> +                                 struct system_time_snapshot *snap,
>>> +                                 u64 cycles, struct timespec64 *ts)
>>> +{
>>> +     struct gve_cycles_to_clock_callback_ctx ctx = {0};
>>> +     struct system_device_crosststamp xtstamp;
>>> +     int err;
>>> +
>>> +     ctx.cycles = cycles;
>>> +     err = get_device_system_crosststamp(gve_cycles_to_clock_fn, &ctx, snap,
>>> +                                         &xtstamp);
>>> +     if (err) {
>>> +             dev_err_ratelimited(&priv->pdev->dev,
>>> +                                 "get_device_system_crosststamp() failed to convert %lld cycles to system time: %d\n",
>>> +                                 cycles,
>>> +                                 err);
>>> +             return err;
>>> +     }
>>> +
>>
>> This looks a lot like a cross timestamp (i.e. something like PCIe PTM)
>> Why not just implement the .crosstimestamp and PTP_SYS_OFF_PRECISE? Does
>> that not work properly? Or is this not really a cross timestamp despite
>> use of the get_device_system_crosststamp handler? :D
> 
> .crosstimestamp is for devices that support simultaneous NIC and
> system timestamps. Devices that don't support simultaneous timestamps
> have to take a system time sandwich by calling
> ptp_read_system_prets()/ptp_read_system_postts() on either side of the
> NIC timestamp. Upper layers (e.g. chrony) use the sandwich delta in
> nontrivial ways when estimating the system clock / NIC clock offset.
> This is information that must be preserved, and it would be incorrect
> to implement .crosstimestamp by returning the midpoint of the
> sandwich, as tempting as that implementation might be.
> 

True.

> Gvnic does not support simultaneous NIC and system timestamps, so it
> must use the sandwich technique. Since the NIC timestamp is obtained
> using a firmware (hypervisor) call, the uncertainty window would be
> too large if it were taken inside the VM. Gvnic takes the sandwich in
> the hypervisor and returns the raw TSC values to the VM.
> get_device_system_crosststamp() is used to convert the TSCs to system
> times, which I believe is the only correct way to do this conversion.
> Jordan
> 

Hmm. The function says:

"Synchronously capture system/device timestamp". That is what confuses
me. Your implementation uses gve_cycles_to_clock_fn() which just sets
some values in the system_counterval struct and exits. It doesn't
"capture a system/device timestamp" tuple.

This does feel a bit weird. No other caller appears to exist outside of
the cross timestamp implementations.

It sounds like what you want is a function that takes a cycles count
value and does the conversion from TSC to the appropriate clock, along
with all of the interopolation etc. What you've done is sort of a cludge
around get_device_system_crosststamp() to force it to do that for you
without actually using it as intended.

I'd argue it would be better to have a cycles_to_ktime() or something
which takes the TSC cycles value and the appropriate clock and does the
exact same flow as get_device_system_crosststamp() for converting the
cycles into proper ktime values without the mess of the callback
function etc.

I guess in principle what you've implemented is "correct" and
functional, but it definitely feels a bit weird to use the API in this
way. It smells like a neat hack instead of a proper interface for this
purpose.

That said, I won't object strongly if the maintainers are fine with
using it for this purpose.

Thanks,
Jake

  reply	other threads:[~2026-04-08 22:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-03 19:44 [PATCH net-next v3 0/3] gve: add support for PTP gettimex64 Harshitha Ramamurthy
2026-04-03 19:44 ` [PATCH net-next v3 1/3] gve: skip error logging for retryable AdminQ commands Harshitha Ramamurthy
2026-04-03 21:11   ` Jacob Keller
2026-04-03 21:29     ` Jordan Rhee
2026-04-03 19:44 ` [PATCH net-next v3 2/3] gve: make nic clock reads thread safe Harshitha Ramamurthy
2026-04-03 19:44 ` [PATCH net-next v3 3/3] gve: implement PTP gettimex64 Harshitha Ramamurthy
2026-04-03 21:17   ` Jacob Keller
2026-04-06 20:41     ` Jordan Rhee
2026-04-08 22:43       ` Jacob Keller [this message]
2026-04-09  1:08         ` 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=093a5c92-f94c-49d6-96ea-0c76ff18f9e1@intel.com \
    --to=jacob.e.keller@intel.com \
    --cc=alok.a.tiwari@oracle.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hramamurthy@google.com \
    --cc=jefrogers@google.com \
    --cc=jfraker@google.com \
    --cc=jordanrhee@google.com \
    --cc=joshwash@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=richardcochran@gmail.com \
    --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