Commit 3176eb82 authored by Jesper Dangaard Brouer's avatar Jesper Dangaard Brouer Committed by Jakub Kicinski

net: avoid irqsave in skb_defer_free_flush

The spin_lock irqsave/restore API variant in skb_defer_free_flush can
be replaced with the faster spin_lock irq variant, which doesn't need
to read and restore the CPU flags.

Using the unconditional irq "disable/enable" API variant is safe,
because the skb_defer_free_flush() function is only called during
NAPI-RX processing in net_rx_action(), where it is known the IRQs
are enabled.

Expected gain is 14 cycles from avoiding reading and restoring CPU
flags in a spin_lock_irqsave/restore operation, measured via a
microbencmark kernel module[1] on CPU E5-1650 v4 @ 3.60GHz.

Microbenchmark overhead of spin_lock+unlock:
 - spin_lock_unlock_irq     cost: 34 cycles(tsc)  9.486 ns
 - spin_lock_unlock_irqsave cost: 48 cycles(tsc) 13.567 ns

We don't expect to see a measurable packet performance gain, as
skb_defer_free_flush() is called infrequently once per NIC device NAPI
bulk cycle and conditionally only if SKBs have been deferred by other
CPUs via skb_attempt_defer_free().

[1] https://github.com/netoptimizer/prototype-kernel/blob/master/kernel/lib/time_bench_sample.cReviewed-by: default avatarJacob Keller <jacob.e.keller@intel.com>
Signed-off-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
Link: https://lore.kernel.org/r/167421646327.1321776.7390743166998776914.stgit@firesoulSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 695a376b
...@@ -6616,17 +6616,16 @@ static int napi_threaded_poll(void *data) ...@@ -6616,17 +6616,16 @@ static int napi_threaded_poll(void *data)
static void skb_defer_free_flush(struct softnet_data *sd) static void skb_defer_free_flush(struct softnet_data *sd)
{ {
struct sk_buff *skb, *next; struct sk_buff *skb, *next;
unsigned long flags;
/* Paired with WRITE_ONCE() in skb_attempt_defer_free() */ /* Paired with WRITE_ONCE() in skb_attempt_defer_free() */
if (!READ_ONCE(sd->defer_list)) if (!READ_ONCE(sd->defer_list))
return; return;
spin_lock_irqsave(&sd->defer_lock, flags); spin_lock_irq(&sd->defer_lock);
skb = sd->defer_list; skb = sd->defer_list;
sd->defer_list = NULL; sd->defer_list = NULL;
sd->defer_count = 0; sd->defer_count = 0;
spin_unlock_irqrestore(&sd->defer_lock, flags); spin_unlock_irq(&sd->defer_lock);
while (skb != NULL) { while (skb != NULL) {
next = skb->next; next = skb->next;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment