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 689BF32694E for ; Tue, 25 Nov 2025 14:54:33 +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=1764082476; cv=none; b=H/tVF8yuy4i5QYWAmySeyjq4BQAQghduzUKNkPBjNiborEZEIHkHMhAkQZccguo2oBJowyfrRnbR3EFlRC55Qup0CbAV/PNzi4otHhL2TVsSAG8yKQ4PT7si4w/YTGIPtgB/WVu6UPy4Y/2THTf308/XPgw11Thq8GsPiwdKLZM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764082476; c=relaxed/simple; bh=8xC7HaADQYW3D+KtCunFe74uUCqkHpl2Q0DkBJIPChA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OEBL4sAwjIz6D2y7fdQhP/55Dvht/z3PO8FmOS2vD/64fHv0JtxnXt7T8aHLGBpAys+d4jw8SM0UO6bxnUMF05OrthmEYVWG/tF620JWH7BG0wW5/U3dOcP+SBbR0/pgw0WE4e0JoUFrl9H9AWsIIdFQbJdwO8sH4/xvkFFNvEY= 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=PHioTsMB; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=cfcFu2mT; 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="PHioTsMB"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="cfcFu2mT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764082472; 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=vUrStbCWzacPZeRn/CeAW92WYQYkVd+P3AlUH3cXvno=; b=PHioTsMBbNlpMlR+CPJ7BTh5VCry/K/TzhYKwdPiKJKzuGAU1Xz4N3C6pATV6E3wvHGYRa o9HPyPCMUPelKD+au+OPQOqpNwiVRVP9cwcb/PX56gZpVytily0KadEF5RbG3TU87SdMiO Ch+M12ojVPdEURkpJVxLZKcPvKeAvss= 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-448-DX6HUFU7OMOzp-jZMdf1Sw-1; Tue, 25 Nov 2025 09:54:30 -0500 X-MC-Unique: DX6HUFU7OMOzp-jZMdf1Sw-1 X-Mimecast-MFC-AGG-ID: DX6HUFU7OMOzp-jZMdf1Sw_1764082469 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-42b3086a055so4849569f8f.3 for ; Tue, 25 Nov 2025 06:54:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1764082469; x=1764687269; 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=vUrStbCWzacPZeRn/CeAW92WYQYkVd+P3AlUH3cXvno=; b=cfcFu2mT/kKAEmorPEqCPxak8/pldhwbINDn/xrL4io3ji1L4N4klw8sgrqUATvU1f HNN2w2V2bh9KiKb/yJj3csEINNzl+zAvXZF7vTPLzkmzVGygrT6biiEbATDCfXDSsRU3 qqz0wtqaSQoasNM+ScGRDNjv/jUB3Y9Ax8NhlSXiuo9eqIgwqkjrc+wGj+Tfkgf/bz4b h7pRuAi+/cJE44PPQQNaBvDFOayQURYMhD2v9gR4vck0gj9yG7H+P6DJwuuF415S4n/S yMbWSDwaDkK2xid8MWiFlSdlV8rbLrYOnK7cDKzFg53BcdYiB2Vt113w4wIEJ7WxzSF7 +jMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764082469; x=1764687269; 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=vUrStbCWzacPZeRn/CeAW92WYQYkVd+P3AlUH3cXvno=; b=RmYNEoVAK8u1SW14nAsBITbc8z1+yfJ8nhunmoXUvweBqqG5ym0kiAY3fQ7xKJv0BK yiTWoig7CRmY1JciHL5kobr2iHuPI7ZeMZwyWz/xgKtW4zOC+0fVn3aA2EQ1FgmhYg+X qPwfVfIxxmRJUy8EGsKE9dyH9JFRU+a7bYB3au96gGKfwFuu06y9GSq4jdH5QAHttO4V pySQp8WYRiuHiRS8EHpWrsutyucwOGW+ANSRNv374ZDbjtxtPmOjWEMNOiKKqRE1TIVN 9LiA6IIGMfth0A27H+OGKJASQR9if44j8mYm2p6mXR8Hvbwwued5kmr7Wm2ofHrAI/9y KGMA== X-Forwarded-Encrypted: i=1; AJvYcCWyMknuWhYvWUeaTIAYD24KAWllckrZVBEsiBsw4PceK9WwucgzYAENF+itiEQGgwVVXwIT+dncDegczXY=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5Bl1pHHn1EMdcDvwVPO4Tc5LVEYIH/AgBTIF2dqimSbaHmofA FKYCgljiQqi2YmpbA2/IFCqtGOtEVq8S27x0Hpyo5A+xuwa4VWj8sbljpdHR0cScO8P7VWod4b0 XfIOvttDicLk6qqD1WRNnTLadwikQ/rL/pwW/bLdphN8QFZicWA3tVEx9zzAKEDO98Q== X-Gm-Gg: ASbGnct4tbGKyKbuspuxbbLyOhcACoSzwSk4Tpk8djrkl6rtFzehxPltkzPouDbJdl8 Ivaz8DlT3uv65FDt5ke3d+MQWWlae/DASpm0k01F2mdKbObt/o6n0xSIz1H4t78WfEr4ksgE9i8 n1PCIUJdNngxcjvzg7net8+j4h6rpFbyZGBtLtVnnaaU4uMCigjt3F4Je8miwgGuxhjAz/9wIzZ cpQVBjWfV/zyDl4W8bFmccvGRXcIrv7L+pOXh+sh5EKEAFnR6tdEXoaMzblHWNjXXfxiPMUQ5gA R3mSp88jdFTElL9+O2VQitbqI/IyMjQ0b3M7bzMwLbQtKyncdwC/t0NJhpuo3Wtx4deJ3HIiulq OnGbQDmmCJuk9EKK13cBJ9u7Sj7YJ6w== X-Received: by 2002:a05:6000:1841:b0:429:b525:6df5 with SMTP id ffacd0b85a97d-42e0f1fc3f8mr3305598f8f.3.1764082469396; Tue, 25 Nov 2025 06:54:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7rvJRNZU8Dcdx4PHJxDxhuM/oczmqfkFeajyK44cHiOkIrlaShhTGgJMJROx6QVQcGeq/5w== X-Received: by 2002:a05:6000:1841:b0:429:b525:6df5 with SMTP id ffacd0b85a97d-42e0f1fc3f8mr3305550f8f.3.1764082468871; Tue, 25 Nov 2025 06:54:28 -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-42cb7f3635bsm35190453f8f.17.2025.11.25.06.54.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Nov 2025 06:54:28 -0800 (PST) Date: Tue, 25 Nov 2025 09:54:25 -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 1/8] ptr_ring: add __ptr_ring_full_next() to predict imminent fullness Message-ID: <20251125092904-mutt-send-email-mst@kernel.org> References: <20251120152914.1127975-1-simon.schippers@tu-dortmund.de> <20251120152914.1127975-2-simon.schippers@tu-dortmund.de> 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: <20251120152914.1127975-2-simon.schippers@tu-dortmund.de> On Thu, Nov 20, 2025 at 04:29:06PM +0100, Simon Schippers wrote: > Introduce the __ptr_ring_full_next() helper, which lets callers check > if the ptr_ring will become full after the next insertion. This is useful > for proactively managing capacity before the ring is actually full. > Callers must ensure the ring is not already full before using this > helper. This is because __ptr_ring_discard_one() may zero entries in > reverse order, the slot after the current producer position may be > cleared before the current one. This must be considered when using this > check. > > Note: This function is especially relevant when paired with the memory > ordering guarantees of __ptr_ring_produce() (smp_wmb()), allowing for > safe producer/consumer coordination. > > 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 | 25 +++++++++++++++++++++++++ > 1 file changed, 25 insertions(+) > > diff --git a/include/linux/ptr_ring.h b/include/linux/ptr_ring.h > index 534531807d95..da141cc8b075 100644 > --- a/include/linux/ptr_ring.h > +++ b/include/linux/ptr_ring.h > @@ -96,6 +96,31 @@ static inline bool ptr_ring_full_bh(struct ptr_ring *r) > return ret; > } > > +/* > + * Checks if the ptr_ring will become full after the next insertion. Is this for the producer or the consumer? A better name would reflect that. > + * > + * Note: Callers must ensure that the ptr_ring is not full before calling > + * this function, how? > as __ptr_ring_discard_one invalidates entries in > + * reverse order. Because the next entry (rather than the current one) > + * may be zeroed after an insertion, failing to account for this can > + * cause false negatives when checking whether the ring will become full > + * on the next insertion. this part confuses more than it clarifies. > + */ > +static inline bool __ptr_ring_full_next(struct ptr_ring *r) > +{ > + int p; > + > + if (unlikely(r->size <= 1)) > + return true; > + > + p = r->producer + 1; > + > + if (unlikely(p >= r->size)) > + p = 0; > + > + return r->queue[p]; > +} > + > /* Note: callers invoking this in a loop must use a compiler barrier, > * for example cpu_relax(). Callers must hold producer_lock. > * Callers are responsible for making sure pointer that is being queued > -- > 2.43.0