Skip to content

Commit 3a9f468

Browse files
leahneukirchenBenBE
authored andcommitted
linux: assign CPU temperatures by package/core or CCD
Closes #806. Closes #1048. Closes #1176. Closes #1335. Addresses #879 (on Linux).
1 parent c079bcc commit 3a9f468

1 file changed

Lines changed: 45 additions & 3 deletions

File tree

linux/LibSensors.c

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ in the source distribution for its full text.
1616
#include <errno.h>
1717
#include <limits.h>
1818
#include <math.h>
19+
#include <stdbool.h>
1920
#include <stdio.h>
2021
#include <stdlib.h>
2122
#include <string.h>
@@ -206,6 +207,8 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns
206207
unsigned int coreTempCount = 0;
207208
int topPriority = 99;
208209

210+
int ccdID = 0;
211+
209212
int n = 0;
210213
for (const sensors_chip_name* chip = sym_sensors_get_detected_chips(NULL, &n); chip; chip = sym_sensors_get_detected_chips(NULL, &n)) {
211214
const int priority = tempDriverPriority(chip);
@@ -223,6 +226,8 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns
223226

224227
topPriority = priority;
225228

229+
int physicalID = -1;
230+
226231
int m = 0;
227232
for (const sensors_feature* feature = sym_sensors_get_features(chip, &m); feature; feature = sym_sensors_get_features(chip, &m)) {
228233
if (feature->type != SENSORS_FEATURE_TEMP)
@@ -238,9 +243,6 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns
238243
/* Feature name IDs start at 1, adjust to start at 0 to match data indices */
239244
tempID--;
240245

241-
if (tempID > existingCPUs)
242-
continue;
243-
244246
const sensors_subfeature* subFeature = sym_sensors_get_subfeature(chip, feature, SENSORS_SUBFEATURE_TEMP_INPUT);
245247
if (!subFeature)
246248
continue;
@@ -291,6 +293,46 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns
291293
}
292294
}
293295

296+
char *label = sym_sensors_get_label(chip, feature);
297+
if (label) {
298+
bool skip = true;
299+
/* Intel coretemp names, labels mention package and phyiscal id */
300+
if (String_startsWith(label, "Package id ")) {
301+
physicalID = strtoul(label + strlen("Package id "), NULL, 10);
302+
} else if (String_startsWith(label, "Physical id ")) {
303+
physicalID = strtoul(label + strlen("Physical id "), NULL, 10);
304+
} else if (String_startsWith(label, "Core ")) {
305+
int coreID = strtoul(label + strlen("Core "), NULL, 10);
306+
for (size_t i = 1; i < existingCPUs + 1; i++) {
307+
if (cpus[i].physicalID == physicalID && cpus[i].coreID == coreID) {
308+
data[i] = temp;
309+
coreTempCount++;
310+
}
311+
}
312+
}
313+
314+
/* AMD k10temp/zenpower names, only CCD is known */
315+
else if (String_startsWith(label, "Tccd")) {
316+
for (size_t i = 1; i <= existingCPUs; i++) {
317+
if (cpus[i].ccdID == ccdID) {
318+
data[i] = temp;
319+
coreTempCount++;
320+
}
321+
}
322+
ccdID++;
323+
} else {
324+
skip = false;
325+
}
326+
327+
free(label);
328+
329+
if (skip)
330+
continue;
331+
}
332+
333+
if (tempID > existingCPUs)
334+
continue;
335+
294336
/* If already set, e.g. Ryzen reporting platform temperature for each die, use the bigger one */
295337
if (isNaN(data[tempID])) {
296338
data[tempID] = temp;

0 commit comments

Comments
 (0)