From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB4A0329C4B for ; Tue, 25 Nov 2025 17:19:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764091142; cv=none; b=kTWYyw+s8WQN2o+CbD/DgXyKF/C+IBERhWi7EYtKNl3C1+ofi4wOsW7fkEKBMirOkTgsau6AwPYxdHQ/ZkmrPYrhyBtjnJfHMTlEiwILnnSkcLn2KqdAx9D51QrXcWCyq2YnaL3cOM2iD/96dbG1BZgeCIiW6br9uRiOLtT8rTg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764091142; c=relaxed/simple; bh=ZPhuaik0VAApbpX38pTQnqYDsCZCeVuWDwCiA5Naac0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VUchiHEVGZpDKI2tWM1qBDY3KcGtWmKvjhOlx/+XrPPslTzHe4Mq5V8bqzEJTjQrIR6XZYD1nGSj0COLMZfCQStOq6ipNJT0lEQy96tbY/4MpKPtkYwmcfQL6q4mNYbjCLPXvNEl2CkW8w1v1uNlIp04JJeEKIFsQPRYTzL+N8w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=BhLHZvb7; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=esSiQknh; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BhLHZvb7"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="esSiQknh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764091139; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=QTDXgrG1WH/0PGWngFbUewy7r2hDyrl7ob2LIaTylyw=; b=BhLHZvb7jOeixfrtVhmtDrcjLP9ebr2NrniJVF0R3Co9O+A/ERgZHCt3WKqbrxjB4ObXA3 3hgV+Z9B+nm4BdUe7cjsYe2CiRr/MUgw2n+1gWMzn2VFjReb7qo3JtR7FpO4IXTr/Q/CbB buU+kJlhvO0mdGqHZTlZ6FExeoCqg/s= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-CG38hUpRPg-Ug2udla3MHA-1; Tue, 25 Nov 2025 12:18:57 -0500 X-MC-Unique: CG38hUpRPg-Ug2udla3MHA-1 X-Mimecast-MFC-AGG-ID: CG38hUpRPg-Ug2udla3MHA_1764091136 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-42b2b9c7ab6so2880983f8f.2 for ; Tue, 25 Nov 2025 09:18:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1764091135; x=1764695935; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=QTDXgrG1WH/0PGWngFbUewy7r2hDyrl7ob2LIaTylyw=; b=esSiQknhwwgSIxH9h576nP+e3IdyPqKvNk6TgDZ3TruRZLZAnBpjaedxhfIEn2EJRU ykeM4nzQQMjsPI+Uwb2Hb3gwJ+lLOfl67oXdL4sIhag4xwJiqBr/4XA+7zCeGUH7Lq4w utYileQ9cYRnvOsksG5PcTIi2EAIrRI8OE0xTYTWNGNFcyq+tuLD7eX4rg47qboDNEEz DA8ca9igTMgz0gyfDukrHjz/w8HU+pUugX10d+MqScE6JeFyz5BJbC1Vdkw2QPzP1ddc LzoiVS9JoVrFqgz4CVW6wM4PhwJo90uA09sW4RooldqP2vjzFce8Pdf3Gq0cyqdT8huh qdMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764091135; x=1764695935; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QTDXgrG1WH/0PGWngFbUewy7r2hDyrl7ob2LIaTylyw=; b=HCQEX2xDJ5aDPeFRddrSwTFZPSn9N9GMD1yAIbkaP9xl7D7oc2Q69XSfCF3RosA/01 zNh3gyBOPMhgqQizZz/xmjEMrBipa+UrYXIcvGn7Q16j1ctodrmdhl0OC/eFV3p60A/b gz3/uX3KK5Wf/LPv+sbwISQg5U0cvo3QFMKoqj2s63Dnz6UqHreH1c43nJUC3g+ecFo6 w6fTfb+L4iEexHqsYyQvKfjYM8+lS33K9uRA8z6p3Ce6AROlib/5nJpDT4rIJfazjlrk IM6/BoT+PuxhXxizl/LTXboUS1hgt+fDNEArsAOWMKawu0sUADmgm6UEBxrzk3dEBTN5 042Q== X-Forwarded-Encrypted: i=1; AJvYcCVsJoe/uK0Euxm4hbbfD79GUIDLgnI//yuHn0EmGbS9A62vdIPkNnxJWAhae3Ftw84em8AZGdd+DZgXMys=@vger.kernel.org X-Gm-Message-State: AOJu0YyTkaEMix5z+KLIfFJph+FXyJ+H4QT9Erprulru8gd4BlK5MLsj pOmoBHwWt+iaoBiDia84pUjlG+lo12qZnfDB0dyn7Wg6U3jLgWXXvI7zeVEjnl0vYYCFvvYzy59 ecNEAV7hAfHJDJzTWFganvKG9WwsZ8G5IEmNnN2LEVIVsrfBo6G2gpiFCWvsCjiQUyg== X-Gm-Gg: ASbGncvSRQ17DYLTVwTRHHqMRdzKPdyaWeWTxs4UyEvS/Od80t5lfTAl4Ypn7AjQFt7 tr5xLnOsVBvBCPLex9z9wfXZSiVVeP++STW3lld4yWc9cL3QGZ4Io5pYjtWRgjC/m0Sn4neCwyK qUTXWYCHa2yvlB0KmeQTgpVMoWiUHCOEiwB9wtqQLZRuj8v8SKWS3Z5MXmRxt8iJSK+ys/VmUv3 Q/ewUFsdbXZGbrbZH8HfS0QIh8ESrLXgwDdtu/XGK8QsE8DgLH8x4fA73h0Upwp03hKSmLJ6DhX /63pXVuW58LuSjc5X7gbaW192aumzl//1uhKVV1nI9sc4XUCeH98oyEY9ZlMA+s7FqxzK8EuGqX Ti8OVkD2wHVWEeGepWrVu+1f75v0KDA== X-Received: by 2002:a05:6000:1863:b0:42b:4267:83c2 with SMTP id ffacd0b85a97d-42cc1cbd18dmr16972096f8f.16.1764091135226; Tue, 25 Nov 2025 09:18:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGDwBcpmQPbHfHTQwxxY5Q+qsOpgYiD3CvZ3WNNO7Ii75RTIrUMAIH9/jzA1J2eiQuQn7dHrw== X-Received: by 2002:a05:6000:1863:b0:42b:4267:83c2 with SMTP id ffacd0b85a97d-42cc1cbd18dmr16972058f8f.16.1764091134693; Tue, 25 Nov 2025 09:18:54 -0800 (PST) Received: from redhat.com (IGLD-80-230-39-63.inter.net.il. [80.230.39.63]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42cb7fa3592sm34039004f8f.21.2025.11.25.09.18.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Nov 2025 09:18:54 -0800 (PST) Date: Tue, 25 Nov 2025 12:18:51 -0500 From: "Michael S. Tsirkin" To: Simon Schippers 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: Re: [PATCH net-next v6 2/8] ptr_ring: add helper to check if consume created space Message-ID: <20251125120122-mutt-send-email-mst@kernel.org> References: <20251120152914.1127975-1-simon.schippers@tu-dortmund.de> <20251120152914.1127975-3-simon.schippers@tu-dortmund.de> <20251125095650-mutt-send-email-mst@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Nov 25, 2025 at 05:12:35PM +0100, Simon Schippers wrote: > 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 > >> Signed-off-by: Tim Gebauer > >> Co-developed by: Jon Kohler > >> Signed-off-by: Jon Kohler > >> Signed-off-by: Simon Schippers > >> --- > >> 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 I see, (an element was consumed) part confused, instead of clarifying. That is not the question - it was consumed. Let me try: Returns true if the last call to __ptr_ring_consume() has created space in the ring buffer (i.e., a new element can be produced). Note: Because of batching, a successful call to __ptr_ring_consume does not guarantee that the next call to __ptr_ring_produce will succeed. Note2: This function is only valid immediately after a single call to __ptr_ring_consume(). If multiple calls to ptr_ring_consume*() have been made, and you want to know whether any of them created space, it is not enough to call this after the last __ptr_ring_consume - instead, this check must be performed after each call individually. Likewise, do not use this function after calling __ptr_ring_consume_batched(). > > > > > > > >> + */ > >> +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 > >