Add complex addressing function computation and output those when calibrating
This commit is contained in:
parent
158b808d92
commit
dca0b156b4
@ -14,6 +14,7 @@ pub enum Verbosity {
|
|||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
use crate::calibration::Verbosity::*;
|
use crate::calibration::Verbosity::*;
|
||||||
|
use crate::complex_addressing::AddressHasher;
|
||||||
use alloc::vec;
|
use alloc::vec;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use core::cmp::min;
|
use core::cmp::min;
|
||||||
@ -219,6 +220,16 @@ fn calibrate_impl(
|
|||||||
num_iterations: u32,
|
num_iterations: u32,
|
||||||
verbosity_level: Verbosity,
|
verbosity_level: Verbosity,
|
||||||
) -> Vec<CalibrateResult> {
|
) -> Vec<CalibrateResult> {
|
||||||
|
// TODO : adapt this to detect CPU generation and grab the correct masks.
|
||||||
|
// These are the skylake masks.
|
||||||
|
let masks: [usize; 3] = [
|
||||||
|
0b1111_0011_0011_0011_0010_0100_1100_0100_000000,
|
||||||
|
0b1011_1010_1101_0111_1110_1010_1010_0010_000000,
|
||||||
|
0b0110_1101_0111_1101_0101_1101_0101_0001_000000,
|
||||||
|
];
|
||||||
|
|
||||||
|
let hasher = AddressHasher::new(&masks);
|
||||||
|
|
||||||
if verbosity_level >= Thresholds {
|
if verbosity_level >= Thresholds {
|
||||||
println!(
|
println!(
|
||||||
"Calibrating {}...",
|
"Calibrating {}...",
|
||||||
@ -231,7 +242,7 @@ fn calibrate_impl(
|
|||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
if verbosity_level >= Thresholds {
|
if verbosity_level >= Thresholds {
|
||||||
println!(
|
println!(
|
||||||
"CSV: address, {} min, {} median, {} max",
|
"CSV: address, hash, {} min, {} median, {} max",
|
||||||
operations.iter().map(|(_, name)| name).format(" min, "),
|
operations.iter().map(|(_, name)| name).format(" min, "),
|
||||||
operations.iter().map(|(_, name)| name).format(" median, "),
|
operations.iter().map(|(_, name)| name).format(" median, "),
|
||||||
operations.iter().map(|(_, name)| name).format(" max, ")
|
operations.iter().map(|(_, name)| name).format(" max, ")
|
||||||
@ -239,9 +250,10 @@ fn calibrate_impl(
|
|||||||
}
|
}
|
||||||
for i in (0..len).step_by(increment) {
|
for i in (0..len).step_by(increment) {
|
||||||
let pointer = unsafe { p.offset(i) };
|
let pointer = unsafe { p.offset(i) };
|
||||||
|
let hash = hasher.hash(pointer as usize);
|
||||||
|
|
||||||
if verbosity_level >= Thresholds {
|
if verbosity_level >= Thresholds {
|
||||||
println!("Calibration for {:p}", pointer);
|
println!("Calibration for {:p} (hash: {:x})", pointer, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO add some useful impl to CalibrateResults
|
// TODO add some useful impl to CalibrateResults
|
||||||
@ -325,8 +337,9 @@ fn calibrate_impl(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
println!(
|
println!(
|
||||||
"CSV: {:p}, {}, {}, {}",
|
"CSV: {:p}; {:x}, {}, {}, {}",
|
||||||
pointer,
|
pointer,
|
||||||
|
hash,
|
||||||
calibrate_result.min.iter().format(", "),
|
calibrate_result.min.iter().format(", "),
|
||||||
calibrate_result.median.iter().format(", "),
|
calibrate_result.median.iter().format(", "),
|
||||||
calibrate_result.max.iter().format(", ")
|
calibrate_result.max.iter().format(", ")
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
pub struct AddressHasher<'a> {
|
||||||
|
masks: &'a [usize],
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hash(addr: usize, mask: usize) -> u32 {
|
||||||
|
(addr & mask).count_ones() & 1
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AddressHasher<'_> {
|
||||||
|
pub fn new(masks: &[usize]) -> AddressHasher {
|
||||||
|
AddressHasher { masks }
|
||||||
|
}
|
||||||
|
pub fn hash(&self, addr: usize) -> u32 {
|
||||||
|
let mut res = 0;
|
||||||
|
for mask in self.masks {
|
||||||
|
res <<= 1;
|
||||||
|
res |= hash(addr, *mask);
|
||||||
|
}
|
||||||
|
res
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@ assert_cfg!(
|
|||||||
|
|
||||||
pub mod cache_info;
|
pub mod cache_info;
|
||||||
pub mod calibration;
|
pub mod calibration;
|
||||||
|
pub mod complex_addressing;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub mod mmap;
|
pub mod mmap;
|
||||||
pub mod prefetcher;
|
pub mod prefetcher;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user