summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2022-09-06 12:48:34 -0700
committerGitHub <noreply@github.com>2022-09-06 12:48:34 -0700
commitee199cfb18e242e8854a3f7c6aa2493bddf0b490 (patch)
treea79053d5fdebff6ea6fe79d3b57bc869fc4d6399 /lib
parentf13a48ad2d0025482c19df06ff27670071e8e1e1 (diff)
downloadohai-ee199cfb18e242e8854a3f7c6aa2493bddf0b490.tar.gz
Use a minimum of 1 thread per core for CPU total calculation (#1756)
In some LXD containers running with VT-x hardware virtualization, it appears that threads per core is 0, resulting in a total number of CPUs of 0. Add a test case and handle some quirks with the `lscpu` output. Closes https://github.com/chef/ohai/issues/1755 Signed-off-by: Stan Hu <stanhu@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/ohai/plugins/cpu.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/ohai/plugins/cpu.rb b/lib/ohai/plugins/cpu.rb
index 1d37c39f..897f716b 100644
--- a/lib/ohai/plugins/cpu.rb
+++ b/lib/ohai/plugins/cpu.rb
@@ -193,7 +193,8 @@ Ohai.plugin(:CPU) do
lscpu_real = lscpu_info[:sockets]
lscpu_cores = lscpu_info[:sockets] * lscpu_info[:cores_per_socket]
else
- lscpu_total = lscpu_info[:sockets] * lscpu_info[:cores_per_socket] * lscpu_info[:threads_per_core]
+ threads_per_core = [lscpu_info[:threads_per_core], 1].max
+ lscpu_total = lscpu_info[:sockets] * lscpu_info[:cores_per_socket] * threads_per_core
lscpu_real = lscpu_info[:sockets]
lscpu_cores = lscpu_info[:sockets] * lscpu_info[:cores_per_socket]
end