From 775c84ffce94b0fb0355db71e6defb4efff6aa04 Mon Sep 17 00:00:00 2001 From: Egor Lazarchuk Date: Thu, 28 Nov 2024 21:51:55 +0000 Subject: [PATCH] chore: fix aarch64 clippy lints Signed-off-by: Egor Lazarchuk --- src/vmm/src/arch/aarch64/cache_info.rs | 61 +++++++++++++------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/src/vmm/src/arch/aarch64/cache_info.rs b/src/vmm/src/arch/aarch64/cache_info.rs index cd61cabeb02..f94fc8f7822 100644 --- a/src/vmm/src/arch/aarch64/cache_info.rs +++ b/src/vmm/src/arch/aarch64/cache_info.rs @@ -23,8 +23,8 @@ pub(crate) enum CacheInfoError { MissingOptionalAttr(String, CacheEntry), } -struct CacheEngine { - store: Box, +struct CacheEngine { + store: T, } trait CacheStore: std::fmt::Debug { @@ -32,7 +32,7 @@ trait CacheStore: std::fmt::Debug { } #[derive(Debug)] -pub(crate) struct CacheEntry { +pub struct CacheEntry { // Cache Level: 1, 2, 3.. pub level: u8, // Type of cache: Unified, Data, Instruction. @@ -45,17 +45,16 @@ pub(crate) struct CacheEntry { } #[derive(Debug)] -struct HostCacheStore { +pub struct HostCacheStore { cache_dir: PathBuf, } -#[cfg(not(test))] -impl Default for CacheEngine { +impl Default for CacheEngine { fn default() -> Self { CacheEngine { - store: Box::new(HostCacheStore { + store: HostCacheStore { cache_dir: PathBuf::from("/sys/devices/system/cpu/cpu0/cache"), - }), + }, } } } @@ -72,7 +71,7 @@ impl CacheStore for HostCacheStore { } impl CacheEntry { - fn from_index(index: u8, store: &dyn CacheStore) -> Result { + fn from_index(index: u8, store: &impl CacheStore) -> Result { let mut err_str = String::new(); let mut cache: CacheEntry = CacheEntry::default(); @@ -287,10 +286,10 @@ pub(crate) fn read_cache_config( // Also without this mechanism we would be logging the warnings for each level which pollutes // a lot the logs. let mut logged_missing_attr = false; - let engine = CacheEngine::default(); + let engine = CacheEngine::::default(); for index in 0..=MAX_CACHE_LEVEL { - match CacheEntry::from_index(index, engine.store.as_ref()) { + match CacheEntry::from_index(index, &engine.store) { Ok(cache) => { append_cache_level(cache_l1, cache_non_l1, cache); } @@ -326,22 +325,22 @@ mod tests { dummy_fs: HashMap, } - impl Default for CacheEngine { + impl Default for CacheEngine { fn default() -> Self { CacheEngine { - store: Box::new(MockCacheStore { + store: MockCacheStore { dummy_fs: create_default_store(), - }), + }, } } } - impl CacheEngine { + impl CacheEngine { fn new(map: &HashMap) -> Self { CacheEngine { - store: Box::new(MockCacheStore { + store: MockCacheStore { dummy_fs: map.clone(), - }), + }, } } } @@ -425,12 +424,12 @@ mod tests { let mut map1 = default_map.clone(); map1.remove("index0/type"); let engine = CacheEngine::new(&map1); - let res = CacheEntry::from_index(0, engine.store.as_ref()); + let res = CacheEntry::from_index(0, &engine.store); // We did create the level file but we still do not have the type file. assert!(matches!(res.unwrap_err(), CacheInfoError::MissingCacheType)); let engine = CacheEngine::new(&default_map); - let res = CacheEntry::from_index(0, engine.store.as_ref()); + let res = CacheEntry::from_index(0, &engine.store); assert_eq!( format!("{}", res.unwrap_err()), "shared cpu map, coherency line size, size, number of sets", @@ -440,7 +439,7 @@ mod tests { let mut map2 = default_map.clone(); map2.insert("index0/level".to_string(), "d".to_string()); let engine = CacheEngine::new(&map2); - let res = CacheEntry::from_index(0, engine.store.as_ref()); + let res = CacheEntry::from_index(0, &engine.store); assert_eq!( format!("{}", res.unwrap_err()), "Invalid cache configuration found for level: invalid digit found in string" @@ -448,7 +447,7 @@ mod tests { default_map.insert("index0/type".to_string(), "Instructionn".to_string()); let engine = CacheEngine::new(&default_map); - let res = CacheEntry::from_index(0, engine.store.as_ref()); + let res = CacheEntry::from_index(0, &engine.store); assert_eq!( format!("{}", res.unwrap_err()), "Invalid cache configuration found for type: Instructionn" @@ -464,7 +463,7 @@ mod tests { "00000000,00000001".to_string(), ); let engine = CacheEngine::new(&default_map); - let res = CacheEntry::from_index(0, engine.store.as_ref()); + let res = CacheEntry::from_index(0, &engine.store); assert_eq!( format!("{}", res.unwrap_err()), "coherency line size, size, number of sets" @@ -475,7 +474,7 @@ mod tests { "00000000,0000000G".to_string(), ); let engine = CacheEngine::new(&default_map); - let res = CacheEntry::from_index(0, engine.store.as_ref()); + let res = CacheEntry::from_index(0, &engine.store); assert_eq!( format!("{}", res.unwrap_err()), "Invalid cache configuration found for shared_cpu_map: invalid digit found in string" @@ -483,7 +482,7 @@ mod tests { default_map.insert("index0/shared_cpu_map".to_string(), "00000000".to_string()); let engine = CacheEngine::new(&default_map); - let res = CacheEntry::from_index(0, engine.store.as_ref()); + let res = CacheEntry::from_index(0, &engine.store); assert_eq!( format!("{}", res.unwrap_err()), "Invalid cache configuration found for shared_cpu_map: 00000000" @@ -496,7 +495,7 @@ mod tests { default_map.insert("index0/coherency_line_size".to_string(), "64".to_string()); let engine = CacheEngine::new(&default_map); - let res = CacheEntry::from_index(0, engine.store.as_ref()); + let res = CacheEntry::from_index(0, &engine.store); assert_eq!( "shared cpu map, size, number of sets", format!("{}", res.unwrap_err()) @@ -507,7 +506,7 @@ mod tests { "Instruction".to_string(), ); let engine = CacheEngine::new(&default_map); - let res = CacheEntry::from_index(0, engine.store.as_ref()); + let res = CacheEntry::from_index(0, &engine.store); assert_eq!( format!("{}", res.unwrap_err()), "Invalid cache configuration found for coherency_line_size: invalid digit found in \ @@ -521,7 +520,7 @@ mod tests { default_map.insert("index0/size".to_string(), "64K".to_string()); let engine = CacheEngine::new(&default_map); - let res = CacheEntry::from_index(0, engine.store.as_ref()); + let res = CacheEntry::from_index(0, &engine.store); assert_eq!( format!("{}", res.unwrap_err()), "shared cpu map, coherency line size, number of sets", @@ -529,7 +528,7 @@ mod tests { default_map.insert("index0/size".to_string(), "64".to_string()); let engine = CacheEngine::new(&default_map); - let res = CacheEntry::from_index(0, engine.store.as_ref()); + let res = CacheEntry::from_index(0, &engine.store); assert_eq!( format!("{}", res.unwrap_err()), "Invalid cache configuration found for size: 64" @@ -537,7 +536,7 @@ mod tests { default_map.insert("index0/size".to_string(), "64Z".to_string()); let engine = CacheEngine::new(&default_map); - let res = CacheEntry::from_index(0, engine.store.as_ref()); + let res = CacheEntry::from_index(0, &engine.store); assert_eq!( format!("{}", res.unwrap_err()), "Invalid cache configuration found for size: 64Z" @@ -550,7 +549,7 @@ mod tests { default_map.insert("index0/number_of_sets".to_string(), "64".to_string()); let engine = CacheEngine::new(&default_map); - let res = CacheEntry::from_index(0, engine.store.as_ref()); + let res = CacheEntry::from_index(0, &engine.store); assert_eq!( "shared cpu map, coherency line size, size", format!("{}", res.unwrap_err()) @@ -558,7 +557,7 @@ mod tests { default_map.insert("index0/number_of_sets".to_string(), "64K".to_string()); let engine = CacheEngine::new(&default_map); - let res = CacheEntry::from_index(0, engine.store.as_ref()); + let res = CacheEntry::from_index(0, &engine.store); assert_eq!( format!("{}", res.unwrap_err()), "Invalid cache configuration found for number_of_sets: invalid digit found in string"