Skip to content

Commit

Permalink
linux: assign CPU temperatures by package/core or CCD
Browse files Browse the repository at this point in the history
Closes htop-dev#806.
Closes htop-dev#1048.
Closes htop-dev#1176.
Closes htop-dev#1335.
Addresses htop-dev#879 (on Linux).
  • Loading branch information
leahneukirchen committed Dec 25, 2023
1 parent 25c42cb commit f61c2d0
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions linux/LibSensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns
unsigned int coreTempCount = 0;
int topPriority = 99;

int ccdID = 0;

int n = 0;
for (const sensors_chip_name* chip = sym_sensors_get_detected_chips(NULL, &n); chip; chip = sym_sensors_get_detected_chips(NULL, &n)) {
const int priority = tempDriverPriority(chip);
Expand All @@ -240,6 +242,8 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns

topPriority = priority;

int physicalID = -1;

int m = 0;
for (const sensors_feature* feature = sym_sensors_get_features(chip, &m); feature; feature = sym_sensors_get_features(chip, &m)) {
if (feature->type != SENSORS_FEATURE_TEMP)
Expand Down Expand Up @@ -267,6 +271,38 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns
if (r != 0)
continue;

char *label = sym_sensors_get_label(chip, feature);
if (label) {
/* Intel coretemp names, labels mention package and phyiscal id */
if (String_startsWith(label, "Package id ")) {
physicalID = strtoul(label + strlen("Package id "), NULL, 10);
} else if (String_startsWith(label, "Physical id ")) {
physicalID = strtoul(label + strlen("Physical id "), NULL, 10);
} else if (String_startsWith(label, "Core ")) {
unsigned long int coreID = strtoul(label + strlen("Core "), NULL, 10);
for (size_t i = 1; i < existingCPUs + 1; i++) {
if (cpus[i].physicalID == physicalID && cpus[i].coreID == coreID) {
data[i] = temp;
coreTempCount++;
}
}
}

/* AMD k10temp/zenpower names, only CCD is known */
else if (String_startsWith(label, "Tccd")) {
for (size_t i = 1; i <= existingCPUs; i++) {
if (cpus[i].ccdID == ccdID) {
data[i] = temp;
coreTempCount++;
}
}
ccdID++;
}

free(label);
continue;
}

/* If already set, e.g. Ryzen reporting platform temperature for each die, use the bigger one */
if (isNaN(data[tempID])) {
data[tempID] = temp;
Expand Down

0 comments on commit f61c2d0

Please sign in to comment.