From: Harshitha Ramamurthy <hramamurthy@google.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, jeroendb@google.com, hramamurthy@google.com,
andrew+netdev@lunn.ch, willemb@google.com, ziweixiao@google.com,
pkaligineedi@google.com, yyd@google.com, joshwash@google.com,
shailend@google.com, linux@treblig.org, thostet@google.com,
jfraker@google.com, richardcochran@gmail.com,
jdamato@fastly.com, vadim.fedorenko@linux.dev, horms@kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next v4 6/8] gve: Add rx hardware timestamp expansion
Date: Mon, 9 Jun 2025 18:40:27 +0000 [thread overview]
Message-ID: <20250609184029.2634345-7-hramamurthy@google.com> (raw)
In-Reply-To: <20250609184029.2634345-1-hramamurthy@google.com>
From: John Fraker <jfraker@google.com>
Allow the rx path to recover the high 32 bits of the full 64 bit rx
timestamp.
Use the low 32 bits of the last synced nic time and the 32 bits of the
timestamp provided in the rx descriptor to generate a difference, which
is then applied to the last synced nic time to reconstruct the complete
64-bit timestamp.
This scheme remains accurate as long as no more than ~2 seconds have
passed between the last read of the nic clock and the timestamping
application of the received packet.
Signed-off-by: John Fraker <jfraker@google.com>
Signed-off-by: Ziwei Xiao <ziweixiao@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Harshitha Ramamurthy <hramamurthy@google.com>
---
Changes in v3:
- Change the last_read to be u64 (Vadim Fedorenko)
Changes in v2:
- Add the missing READ_ONCE (Joe Damato)
---
drivers/net/ethernet/google/gve/gve_rx_dqo.c | 23 ++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/drivers/net/ethernet/google/gve/gve_rx_dqo.c b/drivers/net/ethernet/google/gve/gve_rx_dqo.c
index dcb0545baa50..9aadf8435f8b 100644
--- a/drivers/net/ethernet/google/gve/gve_rx_dqo.c
+++ b/drivers/net/ethernet/google/gve/gve_rx_dqo.c
@@ -437,6 +437,29 @@ static void gve_rx_skb_hash(struct sk_buff *skb,
skb_set_hash(skb, le32_to_cpu(compl_desc->hash), hash_type);
}
+/* Expand the hardware timestamp to the full 64 bits of width, and add it to the
+ * skb.
+ *
+ * This algorithm works by using the passed hardware timestamp to generate a
+ * diff relative to the last read of the nic clock. This diff can be positive or
+ * negative, as it is possible that we have read the clock more recently than
+ * the hardware has received this packet. To detect this, we use the high bit of
+ * the diff, and assume that the read is more recent if the high bit is set. In
+ * this case we invert the process.
+ *
+ * Note that this means if the time delta between packet reception and the last
+ * clock read is greater than ~2 seconds, this will provide invalid results.
+ */
+static void __maybe_unused gve_rx_skb_hwtstamp(struct gve_rx_ring *rx, u32 hwts)
+{
+ u64 last_read = READ_ONCE(rx->gve->last_sync_nic_counter);
+ struct sk_buff *skb = rx->ctx.skb_head;
+ u32 low = (u32)last_read;
+ s32 diff = hwts - low;
+
+ skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(last_read + diff);
+}
+
static void gve_rx_free_skb(struct napi_struct *napi, struct gve_rx_ring *rx)
{
if (!rx->ctx.skb_head)
--
2.50.0.rc0.604.gd4ff7b7c86-goog
next prev parent reply other threads:[~2025-06-09 18:40 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-09 18:40 [PATCH net-next v4 0/8] gve: Add Rx HW timestamping support Harshitha Ramamurthy
2025-06-09 18:40 ` [PATCH net-next v4 1/8] gve: Add device option for nic clock synchronization Harshitha Ramamurthy
2025-06-09 18:40 ` [PATCH net-next v4 2/8] gve: Add adminq command to report nic timestamp Harshitha Ramamurthy
2025-06-09 18:40 ` [PATCH net-next v4 3/8] gve: Add initial PTP device support Harshitha Ramamurthy
2025-06-09 18:40 ` [PATCH net-next v4 4/8] gve: Add adminq lock for queues creation and destruction Harshitha Ramamurthy
2025-06-09 18:40 ` [PATCH net-next v4 5/8] gve: Add support to query the nic clock Harshitha Ramamurthy
2025-06-10 9:47 ` Vadim Fedorenko
2025-06-11 1:25 ` Jakub Kicinski
2025-06-11 23:41 ` Ziwei Xiao
2025-06-09 18:40 ` Harshitha Ramamurthy [this message]
2025-06-10 9:49 ` [PATCH net-next v4 6/8] gve: Add rx hardware timestamp expansion Vadim Fedorenko
2025-06-09 18:40 ` [PATCH net-next v4 7/8] gve: Implement ndo_hwtstamp_get/set for RX timestamping Harshitha Ramamurthy
2025-06-09 18:40 ` [PATCH net-next v4 8/8] gve: Advertise support for rx hardware timestamping Harshitha Ramamurthy
2025-06-11 1:23 ` [PATCH net-next v4 0/8] gve: Add Rx HW timestamping support Jakub Kicinski
2025-06-11 22:05 ` Ziwei Xiao
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=20250609184029.2634345-7-hramamurthy@google.com \
--to=hramamurthy@google.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jdamato@fastly.com \
--cc=jeroendb@google.com \
--cc=jfraker@google.com \
--cc=joshwash@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@treblig.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pkaligineedi@google.com \
--cc=richardcochran@gmail.com \
--cc=shailend@google.com \
--cc=thostet@google.com \
--cc=vadim.fedorenko@linux.dev \
--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;
as well as URLs for NNTP newsgroup(s).