-
Notifications
You must be signed in to change notification settings - Fork 78
Refactor iterate_meta_bits #1181
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
Changes from 12 commits
a837987
acaf942
f4a08b3
a51cdc4
b1486e3
ab28a79
e2bafd5
c3c3dfa
a73061c
d994f6e
323d39e
95cd6df
be28f28
6994e09
6a9320b
74cf0d8
4f71855
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| //! Benchmarks for bulk zeroing and setting. | ||
|
|
||
| use std::os::raw::c_void; | ||
|
|
||
| use criterion::Criterion; | ||
| use mmtk::util::{constants::LOG_BITS_IN_WORD, metadata::side_metadata::SideMetadataSpec, Address}; | ||
|
|
||
| fn allocate_aligned(size: usize) -> Address { | ||
| let ptr = unsafe { | ||
| std::alloc::alloc_zeroed(std::alloc::Layout::from_size_align(size, size).unwrap()) | ||
| }; | ||
| Address::from_mut_ptr(ptr) | ||
| } | ||
|
|
||
| const LINE_BYTES: usize = 256usize; // Match an Immix line size. | ||
| const BLOCK_BYTES: usize = 32768usize; // Match an Immix block size. | ||
|
|
||
| // Asssume one-bit-per-word metadata (matching VO bits). | ||
| const LINE_META_BYTES: usize = LINE_BYTES >> LOG_BITS_IN_WORD; | ||
| const BLOCK_META_BYTES: usize = BLOCK_BYTES >> LOG_BITS_IN_WORD; | ||
|
|
||
| pub fn bench(c: &mut Criterion) { | ||
| c.bench_function("bzero_bset_line", |b| { | ||
| let start = allocate_aligned(LINE_META_BYTES); | ||
| let end = start + LINE_META_BYTES; | ||
|
|
||
| b.iter(|| { | ||
| SideMetadataSpec::bench_set_meta_bits(start, 0, end, 0); | ||
| SideMetadataSpec::bench_zero_meta_bits(start, 0, end, 0); | ||
| }) | ||
| }); | ||
|
|
||
| c.bench_function("bzero_bset_line_memset", |b| { | ||
| let start = allocate_aligned(LINE_META_BYTES); | ||
| let end = start + LINE_META_BYTES; | ||
|
|
||
| b.iter(|| unsafe { | ||
| libc::memset(start.as_mut_ref() as *mut c_void, 0xff, end - start); | ||
| libc::memset(start.as_mut_ref() as *mut c_void, 0x00, end - start); | ||
| }) | ||
| }); | ||
|
|
||
| c.bench_function("bzero_bset_block", |b| { | ||
| let start = allocate_aligned(BLOCK_META_BYTES); | ||
| let end = start + BLOCK_META_BYTES; | ||
|
|
||
| b.iter(|| { | ||
| SideMetadataSpec::bench_set_meta_bits(start, 0, end, 0); | ||
| SideMetadataSpec::bench_zero_meta_bits(start, 0, end, 0); | ||
| }) | ||
| }); | ||
|
|
||
| c.bench_function("bzero_bset_block_memset", |b| { | ||
| let start = allocate_aligned(BLOCK_META_BYTES); | ||
| let end = start + BLOCK_META_BYTES; | ||
|
|
||
| b.iter(|| unsafe { | ||
| libc::memset(start.as_mut_ref() as *mut c_void, 0xff, end - start); | ||
| libc::memset(start.as_mut_ref() as *mut c_void, 0x00, end - start); | ||
| }) | ||
| }); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pub mod bzero_bset; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,11 +19,14 @@ use criterion::Criterion; | |
| // However, I will just keep these benchmarks here. If we find it not useful, and we do not plan to improve MockVM, we can delete | ||
| // them. | ||
|
|
||
| #[cfg(feature = "bench")] | ||
| mod bulk_meta; | ||
|
|
||
| #[cfg(feature = "mock_test")] | ||
| mod mock_bench; | ||
|
|
||
| pub fn bench_main(_c: &mut Criterion) { | ||
| #[cfg(feature = "mock_test")] | ||
| #[cfg(feature = "mock_test")] | ||
| pub fn bench_mock(_c: &mut Criterion) { | ||
| match std::env::var("MMTK_BENCH") { | ||
| Ok(bench) => match bench.as_str() { | ||
| "alloc" => mock_bench::alloc::bench(_c), | ||
|
|
@@ -33,12 +36,17 @@ pub fn bench_main(_c: &mut Criterion) { | |
| }, | ||
| Err(_) => panic!("Need to name a benchmark by the env var MMTK_BENCH"), | ||
| } | ||
| } | ||
|
|
||
| #[cfg(not(feature = "mock_test"))] | ||
| { | ||
| eprintln!("ERROR: Currently there are no benchmarks when the \"mock_test\" feature is not enabled."); | ||
| std::process::exit(1); | ||
| } | ||
| pub fn bench_main(_c: &mut Criterion) { | ||
| // If the "mock_test" feature is enabled, we only run mock test. | ||
| #[cfg(feature = "mock_test")] | ||
| return bench_mock(_c); | ||
|
|
||
| // Some benchmarks rely on the "bench" feature to expose some private functions. | ||
| // Run them with `cargo bench --features bench`. | ||
| #[cfg(feature = "bench")] | ||
| bulk_meta::bzero_bset::bench(_c); | ||
|
||
| } | ||
|
|
||
| criterion_group!(benches, bench_main); | ||
|
|
||
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 suggest renaming this to something like
test_privateortest_private_items. This would be clear for both the function definitions in mmtk-core, and for the bench/test modules outside mmtk-core.I found the following code confusing: we are in the bench crate, why do we have the
benchfeature for some tests but not other tests? A better feature name would make it more clear.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 is also posssible to have
mock_test = ["test_private_item"]. In that case, you don't have to changebench_mainand you can simply add your benchmark.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 am OK with renaming it to
test_private.The reason for not requiring the "bench" feature for some test cases is because the current mock tests don't require any of the items exposed from the "bench" feature. But it will probably make things clearer to unconditionally require the "bench" or "test_private" feature when doing benchmarks.