* [net-next PATCH] bpf: cpumap micro-optimization in cpu_map_enqueue
@ 2017-11-01 11:44 Jesper Dangaard Brouer
2017-11-01 13:54 ` John Fastabend
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jesper Dangaard Brouer @ 2017-11-01 11:44 UTC (permalink / raw)
To: netdev; +Cc: Jesper Dangaard Brouer
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>
---
kernel/bpf/cpumap.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c
index 86e29cbf7827..ce5b669003b2 100644
--- a/kernel/bpf/cpumap.c
+++ b/kernel/bpf/cpumap.c
@@ -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 */
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [net-next PATCH] bpf: cpumap micro-optimization in cpu_map_enqueue
2017-11-01 11:44 [net-next PATCH] bpf: cpumap micro-optimization in cpu_map_enqueue Jesper Dangaard Brouer
@ 2017-11-01 13:54 ` John Fastabend
2017-11-01 14:18 ` Jesper Dangaard Brouer
2017-11-01 16:12 ` Alexei Starovoitov
2017-11-02 7:14 ` David Miller
2 siblings, 1 reply; 5+ messages in thread
From: John Fastabend @ 2017-11-01 13:54 UTC (permalink / raw)
To: Jesper Dangaard Brouer, netdev
On 11/01/2017 04:44 AM, Jesper Dangaard Brouer wrote:
> 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>
> ---
> kernel/bpf/cpumap.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c
> index 86e29cbf7827..ce5b669003b2 100644
> --- a/kernel/bpf/cpumap.c
> +++ b/kernel/bpf/cpumap.c
> @@ -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 */
>
Seems OK to me, just curious is this noticeable at pps benchmarks?
Acked-by: John Fastabend <john.fastabend@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [net-next PATCH] bpf: cpumap micro-optimization in cpu_map_enqueue
2017-11-01 13:54 ` John Fastabend
@ 2017-11-01 14:18 ` Jesper Dangaard Brouer
0 siblings, 0 replies; 5+ messages in thread
From: Jesper Dangaard Brouer @ 2017-11-01 14:18 UTC (permalink / raw)
To: John Fastabend; +Cc: netdev, brouer
On Wed, 1 Nov 2017 06:54:46 -0700
John Fastabend <john.fastabend@gmail.com> wrote:
> On 11/01/2017 04:44 AM, Jesper Dangaard Brouer wrote:
> > 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>
> > ---
> > kernel/bpf/cpumap.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c
> > index 86e29cbf7827..ce5b669003b2 100644
> > --- a/kernel/bpf/cpumap.c
> > +++ b/kernel/bpf/cpumap.c
> > @@ -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 */
> >
>
> Seems OK to me, just curious is this noticeable at pps benchmarks?
I calculate this into an approx 2 nanosec improvement based on PPS
benchmarks. Given my systems accuracy is around 2 nanosec (after much
tuning) then I cannot claim my measurements to be statistically
significant ;-)
> Acked-by: John Fastabend <john.fastabend@gmail.com>
Thanks
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [net-next PATCH] bpf: cpumap micro-optimization in cpu_map_enqueue
2017-11-01 11:44 [net-next PATCH] bpf: cpumap micro-optimization in cpu_map_enqueue Jesper Dangaard Brouer
2017-11-01 13:54 ` John Fastabend
@ 2017-11-01 16:12 ` Alexei Starovoitov
2017-11-02 7:14 ` David Miller
2 siblings, 0 replies; 5+ messages in thread
From: Alexei Starovoitov @ 2017-11-01 16:12 UTC (permalink / raw)
To: Jesper Dangaard Brouer; +Cc: netdev
On Wed, Nov 01, 2017 at 12:44:45PM +0100, Jesper Dangaard Brouer wrote:
> 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: Alexei Starovoitov <ast@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [net-next PATCH] bpf: cpumap micro-optimization in cpu_map_enqueue
2017-11-01 11:44 [net-next PATCH] bpf: cpumap micro-optimization in cpu_map_enqueue Jesper Dangaard Brouer
2017-11-01 13:54 ` John Fastabend
2017-11-01 16:12 ` Alexei Starovoitov
@ 2017-11-02 7:14 ` David Miller
2 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2017-11-02 7:14 UTC (permalink / raw)
To: brouer; +Cc: netdev
From: Jesper Dangaard Brouer <brouer@redhat.com>
Date: Wed, 01 Nov 2017 12:44:45 +0100
> 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>
Applied, thanks Jesper.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-11-02 7:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-01 11:44 [net-next PATCH] bpf: cpumap micro-optimization in cpu_map_enqueue Jesper Dangaard Brouer
2017-11-01 13:54 ` John Fastabend
2017-11-01 14:18 ` Jesper Dangaard Brouer
2017-11-01 16:12 ` Alexei Starovoitov
2017-11-02 7:14 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).