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 #806.
Closes #1048.
Closes #1176.
Closes #1335.
Addresses #879 (on Linux).
  • Loading branch information
leahneukirchen committed Dec 25, 2023
1 parent ad4c95b commit d4cb5d1
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 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,42 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns
if (r != 0)
continue;

char *label = sym_sensors_get_label(chip, feature);
if (label) {
int skip = 1;
/* 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 ")) {
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++;
} else {
skip = 0;
}

free(label);
if (skip)
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 d4cb5d1

Please sign in to comment.