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