-
Notifications
You must be signed in to change notification settings - Fork 194
Improve shm api #1950
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
base: main
Are you sure you want to change the base?
Improve shm api #1950
Conversation
- improved relation between owned and borrowed shm buffers - add alignment constants - default alignment now is 1 - fix bug in shm and session tests
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1950 +/- ##
=======================================
Coverage ? 70.84%
=======================================
Files ? 365
Lines ? 61664
Branches ? 0
=======================================
Hits ? 43684
Misses ? 17980
Partials ? 0 ☔ View full report in Codecov by Sentry. |
@@ -35,9 +38,19 @@ impl ShmBuf for ZShm { | |||
} | |||
} | |||
|
|||
impl OwnedShmBuf for ZShm { | |||
fn try_resize(&mut self, new_size: NonZeroUsize) -> Option<()> { |
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.
It's better to document its safety.
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.
done
} | ||
|
||
fn try_relayout(&mut self, new_layout: MemoryLayout) -> Result<(), BufferRelayoutError> { | ||
unsafe { self.0.try_relayout(new_layout) } |
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 document the safety.
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.
Done
Self(data) | ||
impl OwnedShmBuf for ZShmMut { | ||
fn try_resize(&mut self, new_size: NonZeroUsize) -> Option<()> { | ||
unsafe { self.0.try_resize(new_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.
Please document the safety.
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.
Done
fn eq(&self, other: &zshmmut) -> bool { | ||
self.0 == other.0 .0 | ||
fn try_relayout(&mut self, new_layout: MemoryLayout) -> Result<(), BufferRelayoutError> { | ||
unsafe { self.0.try_relayout(new_layout) } |
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 document the safety.
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.
Done
@@ -84,7 +84,7 @@ async fn open_session_multicast(endpoint01: &str, endpoint02: &str) -> (Session, | |||
.endpoints | |||
.set(vec![endpoint01.parse().unwrap()]) | |||
.unwrap(); | |||
config.scouting.multicast.set_enabled(Some(true)).unwrap(); | |||
config.scouting.multicast.set_enabled(Some(false)).unwrap(); |
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.
Is it relevant to this PR?
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.
No, this is small test bugfix - too small to deserve separate PR
zenoh/tests/shm.rs
Outdated
}); | ||
} | ||
|
||
#[test] |
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.
Minor suggestion. We can use tokio::test
macro as we do in other tests.
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.
Nice catch! Fixed
zenoh/tests/shm.rs
Outdated
}); | ||
} | ||
|
||
#[test] |
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.
Minor suggestion. We can use tokio::test
macro as we do in other tests.
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.
Nice catch! Fixed
zenoh/tests/shm.rs
Outdated
}); | ||
} | ||
|
||
#[test] |
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.
Minor suggestion. We can use tokio::test
macro as we do in other tests.
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.
Nice catch! Fixed
zenoh/tests/shm.rs
Outdated
}); | ||
} | ||
|
||
#[test] |
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.
Minor suggestion. We can use tokio::test
macro as we do in other tests.
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.
Nice catch! Fixed
|
||
const TIMEOUT: Duration = Duration::from_secs(60); | ||
const SLEEP: Duration = Duration::from_secs(1); | ||
|
||
const MSG_COUNT: usize = 1_00; | ||
const MSG_SIZE: [usize; 2] = [1_024, 100_000]; | ||
|
||
async fn open_session_unicast(endpoints: &[&str]) -> (Session, Session) { | ||
async fn open_session_unicast<const NO_SHM_FOR_SECOND_PEER: bool>( |
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.
Just out of curiosity. Is there any reason to use a const generic rather than a plain bool argument?
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.
Well, no reason, I just thought that this is more readable (nobody cares about endpoints list, but testing modes are more interesting)
Series of SHM API improvements:
try_resize
andtry_relayout
API to resize owned SHM bufferstr
andString
relation semantic)OwnedShmBuf
trait to aggregate API related to owned shm buffer typesALIGN_1_BYTE .. ALIGN_8_BYTES
to better express alignment in codeAlignment
is nowALIGN_1_BYTE
(fixes the issue with user not able to allocate arbitrary-sized buffers on default-initialized POSIX SHM provider)