-
Notifications
You must be signed in to change notification settings - Fork 228
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
Design proposal for new ring buffer API #3848
base: main
Are you sure you want to change the base?
Conversation
Converting to draft while I make a few design updates. |
* @returns Pointer to ring buffer manager. | ||
*/ | ||
struct ring_buffer * | ||
ring_buffer__new(int map_fd, ring_buffer_sample_fn sample_cb, void *ctx, |
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.
How do we differentiate between callback vs poll?
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.
Updated the design so callback consumers now use the libbpf ring buffer manager, and direct mapped memory consumers use the new functions.
docs/RingBuffer.md
Outdated
// … log error … | ||
break; | ||
} | ||
have_data = *prod_offset > *cons_offset; // It's possible we still have data. |
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.
You need a ReadAcquire here (or an explicit memory barrier). With out that, you can potentially read the record before its been written to by the producer. Likewise you will need a WriteRelease in the producer.
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.
Also, reading it multiple times like this is going to cause issues. It should read prod_offset once using ReadAcquire and then use the value.
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.
Now uses ReadAcquire64/WriteRelease64 for access to the producer and consumer offset.
I went with bit fields for the record header for simpler example code, so that part is already pseudocode and I didn't add the ReadAcquire needed to read the header, but added a comment in the struct.
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.
Please fix the sample code. Its broken as it will not work correctly on weakly ordered systems (ARM64 as an example).
Splits the design so callback consumers use the existing libbpf APIs, and mapped memory consumers use the new windows-specific functions.
docs/RingBuffer.md
Outdated
|
||
// Update consumer offset (and pad record length to multiple of 8). | ||
consumer_offset += sizeof(rb_header_t) + (record->length + 7 & ~7); | ||
WriteRelease64(cons_offset, consumer_offset); |
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.
WriteNoFence64
Description
Add docs/RingBuffer.md with proposal for new ebpf ring buffer map API exposing mapped memory so consumers can directly read the records written by the producer (similar to linux mmap/epoll style ring buffer consumer).
Testing
N/A
Documentation
Documentation only.
Installation
N/A