On 2026-12-04 08:51:52 [+0100], Florent Carli via B4 Relay wrote:
> From: Florent Carli <fcar…@gmail.com>
>
> On PREEMPT_RT the callers of __veth_xdp_flush() are preemptible: the
> BH-disabled sections of the transmit path do not disable preemption
> there. A producer can be preempted after napi_schedule_prep() has
> marked the peer's NAPI as scheduled, before __napi_schedule() wakes it
> up. Every later producer then sees rx_notify_masked or
> NAPI_STATE_SCHED set, queues its packet in the ptr_ring and returns,
> and the NAPI sleeps until the preempted producer runs again. No lock is
> held across that window, so priority inheritance cannot shorten it.
Right but if you schedule NAPI at low priority in a BH disabled section,
then the NAPI callback is invoked once BH is enabled again. So there is
no gain.
> A low priority sender can thus hold the packets of every higher
> priority sender of the same veth for as long as it stays preempted. We
> hit this with IEC 61850 sampled values delivered through a veth whose
> peer runs threaded NAPI, to a real-time reader on an isolated CPU: a
> nice 19 sender was preempted for 4.33 ms between the two calls, the
> peer's NAPI thread was not woken during that time, then was woken 4 us
> after the sender ran again and polled 23 packets at once.
I *think* if you have critical sender in your environment then it should
not run at low priority.
…
> Reproducer, in a PREEMPT_RT guest of this tree (4 vCPUs, each on its
> own host CPU): a veth pair, the peer with GRO on and threaded NAPI,
> its thread SCHED_FIFO 50 on CPU 2; a SCHED_FIFO 50 task sends a
so this needed, threaded NAPI. Otherwise the NAPI task would remain in
your context and you gain nothing. With this change you push it to
another thread.
> timestamped packet every 250 us from CPU 1; a nice 19 task sends
> 100k packets/s on the same veth from CPU 3, where a SCHED_FIFO 10 task
> runs 1 ms out of every 1.2 ms; a SCHED_FIFO 60 packet socket reader on
> the peer measures the delay of each periodic packet, 480000 per run.
> To make the race frequent, the test kernels also delay 50 us between
> napi_schedule_prep() and __napi_schedule() (not part of this patch):
You have low priority sender and high prio sender and when the low
priority one owns NAPI and the high priority one stuffs packets into
queue without processing.
I would argue that you shouldn't have a nice-19 task sending packets.
With real hardware, the traffic is usually split into high and low
priority. For that NICs provide queues and you can configure them.
This is something I would expect one to do.
Sebastian