From ee199cfb18e242e8854a3f7c6aa2493bddf0b490 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 6 Sep 2022 12:48:34 -0700 Subject: 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 --- lib/ohai/plugins/cpu.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') 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 -- cgit v1.2.1