From: Jon Doron <arilou@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
Jon Doron <jond@wiz.io>
Subject: Re: [PATCH bpf-next v2] libbpf: Add wakeup_events to creation options
Date: Fri, 3 Feb 2023 09:14:20 +0200 [thread overview]
Message-ID: <Y9y0THRh7zrO4fZL@jondnuc> (raw)
In-Reply-To: <CAEf4BzZE_icgcddkwVQW+0HRtHM=wRaHr3jqmkTJ92O86=6hjA@mail.gmail.com>
On 02/02/2023, Andrii Nakryiko wrote:
>On Wed, Feb 1, 2023 at 10:26 PM Jon Doron <arilou@gmail.com> 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 | 3 ++-
>> 2 files changed, 4 insertions(+), 3 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);
>
>I suspect the case of
>
>LIBBPF_OPTS(perf_buffer_opts, opts);
>
>perf_buffer__new(...., &opts);
>
>is not handled correctly and you end up with sample_period == wakeup_events == 0
>
>Can you please add BPF selftests that's setting wakeup_events to zero
>and separately to >1?
>
Hi Andrii,
I'm not sure what we are testing, when you have sample_period ==
wakeup_events == 0, it basically means to never wakeup, so let's say you
would wait on the poll_fd infinitely it will never wake you up.
When you have let's say wakeup_event != 0, you will wakeup after the
ring buffer in the perf buffer has more events than wakeup_events.
I do see your point that if someone is using the macro to build the opts
they will end with something unexpected, would you like me to treat 0 as
1 in that case?
-- Jon.
>>
>> p.attr = &attr;
>> p.sample_cb = sample_cb;
>> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
>> index 8777ff21ea1d..e83c0a915dc7 100644
>> --- a/tools/lib/bpf/libbpf.h
>> +++ b/tools/lib/bpf/libbpf.h
>> @@ -1246,8 +1246,9 @@ 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
>> +#define perf_buffer_opts__last_field wakeup_events
>>
>> /**
>> * @brief **perf_buffer__new()** creates BPF perfbuf manager for a specified
>> --
>> 2.39.1
>>
next prev parent reply other threads:[~2023-02-03 7:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-02 6:25 [PATCH bpf-next v2] libbpf: Add wakeup_events to creation options Jon Doron
2023-02-02 22:50 ` Andrii Nakryiko
2023-02-03 7:14 ` Jon Doron [this message]
2023-02-03 21:41 ` Andrii Nakryiko
2023-02-03 18:31 ` Yonghong Song
2023-02-03 21:42 ` Andrii Nakryiko
2023-02-03 23:11 ` Yonghong Song
2023-02-06 5:39 ` Yonghong Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y9y0THRh7zrO4fZL@jondnuc \
--to=arilou@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=jond@wiz.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox