Skip to content

Commit

Permalink
usbnet: jump to rx_cleanup case instead of calling skb_queue_tail
Browse files Browse the repository at this point in the history
The current source pushes skb into dev->done queue by calling
skb_queue_tail() and then, call skb_dequeue() to pop for rx_cleanup state
to free urb and skb next in usbnet_bh().
It wastes CPU resource with extra instructions. Instead, use return values
jumping to rx_cleanup case directly to free them. Therefore calling
skb_queue_tail() and skb_dequeue() is not necessary.

The follows are just showing difference between calling skb_queue_tail()
and using return values jumping to rx_cleanup state directly in usbnet_bh()
in Arm64 instructions with perf tool.

----------- calling skb_queue_tail() -----------
       │     if (!(dev->driver_info->flags & FLAG_RX_ASSEMBLE))
  7.58 │248:   ldr     x0, [x20, torvalds#16]
  2.46 │24c:   ldr     w0, [x0, torvalds#8]
  1.64 │250: ↑ tbnz    w0, torvalds#14, 16c
       │     dev->net->stats.rx_errors++;
  0.57 │254:   ldr     x1, [x20, torvalds#184]
  1.64 │258:   ldr     x0, [x1, torvalds#336]
  2.65 │25c:   add     x0, x0, #0x1
       │260:   str     x0, [x1, torvalds#336]
       │     skb_queue_tail(&dev->done, skb);
  0.38 │264:   mov     x1, x19
       │268:   mov     x0, x21
  2.27 │26c: → bl      skb_queue_tail
  0.57 │270: ↑ b       44    // branch to call skb_dequeue()

----------- jumping to rx_cleanup state -----------
       │     if (!(dev->driver_info->flags & FLAG_RX_ASSEMBLE))
  1.69 │25c:   ldr     x0, [x21, torvalds#16]
  4.78 │260:   ldr     w0, [x0, torvalds#8]
  3.28 │264: ↑ tbnz    w0, torvalds#14, e4    // jump to 'rx_cleanup' state
       │     dev->net->stats.rx_errors++;
  0.09 │268:   ldr     x1, [x21, torvalds#184]
  2.72 │26c:   ldr     x0, [x1, torvalds#336]
  3.37 │270:   add     x0, x0, #0x1
  0.09 │274:   str     x0, [x1, torvalds#336]
  0.66 │278: ↑ b       e4    // branch to 'rx_cleanup' state

Signed-off-by: Leesoo Ahn <[email protected]>
  • Loading branch information
lsahn-gh authored and intel-lab-lkp committed Dec 17, 2022
1 parent f9ff564 commit 05ea800
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions drivers/net/usb/usbnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ static int rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)

/*-------------------------------------------------------------------------*/

static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
static inline int rx_process(struct usbnet *dev, struct sk_buff *skb)
{
if (dev->driver_info->rx_fixup &&
!dev->driver_info->rx_fixup (dev, skb)) {
Expand All @@ -576,11 +576,11 @@ static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
netif_dbg(dev, rx_err, dev->net, "rx length %d\n", skb->len);
} else {
usbnet_skb_return(dev, skb);
return;
return 0;
}

done:
skb_queue_tail(&dev->done, skb);
return -1;
}

/*-------------------------------------------------------------------------*/
Expand Down Expand Up @@ -1528,13 +1528,14 @@ static void usbnet_bh (struct timer_list *t)
entry = (struct skb_data *) skb->cb;
switch (entry->state) {
case rx_done:
entry->state = rx_cleanup;
rx_process (dev, skb);
if (rx_process(dev, skb))
goto cleanup;
continue;
case tx_done:
kfree(entry->urb->sg);
fallthrough;
case rx_cleanup:
cleanup:
usb_free_urb (entry->urb);
dev_kfree_skb (skb);
continue;
Expand Down

0 comments on commit 05ea800

Please sign in to comment.