dendrobates-t-azureus/cache_utils/src/prefetcher.rs

53 lines
1.2 KiB
Rust
Raw Normal View History

2020-02-05 10:23:52 +01:00
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;
2020-02-05 10:23:52 +01:00
const MSR_MISC_FEATURE8CONTROL: u32 = 0x1a4;
const N: i32 = 10;
2020-02-05 10:23:52 +01:00
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) };
}
2020-02-28 12:03:51 +01:00
pub fn prefetcher_fun(
victim_4k_addr: *mut u8,
victim_2M_addr: *mut u8,
2020-02-28 12:03:51 +01:00
threshold_ff: u64,
) -> Vec<i32> {
let mut results = vec![0; 4096 / 64];
2020-03-12 14:46:43 +01:00
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
}