diff mbox series

[v7,bpf-next,2/3] libbpf: add support for command BPF_ENABLE_STATS

Message ID 20200429035841.3959159-3-songliubraving@fb.com
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series bpf: sharing bpf runtime stats with | expand

Commit Message

Song Liu April 29, 2020, 3:58 a.m. UTC
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 |  5 +++++
 3 files changed, 16 insertions(+)

Comments

Andrii Nakryiko April 29, 2020, 5:32 a.m. UTC | #1
On Tue, Apr 28, 2020 at 8:59 PM Song Liu <songliubraving@fb.com> wrote:
>
> 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 |  5 +++++
>  3 files changed, 16 insertions(+)
>
> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> index 5cc1b0785d18..17bb4ad06c0e 100644
> --- a/tools/lib/bpf/bpf.c
> +++ b/tools/lib/bpf/bpf.c
> @@ -826,3 +826,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 46d47afdd887..5996e64d324c 100644
> --- a/tools/lib/bpf/bpf.h
> +++ b/tools/lib/bpf/bpf.h
> @@ -229,6 +229,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 bb8831605b25..ebd946faada5 100644
> --- a/tools/lib/bpf/libbpf.map
> +++ b/tools/lib/bpf/libbpf.map
> @@ -254,3 +254,8 @@ LIBBPF_0.0.8 {
>                 bpf_program__set_lsm;
>                 bpf_set_link_xdp_fd_opts;
>  } LIBBPF_0.0.7;
> +
> +LIBBPF_0.0.9 {
> +       global:

You forgot to pull and rebase. LIBBPF_0.0.9 is already in master.

> +               bpf_enable_stats;
> +} LIBBPF_0.0.8;
> \ No newline at end of file
> --
> 2.24.1
>
Song Liu April 29, 2020, 5:36 a.m. UTC | #2
> On Apr 28, 2020, at 10:32 PM, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
> 
> On Tue, Apr 28, 2020 at 8:59 PM Song Liu <songliubraving@fb.com> wrote:
>> 
>> 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 |  5 +++++
>> 3 files changed, 16 insertions(+)
>> 
>> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
>> index 5cc1b0785d18..17bb4ad06c0e 100644
>> --- a/tools/lib/bpf/bpf.c
>> +++ b/tools/lib/bpf/bpf.c
>> @@ -826,3 +826,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 46d47afdd887..5996e64d324c 100644
>> --- a/tools/lib/bpf/bpf.h
>> +++ b/tools/lib/bpf/bpf.h
>> @@ -229,6 +229,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 bb8831605b25..ebd946faada5 100644
>> --- a/tools/lib/bpf/libbpf.map
>> +++ b/tools/lib/bpf/libbpf.map
>> @@ -254,3 +254,8 @@ LIBBPF_0.0.8 {
>>                bpf_program__set_lsm;
>>                bpf_set_link_xdp_fd_opts;
>> } LIBBPF_0.0.7;
>> +
>> +LIBBPF_0.0.9 {
>> +       global:
> 
> You forgot to pull and rebase. LIBBPF_0.0.9 is already in master.

Hmm.. I pulled earlier today. Let me pull again..

Thanks,
Song
diff mbox series

Patch

diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 5cc1b0785d18..17bb4ad06c0e 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -826,3 +826,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 46d47afdd887..5996e64d324c 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -229,6 +229,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 bb8831605b25..ebd946faada5 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -254,3 +254,8 @@  LIBBPF_0.0.8 {
 		bpf_program__set_lsm;
 		bpf_set_link_xdp_fd_opts;
 } LIBBPF_0.0.7;
+
+LIBBPF_0.0.9 {
+	global:
+		bpf_enable_stats;
+} LIBBPF_0.0.8;
\ No newline at end of file