mbox series

[v4,0/4] libbpf: API to partially consume items from ringbuffer

Message ID 20240406092005.92399-1-andrea.righi@canonical.com (mailing list archive)
Headers show
Series libbpf: API to partially consume items from ringbuffer | expand

Message

Andrea Righi April 6, 2024, 9:15 a.m. UTC
Introduce ring__consume_n() and ring_buffer__consume_n() API to
partially consume items from one (or more) ringbuffer(s).

This can be useful, for example, to consume just a single item or when
we need to copy multiple items to a limited user-space buffer from the
ringbuffer callback.

Practical example (where this API can be used):
https://github.com/sched-ext/scx/blob/b7c06b9ed9f72cad83c31e39e9c4e2cfd8683a55/rust/scx_rustland_core/src/bpf.rs#L217

See also:
https://lore.kernel.org/lkml/20240310154726.734289-1-andrea.righi@canonical.com/T/#u

v4:
 - add a selftest to test the new API
 - open a new 1.5.0 cycle

v3:
 - rename ring__consume_max() -> ring__consume_n() and
   ring_buffer__consume_max() -> ring_buffer__consume_n()
 - add new API to a new 1.5.0 cycle
 - fixed minor nits / comments

v2:
 - introduce a new API instead of changing the callback's retcode
   behavior

Andrea Righi (4):
      libbpf: Start v1.5 development cycle
      libbpf: ringbuf: allow to consume up to a certain amount of items
      libbpf: Add ring__consume_n / ring_buffer__consume_n
      selftests/bpf: Add tests for ring__consume_n and ring_buffer__consume_n

 tools/lib/bpf/libbpf.h                           | 12 +++++
 tools/lib/bpf/libbpf.map                         |  6 +++
 tools/lib/bpf/libbpf_version.h                   |  2 +-
 tools/lib/bpf/ringbuf.c                          | 59 ++++++++++++++++++++----
 tools/testing/selftests/bpf/prog_tests/ringbuf.c |  8 ++++
 5 files changed, 76 insertions(+), 11 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org April 6, 2024, 5:50 p.m. UTC | #1
Hello:

This series was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Sat,  6 Apr 2024 11:15:40 +0200 you wrote:
> Introduce ring__consume_n() and ring_buffer__consume_n() API to
> partially consume items from one (or more) ringbuffer(s).
> 
> This can be useful, for example, to consume just a single item or when
> we need to copy multiple items to a limited user-space buffer from the
> ringbuffer callback.
> 
> [...]

Here is the summary with links:
  - [v4,1/4] libbpf: Start v1.5 development cycle
    https://git.kernel.org/bpf/bpf-next/c/5bd2ed658231
  - [v4,2/4] libbpf: ringbuf: allow to consume up to a certain amount of items
    https://git.kernel.org/bpf/bpf-next/c/13e8125a2276
  - [v4,3/4] libbpf: Add ring__consume_n / ring_buffer__consume_n
    https://git.kernel.org/bpf/bpf-next/c/4d22ea94ea33
  - [v4,4/4] selftests/bpf: Add tests for ring__consume_n and ring_buffer__consume_n
    (no matching commit)

You are awesome, thank you!