Commit fb59bf28 authored by Leesoo Ahn's avatar Leesoo Ahn Committed by David S. Miller

usbnet: optimize usbnet_bh() to reduce CPU load

The current source pushes skb into dev-done queue by calling
skb_dequeue_tail() and then pop it by skb_dequeue() to branch to
rx_cleanup state for freeing urb/skb in usbnet_bh(). It takes extra CPU
load, 2.21% (skb_queue_tail) as follows,

-   11.58%     0.26%  swapper          [k] usbnet_bh
   - 11.32% usbnet_bh
      - 6.43% skb_dequeue
           6.34% _raw_spin_unlock_irqrestore
      - 2.21% skb_queue_tail
           2.19% _raw_spin_unlock_irqrestore
      - 1.68% consume_skb
         - 0.97% kfree_skbmem
              0.80% kmem_cache_free
           0.53% skb_release_data

To reduce the extra CPU load use return values to call helper function
usb_free_skb() to free the resources instead of calling skb_queue_tail()
and skb_dequeue() for push and pop respectively.

-    7.87%     0.25%  swapper          [k] usbnet_bh
   - 7.62% usbnet_bh
      - 4.81% skb_dequeue
           4.74% _raw_spin_unlock_irqrestore
      - 1.75% consume_skb
         - 0.98% kfree_skbmem
              0.78% kmem_cache_free
           0.58% skb_release_data
        0.53% smsc95xx_rx_fixup
Signed-off-by: default avatarLeesoo Ahn <lsahn@ooseel.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9cb8bae3
...@@ -555,32 +555,30 @@ static int rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags) ...@@ -555,32 +555,30 @@ 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 && if (dev->driver_info->rx_fixup &&
!dev->driver_info->rx_fixup (dev, skb)) { !dev->driver_info->rx_fixup (dev, skb)) {
/* With RX_ASSEMBLE, rx_fixup() must update counters */ /* With RX_ASSEMBLE, rx_fixup() must update counters */
if (!(dev->driver_info->flags & FLAG_RX_ASSEMBLE)) if (!(dev->driver_info->flags & FLAG_RX_ASSEMBLE))
dev->net->stats.rx_errors++; dev->net->stats.rx_errors++;
goto done; return -EPROTO;
} }
// else network stack removes extra byte if we forced a short packet // else network stack removes extra byte if we forced a short packet
/* all data was already cloned from skb inside the driver */ /* all data was already cloned from skb inside the driver */
if (dev->driver_info->flags & FLAG_MULTI_PACKET) if (dev->driver_info->flags & FLAG_MULTI_PACKET)
goto done; return -EALREADY;
if (skb->len < ETH_HLEN) { if (skb->len < ETH_HLEN) {
dev->net->stats.rx_errors++; dev->net->stats.rx_errors++;
dev->net->stats.rx_length_errors++; dev->net->stats.rx_length_errors++;
netif_dbg(dev, rx_err, dev->net, "rx length %d\n", skb->len); netif_dbg(dev, rx_err, dev->net, "rx length %d\n", skb->len);
} else { return -EPROTO;
usbnet_skb_return(dev, skb);
return;
} }
done: usbnet_skb_return(dev, skb);
skb_queue_tail(&dev->done, skb); return 0;
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -1514,6 +1512,14 @@ static int rx_alloc_submit(struct usbnet *dev, gfp_t flags) ...@@ -1514,6 +1512,14 @@ static int rx_alloc_submit(struct usbnet *dev, gfp_t flags)
return ret; return ret;
} }
static inline void usb_free_skb(struct sk_buff *skb)
{
struct skb_data *entry = (struct skb_data *)skb->cb;
usb_free_urb(entry->urb);
dev_kfree_skb(skb);
}
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
// tasklet (work deferred from completions, in_irq) or timer // tasklet (work deferred from completions, in_irq) or timer
...@@ -1528,15 +1534,14 @@ static void usbnet_bh (struct timer_list *t) ...@@ -1528,15 +1534,14 @@ static void usbnet_bh (struct timer_list *t)
entry = (struct skb_data *) skb->cb; entry = (struct skb_data *) skb->cb;
switch (entry->state) { switch (entry->state) {
case rx_done: case rx_done:
entry->state = rx_cleanup; if (rx_process(dev, skb))
rx_process (dev, skb); usb_free_skb(skb);
continue; continue;
case tx_done: case tx_done:
kfree(entry->urb->sg); kfree(entry->urb->sg);
fallthrough; fallthrough;
case rx_cleanup: case rx_cleanup:
usb_free_urb (entry->urb); usb_free_skb(skb);
dev_kfree_skb (skb);
continue; continue;
default: default:
netdev_dbg(dev->net, "bogus skb state %d\n", entry->state); netdev_dbg(dev->net, "bogus skb state %d\n", entry->state);
......
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