mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julius Bairaktaris <julius@bairaktaris.de>
To: Jeff Johnson <jjohnson@kernel.org>
Cc: ath11k@lists.infradead.org, linux-wireless@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Baochen Qiang <baochen.qiang@oss.qualcomm.com>,
	Vasanthakumar Thiagarajan
	<vasanthakumar.thiagarajan@oss.qualcomm.com>,
	Rameshkumar Sundaram <rameshkumar.sundaram@oss.qualcomm.com>,
	Praneesh P <praneesh.p@oss.qualcomm.com>,
	Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>,
	Mark Ruvald Pedersen <wabsie@gmail.com>,
	Rosen Penev <rosenp@gmail.com>
Subject: [PATCH ath-next v1 10/10] wifi: ath11k: give the refill buffers their ids a chunk at a time
Date: Mon, 23 Nov 2026 14:41:37 +0100	[thread overview]
Message-ID: <20261123134137.718575-11-julius@bairaktaris.de> (raw)
In-Reply-To: <20261123134137.718575-1-julius@bairaktaris.de>

The refill takes the buffer table lock of the refill ring once per
buffer, and the cache line of the lock moves between the CPUs of the REO
rings, whose reaps take it for every frame: in a profile of bridged
uplink at 850 Mbit/s (IPQ8074, one run) the compare-and-swap of that
spin_lock() in ath11k_dp_rxbufs_replenish() takes 0.84 % of all samples.

Allocate the buffers of a chunk of up to 16 first, outside the lock, and
give them their ids under one hold of it. A buffer that gets no id or no
ring entry goes back and ends the refill with what is on the ring, as an
allocation failure does. The reaps still hold the lock for one table
entry at a time, so they wait at most for 16 id operations.

Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.9.0.1-02146-QCAHKSWPL_SILICONZ-1
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
 drivers/net/wireless/ath/ath11k/dp_rx.c | 142 +++++++++++++++---------
 1 file changed, 92 insertions(+), 50 deletions(-)

diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c
index 313a39f15781..a85edaf19bfb 100644
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -497,12 +497,65 @@ static struct sk_buff *ath11k_dp_rx_pp_alloc_skb(struct dp_rxdma_ring *rx_ring)
 	return skb;
 }
 
