All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v1] libbpf: Add wakeup_events to creation options
@ 2023-02-01  9:00 Jon Doron
  2023-02-01 19:57 ` Jiri Olsa
  0 siblings, 1 reply; 4+ messages in thread
From: Jon Doron @ 2023-02-01  9:00 UTC (permalink / raw)
  To: bpf, ast, andrii; +Cc: Jon Doron

From: Jon Doron <jond@wiz.io>

Add option to set when the perf buffer should wake up, by default the
perf buffer becomes signaled for every event that is being pushed to it.

In case of a high throughput of events it will be more efficient to wake
up only once you have X events ready to be read.

So your application can wakeup once and drain the entire perf buffer.

Signed-off-by: Jon Doron <jond@wiz.io>
---
 tools/lib/bpf/libbpf.c | 4 ++--
 tools/lib/bpf/libbpf.h | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index eed5cec6f510..6b30ff13922b 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -11719,8 +11719,8 @@ struct perf_buffer *perf_buffer__new(int map_fd, size_t page_cnt,
 	attr.config = PERF_COUNT_SW_BPF_OUTPUT;
 	attr.type = PERF_TYPE_SOFTWARE;
 	attr.sample_type = PERF_SAMPLE_RAW;
-	attr.sample_period = 1;
-	attr.wakeup_events = 1;
+	attr.sample_period = OPTS_GET(opts, wakeup_events, 1);
+	attr.wakeup_events = OPTS_GET(opts, wakeup_events, 1);
 
 	p.attr = &attr;
 	p.sample_cb = sample_cb;
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 8777ff21ea1d..2e4bdfc58c82 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -1246,6 +1246,7 @@ typedef void (*perf_buffer_lost_fn)(void *ctx, int cpu, __u64 cnt);
 /* common use perf buffer options */
 struct perf_buffer_opts {
 	size_t sz;
+	__u32 wakeup_events;
 };
 #define perf_buffer_opts__last_field sz
 
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next v1] libbpf: Add wakeup_events to creation options
  2023-02-01  9:00 [PATCH bpf-next v1] libbpf: Add wakeup_events to creation options Jon Doron
@ 2023-02-01 19:57 ` Jiri Olsa
  2023-02-02  1:28   ` Andrii Nakryiko
  0 siblings, 1 reply; 4+ messages in thread
From: Jiri Olsa @ 2023-02-01 19:57 UTC (permalink / raw)
  To: Jon Doron; +Cc: bpf, ast, andrii, Jon Doron

On Wed, Feb 01, 2023 at 11:00:09AM +0200, Jon Doron wrote:
> From: Jon Doron <jond@wiz.io>
> 
> Add option to set when the perf buffer should wake up, by default the
> perf buffer becomes signaled for every event that is being pushed to it.
> 
> In case of a high throughput of events it will be more efficient to wake
> up only once you have X events ready to be read.
> 
> So your application can wakeup once and drain the entire perf buffer.
> 
> Signed-off-by: Jon Doron <jond@wiz.io>
> ---
>  tools/lib/bpf/libbpf.c | 4 ++--
>  tools/lib/bpf/libbpf.h | 1 +
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index eed5cec6f510..6b30ff13922b 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -11719,8 +11719,8 @@ struct perf_buffer *perf_buffer__new(int map_fd, size_t page_cnt,
>  	attr.config = PERF_COUNT_SW_BPF_OUTPUT;
>  	attr.type = PERF_TYPE_SOFTWARE;
>  	attr.sample_type = PERF_SAMPLE_RAW;
> -	attr.sample_period = 1;
> -	attr.wakeup_events = 1;
> +	attr.sample_period = OPTS_GET(opts, wakeup_events, 1);

hm, but I think we still want every event.. setting sample_period to X
would store only every X-th bpf-output event, no?

jirka

> +	attr.wakeup_events = OPTS_GET(opts, wakeup_events, 1);
>  
>  	p.attr = &attr;
>  	p.sample_cb = sample_cb;
> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> index 8777ff21ea1d..2e4bdfc58c82 100644
> --- a/tools/lib/bpf/libbpf.h
> +++ b/tools/lib/bpf/libbpf.h
> @@ -1246,6 +1246,7 @@ typedef void (*perf_buffer_lost_fn)(void *ctx, int cpu, __u64 cnt);
>  /* common use perf buffer options */
>  struct perf_buffer_opts {
>  	size_t sz;
> +	__u32 wakeup_events;
>  };
>  #define perf_buffer_opts__last_field sz
>  
> -- 
> 2.39.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next v1] libbpf: Add wakeup_events to creation options
  2023-02-01 19:57 ` Jiri Olsa
@ 2023-02-02  1:28   ` Andrii Nakryiko
  2023-02-02  6:25     ` Jon Doron
  0 siblings, 1 reply; 4+ messages in thread
From: Andrii Nakryiko @ 2023-02-02  1:28 UTC (permalink / raw)
  To: Jiri Olsa; +Cc: Jon Doron, bpf, ast, andrii, Jon Doron

