Message ID | 20200430071506.1408910-3-songliubraving@fb.com |
---|---|
State | Accepted |
Delegated to: | BPF Maintainers |
Headers | show |
Series | bpf: sharing bpf runtime stats with | expand |
On Thu, Apr 30, 2020 at 12:15 AM Song Liu <songliubraving@fb.com> wrote: > > bpf_enable_stats() is added to enable given stats. > > Signed-off-by: Song Liu <songliubraving@fb.com> ... > diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h > index 335b457b3a25..1901b2777854 100644 > --- a/tools/lib/bpf/bpf.h > +++ b/tools/lib/bpf/bpf.h > @@ -231,6 +231,7 @@ LIBBPF_API int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf, > LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, > __u32 *buf_len, __u32 *prog_id, __u32 *fd_type, > __u64 *probe_offset, __u64 *probe_addr); > +LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); I see odd warning here while building selftests In file included from runqslower.c:10: .../tools/testing/selftests/bpf/tools/include/bpf/bpf.h:234:38: warning: ‘enum bpf_stats_type’ declared inside parameter list will not be visible outside of this definition or declaration 234 | LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); Since this warning is printed only when building runqslower and the rest of selftests are fine, I'm guessing it's a makefile issue with order of includes? Andrii, could you please take a look ? Not urgent. Just flagging for visibility.
> On May 2, 2020, at 1:00 PM, Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote: > > On Thu, Apr 30, 2020 at 12:15 AM Song Liu <songliubraving@fb.com> wrote: >> >> bpf_enable_stats() is added to enable given stats. >> >> Signed-off-by: Song Liu <songliubraving@fb.com> > ... >> diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h >> index 335b457b3a25..1901b2777854 100644 >> --- a/tools/lib/bpf/bpf.h >> +++ b/tools/lib/bpf/bpf.h >> @@ -231,6 +231,7 @@ LIBBPF_API int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf, >> LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, >> __u32 *buf_len, __u32 *prog_id, __u32 *fd_type, >> __u64 *probe_offset, __u64 *probe_addr); >> +LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); > > I see odd warning here while building selftests > > In file included from runqslower.c:10: > .../tools/testing/selftests/bpf/tools/include/bpf/bpf.h:234:38: > warning: ‘enum bpf_stats_type’ declared inside parameter list will not > be visible outside of this definition or declaration > 234 | LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); > > Since this warning is printed only when building runqslower > and the rest of selftests are fine, I'm guessing > it's a makefile issue with order of includes? > > Andrii, could you please take a look ? > Not urgent. Just flagging for visibility. The following should fix it. Thanks, Song =========================== 8< ============================== From 485c28c8e2cbcc22aa8fcda82f8f599411faa755 Mon Sep 17 00:00:00 2001 From: Song Liu <songliubraving@fb.com> Date: Mon, 4 May 2020 10:36:26 -0700 Subject: [PATCH bpf-next] runqslower: include proper uapi/bpf.h runqslower doesn't specify include path for uapi/bpf.h. This causes the following warning: In file included from runqslower.c:10: .../tools/testing/selftests/bpf/tools/include/bpf/bpf.h:234:38: warning: 'enum bpf_stats_type' declared inside parameter list will not be visible outside of this definition or declaration 234 | LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); Fix this by adding -I tools/includ/uapi to the Makefile. Reported-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Song Liu <songliubraving@fb.com> --- tools/bpf/runqslower/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/bpf/runqslower/Makefile b/tools/bpf/runqslower/Makefile index 8a6f82e56a24..722a29a988cd 100644 --- a/tools/bpf/runqslower/Makefile +++ b/tools/bpf/runqslower/Makefile @@ -8,7 +8,8 @@ BPFTOOL ?= $(DEFAULT_BPFTOOL) LIBBPF_SRC := $(abspath ../../lib/bpf) BPFOBJ := $(OUTPUT)/libbpf.a BPF_INCLUDE := $(OUTPUT) -INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../lib) +INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../lib) \ + -I$(abspath ../../include/uapi) CFLAGS := -g -Wall # Try to detect best kernel BTF source -- 2.24.1
On Mon, May 4, 2020 at 10:47 AM Song Liu <songliubraving@fb.com> wrote: > > > > > On May 2, 2020, at 1:00 PM, Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote: > > > > On Thu, Apr 30, 2020 at 12:15 AM Song Liu <songliubraving@fb.com> wrote: > >> > >> bpf_enable_stats() is added to enable given stats. > >> > >> Signed-off-by: Song Liu <songliubraving@fb.com> > > ... > >> diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h > >> index 335b457b3a25..1901b2777854 100644 > >> --- a/tools/lib/bpf/bpf.h > >> +++ b/tools/lib/bpf/bpf.h > >> @@ -231,6 +231,7 @@ LIBBPF_API int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf, > >> LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, > >> __u32 *buf_len, __u32 *prog_id, __u32 *fd_type, > >> __u64 *probe_offset, __u64 *probe_addr); > >> +LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); > > > > I see odd warning here while building selftests > > > > In file included from runqslower.c:10: > > .../tools/testing/selftests/bpf/tools/include/bpf/bpf.h:234:38: > > warning: ‘enum bpf_stats_type’ declared inside parameter list will not > > be visible outside of this definition or declaration > > 234 | LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); > > > > Since this warning is printed only when building runqslower > > and the rest of selftests are fine, I'm guessing > > it's a makefile issue with order of includes? > > > > Andrii, could you please take a look ? > > Not urgent. Just flagging for visibility. > > The following should fix it. > > Thanks, > Song > > =========================== 8< ============================== > > From 485c28c8e2cbcc22aa8fcda82f8f599411faa755 Mon Sep 17 00:00:00 2001 > From: Song Liu <songliubraving@fb.com> > Date: Mon, 4 May 2020 10:36:26 -0700 > Subject: [PATCH bpf-next] runqslower: include proper uapi/bpf.h > > runqslower doesn't specify include path for uapi/bpf.h. This causes the > following warning: > > In file included from runqslower.c:10: > .../tools/testing/selftests/bpf/tools/include/bpf/bpf.h:234:38: > warning: 'enum bpf_stats_type' declared inside parameter list will not > be visible outside of this definition or declaration > 234 | LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); > > Fix this by adding -I tools/includ/uapi to the Makefile. > > Reported-by: Alexei Starovoitov <ast@kernel.org> > Signed-off-by: Song Liu <songliubraving@fb.com> > --- LGTM. Thanks! Acked-by: Andrii Nakryiko <andriin@fb.com> > tools/bpf/runqslower/Makefile | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/tools/bpf/runqslower/Makefile b/tools/bpf/runqslower/Makefile > index 8a6f82e56a24..722a29a988cd 100644 > --- a/tools/bpf/runqslower/Makefile > +++ b/tools/bpf/runqslower/Makefile > @@ -8,7 +8,8 @@ BPFTOOL ?= $(DEFAULT_BPFTOOL) > LIBBPF_SRC := $(abspath ../../lib/bpf) > BPFOBJ := $(OUTPUT)/libbpf.a > BPF_INCLUDE := $(OUTPUT) > -INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../lib) > +INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../lib) \ > + -I$(abspath ../../include/uapi) > CFLAGS := -g -Wall > > # Try to detect best kernel BTF source > -- > 2.24.1 >
On Mon, May 4, 2020 at 10:45 AM Song Liu <songliubraving@fb.com> wrote: > > > > > On May 2, 2020, at 1:00 PM, Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote: > > > > On Thu, Apr 30, 2020 at 12:15 AM Song Liu <songliubraving@fb.com> wrote: > >> > >> bpf_enable_stats() is added to enable given stats. > >> > >> Signed-off-by: Song Liu <songliubraving@fb.com> > > ... > >> diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h > >> index 335b457b3a25..1901b2777854 100644 > >> --- a/tools/lib/bpf/bpf.h > >> +++ b/tools/lib/bpf/bpf.h > >> @@ -231,6 +231,7 @@ LIBBPF_API int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf, > >> LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, > >> __u32 *buf_len, __u32 *prog_id, __u32 *fd_type, > >> __u64 *probe_offset, __u64 *probe_addr); > >> +LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); > > > > I see odd warning here while building selftests > > > > In file included from runqslower.c:10: > > .../tools/testing/selftests/bpf/tools/include/bpf/bpf.h:234:38: > > warning: ‘enum bpf_stats_type’ declared inside parameter list will not > > be visible outside of this definition or declaration > > 234 | LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); > > > > Since this warning is printed only when building runqslower > > and the rest of selftests are fine, I'm guessing > > it's a makefile issue with order of includes? > > > > Andrii, could you please take a look ? > > Not urgent. Just flagging for visibility. > > The following should fix it. > > Thanks, > Song > > =========================== 8< ============================== > > From 485c28c8e2cbcc22aa8fcda82f8f599411faa755 Mon Sep 17 00:00:00 2001 > From: Song Liu <songliubraving@fb.com> > Date: Mon, 4 May 2020 10:36:26 -0700 > Subject: [PATCH bpf-next] runqslower: include proper uapi/bpf.h > > runqslower doesn't specify include path for uapi/bpf.h. This causes the > following warning: > > In file included from runqslower.c:10: > .../tools/testing/selftests/bpf/tools/include/bpf/bpf.h:234:38: > warning: 'enum bpf_stats_type' declared inside parameter list will not > be visible outside of this definition or declaration > 234 | LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); > > Fix this by adding -I tools/includ/uapi to the Makefile. > > Reported-by: Alexei Starovoitov <ast@kernel.org> > Signed-off-by: Song Liu <songliubraving@fb.com> Applied. In the future please always send patches as fresh email otherwise they don't register in patchworks. I applied this one manually.
On Mon, May 4, 2020 at 10:47 AM Song Liu <songliubraving@fb.com> wrote: > > > > > On May 2, 2020, at 1:00 PM, Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote: > > > > On Thu, Apr 30, 2020 at 12:15 AM Song Liu <songliubraving@fb.com> wrote: > >> > >> bpf_enable_stats() is added to enable given stats. > >> > >> Signed-off-by: Song Liu <songliubraving@fb.com> > > ... > >> diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h > >> index 335b457b3a25..1901b2777854 100644 > >> --- a/tools/lib/bpf/bpf.h > >> +++ b/tools/lib/bpf/bpf.h > >> @@ -231,6 +231,7 @@ LIBBPF_API int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf, > >> LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, > >> __u32 *buf_len, __u32 *prog_id, __u32 *fd_type, > >> __u64 *probe_offset, __u64 *probe_addr); > >> +LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); > > > > I see odd warning here while building selftests > > > > In file included from runqslower.c:10: > > .../tools/testing/selftests/bpf/tools/include/bpf/bpf.h:234:38: > > warning: ‘enum bpf_stats_type’ declared inside parameter list will not > > be visible outside of this definition or declaration > > 234 | LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); > > > > Since this warning is printed only when building runqslower > > and the rest of selftests are fine, I'm guessing > > it's a makefile issue with order of includes? > > > > Andrii, could you please take a look ? > > Not urgent. Just flagging for visibility. > > The following should fix it. > > Thanks, > Song > > =========================== 8< ============================== > > From 485c28c8e2cbcc22aa8fcda82f8f599411faa755 Mon Sep 17 00:00:00 2001 > From: Song Liu <songliubraving@fb.com> > Date: Mon, 4 May 2020 10:36:26 -0700 > Subject: [PATCH bpf-next] runqslower: include proper uapi/bpf.h > > runqslower doesn't specify include path for uapi/bpf.h. This causes the > following warning: > > In file included from runqslower.c:10: > .../tools/testing/selftests/bpf/tools/include/bpf/bpf.h:234:38: > warning: 'enum bpf_stats_type' declared inside parameter list will not > be visible outside of this definition or declaration > 234 | LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); > > Fix this by adding -I tools/includ/uapi to the Makefile. > > Reported-by: Alexei Starovoitov <ast@kernel.org> > Signed-off-by: Song Liu <songliubraving@fb.com> > --- > tools/bpf/runqslower/Makefile | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/tools/bpf/runqslower/Makefile b/tools/bpf/runqslower/Makefile > index 8a6f82e56a24..722a29a988cd 100644 > --- a/tools/bpf/runqslower/Makefile > +++ b/tools/bpf/runqslower/Makefile > @@ -8,7 +8,8 @@ BPFTOOL ?= $(DEFAULT_BPFTOOL) > LIBBPF_SRC := $(abspath ../../lib/bpf) > BPFOBJ := $(OUTPUT)/libbpf.a > BPF_INCLUDE := $(OUTPUT) > -INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../lib) > +INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../lib) \ > + -I$(abspath ../../include/uapi) > CFLAGS := -g -Wall > > # Try to detect best kernel BTF source > -- > 2.24.1 > This is a partial work-around just for runqslower, which has a luxury to access the very latest linux/bpf.h. Any other system that doesn't have the very latest bpf.h header will get warnings about undefined `enum bpf_stats_type` definition, even if they don't use bpf_stats_enable(). I think the proper fix here is to add forward declaration of this enum in libbpf/bpf.h. I'll send a patch in a few minutes.
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 8f2f0958d446..43322f0d6c7f 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -841,3 +841,13 @@ int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, __u32 *buf_len, return err; } + +int bpf_enable_stats(enum bpf_stats_type type) +{ + union bpf_attr attr; + + memset(&attr, 0, sizeof(attr)); + attr.enable_stats.type = type; + + return sys_bpf(BPF_ENABLE_STATS, &attr, sizeof(attr)); +} diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 335b457b3a25..1901b2777854 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -231,6 +231,7 @@ LIBBPF_API int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf, LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, __u32 *buf_len, __u32 *prog_id, __u32 *fd_type, __u64 *probe_offset, __u64 *probe_addr); +LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); #ifdef __cplusplus } /* extern "C" */ diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 7cd49aa38005..e03bd4db827e 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -257,6 +257,7 @@ LIBBPF_0.0.8 { LIBBPF_0.0.9 { global: + bpf_enable_stats; bpf_link_get_fd_by_id; bpf_link_get_next_id; } LIBBPF_0.0.8;
bpf_enable_stats() is added to enable given stats. Signed-off-by: Song Liu <songliubraving@fb.com> --- tools/lib/bpf/bpf.c | 10 ++++++++++ tools/lib/bpf/bpf.h | 1 + tools/lib/bpf/libbpf.map | 1 + 3 files changed, 12 insertions(+)