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 06/10] wifi: ath11k: prefetch the buffers of the REO entries ahead of their reap
Date: Mon, 23 Nov 2026 14:41:33 +0100	[thread overview]
Message-ID: <20261123134137.718575-7-julius@bairaktaris.de> (raw)
In-Reply-To: <20261123134137.718575-1-julius@bairaktaris.de>

The REO reap loads, for each frame, the buffer table entry its cookie
names, then the sk_buff the entry holds, and after the reap the
processing of the frame loads the descriptor TLVs and headers the device
wrote. Each is a cache miss, taken one after the other: the table entry
and the sk_buff were written when the buffer was posted and are cold when
the frame comes back, and the frame's lines were just invalidated. In a
profile of bridged uplink at 900 Mbit/s (IPQ8074, one run) the
instruction after the table load in ath11k_dp_process_rx() takes 0.72 %
of all samples, the ones after the first sk_buff loads in
ath11k_dp_rx_unmap_buf() 2.26 %, after the attention load in
ath11k_dp_rx_h_attn_mpdu_err() 1.10 %, after the source address load in
ath11k_dp_rx_h_mpdu() 1.01 % and after the load of the data pointer in
ath11k_dp_rx_process_msdu() 1.05 %.

On a cached REO ring the entries ahead and their cookies are already in
the cache, so start these loads early: as each entry is reaped, prefetch
the table entry of the one after the next and the four lines of the next
one's sk_buff, whose table entry the entry before prefetched; once a
frame is handed to the CPU, prefetch the first three lines of its
descriptor and the first two lines of the frame behind it.
ath11k_hal_srng_dst_peek_ahead() returns an entry below the head pointer
read last. The table is read for an address only, without its lock: a
buffer the table no longer holds costs a prefetch to nothing. Rings in
coherent memory, where each entry read is a read from uncached memory,
are left as they are.

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 | 93 +++++++++++++++++++++++++
 drivers/net/wireless/ath/ath11k/hal.c   | 27 +++++++
 drivers/net/wireless/ath/ath11k/hal.h   |  1 +
 3 files changed, 121 insertions(+)

diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c
index b027b76ea3f3..e8226b2b832c 100644
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -2919,6 +2919,92 @@ static void ath11k_dp_rx_process_received_packets(struct ath11k_base *ab,
 	}
 }
 
