]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bpf: cpumap micro-optimization in cpu_map_enqueue
authorJesper Dangaard Brouer <brouer@redhat.com>
Wed, 1 Nov 2017 11:44:45 +0000 (12:44 +0100)
committerDavid S. Miller <davem@davemloft.net>
Thu, 2 Nov 2017 07:13:14 +0000 (16:13 +0900)
Discovered that the compiler laid-out asm code in suboptimal way
when studying perf report during benchmarking of cpumap. Help
the compiler by the marking unlikely code paths.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
kernel/bpf/cpumap.c

index 86e29cbf7827b7a93e39d1aa4b4e959316f85c41..ce5b669003b279640313aaf9dbe9a91256070e8b 100644 (file)
@@ -208,7 +208,7 @@ static struct xdp_pkt *convert_to_xdp_pkt(struct xdp_buff *xdp)
        headroom = xdp->data - xdp->data_hard_start;
        metasize = xdp->data - xdp->data_meta;
        metasize = metasize > 0 ? metasize : 0;
-       if ((headroom - metasize) < sizeof(*xdp_pkt))
+       if (unlikely((headroom - metasize) < sizeof(*xdp_pkt)))
                return NULL;
 
        /* Store info in top of packet */
@@ -656,7 +656,7 @@ int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_buff *xdp,
        struct xdp_pkt *xdp_pkt;
 
        xdp_pkt = convert_to_xdp_pkt(xdp);
-       if (!xdp_pkt)
+       if (unlikely(!xdp_pkt))
                return -EOVERFLOW;
 
        /* Info needed when constructing SKB on remote CPU */