diff options
author | Stan Hu <stanhu@gmail.com> | 2022-07-26 23:14:30 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2022-08-24 09:31:06 -0700 |
commit | a449813c7dc7c75738a7937f252883bb20289268 (patch) | |
tree | aee7d3430922aaf3adac9d4812beea69e924b4ed | |
parent | 2cd91848d807d7a37342b964c6c5e204570469f9 (diff) | |
download | ohai-a449813c7dc7c75738a7937f252883bb20289268.tar.gz |
Fall back to /proc/cpuinfo if lscpu doesn't have CPU totals
https://github.com/chef/ohai/pull/1454 made `lscpu` the primary way
Ohai gathers CPU data, but the parser doesn't handle the output from a
Raspberry Pi 4 Cortex-A72. For example, an ARM cluster has the output
`Core(s) per cluster` instead of `Core(s) per socket`.
We should fall back to `/proc/cpuinfo` if we don't get reasonable data
back. It's not enough just to have `lscpu` output.
Closes https://github.com/chef/ohai/issues/1760
Signed-off-by: Stan Hu <stanhu@gmail.com>
-rw-r--r-- | lib/ohai/plugins/cpu.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/ohai/plugins/cpu.rb b/lib/ohai/plugins/cpu.rb index e26a7ace..1d37c39f 100644 --- a/lib/ohai/plugins/cpu.rb +++ b/lib/ohai/plugins/cpu.rb @@ -344,15 +344,23 @@ Ohai.plugin(:CPU) do cpuinfo end + # Check if the `lscpu` data looks reasonable + def valid_lscpu?(lscpu) + return false if lscpu.empty? + return false if %i{total real cores}.any? { |key| lscpu[key].to_i == 0 } + + true + end + collect_data(:linux) do cpuinfo = parse_cpuinfo lscpu = parse_lscpu(cpuinfo) - # If we don't have any data from lscpu then get it from /proc/cpuinfo - if lscpu.empty? - cpu cpuinfo - else + # If we don't have any sensible data from lscpu then get it from /proc/cpuinfo + if valid_lscpu?(lscpu) cpu lscpu + else + cpu cpuinfo end end |