libbpf: Add wakeup_events to creation options
PATCH 1/1 libbpf: Add wakeup_events to creation options
From: Jon Doron <[email protected]>
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.
--- tools/lib/bpf/libbpf.c | 4 ++-- tools/lib/bpf/libbpf.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-)
tools/lib/bpf/libbpf.c +2 -2
@@ -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;
tools/lib/bpf/libbpf.h +1 -0
@@ -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
Signature · 1 line
2.39.1
Quoted 21 lines · Jon Doron
From: Jon Doron <[email protected]>
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 <[email protected]>--- tools/lib/bpf/libbpf.c | 4 ++-- tools/lib/bpf/libbpf.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-)tools/lib/bpf/libbpf.c +0
-0
tools/lib/bpf/libbpf.c struct perf_buffer *perf_buffer__new(int map_fd, size_t page_cnt, · line 11722
Quoted 6 lines
tools/lib/bpf/libbpf.c +1
-2@@ -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
Quoted 19 lines
tools/lib/bpf/libbpf.c +1
-0+ attr.wakeup_events =OPTS_GET (opts, wakeup_events,1 ); p.attr = &attr; p.sample_cb = sample_cb;tools/lib/bpf/libbpf.h +1
-0@@ -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 szSignature · 1 line
2.39.1
Quoted 18 lines · Jiri Olsa
Quoted 16 lines · Jon Doron
From: Jon Doron <[email protected]>
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 <[email protected]>--- tools/lib/bpf/libbpf.c | 4 ++-- tools/lib/bpf/libbpf.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-)
Quoted 14 lines
tools/lib/bpf/libbpf.c struct perf_buffer *perf_buffer__new(int map_fd, size_t page_cnt, · line 11722
Quoted 11 lines
tools/lib/bpf/libbpf.c +1
-2@@ -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_periodto 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.
Quoted 5 lines
jirka
Quoted 2 lines
tools/lib/bpf/libbpf.c +1
-0+ attr.wakeup_events =OPTS_GET (opts, wakeup_events,1 );
Quoted 13 lines
tools/lib/bpf/libbpf.h typedef void (*perf_buffer_lost_fn)(void *ctx, int cpu, __u64 cnt); · line 1251
Quoted 13 lines
tools/lib/bpf/libbpf.c +0
-0p.attr = &attr; p.sample_cb = sample_cb;tools/lib/bpf/libbpf.h +1
-0@@ -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
Quoted 4 lines
Quoted 4 lines
tools/lib/bpf/libbpf.h +0
-1--2.39.1
Quoted 34 lines · Andrii Nakryiko
Quoted 18 lines · Jiri Olsa
Quoted 16 lines · Jon Doron
From: Jon Doron <[email protected]>
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 <[email protected]>--- tools/lib/bpf/libbpf.c | 4 ++-- tools/lib/bpf/libbpf.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-)Quoted 14 lines
tools/lib/bpf/libbpf.c struct perf_buffer *perf_buffer__new(int map_fd, size_t page_cnt, · line 11722
Quoted 11 lines
tools/lib/bpf/libbpf.c +1
-2@@ -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_periodto X would store only every X-th bpf-output event, no?
Quoted 6 lines
seems like
benchs/bench_ringbufs.csets bothsample_periodandwakeup_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
Quoted 5 lines
Quoted 5 lines
jirka
Quoted 2 lines
tools/lib/bpf/libbpf.c +1
-0+ attr.wakeup_events =OPTS_GET (opts, wakeup_events,1 );
Quoted 17 lines
Quoted 5 lines
Quoted 5 lines
tools/lib/bpf/libbpf.c +0
-0p.attr = &attr; p.sample_cb = sample_cb;tools/lib/bpf/libbpf.h +0
-1--- a/tools/lib/bpf/libbpf.hQuoted 8 lines
tools/lib/bpf/libbpf.h typedef void (*perf_buffer_lost_fn)(void *ctx, int cpu, __u64 cnt); · line 1251
Quoted 8 lines
+++
b/tools/lib/bpf/libbpf.htools/lib/bpf/libbpf.h +1
-0@@ -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 szyou need to update
perf_buffer_opts__last_fieldtowakeup_eventsas well
Done
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
tools/lib/bpf/libbpf.h +0
-1--2.39.1