+/*
+ * The refill takes buffer ids for this many buffers under one hold of the
+ * buffer table lock, which the reaps of every REO ring take too.
+ */
+#define ATH11K_DP_RX_REFILL_CHUNK	16
+
+/* A buffer for the refill of @rx_ring and the address the device writes it at */
+static struct sk_buff *ath11k_dp_rx_refill_alloc(struct ath11k_base *ab,
+						 struct dp_rxdma_ring *rx_ring,
+						 dma_addr_t *paddr)
+{
+	struct sk_buff *skb;
+
+	if (rx_ring->page_pool) {
+		skb = ath11k_dp_rx_pp_alloc_skb(rx_ring);
+		if (skb)
+			*paddr = ath11k_dp_rx_pp_dma_addr(skb);
+		return skb;
+	}
+
+	skb = dev_alloc_skb(DP_RX_BUFFER_SIZE + DP_RX_BUFFER_ALIGN_SIZE);
+	if (!skb)
+		return NULL;
+
+	if (!IS_ALIGNED((unsigned long)skb->data, DP_RX_BUFFER_ALIGN_SIZE))
+		skb_pull(skb, PTR_ALIGN(skb->data, DP_RX_BUFFER_ALIGN_SIZE) -
+			      skb->data);
+
+	*paddr = dma_map_single(ab->dev, skb->data,
+				skb->len + skb_tailroom(skb), DMA_FROM_DEVICE);
+	if (dma_mapping_error(ab->dev, *paddr)) {
+		dev_kfree_skb_any(skb);
+		return NULL;
+	}
+
+	return skb;
+}
+
+/* Frees a buffer ath11k_dp_rx_refill_alloc() gave that is not on the ring */
+static void ath11k_dp_rx_refill_free(struct ath11k_base *ab,
+				     struct dp_rxdma_ring *rx_ring,
+				     struct sk_buff *skb, dma_addr_t paddr)
+{
+	if (!rx_ring->page_pool)
+		dma_unmap_single(ab->dev, paddr, skb->len + skb_tailroom(skb),
+				 DMA_FROM_DEVICE);
+	dev_kfree_skb_any(skb);
+}
+
 /* Returns number of Rx buffers replenished */
 int ath11k_dp_rxbufs_replenish(struct ath11k_base *ab, int mac_id,
 			       struct dp_rxdma_ring *rx_ring,
 			       int req_entries,
 			       enum hal_rx_buf_return_buf_manager mgr)
 {
+	struct sk_buff *skbs[ATH11K_DP_RX_REFILL_CHUNK];
+	dma_addr_t paddrs[ATH11K_DP_RX_REFILL_CHUNK];
+	int ids[ATH11K_DP_RX_REFILL_CHUNK];
+	int n, got, ided, i, j;
 	struct hal_srng *srng;
 	u32 *desc;
 	struct sk_buff *skb;
@@ -528,70 +581,59 @@ int ath11k_dp_rxbufs_replenish(struct ath11k_base *ab, int mac_id,
 	num_remain = req_entries;
 
 	while (num_remain > 0) {
-		if (rx_ring->page_pool) {
-			skb = ath11k_dp_rx_pp_alloc_skb(rx_ring);
-			if (!skb)
-				break;
-
-			paddr = ath11k_dp_rx_pp_dma_addr(skb);
-		} else {
-			skb = dev_alloc_skb(DP_RX_BUFFER_SIZE +
-					    DP_RX_BUFFER_ALIGN_SIZE);
+		n = min(num_remain, ATH11K_DP_RX_REFILL_CHUNK);
+		for (got = 0; got < n; got++) {
+			skb = ath11k_dp_rx_refill_alloc(ab, rx_ring, &paddr);
 			if (!skb)
 				break;
-
-			if (!IS_ALIGNED((unsigned long)skb->data,
-					DP_RX_BUFFER_ALIGN_SIZE)) {
-				skb_pull(skb,
-					 PTR_ALIGN(skb->data,
-						   DP_RX_BUFFER_ALIGN_SIZE) -
-					 skb->data);
-			}
-
-			paddr = dma_map_single(ab->dev, skb->data,
-					       skb->len + skb_tailroom(skb),
-					       DMA_FROM_DEVICE);
-			if (dma_mapping_error(ab->dev, paddr))
-				goto fail_free_skb;
+			skbs[got] = skb;
+			paddrs[got] = paddr;
 		}
 
 		/* bottom halves are off with the ring lock */
 		spin_lock(&rx_ring->bufs_lock);
-		buf_id = ath11k_dp_rx_buf_get_id(rx_ring, skb);
+		for (ided = 0; ided < got; ided++) {
+			buf_id = ath11k_dp_rx_buf_get_id(rx_ring, skbs[ided]);
+			if (buf_id <= 0)
+				break;
+			ids[ided] = buf_id;
+		}
 		spin_unlock(&rx_ring->bufs_lock);
-		if (buf_id <= 0)
-			goto fail_dma_unmap;
-
-		desc = ath11k_hal_srng_src_get_next_entry(ab, srng);
-		if (!desc)
-			goto fail_idr_remove;
-
-		ATH11K_SKB_RXCB(skb)->paddr = paddr;
 
-		cookie = FIELD_PREP(DP_RXDMA_BUF_COOKIE_PDEV_ID, mac_id) |
-			 FIELD_PREP(DP_RXDMA_BUF_COOKIE_BUF_ID, buf_id);
+		for (i = 0; i < ided; i++) {
+			desc = ath11k_hal_srng_src_get_next_entry(ab, srng);
+			if (!desc)
+				break;
 
-		num_remain--;
+			ATH11K_SKB_RXCB(skbs[i])->paddr = paddrs[i];
 
-		ath11k_hal_rx_buf_addr_info_set(desc, paddr, cookie, mgr);
-	}
+			cookie = FIELD_PREP(DP_RXDMA_BUF_COOKIE_PDEV_ID, mac_id) |
+				 FIELD_PREP(DP_RXDMA_BUF_COOKIE_BUF_ID, ids[i]);
 
-	ath11k_hal_srng_access_end(ab, srng);
+			num_remain--;
 
-	spin_unlock_bh(&srng->lock);
+			ath11k_hal_rx_buf_addr_info_set(desc, paddrs[i], cookie,
+							mgr);
+		}
 
-	return req_entries - num_remain;
+		/*
+		 * A buffer that got no id or no ring entry goes back, and the
+		 * refill ends with what is on the ring.
+		 */
+		if (i < got) {
+			spin_lock(&rx_ring->bufs_lock);
+			for (j = i; j < ided; j++)
+				ath11k_dp_rx_buf_put_id(rx_ring, ids[j]);
+			spin_unlock(&rx_ring->bufs_lock);
+			for (j = i; j < got; j++)
+				ath11k_dp_rx_refill_free(ab, rx_ring, skbs[j],
+							 paddrs[j]);
+			break;
+		}
 
-fail_idr_remove:
-	spin_lock(&rx_ring->bufs_lock);
-	ath11k_dp_rx_buf_put_id(rx_ring, buf_id);
-	spin_unlock(&rx_ring->bufs_lock);
-fail_dma_unmap:
-	if (!rx_ring->page_pool)
-		dma_unmap_single(ab->dev, paddr, skb->len + skb_tailroom(skb),
-				 DMA_FROM_DEVICE);
-fail_free_skb:
-	dev_kfree_skb_any(skb);
+		if (got < n)
+			break;
+	}
 
 	ath11k_hal_srng_access_end(ab, srng);
 
-- 
2.53.0


      parent reply	other threads:[~2026-11-23 13:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 13:41 [PATCH ath-next v1 00/10] wifi: ath11k: cut the per-packet cost of the RX path Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 01/10] wifi: ath11k: use page_pool for the RX refill ring Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 02/10] wifi: ath11k: replace the RX buffer IDR with a table Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 03/10] wifi: ath11k: request only the PPDU stats TLVs it reads Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 04/10] wifi: ath11k: set the skb hash of a received frame from the hardware Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 05/10] wifi: ath11k: sync a cached ring's new entries once per head read Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 06/10] wifi: ath11k: prefetch the buffers of the REO entries ahead of their reap Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 07/10] wifi: ath11k: look the peer of a received MSDU up once Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 08/10] wifi: ath11k: take the refill buffer lock without a second BH disable Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 09/10] wifi: ath11k: hand the CPU only the part of a REO buffer the device wrote Julius Bairaktaris
2026-11-23 13:41 ` Julius Bairaktaris [this message]

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=20261123134137.718575-11-julius@bairaktaris.de \
    --to=julius@bairaktaris.de \
    --cc=ath11k@lists.infradead.org \
    --cc=baochen.qiang@oss.qualcomm.com \
    --cc=jjohnson@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lorenzo.bianconi@oss.qualcomm.com \
    --cc=praneesh.p@oss.qualcomm.com \
    --cc=rameshkumar.sundaram@oss.qualcomm.com \
    --cc=rosenp@gmail.com \
    --cc=vasanthakumar.thiagarajan@oss.qualcomm.com \
    --cc=wabsie@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®