Skip to content

Commit 08a92a4

Browse files
committed
CPU (OpenBSD): support CPU temp detection
1 parent d10c147 commit 08a92a4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/detection/cpu/cpu_obsd.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "cpu.h"
22
#include "common/sysctl.h"
33

4+
#include <sys/time.h>
5+
#include <sys/sensors.h>
6+
47
const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
58
{
69
if (ffSysctlGetString(CTL_HW, HW_MODEL, &cpu->name))
@@ -13,7 +16,14 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
1316
ffCPUDetectSpeedByCpuid(cpu);
1417

1518
cpu->frequencyBase = (uint32_t) ffSysctlGetInt(CTL_HW, HW_CPUSPEED, 0);
16-
cpu->temperature = FF_CPU_TEMP_UNSET; // HW_SENSORS?
19+
cpu->temperature = FF_CPU_TEMP_UNSET;
20+
if (options->temp)
21+
{
22+
struct sensor sensors;
23+
size_t size = sizeof(sensors);
24+
if (sysctl((int[]) {CTL_HW, HW_SENSORS, 0, SENSOR_TEMP, 0}, 5, &sensors, &size, NULL, 0) == 0)
25+
cpu->temperature = (double) (sensors.value - 273150000) / 1E6;
26+
}
1727

1828
return NULL;
1929
}

0 commit comments

Comments
 (0)