net: xilinx: axienet: Enable adaptive IRQ coalescing with DIM
v5 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.
Changes in v5:
- Move axienet_coalesce_params doc fix to correct patch
- Rebase onto net-next/master
Changes in v4:
- Rebase onto net-next/master
- Fix incorrect function name in doc comment for axienet_coalesce_params
Changes in v3:
- Fix mismatched parameter name documentation for axienet_calc_cr
- Integrate some cleanups originally included in
https://lore.kernel.org/netdev/[email protected]/
- Move spin (un)locking in IRQs inside the if condition of napi_schedule_prep. This lets us hold the lock just for the rmw.
- Fix function name in doc comments for axienet_update_coalesce_rx/tx
- Adjust axienet_local doc comment order to match the members
- Rebase onto net-next/master
Changes in v2:
- Don't use spin_lock_irqsave when we know the context
- Split the CR calculation refactor from runtime coalesce settings adjustment support for easier review.
- Have axienet_update_coalesce_rx/tx take the cr value/mask instead of calculating it with axienet_calc_cr. This will make it easier to add partial updates in the next few commits.
- Get coalesce parameters from driver state
- Don't take the RTNL in axienet_rx_dim_work to avoid deadlock. Instead, calculate a partial cr update that axienet_update_coalesce_rx can perform under a spin lock.
- Use READ/WRITE_ONCE when accessing/modifying rx_irqs
Sean Anderson (4):
net: xilinx: axienet: Combine CR calculation
net: xilinx: axienet: Support adjusting coalesce settings while
running
net: xilinx: axienet: Get coalesce parameters from driver state
net: xilinx: axienet: Enable adaptive IRQ coalescing with DIM
drivers/net/ethernet/xilinx/Kconfig | 1 + drivers/net/ethernet/xilinx/xilinx_axienet.h | 29 +- .../net/ethernet/xilinx/xilinx_axienet_main.c | 312 ++++++++++++++---- 3 files changed, 264 insertions(+), 78 deletions(-)
Signature · 1 line
2.35.1.1320.gc452695387.dirty
PATCH v5 1/4 net: xilinx: axienet: Combine CR calculation
Combine the common parts of the CR calculations for better code reuse. While we're at it, simplify the code a bit.
---
(no changes since v3)
Changes in v3:
- Fix mismatched parameter name documentation for axienet_calc_cr
- Integrate some cleanups originally included in
https://lore.kernel.org/netdev/[email protected]/
Changes in v2:
- Split off from runtime coalesce modification support
drivers/net/ethernet/xilinx/xilinx_axienet.h | 3 - .../net/ethernet/xilinx/xilinx_axienet_main.c | 64 ++++++++++--------- 2 files changed, 34 insertions(+), 33 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +0 -3
@@ -112,9 +112,6 @@#define XAXIDMA_DELAY_MASK 0xFF000000/* Delay timeout counter */ #define XAXIDMA_COALESCE_MASK 0x00FF0000/* Coalesce counter */ -#define XAXIDMA_DELAY_SHIFT 24 -#define XAXIDMA_COALESCE_SHIFT 16 -#define XAXIDMA_IRQ_IOC_MASK 0x00001000/* Completion intr */ #define XAXIDMA_IRQ_DELAY_MASK 0x00002000/* Delay interrupt */ #define XAXIDMA_IRQ_ERROR_MASK 0x00004000/* Error interrupt */
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +34 -30
83 lines not on this page · raw message
Signature · 1 line
2.35.1.1320.gc452695387.dirty
PATCH v5 2/4 net: xilinx: axienet: Support adjusting coalesce settings while running
In reply to Sean AndersonIn 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. Converting coalescing settings to control register values may require sleeping because of clk_get_rate. However, the read/modify/write of the control registers themselves can't sleep because it needs to happen in IRQ context. By pre-calculating the control register values, we avoid introducing an additional mutex.
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.
---
(no changes since v3)
Changes in v3:
- Move spin (un)locking in IRQs inside the if condition of napi_schedule_prep. This lets us hold the lock just for the rmw.
- Fix function name in doc comments for axienet_update_coalesce_rx/tx
Changes in v2:
- Don't use spin_lock_irqsave when we know the context
- Split the CR calculation refactor from runtime coalesce settings adjustment support for easier review.
- Have axienet_update_coalesce_rx/tx take the cr value/mask instead of calculating it with axienet_calc_cr. This will make it easier to add partial updates in the next few commits.
- Split off CR calculation merging into another patch
drivers/net/ethernet/xilinx/xilinx_axienet.h | 8 ++ .../net/ethernet/xilinx/xilinx_axienet_main.c | 134 +++++++++++++++--- 2 files changed, 119 insertions(+), 23 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 +111 -23
223 lines not on this page · raw message
Signature · 1 line
2.35.1.1320.gc452695387.dirty
PATCH v5 3/4 net: xilinx: axienet: Get coalesce parameters from driver state
In reply to Sean AndersonThe cr variables now contain the same values as the control registers themselves. Extract/calculate the values from the variables instead of saving the user-specified values. This allows us to remove some bookeeping, and also lets the user know what the actual coalesce settings are.
Reviewed by: Shannon Nelson <[email protected]>
---
Changes in v5:
- Move axienet_coalesce_params doc fix to correct patch
Changes in v2:
- New
drivers/net/ethernet/xilinx/xilinx_axienet.h | 8 --- .../net/ethernet/xilinx/xilinx_axienet_main.c | 70 +++++++++++++------ 2 files changed, 47 insertions(+), 31 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +0 -8
@@ -533,10 +533,6 @@ struct skbuf_dma_descriptor {* supported, the maximum frame size would be 9k. Else it is * 1522 bytes (assuming support for basic VLAN) * @rxmem: Stores rx memory size for jumbo frame handling. -* @coalesce_count_rx: Store the irq coalesce on RX side. -* @coalesce_usec_rx: IRQ coalesce delay for RX -* @coalesce_count_tx: Store the irq coalesce on TX side. -* @coalesce_usec_tx: IRQ coalesce delay for TX * @use_dmaengine: flag to check dmaengine framework usage. * @tx_chan: TX DMA channel. * @rx_chan: RX DMA channel.
@@ -615,10 +611,6 @@ struct axienet_local {u32 max_frm_size;u32 rxmem; -u32 coalesce_count_rx; -u32 coalesce_usec_rx; -u32 coalesce_count_tx; -u32 coalesce_usec_tx;u8 use_dmaengine;struct dma_chan *tx_chan;struct dma_chan *rx_chan;
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +47 -23
111 lines not on this page · raw message
Signature · 1 line
2.35.1.1320.gc452695387.dirty
PATCH v5 4/4 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%.
[1] Who names this stuff?
Reviewed by: Shannon Nelson <[email protected]>
---
Heng, maybe you have some comments on DIM regarding the above?
(no changes since v3)
Changes in v3:
- Adjust axienet_local doc comment order to match the members
Changes in v2:
- Don't take the RTNL in axienet_rx_dim_work to avoid deadlock. Instead, calculate a partial cr update that axienet_update_coalesce_rx can perform under a spin lock.
- Use READ/WRITE_ONCE when accessing/modifying rx_irqs
drivers/net/ethernet/xilinx/Kconfig | 1 + drivers/net/ethernet/xilinx/xilinx_axienet.h | 10 ++- .../net/ethernet/xilinx/xilinx_axienet_main.c | 80 +++++++++++++++++-- 3 files changed, 82 insertions(+), 9 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_dim_enabled: Whether DIM is enabled or not +* @rx_irqs: Number of interrupts * @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
@@ -566,6 +569,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 +73 -7
146 lines not on this page · raw message
Signature · 1 line
2.35.1.1320.gc452695387.dirty
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Thu, 6 Feb 2025 15:10:32 -0500 you wrote:
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.
Changes in v5:
- Moveaxienet_coalesce_paramsdoc fix to correct patch
- Rebase onto net-next/master[...]
Here is the summary with links:
- [net-next,v5,1/4] net: xilinx: axienet: Combine CR calculation
https://git.kernel.org/netdev/net-next/c/e76d1ea8cb18 - [net-next,v5,2/4] net: xilinx: axienet: Support adjusting coalesce settings while running https://git.kernel.org/netdev/net-next/c/d048c717df33 - [net-next,v5,3/4] net: xilinx: axienet: Get coalesce parameters from driver state https://git.kernel.org/netdev/net-next/c/eb80520e8a5b - [net-next,v5,4/4] net: xilinx: axienet: Enable adaptive IRQ coalescing with DIM https://git.kernel.org/netdev/net-next/c/e1d27d29dbe5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html