2020-05-06 20:55:01

by Ian Rogers

[permalink] [raw]
Subject: [PATCH 1/2] lib/bpf hashmap: increase portability

Don't include libbpf_internal.h as it is unused and has conflicting
definitions, for example, with tools/perf/util/debug.h.
Fix a non-glibc include path.

Signed-off-by: Ian Rogers <[email protected]>
---
tools/lib/bpf/hashmap.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/lib/bpf/hashmap.h b/tools/lib/bpf/hashmap.h
index bae8879cdf58..d5ef212a55ba 100644
--- a/tools/lib/bpf/hashmap.h
+++ b/tools/lib/bpf/hashmap.h
@@ -13,9 +13,8 @@
#ifdef __GLIBC__
#include <bits/wordsize.h>
#else
-#include <bits/reg.h>
+#include <linux/bitops.h>
#endif
-#include "libbpf_internal.h"

static inline size_t hash_bits(size_t h, int bits)
{
--
2.26.2.526.g744177e7f7-goog


2020-05-06 21:36:38

by Andrii Nakryiko

[permalink] [raw]
Subject: Re: [PATCH 1/2] lib/bpf hashmap: increase portability

On Wed, May 6, 2020 at 1:54 PM Ian Rogers <[email protected]> wrote:
>
> Don't include libbpf_internal.h as it is unused and has conflicting
> definitions, for example, with tools/perf/util/debug.h.
> Fix a non-glibc include path.
>
> Signed-off-by: Ian Rogers <[email protected]>
> ---
> tools/lib/bpf/hashmap.h | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/tools/lib/bpf/hashmap.h b/tools/lib/bpf/hashmap.h
> index bae8879cdf58..d5ef212a55ba 100644
> --- a/tools/lib/bpf/hashmap.h
> +++ b/tools/lib/bpf/hashmap.h
> @@ -13,9 +13,8 @@
> #ifdef __GLIBC__
> #include <bits/wordsize.h>
> #else
> -#include <bits/reg.h>
> +#include <linux/bitops.h>

why this change? It might be ok for libbpf built from kernel source,
but it will break Github libbpf.

> #endif
> -#include "libbpf_internal.h"

Dropping this seems ok, don't remember why I had it here in the first place.

>
> static inline size_t hash_bits(size_t h, int bits)
> {
> --
> 2.26.2.526.g744177e7f7-goog
>

2020-05-06 21:49:52

by Ian Rogers

[permalink] [raw]
Subject: Re: [PATCH 1/2] lib/bpf hashmap: increase portability

On Wed, May 6, 2020 at 2:33 PM Andrii Nakryiko
<[email protected]> wrote:
>
> On Wed, May 6, 2020 at 1:54 PM Ian Rogers <[email protected]> wrote:
> >
> > Don't include libbpf_internal.h as it is unused and has conflicting
> > definitions, for example, with tools/perf/util/debug.h.
> > Fix a non-glibc include path.
> >
> > Signed-off-by: Ian Rogers <[email protected]>
> > ---
> > tools/lib/bpf/hashmap.h | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/tools/lib/bpf/hashmap.h b/tools/lib/bpf/hashmap.h
> > index bae8879cdf58..d5ef212a55ba 100644
> > --- a/tools/lib/bpf/hashmap.h
> > +++ b/tools/lib/bpf/hashmap.h
> > @@ -13,9 +13,8 @@
> > #ifdef __GLIBC__
> > #include <bits/wordsize.h>
> > #else
> > -#include <bits/reg.h>
> > +#include <linux/bitops.h>
>
> why this change? It might be ok for libbpf built from kernel source,
> but it will break Github libbpf.

Without this change my debian based machine wasn't able to build
within the kernel tree. I see bits/wordsize.h on the machine. Perhaps
the __WORDSIZE computation could just be based on __LP64__ to remove
any #include?

Thanks,
Ian

> > #endif
> > -#include "libbpf_internal.h"
>
> Dropping this seems ok, don't remember why I had it here in the first place.
>
> >
> > static inline size_t hash_bits(size_t h, int bits)
> > {
> > --
> > 2.26.2.526.g744177e7f7-goog
> >

2020-05-06 21:58:31

by Andrii Nakryiko

[permalink] [raw]
Subject: Re: [PATCH 1/2] lib/bpf hashmap: increase portability

On Wed, May 6, 2020 at 2:47 PM Ian Rogers <[email protected]> wrote:
>
> On Wed, May 6, 2020 at 2:33 PM Andrii Nakryiko
> <[email protected]> wrote:
> >
> > On Wed, May 6, 2020 at 1:54 PM Ian Rogers <[email protected]> wrote:
> > >
> > > Don't include libbpf_internal.h as it is unused and has conflicting
> > > definitions, for example, with tools/perf/util/debug.h.
> > > Fix a non-glibc include path.
> > >
> > > Signed-off-by: Ian Rogers <[email protected]>
> > > ---
> > > tools/lib/bpf/hashmap.h | 3 +--
> > > 1 file changed, 1 insertion(+), 2 deletions(-)
> > >
> > > diff --git a/tools/lib/bpf/hashmap.h b/tools/lib/bpf/hashmap.h
> > > index bae8879cdf58..d5ef212a55ba 100644
> > > --- a/tools/lib/bpf/hashmap.h
> > > +++ b/tools/lib/bpf/hashmap.h
> > > @@ -13,9 +13,8 @@
> > > #ifdef __GLIBC__
> > > #include <bits/wordsize.h>
> > > #else
> > > -#include <bits/reg.h>
> > > +#include <linux/bitops.h>
> >
> > why this change? It might be ok for libbpf built from kernel source,
> > but it will break Github libbpf.
>
> Without this change my debian based machine wasn't able to build
> within the kernel tree. I see bits/wordsize.h on the machine. Perhaps
> the __WORDSIZE computation could just be based on __LP64__ to remove
> any #include?

It might work. Do you mind forking https://github.com/libbpf/libbpf
and trying to execute travis CI tests with such change? It compiles
across a range of distros and arches. You might need to set up Travis
CI login, hope that's not a problem. Thanks!

>
> Thanks,
> Ian
>
> > > #endif
> > > -#include "libbpf_internal.h"
> >
> > Dropping this seems ok, don't remember why I had it here in the first place.
> >
> > >
> > > static inline size_t hash_bits(size_t h, int bits)
> > > {
> > > --
> > > 2.26.2.526.g744177e7f7-goog
> > >

2020-05-06 22:16:08

by Ian Rogers

[permalink] [raw]
Subject: Re: [PATCH 1/2] lib/bpf hashmap: increase portability

On Wed, May 6, 2020 at 2:56 PM Andrii Nakryiko
<[email protected]> wrote:
>
> On Wed, May 6, 2020 at 2:47 PM Ian Rogers <[email protected]> wrote:
> >
> > On Wed, May 6, 2020 at 2:33 PM Andrii Nakryiko
> > <[email protected]> wrote:
> > >
> > > On Wed, May 6, 2020 at 1:54 PM Ian Rogers <[email protected]> wrote:
> > > >
> > > > Don't include libbpf_internal.h as it is unused and has conflicting
> > > > definitions, for example, with tools/perf/util/debug.h.
> > > > Fix a non-glibc include path.
> > > >
> > > > Signed-off-by: Ian Rogers <[email protected]>
> > > > ---
> > > > tools/lib/bpf/hashmap.h | 3 +--
> > > > 1 file changed, 1 insertion(+), 2 deletions(-)
> > > >
> > > > diff --git a/tools/lib/bpf/hashmap.h b/tools/lib/bpf/hashmap.h
> > > > index bae8879cdf58..d5ef212a55ba 100644
> > > > --- a/tools/lib/bpf/hashmap.h
> > > > +++ b/tools/lib/bpf/hashmap.h
> > > > @@ -13,9 +13,8 @@
> > > > #ifdef __GLIBC__
> > > > #include <bits/wordsize.h>
> > > > #else
> > > > -#include <bits/reg.h>
> > > > +#include <linux/bitops.h>
> > >
> > > why this change? It might be ok for libbpf built from kernel source,
> > > but it will break Github libbpf.
> >
> > Without this change my debian based machine wasn't able to build
> > within the kernel tree. I see bits/wordsize.h on the machine. Perhaps
> > the __WORDSIZE computation could just be based on __LP64__ to remove
> > any #include?
>
> It might work. Do you mind forking https://github.com/libbpf/libbpf
> and trying to execute travis CI tests with such change? It compiles
> across a range of distros and arches. You might need to set up Travis
> CI login, hope that's not a problem. Thanks!

I'll try to find time. Thanks,
Ian

> >
> > Thanks,
> > Ian
> >
> > > > #endif
> > > > -#include "libbpf_internal.h"
> > >
> > > Dropping this seems ok, don't remember why I had it here in the first place.
> > >
> > > >
> > > > static inline size_t hash_bits(size_t h, int bits)
> > > > {
> > > > --
> > > > 2.26.2.526.g744177e7f7-goog
> > > >