2020-03-09 12:10:41 +01:00
|
|
|
// TODO create a nice program that can run on a system and will do the calibration.
|
2020-03-12 14:20:06 +01:00
|
|
|
// Calibration has to be sequential
|
|
|
|
// Will pin on each core one after the other
|
|
|
|
|
|
|
|
//fn execute_on_core(FnOnce)
|
|
|
|
|
|
|
|
#![feature(vec_resize_default)]
|
|
|
|
|
|
|
|
use cache_utils::calibration::calibrate_flush;
|
|
|
|
use cache_utils::calibration::Verbosity;
|
|
|
|
|
|
|
|
use nix::errno::Errno;
|
|
|
|
use nix::sched::{sched_getaffinity, sched_setaffinity, CpuSet};
|
|
|
|
use nix::unistd::Pid;
|
|
|
|
use nix::Error::Sys;
|
|
|
|
|
2020-03-18 14:30:16 +01:00
|
|
|
use nix::sys::mman;
|
|
|
|
use static_assertions::_core::ptr::{null_mut, slice_from_raw_parts};
|
|
|
|
|
|
|
|
/* from linux kernel headers.
|
|
|
|
#define HUGETLB_FLAG_ENCODE_SHIFT 26
|
|
|
|
#define HUGETLB_FLAG_ENCODE_MASK 0x3f
|
|
|
|
|
|
|
|
#define HUGETLB_FLAG_ENCODE_64KB (16 << HUGETLB_FLAG_ENCODE_SHIFT)
|
|
|
|
#define HUGETLB_FLAG_ENCODE_512KB (19 << HUGETLB_FLAG_ENCODE_SHIFT)
|
|
|
|
#define HUGETLB_FLAG_ENCODE_1MB (20 << HUGETLB_FLAG_ENCODE_SHIFT)
|
|
|
|
#define HUGETLB_FLAG_ENCODE_2MB (21 << HUGETLB_FLAG_ENCODE_SHIFT)
|
|
|
|
*/
|
|
|
|
|
|
|
|
const SIZE: usize = 2 << 20;
|
|
|
|
/*
|
2020-03-12 14:20:06 +01:00
|
|
|
#[repr(align(4096))]
|
|
|
|
struct Page {
|
|
|
|
pub mem: [u8; 4096],
|
|
|
|
}
|
2020-03-18 14:30:16 +01:00
|
|
|
*/
|
2020-03-09 14:27:32 +01:00
|
|
|
pub fn main() {
|
2020-03-18 14:30:16 +01:00
|
|
|
let m: &[u8] = unsafe {
|
|
|
|
let p: *mut u8 = mman::mmap(
|
|
|
|
null_mut(),
|
|
|
|
SIZE,
|
|
|
|
mman::ProtFlags::PROT_READ | mman::ProtFlags::PROT_WRITE,
|
|
|
|
mman::MapFlags::MAP_PRIVATE
|
|
|
|
| mman::MapFlags::MAP_ANONYMOUS
|
|
|
|
| mman::MapFlags::MAP_HUGETLB,
|
|
|
|
-1,
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
.unwrap() as *mut u8;
|
|
|
|
/*addr: *mut c_void,
|
|
|
|
length: size_t,
|
|
|
|
prot: ProtFlags,
|
|
|
|
flags: MapFlags,
|
|
|
|
fd: RawFd,
|
|
|
|
offset: off_t*/
|
2020-03-12 14:20:06 +01:00
|
|
|
|
2020-03-18 14:30:16 +01:00
|
|
|
&*slice_from_raw_parts(p, SIZE)
|
|
|
|
};
|
|
|
|
/*
|
|
|
|
let p = Box::new(Page { mem: [0; 4096] });
|
2020-03-12 14:20:06 +01:00
|
|
|
|
2020-03-18 14:30:16 +01:00
|
|
|
let m: &[u8] = &p.mem;
|
|
|
|
*/
|
2020-03-12 14:20:06 +01:00
|
|
|
let old = sched_getaffinity(Pid::from_raw(0)).unwrap();
|
|
|
|
|
|
|
|
for i in 0..(CpuSet::count() - 1) {
|
|
|
|
if old.is_set(i).unwrap() {
|
|
|
|
println!("Iteration {}...", i);
|
|
|
|
let mut core = CpuSet::new();
|
|
|
|
core.set(i).unwrap();
|
|
|
|
|
|
|
|
match sched_setaffinity(Pid::from_raw(0), &core) {
|
|
|
|
Ok(()) => {
|
2020-03-20 16:09:03 +01:00
|
|
|
calibrate_flush(m, 64, Verbosity::NoOutput);
|
2020-03-12 14:20:06 +01:00
|
|
|
calibrate_flush(m, 64, Verbosity::Thresholds);
|
|
|
|
sched_setaffinity(Pid::from_raw(0), &old).unwrap();
|
|
|
|
println!("Iteration {}...ok ", i);
|
2020-03-20 16:09:03 +01:00
|
|
|
eprintln!("Iteration {}...ok ", i);
|
2020-03-12 14:20:06 +01:00
|
|
|
}
|
|
|
|
Err(Sys(Errno::EINVAL)) => {
|
|
|
|
println!("skipping");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Err(_) => {
|
|
|
|
panic!("Unexpected error while setting affinity");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let's grab all the list of CPUS
|
|
|
|
// Then iterate the calibration on each CPU core.
|
2020-03-09 14:27:32 +01:00
|
|
|
}
|