From: Simon Schippers <simon.schippers@tu-dortmund.de>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: willemdebruijn.kernel@gmail.com, jasowang@redhat.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, eperezma@redhat.com,
jon@nutanix.com, tim.gebauer@tu-dortmund.de,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org, virtualization@lists.linux.dev
Subject: [PATCH net-next v6 2/8] ptr_ring: add helper to check if consume created space
Date: Tue, 25 Nov 2025 17:12:35 +0100 [thread overview]
Message-ID: <ce371d19-e69a-4d8e-a9a0-f3e20439a094@tu-dortmund.de> (raw)
In-Reply-To: <20251125095650-mutt-send-email-mst@kernel.org>
On 11/25/25 16:01, Michael S. Tsirkin wrote:
> On Thu, Nov 20, 2025 at 04:29:07PM +0100, Simon Schippers wrote:
>> Add __ptr_ring_consume_created_space() to check whether the previous
>> __ptr_ring_consume() call successfully consumed an element and created
>> space in the ring buffer. This enables callers to conditionally notify
>> producers when space becomes available.
>>
>> The function is only valid immediately after a single consume operation
>> and should not be used after calling __ptr_ring_consume_batched().
>>
>> Co-developed-by: Tim Gebauer <tim.gebauer@tu-dortmund.de>
>> Signed-off-by: Tim Gebauer <tim.gebauer@tu-dortmund.de>
>> Co-developed by: Jon Kohler <jon@nutanix.com>
>> Signed-off-by: Jon Kohler <jon@nutanix.com>
>> Signed-off-by: Simon Schippers <simon.schippers@tu-dortmund.de>
>> ---
>> include/linux/ptr_ring.h | 17 +++++++++++++++++
>> 1 file changed, 17 insertions(+)
>>
>> diff --git a/include/linux/ptr_ring.h b/include/linux/ptr_ring.h
>> index da141cc8b075..76d6840b45a3 100644
>> --- a/include/linux/ptr_ring.h
>> +++ b/include/linux/ptr_ring.h
>> @@ -453,6 +453,23 @@ static inline int ptr_ring_consume_batched_bh(struct ptr_ring *r,
>> return ret;
>> }
>>
>> +/*
>> + * Check if the previous consume operation created space
>
> space?
>
> what does this mean?
>
>> + *
>> + * Returns true if the last call to __ptr_ring_consume() has created
>> + * space in the ring buffer (i.e., an element was consumed).
>> + *
>> + * Note: This function is only valid immediately after a single call to
>> + * __ptr_ring_consume(). If multiple calls to ptr_ring_consume*() have
>> + * been made, this check must be performed after each call individually.
>> + * Likewise, do not use this function after calling
>> + * __ptr_ring_consume_batched().
>
> API-wise, it is a really weird function. So is
>
> {
> p = __ptr_ring_consume
>
> return !!p
> }
>
> guaranteed to be equivalent to
>
> {
> p = __ptr_ring_consume
>
> return !!__ptr_ring_consume_created_space
> }
I am a bit confused. You were the one recommending this function to me,
see [1].
Maybe the comments need rework here, but the function should be fine.
Thanks
[1] Link: https://lore.kernel.org/netdev/20250922221553.47802-1-simon.schippers@tu-dortmund.de/T/#mb722e8ae4ceb5df24f74305c6145561883d4e987
>
>
>
>> + */
>> +static inline bool __ptr_ring_consume_created_space(struct ptr_ring *r)
>> +{
>> + return r->consumer_tail >= r->consumer_head;
>> +}
>> +
>> /* Cast to structure type and call a function without discarding from FIFO.
>> * Function must return a value.
>> * Callers must take consumer_lock.
>> --
>> 2.43.0
>
next prev parent reply other threads:[~2025-11-25 16:12 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-20 15:29 [PATCH net-next v6 0/8] tun/tap & vhost-net: netdev queue flow control to avoid ptr_ring tail drop Simon Schippers
2025-11-20 15:29 ` [PATCH net-next v6 1/8] ptr_ring: add __ptr_ring_full_next() to predict imminent fullness Simon Schippers
2025-11-25 14:54 ` Michael S. Tsirkin
2025-11-20 15:29 ` [PATCH net-next v6 2/8] ptr_ring: add helper to check if consume created space Simon Schippers
2025-11-25 15:01 ` Michael S. Tsirkin
2025-11-25 16:12 ` Simon Schippers [this message]
2025-11-25 17:18 ` Michael S. Tsirkin
2025-11-30 18:16 ` Willem de Bruijn
2025-11-20 15:29 ` [PATCH net-next v6 3/8] tun/tap: add synchronized ring produce/consume with queue management Simon Schippers
2025-11-25 16:54 ` Michael S. Tsirkin
2025-11-26 9:23 ` Simon Schippers
2025-11-26 15:25 ` Michael S. Tsirkin
2025-11-26 16:04 ` Simon Schippers
2025-11-26 18:16 ` Michael S. Tsirkin
2025-11-20 15:29 ` [PATCH net-next v6 4/8] tun/tap: add batched ring consume function Simon Schippers
2025-11-20 15:29 ` [PATCH net-next v6 5/8] tun/tap: add uncomsume function for returning entries to ring Simon Schippers
2025-11-20 15:29 ` [PATCH net-next v6 6/8] tun/tap: add helper functions to check file type Simon Schippers
2025-11-20 15:29 ` [PATCH net-next v6 7/8] tun/tap & vhost-net: use {tun|tap}_ring_{consume|produce} to avoid tail drops Simon Schippers
2025-11-20 15:29 ` [PATCH net-next v6 7/8] tun/tap/vhost: " Simon Schippers
2025-11-20 15:29 ` [PATCH net-next v6 8/8] tun/tap: drop get ring exports Simon Schippers
2025-11-21 6:19 ` [PATCH net-next v6 0/8] tun/tap & vhost-net: netdev queue flow control to avoid ptr_ring tail drop Jason Wang
2025-11-21 9:22 ` Simon Schippers
2025-11-24 1:04 ` Jason Wang
2025-11-24 9:19 ` Simon Schippers
2025-11-25 1:34 ` Jason Wang
2025-11-25 14:04 ` Simon Schippers
2025-11-26 6:19 ` Jason Wang
2025-11-26 7:15 ` Michael S. Tsirkin
2025-11-26 9:24 ` Simon Schippers
2025-11-21 9:18 ` [syzbot ci] " syzbot ci
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=ce371d19-e69a-4d8e-a9a0-f3e20439a094@tu-dortmund.de \
--to=simon.schippers@tu-dortmund.de \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=jon@nutanix.com \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tim.gebauer@tu-dortmund.de \
--cc=virtualization@lists.linux.dev \
--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
all inboxes | Powered by JetHome®