Commit ab8684b8 authored by Jon Doron's avatar Jon Doron Committed by Andrii Nakryiko

libbpf: Add sample_period to creation options

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: default avatarJon Doron <jond@wiz.io>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20230207081916.3398417-1-arilou@gmail.com
parent 9b0651e4
...@@ -11673,17 +11673,22 @@ struct perf_buffer *perf_buffer__new(int map_fd, size_t page_cnt, ...@@ -11673,17 +11673,22 @@ struct perf_buffer *perf_buffer__new(int map_fd, size_t page_cnt,
const size_t attr_sz = sizeof(struct perf_event_attr); const size_t attr_sz = sizeof(struct perf_event_attr);
struct perf_buffer_params p = {}; struct perf_buffer_params p = {};
struct perf_event_attr attr; struct perf_event_attr attr;
__u32 sample_period;
if (!OPTS_VALID(opts, perf_buffer_opts)) if (!OPTS_VALID(opts, perf_buffer_opts))
return libbpf_err_ptr(-EINVAL); return libbpf_err_ptr(-EINVAL);
sample_period = OPTS_GET(opts, sample_period, 1);
if (!sample_period)
sample_period = 1;
memset(&attr, 0, attr_sz); memset(&attr, 0, attr_sz);
attr.size = attr_sz; attr.size = attr_sz;
attr.config = PERF_COUNT_SW_BPF_OUTPUT; attr.config = PERF_COUNT_SW_BPF_OUTPUT;
attr.type = PERF_TYPE_SOFTWARE; attr.type = PERF_TYPE_SOFTWARE;
attr.sample_type = PERF_SAMPLE_RAW; attr.sample_type = PERF_SAMPLE_RAW;
attr.sample_period = 1; attr.sample_period = sample_period;
attr.wakeup_events = 1; attr.wakeup_events = sample_period;
p.attr = &attr; p.attr = &attr;
p.sample_cb = sample_cb; p.sample_cb = sample_cb;
......
...@@ -1247,8 +1247,10 @@ typedef void (*perf_buffer_lost_fn)(void *ctx, int cpu, __u64 cnt); ...@@ -1247,8 +1247,10 @@ typedef void (*perf_buffer_lost_fn)(void *ctx, int cpu, __u64 cnt);
/* common use perf buffer options */ /* common use perf buffer options */
struct perf_buffer_opts { struct perf_buffer_opts {
size_t sz; size_t sz;
__u32 sample_period;
size_t :0;
}; };
#define perf_buffer_opts__last_field sz #define perf_buffer_opts__last_field sample_period
/** /**
* @brief **perf_buffer__new()** creates BPF perfbuf manager for a specified * @brief **perf_buffer__new()** creates BPF perfbuf manager for a specified
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment