linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: Expose libbpf ringbufer epoll_fd
@ 2020-12-11 17:24 Brendan Jackman
  2020-12-11 19:44 ` Andrii Nakryiko
  0 siblings, 1 reply; 3+ messages in thread
From: Brendan Jackman @ 2020-12-11 17:24 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, KP Singh, Florent Revest,
	linux-kernel, Brendan Jackman

This allows the user to do their own manual polling in more
complicated setups.

Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
 tools/lib/bpf/libbpf.h  | 1 +
 tools/lib/bpf/ringbuf.c | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 6909ee81113a..cde07f64771e 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -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;
diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c
index 5c6522c89af1..45a36648b403 100644
--- a/tools/lib/bpf/ringbuf.c
+++ b/tools/lib/bpf/ringbuf.c
@@ -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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] libbpf: Expose libbpf ringbufer epoll_fd
  2020-12-11 17:24 [PATCH bpf-next] libbpf: Expose libbpf ringbufer epoll_fd Brendan Jackman
@ 2020-12-11 19:44 ` Andrii Nakryiko
  2020-12-14 11:29   ` Brendan Jackman
  0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2020-12-11 19:44 UTC (permalink / raw)
  To: Brendan Jackman
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, KP Singh,
	Florent Revest, open list

On Fri, Dec 11, 2020 at 10:58 AM Brendan Jackman <jackmanb@google.com> wrote:
>
> This allows the user to do their own manual polling in more
> complicated setups.
>
> Signed-off-by: Brendan Jackman <jackmanb@google.com>
> ---

perf_buffer has it, so it's good for consistency. In practice, though,
I'd expect anyone who needs more complicated polling to use ring buf's
map FD directly on their instance of epoll. Doesn't that work for you?

Regardless, though, you need to add the API into libbpf.map file first.


>  tools/lib/bpf/libbpf.h  | 1 +
>  tools/lib/bpf/ringbuf.c | 6 ++++++
>  2 files changed, 7 insertions(+)
>
> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> index 6909ee81113a..cde07f64771e 100644
> --- a/tools/lib/bpf/libbpf.h
> +++ b/tools/lib/bpf/libbpf.h
> @@ -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;
> diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c
> index 5c6522c89af1..45a36648b403 100644
> --- a/tools/lib/bpf/ringbuf.c
> +++ b/tools/lib/bpf/ringbuf.c
> @@ -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
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] libbpf: Expose libbpf ringbufer epoll_fd
  2020-12-11 19:44 ` Andrii Nakryiko
@ 2020-12-14 11:29   ` Brendan Jackman
  0 siblings, 0 replies; 3+ messages in thread
From: Brendan Jackman @ 2020-12-14 11:29 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, KP Singh,
	Florent Revest, open list

On Fri, Dec 11, 2020 at 11:44:41AM -0800, Andrii Nakryiko wrote:
> On Fri, Dec 11, 2020 at 10:58 AM Brendan Jackman <jackmanb@google.com> wrote:
> >
> > This allows the user to do their own manual polling in more
> > complicated setups.
> >
> > Signed-off-by: Brendan Jackman <jackmanb@google.com>
> > ---
> 
> perf_buffer has it, so it's good for consistency. In practice, though,
> I'd expect anyone who needs more complicated polling to use ring buf's
> map FD directly on their instance of epoll. Doesn't that work for you?

Yep, thanks - on closer inspection I think that would be a better
eventual solution.  However this API provides a convenient migration
path. I suspect it's a similar situation to what motivated
perf_buffer__epoll_fd in commit dca5612f8eb9d.

> Regardless, though, you need to add the API into libbpf.map file first.

Ack, will send a v2. I guess this falls into Linus description of 'happy
sending it in this upcoming week' for the 5.10 window so I'll put it in
libbpf 0.3.0.

> >  tools/lib/bpf/libbpf.h  | 1 +
> >  tools/lib/bpf/ringbuf.c | 6 ++++++
> >  2 files changed, 7 insertions(+)
> >
> > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> > index 6909ee81113a..cde07f64771e 100644
> > --- a/tools/lib/bpf/libbpf.h
> > +++ b/tools/lib/bpf/libbpf.h
> > @@ -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;
> > diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c
> > index 5c6522c89af1..45a36648b403 100644
> > --- a/tools/lib/bpf/ringbuf.c
> > +++ b/tools/lib/bpf/ringbuf.c
> > @@ -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
> >

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-14 11:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-11 17:24 [PATCH bpf-next] libbpf: Expose libbpf ringbufer epoll_fd Brendan Jackman
2020-12-11 19:44 ` Andrii Nakryiko
2020-12-14 11:29   ` Brendan Jackman

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).