-
Notifications
You must be signed in to change notification settings - Fork 651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BPF ring buffer #318
BPF ring buffer #318
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding sharing code: seems like the epoll stuff is very similar. Maybe pull that into it's own abstraction in internal
? It would:
- Take a list of fds and event values to wait for
- Have a function Wait() or similar that handles turning events into event values
- Have a function Close() that handles interruption
For the ringbuf code: is there documentation somewhere? What are the BUSY and DISCARD bits used for? How do we account for dropped events from the buffer (I assume those are also a thing)?
I added the kernel doc URL in the commit message. Also, I've found this blog post very useful: https://nakryiko.com/posts/bpf-ringbuf/ . The latter also talks about the dropped/lost samples case. |
That was helpful, thanks!
This doesn't specify what should happen in case of the busy bit being set. Can user space actually encounter that? Currently the consumer returns an error (?), should it retry instead? More random thoughts:
|
AFAICS
|
I personally wouldn't add tests for creating ringbuf maps with weird sizes: they just assert kernel behaviour which may change in the future (the uapi isn't as immutable as we like to think!). Instead I'd duplicate the power of two check to the start of NewReader. More robust and less code. Up to you. |
@mythi Would you be up for splitting up the two first commits into a separate PR? IMO that part is good to go, doesn't need to be blocked on the epoll stuff. |
FYI, I've improved things and rebased to master. Keeping it draft still until I finish all the unit tests.
+1
With BPF ringbuf, there's no per CPU buffers.
Good question. It should be easy to add (by reusing the perCPU infra
In the latest version, I added pollTimeout as the Reader parameter to support busyloop reads and blocking read.
Yes, implemented.
Can we rely on the verifier to check the ringbuf map has the correct size? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your continued work on this!
I'd like to look at the tests in a future round, this is all I have for now. Would also like for this to be a little more polished before it goes in (or we might hold off until after 0.7), but looks solid overall. 👍
@ti-mo thanks for the great comments! I agree with them. This work is closely based on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took another look as well. Have you considered #318 (review) ?
There is a lot of similar-but-not-quite the same code here, which is a great recipe for bugs. If possible I'd like to share code that actually is similar/
68a1776
to
1793dc5
Compare
@lmb Yes, but getting some of the code shared between |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small comments, I think this is in a good shape. Doing the epoll changes later is ok.
5157592
to
f9fe205
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some nits, and would like some clarification around the use of atomics in ringbuf
.
6122b08
to
ac00f6b
Compare
@ti-mo I took another quick look, and all seems well. I'll merge this end of today if you want to do another pass. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thank you!
Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
Linux 5.8 added support for BPF ring buffer that addresses some limitations with perf events when delivering variable size records from BPF programs to user space [1]. Similar to and based on the 'perf' package, 'ringbuf' package implements an io.Reader to read such records submitted by bpf_ringbuf_output()/ bpf_ringbuf_submit(). [1] https://www.kernel.org/doc/html/latest/bpf/ringbuf.html Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
Fixes: #316