From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, Vadim Fedorenko <vadim.fedorenko@linux.dev>
Subject: [PATCH RFC 3/7] net: timestamp: add helper returning skb's tx tstamp
Date: Mon, 28 Apr 2025 13:52:34 +0100 [thread overview]
Message-ID: <73287c9af35f3f7294d7dcd31772692f33b5b330.1745843119.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1745843119.git.asml.silence@gmail.com>
Add a helper function skb_get_tx_timestamp() that returns a tx timestamp
associated with an skb from an queue queue.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
include/net/sock.h | 3 +++
net/socket.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/include/net/sock.h b/include/net/sock.h
index 694f954258d4..37fb15a04799 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2661,6 +2661,9 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
void __sock_recv_wifi_status(struct msghdr *msg, struct sock *sk,
struct sk_buff *skb);
+bool skb_get_tx_timestamp(struct sock *sk, struct sk_buff *skb,
+ struct timespec64 *ts);
+
static inline void
sock_recv_timestamp(struct msghdr *msg, struct sock *sk, struct sk_buff *skb)
{
diff --git a/net/socket.c b/net/socket.c
index 9a0e720f0859..2ae776011ca1 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -843,6 +843,38 @@ static void put_ts_pktinfo(struct msghdr *msg, struct sk_buff *skb,
sizeof(ts_pktinfo), &ts_pktinfo);
}
+bool skb_get_tx_timestamp(struct sock *sk, struct sk_buff *skb,
+ struct timespec64 *ts)
+{
+ u32 tsflags = READ_ONCE(sk->sk_tsflags);
+ bool false_tstamp = false;
+ ktime_t hwtstamp;
+ int if_index = 0;
+
+ if (sock_flag(sk, SOCK_RCVTSTAMP) && skb->tstamp == 0) {
+ __net_timestamp(skb);
+ false_tstamp = true;
+ }
+
+ if ((tsflags & SOF_TIMESTAMPING_SOFTWARE) &&
+ ktime_to_timespec64_cond(skb->tstamp, ts))
+ return true;
+
+ if (!(tsflags & SOF_TIMESTAMPING_RAW_HARDWARE) ||
+ skb_is_swtx_tstamp(skb, false_tstamp))
+ return false;
+
+ if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP_NETDEV)
+ hwtstamp = get_timestamp(sk, skb, &if_index);
+ else
+ hwtstamp = skb_hwtstamps(skb)->hwtstamp;
+
+ if (tsflags & SOF_TIMESTAMPING_BIND_PHC)
+ hwtstamp = ptp_convert_timestamp(&hwtstamp,
+ READ_ONCE(sk->sk_bind_phc));
+ return ktime_to_timespec64_cond(hwtstamp, ts);
+}
+
/*
* called from sock_recv_timestamp() if sock_flag(sk, SOCK_RCVTSTAMP)
*/
--
2.48.1
next prev parent reply other threads:[~2025-04-28 12:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-28 12:52 [PATCH RFC 0/7] tx timestamp io_uring commands Pavel Begunkov
2025-04-28 12:52 ` [PATCH RFC 1/7] io_uring: delete misleading comment in io_fill_cqe_aux() Pavel Begunkov
2025-04-28 12:52 ` [PATCH RFC 2/7] io_uring/cmd: move net cmd into a separate file Pavel Begunkov
2025-04-28 12:52 ` Pavel Begunkov [this message]
2025-04-28 12:52 ` [PATCH RFC 4/7] io_uring/poll: introduce io_arm_apoll() Pavel Begunkov
2025-04-28 12:52 ` [PATCH RFC 5/7] io_uring/cmd: allow multishot polled commands Pavel Begunkov
2025-04-28 12:52 ` [PATCH RFC 6/7] io_uring: add mshot helper for posting CQE32 Pavel Begunkov
2025-04-28 12:52 ` [PATCH RFC 7/7] io_uring/cmd: add tx timestamping cmd support Pavel Begunkov
2025-04-28 13:08 ` [PATCH RFC 0/7] tx timestamp io_uring commands Pavel Begunkov
2025-04-28 17:51 ` Jens Axboe
2025-04-28 17:51 ` (subset) " Jens Axboe
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=73287c9af35f3f7294d7dcd31772692f33b5b330.1745843119.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=io-uring@vger.kernel.org \
--cc=vadim.fedorenko@linux.dev \
/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