mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next v2] net/mlx5e: Prefetch the packet a few strides ahead in the linear MPWQE path
@ 2026-11-04 19:52 Antonio Quartulli
  2026-11-06 10:55 ` Dragos Tatulea
  0 siblings, 1 reply; 4+ messages in thread
From: Antonio Quartulli @ 2026-11-04 19:52 UTC (permalink / raw)
  To: netdev
  Cc: saeedm, tariqt, mbloch, leon, dtatulea, cratiu, andrew+netdev,
	davem, edumazet, kuba, pabeni, ast, daniel, hawk, john.fastabend,
	sdf, linux-rdma, bpf, linux-kernel, Antonio Quartulli

Without cache injection (DDIO/SDCI), the first accesses to a received
packet's headers and skb_shared_info are DRAM misses, and the
net_prefetch() in mlx5e_skb_from_cqe_mpwrq_linear() is too late to hide
them. This caps the packet rate of a queue.

In the linear striding RQ path a packet takes one stride and the device
fills the strides in order, so the packet MLX5E_RX_PREFETCH_DIST (4)
strides ahead is known without its CQE: prefetch its headers and page,
and the line its skb_shared_info will use if it has the length of the
current packet, as in bulk flows. That line matters when every packet
becomes its own skb: TCP inside an ovpn UDP tunnel gains 34% with it and
4% without.

AMD Ryzen 9 9950X, ConnectX-5 Ex, one RX queue on a dedicated CPU,
MTU 1500, mean of 3 runs:

                                   before       after
  UDP 512B flood, pktgen         2.52 Mpps    3.44 Mpps   +36%
  TCP, 1 stream                  44.6 Gb/s    48.0 Gb/s    +8%
    NAPI CPU cycles/packet            1334          715   -46%
  XDP_DROP reading the packet,
    NAPI CPU cycles/packet             409          280   -32%
  XDP_TX, NAPI CPU cycles/packet       829          554   -33%

With the change, the XDP packet rates were limited by the sender, so
cycles per packet are compared.

Suggested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
v2:
- prefetch the packet MLX5E_RX_PREFETCH_DIST strides ahead instead of
  looking at the CQE ahead (Alexei); no CQE peek, RQ state bit or wq.h
  helper any more, and it also works with CQE compression (with it on:
  UDP floods +26%, TCP +6%, where v1 did nothing)
- also prefetch the skb_shared_info line, guessing the length from the
  current packet: without it, TCP inside a VPN tunnel (one skb per
  record) gained 4% instead of 34%
- XDP numbers added; XDP_DROP without touching the packet is unchanged,
  and the XDP packet rates were capped by the sender (12-16 Mpps), so
  cycles per packet are quoted
v1: https://lore.kernel.org/netdev/20261103235823.536706-1-antonio@openvpn.net/

Notes:
- Distance: with v1, 4, 6 and 8 were within 3% of each other.
- The prefetches are issued before the stride ahead is synced for the
  CPU; if the device hasn't written it yet (low rate), they are wasted.
- No prefetch for the first 4 strides of a WQE.
- Measured on one system only (Zen 5 desktop, no cache injection,
  CX-5 Ex); numbers from DDIO/SDCI systems and CX-6/CX-7 would be
  welcome.

 .../net/ethernet/mellanox/mlx5/core/en_rx.c   | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
index 22fea4739a2c..57da30b1bffe 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -2094,6 +2094,36 @@ mlx5e_skb_from_cqe_mpwrq_nonlinear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *w
 	return skb;
 }
 
+#define MLX5E_RX_PREFETCH_DIST	4
+
+/* A packet that fits the MTU takes one stride of a linear MPWQE, and the
+ * device fills the strides in order: prefetch the packet
+ * MLX5E_RX_PREFETCH_DIST strides ahead, and the line its skb_shared_info
+ * will use if it has the length of the current one, as in a bulk flow.
+ */
+static void mlx5e_mpwrq_linear_prefetch(struct mlx5e_rq *rq,
+					struct mlx5e_mpw_info *wi,
+					u32 head_offset, u32 page_idx,
+					u16 cqe_bcnt)
+{
+	struct mlx5e_frag_page *frag_page;
+	void *va;
+
+	head_offset += MLX5E_RX_PREFETCH_DIST << rq->mpwqe.log_stride_sz;
+	page_idx += head_offset >> rq->mpwqe.page_shift;
+	if (page_idx >= rq->mpwqe.pages_per_wqe)
+		return;
+
+	head_offset &= (1 << rq->mpwqe.page_shift) - 1;
+	frag_page = &wi->alloc_units.frag_pages[page_idx];
+	va = netmem_address(frag_page->netmem) + head_offset;
+	prefetch(netmem_to_page(frag_page->netmem));
+	net_prefetch(va + rq->buff.headroom);
+	/* with XDP the packet may not become an skb */
+	if (!rcu_access_pointer(rq->xdp_prog))
+		prefetchw(va + SKB_DATA_ALIGN(rq->buff.headroom + cqe_bcnt));
+}
+
 static struct sk_buff *
 mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi,
 				struct mlx5_cqe64 *cqe, u16 cqe_bcnt, u32 head_offset,
@@ -2114,6 +2144,8 @@ mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi,
 		return NULL;
 	}
 
+	mlx5e_mpwrq_linear_prefetch(rq, wi, head_offset, page_idx, cqe_bcnt);
+
 	va             = netmem_address(frag_page->netmem) + head_offset;
 	data           = va + rx_headroom;
 	frag_size      = MLX5_SKB_FRAG_SZ(rx_headroom + cqe_bcnt);
-- 
2.56.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v2] net/mlx5e: Prefetch the packet a few strides ahead in the linear MPWQE path
  2026-11-04 19:52 [PATCH net-next v2] net/mlx5e: Prefetch the packet a few strides ahead in the linear MPWQE path Antonio Quartulli
@ 2026-11-06 10:55 ` Dragos Tatulea
  2026-11-10 10:40   ` Antonio Quartulli
  0 siblings, 1 reply; 4+ messages in thread
From: Dragos Tatulea @ 2026-11-06 10:55 UTC (permalink / raw)
  To: Antonio Quartulli, netdev
  Cc: saeedm, tariqt, mbloch, leon, cratiu, andrew+netdev, davem,
	edumazet, kuba, pabeni, ast, daniel, hawk, john.fastabend, sdf,
	linux-rdma, bpf, linux-kernel

Hi,

On 04.11.26 20:52, Antonio Quartulli wrote:
> Without cache injection (DDIO/SDCI), the first accesses to a received
> packet's headers and skb_shared_info are DRAM misses, and the
> net_prefetch() in mlx5e_skb_from_cqe_mpwrq_linear() is too late to hide
> them. This caps the packet rate of a queue.
> 
> In the linear striding RQ path a packet takes one stride and the device
> fills the strides in order, so the packet MLX5E_RX_PREFETCH_DIST (4)
> strides ahead is known without its CQE: prefetch its headers and page,
> and the line its skb_shared_info will use if it has the length of the
> current packet, as in bulk flows. That line matters when every packet
> becomes its own skb: TCP inside an ovpn UDP tunnel gains 34% with it and
> 4% without.
> 
> AMD Ryzen 9 9950X, ConnectX-5 Ex, one RX queue on a dedicated CPU,
> MTU 1500, mean of 3 runs:
> 
>                                    before       after
>   UDP 512B flood, pktgen         2.52 Mpps    3.44 Mpps   +36%
>   TCP, 1 stream                  44.6 Gb/s    48.0 Gb/s    +8%
>     NAPI CPU cycles/packet            1334          715   -46%
>   XDP_DROP reading the packet,
>     NAPI CPU cycles/packet             409          280   -32%
>   XDP_TX, NAPI CPU cycles/packet       829          554   -33%
> 
> With the change, the XDP packet rates were limited by the sender, so
> cycles per packet are compared.
> 
Thanks for your patch! These look indeed like enticing numbers. I'd
like to take some time to try this at scale and on other NICs (CX8)
and CPUs (Grace) and also check latency.

Thanks,
Dragos

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v2] net/mlx5e: Prefetch the packet a few strides ahead in the linear MPWQE path
  2026-11-06 10:55 ` Dragos Tatulea
@ 2026-11-10 10:40   ` Antonio Quartulli
  2026-11-25 21:52     ` Dragos Tatulea
  0 siblings, 1 reply; 4+ messages in thread
From: Antonio Quartulli @ 2026-11-10 10:40 UTC (permalink / raw)
  To: Dragos Tatulea, netdev
  Cc: saeedm, tariqt, mbloch, leon, cratiu, andrew+netdev, davem,
	edumazet, kuba, pabeni, ast, daniel, hawk, john.fastabend, sdf,
	linux-rdma, bpf, linux-kernel

Hi Dragos,

On 06/11/2026 11:55, Dragos Tatulea wrote:
> Thanks for your patch! These look indeed like enticing numbers. I'd
> like to take some time to try this at scale and on other NICs (CX8)
> and CPUs (Grace) and also check latency.

Thanks! In case it helps, I measured latency on my side in the meantime
(I don't have access to the monster Grace/CX8 equipment, but it's still
something :-)).

Request/response over the bare ports (one transaction in flight, like
netperf UDP_RR/TCP_RR), same system as in the commit message: one RX
queue per port with its IRQ on a dedicated CPU, MTU 1500, default
coalescing (adaptive RX, rx-usecs 8, rx-frames 128), 10s per test,
prefetch off / v2 / v2 + next-WQE follow-up (see below) interleaved,
mean of 3 rounds:

                      p50 (us)              p90 (us)
                  off    v2    +next    off    v2    +next
   UDP, 64 B     24.60  24.61  24.60   25.37  25.37  25.39
   UDP, 1400 B   25.08  25.08  25.10   25.94  25.96  25.92
   TCP, 64 B     24.65  24.64  24.66   25.48  25.46  25.85 (*)

   (*) one round at 26.59, the other two at 25.47 and 25.50

