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