public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Jason Xing <kerneljasonxing@gmail.com>
To: Pavel Begunkov <asml.silence@gmail.com>
Cc: io-uring@vger.kernel.org,
	Vadim Fedorenko <vadim.fedorenko@linux.dev>,
	 netdev@vger.kernel.org, Eric Dumazet <edumazet@google.com>,
	 Kuniyuki Iwashima <kuniyu@amazon.com>,
	Paolo Abeni <pabeni@redhat.com>,
	 Willem de Bruijn <willemb@google.com>,
	"David S . Miller" <davem@davemloft.net>,
	 Jakub Kicinski <kuba@kernel.org>,
	Richard Cochran <richardcochran@gmail.com>
Subject: Re: [PATCH v2 1/5] net: timestamp: add helper returning skb's tx tstamp
Date: Thu, 5 Jun 2025 11:51:46 +0800	[thread overview]
Message-ID: <CAL+tcoAVq5AcD+YAjT3OgLEgrvFeY8phZgqk23m++A+hdEu9RQ@mail.gmail.com> (raw)
In-Reply-To: <3fd901885e836b924b9acc4c9dc1b0148612a480.1749026421.git.asml.silence@gmail.com>

On Wed, Jun 4, 2025 at 4:41 PM Pavel Begunkov <asml.silence@gmail.com> wrote:
>
> 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>

Reviewed-by: Jason Xing <kerneljasonxing@gmail.com>

Thanks,
Jason

> ---
>  include/net/sock.h |  4 ++++
>  net/socket.c       | 43 +++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 47 insertions(+)
>
> diff --git a/include/net/sock.h b/include/net/sock.h
> index 92e7c1aae3cc..1cd288880ab3 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -2677,6 +2677,10 @@ 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_has_tx_timestamp(struct sk_buff *skb, const struct sock *sk);
> +bool skb_get_tx_timestamp(struct sk_buff *skb, struct sock *sk,
> +                         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..e9c8f3074fe1 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -843,6 +843,49 @@ static void put_ts_pktinfo(struct msghdr *msg, struct sk_buff *skb,
>                  sizeof(ts_pktinfo), &ts_pktinfo);
>  }
>
> +bool skb_has_tx_timestamp(struct sk_buff *skb, const struct sock *sk)
> +{
> +       const struct sock_exterr_skb *serr = SKB_EXT_ERR(skb);
> +       u32 tsflags = READ_ONCE(sk->sk_tsflags);
> +
> +       if (serr->ee.ee_errno != ENOMSG ||
> +          serr->ee.ee_origin != SO_EE_ORIGIN_TIMESTAMPING)
> +               return false;
> +
> +       /* software time stamp available and wanted */
> +       if ((tsflags & SOF_TIMESTAMPING_SOFTWARE) && skb->tstamp)
> +               return true;
> +       /* hardware time stamps available and wanted */
> +       return (tsflags & SOF_TIMESTAMPING_RAW_HARDWARE) &&
> +               skb_hwtstamps(skb)->hwtstamp;
> +}
> +
> +bool skb_get_tx_timestamp(struct sk_buff *skb, struct sock *sk,
> +                         struct timespec64 *ts)
> +{
> +       u32 tsflags = READ_ONCE(sk->sk_tsflags);
> +       ktime_t hwtstamp;
> +       int if_index = 0;
> +
> +       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))
> +               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.49.0
>
>

  parent reply	other threads:[~2025-06-05  3:52 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-04  8:42 [PATCH v2 0/5] io_uring cmd for tx timestamps Pavel Begunkov
2025-06-04  8:42 ` [PATCH v2 1/5] net: timestamp: add helper returning skb's tx tstamp Pavel Begunkov
2025-06-04 15:37   ` Stanislav Fomichev
2025-06-05  0:52   ` Willem de Bruijn
2025-06-05  3:51   ` Jason Xing [this message]
2025-06-04  8:42 ` [PATCH v2 2/5] io_uring/poll: introduce io_arm_apoll() Pavel Begunkov
2025-06-04  8:42 ` [PATCH v2 3/5] io_uring/cmd: allow multishot polled commands Pavel Begunkov
2025-06-04  8:42 ` [PATCH v2 4/5] io_uring: add mshot helper for posting CQE32 Pavel Begunkov
2025-06-04  8:42 ` [PATCH v2 5/5] io_uring/netcmd: add tx timestamping cmd support Pavel Begunkov
2025-06-04 12:04   ` Jens Axboe
2025-06-04 12:33     ` Pavel Begunkov
2025-06-05  0:59   ` Willem de Bruijn
2025-06-05 10:25     ` Vadim Fedorenko
2025-06-05 11:01       ` Pavel Begunkov
2025-06-05 23:54       ` Willem de Bruijn
2025-06-06  0:17         ` Jason Xing
2025-06-06  0:02       ` Jason Xing
2025-06-06  8:12         ` Pavel Begunkov
2025-06-06  8:33           ` Jason Xing
2025-06-06  9:08             ` Pavel Begunkov
2025-06-04  8:53 ` [PATCH v2 0/5] io_uring cmd for tx timestamps Pavel Begunkov
2025-06-04 12:06 ` Jens Axboe
2025-06-04 12:38   ` Pavel Begunkov

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=CAL+tcoAVq5AcD+YAjT3OgLEgrvFeY8phZgqk23m++A+hdEu9RQ@mail.gmail.com \
    --to=kerneljasonxing@gmail.com \
    --cc=asml.silence@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=io-uring@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@amazon.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=vadim.fedorenko@linux.dev \
    --cc=willemb@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