Regroup options into a single parameters
This commit is contained in:
parent
0e0d5606bd
commit
1d146fe544
@ -1,7 +1,7 @@
|
|||||||
use cache_utils::calibration::{
|
use cache_utils::calibration::{
|
||||||
calibrate_fixed_freq_2_thread, flush_and_reload, load_and_flush, only_flush, only_reload,
|
calibrate_fixed_freq_2_thread, flush_and_reload, load_and_flush, only_flush, only_reload,
|
||||||
reload_and_flush, CalibrateOperation2T, HistParams, Verbosity, CFLUSH_BUCKET_NUMBER,
|
reload_and_flush, CalibrateOperation2T, CalibrationOptions, HistParams, Verbosity,
|
||||||
CFLUSH_BUCKET_SIZE, CFLUSH_NUM_ITER,
|
CFLUSH_BUCKET_NUMBER, CFLUSH_BUCKET_SIZE, CFLUSH_NUM_ITER,
|
||||||
};
|
};
|
||||||
use cache_utils::mmap::MMappedMemory;
|
use cache_utils::mmap::MMappedMemory;
|
||||||
use cache_utils::{flush, maccess, noop};
|
use cache_utils::{flush, maccess, noop};
|
||||||
@ -122,12 +122,15 @@ fn main() {
|
|||||||
display_name: "reload local hit",
|
display_name: "reload local hit",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
HistParams {
|
CalibrationOptions {
|
||||||
|
hist_params: HistParams {
|
||||||
bucket_number: CFLUSH_BUCKET_NUMBER,
|
bucket_number: CFLUSH_BUCKET_NUMBER,
|
||||||
bucket_size: CFLUSH_BUCKET_SIZE,
|
bucket_size: CFLUSH_BUCKET_SIZE,
|
||||||
iterations: CFLUSH_NUM_ITER,
|
iterations: CFLUSH_NUM_ITER,
|
||||||
},
|
},
|
||||||
verbose_level,
|
verbosity: verbose_level,
|
||||||
|
optimised_addresses: true,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,22 @@ pub struct HistParams {
|
|||||||
pub bucket_number: usize,
|
pub bucket_number: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct CalibrationOptions {
|
||||||
|
pub hist_params: HistParams,
|
||||||
|
pub verbosity: Verbosity,
|
||||||
|
pub optimised_addresses: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CalibrationOptions {
|
||||||
|
pub fn new(hist_params: HistParams, verbosity: Verbosity) -> CalibrationOptions {
|
||||||
|
CalibrationOptions {
|
||||||
|
hist_params,
|
||||||
|
verbosity,
|
||||||
|
optimised_addresses: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub unsafe fn only_reload(p: *const u8) -> u64 {
|
pub unsafe fn only_reload(p: *const u8) -> u64 {
|
||||||
let t = rdtsc_fence();
|
let t = rdtsc_fence();
|
||||||
maccess(p);
|
maccess(p);
|
||||||
@ -480,20 +496,14 @@ pub unsafe fn calibrate_fixed_freq_2_thread<I: Iterator<Item = (usize, usize)>>(
|
|||||||
len: isize,
|
len: isize,
|
||||||
cores: &mut I,
|
cores: &mut I,
|
||||||
operations: &[CalibrateOperation2T],
|
operations: &[CalibrateOperation2T],
|
||||||
hist_params: HistParams,
|
options: CalibrationOptions,
|
||||||
verbosity_level: Verbosity,
|
|
||||||
) -> Vec<CalibrateResult2T> {
|
) -> Vec<CalibrateResult2T> {
|
||||||
calibrate_fixed_freq_2_thread_impl(
|
calibrate_fixed_freq_2_thread_impl(p, increment, len, cores, operations, options)
|
||||||
p,
|
|
||||||
increment,
|
|
||||||
len,
|
|
||||||
cores,
|
|
||||||
operations,
|
|
||||||
hist_params,
|
|
||||||
verbosity_level,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO : Add the optimised address support
|
||||||
|
// TODO : Modularisation / factorisation of some of the common code with the single threaded no_std version ?
|
||||||
|
|
||||||
#[cfg(feature = "use_std")]
|
#[cfg(feature = "use_std")]
|
||||||
fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>>(
|
fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>>(
|
||||||
p: *const u8,
|
p: *const u8,
|
||||||
@ -501,10 +511,9 @@ fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>>(
|
|||||||
len: isize,
|
len: isize,
|
||||||
cores: &mut I,
|
cores: &mut I,
|
||||||
operations: &[CalibrateOperation2T],
|
operations: &[CalibrateOperation2T],
|
||||||
hist_params: HistParams,
|
options: CalibrationOptions,
|
||||||
verbosity_level: Verbosity,
|
|
||||||
) -> Vec<CalibrateResult2T> {
|
) -> Vec<CalibrateResult2T> {
|
||||||
if verbosity_level >= Thresholds {
|
if options.verbosity >= Thresholds {
|
||||||
println!(
|
println!(
|
||||||
"Calibrating {}...",
|
"Calibrating {}...",
|
||||||
operations
|
operations
|
||||||
@ -514,8 +523,8 @@ fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>>(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let to_bucket = |time: u64| -> usize { time as usize / hist_params.bucket_size };
|
let to_bucket = |time: u64| -> usize { time as usize / options.hist_params.bucket_size };
|
||||||
let from_bucket = |bucket: usize| -> u64 { (bucket * hist_params.bucket_size) as u64 };
|
let from_bucket = |bucket: usize| -> u64 { (bucket * options.hist_params.bucket_size) as u64 };
|
||||||
|
|
||||||
let slicing = if let Some(uarch) = MicroArchitecture::get_micro_architecture() {
|
let slicing = if let Some(uarch) = MicroArchitecture::get_micro_architecture() {
|
||||||
if let Some(vendor_family_model_stepping) = MicroArchitecture::get_family_model_stepping() {
|
if let Some(vendor_family_model_stepping) = MicroArchitecture::get_family_model_stepping() {
|
||||||
@ -552,7 +561,7 @@ fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>>(
|
|||||||
address: AtomicPtr::new(null_mut()),
|
address: AtomicPtr::new(null_mut()),
|
||||||
});
|
});
|
||||||
|
|
||||||
if verbosity_level >= Thresholds {
|
if options.verbosity >= Thresholds {
|
||||||
print!("CSV: main_core, helper_core, address, ");
|
print!("CSV: main_core, helper_core, address, ");
|
||||||
if h.is_some() {
|
if h.is_some() {
|
||||||
print!("hash, ");
|
print!("hash, ");
|
||||||
@ -574,7 +583,7 @@ fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>>(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if verbosity_level >= RawResult {
|
if options.verbosity >= RawResult {
|
||||||
print!("RESULT:main_core,helper_core,address,");
|
print!("RESULT:main_core,helper_core,address,");
|
||||||
if h.is_some() {
|
if h.is_some() {
|
||||||
print!("hash,");
|
print!("hash,");
|
||||||
@ -593,7 +602,7 @@ fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>>(
|
|||||||
for (main_core, helper_core) in cores {
|
for (main_core, helper_core) in cores {
|
||||||
// set main thread affinity
|
// set main thread affinity
|
||||||
|
|
||||||
if verbosity_level >= Thresholds {
|
if options.verbosity >= Thresholds {
|
||||||
println!(
|
println!(
|
||||||
"Calibration for main_core {}, helper {}.",
|
"Calibration for main_core {}, helper {}.",
|
||||||
main_core, helper_core
|
main_core, helper_core
|
||||||
@ -653,7 +662,7 @@ fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>>(
|
|||||||
|
|
||||||
let hash = h.map(|h| h(pointer as usize));
|
let hash = h.map(|h| h(pointer as usize));
|
||||||
|
|
||||||
if verbosity_level >= Thresholds {
|
if options.verbosity >= Thresholds {
|
||||||
print!("Calibration for {:p}", pointer);
|
print!("Calibration for {:p}", pointer);
|
||||||
if let Some(h) = hash {
|
if let Some(h) = hash {
|
||||||
print!(" (hash: {:x})", h)
|
print!(" (hash: {:x})", h)
|
||||||
@ -674,34 +683,34 @@ fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>>(
|
|||||||
if helper_core != main_core {
|
if helper_core != main_core {
|
||||||
for op in operations {
|
for op in operations {
|
||||||
helper_thread_params.op.store(op.prepare, Ordering::Relaxed);
|
helper_thread_params.op.store(op.prepare, Ordering::Relaxed);
|
||||||
let mut hist = vec![0; hist_params.bucket_number];
|
let mut hist = vec![0; options.hist_params.bucket_number];
|
||||||
for _ in 0..hist_params.iterations {
|
for _ in 0..options.hist_params.iterations {
|
||||||
next(&helper_thread_params.turn);
|
next(&helper_thread_params.turn);
|
||||||
wait(&helper_thread_params.turn, false);
|
wait(&helper_thread_params.turn, false);
|
||||||
let _time = unsafe { (op.op)(pointer) };
|
let _time = unsafe { (op.op)(pointer) };
|
||||||
}
|
}
|
||||||
for _ in 0..hist_params.iterations {
|
for _ in 0..options.hist_params.iterations {
|
||||||
next(&helper_thread_params.turn);
|
next(&helper_thread_params.turn);
|
||||||
wait(&helper_thread_params.turn, false);
|
wait(&helper_thread_params.turn, false);
|
||||||
let time = unsafe { (op.op)(pointer) };
|
let time = unsafe { (op.op)(pointer) };
|
||||||
let bucket = min(hist_params.bucket_number - 1, to_bucket(time));
|
let bucket = min(options.hist_params.bucket_number - 1, to_bucket(time));
|
||||||
hist[bucket] += 1;
|
hist[bucket] += 1;
|
||||||
}
|
}
|
||||||
calibrate_result.histogram.push(hist);
|
calibrate_result.histogram.push(hist);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for op in operations {
|
for op in operations {
|
||||||
let mut hist = vec![0; hist_params.bucket_number];
|
let mut hist = vec![0; options.hist_params.bucket_number];
|
||||||
for _ in 0..hist_params.iterations {
|
for _ in 0..options.hist_params.iterations {
|
||||||
unsafe { (op.prepare)(pointer) };
|
unsafe { (op.prepare)(pointer) };
|
||||||
unsafe { arch_x86::_mm_mfence() }; // Test with this ?
|
unsafe { arch_x86::_mm_mfence() }; // Test with this ?
|
||||||
let _time = unsafe { (op.op)(pointer) };
|
let _time = unsafe { (op.op)(pointer) };
|
||||||
}
|
}
|
||||||
for _ in 0..hist_params.iterations {
|
for _ in 0..options.hist_params.iterations {
|
||||||
unsafe { (op.prepare)(pointer) };
|
unsafe { (op.prepare)(pointer) };
|
||||||
unsafe { arch_x86::_mm_mfence() }; // Test with this ?
|
unsafe { arch_x86::_mm_mfence() }; // Test with this ?
|
||||||
let time = unsafe { (op.op)(pointer) };
|
let time = unsafe { (op.op)(pointer) };
|
||||||
let bucket = min(hist_params.bucket_number - 1, to_bucket(time));
|
let bucket = min(options.hist_params.bucket_number - 1, to_bucket(time));
|
||||||
hist[bucket] += 1;
|
hist[bucket] += 1;
|
||||||
}
|
}
|
||||||
calibrate_result.histogram.push(hist);
|
calibrate_result.histogram.push(hist);
|
||||||
@ -712,11 +721,13 @@ fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>>(
|
|||||||
let median_thresholds: Vec<u32> = calibrate_result
|
let median_thresholds: Vec<u32> = calibrate_result
|
||||||
.histogram
|
.histogram
|
||||||
.iter()
|
.iter()
|
||||||
.map(|h| (hist_params.iterations - h[hist_params.bucket_number - 1]) / 2)
|
.map(|h| {
|
||||||
|
(options.hist_params.iterations - h[options.hist_params.bucket_number - 1]) / 2
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for j in 0..hist_params.bucket_number - 1 {
|
for j in 0..options.hist_params.bucket_number - 1 {
|
||||||
if verbosity_level >= RawResult {
|
if options.verbosity >= RawResult {
|
||||||
print!("RESULT:{},{},{:p},", main_core, helper_core, pointer);
|
print!("RESULT:{},{},{:p},", main_core, helper_core, pointer);
|
||||||
if let Some(h) = hash {
|
if let Some(h) = hash {
|
||||||
print!("{:x},", h);
|
print!("{:x},", h);
|
||||||
@ -730,7 +741,7 @@ fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>>(
|
|||||||
let max = &mut calibrate_result.max[op];
|
let max = &mut calibrate_result.max[op];
|
||||||
let med = &mut calibrate_result.median[op];
|
let med = &mut calibrate_result.median[op];
|
||||||
let sum = &mut sums[op];
|
let sum = &mut sums[op];
|
||||||
if verbosity_level >= RawResult {
|
if options.verbosity >= RawResult {
|
||||||
print!(",{}", hist);
|
print!(",{}", hist);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -750,11 +761,11 @@ fn calibrate_fixed_freq_2_thread_impl<I: Iterator<Item = (usize, usize)>>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if verbosity_level >= RawResult {
|
if options.verbosity >= RawResult {
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if verbosity_level >= Thresholds {
|
if options.verbosity >= Thresholds {
|
||||||
for (j, op) in operations.iter().enumerate() {
|
for (j, op) in operations.iter().enumerate() {
|
||||||
println!(
|
println!(
|
||||||
"{}: min {}, median {}, max {}",
|
"{}: min {}, median {}, max {}",
|
||||||
|
Loading…
Reference in New Issue
Block a user