fix: cpu temperature AMD

This commit is contained in:
Sebastian Hildebrandt 2025-12-22 22:00:26 +01:00
parent 61608655a7
commit 8bcc01bc51

View File

@ -1181,13 +1181,13 @@ function cpuTemperature(callback) {
const cmd =
'for mon in /sys/class/hwmon/hwmon*; do for label in "$mon"/temp*_label; do if [ -f $label ]; then value=${label%_*}_input; echo $(cat "$label")___$(cat "$value"); fi; done; done;';
try {
exec(cmd, function (error, stdout) {
exec(cmd, (error, stdout) => {
stdout = stdout.toString();
const tdiePos = stdout.toLowerCase().indexOf('tdie');
if (tdiePos !== -1) {
stdout = stdout.substring(tdiePos);
}
let lines = stdout.split('\n');
const lines = stdout.split('\n');
let tctl = 0;
lines.forEach((line) => {
const parts = line.split('___');
@ -1223,13 +1223,13 @@ function cpuTemperature(callback) {
resolve(result);
return;
}
exec('sensors', function (error, stdout) {
exec('sensors', (error, stdout) => {
if (!error) {
let lines = stdout.toString().split('\n');
const lines = stdout.toString().split('\n');
let tdieTemp = null;
let newSectionStarts = true;
let section = '';
lines.forEach(function (line) {
lines.forEach((line) => {
// determine section
if (line.trim() === '') {
newSectionStarts = true;
@ -1243,11 +1243,14 @@ function cpuTemperature(callback) {
if (line.trim().toLowerCase().startsWith('core')) {
section = 'core';
}
if (line.trim().toLowerCase().startsWith('k10temp')) {
section = 'coreAMD';
}
newSectionStarts = false;
}
let regex = /[+-]([^°]*)/g;
let temps = line.match(regex);
let firstPart = line.split(':')[0].toUpperCase();
const regex = /[+-]([^°]*)/g;
const temps = line.match(regex);
const firstPart = line.split(':')[0].toUpperCase();
if (section === 'acpi') {
// socket temp
if (firstPart.indexOf('TEMP') !== -1) {
@ -1260,7 +1263,7 @@ function cpuTemperature(callback) {
}
}
// cpu temp
if (firstPart.indexOf('PHYSICAL') !== -1 || firstPart.indexOf('PACKAGE') !== -1) {
if (firstPart.indexOf('PHYSICAL') !== -1 || firstPart.indexOf('PACKAGE') !== -1 || (section === 'coreAMD' && firstPart.indexOf('TDIE') !== -1) || firstPart.indexOf('TEMP') !== -1) {
result.main = parseFloat(temps);
}
if (firstPart.indexOf('CORE ') !== -1) {
@ -1288,11 +1291,11 @@ function cpuTemperature(callback) {
return;
}
}
fs.stat('/sys/class/thermal/thermal_zone0/temp', function (err) {
fs.stat('/sys/class/thermal/thermal_zone0/temp', (err) => {
if (err === null) {
fs.readFile('/sys/class/thermal/thermal_zone0/temp', function (error, stdout) {
fs.readFile('/sys/class/thermal/thermal_zone0/temp', (error, stdout) => {
if (!error) {
let lines = stdout.toString().split('\n');
const lines = stdout.toString().split('\n');
if (lines.length > 0) {
result.main = parseFloat(lines[0]) / 1000.0;
result.max = result.main;
@ -1304,9 +1307,9 @@ function cpuTemperature(callback) {
resolve(result);
});
} else {
exec('/opt/vc/bin/vcgencmd measure_temp', function (error, stdout) {
exec('/opt/vc/bin/vcgencmd measure_temp', (error, stdout) => {
if (!error) {
let lines = stdout.toString().split('\n');
const lines = stdout.toString().split('\n');
if (lines.length > 0 && lines[0].indexOf('=')) {
result.main = parseFloat(lines[0].split('=')[1]);
result.max = result.main;
@ -1329,11 +1332,11 @@ function cpuTemperature(callback) {
}
}
if (_freebsd || _openbsd || _netbsd) {
exec('sysctl dev.cpu | grep temp', function (error, stdout) {
exec('sysctl dev.cpu | grep temp', (error, stdout) => {
if (!error) {
let lines = stdout.toString().split('\n');
let sum = 0;
lines.forEach(function (line) {
lines.forEach((line) => {
const parts = line.split(':');
if (parts.length > 1) {
const temp = parseFloat(parts[1].replace(',', '.'));