Skip to contentSkip to conversation

net: axienet: Use NAPI for TX completion path

PATCH Superseded Robert Hancock 2 participants 3 messages May 5, 2022 – May 6, 2022

Subsystems (4)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 net: axienet: Use NAPI for TX completion path

This driver was using the TX IRQ handler to perform all TX completion tasks. Under heavy TX network load, this can cause significant irqs-off latencies (found to be in the hundreds of microseconds using ftrace). This can cause other issues, such as overrunning serial UART FIFOs when using high baud rates with limited UART FIFO sizes.

Switch to using a NAPI poll handler to perform the TX completion work to get this out of hard IRQ context and avoid the IRQ latency impact. A separate poll handler is used for TX and RX since they have separate IRQs on this controller, so that the completion work for each of them stays on the same CPU as the interrupt.

Testing on a Xilinx MPSoC ZU9EG platform using iperf3 from a Linux PC through a switch at 1G link speed showed no significant change in TX or RX throughput, with approximately 941 Mbps before and after. Hard IRQ time in the TX throughput test was significantly reduced from 12% to below 1% on the CPU handling TX interrupts, with total hard+soft IRQ CPU usage dropping from about 56% down to 48%.

---

Changed since v2: Use separate TX and RX NAPI poll handlers to keep completion handling on same CPU as TX/RX IRQ. Added hard/soft IRQ benchmark information to commit message.

Changed since v1: Added benchmark information to commit message, no code changes.

 drivers/net/ethernet/xilinx/xilinx_axienet.h  |  53 +++----
 .../net/ethernet/xilinx/xilinx_axienet_main.c | 130 +++++++++++-------
 2 files changed, 105 insertions(+), 78 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +28 -25
