Commit 6213f07c authored by Li RongQing's avatar Li RongQing Committed by David S. Miller

virtio_net: skip RCU read lock by checking xdp_enabled of vi

networking benchmark shows that __rcu_read_lock and
__rcu_read_unlock takes some cpu cycles, and we can avoid
calling them partially in virtio rx path by check xdp_enabled
of vi, and xdp is disabled most of time
Signed-off-by: default avatarLi RongQing <lirongqing@baidu.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c0288ae8
...@@ -734,6 +734,12 @@ static struct sk_buff *receive_small(struct net_device *dev, ...@@ -734,6 +734,12 @@ static struct sk_buff *receive_small(struct net_device *dev,
dev->stats.rx_length_errors++; dev->stats.rx_length_errors++;
goto err_len; goto err_len;
} }
if (likely(!vi->xdp_enabled)) {
xdp_prog = NULL;
goto skip_xdp;
}
rcu_read_lock(); rcu_read_lock();
xdp_prog = rcu_dereference(rq->xdp_prog); xdp_prog = rcu_dereference(rq->xdp_prog);
if (xdp_prog) { if (xdp_prog) {
...@@ -816,6 +822,7 @@ static struct sk_buff *receive_small(struct net_device *dev, ...@@ -816,6 +822,7 @@ static struct sk_buff *receive_small(struct net_device *dev,
} }
rcu_read_unlock(); rcu_read_unlock();
skip_xdp:
skb = build_skb(buf, buflen); skb = build_skb(buf, buflen);
if (!skb) { if (!skb) {
put_page(page); put_page(page);
...@@ -897,6 +904,12 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, ...@@ -897,6 +904,12 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
dev->stats.rx_length_errors++; dev->stats.rx_length_errors++;
goto err_skb; goto err_skb;
} }
if (likely(!vi->xdp_enabled)) {
xdp_prog = NULL;
goto skip_xdp;
}
rcu_read_lock(); rcu_read_lock();
xdp_prog = rcu_dereference(rq->xdp_prog); xdp_prog = rcu_dereference(rq->xdp_prog);
if (xdp_prog) { if (xdp_prog) {
...@@ -1024,6 +1037,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, ...@@ -1024,6 +1037,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
} }
rcu_read_unlock(); rcu_read_unlock();
skip_xdp:
head_skb = page_to_skb(vi, rq, page, offset, len, truesize, !xdp_prog, head_skb = page_to_skb(vi, rq, page, offset, len, truesize, !xdp_prog,
metasize, headroom); metasize, headroom);
curr_skb = head_skb; curr_skb = head_skb;
......
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