Skip to content

Commit 4734bd1

Browse files
committed
Linux/LibSensors: adjust data for k10temp
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.
1 parent ecb6a41 commit 4734bd1

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Diff for: linux/LibSensors.c

+40
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,46 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns
233233
}
234234
}
235235

236+
/*
237+
* k10temp, see https://www.kernel.org/doc/html/latest/hwmon/k10temp.html
238+
* temp1 = Tctl, (optional) temp2 = Tdie, temp3..temp10 = Tccd1..8
239+
*/
240+
if (topDriver == TD_K10TEMP) {
241+
/* Display Tdie instead of Tctl if available */
242+
if (!isNaN(data[1]))
243+
data[0] = data[1];
244+
245+
/* Compute number of CCD entries */
246+
unsigned int ccd_entries = 0;
247+
for (size_t i = 2; i <= existingCPUs; i++) {
248+
if (isNaN(data[i]))
249+
break;
250+
251+
ccd_entries++;
252+
}
253+
254+
if (ccd_entries == 0) {
255+
for (size_t i = 1; i <= existingCPUs; i++)
256+
data[i] = data[0];
257+
} else {
258+
assert(ccd_entries <= 16);
259+
float ccd_data[ccd_entries];
260+
for (size_t i = 0; i < ccd_entries; i++)
261+
ccd_data[i] = data[i + 2];
262+
263+
/* Handle threads being listed at the end */
264+
unsigned int ccd_size = existingCPUs / ccd_entries / 2;
265+
266+
for (size_t i = 1; i <= existingCPUs; i++) {
267+
unsigned int index = ((i - 1) / ccd_size) % ccd_entries;
268+
data[i] = ccd_data[index];
269+
}
270+
}
271+
272+
/* No further adjustments */
273+
goto out;
274+
}
275+
236276
/* Adjust data for chips not providing a platform temperature */
237277
if (coreTempCount + 1 == activeCPUs || coreTempCount + 1 == activeCPUs / 2) {
238278
memmove(&data[1], &data[0], existingCPUs * sizeof(*data));

0 commit comments

Comments
 (0)