p99 and p99.9 (37-45 us and 67-100 us) varied more between rounds than
between the variants, and nothing was lost. So no latency cost that I
could see at low rate.

I'm also testing a small follow-up: v2 doesn't prefetch when the stride
4 ahead is in the next WQE, so the first strides of every WQE are never
prefetched. Following the WQ list to the next WQE (only when
cur_sz >= 2, so it is posted and its pages are allocated) removes 26-32%
of the remaining DRAM demand fills on the RX CPU and adds 1.8-3.3%
throughput, measured with TCP inside an ovpn UDP tunnel (where the RX
CPU is the bottleneck); its latency is the "+next" column above.

I had planned to send it as a follow-up patch, but I can also fold it in 
a v3, whatever you prefer once you have your results.

If there is anything specific you'd like me to run here, feel free
to let me know.


Thanks!


-- 
Antonio Quartulli

CEO and Co-Founder
Mandelbit Srl
https://www.mandelbit.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next v2] net/mlx5e: Prefetch the packet a few strides ahead in the linear MPWQE path
  2026-11-10 10:40   ` Antonio Quartulli
@ 2026-11-25 21:52     ` Dragos Tatulea
  0 siblings, 0 replies; 4+ messages in thread
From: Dragos Tatulea @ 2026-11-25 21:52 UTC (permalink / raw)
  To: Antonio Quartulli
  Cc: netdev, saeedm, tariqt, mbloch, leon, cratiu, andrew+netdev,
	davem, edumazet, kuba, pabeni, ast, daniel, hawk, john.fastabend,
	sdf, linux-rdma, bpf, linux-kernel

Hi Antonio,

On Tue, Nov 10, 2026 at 11:40:49 +0100, Antonio Quartulli wrote:
> Hi Dragos,
>
> On 06/11/2026 11:55, Dragos Tatulea wrote:
>> Thanks for your patch! These look indeed like enticing numbers. I'd
>> like to take some time to try this at scale and on other NICs (CX8)
>> and CPUs (Grace) and also check latency.
>
> Thanks! In case it helps, I measured latency on my side in the meantime
> (I don't have access to the monster Grace/CX8 equipment, but it's still
> something :-)).
>
First of all, thanks for your patience. I was on vacation, had to
catch up with stuff and finally it took some time to get to a
GB system.

> Request/response over the bare ports (one transaction in flight, like
> netperf UDP_RR/TCP_RR), same system as in the commit message: one RX
> queue per port with its IRQ on a dedicated CPU, MTU 1500, default
> coalescing (adaptive RX, rx-usecs 8, rx-frames 128), 10s per test,
> prefetch off / v2 / v2 + next-WQE follow-up (see below) interleaved,
> mean of 3 rounds:
>
>                       p50 (us)              p90 (us)
>                   off    v2    +next    off    v2    +next
>    UDP, 64 B     24.60  24.61  24.60   25.37  25.37  25.39
>    UDP, 1400 B   25.08  25.08  25.10   25.94  25.96  25.92
>    TCP, 64 B     24.65  24.64  24.66   25.48  25.46  25.85 (*)
>
>    (*) one round at 26.59, the other two at 25.47 and 25.50
>
> p99 and p99.9 (37-45 us and 67-100 us) varied more between rounds than
> between the variants, and nothing was lost. So no latency cost that I
> could see at low rate.
>
Thanks for checking the latency. I saw similar results. So I think
we are good on that front.

Here goes the rest:

The results are baseline (recent net-next) vs your v2 on AMD and a Grace
Blackwell system. NIC is CX8. Results are medians of multiple runs.

Single queue; IRQ, NAPI and the application all on one core, which
is 100% busy in every test.

AMD EPYC 9825 (Zen 5):
                          throughput           cycles/packet
  UDP 64B flood, Mpps    1.35 ->  1.44   +7%   1655 -> 1551   -6%
  UDP 512B flood, Mpps   1.32 ->  1.43   +8%   1683 -> 1562   -7%
  TCP 1 stream, Gb/s     23.9 ->  28.2  +18%   1125 ->  954  -15%
  XDP_DROP read, Mpps    10.2 ->  18.4  +81%    219 ->  121  -45%
  XDP_DROP no-touch,     23.3 ->  21.9   -6%     96 ->  102   +6%
  XDP_TX, Mpps            5.5 ->  11.4 +106%    402 ->  196  -51%

Grace Blackwell (ARM Neoverse V2, 64K page):
                          throughput           cycles/packet
  UDP 64B flood, Mpps    2.35 ->  2.58  +10%   1341 -> 1226   -9%
  UDP 512B flood, Mpps   2.47 ->  2.56   +4%   1275 -> 1230   -4%
  TCP 1 stream, Gb/s     34.0 ->  39.2  +16%   1120 ->  970  -13%
  XDP_DROP read, Mpps    12.6 ->  19.6  +56%    255 ->  161  -37%
  XDP_DROP no-touch,     36.0 ->  32.4  -10%     88 ->   97  +11%
  XDP_TX, Mpps           11.0 ->  12.5  +14%    287 ->  253  -12%

Results on Grace are a a bit noisier. But we can still get
enough signal from them.

So most results look good just as in your test. Except plain
XDP_DROP which has a regression. Nothing to be surprised about
here.

Multi-queue TCP, one iperf3 stream per queue, again IRQ and iperf3
on the same core:

One TCP stream per queue over multiple queues (same pinning):

  queues   AMD Gb/s                Grace Gb/s
     1      24.0 ->  28.4  +18%     33.9 ->  39.2  +16%
     2      47.0 ->  56.3  +20%     67.4 ->  78.4  +16%
     4      92.5 -> 110.5  +19%    134.9 -> 157.4  +17%
     8     172.5 -> 206.5  +20%    263.9 -> 308.2  +17%
    12     240.3 -> 265.5  +10%    382.8 -> 402.7   +5%
    24     370.7 -> 371.7   +0%    413.1 -> 411.7   -0%

The AMD system has 12 CPUs per L3 domain with L3 cache of 32MB. The
Grace ARM has a L3 cache of 112 MB for the whole 72 CPU socket.

Overall I think these results are quite good. I was expecting to
see some issues at scale but nothing really stands out to be
honest.

I wondered how much each prefetch bings and gathered some data
about that as well on the AMD system:

                          v2    without   without   without
                                page      headers   shinfo
  UDP 64B flood          +7%     +7%       +3%       +7%
  UDP 512B flood         +8%     +8%        0%       +8%
  TCP 1 stream          +18%    +17%        0%      +18%
  XDP_DROP read         +81%    +81%       -2%      +82%
  XDP_DROP no-touch      -6%     -6%       -4%       -5%
  XDP_TX               +106%   +106%       -1%      +108%

It does look like the big bulk of the advantage comes from
the header fetch.

> I'm also testing a small follow-up: v2 doesn't prefetch when the stride
> 4 ahead is in the next WQE, so the first strides of every WQE are never
> prefetched. Following the WQ list to the next WQE (only when
> cur_sz >= 2, so it is posted and its pages are allocated) removes 26-32%
> of the remaining DRAM demand fills on the RX CPU and adds 1.8-3.3%
> throughput, measured with TCP inside an ovpn UDP tunnel (where the RX
> CPU is the bottleneck); its latency is the "+next" column above.
>
> I had planned to send it as a follow-up patch, but I can also fold it in
> a v3, whatever you prefer once you have your results.
>
Do you have some results for this?

Thanks,
Dragos

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-25 21:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04 19:52 [PATCH net-next v2] net/mlx5e: Prefetch the packet a few strides ahead in the linear MPWQE path Antonio Quartulli
2026-11-06 10:55 ` Dragos Tatulea
2026-11-10 10:40   ` Antonio Quartulli
2026-11-25 21:52     ` Dragos Tatulea

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®