[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <70880c86-34e7-410b-b15e-79f7a039df8d@gmail.com>
Date: Fri, 13 Jun 2025 19:29:51 +0100
From: Pavel Begunkov <asml.silence@...il.com>
To: Willem de Bruijn <willemdebruijn.kernel@...il.com>,
io-uring@...r.kernel.org, Vadim Fedorenko <vadim.fedorenko@...ux.dev>
Cc: netdev@...r.kernel.org, Eric Dumazet <edumazet@...gle.com>,
Kuniyuki Iwashima <kuniyu@...zon.com>, Paolo Abeni <pabeni@...hat.com>,
Willem de Bruijn <willemb@...gle.com>, "David S . Miller"
<davem@...emloft.net>, Jakub Kicinski <kuba@...nel.org>,
Richard Cochran <richardcochran@...il.com>,
Stanislav Fomichev <sdf@...ichev.me>, Jason Xing <kerneljasonxing@...il.com>
Subject: Re: [PATCH v3 5/5] io_uring/netcmd: add tx timestamping cmd support
On 6/12/25 22:35, Willem de Bruijn wrote:
> Pavel Begunkov wrote:
>> Add a new socket command which returns tx time stamps to the user. It
>> provide an alternative to the existing error queue recvmsg interface.
>> The command works in a polled multishot mode, which means io_uring will
>> poll the socket and keep posting timestamps until the request is
>> cancelled or fails in any other way (e.g. with no space in the CQ). It
>> reuses the net infra and grabs timestamps from the socket's error queue.
>>
>> The command requires IORING_SETUP_CQE32. All non-final CQEs (marked with
>> IORING_CQE_F_MORE) have cqe->res set to the tskey, and the upper 16 bits
>> of cqe->flags keep tstype (i.e. offset by IORING_CQE_BUFFER_SHIFT). The
>> timevalue is store in the upper part of the extended CQE. The final
>> completion won't have IORING_CQR_F_MORE and will have cqe->res storing
>> 0/error.
>>
>> Suggested-by: Vadim Fedorenko <vadim.fedorenko@...ux.dev>
>> Signed-off-by: Pavel Begunkov <asml.silence@...il.com>
>> ---
>> include/uapi/linux/io_uring.h | 9 ++++
>> io_uring/cmd_net.c | 82 +++++++++++++++++++++++++++++++++++
>> 2 files changed, 91 insertions(+)
>>
>> diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
>> index cfd17e382082..5c89e6f6d624 100644
>> --- a/include/uapi/linux/io_uring.h
>> +++ b/include/uapi/linux/io_uring.h
>> @@ -968,6 +968,15 @@ enum io_uring_socket_op {
>> SOCKET_URING_OP_SIOCOUTQ,
>> SOCKET_URING_OP_GETSOCKOPT,
>> SOCKET_URING_OP_SETSOCKOPT,
>> + SOCKET_URING_OP_TX_TIMESTAMP,
>> +};
>> +
>> +#define IORING_CQE_F_TIMESTAMP_HW ((__u32)1 << IORING_CQE_BUFFER_SHIFT)
>> +#define IORING_TIMESTAMP_TSTYPE_SHIFT (IORING_CQE_BUFFER_SHIFT + 1)
>> +
>
> Perhaps instead of these shifts define an actual struct, e.g.,
> io_uring_cqe_tstamp.
That wouldn't be pretty since there is a generic io_uring field in
there, it needs to be casted between types, explained to the user
that it's aliased, and you still need to pack the type somehow.
> One question is the number of bits to reserve for the tstype.
> Currently only 2 are needed. But that can grow. The current
> approach conveniently leaves that open.
>
> Alternatively, perhaps make the dependency between the shifts more
> obvious:
>
> +#define IORING_TIMESTAMP_HW_SHIFT IORING_CQE_BUFFER_SHIFT
> +#define IORING_TIMESTAMP_TYPE_SHIFT (IORING_CQE_BUFFER_SHIFT + 1)
>
> +#define IORING_CQE_F_TSTAMP_HW ((__u32)1 << IORING_TIMESTAMP_HW_SHIFT);
Let's do that
--
Pavel Begunkov
Powered by blists - more mailing lists