+/*
+ * The refill buffer table entry a REO entry names, or NULL for a cookie that
+ * names none.
+ */
+static struct sk_buff **
+ath11k_dp_rx_reo_buf_slot(struct ath11k_base *ab,
+			  const struct hal_reo_dest_ring *desc)
+{
+	u32 cookie = FIELD_GET(BUFFER_ADDR_INFO1_SW_COOKIE,
+			       desc->buf_addr_info.info1);
+	u32 buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, cookie);
+	u32 mac_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_PDEV_ID, cookie);
+	struct dp_rxdma_ring *rx_ring;
+	struct ath11k *ar;
+
+	if (!buf_id || mac_id >= ab->num_radios)
+		return NULL;
+
+	ar = ab->pdevs[mac_id].ar;
+	if (!ar)
+		return NULL;
+
+	rx_ring = &ar->dp.rx_refill_buf_ring;
+	if (buf_id >= rx_ring->num_ids)
+		return NULL;
+
+	return &rx_ring->bufs[buf_id];
+}
+
+/*
+ * Starts the loads of the reap of the next REO entries, which are cold by
+ * the time the frames come back: the buffer table entry of the entry after
+ * the next one, and the sk_buff of the next one, whose table entry the reap
+ * before prefetched. Only an address is read from the table, without its
+ * lock: a buffer it no longer holds costs a prefetch to nothing.
+ */
+static void ath11k_dp_rx_reo_prefetch(struct ath11k_base *ab,
+				      struct hal_srng *srng)
+{
+	struct sk_buff **slot;
+	struct sk_buff *skb;
+	void *desc;
+
+	desc = ath11k_hal_srng_dst_peek_ahead(srng, 1);
+	if (desc) {
+		slot = ath11k_dp_rx_reo_buf_slot(ab, desc);
+		if (slot)
+			prefetch(slot);
+	}
+
+	desc = ath11k_hal_srng_dst_peek_ahead(srng, 0);
+	if (!desc)
+		return;
+
+	slot = ath11k_dp_rx_reo_buf_slot(ab, desc);
+	if (!slot)
+		return;
+
+	skb = READ_ONCE(*slot);
+	if (skb) {
+		prefetchw(skb);
+		prefetchw((u8 *)skb + L1_CACHE_BYTES);
+		prefetchw((u8 *)skb + 2 * L1_CACHE_BYTES);
+		prefetchw((u8 *)skb + 3 * L1_CACHE_BYTES);
+	}
+}
+
+/*
+ * Starts the loads of the descriptor TLVs and the headers of a frame the
+ * device has handed back, which its processing reads once the reap is done:
+ * the first three lines of the descriptor, where its end, attention and start
+ * TLVs begin, and the first two lines past it. A line past what the device
+ * wrote is not read.
+ */
+static void ath11k_dp_rx_prefetch_frame(struct ath11k_base *ab,
+					struct sk_buff *msdu)
+{
+	u8 *data = msdu->data, *hdr = data + ab->hw_params.hal_desc_sz;
+
+	prefetch(data);
+	prefetch(data + L1_CACHE_BYTES);
+	prefetch(data + 2 * L1_CACHE_BYTES);
+	prefetch(hdr);
+	prefetch(hdr + L1_CACHE_BYTES);
+}
+
 int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
 			 struct napi_struct *napi, int budget)
 {
@@ -2936,12 +3022,14 @@ int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
 	struct hal_reo_dest_ring *desc;
 	enum hal_reo_dest_ring_push_reason push_reason;
 	u32 cookie;
+	bool cached;
 	int i;
 
 	for (i = 0; i < MAX_RADIOS; i++)
 		__skb_queue_head_init(&msdu_list[i]);
 
 	srng = &ab->hal.srng_list[dp->reo_dst_ring[ring_id].ring_id];
+	cached = srng->flags & HAL_SRNG_FLAGS_CACHED;
 
 	spin_lock_bh(&srng->lock);
 
@@ -2951,6 +3039,9 @@ int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
 	while (likely(desc =
 	      (struct hal_reo_dest_ring *)ath11k_hal_srng_dst_get_next_entry(ab,
 									     srng))) {
+		if (cached)
+			ath11k_dp_rx_reo_prefetch(ab, srng);
+
 		cookie = FIELD_GET(BUFFER_ADDR_INFO1_SW_COOKIE,
 				   desc->buf_addr_info.info1);
 		buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID,
@@ -2976,6 +3067,8 @@ int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
 
 		rxcb = ATH11K_SKB_RXCB(msdu);
 		ath11k_dp_rx_unmap_buf(ab, msdu, DMA_FROM_DEVICE);
+		if (cached)
+			ath11k_dp_rx_prefetch_frame(ab, msdu);
 
 		num_buffs_reaped[mac_id]++;
 
diff --git a/drivers/net/wireless/ath/ath11k/hal.c b/drivers/net/wireless/ath/ath11k/hal.c
index e5c35647a136..fffecc077eac 100644
--- a/drivers/net/wireless/ath/ath11k/hal.c
+++ b/drivers/net/wireless/ath/ath11k/hal.c
@@ -627,6 +627,33 @@ u32 *ath11k_hal_srng_dst_peek(struct ath11k_base *ab, struct hal_srng *srng)
 	return NULL;
 }
 
+/**
+ * ath11k_hal_srng_dst_peek_ahead() - an entry of a destination ring past the next
+ * @srng: the ring, whose lock the caller holds
+ * @n: how many entries past the one ath11k_hal_srng_dst_get_next_entry()
+ *	returns next
+ *
+ * Return: the entry, or NULL when the head pointer read last does not
+ * reach it.
+ */
+u32 *ath11k_hal_srng_dst_peek_ahead(struct hal_srng *srng, u32 n)
+{
+	u32 tp = srng->u.dst_ring.tp, hp = srng->u.dst_ring.cached_hp;
+	u32 avail, off = n * srng->entry_size;
+
+	lockdep_assert_held(&srng->lock);
+
+	avail = hp >= tp ? hp - tp : srng->ring_size - tp + hp;
+	if (off >= avail)
+		return NULL;
+
+	tp += off;
+	if (tp >= srng->ring_size)
+		tp -= srng->ring_size;
+
+	return srng->ring_base_vaddr + tp;
+}
+
 /*
  * Hands the CPU the entries of a cached destination ring from word @from up
  * to word @to, which the head pointer the caller just read shows the device
diff --git a/drivers/net/wireless/ath/ath11k/hal.h b/drivers/net/wireless/ath/ath11k/hal.h
index 82603a389bb9..45ac2391abd8 100644
--- a/drivers/net/wireless/ath/ath11k/hal.h
+++ b/drivers/net/wireless/ath/ath11k/hal.h
@@ -944,6 +944,7 @@ void ath11k_hal_srng_get_params(struct ath11k_base *ab, struct hal_srng *srng,
 u32 *ath11k_hal_srng_dst_get_next_entry(struct ath11k_base *ab,
 					struct hal_srng *srng);
 u32 *ath11k_hal_srng_dst_peek(struct ath11k_base *ab, struct hal_srng *srng);
+u32 *ath11k_hal_srng_dst_peek_ahead(struct hal_srng *srng, u32 n);
 int ath11k_hal_srng_dst_num_free(struct ath11k_base *ab, struct hal_srng *srng,
 				 bool sync_hw_ptr);
 u32 *ath11k_hal_srng_src_peek(struct ath11k_base *ab, struct hal_srng *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 ` Julius Bairaktaris [this message]
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 ` [PATCH ath-next v1 10/10] wifi: ath11k: give the refill buffers their ids a chunk at a time Julius Bairaktaris

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-7-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®