Add a sanity check on the threshold

This commit is contained in:
guillaume didier 2020-02-19 11:57:51 +01:00
parent b28221d4c2
commit 1d4ca06c96

View File

@ -18,6 +18,9 @@ use vga_buffer; // required for custom panic handler
use vga_buffer::{print, println};
use x86_64;
use core::cmp::Ord;
use core::ops::Sub;
#[cfg(not(test))]
use dendrobates_tinctoreus_azureus::hlt_loop;
@ -35,6 +38,14 @@ fn panic(info: &PanicInfo) -> ! {
hlt_loop();
}
fn distance<T: Sub<Output = T> + Ord>(a: T, b: T) -> T {
if a > b {
a - b
} else {
b - a
}
}
entry_point!(kernel_main);
// Kernel entry point
@ -98,14 +109,20 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
}
println!();
cache_utils::calibration::calibrate_access();
cache_utils::calibration::calibrate_flush();
let threshold_access_p = cache_utils::calibration::calibrate_access();
let threshold_flush_p = cache_utils::calibration::calibrate_flush();
cache_utils::prefetcher::enable_prefetchers(false);
serial_println!("Prefetcher disabled");
cache_utils::calibration::calibrate_access();
cache_utils::calibration::calibrate_flush();
let threshold_access = cache_utils::calibration::calibrate_access();
let threshold_flush = cache_utils::calibration::calibrate_flush();
serial_println!("Please compare histograms for sanity");
if distance(threshold_access_p, threshold_access) > 10
|| distance(threshold_flush_p, threshold_flush) > 2
{
panic!("Inconsistent thresholds");
}
// Calibration
// disable pretechers
// Calibrate hit / miss rdtsc threshold