From b0d5c0378711930c320e19def97307166d80b4d9 Mon Sep 17 00:00:00 2001 From: aristocratos Date: Sat, 26 Mar 2022 03:00:54 +0100 Subject: [PATCH] Fixed: Use cpu cores avarage temp if missing cpu package temp for FreeBSD --- src/freebsd/btop_collect.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/freebsd/btop_collect.cpp b/src/freebsd/btop_collect.cpp index 69a9dc6..1cf7a1e 100644 --- a/src/freebsd/btop_collect.cpp +++ b/src/freebsd/btop_collect.cpp @@ -266,20 +266,25 @@ namespace Cpu { } void update_sensors() { - int temp; - size_t size = sizeof(temp); - sysctlbyname("hw.acpi.thermal.tz0.temperature", &temp, &size, NULL, 0); - temp = (temp - 2732) / 10; // since it's an int, it's multiplied by 10, and offset to absolute zero... - current_cpu.temp.at(0).push_back(temp); - if (current_cpu.temp.at(0).size() > 20) - current_cpu.temp.at(0).pop_front(); + int temp = 0; + int p_temp = 0; + int found = 0; + bool got_package = false; + size_t size = sizeof(p_temp); + if (sysctlbyname("hw.acpi.thermal.tz0.temperature", &p_temp, &size, NULL, 0) >= 0) { + got_package = true; + p_temp = (p_temp - 2732) / 10; // since it's an int, it's multiplied by 10, and offset to absolute zero... + } + size = sizeof(temp); for (int i = 0; i < Shared::coreCount; i++) { string s = "dev.cpu." + std::to_string(i) + ".temperature"; - if (sysctlbyname(s.c_str(), &temp, &size, NULL, 0) < 0) { - Logger::warning("Could not get temp sensor - maybe you need to load the coretemp module"); - } else { + if (sysctlbyname(s.c_str(), &temp, &size, NULL, 0) >= 0) { temp = (temp - 2732) / 10; + if (not got_package) { + p_temp += temp; + found++; + } if (cmp_less(i + 1, current_cpu.temp.size())) { current_cpu.temp.at(i + 1).push_back(temp); if (current_cpu.temp.at(i + 1).size() > 20) @@ -288,6 +293,11 @@ namespace Cpu { } } + if (not got_package) p_temp /= found; + current_cpu.temp.at(0).push_back(p_temp); + if (current_cpu.temp.at(0).size() > 20) + current_cpu.temp.at(0).pop_front(); + } string get_cpuHz() {