net: xilinx: axienet: Enable adaptive IRQ coalescing with DIM
cover net: xilinx: axienet: Enable adaptive IRQ coalescing with DIM
To improve performance without sacrificing latency under low load, enable DIM. While I appreciate not having to write the library myself, I do think there are many unusual aspects to DIM, as detailed in the last patch.
This series depends on [1].
[1] https://lore.kernel.org/netdev/[email protected]/
Sean Anderson (2):
net: xilinx: axienet: Support adjusting coalesce settings while
running
net: xilinx: axienet: Enable adaptive IRQ coalescing with DIM
drivers/net/ethernet/xilinx/Kconfig | 1 + drivers/net/ethernet/xilinx/xilinx_axienet.h | 18 +- .../net/ethernet/xilinx/xilinx_axienet_main.c | 254 ++++++++++++++---- 3 files changed, 220 insertions(+), 53 deletions(-)
Signature · 1 line
2.35.1.1320.gc452695387.dirty
PATCH 1/2 net: xilinx: axienet: Support adjusting coalesce settings while running
In preparation for adaptive IRQ coalescing, we first need to support adjusting the settings at runtime. The existing code doesn't require any locking because
- dma_start is the only function that modifies rx/tx_dma_cr. It is always called with IRQs and NAPI disabled, so nothing else is touching the hardware.
- The IRQs don't race with poll, since the latter is a softirq.
- The IRQs don't race with dma_stop since they both just clear the control registers.
- dma_stop doesn't race with poll since the former is called with NAPI disabled.
However, once we introduce another function that modifies rx/tx_dma_cr, we need to have some locking to prevent races. Introduce two locks to protect these variables and their registers.
The control register values are now generated where the coalescing settings are set. This is because we need to hold the RTNL when reading the settings, but axienet_dma_start cannot sleep.
Since axienet_dma_start writes the control settings when it runs, we don't bother updating the CR registers when rx/tx_dma_started is false. This prevents any issues from writing to the control registers in the middle of a reset sequence.
---
drivers/net/ethernet/xilinx/xilinx_axienet.h | 8 + .../net/ethernet/xilinx/xilinx_axienet_main.c | 187 +++++++++++++----- 2 files changed, 146 insertions(+), 49 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +8 -0
@@ -484,7 +484,9 @@ struct skbuf_dma_descriptor {* @regs: Base address for the axienet_local device address space * @dma_regs: Base address for the axidma device address space * @napi_rx: NAPI RX control structure +* @rx_cr_lock: Lock protecting @rx_dma_cr, its register, and @rx_dma_started * @rx_dma_cr: Nominal content of RX DMA control register +* @rx_dma_started: Set when RX DMA is started * @rx_bd_v: Virtual address of the RX buffer descriptor ring * @rx_bd_p: Physical address(start address) of the RX buffer descr. ring * @rx_bd_num: Size of RX buffer descriptor ring
@@ -494,7 +496,9 @@ struct skbuf_dma_descriptor {* @rx_bytes: RX byte count for statistics * @rx_stat_sync: Synchronization object for RX stats * @napi_tx: NAPI TX control structure +* @tx_cr_lock: Lock protecting @tx_dma_cr, its register, and @tx_dma_started * @tx_dma_cr: Nominal content of TX DMA control register +* @tx_dma_started: Set when TX DMA is started * @tx_bd_v: Virtual address of the TX buffer descriptor ring * @tx_bd_p: Physical address(start address) of the TX buffer descr. ring * @tx_bd_num: Size of TX buffer descriptor ring
@@ -566,7 +570,9 @@ struct axienet_local {void __iomem *dma_regs;struct napi_struct napi_rx; +spinlock_t rx_cr_lock;u32 rx_dma_cr; +bool rx_dma_started;struct axidma_bd *rx_bd_v;dma_addr_t rx_bd_p;u32 rx_bd_num;
@@ -576,7 +582,9 @@ struct axienet_local {struct u64_stats_sync rx_stat_sync;struct napi_struct napi_tx; +spinlock_t tx_cr_lock;u32 tx_dma_cr; +bool tx_dma_started;struct axidma_bd *tx_bd_v;dma_addr_t tx_bd_p;u32 tx_bd_num;
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +138 -49
297 lines not on this page · raw message
Signature · 1 line
2.35.1.1320.gc452695387.dirty
PATCH 2/2 net: xilinx: axienet: Enable adaptive IRQ coalescing with DIM
In reply to Sean AndersonThe default RX IRQ coalescing settings of one IRQ per packet can represent a significant CPU load. However, increasing the coalescing unilaterally can result in undesirable latency under low load. Adaptive IRQ coalescing with DIM offers a way to adjust the coalescing settings based on load.
This device only supports "CQE" mode [1], where each packet resets the timer. Therefore, an interrupt is fired either when we receive coalesce_count_rx packets or when the interface is idle for coalesce_usec_rx. With this in mind, consider the following scenarios:
Link saturated
Here we want to set coalesce_count_rx to a large value, in order to coalesce more packets and reduce CPU load. coalesce_usec_rx should be set to at least the time for one packet. Otherwise the link will be "idle" and we will get an interrupt for each packet anyway.
Bursts of packets
Each burst should be coalesced into a single interrupt, although it may be prudent to reduce coalesce_count_rx for better latency. coalesce_usec_rx should be set to at least the time for one packet so bursts are coalesced. However, additional time beyond the packet time will just increase latency at the end of a burst.
Sporadic packets
Due to low load, we can set coalesce_count_rx to 1 in order to reduce latency to the minimum. coalesce_usec_rx does not matter in this case.
Based on this analysis, I expected the CQE profiles to look something like
usec = 0, pkts = 1 // Low load usec = 16, pkts = 4 usec = 16, pkts = 16 usec = 16, pkts = 64 usec = 16, pkts = 256 // High load
Where usec is set to 16 to be a few us greater than the 12.3 us packet time of a 1500 MTU packet at 1 GBit/s. However, the CQE profile is instead
usec = 2, pkts = 256 // Low load usec = 8, pkts = 128 usec = 16, pkts = 64 usec = 32, pkts = 64 usec = 64, pkts = 64 // High load
I found this very surprising. The number of coalesced packets *decreases* as load increases. But as load increases we have more opportunities to coalesce packets without affecting latency as much. Additionally, the profile *increases* the usec as the load increases. But as load increases, the gaps between packets will tend to become smaller, making it possible to *decrease* usec for better latency at the end of a "burst".
I consider the default CQE profile unsuitable for this NIC. Therefore, we use the first profile outlined in this commit instead. coalesce_usec_rx is set to 16 by default, but the user can customize it. This may be necessary if they are using jumbo frames. I think adjusting the profile times based on the link speed/mtu would be good improvement for generic DIM.
In addition to the above profile problems, I noticed the following additional issues with DIM while testing:
- DIM tends to "wander" when at low load, since the performance gradient is pretty flat. If you only have 10p/ms anyway then adjusting the coalescing settings will not affect throughput very much.
- DIM takes a long time to adjust back to low indices when load is decreased following a period of high load. This is because it only re-evaluates its settings once every 64 interrupts. However, at low load 64 interrupts can be several seconds.
Finally: performance. This patch increases receive throughput with iperf3 from 840 Mbits/sec to 938 Mbits/sec, decreases interrupts from 69920/sec to 316/sec, and decreases CPU utilization (4x Cortex-A53) from 43% to 9%. I did not notice an increase in latency with this patch applied.
[1] Who names this stuff?
---
Heng, maybe you have some comments on DIM regarding the above?
drivers/net/ethernet/xilinx/Kconfig | 1 + drivers/net/ethernet/xilinx/xilinx_axienet.h | 10 ++- .../net/ethernet/xilinx/xilinx_axienet_main.c | 71 +++++++++++++++++-- 3 files changed, 76 insertions(+), 6 deletions(-)
drivers/net/ethernet/xilinx/Kconfig +1 -0
@@ -28,6 +28,7 @@ config XILINX_AXI_EMAC depends on HAS_IOMEM depends on XILINX_DMA select PHYLINK + select DIMLIB help This driver supports the 10/100/1000 Ethernet from Xilinx for the AXI bus interface used in Xilinx Virtex FPGAs and Soc's.
drivers/net/ethernet/xilinx/xilinx_axienet.h +8 -2
@@ -9,6 +9,7 @@#ifndef XILINX_AXIENET_H #define XILINX_AXIENET_H +#include <linux/dim.h> #include <linux/netdevice.h> #include <linux/spinlock.h> #include <linux/interrupt.h>
@@ -123,8 +124,7 @@/* Default TX/RX Threshold and delay timer values for SGDMA mode */ #define XAXIDMA_DFT_TX_THRESHOLD 24#define XAXIDMA_DFT_TX_USEC 50 -#define XAXIDMA_DFT_RX_THRESHOLD 1 -#define XAXIDMA_DFT_RX_USEC 50 +#define XAXIDMA_DFT_RX_USEC 16#define XAXIDMA_BD_CTRL_TXSOF_MASK 0x08000000/* First tx packet */ #define XAXIDMA_BD_CTRL_TXEOF_MASK 0x04000000/* Last tx packet */
@@ -484,6 +484,9 @@ struct skbuf_dma_descriptor {* @regs: Base address for the axienet_local device address space * @dma_regs: Base address for the axidma device address space * @napi_rx: NAPI RX control structure +* @rx_dim: DIM state for the receive queue +* @rx_irqs: Number of interrupts +* @rx_dim_enabled: Whether DIM is enabled or not * @rx_cr_lock: Lock protecting @rx_dma_cr, its register, and @rx_dma_started * @rx_dma_cr: Nominal content of RX DMA control register * @rx_dma_started: Set when RX DMA is started
@@ -570,6 +573,9 @@ struct axienet_local {void __iomem *dma_regs;struct napi_struct napi_rx; +struct dim rx_dim; +bool rx_dim_enabled; +u16 rx_irqs;spinlock_t rx_cr_lock;u32 rx_dma_cr;bool rx_dma_started;
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +67 -4
132 lines not on this page · raw message
Signature · 1 line
2.35.1.1320.gc452695387.dirty
Simon Horman
reviewerQuoted 8 lines · Sean Anderson
To improve performance without sacrificing latency under low load, enable DIM. While I appreciate not having to write the library myself, I do think there are many unusual aspects to DIM, as detailed in the last patch.
This series depends on [1].
Hi Sean,
Unfortunately the CI doesn't understand dependencies, and so it is unable to apply this patchset :(
I would suggest bundling patches for the same driver for net-next in a single patchset. And in any case, only having one active at any given time.
Signature · 1 line
pw-bot: cr
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static void axienet_update_coalesce_rx(struct axienet_local *lp) · line 2087
Quoted 13 lines · Sean Anderson
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +11
-0+ +/** +* axienet_rx_dim_work() - Adjust RX DIM settings +* @work: The work struct +*/ +static void axienet_rx_dim_work (struct work_struct *work) +{ +struct axienet_local *lp = + container_of(work, struct axienet_local, rx_dim.work); + +rtnl_lock ();
Why do you need rtnl ?
This is very dangerous, because cancel_work_sync(&lp->rx_dim.work) might deadlock.
Quoted 7 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6
-0+axienet_dim_coalesce_rx (lp); +axienet_update_coalesce_rx (lp); +rtnl_unlock (); + + lp->rx_dim.state =DIM_START_MEASURE ; +}
Quoted 10 lines · Simon Horman
Quoted 8 lines · Sean Anderson
To improve performance without sacrificing latency under low load, enable DIM. While I appreciate not having to write the library myself, I do think there are many unusual aspects to DIM, as detailed in the last patch.
This series depends on [1].
Quoted 9 lines
Hi Sean,
Unfortunately the CI doesn't understand dependencies, and so it is unable to apply this patchset :(
I would suggest bundling patches for the same driver for net-next in a single patchset. And in any case, only having one active at any given time.
Well, I would normally do so, but that patch is a fix and this series is an improvement. So that one goes into net and this one goes into net-next.
I've been advised in the past to split up independent patches so they can be reviewed/applied individually.
--Sean
Quoted 16 lines · Eric Dumazet
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static void axienet_update_coalesce_rx(struct axienet_local *lp) · line 2087
Quoted 13 lines · Sean Anderson
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +11
-0+ +/** +* axienet_rx_dim_work() - Adjust RX DIM settings +* @work: The work struct +*/ +static void axienet_rx_dim_work (struct work_struct *work) +{ +struct axienet_local *lp = + container_of(work, struct axienet_local, rx_dim.work); + +rtnl_lock ();Why do you need rtnl ?
To protect against concurrent modification in axienet_ethtools_set_coalesce.
Quoted 2 lines
This is very dangerous, because
cancel_work_sync(&lp->rx_dim.work)might deadlock.
Ah, you're right. So maybe I should add a separate mutex for this.
--Sean
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6
-0+axienet_dim_coalesce_rx (lp); +axienet_update_coalesce_rx (lp); +rtnl_unlock (); + + lp->rx_dim.state =DIM_START_MEASURE ; +}
Simon Horman
reviewerQuoted 21 lines · Sean Anderson
Quoted 10 lines · Simon Horman
Quoted 8 lines · Sean Anderson
To improve performance without sacrificing latency under low load, enable DIM. While I appreciate not having to write the library myself, I do think there are many unusual aspects to DIM, as detailed in the last patch.
This series depends on [1].
Quoted 9 lines
Hi Sean,
Unfortunately the CI doesn't understand dependencies, and so it is unable to apply this patchset :(
I would suggest bundling patches for the same driver for net-next in a single patchset. And in any case, only having one active at any given time.
Quoted 5 lines
Well, I would normally do so, but that patch is a fix and this series is an improvement. So that one goes into net and this one goes into net-next.
I've been advised in the past to split up independent patches so they can be reviewed/applied individually.
Thanks Sean,
Understood. Given the first point, which I had missed earlier, I'd would have suggested marking this patch-set as an RFC, then reposting it once the dependency hits net-next (via net).