public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
	io-uring@vger.kernel.org,
	Vadim Fedorenko <vadim.fedorenko@linux.dev>
Cc: 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 1/5] net: timestamp: add helper returning skb's tx tstamp
Date: Mon, 2 Jun 2025 10:57:11 +0100	[thread overview]
Message-ID: <07d408c8-c816-4997-ab87-1a6521d0bacd@gmail.com> (raw)
In-Reply-To: <683c5b38ed614_232d4429431@willemb.c.googlers.com.notmuch>

On 6/1/25 14:52, Willem de Bruijn wrote:
> Pavel Begunkov wrote:
>> Add a helper function skb_get_tx_timestamp() that returns a tx timestamp
>> associated with an skb from an queue queue.
> 
> Just curious: why a timestamp specific operation, rather than a
> general error queue report?

Timestamps still need custom code, not like we can do a generic
implementation just by copying sock_extended_err to user. And then
it'll be a problem to fit it into completions, it's already tight
after placing the timeval directly into cqe, there are only
few bits left.

Either way, I guess it can be extended if there are more use cases,
or might be better introducing and new command to cover that and
share some of the handling.

...>> diff --git a/net/socket.c b/net/socket.c
>> index 9a0e720f0859..d1dc8ab28e46 100644
>> --- a/net/socket.c
>> +++ b/net/socket.c
>> @@ -843,6 +843,55 @@ 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, struct sock *sk)
> 
> Here and elsewhere: consider const pointers where possible

will do

> 
>> +{
>> +	u32 tsflags = READ_ONCE(sk->sk_tsflags);
>> +	struct sock_exterr_skb *serr = SKB_EXT_ERR(skb);
>> +
>> +	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);
>> +	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;
>> +	}
> 
> This is for SO_TIMESTAMP, not SO_TIMESTAMPING, and intended in the
> receive path only, where net_enable_timestamp may be too late for
> initial packets.

Got it, I'll drop that chunk if you think it's fine. Thanks
for review

>> +	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);
> 
> This duplicates code in __sock_recv_timestamp. Perhaps worth a helper.

I couldn't find a good way for doing that. There are rx checks in
every if, there is also pkt info handling nested. And
scm_timestamping_internal has 3 timeouts , so
__sock_recv_timestamp() would need to duplicate some checks to
choose the right place for the timeout or so.

-- 
Pavel Begunkov


  reply	other threads:[~2025-06-02  9:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-30 12:18 [PATCH io_uring-next 0/5] io_uring cmd for tx timestamps Pavel Begunkov
2025-05-30 12:18 ` [PATCH 1/5] net: timestamp: add helper returning skb's tx tstamp Pavel Begunkov
2025-05-30 18:14   ` Stanislav Fomichev
2025-05-30 18:30     ` Stanislav Fomichev
2025-05-30 18:44       ` Pavel Begunkov
2025-06-01 13:52   ` Willem de Bruijn
2025-06-02  9:57     ` Pavel Begunkov [this message]
2025-06-02 13:31       ` Willem de Bruijn
2025-06-04  8:51         ` Pavel Begunkov
2025-06-04 13:38           ` Willem de Bruijn
2025-05-30 12:18 ` [PATCH 2/5] io_uring/poll: introduce io_arm_apoll() Pavel Begunkov
2025-05-31 10:28   ` Pavel Begunkov
2025-05-30 12:18 ` [PATCH 3/5] io_uring/cmd: allow multishot polled commands Pavel Begunkov
2025-05-30 12:18 ` [PATCH 4/5] io_uring: add mshot helper for posting CQE32 Pavel Begunkov
2025-05-30 12:18 ` [PATCH 5/5] io_uring/netcmd: add tx timestamping cmd support Pavel Begunkov
2025-05-31  8:34   ` kernel test robot
2025-05-30 13:30 ` [PATCH io_uring-next 0/5] io_uring cmd for tx timestamps 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=07d408c8-c816-4997-ab87-1a6521d0bacd@gmail.com \
    --to=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 \
    --cc=willemdebruijn.kernel@gmail.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