Skip to content
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

feat(s2n-quic-core): add buffer::Deque implemention #2207

Merged
merged 3 commits into from May 14, 2024

Conversation

camshaft
Copy link
Contributor

@camshaft camshaft commented May 10, 2024

Description of changes:

This adds a byte ring buffer for efficient vectored reads/writes between socket syscalls.

Testing:

I've added several bolero harnesses for checking the correctness of the implementation.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@camshaft camshaft marked this pull request as ready for review May 10, 2024 02:57
impl Deque {
#[inline]
pub fn new(mut cap: usize) -> Self {
if !cap.is_power_of_two() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

No real need for a conditional -- "Returns the smallest power of two greater than or equal to self." is the documentation for next_power_of_two, so it's a no-op if you're already a power of two.

quic/s2n-quic-core/src/buffer/deque.rs Show resolved Hide resolved
Comment on lines +166 to +167
send: Data::new(usize::MAX as _),
recv: Data::new(usize::MAX as _),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the customization vs. Data::default()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Default should work, yeah

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right. The Default implementation for Data is set to 1024 bytes and I wanted an endless stream in this case.

impl Default for Model {
fn default() -> Self {
Self {
buffer: Deque::new(u16::MAX as _),
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 be testing a smaller Deque? That way we're more likely to notice problems around the edges, right? (And tests should be faster).

Not sure if we're running this through kani though, in which case maybe it matters less. Ideally there we'd do a kani::any() or something here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's probably a good call. I guess the size doesn't matter too much as long as we're exercising the corner cases. Let me try and get the Kani harness working as well.

let oracle = {
let (head, tail) = self.oracle.as_slices();
head.iter().chain(tail)
};
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 check that we also match the head/tail lengths? Or do we expect our impl to differ there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't want to over index on the impls strictly matching so I decided against that.

std::io::IoSlice::new(&[]),
split_at,
|chunk: &[u8]| unsafe {
// SAFETY: we're using transmute to extend the lifetime of the chunk to `self`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// SAFETY: we're using transmute to extend the lifetime of the chunk to `self`
// SAFETY: we're using transmute to extend the lifetime of the chunk to `self`
// Upstream tracking: https://github.com/rust-lang/rust/issues/124659

@camshaft camshaft merged commit 30ef24c into main May 14, 2024
127 of 128 checks passed
@camshaft camshaft deleted the camshaft/buffer-deque branch May 14, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants