On Sun, 2017-02-26 at 19:31 -0800, Eric Dumazet wrote: > From: Eric Dumazet <eduma...@google.com> > > While playing with mlx4 hardware timestamping of RX packets, I found > that some packets were received by TCP stack with a ~200 ms delay... > > Since the timestamp was provided by the NIC, and my probe was added > in tcp_v4_rcv() while in BH handler, I was confident it was not > a sender issue, or a drop in the network. > > This would happen with a very low probability, but hurting RPC > workloads. > > A NAPI driver normally arms the IRQ after the napi_complete_done(), > after NAPI_STATE_SCHED is cleared, so that the hard irq handler can grab > it. > > Problem is that if another point in the stack grabs NAPI_STATE_SCHED bit > while IRQ are not disabled, we might have later an IRQ firing and > finding this bit set, right before napi_complete_done() clears it. > > This can happen with busy polling users, or if gro_flush_timeout is > used. But some other uses of napi_schedule() in drivers can cause this > as well. > > This patch adds a new NAPI_STATE_MISSED bit, that napi_schedule_prep() > can set if it could not grab NAPI_STATE_SCHED > > Then napi_complete_done() properly reschedules the napi to make sure > we do not miss something. > > Since we manipulate multiple bits at once, use cmpxchg() like in > sk_busy_loop() to provide proper transactions. > > Signed-off-by: Eric Dumazet <eduma...@google.com> > --- > include/linux/netdevice.h | 29 +++++++---------------- > net/core/dev.c | 44 ++++++++++++++++++++++++++++++++++-- > 2 files changed, 51 insertions(+), 22 deletions(-)
I will send a v2 of this patch. Points trying to grab NAPI_STATE_SCHED not from the device driver IRQ handler should not set NAPI_STATE_MISSED if they fail, otherwise this adds extra work for no purpose. One of this point is napi_watchdog() which can fire pretty often.