From f06e60b9c106ab6b39ad01ef63013be886fbca65 Mon Sep 17 00:00:00 2001 From: GuillaumeDIDIER Date: Wed, 27 May 2020 14:02:19 +0200 Subject: [PATCH] Add first steps on complex addressing --- cache_utils/src/calibration.rs | 11 ++++----- cache_utils/src/complex_addressing.rs | 32 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/cache_utils/src/calibration.rs b/cache_utils/src/calibration.rs index c709183..cdc99f1 100644 --- a/cache_utils/src/calibration.rs +++ b/cache_utils/src/calibration.rs @@ -41,6 +41,12 @@ pub unsafe fn flush_and_reload(p: *const u8) -> u64 { rdtsc_fence() - t } +pub unsafe fn only_flush(p: *const u8) -> u64 { + let t = rdtsc_fence(); + flush(p); + rdtsc_fence() - t +} + pub unsafe fn load_and_flush(p: *const u8) -> u64 { maccess(p); let t = rdtsc_fence(); @@ -54,11 +60,6 @@ pub unsafe fn flush_and_flush(p: *const u8) -> u64 { flush(p); rdtsc_fence() - t } -pub unsafe fn only_flush(p: *const u8) -> u64 { - let t = rdtsc_fence(); - flush(p); - rdtsc_fence() - t -} pub unsafe fn l3_and_reload(p: *const u8) -> u64 { flush(p); diff --git a/cache_utils/src/complex_addressing.rs b/cache_utils/src/complex_addressing.rs index afb665d..2c550a1 100644 --- a/cache_utils/src/complex_addressing.rs +++ b/cache_utils/src/complex_addressing.rs @@ -1,3 +1,35 @@ +use crate::complex_addressing::CacheSlicing::{ComplexAddressing, Unsupported}; +use cpuid::MicroArchitecture; + +pub enum CacheSlicing { + Unsupported, + ComplexAddressing(&'static [usize]), + SimpleAddressing(&'static usize), + NoSlice, +} +const SANDYBRIDGE_TO_SKYLAKE_FUNCTIONS: [usize; 3] = [ + 0b0110_1101_0111_1101_0101_1101_0101_0001_000000, + 0b1011_1010_1101_0111_1110_1010_1010_0010_000000, + 0b1111_0011_0011_0011_0010_0100_1100_0100_000000, +]; +// missing functions for more than 8 cores. + +pub fn cache_slicing(uarch: MicroArchitecture, physical_cores: u8) -> CacheSlicing { + let trailing_zeros = physical_cores.trailing_zeros(); + if physical_cores != (1 << trailing_zeros) { + return Unsupported; + } + + match uarch { + MicroArchitecture::Skylake + | MicroArchitecture::KabyLake + | MicroArchitecture::CoffeeLake => { + ComplexAddressing(&SANDYBRIDGE_TO_SKYLAKE_FUNCTIONS[0..((trailing_zeros + 1) as usize)]) + } + _ => Unsupported, + } +} + pub struct AddressHasher<'a> { masks: &'a [usize], }