* [PATCH bpf-next v2] libbpf: add API to consume the perf ring buffer content
@ 2020-05-26 9:21 Eelco Chaudron
2020-05-26 17:42 ` Andrii Nakryiko
2020-05-26 21:15 ` Daniel Borkmann
0 siblings, 2 replies; 3+ messages in thread
From: Eelco Chaudron @ 2020-05-26 9:21 UTC (permalink / raw)
To: bpf; +Cc: davem, netdev, ast, daniel, kafai, songliubraving, yhs, andriin,
toke
This new API, perf_buffer__consume, can be used as follows:
- When you have a perf ring where wakeup_events is higher than 1,
and you have remaining data in the rings you would like to pull
out on exit (or maybe based on a timeout).
- For low latency cases where you burn a CPU that constantly polls
the queues.
Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
---
v2:
- Removed some input checks
- Support spare CPU buffers
- Moved variable "err" up
tools/lib/bpf/libbpf.c | 19 +++++++++++++++++++
tools/lib/bpf/libbpf.h | 1 +
tools/lib/bpf/libbpf.map | 1 +
3 files changed, 21 insertions(+)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index fa04cbe547ed..5d60de6fd818 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -8456,6 +8456,25 @@ int perf_buffer__poll(struct perf_buffer *pb, int timeout_ms)
return cnt < 0 ? -errno : cnt;
}
+int perf_buffer__consume(struct perf_buffer *pb)
+{
+ int i, err;
+
+ for (i = 0; i < pb->cpu_cnt; i++) {
+ struct perf_cpu_buf *cpu_buf = pb->cpu_bufs[i];
+
+ if (!cpu_buf)
+ continue;
+
+ err = perf_buffer__process_records(pb, cpu_buf);
+ if (err) {
+ pr_warn("error while processing records: %d\n", err);
+ return err;
+ }
+ }
+ return 0;
+}
+
struct bpf_prog_info_array_desc {
int array_offset; /* e.g. offset of jited_prog_insns */
int count_offset; /* e.g. offset of jited_prog_len */
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 8ea69558f0a8..1e2e399a5f2c 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -533,6 +533,7 @@ perf_buffer__new_raw(int map_fd, size_t page_cnt,
LIBBPF_API void perf_buffer__free(struct perf_buffer *pb);
LIBBPF_API int perf_buffer__poll(struct perf_buffer *pb, int timeout_ms);
+LIBBPF_API int perf_buffer__consume(struct perf_buffer *pb);
typedef enum bpf_perf_event_ret
(*bpf_perf_event_print_t)(struct perf_event_header *hdr,
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 0133d469d30b..381a7342ecfc 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -262,4 +262,5 @@ LIBBPF_0.0.9 {
bpf_link_get_fd_by_id;
bpf_link_get_next_id;
bpf_program__attach_iter;
+ perf_buffer__consume;
} LIBBPF_0.0.8;
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next v2] libbpf: add API to consume the perf ring buffer content
2020-05-26 9:21 [PATCH bpf-next v2] libbpf: add API to consume the perf ring buffer content Eelco Chaudron
@ 2020-05-26 17:42 ` Andrii Nakryiko
2020-05-26 21:15 ` Daniel Borkmann
1 sibling, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2020-05-26 17:42 UTC (permalink / raw)
To: Eelco Chaudron
Cc: bpf, David S. Miller, Networking, Alexei Starovoitov,
Daniel Borkmann, Martin Lau, Song Liu, Yonghong Song,
Andrii Nakryiko, Toke Høiland-Jørgensen
On Tue, May 26, 2020 at 2:22 AM Eelco Chaudron <echaudro@redhat.com> wrote:
>
> This new API, perf_buffer__consume, can be used as follows:
> - When you have a perf ring where wakeup_events is higher than 1,
> and you have remaining data in the rings you would like to pull
> out on exit (or maybe based on a timeout).
> - For low latency cases where you burn a CPU that constantly polls
> the queues.
>
> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
> ---
Looks good, thanks. I'd really appreciate if you could follow up with
a fix to perf_buffer__free() as well. If not, I will get to it
eventually anyway :)
Acked-by: Andrii Nakryiko <andriin@fb.com>
[...]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next v2] libbpf: add API to consume the perf ring buffer content
2020-05-26 9:21 [PATCH bpf-next v2] libbpf: add API to consume the perf ring buffer content Eelco Chaudron
2020-05-26 17:42 ` Andrii Nakryiko
@ 2020-05-26 21:15 ` Daniel Borkmann
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2020-05-26 21:15 UTC (permalink / raw)
To: Eelco Chaudron
Cc: bpf, davem, netdev, ast, kafai, songliubraving, yhs, andriin,
toke
On Tue, May 26, 2020 at 11:21:42AM +0200, Eelco Chaudron wrote:
> This new API, perf_buffer__consume, can be used as follows:
> - When you have a perf ring where wakeup_events is higher than 1,
> and you have remaining data in the rings you would like to pull
> out on exit (or maybe based on a timeout).
> - For low latency cases where you burn a CPU that constantly polls
> the queues.
>
> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
Applied, thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-05-26 21:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-26 9:21 [PATCH bpf-next v2] libbpf: add API to consume the perf ring buffer content Eelco Chaudron
2020-05-26 17:42 ` Andrii Nakryiko
2020-05-26 21:15 ` Daniel Borkmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).