Skip to content

Commit 0956312

Browse files
committed
fix(aarch64): removed warnings for missing cache info
Previously during FC startup on aarch64 platforms warnings about missing cache levels were emitted. Even though these warning are not critical and can be ignored, they were causing confusion. This commit removes warnings when cache level or cache type can not be obtained. Otherwise the error handing remains the same. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent fd72d1a commit 0956312

File tree

1 file changed

+22
-37
lines changed

1 file changed

+22
-37
lines changed

src/vmm/src/arch/aarch64/cache_info.rs

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::path::{Path, PathBuf};
55
use std::{fs, io};
66

7-
use logger::warn;
7+
use log::warn;
88

99
// Based on https://elixir.free-electrons.com/linux/v4.9.62/source/arch/arm64/kernel/cacheinfo.c#L29.
1010
const MAX_CACHE_LEVEL: u8 = 7;
@@ -15,8 +15,10 @@ pub(crate) enum CacheInfoError {
1515
FailedToReadCacheInfo(#[from] io::Error),
1616
#[error("Invalid cache configuration found for {0}: {1}")]
1717
InvalidCacheAttr(String, String),
18-
#[error("Cannot proceed with reading cache info.")]
19-
MissingCacheConfig,
18+
#[error("Cannot read cache level.")]
19+
MissingCacheLevel,
20+
#[error("Cannot read cache type.")]
21+
MissingCacheType,
2022
#[error("{0}")]
2123
MissingOptionalAttr(String, CacheEntry),
2224
}
@@ -76,29 +78,17 @@ impl CacheEntry {
7678

7779
// If the cache level or the type cannot be retrieved we stop the process
7880
// of populating the cache levels.
79-
match store.get_by_key(index, "level") {
80-
Ok(level) => {
81-
cache.level = level.parse::<u8>().map_err(|err| {
82-
CacheInfoError::InvalidCacheAttr("level".to_string(), err.to_string())
83-
})?;
84-
}
85-
Err(err) => {
86-
// If we cannot read the cache level even for the first level of cache, we will
87-
// stop processing anymore cache info and log an error.
88-
warn!("Could not read cache level for index {}: {}", index, err);
89-
return Err(CacheInfoError::MissingCacheConfig);
90-
}
91-
}
92-
match store.get_by_key(index, "type") {
93-
Ok(cache_type) => cache.type_ = CacheType::try_from(&cache_type)?,
94-
Err(err) => {
95-
warn!(
96-
"Could not read type for cache level {}: {}",
97-
cache.level, err
98-
);
99-
return Err(CacheInfoError::MissingCacheConfig);
100-
}
101-
}
81+
let level_str = store
82+
.get_by_key(index, "level")
83+
.map_err(|_| CacheInfoError::MissingCacheLevel)?;
84+
cache.level = level_str.parse::<u8>().map_err(|err| {
85+
CacheInfoError::InvalidCacheAttr("level".to_string(), err.to_string())
86+
})?;
87+
88+
let cache_type_str = store
89+
.get_by_key(index, "type")
90+
.map_err(|_| CacheInfoError::MissingCacheType)?;
91+
cache.type_ = CacheType::try_from(&cache_type_str)?;
10292

10393
if let Ok(shared_cpu_map) = store.get_by_key(index, "shared_cpu_map") {
10494
cache.cpus_per_unit = mask_str2bit_count(shared_cpu_map.trim_end())?;
@@ -296,22 +286,20 @@ pub(crate) fn read_cache_config(
296286
let mut logged_missing_attr = false;
297287
let engine = CacheEngine::default();
298288

299-
for index in 0..(MAX_CACHE_LEVEL + 1) {
289+
for index in 0..=MAX_CACHE_LEVEL {
300290
match CacheEntry::from_index(index, engine.store.as_ref()) {
301291
Ok(cache) => {
302292
append_cache_level(cache_l1, cache_non_l1, cache);
303293
}
294+
// Missing cache level or type means not further search is necessary.
295+
Err(CacheInfoError::MissingCacheLevel) | Err(CacheInfoError::MissingCacheType) => break,
304296
// Missing cache files is not necessary an error so we
305-
// do not propagate it upwards. We were prudent enough to log a warning.
306-
Err(CacheInfoError::MissingCacheConfig) => return Ok(()),
297+
// do not propagate it upwards. We were prudent enough to log it.
307298
Err(CacheInfoError::MissingOptionalAttr(msg, cache)) => {
308299
let level = cache.level;
309300
append_cache_level(cache_l1, cache_non_l1, cache);
310301
if !msg.is_empty() && !logged_missing_attr {
311-
warn!(
312-
"{}",
313-
format!("Could not read the {} for cache level {}.", msg, level)
314-
);
302+
warn!("Could not read the {msg} for cache level {level}.");
315303
logged_missing_attr = true;
316304
}
317305
}
@@ -437,10 +425,7 @@ mod tests {
437425
let res = CacheEntry::from_index(0, engine.store.as_ref());
438426
assert!(res.is_err());
439427
// We did create the level file but we still do not have the type file.
440-
assert_eq!(
441-
format!("{}", res.unwrap_err()),
442-
"Cannot proceed with reading cache info."
443-
);
428+
assert!(matches!(res.unwrap_err(), CacheInfoError::MissingCacheType));
444429

445430
let engine = CacheEngine::new(&default_map);
446431
let res = CacheEntry::from_index(0, engine.store.as_ref());

0 commit comments

Comments
 (0)