Skip to content

Commit

Permalink
Tweak cpuinfo parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars T Hansen committed Jan 22, 2025
1 parent 4f0802a commit c972a94
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/procfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub fn get_memtotal_kib(fs: &dyn procfsapi::ProcfsAPI) -> Result<usize, String>
pub fn get_cpu_info(fs: &dyn procfsapi::ProcfsAPI) -> Result<(String, i32, i32, i32), String> {
let mut physids = HashMap::<i32, bool>::new();
let mut processors = HashSet::<i32>::new();
let mut cores_per_socket = 0i32;
let mut siblings = 0i32;
let cpuinfo = fs.read_to_string("cpuinfo")?;
Expand All @@ -58,8 +59,12 @@ pub fn get_cpu_info(fs: &dyn procfsapi::ProcfsAPI) -> Result<(String, i32, i32,
let mut model_major = 0i32;
let mut model_minor = 0i32;
for l in cpuinfo.split('\n') {
// "processor" could be either kind of CPU, so don't commit
if l.starts_with("processor") {
processors.insert(i32_field(l)?);
}
// model name, physical id, siblings, cpu cores are x86_64
if l.starts_with("model name") {
else if l.starts_with("model name") {
amd64 = true;
model_name = text_field(l)?;
} else if l.starts_with("physical id") {
Expand All @@ -72,11 +77,8 @@ pub fn get_cpu_info(fs: &dyn procfsapi::ProcfsAPI) -> Result<(String, i32, i32,
amd64 = true;
cores_per_socket = i32_field(l)?;
}
// processor, CPU architecture, CPU variant are aarch64
else if l.starts_with("processor") {
aarch64 = true;
physids.insert(i32_field(l)?, true);
} else if l.starts_with("CPU architecture") {
// CPU architecture, CPU variant are aarch64
else if l.starts_with("CPU architecture") {
aarch64 = true;
model_major = i32_field(l)?;
} else if l.starts_with("CPU variant") {
Expand All @@ -95,7 +97,7 @@ pub fn get_cpu_info(fs: &dyn procfsapi::ProcfsAPI) -> Result<(String, i32, i32,
Ok((
format!("ARMv{model_major}.{model_minor}"),
1,
physids.len() as i32,
processors.len() as i32,
1,
))
} else {
Expand Down

0 comments on commit c972a94

Please sign in to comment.