mirror of https://github.com/aristocratos/btop.git
Cpu temp set to average of pACC and eACC for mac m1
This commit is contained in:
parent
940cd0a513
commit
53c8a0325b
|
@ -170,6 +170,7 @@ namespace Cpu {
|
||||||
string cpuName;
|
string cpuName;
|
||||||
string cpuHz;
|
string cpuHz;
|
||||||
bool has_battery = true;
|
bool has_battery = true;
|
||||||
|
bool macM1 = false;
|
||||||
tuple<int, long, string> current_bat;
|
tuple<int, long, string> current_bat;
|
||||||
|
|
||||||
const array<string, 10> time_names = {"user", "nice", "system", "idle"};
|
const array<string, 10> time_names = {"user", "nice", "system", "idle"};
|
||||||
|
@ -233,8 +234,10 @@ namespace Cpu {
|
||||||
got_sensors = false;
|
got_sensors = false;
|
||||||
if (Config::getB("show_coretemp") and Config::getB("check_temp")) {
|
if (Config::getB("show_coretemp") and Config::getB("check_temp")) {
|
||||||
ThermalSensors sensors;
|
ThermalSensors sensors;
|
||||||
if (sensors.getSensors().size() > 0) {
|
if (sensors.getSensors() > 0) {
|
||||||
got_sensors = true;
|
got_sensors = true;
|
||||||
|
cpu_temp_only = true;
|
||||||
|
macM1 = true;
|
||||||
} else {
|
} else {
|
||||||
// try SMC (intel)
|
// try SMC (intel)
|
||||||
SMCConnection smcCon;
|
SMCConnection smcCon;
|
||||||
|
@ -257,23 +260,12 @@ namespace Cpu {
|
||||||
void update_sensors() {
|
void update_sensors() {
|
||||||
current_cpu.temp_max = 95; // we have no idea how to get the critical temp
|
current_cpu.temp_max = 95; // we have no idea how to get the critical temp
|
||||||
try {
|
try {
|
||||||
ThermalSensors sensors;
|
if (macM1) {
|
||||||
auto sensor = sensors.getSensors();
|
ThermalSensors sensors;
|
||||||
if (sensor.size() > 0) {
|
current_cpu.temp.at(0).push_back(sensors.getSensors());
|
||||||
current_cpu.temp.at(0).push_back((long long)sensor[0]);
|
|
||||||
if (current_cpu.temp.at(0).size() > 20)
|
if (current_cpu.temp.at(0).size() > 20)
|
||||||
current_cpu.temp.at(0).pop_front();
|
current_cpu.temp.at(0).pop_front();
|
||||||
|
|
||||||
if (Config::getB("show_coretemp") and not cpu_temp_only) {
|
|
||||||
for (int core = 1; core <= Shared::coreCount; core++) {
|
|
||||||
long long temp = (long long)sensor[core];
|
|
||||||
if (cmp_less(core, current_cpu.temp.size())) {
|
|
||||||
current_cpu.temp.at(core).push_back(temp);
|
|
||||||
if (current_cpu.temp.at(core).size() > 20)
|
|
||||||
current_cpu.temp.at(core).pop_front();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
SMCConnection smcCon;
|
SMCConnection smcCon;
|
||||||
int threadsPerCore = Shared::coreCount / Shared::physicalCoreCount;
|
int threadsPerCore = Shared::coreCount / Shared::physicalCoreCount;
|
||||||
|
@ -292,6 +284,7 @@ namespace Cpu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (std::runtime_error &e) {
|
} catch (std::runtime_error &e) {
|
||||||
|
got_sensors = false;
|
||||||
Logger::error("failed getting CPU temp");
|
Logger::error("failed getting CPU temp");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1182,19 +1175,19 @@ namespace Proc {
|
||||||
Logger::error("Failed getting CPU load info");
|
Logger::error("Failed getting CPU load info");
|
||||||
}
|
}
|
||||||
cpu_load_info = (processor_cpu_load_info_data_t *)info.info_array;
|
cpu_load_info = (processor_cpu_load_info_data_t *)info.info_array;
|
||||||
cputimes = (cpu_load_info[0].cpu_ticks[CPU_STATE_USER]
|
for (natural_t i = 0; i < cpu_count; i++) {
|
||||||
+ cpu_load_info[0].cpu_ticks[CPU_STATE_NICE]
|
cputimes = (cpu_load_info[i].cpu_ticks[CPU_STATE_USER]
|
||||||
+ cpu_load_info[0].cpu_ticks[CPU_STATE_SYSTEM]
|
+ cpu_load_info[i].cpu_ticks[CPU_STATE_NICE]
|
||||||
+ cpu_load_info[0].cpu_ticks[CPU_STATE_IDLE]);
|
+ cpu_load_info[i].cpu_ticks[CPU_STATE_SYSTEM]
|
||||||
|
+ cpu_load_info[i].cpu_ticks[CPU_STATE_IDLE]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
should_filter = true;
|
should_filter = true;
|
||||||
int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
|
int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
|
||||||
vector<size_t> found;
|
vector<size_t> found;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
struct timeval currentTime;
|
const double timeNow = (time_micros() / 1'000'000);
|
||||||
gettimeofday(¤tTime, NULL);
|
|
||||||
const double timeNow = currentTime.tv_sec + (currentTime.tv_usec / 1'000'000);
|
|
||||||
|
|
||||||
if (sysctl(mib, 4, NULL, &size, NULL, 0) < 0 || size == 0) {
|
if (sysctl(mib, 4, NULL, &size, NULL, 0) < 0 || size == 0) {
|
||||||
Logger::error("Unable to get size of kproc_infos");
|
Logger::error("Unable to get size of kproc_infos");
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
typedef struct __IOHIDEvent *IOHIDEventRef;
|
typedef struct __IOHIDEvent *IOHIDEventRef;
|
||||||
|
@ -54,14 +55,14 @@ double getValue(IOHIDServiceClientRef sc) {
|
||||||
|
|
||||||
} // extern C
|
} // extern C
|
||||||
|
|
||||||
unordered_flat_map<int, double> Cpu::ThermalSensors::getSensors() {
|
long long Cpu::ThermalSensors::getSensors() {
|
||||||
unordered_flat_map<int, double> cpuValues;
|
|
||||||
CFDictionaryRef thermalSensors = matching(0xff00, 5); // 65280_10 = FF00_16
|
CFDictionaryRef thermalSensors = matching(0xff00, 5); // 65280_10 = FF00_16
|
||||||
// thermalSensors's PrimaryUsagePage should be 0xff00 for M1 chip, instead of 0xff05
|
// thermalSensors's PrimaryUsagePage should be 0xff00 for M1 chip, instead of 0xff05
|
||||||
// can be checked by ioreg -lfx
|
// can be checked by ioreg -lfx
|
||||||
IOHIDEventSystemClientRef system = IOHIDEventSystemClientCreate(kCFAllocatorDefault);
|
IOHIDEventSystemClientRef system = IOHIDEventSystemClientCreate(kCFAllocatorDefault);
|
||||||
IOHIDEventSystemClientSetMatching(system, thermalSensors);
|
IOHIDEventSystemClientSetMatching(system, thermalSensors);
|
||||||
CFArrayRef matchingsrvs = IOHIDEventSystemClientCopyServices(system);
|
CFArrayRef matchingsrvs = IOHIDEventSystemClientCopyServices(system);
|
||||||
|
vector<double> temps;
|
||||||
if (matchingsrvs) {
|
if (matchingsrvs) {
|
||||||
long count = CFArrayGetCount(matchingsrvs);
|
long count = CFArrayGetCount(matchingsrvs);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
|
@ -72,19 +73,13 @@ unordered_flat_map<int, double> Cpu::ThermalSensors::getSensors() {
|
||||||
char buf[200];
|
char buf[200];
|
||||||
CFStringGetCString(name, buf, 200, kCFStringEncodingASCII);
|
CFStringGetCString(name, buf, 200, kCFStringEncodingASCII);
|
||||||
std::string n(buf);
|
std::string n(buf);
|
||||||
if (n.starts_with("PMU tdie")) {
|
// this is just a guess, nobody knows which sensors mean what
|
||||||
// this is just a guess, nobody knows which sensors mean what
|
// on my system PMU tdie 3 and 9 are missing...
|
||||||
// on my system PMU tdie 3 and 9 are missing...
|
// there is also PMU tdev1-8 but it has negative values??
|
||||||
// there is also PMU tdev1-8 but it has negative values??
|
// there is also eACC for efficiency package but it only has 2 entries
|
||||||
// there is also eACC for efficiency package but it only has 2 entries
|
// and pACC for performance but it has 7 entries (2 - 9) WTF
|
||||||
// and pACC for performance but it has 7 entries (2 - 9) WTF
|
if (n.starts_with("eACC") or n.starts_with("pACC")) {
|
||||||
std::string indexString = n.substr(8, 1);
|
temps.push_back(getValue(sc));
|
||||||
int index = stoi(indexString);
|
|
||||||
cpuValues[index - 1] = getValue(sc);
|
|
||||||
Logger::debug("T " + n + "=" + std::to_string(cpuValues[index - 1]));
|
|
||||||
} else if (n == "SOC MTR Temp Sensor0") {
|
|
||||||
// package T for Apple Silicon - also a guess
|
|
||||||
cpuValues[0] = getValue(sc);
|
|
||||||
}
|
}
|
||||||
CFRelease(name);
|
CFRelease(name);
|
||||||
}
|
}
|
||||||
|
@ -94,5 +89,6 @@ unordered_flat_map<int, double> Cpu::ThermalSensors::getSensors() {
|
||||||
}
|
}
|
||||||
CFRelease(system);
|
CFRelease(system);
|
||||||
CFRelease(thermalSensors);
|
CFRelease(thermalSensors);
|
||||||
return cpuValues;
|
if (temps.empty()) return 0ll;
|
||||||
|
return round(std::accumulate(temps.begin(), temps.end(), 0ll) / temps.size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
#include <robin_hood.h>
|
|
||||||
|
|
||||||
using robin_hood::unordered_flat_map;
|
|
||||||
|
|
||||||
namespace Cpu {
|
namespace Cpu {
|
||||||
class ThermalSensors {
|
class ThermalSensors {
|
||||||
public:
|
public:
|
||||||
unordered_flat_map<int, double> getSensors();
|
long long getSensors();
|
||||||
};
|
};
|
||||||
} // namespace Cpu
|
} // namespace Cpu
|
||||||
|
|
Loading…
Reference in New Issue