Skip to content

Commit

Permalink
Linux/LibSensors: adjust data for k10temp
Browse files Browse the repository at this point in the history
Adjust the temperature data gathered from the k10temp driver.  Only a
control value, an optional die value, and one value per CCD are
provided.

See https://www.kernel.org/doc/html/latest/hwmon/k10temp.html for
details.
  • Loading branch information
cgzones committed Aug 19, 2023
1 parent b650de8 commit 517adf2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions linux/LibSensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,45 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns
}
}

/*
* k10temp, see https://www.kernel.org/doc/html/latest/hwmon/k10temp.html
* temp1 = Tctl, (optional) temp2 = Tdie, temp3..temp10 = Tccd1..8
*/
if (topDriver == TD_K10TEMP) {
/* Display Tdie instead of Tctl if available */
if (!isnan(data[1]))
data[0] = data[1];

/* Compute number of CCD entries */
unsigned int ccd_entries = 0;
for (size_t i = 2; i <= existingCPUs; i++) {
if (isnan(data[i]))
break;

ccd_entries++;
}

if (ccd_entries == 0) {
for (size_t i = 1; i <= existingCPUs; i++)
data[i] = data[0];
} else {
float ccd_data[ccd_entries];
for (size_t i = 0; i < ccd_entries; i++)
ccd_data[i] = data[i + 2];

/* Handle threads being listed at the end */
unsigned int ccd_size = existingCPUs / ccd_entries / 2;

for (size_t i = 1; i <= existingCPUs; i++) {
unsigned int index = ((i - 1) / ccd_size) % ccd_entries;
data[i] = ccd_data[index];
}
}

/* No further adjustments */
goto out;
}

/* Adjust data for chips not providing a platform temperature */
if (coreTempCount + 1 == activeCPUs || coreTempCount + 1 == activeCPUs / 2) {
memmove(&data[1], &data[0], existingCPUs * sizeof(*data));
Expand Down

0 comments on commit 517adf2

Please sign in to comment.