-
Notifications
You must be signed in to change notification settings - Fork 119
Rust: Update build features #804
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5d45a29
build(snmalloc-sys): sync features with upstream and fix build-system…
ryancinsight f964b52
fix(build): define NDEBUG for release builds in build_cc to resolve p…
ryancinsight 17fb51e
fix(build): define SNMALLOC_HAS_LINUX_FUTEX_H for build_cc on Linux
ryancinsight 7677b99
fix(build): revert NDEBUG change and restrict Futex definitions to bu…
ryancinsight c16c5cb
fix(build): define _WIN32_WINNT for consistent Windows targeting
ryancinsight dbe0cd1
fix(cargo): enable usewait-on-address by default
ryancinsight c8d14ae
feat(xtask): add benchmark comparison tool for build backends
ryancinsight 6baa454
fix(build): pass Windows versions as compiler defines for cmake
ryancinsight df4293f
refactor(snmalloc-sys): improve build configuration logic
ryancinsight c59be91
build: respect cargo debug and optimization levels
ryancinsight d36dfe5
docs: update README and Cargo.toml for build alignment and new features
ryancinsight 551d6a6
Handle relocation
mjp41 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| use std::sync::mpsc::channel; | ||
| use std::thread; | ||
| use std::time::Instant; | ||
| use std::alloc::Layout; | ||
|
|
||
| #[global_allocator] | ||
| static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc; | ||
|
|
||
| const BLOCK_SIZE: usize = 64; | ||
| const ITERATIONS: usize = 1_000_000; | ||
|
|
||
| struct Ptr(*mut u8); | ||
| unsafe impl Send for Ptr {} | ||
|
|
||
| fn main() { | ||
| let thread_count = std::thread::available_parallelism().map(|n| n.get()).unwrap_or(4); | ||
| println!("Running contention benchmark with {} threads, {} iterations per thread", thread_count, ITERATIONS); | ||
|
|
||
| // Use std::sync::Barrier | ||
| let barrier = std::sync::Arc::new(std::sync::Barrier::new(thread_count + 1)); | ||
|
|
||
| let mut senders = Vec::new(); | ||
| let mut receivers = Vec::new(); | ||
|
|
||
| // Create a ring topology channels | ||
| for _ in 0..thread_count { | ||
| let (tx, rx) = channel::<Ptr>(); | ||
| senders.push(tx); | ||
| receivers.push(Some(rx)); | ||
| } | ||
|
|
||
| let mut handles = Vec::new(); | ||
|
|
||
| // Start timing from here, but actual work starts after barrier | ||
| let _start = Instant::now(); | ||
|
|
||
| for i in 0..thread_count { | ||
| let barrier = barrier.clone(); | ||
| // Thread i sends to (i + 1) % N | ||
| let tx = senders[(i + 1) % thread_count].clone(); | ||
| // Thread i receives from i | ||
| let rx = receivers[i].take().unwrap(); | ||
|
|
||
| handles.push(thread::spawn(move || { | ||
| // Pre-allocate some items to fill the pipe | ||
| let layout = Layout::from_size_align(BLOCK_SIZE, 8).unwrap(); | ||
|
|
||
| barrier.wait(); // Synchronize start | ||
|
|
||
| for _ in 0..ITERATIONS { | ||
| // 1. Allocate a new block | ||
| let ptr = unsafe { std::alloc::alloc(layout) }; | ||
|
|
||
| // 2. Send to next neighbor (who will free it) | ||
| tx.send(Ptr(ptr)).unwrap(); | ||
|
|
||
| // 3. Receive from prev neighbor (who allocated it) | ||
| let received = rx.recv().unwrap(); | ||
|
|
||
| // 4. Free the received block | ||
| unsafe { std::alloc::dealloc(received.0, layout) }; | ||
| } | ||
| })); | ||
| } | ||
|
|
||
| barrier.wait(); // Start timing | ||
| let loop_start = Instant::now(); | ||
|
|
||
| for h in handles { | ||
| h.join().unwrap(); | ||
| } | ||
|
|
||
| let duration = loop_start.elapsed(); | ||
| println!("Benchmark completed in {:.2?}", duration); | ||
| println!("Throughput: {:.2} Mops/sec", (thread_count * ITERATIONS) as f64 / duration.as_secs_f64() / 1_000_000.0); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@SchrodingerZhu did you have a reason to separate snmalloc debug from rust compile, I modified this yesterday base on @mjp41 feedback but seeing this flag in readme is making me question if you had a reason
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.
At that time letting
cmake-rsdecide debug build was not that prevalent. I agree it is more preferable to have a unified debug build now.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'm happy to simplify the options. As we're about to release with a big version number change, Now is a good time to put a breaking change in.
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'm happy to simplify the options. As we're about to release with a big version number change, Now is a good time to put a breaking change in.
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 propose we take this as is, and then if someone could simplify the options in a subsequent PR that would be great.