index d5c1e5c4a508..76fdaac13146 100644
@@ -385,7 +385,6 @@ struct axidma_bd {
  * @phy_node:	Pointer to device node structure
  * @phylink:	Pointer to phylink instance
  * @phylink_config: phylink configuration settings
- * @napi:	NAPI control structure
  * @pcs_phy:	Reference to PCS/PMA PHY if used
  * @pcs:	phylink pcs structure for PCS PHY
  * @switch_x_sgmii: Whether switchable 1000BaseX/SGMII mode is enabled in the core
@@ -396,27 +395,30 @@ struct axidma_bd {
  * @regs_start: Resource start for axienet device addresses
  * @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_dma_cr:  Nominal content of RX DMA control register
- * @dma_err_task: Work structure to process Axi DMA errors
- * @tx_irq:	Axidma TX IRQ number
- * @rx_irq:	Axidma RX IRQ number
- * @eth_irq:	Ethernet core IRQ number
- * @phy_mode:	Phy type to identify between MII/GMII/RGMII/SGMII/1000 Base-X
- * @options:	AxiEthernet option word
- * @features:	Stores the extended features supported by the axienet hw
- * @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
  * @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
+ * @rx_bd_ci:	Stores the index of the Rx buffer descriptor in the ring being
+ *		accessed currently.
+ * @napi_tx:	NAPI TX control structure
+ * @tx_dma_cr:  Nominal content of TX DMA control register
+ * @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
  * @tx_bd_ci:	Stores the index of the Tx buffer descriptor in the ring being
  *		accessed currently. Used while alloc. BDs before a TX starts
  * @tx_bd_tail:	Stores the index of the Tx buffer descriptor in the ring being
  *		accessed currently. Used while processing BDs after the TX
  *		completed.
- * @rx_bd_ci:	Stores the index of the Rx buffer descriptor in the ring being
- *		accessed currently.
+ * @dma_err_task: Work structure to process Axi DMA errors
+ * @tx_irq:	Axidma TX IRQ number
+ * @rx_irq:	Axidma RX IRQ number
+ * @eth_irq:	Ethernet core IRQ number
+ * @phy_mode:	Phy type to identify between MII/GMII/RGMII/SGMII/1000 Base-X
+ * @options:	AxiEthernet option word
+ * @features:	Stores the extended features supported by the axienet hw
  * @max_frm_size: Stores the maximum size of the frame that can be that
  *		  Txed/Rxed in the existing hardware. If jumbo option is
  *		  supported, the maximum frame size would be 9k. Else it is
@@ -436,8 +438,6 @@ struct axienet_local {
 	struct phylink *phylink;
 	struct phylink_config phylink_config;
 
-	struct napi_struct napi;
-
 	struct mdio_device *pcs_phy;
 	struct phylink_pcs pcs;
 
@@ -453,7 +453,20 @@ struct axienet_local {
 	void __iomem *regs;
 	void __iomem *dma_regs;
 
+	struct napi_struct napi_rx;
 	u32 rx_dma_cr;
+	struct axidma_bd *rx_bd_v;
+	dma_addr_t rx_bd_p;
+	u32 rx_bd_num;
+	u32 rx_bd_ci;
+
+	struct napi_struct napi_tx;
+	u32 tx_dma_cr;
+	struct axidma_bd *tx_bd_v;
+	dma_addr_t tx_bd_p;
+	u32 tx_bd_num;
+	u32 tx_bd_ci;
+	u32 tx_bd_tail;
 
 	struct work_struct dma_err_task;
 
@@ -465,16 +478,6 @@ struct axienet_local {
 	u32 options;
 	u32 features;
 
-	struct axidma_bd *tx_bd_v;
-	dma_addr_t tx_bd_p;
-	u32 tx_bd_num;
-	struct axidma_bd *rx_bd_v;
-	dma_addr_t rx_bd_p;
-	u32 rx_bd_num;
-	u32 tx_bd_ci;
-	u32 tx_bd_tail;
-	u32 rx_bd_ci;
-
 	u32 max_frm_size;
 	u32 rxmem;
 
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +77 -53

271 lines not on this page · raw message

Signature · 1 line
2.31.1
#1 lore raw
Thank you for the patch! Perhaps something to improve:

Hi Robert,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Robert-Hancock/net-axienet-Use-NAPI-for-TX-completion-path/20220506-043932
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 1c1ed5a48411e1686997157c21633653fbe045c6
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20220506/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 11.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/89eb9e692229a3af81eaf2f599781bfae3091e93
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Robert-Hancock/net-axienet-Use-NAPI-for-TX-completion-path/20220506-043932
git checkout 89eb9e692229a3af81eaf2f599781bfae3091e93
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/net/ethernet/xilinx/

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/net/ethernet/xilinx/xilinx_axienet_main.c:765: warning: expecting prototype for axienet_start_xmit_done(). Prototype was for axienet_tx_poll() instead

vim +765 drivers/net/ethernet/xilinx/xilinx_axienet_main.c

bb193e3db8b86a Robert Hancock  2022-01-18  749  
ab365c3393664f Andre Przywara  2020-03-24  750  /**
ab365c3393664f Andre Przywara  2020-03-24  751   * axienet_start_xmit_done - Invoked once a transmit is completed by the
ab365c3393664f Andre Przywara  2020-03-24  752   * Axi DMA Tx channel.
89eb9e692229a3 Robert Hancock  2022-05-05  753   * @napi:	Pointer to NAPI structure.
89eb9e692229a3 Robert Hancock  2022-05-05  754   * @budget:	Max number of TX packets to process.
89eb9e692229a3 Robert Hancock  2022-05-05  755   *
89eb9e692229a3 Robert Hancock  2022-05-05  756   * Return: Number of TX packets processed.
ab365c3393664f Andre Przywara  2020-03-24  757   *
89eb9e692229a3 Robert Hancock  2022-05-05  758   * This function is invoked from the NAPI processing to notify the completion
ab365c3393664f Andre Przywara  2020-03-24  759   * of transmit operation. It clears fields in the corresponding Tx BDs and
ab365c3393664f Andre Przywara  2020-03-24  760   * unmaps the corresponding buffer so that CPU can regain ownership of the
ab365c3393664f Andre Przywara  2020-03-24  761   * buffer. It finally invokes "netif_wake_queue" to restart transmission if
ab365c3393664f Andre Przywara  2020-03-24  762   * required.
ab365c3393664f Andre Przywara  2020-03-24  763   */
89eb9e692229a3 Robert Hancock  2022-05-05  764  static int axienet_tx_poll(struct napi_struct *napi, int budget)
ab365c3393664f Andre Przywara  2020-03-24 @765  {
89eb9e692229a3 Robert Hancock  2022-05-05  766  	struct axienet_local *lp = container_of(napi, struct axienet_local, napi_tx);
89eb9e692229a3 Robert Hancock  2022-05-05  767  	struct net_device *ndev = lp->ndev;
ab365c3393664f Andre Przywara  2020-03-24  768  	u32 size = 0;
89eb9e692229a3 Robert Hancock  2022-05-05  769  	int packets;
ab365c3393664f Andre Przywara  2020-03-24  770  
89eb9e692229a3 Robert Hancock  2022-05-05  771  	packets = axienet_free_tx_chain(lp, lp->tx_bd_ci, budget, false, &size, budget);
ab365c3393664f Andre Przywara  2020-03-24  772  
89eb9e692229a3 Robert Hancock  2022-05-05  773  	if (packets) {
ab365c3393664f Andre Przywara  2020-03-24  774  		lp->tx_bd_ci += packets;
ab365c3393664f Andre Przywara  2020-03-24  775  		if (lp->tx_bd_ci >= lp->tx_bd_num)
89eb9e692229a3 Robert Hancock  2022-05-05  776  			lp->tx_bd_ci %= lp->tx_bd_num;
ab365c3393664f Andre Przywara  2020-03-24  777  
8a3b7a252dca9f Daniel Borkmann 2012-01-19  778  		ndev->stats.tx_packets += packets;
8a3b7a252dca9f Daniel Borkmann 2012-01-19  779  		ndev->stats.tx_bytes += size;
7de44285c1f69c Robert Hancock  2019-06-06  780  
7de44285c1f69c Robert Hancock  2019-06-06  781  		/* Matches barrier in axienet_start_xmit */
7de44285c1f69c Robert Hancock  2019-06-06  782  		smp_mb();
7de44285c1f69c Robert Hancock  2019-06-06  783  
bb193e3db8b86a Robert Hancock  2022-01-18  784  		if (!axienet_check_tx_bd_space(lp, MAX_SKB_FRAGS + 1))
8a3b7a252dca9f Daniel Borkmann 2012-01-19  785  			netif_wake_queue(ndev);
8a3b7a252dca9f Daniel Borkmann 2012-01-19  786  	}
8a3b7a252dca9f Daniel Borkmann 2012-01-19  787  
89eb9e692229a3 Robert Hancock  2022-05-05  788  	if (packets < budget && napi_complete_done(napi, packets)) {
89eb9e692229a3 Robert Hancock  2022-05-05  789  		/* Re-enable TX completion interrupts. This should
89eb9e692229a3 Robert Hancock  2022-05-05  790  		 * cause an immediate interrupt if any TX packets are
89eb9e692229a3 Robert Hancock  2022-05-05  791  		 * already pending.
89eb9e692229a3 Robert Hancock  2022-05-05  792  		 */
89eb9e692229a3 Robert Hancock  2022-05-05  793  		axienet_dma_out32(lp, XAXIDMA_TX_CR_OFFSET, lp->tx_dma_cr);
89eb9e692229a3 Robert Hancock  2022-05-05  794  	}
89eb9e692229a3 Robert Hancock  2022-05-05  795  	return packets;
89eb9e692229a3 Robert Hancock  2022-05-05  796  }
89eb9e692229a3 Robert Hancock  2022-05-05  797  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
#2 lore raw
In reply to Robert Hancock
Thank you for the patch! Perhaps something to improve:

Hi Robert,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Robert-Hancock/net-axienet-Use-NAPI-for-TX-completion-path/20220506-043932
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 1c1ed5a48411e1686997157c21633653fbe045c6
config: x86_64-randconfig-c007 (https://download.01.org/0day-ci/archive/20220506/[email protected]/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 5e004fb787698440a387750db7f8028e7cb14cfc)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/89eb9e692229a3af81eaf2f599781bfae3091e93
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Robert-Hancock/net-axienet-Use-NAPI-for-TX-completion-path/20220506-043932 git checkout 89eb9e692229a3af81eaf2f599781bfae3091e93
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/net/ethernet/xilinx/

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> drivers/net/ethernet/xilinx/xilinx_axienet_main.c:765: warning: expecting prototype for axienet_start_xmit_done(). Prototype was for axienet_tx_poll() instead

vim +765 drivers/net/ethernet/xilinx/xilinx_axienet_main.c

bb193e3db8b86a Robert Hancock  2022-01-18  749  
ab365c3393664f Andre Przywara  2020-03-24  750  /**
ab365c3393664f Andre Przywara  2020-03-24  751   * axienet_start_xmit_done - Invoked once a transmit is completed by the
ab365c3393664f Andre Przywara  2020-03-24  752   * Axi DMA Tx channel.
89eb9e692229a3 Robert Hancock  2022-05-05  753   * @napi:	Pointer to NAPI structure.
89eb9e692229a3 Robert Hancock  2022-05-05  754   * @budget:	Max number of TX packets to process.
89eb9e692229a3 Robert Hancock  2022-05-05  755   *
89eb9e692229a3 Robert Hancock  2022-05-05  756   * Return: Number of TX packets processed.
ab365c3393664f Andre Przywara  2020-03-24  757   *
89eb9e692229a3 Robert Hancock  2022-05-05  758   * This function is invoked from the NAPI processing to notify the completion
ab365c3393664f Andre Przywara  2020-03-24  759   * of transmit operation. It clears fields in the corresponding Tx BDs and
ab365c3393664f Andre Przywara  2020-03-24  760   * unmaps the corresponding buffer so that CPU can regain ownership of the
ab365c3393664f Andre Przywara  2020-03-24  761   * buffer. It finally invokes "netif_wake_queue" to restart transmission if
ab365c3393664f Andre Przywara  2020-03-24  762   * required.
ab365c3393664f Andre Przywara  2020-03-24  763   */
89eb9e692229a3 Robert Hancock  2022-05-05  764  static int axienet_tx_poll(struct napi_struct *napi, int budget)
ab365c3393664f Andre Przywara  2020-03-24 @765  {
89eb9e692229a3 Robert Hancock  2022-05-05  766  	struct axienet_local *lp = container_of(napi, struct axienet_local, napi_tx);
89eb9e692229a3 Robert Hancock  2022-05-05  767  	struct net_device *ndev = lp->ndev;
ab365c3393664f Andre Przywara  2020-03-24  768  	u32 size = 0;
89eb9e692229a3 Robert Hancock  2022-05-05  769  	int packets;
ab365c3393664f Andre Przywara  2020-03-24  770  
89eb9e692229a3 Robert Hancock  2022-05-05  771  	packets = axienet_free_tx_chain(lp, lp->tx_bd_ci, budget, false, &size, budget);
ab365c3393664f Andre Przywara  2020-03-24  772  
89eb9e692229a3 Robert Hancock  2022-05-05  773  	if (packets) {
ab365c3393664f Andre Przywara  2020-03-24  774  		lp->tx_bd_ci += packets;
ab365c3393664f Andre Przywara  2020-03-24  775  		if (lp->tx_bd_ci >= lp->tx_bd_num)
89eb9e692229a3 Robert Hancock  2022-05-05  776  			lp->tx_bd_ci %= lp->tx_bd_num;
ab365c3393664f Andre Przywara  2020-03-24  777  
8a3b7a252dca9f Daniel Borkmann 2012-01-19  778  		ndev->stats.tx_packets += packets;
8a3b7a252dca9f Daniel Borkmann 2012-01-19  779  		ndev->stats.tx_bytes += size;
7de44285c1f69c Robert Hancock  2019-06-06  780  
7de44285c1f69c Robert Hancock  2019-06-06  781  		/* Matches barrier in axienet_start_xmit */
7de44285c1f69c Robert Hancock  2019-06-06  782  		smp_mb();
7de44285c1f69c Robert Hancock  2019-06-06  783  
bb193e3db8b86a Robert Hancock  2022-01-18  784  		if (!axienet_check_tx_bd_space(lp, MAX_SKB_FRAGS + 1))
8a3b7a252dca9f Daniel Borkmann 2012-01-19  785  			netif_wake_queue(ndev);
8a3b7a252dca9f Daniel Borkmann 2012-01-19  786  	}
8a3b7a252dca9f Daniel Borkmann 2012-01-19  787  
89eb9e692229a3 Robert Hancock  2022-05-05  788  	if (packets < budget && napi_complete_done(napi, packets)) {
89eb9e692229a3 Robert Hancock  2022-05-05  789  		/* Re-enable TX completion interrupts. This should
89eb9e692229a3 Robert Hancock  2022-05-05  790  		 * cause an immediate interrupt if any TX packets are
89eb9e692229a3 Robert Hancock  2022-05-05  791  		 * already pending.
89eb9e692229a3 Robert Hancock  2022-05-05  792  		 */
89eb9e692229a3 Robert Hancock  2022-05-05  793  		axienet_dma_out32(lp, XAXIDMA_TX_CR_OFFSET, lp->tx_dma_cr);
89eb9e692229a3 Robert Hancock  2022-05-05  794  	}
89eb9e692229a3 Robert Hancock  2022-05-05  795  	return packets;
89eb9e692229a3 Robert Hancock  2022-05-05  796  }
89eb9e692229a3 Robert Hancock  2022-05-05  797  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp