MACB NAPI improvements
Subsystems (3)
PATCH v2 1/2 net: macb: simplify/cleanup NAPI reschedule checking
In reply to Robert HancockPreviously the macb_poll method was checking the RSR register after completing its RX receive work to see if additional packets had been received since IRQs were disabled, since this controller does not maintain the pending IRQ status across IRQ disable. It also had to double-check the register after re-enabling IRQs to detect if packets were received after the first check but before IRQs were enabled.
Using the RSR register for this purpose is problematic since it reflects the global device state rather than the per-queue state, so if packets are being received on multiple queues it may end up retriggering receive on a queue where the packets did not actually arrive and not on the one where they did arrive. This will also cause problems with an upcoming change to use NAPI for the TX path where use of multiple queues is more likely.
Add a macb_rx_pending function to check the RX ring to see if more packets have arrived in the queue, and use that to check if NAPI should be rescheduled rather than the RSR register. By doing this, we can just ignore the global RSR register entirely, and thus save some extra device register accesses at the same time.
This also makes the previous first check for pending packets rather redundant, since it would be checking the RX ring state which was just checked in the receive work function. Therefore we can get rid of it and just check after enabling interrupts whether packets are already pending.
--- drivers/net/ethernet/cadence/macb_main.c | 65 +++++++++++------------- 1 file changed, 31 insertions(+), 34 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +31 -34
@@ -1554,54 +1554,51 @@ static int macb_rx(struct macb_queue *queue, struct napi_struct *napi,return received; } +static bool macb_rx_pending (struct macb_queue *queue) +{ +struct macb *bp = queue->bp; +unsigned int entry; +struct macb_dma_desc *desc; + + entry =macb_rx_ring_wrap (bp, queue->rx_tail); + desc =macb_rx_desc (queue, entry); + +/* Make hw descriptor updates visible to CPU */ +rmb (); + +return (desc->addr &MACB_BIT (RX_USED )) !=0 ; +} +static int macb_poll (struct napi_struct *napi,int budget) { struct macb_queue *queue = container_of(napi, struct macb_queue, napi);struct macb *bp = queue->bp;int work_done; -u32 status; - status =macb_readl (bp,RSR ); -macb_writel (bp,RSR , status); + work_done = bp->macbgem_ops.mog_rx (queue, napi, budget); -netdev_vdbg (bp->dev,"poll: status = %08lx, budget = %d\n" , - (unsigned long )status, budget); +netdev_vdbg (bp->dev,"poll: queue = %u, work_done = %d, budget = %d\n" , + (unsigned int )(queue - bp->queues), work_done, budget); - work_done = bp->macbgem_ops.mog_rx (queue, napi, budget); -if (work_done < budget) { -napi_complete_done (napi, work_done); +if (work_done < budget &&napi_complete_done (napi, work_done)) { +queue_writel (queue,IER , bp->rx_intr_mask); -/* RSR bits only seem to propagate to raise interrupts when -* interrupts are enabled at the time, so if bits are already -* set due to packets received while interrupts were disabled, +/* Packet completions only seem to propagate to raise +* interrupts when interrupts are enabled at the time, so if +* packets were received while interrupts were disabled, * they will not cause another interrupt to be generated when * interrupts are re-enabled. -* Check for this case here. This has been seen to happen -* around 30% of the time under heavy network load. +* Check for this case here to avoid losing a wakeup. This can +* potentially race with the interrupt handler doing the same +* actions if an interrupt is raised just after enabling them, +* but this should be harmless. */ - status =macb_readl (bp,RSR ); -if (status) { +if (macb_rx_pending (queue)) { +queue_writel (queue,IDR , bp->rx_intr_mask);if (bp->caps &MACB_CAPS_ISR_CLEAR_ON_WRITE )queue_writel (queue,ISR ,MACB_BIT (RCOMP )); -napi_reschedule (napi); - }else { -queue_writel (queue,IER , bp->rx_intr_mask); - -/* In rare cases, packets could have been received in -* the window between the check above and re-enabling -* interrupts. Therefore, a double-check is required -* to avoid losing a wakeup. This can potentially race -* with the interrupt handler doing the same actions -* if an interrupt is raised just after enabling them, -* but this should be harmless. -*/ - status =macb_readl (bp,RSR ); -if (unlikely (status)) { -queue_writel (queue,IDR , bp->rx_intr_mask); -if (bp->caps &MACB_CAPS_ISR_CLEAR_ON_WRITE ) -queue_writel (queue,ISR ,MACB_BIT (RCOMP )); -napi_schedule (napi); - } +netdev_vdbg (bp->dev,"poll: packets pending, reschedule\n" ); +napi_schedule (napi); } }
Signature · 1 line
2.31.1
PATCH v2 2/2 net: macb: use NAPI for TX completion path
In reply to Robert HancockThis 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 NAPI instance is used for TX and RX to avoid checking the other ring's state unnecessarily when doing the poll, and so that the NAPI budget handling can work for both TX and RX packets.
A new per-queue tx_ptr_lock spinlock has been added to avoid using the main device lock (with IRQs needing to be disabled) across the entire TX mapping operation, and also to protect the TX queue pointers from concurrent access between the TX start and TX poll operations.
The TX Used Bit Read interrupt (TXUBR) handling also needs to be moved into the TX NAPI poll handler to maintain the proper order of operations. A flag is used to notify the poll handler that a UBR condition needs to be handled. The macb_tx_restart handler has had some locking added for global register access, since this could now potentially happen concurrently on different queues.
--- drivers/net/ethernet/cadence/macb.h | 6 +- drivers/net/ethernet/cadence/macb_main.c | 228 ++++++++++++++++------- 2 files changed, 161 insertions(+), 73 deletions(-)
drivers/net/ethernet/cadence/macb.h +5 -1
@@ -1204,11 +1204,15 @@ struct macb_queue {unsigned int RBQP ;unsigned int RBQPH ; +/* Lock to protect tx_head and tx_tail */ +spinlock_t tx_ptr_lock;unsigned int tx_head, tx_tail;struct macb_dma_desc *tx_ring;struct macb_tx_skb *tx_skb;dma_addr_t tx_ring_dma;struct work_struct tx_error_task; +bool txubr_pending; +struct napi_struct napi_tx;dma_addr_t rx_ring_dma;dma_addr_t rx_buffers_dma;
@@ -1217,7 +1221,7 @@ struct macb_queue {struct macb_dma_desc *rx_ring;struct sk_buff **rx_skbuff;void *rx_buffers; -struct napi_struct napi; +struct napi_struct napi_rx;struct queue_stats stats;#ifdef CONFIG_MACB_USE_HWSTAMP
drivers/net/ethernet/cadence/macb_main.c +156 -72
400 lines not on this page · raw message
Signature · 1 line
2.31.1
v2 cover MACB NAPI improvements
Simplify the logic in the Cadence MACB/GEM driver for determining when to reschedule NAPI processing, and update it to use NAPI for the TX path as well as the RX path.
Changes since v1: Changed to use separate TX and RX NAPI instances and poll functions to avoid unnecessary checks of the other ring (TX/RX) states during polling and to use budget handling for both RX and TX. Fixed locking to protect against concurrent access to TX ring on TX transmit and TX poll paths.
Robert Hancock (2):
net: macb: simplify/cleanup NAPI reschedule checking
net: macb: use NAPI for TX completion path
drivers/net/ethernet/cadence/macb.h | 6 +- drivers/net/ethernet/cadence/macb_main.c | 291 +++++++++++++++-------- 2 files changed, 191 insertions(+), 106 deletions(-)
Signature · 1 line
2.31.1
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Mon, 9 May 2022 13:46:33 -0600 you wrote:
Simplify the logic in the Cadence MACB/GEM driver for determining when to reschedule NAPI processing, and update it to use NAPI for the TX path as well as the RX path.
Changes since v1: Changed to use separate TX and RX NAPI instances and poll functions to avoid unnecessary checks of the other ring (TX/RX) states during polling and to use budget handling for both RX and TX. Fixed locking to protect against concurrent access to TX ring on TX transmit and TX poll paths.
[...]
Here is the summary with links:
- [net-next,v2,1/2] net: macb: simplify/cleanup NAPI reschedule checking
https://git.kernel.org/netdev/net-next/c/1900e30d0ef7 - [net-next,v2,2/2] net: macb: use NAPI for TX completion path https://git.kernel.org/netdev/net-next/c/138badbc21a0
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html