Commit bb024780 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Daniel Borkmann

bpf, cpumap: Bulk skb using netif_receive_skb_list

Rely on netif_receive_skb_list routine to send skbs converted from
xdp_frames in cpu_map_kthread_run in order to improve i-cache usage.
The proposed patch has been tested running xdp_redirect_cpu bpf sample
available in the kernel tree that is used to redirect UDP frames from
ixgbe driver to a cpumap entry and then to the networking stack. UDP
frames are generated using pktgen. Packets are discarded by the UDP
layer.

$ xdp_redirect_cpu  --cpu <cpu> --progname xdp_cpu_map0 --dev <eth>

bpf-next: ~2.35Mpps
bpf-next + cpumap skb-list: ~2.72Mpps

Rename drops counter in kmem_alloc_drops since now it reports just
kmem_cache_alloc_bulk failures
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
Link: https://lore.kernel.org/bpf/c729f83e5d7482d9329e0f165bdbe5adcefd1510.1619169700.git.lorenzo@kernel.org
parent 10bf4e83
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <linux/capability.h> #include <linux/capability.h>
#include <trace/events/xdp.h> #include <trace/events/xdp.h>
#include <linux/netdevice.h> /* netif_receive_skb_core */ #include <linux/netdevice.h> /* netif_receive_skb_list */
#include <linux/etherdevice.h> /* eth_type_trans */ #include <linux/etherdevice.h> /* eth_type_trans */
/* General idea: XDP packets getting XDP redirected to another CPU, /* General idea: XDP packets getting XDP redirected to another CPU,
...@@ -252,11 +252,12 @@ static int cpu_map_kthread_run(void *data) ...@@ -252,11 +252,12 @@ static int cpu_map_kthread_run(void *data)
*/ */
while (!kthread_should_stop() || !__ptr_ring_empty(rcpu->queue)) { while (!kthread_should_stop() || !__ptr_ring_empty(rcpu->queue)) {
struct xdp_cpumap_stats stats = {}; /* zero stats */ struct xdp_cpumap_stats stats = {}; /* zero stats */
unsigned int kmem_alloc_drops = 0, sched = 0;
gfp_t gfp = __GFP_ZERO | GFP_ATOMIC; gfp_t gfp = __GFP_ZERO | GFP_ATOMIC;
unsigned int drops = 0, sched = 0;
void *frames[CPUMAP_BATCH]; void *frames[CPUMAP_BATCH];
void *skbs[CPUMAP_BATCH]; void *skbs[CPUMAP_BATCH];
int i, n, m, nframes; int i, n, m, nframes;
LIST_HEAD(list);
/* Release CPU reschedule checks */ /* Release CPU reschedule checks */
if (__ptr_ring_empty(rcpu->queue)) { if (__ptr_ring_empty(rcpu->queue)) {
...@@ -297,7 +298,7 @@ static int cpu_map_kthread_run(void *data) ...@@ -297,7 +298,7 @@ static int cpu_map_kthread_run(void *data)
if (unlikely(m == 0)) { if (unlikely(m == 0)) {
for (i = 0; i < nframes; i++) for (i = 0; i < nframes; i++)
skbs[i] = NULL; /* effect: xdp_return_frame */ skbs[i] = NULL; /* effect: xdp_return_frame */
drops += nframes; kmem_alloc_drops += nframes;
} }
} }
...@@ -305,7 +306,6 @@ static int cpu_map_kthread_run(void *data) ...@@ -305,7 +306,6 @@ static int cpu_map_kthread_run(void *data)
for (i = 0; i < nframes; i++) { for (i = 0; i < nframes; i++) {
struct xdp_frame *xdpf = frames[i]; struct xdp_frame *xdpf = frames[i];
struct sk_buff *skb = skbs[i]; struct sk_buff *skb = skbs[i];
int ret;
skb = __xdp_build_skb_from_frame(xdpf, skb, skb = __xdp_build_skb_from_frame(xdpf, skb,
xdpf->dev_rx); xdpf->dev_rx);
...@@ -314,13 +314,13 @@ static int cpu_map_kthread_run(void *data) ...@@ -314,13 +314,13 @@ static int cpu_map_kthread_run(void *data)
continue; continue;
} }
/* Inject into network stack */ list_add_tail(&skb->list, &list);
ret = netif_receive_skb_core(skb);
if (ret == NET_RX_DROP)
drops++;
} }
netif_receive_skb_list(&list);
/* Feedback loop via tracepoint */ /* Feedback loop via tracepoint */
trace_xdp_cpumap_kthread(rcpu->map_id, n, drops, sched, &stats); trace_xdp_cpumap_kthread(rcpu->map_id, n, kmem_alloc_drops,
sched, &stats);
local_bh_enable(); /* resched point, may call do_softirq() */ local_bh_enable(); /* resched point, may call do_softirq() */
} }
......
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