dendrobates-t-azureus/cache_utils/src/prefetcher.rs
guillaume didier 17e1b283d8 Clean up
2020-03-12 14:46:43 +01:00

53 lines
1.2 KiB
Rust

use x86_64::registers::model_specific::Msr;
use crate::calibration::only_flush;
use crate::flush;
use crate::maccess;
extern crate alloc;
use alloc::vec;
use alloc::vec::Vec;
const MSR_MISC_FEATURE8CONTROL: u32 = 0x1a4;
const N: i32 = 10;
pub fn prefetcher_status() -> bool {
let msr = Msr::new(MSR_MISC_FEATURE8CONTROL);
let value = unsafe { msr.read() };
value & 0xf != 0xf
}
pub fn enable_prefetchers(status: bool) {
let mut msr = Msr::new(MSR_MISC_FEATURE8CONTROL);
let mut value = unsafe { msr.read() } & !0xf;
if !status {
value |= 0xf;
}
unsafe { msr.write(value) };
}
pub fn prefetcher_fun(
victim_4k_addr: *mut u8,
victim_2M_addr: *mut u8,
threshold_ff: u64,
) -> Vec<i32> {
let mut results = vec![0; 4096 / 64];
return results;
for _ in 0..N {
//unsafe { maccess(victim4kaddr) };
for j in (0..4096).step_by(64).rev() {
let t = unsafe { only_flush(victim_4k_addr.offset(j)) };
if threshold_ff < t {
// hit
results[(j / 64) as usize] += 1;
} else if threshold_ff > t {
results[(j / 64) as usize] -= 1;
}
}
}
results
}