Skip to content

RingBuffer: Introduce consume_raw_n() #1173

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
May 21, 2025
Merged

Conversation

arighi
Copy link
Contributor

@arighi arighi commented May 21, 2025

libbpf provides the ring_buffer__consume_n() API to consume up to a certain amount of items from ringbuffers [1].

Add the new method consume_raw_n() also in RingBuffer to provide the same functionality.

This is needed by sched_ext to allow user-space schedulers (based on scx_rustland_core) to selectively consume task items from BPF ring buffer [2].

[1] https://lore.kernel.org/bpf/20240406092005.92399-1-andrea.righi@canonical.com/
[2] https://github.com/sched-ext/scx/blob/ea361886f714b968092a1ea14bdee8330beb4d5f/rust/scx_rustland_core/assets/bpf.rs#L228

Copy link
Collaborator

@d-e-s-o d-e-s-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good to me, thanks. Left one question/suggestion.

Comment on lines +994 to +997
// Consume exactly one item
let ret = mgr.consume_raw_n(1);
assert!(ret == 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add a test making sure that with two events (or more) events available we also consume & report two? 1 really could mean so many things, so I'd think there is some value add.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, I'll add a test for this case as well, thanks.

@arighi
Copy link
Contributor Author

arighi commented May 21, 2025

Updated the consume_raw_n() selftest to cover more cases.

libbpf provides the ring_buffer__consume_n() API to consume up to a
certain amount of items from ringbuffers [1].

Add the new method consume_raw_n() also in RingBuffer to provide the
same functionality.

This is needed by sched_ext to allow user-space schedulers (based on
scx_rustland_core) to selectively consume task items from BPF ring
buffer [2].

[1] https://lore.kernel.org/bpf/20240406092005.92399-1-andrea.righi@canonical.com/
[2] https://github.com/sched-ext/scx/blob/ea361886f714b968092a1ea14bdee8330beb4d5f/rust/scx_rustland_core/assets/bpf.rs#L228

Signed-off-by: Andrea Righi <arighi@nvidia.com>
@d-e-s-o d-e-s-o merged commit 94b7b11 into libbpf:master May 21, 2025
14 checks passed
@d-e-s-o
Copy link
Collaborator

d-e-s-o commented May 21, 2025

Thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants