can: mcp251xfd: bound RX offload batches during long IRQs
Subsystems (2)
v2 cover can: mcp251xfd: bound RX offload batches during long IRQs
Hi all,
Under sustained receive traffic, the MCP251XFD threaded interrupt handler can remain active indefinitely, leaving received SKBs in the IRQ-local RX-offload queue while NAPI remains unscheduled.
Add an RX-offload helper for identifying a full IRQ-local batch, then use it in MCP251XFD to publish batches while the handler continues draining the controller.
An equivalent backport was tested on a Qualcomm QRB5165 (msm-qrb5165-4.19 vendor tree, with mcp251xfd and rx-offload backported from v5.15+) driving an MCP251863 over GENI SPI at 125 kbit/s. The system remained operational overnight under 100% CAN bus load while receiving more than 51 million frames.
This mainline version passes checkpatch and an x86_64 build with MCP251XFD enabled. I do not have a setup that can run mainline with an MCP251863, so it is build-tested only; a hardware test would be welcome.
---
Changes in v2:
- Split the RX-offload helper into a separate patch.
- Shorten the patch descriptions and use imperative mood.
- Keep the code unchanged from v1.
Link to v1: https://lore.kernel.org/r/20260922-upstream-can-rx-offload-batching-v1-1-099e7ca12c91@flocksafety.com
---
Chris Strong (2):
can: rx-offload: add IRQ queue flush predicate
can: mcp251xfd: flush RX offload queue during long IRQs
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 14 +++++++++++++- include/linux/can/rx-offload.h | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-)
---
base-commit: 54518e0e827f4ca9229ae657022c60bf60f5c1bf
change-id: 20260921-upstream-can-rx-offload-batching-6c8faed6c156
Best regards,
Signature · 1 line
Chris Strong <[email protected]>
PATCH v2 1/2 can: rx-offload: add IRQ queue flush predicate
Drivers that queue received SKBs from a threaded interrupt may need to publish a partial batch before the handler returns. The existing overflow check covers only the NAPI-visible queue after the IRQ-local queue has been spliced, so it cannot guide that decision.
Add can_rx_offload_irq_queue_needs_flush() to report when the IRQ-local queue reaches the NAPI poll weight. Keep the query separate from the flush operation so callers can finish processing related interrupt sources before publishing the batch.
--- include/linux/can/rx-offload.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/linux/can/rx-offload.h +7 -0
@@ -62,4 +62,11 @@ static inline void can_rx_offload_disable(struct can_rx_offload *offload) napi_disable(&offload->napi); } +static inline bool +can_rx_offload_irq_queue_needs_flush (const struct can_rx_offload *offload) +{ +/* skb_irq_queue is owned by the interrupt context queuing the SKBs. */ +return skb_queue_len (&offload->skb_irq_queue) >= offload->napi.weight; +} +#endif /* !_CAN_RX_OFFLOAD_H */
Signature · 1 line
2.43.0
PATCH v2 2/2 can: mcp251xfd: flush RX offload queue during long IRQs
In reply to Chris StrongUnder sustained receive traffic, the threaded interrupt handler can continue draining the controller indefinitely. Received SKBs remain in skb_irq_queue until the handler returns, but the overflow checks inspect the NAPI-visible skb_queue instead. The IRQ-local queue can therefore grow without bound while NAPI remains unscheduled, potentially exhausting memory.
Stop the dedicated RX loop when the IRQ-local queue reaches the NAPI weight so TEF and other pending interrupts are processed before publishing the batch. Publish further batches from the main interrupt loop while the controller remains busy. This bounds IRQ-local accumulation and keeps RX and TEF timestamps from each controller-status pass in the same sort window.
--- drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +13 -1
@@ -1498,8 +1498,14 @@ static irqreturn_t mcp251xfd_irq(int irq, void *dev_id)/* We don't know which RX-FIFO is pending, but only * handle the 1st RX-FIFO. Leave loop here if we have * more than 1 RX-FIFO to avoid starvation. +* +* Once the IRQ queue reaches the NAPI weight, process +* TEF and other pending interrupts before publishing +* the batch, keeping RX and TEF timestamps in the same +* sort window. */ - }while (priv->rx_ring_num ==1 ); + }while (priv->rx_ring_num ==1 && + !can_rx_offload_irq_queue_needs_flush (&priv->offload)); do { u32 intf_pending, intf_pending_clearable;
@@ -1615,6 +1621,12 @@ static irqreturn_t mcp251xfd_irq(int irq, void *dev_id) } } +/* Keep each splice into the offload queue near one NAPI poll +* budget when a busy controller keeps this handler running. +*/ +if (can_rx_offload_irq_queue_needs_flush (&priv->offload)) +can_rx_offload_threaded_irq_finish (&priv->offload); + handled =IRQ_HANDLED ; }while (1 );
Signature · 1 line
2.43.0