-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix/modbuf-global-gc-bug
- Loading branch information
Showing
39 changed files
with
1,413 additions
and
276 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,3 +1,34 @@ | ||
use criterion::Criterion; | ||
|
||
pub mod alloc; | ||
pub mod internal_pointer; | ||
pub mod sft; | ||
|
||
// As we can only initialize one MMTk instance, we have to run each benchmark in a separate process. | ||
// So we only register one benchmark to criterion ('bench_main'), and based on the env var MMTK_BENCH, | ||
// we pick the right benchmark to run. | ||
|
||
// The benchmark can be executed with the following command. The feature `mock_test` is required, as the tests use MockVM. | ||
// MMTK_BENCH=alloc cargo bench --features mock_test | ||
// MMTK_BENCH=sft cargo bench --features mock_test | ||
|
||
// [Yi] I am not sure if these benchmarks are helpful any more after the MockVM refactoring. MockVM is really slow, as it | ||
// is accessed with a lock, and it dispatches every call to function pointers in a struct. These tests may use MockVM, | ||
// so they become slower as well. And the slowdown | ||
// from MockVM may hide the actual performance difference when we change the functions that are benchmarked. | ||
// We may want to improve the MockVM implementation so we can skip dispatching for benchmarking, or introduce another MockVM | ||
// implementation for benchmarking. | ||
// 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. | ||
|
||
pub fn bench(c: &mut Criterion) { | ||
match std::env::var("MMTK_BENCH") { | ||
Ok(bench) => match bench.as_str() { | ||
"alloc" => alloc::bench(c), | ||
"internal_pointer" => internal_pointer::bench(c), | ||
"sft" => sft::bench(c), | ||
_ => panic!("Unknown benchmark {:?}", bench), | ||
}, | ||
Err(_) => panic!("Need to name a benchmark by the env var MMTK_BENCH"), | ||
} | ||
} |
This file contains 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,87 @@ | ||
//! Benchmarks for scanning side metadata for non-zero bits. | ||
use criterion::Criterion; | ||
use mmtk::util::{ | ||
constants::LOG_BITS_IN_WORD, test_private::scan_non_zero_bits_in_metadata_bytes, Address, | ||
}; | ||
use rand::{seq::IteratorRandom, SeedableRng}; | ||
use rand_chacha::ChaCha8Rng; | ||
|
||
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 BLOCK_BYTES: usize = 32768usize; // Match an Immix block size. | ||
|
||
// Asssume one-bit-per-word metadata (matching VO bits). | ||
const BLOCK_META_BYTES: usize = BLOCK_BYTES >> LOG_BITS_IN_WORD; | ||
|
||
/// Set this many distinct bits in the bitmap. | ||
const NUM_OBJECTS: usize = 200; | ||
|
||
/// Get a deterministic seeded Rng. | ||
fn get_rng() -> ChaCha8Rng { | ||
// Create an Rng from a seed and an explicit Rng type. | ||
// Not secure at all, but completely deterministic and reproducible. | ||
// The following seed is read from /dev/random | ||
const SEED64: u64 = 0x4050cb1b5ab26c70; | ||
ChaCha8Rng::seed_from_u64(SEED64) | ||
} | ||
|
||
/// A bitmap, with known location of each bit for assertion. | ||
struct PreparedBitmap { | ||
start: Address, | ||
end: Address, | ||
set_bits: Vec<(Address, u8)>, | ||
} | ||
|
||
/// Make a bitmap of the desired size and set bits. | ||
fn make_standard_bitmap() -> PreparedBitmap { | ||
let start = allocate_aligned(BLOCK_META_BYTES); | ||
let end = start + BLOCK_META_BYTES; | ||
let mut rng = get_rng(); | ||
|
||
let mut set_bits = (0..(BLOCK_BYTES >> LOG_BITS_IN_WORD)) | ||
.choose_multiple(&mut rng, NUM_OBJECTS) | ||
.iter() | ||
.map(|total_bit_offset| { | ||
let word_offset = total_bit_offset >> LOG_BITS_IN_WORD; | ||
let bit_offset = total_bit_offset & ((1 << LOG_BITS_IN_WORD) - 1); | ||
(start + (word_offset << LOG_BITS_IN_WORD), bit_offset as u8) | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
set_bits.sort(); | ||
|
||
for (addr, bit) in set_bits.iter() { | ||
let word = unsafe { addr.load::<usize>() }; | ||
let new_word = word | (1 << bit); | ||
unsafe { addr.store::<usize>(new_word) }; | ||
} | ||
|
||
PreparedBitmap { | ||
start, | ||
end, | ||
set_bits, | ||
} | ||
} | ||
|
||
pub fn bench(c: &mut Criterion) { | ||
c.bench_function("bscan_block", |b| { | ||
let bitmap = make_standard_bitmap(); | ||
let mut holder: Vec<(Address, u8)> = Vec::with_capacity(NUM_OBJECTS); | ||
|
||
b.iter(|| { | ||
holder.clear(); | ||
scan_non_zero_bits_in_metadata_bytes(bitmap.start, bitmap.end, &mut |addr, shift| { | ||
holder.push((addr, shift)); | ||
}); | ||
}); | ||
|
||
assert_eq!(holder.len(), NUM_OBJECTS); | ||
assert_eq!(holder, bitmap.set_bits); | ||
}); | ||
} |
Oops, something went wrong.