Skip to content

Commit e7df944

Browse files
committed
Temp (FreeBSD): improve CPU temp detection
1 parent 42f6d02 commit e7df944

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/detection/cpu/cpu_bsd.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
1616
cpu->temperature = FF_CPU_TEMP_UNSET;
1717

1818
if (options->temp)
19-
ffDetectThermalTemp(&cpu->temperature);
19+
{
20+
if (!ffDetectCpuTemp(&cpu->temperature))
21+
ffDetectThermalTemp(&cpu->temperature);
22+
}
2023

2124
return NULL;
2225
}

src/detection/temps/temps_bsd.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
#include "temps_bsd.h"
22
#include "common/sysctl.h"
33

4+
const char* ffDetectCpuTemp(double* current)
5+
{
6+
int temp = ffSysctlGetInt("dev.cpu.0.temperature", -999999);
7+
if (temp == -999999)
8+
return "ffSysctlGetInt(\"dev.cpu.0.temperature\") failed";
9+
10+
// In tenth of degrees Celsius
11+
*current = (double) temp / 10;
12+
return NULL;
13+
}
14+
415
const char* ffDetectThermalTemp(double* current)
516
{
617
int temp = ffSysctlGetInt("hw.acpi.thermal.tz0.temperature", -999999);

src/detection/temps/temps_bsd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#ifndef FF_INCLUDED_detection_temps_windows
44
#define FF_INCLUDED_detection_temps_windows
55

6+
const char* ffDetectCpuTemp(double* current);
67
const char* ffDetectThermalTemp(double* current);
78

89
#endif

0 commit comments

Comments
 (0)