On Wed, Feb 1, 2023 at 11:57 AM Jiri Olsa <olsajiri@gmail.com> wrote:
>
> On Wed, Feb 01, 2023 at 11:00:09AM +0200, Jon Doron wrote:
> > From: Jon Doron <jond@wiz.io>
> >
> > Add option to set when the perf buffer should wake up, by default the
> > perf buffer becomes signaled for every event that is being pushed to it.
> >
> > In case of a high throughput of events it will be more efficient to wake
> > up only once you have X events ready to be read.
> >
> > So your application can wakeup once and drain the entire perf buffer.
> >
> > Signed-off-by: Jon Doron <jond@wiz.io>
> > ---
> >  tools/lib/bpf/libbpf.c | 4 ++--
> >  tools/lib/bpf/libbpf.h | 1 +
> >  2 files changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index eed5cec6f510..6b30ff13922b 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
> > @@ -11719,8 +11719,8 @@ struct perf_buffer *perf_buffer__new(int map_fd, size_t page_cnt,
> >       attr.config = PERF_COUNT_SW_BPF_OUTPUT;
> >       attr.type = PERF_TYPE_SOFTWARE;
> >       attr.sample_type = PERF_SAMPLE_RAW;
> > -     attr.sample_period = 1;
> > -     attr.wakeup_events = 1;
> > +     attr.sample_period = OPTS_GET(opts, wakeup_events, 1);
>
> hm, but I think we still want every event.. setting sample_period to X
> would store only every X-th bpf-output event, no?

seems like benchs/bench_ringbufs.c sets both sample_period and
wakeup_events, but it would be nice to make sure we do not lose events
with such configuration.

Let's add a selftest for this feature.

>
> jirka
>
> > +     attr.wakeup_events = OPTS_GET(opts, wakeup_events, 1);
> >
> >       p.attr = &attr;
> >       p.sample_cb = sample_cb;
> > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> > index 8777ff21ea1d..2e4bdfc58c82 100644
> > --- a/tools/lib/bpf/libbpf.h
> > +++ b/tools/lib/bpf/libbpf.h
> > @@ -1246,6 +1246,7 @@ typedef void (*perf_buffer_lost_fn)(void *ctx, int cpu, __u64 cnt);
> >  /* common use perf buffer options */
> >  struct perf_buffer_opts {
> >       size_t sz;
> > +     __u32 wakeup_events;
> >  };
> >  #define perf_buffer_opts__last_field sz

you need to update perf_buffer_opts__last_field to wakeup_events as well


> >
> > --
> > 2.39.1
> >

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next v1] libbpf: Add wakeup_events to creation options
  2023-02-02  1:28   ` Andrii Nakryiko
@ 2023-02-02  6:25     ` Jon Doron
  0 siblings, 0 replies; 4+ messages in thread
From: Jon Doron @ 2023-02-02  6:25 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: Jiri Olsa, bpf, ast, andrii, Jon Doron

On 01/02/2023, Andrii Nakryiko wrote:
>On Wed, Feb 1, 2023 at 11:57 AM Jiri Olsa <olsajiri@gmail.com> wrote:
>>
>> On Wed, Feb 01, 2023 at 11:00:09AM +0200, Jon Doron wrote:
>> > From: Jon Doron <jond@wiz.io>
>> >
>> > Add option to set when the perf buffer should wake up, by default the
>> > perf buffer becomes signaled for every event that is being pushed to it.
>> >
>> > In case of a high throughput of events it will be more efficient to wake
>> > up only once you have X events ready to be read.
>> >
>> > So your application can wakeup once and drain the entire perf buffer.
>> >
>> > Signed-off-by: Jon Doron <jond@wiz.io>
>> > ---
>> >  tools/lib/bpf/libbpf.c | 4 ++--
>> >  tools/lib/bpf/libbpf.h | 1 +
>> >  2 files changed, 3 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> > index eed5cec6f510..6b30ff13922b 100644
>> > --- a/tools/lib/bpf/libbpf.c
>> > +++ b/tools/lib/bpf/libbpf.c
>> > @@ -11719,8 +11719,8 @@ struct perf_buffer *perf_buffer__new(int map_fd, size_t page_cnt,
>> >       attr.config = PERF_COUNT_SW_BPF_OUTPUT;
>> >       attr.type = PERF_TYPE_SOFTWARE;
>> >       attr.sample_type = PERF_SAMPLE_RAW;
>> > -     attr.sample_period = 1;
>> > -     attr.wakeup_events = 1;
>> > +     attr.sample_period = OPTS_GET(opts, wakeup_events, 1);
>>
>> hm, but I think we still want every event.. setting sample_period to X
>> would store only every X-th bpf-output event, no?
>
>seems like benchs/bench_ringbufs.c sets both sample_period and
>wakeup_events, but it would be nice to make sure we do not lose events
>with such configuration.
>
>Let's add a selftest for this feature.
>

That's how it works, we wont be losing any events

>>
>> jirka
>>
>> > +     attr.wakeup_events = OPTS_GET(opts, wakeup_events, 1);
>> >
>> >       p.attr = &attr;
>> >       p.sample_cb = sample_cb;
>> > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
>> > index 8777ff21ea1d..2e4bdfc58c82 100644
>> > --- a/tools/lib/bpf/libbpf.h
>> > +++ b/tools/lib/bpf/libbpf.h
>> > @@ -1246,6 +1246,7 @@ typedef void (*perf_buffer_lost_fn)(void *ctx, int cpu, __u64 cnt);
>> >  /* common use perf buffer options */
>> >  struct perf_buffer_opts {
>> >       size_t sz;
>> > +     __u32 wakeup_events;
>> >  };
>> >  #define perf_buffer_opts__last_field sz
>
>you need to update perf_buffer_opts__last_field to wakeup_events as well
>
>

Done

>> >
>> > --
>> > 2.39.1
>> >

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-02-02  6:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-01  9:00 [PATCH bpf-next v1] libbpf: Add wakeup_events to creation options Jon Doron
2023-02-01 19:57 ` Jiri Olsa
2023-02-02  1:28   ` Andrii Nakryiko
2023-02-02  6:25     ` Jon Doron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.