From ba210848e237ec32562023090bb2a119b59897c0 Mon Sep 17 00:00:00 2001 From: guillaume didier Date: Wed, 18 Mar 2020 14:30:16 +0100 Subject: [PATCH] cache_utils update --- cache_utils/src/calibration.rs | 7 ++---- cache_utils/src/main.rs | 43 +++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/cache_utils/src/calibration.rs b/cache_utils/src/calibration.rs index 1c5d1ca..41a1893 100644 --- a/cache_utils/src/calibration.rs +++ b/cache_utils/src/calibration.rs @@ -139,7 +139,7 @@ pub fn calibrate_access(array: &[u8; 4096]) -> u64 { } const CFLUSH_BUCKET_SIZE: usize = 1; -const CFLUSH_BUCKET_NUMBER: usize = 250; +const CFLUSH_BUCKET_NUMBER: usize = 500; const CFLUSH_NUM_ITER: usize = 1 << 11; const CFLUSH_SPURIOUS_THRESHOLD: usize = 1; @@ -231,9 +231,6 @@ pub fn calibrate_flush( miss_histogram[i] ); } - // FIXME - // Code duplication for histogram analysis is meh. - // Is there a better way ? for (min, max, med, sum, hist) in &mut [ ( @@ -265,7 +262,7 @@ pub fn calibrate_flush( if **med == 0 { **sum += hist[i]; - if **sum >= CFLUSH_NUM_ITER / 2 { + if **sum >= (CFLUSH_NUM_ITER - hist[hist.len() - 1]) / 2 { **med = i; } } diff --git a/cache_utils/src/main.rs b/cache_utils/src/main.rs index 4294960..d3e7a67 100644 --- a/cache_utils/src/main.rs +++ b/cache_utils/src/main.rs @@ -14,16 +14,53 @@ use nix::sched::{sched_getaffinity, sched_setaffinity, CpuSet}; use nix::unistd::Pid; use nix::Error::Sys; +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; +/* #[repr(align(4096))] struct Page { pub mem: [u8; 4096], } - +*/ pub fn main() { - let p = Box::new(Page { mem: [0; 4096] }); + 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*/ - let m: &[u8] = &p.mem; + &*slice_from_raw_parts(p, SIZE) + }; + /* + let p = Box::new(Page { mem: [0; 4096] }); + let m: &[u8] = &p.mem; + */ let old = sched_getaffinity(Pid::from_raw(0)).unwrap(); for i in 0..(CpuSet::count() - 1) {