Skip to contentSkip to conversation

libbpf: Expose libbpf ringbufer epoll_fd

PATCH Superseded Brendan Jackman 2 participants 3 messages Dec 14, 2020 – Dec 15, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libbpf: Expose libbpf ringbufer epoll_fd

This provides a convenient perf ringbuf -> libbpf ringbuf migration path for users of external polling systems. It is analogous to perf_buffer__epoll_fd.

---
Difference from v1: Added entry to libbpf.map.

 tools/lib/bpf/libbpf.h   | 1 +
 tools/lib/bpf/libbpf.map | 1 +
 tools/lib/bpf/ringbuf.c  | 6 ++++++
 3 files changed, 8 insertions(+)
tools/lib/bpf/libbpf.h +1 -0
index 6909ee81113a..cde07f64771e 100644
@@ -536,6 +536,7 @@ LIBBPF_API int ring_buffer__add(struct ring_buffer *rb, int map_fd,
 				ring_buffer_sample_fn sample_cb, void *ctx);
 LIBBPF_API int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms);
 LIBBPF_API int ring_buffer__consume(struct ring_buffer *rb);
+LIBBPF_API int ring_buffer__epoll_fd(struct ring_buffer *rb);
 
 /* Perf buffer APIs */
 struct perf_buffer;
tools/lib/bpf/libbpf.map +1 -0
index 7c4126542e2b..7be850271be6 100644
@@ -348,4 +348,5 @@ LIBBPF_0.3.0 {
 		btf__new_split;
 		xsk_setup_xdp_prog;
 		xsk_socket__update_xskmap;
+                ring_buffer__epoll_fd;
 } LIBBPF_0.2.0;
tools/lib/bpf/ringbuf.c +6 -0
index 5c6522c89af1..45a36648b403 100644
@@ -282,3 +282,9 @@ int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms)
 	}
 	return cnt < 0 ? -errno : res;
 }
+
+/* Get an fd that can be used to sleep until data is available in the ring(s) */
+int ring_buffer__epoll_fd(struct ring_buffer *rb)
+{
+	return rb->epoll_fd;
+}

base-commit: b4fe9fec51ef48011f11c2da4099f0b530449c92 --
2.29.2.576.ga3fc446d84-goog

maintainer
#1 lore raw
Quoted 30 lines · Brendan Jackman

This provides a convenient perf ringbuf -> libbpf ringbuf migration path for users of external polling systems. It is analogous to perf_buffer__epoll_fd.

---
Difference from v1: Added entry to libbpf.map.

  tools/lib/bpf/libbpf.h   | 1 +
  tools/lib/bpf/libbpf.map | 1 +
  tools/lib/bpf/ringbuf.c  | 6 ++++++
  3 files changed, 8 insertions(+)
tools/lib/bpf/libbpf.h +1 -0
index 6909ee81113a..cde07f64771e 100644
@@ -536,6 +536,7 @@ LIBBPF_API int ring_buffer__add(struct ring_buffer *rb, int map_fd,
  				ring_buffer_sample_fn sample_cb, void *ctx);
  LIBBPF_API int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms);
  LIBBPF_API int ring_buffer__consume(struct ring_buffer *rb);
+LIBBPF_API int ring_buffer__epoll_fd(struct ring_buffer *rb);
 
  /* Perf buffer APIs */
  struct perf_buffer;
tools/lib/bpf/libbpf.map +0 -0
index 7c4126542e2b..7be850271be6 100644

tools/lib/bpf/libbpf.map LIBBPF_0.3.0 { · line 351

Quoted 4 lines
tools/lib/bpf/libbpf.map +1 -0
@@ -348,4 +348,5 @@ LIBBPF_0.3.0 {
  		btf__new_split;
  		xsk_setup_xdp_prog;
  		xsk_socket__update_xskmap;
+                ring_buffer__epoll_fd;

Fyi, this had a whitespace issue, Andrii fixed it up while applying.

Quoted 20 lines
tools/lib/bpf/libbpf.map +0 -0
  } LIBBPF_0.2.0;
tools/lib/bpf/ringbuf.c +6 -0
index 5c6522c89af1..45a36648b403 100644
@@ -282,3 +282,9 @@ int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms)
  	}
  	return cnt < 0 ? -errno : res;
  }
+
+/* Get an fd that can be used to sleep until data is available in the ring(s) */
+int ring_buffer__epoll_fd(struct ring_buffer *rb)
+{
+	return rb->epoll_fd;
+}

base-commit: b4fe9fec51ef48011f11c2da4099f0b530449c92 --
2.29.2.576.ga3fc446d84-goog

#2 lore raw
Quoted 2 lines · Daniel Borkmann

On 12/14/20 12:38 PM, Brendan Jackman wrote:

[...]

Quoted 11 lines

tools/lib/bpf/libbpf.map LIBBPF_0.3.0 { · line 351

Quoted 9 lines
tools/lib/bpf/libbpf.map +1 -0
index 7c4126542e2b..7be850271be6 100644
@@ -348,4 +348,5 @@ LIBBPF_0.3.0 {
              btf__new_split;
              xsk_setup_xdp_prog;
              xsk_socket__update_xskmap;
+                ring_buffer__epoll_fd;

Fyi, this had a whitespace issue, Andrii fixed it up while applying.

Sorry about that.