net: stmmac: reduce DMA interrupt latency on YT6801
Subsystems (5)
cover net: stmmac: reduce DMA interrupt latency on YT6801
On the Motorcomm YT6801 (dwmac-motorcomm), an RX or TX completion that happens while stmmac has the DMA channel interrupt masked for NAPI does not raise a new MSI when it is unmasked. The glue's 200 us interrupt moderation adds to the delay. At high packet rates the RX ring overflows. With the series, ping RTT to a peer one routed hop away goes from 0.82-0.86 to 0.60-0.66 ms and 64-byte UDP RX loss from 0.65-1.60 % to 0.01-0.06 %, with more interrupts. Patch 3 has the full numbers.
Patch 1 stops dwmac4 from reporting TBU as TX work, as commit 305deb54c6c2 ("net: stmmac: xgmac: do not treat TBU as a TX event") did for xgmac.
Patch 2 adds an opt-in flag to mask the per-channel MSI vector during NAPI instead of the DMA channel interrupt, as the vendor driver does, so the irq core resends an event raised meanwhile. Patch 3 sets it for the YT6801 with MSI-X and turns the glue moderation off. Neither change is enough alone.
An alternative, keeping the DMA mask and rechecking RI/TI after unmasking, performed the same, but needed a new DMA op, an MMIO read on every unmask and about 2000 extra acknowledges/s under UDP TX.
Only the YT6801 is known to need this. I have no other multi-MSI dwmac4 hardware (dwmac-intel, dwmac-loongson), so only dwmac-motorcomm sets the flag. On an affected device, bpftrace shows gaps over 2 ms between stmmac_napi_poll_tx() calls during a 64-byte UDP TX flood.
Tested on an Orange Pi 5 Pro (RK3588S, YT6801 on PCIe 2.0 x1) with the series backported to 7.3.6. Build tested each patch with W=1 at net-next d5cf954cebe4.
Johan Alvarado (3):
net: stmmac: dwmac4: do not treat TBU as a TX event
net: stmmac: add an opt-in MSI vector mask for NAPI
net: stmmac: motorcomm: mask the MSI vector during NAPI
.../ethernet/stmicro/stmmac/dwmac-motorcomm.c | 8 +- .../net/ethernet/stmicro/stmmac/dwmac4_lib.c | 2 - drivers/net/ethernet/stmicro/stmmac/stmmac.h | 3 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 105 ++++++++++++++++-- include/linux/stmmac.h | 1 + 5 files changed, 106 insertions(+), 13 deletions(-)
base-commit: d5cf954cebe4f175dfd834e1dc471a3aa203ec7d
Signature · 1 line
2.56.1
PATCH 1/3 net: stmmac: dwmac4: do not treat TBU as a TX event
Commit 1103d3a5531c ("net: stmmac: dwmac4: Also use TBU interrupt to clean TX path") made dwmac4_dma_interrupt() report TBU as TX work. TBUE is not in the default DMA interrupt mask and only enabled bits are cleared, so TBU stays set on every idle TX channel.
With a shared interrupt, stmmac_dma_interrupt() checks all channels. Every interrupt then schedules TX NAPI on every idle TX channel.
Only use TI to trigger TX processing, as commit 305deb54c6c2 ("net:
stmmac: xgmac: do not treat TBU as a TX event") did for xgmac. The author of that commit pointed out that dwmac4 has the same problem [1].
On a YT6801 forced to a single MSI, throughput, ping and interrupt rate did not change (5 runs each).
--- drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4_lib.c +0 -2
@@ -188,8 +188,6 @@ int dwmac4_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, ret |= handle_tx; } -if (unlikely (intr_status &DMA_CHAN_STATUS_TBU )) - ret |= handle_tx;if (unlikely (intr_status &DMA_CHAN_STATUS_ERI )) x->rx_early_irq++;
Signature · 1 line
2.56.1
PATCH 2/3 net: stmmac: add an opt-in MSI vector mask for NAPI
In reply to Johan AlvaradoWith one MSI per DMA channel, stmmac masks the channel interrupt in DMA_CHAN_INTR_ENA during NAPI. On the YT6801, an RI or TI set while masked raises no interrupt on unmask. The event waits for an unrelated interrupt or the TX coalesce timer.
Add STMMAC_FLAG_NAPI_MASK_MSI_VEC. When it and STMMAC_FLAG_MULTI_MSI_EN are set, the RX and TX MSI handlers disable their vector with disable_irq_nosync() and the poll enables it again. The DMA channel interrupt stays enabled, so the irq core resends events raised during the poll on enable_irq(). The vendor driver does the same.
The channel records which vector it disabled, and a completing poll undoes only its own mask. The TX timer and the shared interrupt keep the DMA mask. stmmac_enable_all_dma_irq() and stmmac_enable_rx/tx_queue() re-enable a vector left disabled by napi_disable(). Freeing the interrupts clears the record.
The resend uses irq_retrigger() or CONFIG_HARDIRQS_SW_RESEND, which arm64 and x86 select. Setting IRQ_DISABLE_UNLAZY instead would add two PCIe writes per NAPI cycle.
The default is unchanged. The vector mask is untested on dwmac-intel and dwmac-loongson.
--- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 3 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 105 ++++++++++++++++-- include/linux/stmmac.h | 1 + 3 files changed, 101 insertions(+), 8 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +3 -0
@@ -146,6 +146,9 @@ struct stmmac_channel {struct stmmac_priv *priv_data;spinlock_t lock;u32 index; +/* RX/TX MSI vector disabled for NAPI, STMMAC_FLAG_NAPI_MASK_MSI_VEC */ +bool rx_vec_masked; +bool tx_vec_masked; };struct stmmac_fpe_cfg {
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +97 -8
165 lines not on this page · raw message
include/linux/stmmac.h +1 -0
@@ -211,6 +211,7 @@ enum dwmac_core_type {#define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY BIT(14)#define STMMAC_FLAG_KEEP_PREAMBLE_BEFORE_SFD BIT(15)#define STMMAC_FLAG_SERDES_SUPPORTS_2500M BIT(16) +#define STMMAC_FLAG_NAPI_MASK_MSI_VEC BIT(17)struct mac_device_info ;
Signature · 1 line
2.56.1
PATCH 3/3 net: stmmac: motorcomm: mask the MSI vector during NAPI
In reply to Johan AlvaradoOn the YT6801, an RI or TI set while the DMA channel interrupt is masked for NAPI raises no MSI on unmask. During a 64-byte UDP TX flood, bpftrace shows over 1300 gaps longer than 2 ms between stmmac_napi_poll_tx() calls per 10 s run.
The glue INT_MODERATION register, set to 200 us by motorcomm_init(), adds up to 200 us of RX latency on top of RIWT (ethtool -C rx-usecs). With rx-usecs 33, the median ping RTT is 0.32-0.36 ms with INT_MODERATION at 0 and 0.53-0.54 ms at 200.
Set STMMAC_FLAG_NAPI_MASK_MSI_VEC under MSI-X and INT_MODERATION to 0. The vector mask alone keeps ping RTT at 0.80-0.87 ms, and moderation 0 alone drops 64-byte UDP TX to 50.2-50.8 kpps.
Orange Pi 5 Pro (RK3588S, YT6801 on PCIe 2.0 x1), 7.3.6 backport, default coalescing (rx-usecs 328, tx-usecs 5000, tx-frames 25), iperf3 to a peer one routed hop away, 10 s per test, 5 interleaved runs, min-max. TX poll gaps are gaps over 2 ms traced with bpftrace.
before after ping RTT (ms) 0.82-0.86 0.60-0.66 TCP RX (Mb/s) 917-923 931-935 TCP TX (Mb/s) 826-866 839-867 UDP 64B TX (kpps) 67.3-68.1 76.9-78.7 TX poll gaps per run 1381-1587 14-298 UDP 64B RX loss (%) 0.65-1.60 0.01-0.06 CPU, TCP RX (%) 10.1-12.4 11.6-13.9 RX interrupts/s, TCP RX 1751-1776 2999-3007 TX interrupts/s, UDP TX 884-928 7684-8492
RIWT alone now times RX interrupts, which accounts for the extra CPU.
motorcomm_resume() calls motorcomm_init(), so the setting survives resume. Link down/up during a UDP flood left no unbalanced enable_irq() warning.
With a single MSI only the moderation change applies:
before after ping RTT (ms) 0.62-0.74 0.63-0.66 UDP 64B RX loss (%) 0.68-2.20 0.01-0.03 CPU, TCP RX (%) 9.2-13.2 13.6-14.1
TCP throughput did not change.
--- drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-motorcomm.c +5 -3
@@ -174,8 +174,9 @@ static void motorcomm_init(struct dwmac_motorcomm_priv *priv) {writel (0x0 , priv->base +MGMT_INT_CTRL0 ); -writel (FIELD_PREP (INT_MODERATION_RX ,200 ) | -FIELD_PREP (INT_MODERATION_TX ,200 ), +/* Interrupt coalescing is left to the stmmac core */ +writel (FIELD_PREP (INT_MODERATION_RX ,0 ) | +FIELD_PREP (INT_MODERATION_TX ,0 ), priv->base +INT_MODERATION );/*
@@ -272,7 +273,8 @@ static int motorcomm_setup_irq(struct pci_dev *pdev, res->tx_irq[0 ] =pci_irq_vector (pdev,4 ); res->irq =pci_irq_vector (pdev,5 ); - plat->flags |=STMMAC_FLAG_MULTI_MSI_EN ; + plat->flags |=STMMAC_FLAG_MULTI_MSI_EN | +STMMAC_FLAG_NAPI_MASK_MSI_VEC ; }else {dev_info (&pdev->dev,"failed to allocate MSI-X vector: %d\n" , ret);
Signature · 1 line
2.56.1