From 7ac6364c999493f90d1c67e95e855130dea6c827 Mon Sep 17 00:00:00 2001 From: Speedy_Lex <78314533+speedy-lex@users.noreply.github.com> Date: Fri, 11 Apr 2025 19:54:52 +0200 Subject: [PATCH] Fix getting cache info on aarch64 --- engine/src/metadata.rs | 57 ++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/engine/src/metadata.rs b/engine/src/metadata.rs index 94a7533..319db10 100644 --- a/engine/src/metadata.rs +++ b/engine/src/metadata.rs @@ -382,38 +382,45 @@ impl CPU { let logical_cores = cpu_opt.map(|_| sys.cpus().len() as u8); let physical_cores = System::physical_core_count().map(|pc| pc as u8); - let cpuid = CpuId::new(); let mut l1_cache = None; let mut l2_cache = None; let mut l3_cache = None; - if let Some(iter) = cpuid.get_cache_parameters() { - for cache in iter { - match cache.level() { - 1 => { - let size = cache.physical_line_partitions() - * cache.coherency_line_size() - * cache.associativity(); - if size > 0 { - l1_cache = Some(Memory::from_bytes(size.try_into().unwrap())); + + #[cfg(any( + all(target_arch = "x86", not(target_env = "sgx"), target_feature = "sse"), + all(target_arch = "x86_64", not(target_env = "sgx")) + ))] + { + let cpuid = CpuId::new(); + if let Some(iter) = cpuid.get_cache_parameters() { + for cache in iter { + match cache.level() { + 1 => { + let size = cache.physical_line_partitions() + * cache.coherency_line_size() + * cache.associativity(); + if size > 0 { + l1_cache = Some(Memory::from_bytes(size.try_into().unwrap())); + } } - } - 2 => { - let size = cache.physical_line_partitions() - * cache.coherency_line_size() - * cache.associativity(); - if size > 0 { - l2_cache = Some(Memory::from_bytes(size.try_into().unwrap())); + 2 => { + let size = cache.physical_line_partitions() + * cache.coherency_line_size() + * cache.associativity(); + if size > 0 { + l2_cache = Some(Memory::from_bytes(size.try_into().unwrap())); + } } - } - 3 => { - let size = (cache.physical_line_partitions() as u64) - * (cache.coherency_line_size() as u64) - * (cache.associativity() as u64); - if size > 0 { - l3_cache = Some(Memory::from_bytes(size)); + 3 => { + let size = (cache.physical_line_partitions() as u64) + * (cache.coherency_line_size() as u64) + * (cache.associativity() as u64); + if size > 0 { + l3_cache = Some(Memory::from_bytes(size)); + } } + _ => {} } - _ => {} } } }