2020-05-28 11:22:50 +02:00
|
|
|
use crate::complex_addressing::CacheSlicing::{
|
|
|
|
ComplexAddressing, NoSlice, SimpleAddressing, Unsupported,
|
|
|
|
};
|
2020-07-15 10:16:26 +02:00
|
|
|
use cpuid::{CPUVendor, MicroArchitecture};
|
|
|
|
|
|
|
|
#[cfg(feature = "no_std")]
|
|
|
|
use hashbrown::HashMap;
|
|
|
|
#[cfg(feature = "no_std")]
|
|
|
|
use hashbrown::HashSet;
|
|
|
|
|
|
|
|
#[cfg(feature = "use_std")]
|
|
|
|
use std::collections::HashMap;
|
|
|
|
#[cfg(feature = "use_std")]
|
|
|
|
use std::collections::HashSet;
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub struct SimpleAddressingParams {
|
|
|
|
pub shift: u8, // How many trailing zeros
|
|
|
|
pub bits: u8, // How many ones
|
|
|
|
}
|
2020-05-27 14:02:19 +02:00
|
|
|
|
2020-05-28 11:22:50 +02:00
|
|
|
#[derive(Debug, Copy, Clone)]
|
2020-05-27 14:02:19 +02:00
|
|
|
pub enum CacheSlicing {
|
|
|
|
Unsupported,
|
|
|
|
ComplexAddressing(&'static [usize]),
|
2020-07-15 10:16:26 +02:00
|
|
|
SimpleAddressing(SimpleAddressingParams),
|
2020-05-27 14:02:19 +02:00
|
|
|
NoSlice,
|
|
|
|
}
|
2020-05-28 11:22:50 +02:00
|
|
|
const SANDYBRIDGE_TO_SKYLAKE_FUNCTIONS: [usize; 4] = [
|
2020-05-27 14:02:19 +02:00
|
|
|
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,
|
2020-05-28 11:22:50 +02:00
|
|
|
0b0, // TODO
|
2020-05-27 14:02:19 +02:00
|
|
|
];
|
2020-07-15 10:16:26 +02:00
|
|
|
|
|
|
|
const KABYLAKE_i9_FUNCTIONS: [usize; 4] = [
|
|
|
|
0b0000_1111_1111_1101_0101_1101_0101_0001_000000,
|
|
|
|
0b0000_0110_1111_1011_1010_1100_0100_1000_000000,
|
|
|
|
0b0000_1111_1110_0001_1111_1100_1011_0000_000000,
|
|
|
|
0b0, // TODO
|
|
|
|
];
|
2020-05-27 14:02:19 +02:00
|
|
|
// missing functions for more than 8 cores.
|
|
|
|
|
2020-07-15 10:16:26 +02:00
|
|
|
// FIXME : Need to account for Family Model (and potentially stepping)
|
|
|
|
// Amongst other thing Crystal well products have a different function. (0x6_46)
|
|
|
|
// Same thing for Kaby Lake with 8 cores apparently.
|
|
|
|
|
|
|
|
pub fn cache_slicing(
|
|
|
|
uarch: MicroArchitecture,
|
|
|
|
physical_cores: u8,
|
|
|
|
vendor: CPUVendor,
|
|
|
|
family_model_display: u32,
|
|
|
|
stepping: u32,
|
|
|
|
) -> CacheSlicing {
|
2020-05-27 14:02:19 +02:00
|
|
|
let trailing_zeros = physical_cores.trailing_zeros();
|
|
|
|
if physical_cores != (1 << trailing_zeros) {
|
|
|
|
return Unsupported;
|
|
|
|
}
|
|
|
|
|
|
|
|
match uarch {
|
2020-07-15 10:16:26 +02:00
|
|
|
MicroArchitecture::Skylake | MicroArchitecture::CoffeeLake => {
|
2020-05-27 14:02:19 +02:00
|
|
|
ComplexAddressing(&SANDYBRIDGE_TO_SKYLAKE_FUNCTIONS[0..((trailing_zeros + 1) as usize)])
|
2020-07-15 10:16:26 +02:00
|
|
|
}
|
|
|
|
MicroArchitecture::KabyLake => {
|
|
|
|
ComplexAddressing(&KABYLAKE_i9_FUNCTIONS[0..((trailing_zeros + 1) as usize)])
|
|
|
|
}
|
2020-06-02 17:29:55 +02:00
|
|
|
MicroArchitecture::SandyBridge
|
2020-07-15 10:16:26 +02:00
|
|
|
| MicroArchitecture::HaswellE
|
2020-06-02 17:29:55 +02:00
|
|
|
| MicroArchitecture::Broadwell
|
2020-07-15 10:16:26 +02:00
|
|
|
| MicroArchitecture::IvyBridge
|
|
|
|
| MicroArchitecture::IvyBridgeE => {
|
2020-05-28 11:22:50 +02:00
|
|
|
ComplexAddressing(&SANDYBRIDGE_TO_SKYLAKE_FUNCTIONS[0..((trailing_zeros) as usize)])
|
2020-07-15 10:16:26 +02:00
|
|
|
}
|
|
|
|
MicroArchitecture::Haswell => {
|
|
|
|
if family_model_display == 0x06_46 {
|
|
|
|
// Crystal Well
|
|
|
|
Unsupported
|
|
|
|
} else {
|
|
|
|
ComplexAddressing(&SANDYBRIDGE_TO_SKYLAKE_FUNCTIONS[0..((trailing_zeros) as usize)])
|
|
|
|
}
|
|
|
|
}
|
2020-06-03 08:49:10 +02:00
|
|
|
MicroArchitecture::Nehalem | MicroArchitecture::Westmere => {
|
2020-07-15 10:16:26 +02:00
|
|
|
Unsupported //SimpleAddressing(((physical_cores - 1) as usize) << 6 + 8) // Hardcoded for 4 cores FIXME !!!
|
2020-05-28 11:22:50 +02:00
|
|
|
}
|
2020-05-27 14:02:19 +02:00
|
|
|
_ => Unsupported,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-15 10:16:26 +02:00
|
|
|
fn hash(addr: usize, mask: usize) -> u8 {
|
|
|
|
((addr & mask).count_ones() & 1) as u8
|
2020-04-06 11:14:05 +02:00
|
|
|
}
|
|
|
|
|
2020-05-28 11:22:50 +02:00
|
|
|
impl CacheSlicing {
|
|
|
|
pub fn can_hash(&self) -> bool {
|
|
|
|
match self {
|
2020-07-15 10:16:26 +02:00
|
|
|
Unsupported | NoSlice | SimpleAddressing(_) => false,
|
|
|
|
ComplexAddressing(_) => true,
|
2020-05-28 11:22:50 +02:00
|
|
|
}
|
2020-04-06 11:14:05 +02:00
|
|
|
}
|
2020-07-15 10:16:26 +02:00
|
|
|
pub fn hash(&self, addr: usize) -> Option<u8> {
|
2020-05-28 11:22:50 +02:00
|
|
|
match self {
|
2020-07-15 10:16:26 +02:00
|
|
|
SimpleAddressing(mask) => None, //Some(addr & *mask),
|
2020-05-28 11:22:50 +02:00
|
|
|
ComplexAddressing(masks) => {
|
|
|
|
let mut res = 0;
|
|
|
|
for mask in *masks {
|
|
|
|
res <<= 1;
|
|
|
|
res |= hash(addr, *mask);
|
|
|
|
}
|
|
|
|
Some(res)
|
|
|
|
}
|
|
|
|
_ => None,
|
2020-04-06 11:14:05 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-15 10:16:26 +02:00
|
|
|
|
|
|
|
pub fn image(&self, mask: usize) -> Option<HashSet<usize>> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn kernel_compl_basis(&self, mask: usize) -> Option<HashMap<usize, usize>> {
|
|
|
|
None
|
|
|
|
}
|
2020-04-06 11:14:05 +02:00
|
|
|
}
|