Skip to content

usb: gadget: f_ncm: retry the TX timer flush when the IN queue is busy - #2095

Open
term-guy wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
term-guy:f_ncm-tx-flush-upstream
Open

term-guy wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
term-guy:f_ncm-tx-flush-upstream

Conversation

@term-guy

Copy link
Copy Markdown

ncm_tx_timeout() flushes a partly filled NTB by calling eth_start_xmit() with a NULL skb. If every IN request is in flight at that moment it returns NETDEV_TX_BUSY and the timer is not restarted, so the NTB stays queued until enough frames arrive to fill it, or forever if none come. With an NFS root over NCM (J704 in gadget mode) this stalled device-to-host traffic for 0.5-27 s a few hundred times per boot ("nfs: server not responding"). Restart the timer when the flush gets NETDEV_TX_BUSY, unless the port is suspended. With it: no stalls, ping p99 0.47 ms, max 0.75 ms.

This is a generic USB gadget fix, not Apple-specific; it probably belongs in mainline (linux-usb) too. Sent here first because that is where I tested it.

Written with an AI assistant (noted in the commit) and tested on the hardware by me.

ncm_wrap_ntb() only starts task_timer when it begins a new NTB, and
ncm_tx_timeout() then flushes the pending NTB by calling
eth_start_xmit() with a NULL skb. If all IN requests are in flight at
that moment, eth_start_xmit() finds tx_reqs empty and returns
NETDEV_TX_BUSY; the timer is not restarted, so the partly filled NTB
stays queued until enough frames arrive to fill it (TX_MAX_NUM_DPE
datagrams or the NTB size).

With an NFS root over NCM this happened a few hundred times per boot
after traffic bursts and stalled device->host traffic for 0.5-27 s
(ping replies held back and delivered together, "nfs: server not
responding"); when no further frames arrive, the NTB is never sent.

Restart the timer when the flush gets NETDEV_TX_BUSY, unless the port
is suspended (eth_start_xmit() then returns busy while waking the
host). With this, the same workload shows no stalls: ping p99 0.47 ms,
max 0.75 ms.

Assisted-By: LLM
Signed-off-by: termg <hello@termg.com>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Tested on a second machine and controller: MacBook Pro M4 Pro (J616s, T6040), configfs NCM + ACM gadget at high speed to a Mac mini running macOS 26 as host. This is the production fleet75 kernel with the T6040 device-mode modules from #2334, plus usb_f_ncm built either from stock fleet75 or with this change (same tree, swapped at runtime).

Test: 500 pings at 20 ms intervals from the Mac to the J616s, while the J616s sends to the Mac with iperf3 -R for 14 s. That load fills every IN request, which is the condition this fixes. Order was A/B/A/B.

f_ncm run ping p50 ping p99 ping max iperf3 J616s->Mac
stock 1 0.74 ms 213.1 ms 358.3 ms 313.6 Mbit/s
this PR 1 4.53 ms 5.45 ms 6.94 ms 334.9 Mbit/s
this PR 2 4.53 ms 5.41 ms 5.48 ms 335.0 Mbit/s
stock 2 4.61 ms 411.8 ms 557.1 ms 333.9 Mbit/s

The first idle stock run also had a 606 ms p99 with no load. With the change, both idle runs stayed under 3 ms at p99. One idle run lost pings for a few seconds while the Mac was still configuring its freshly created interface; the repeat was 500/500. The suspended-port case (is_suspend) was not exercised here. Looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants