Skip to content

Commit 229d5f8

Browse files
committed
CPU (NetBSD): add support
1 parent 3f41306 commit 229d5f8

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ elseif(NetBSD)
682682
src/detection/brightness/brightness_bsd.c
683683
src/detection/btrfs/btrfs_nosupport.c
684684
src/detection/chassis/chassis_nbsd.c
685-
src/detection/cpu/cpu_bsd.c
685+
src/detection/cpu/cpu_nbsd.c
686686
src/detection/cpucache/cpucache_nosupport.c
687687
src/detection/cpuusage/cpuusage_bsd.c
688688
src/detection/cursor/cursor_linux.c

src/detection/cpu/cpu_bsd.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,8 @@ static const char* detectThermalTemp(double* current)
2525

2626
const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
2727
{
28-
#if __NetBSD__
29-
if (ffSysctlGetString("machdep.cpu_brand", &cpu->name) != NULL)
30-
return "sysctlbyname(machdep.cpu_brand) failed";
31-
#else
3228
if (ffSysctlGetString("hw.model", &cpu->name) != NULL)
3329
return "sysctlbyname(hw.model) failed";
34-
#endif
3530

3631
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1);
3732
cpu->coresLogical = cpu->coresPhysical;

src/detection/cpu/cpu_nbsd.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "cpu.h"
2+
#include "common/sysctl.h"
3+
#include <sys/sysctl.h>
4+
5+
static const char* detectCpuTemp(double* current)
6+
{
7+
int temp = ffSysctlGetInt("dev.cpu.0.temperature", -999999);
8+
if (temp == -999999)
9+
return "ffSysctlGetInt(\"dev.cpu.0.temperature\") failed";
10+
11+
// In tenth of degrees Kelvin
12+
*current = (double) temp / 10 - 273.15;
13+
return NULL;
14+
}
15+
16+
static const char* detectThermalTemp(double* current)
17+
{
18+
int temp = ffSysctlGetInt("hw.acpi.thermal.tz0.temperature", -999999);
19+
if (temp == -999999)
20+
return "ffSysctlGetInt(\"hw.acpi.thermal.tz0.temperature\") failed";
21+
22+
// In tenth of degrees Kelvin
23+
*current = (double) temp / 10 - 273.15;
24+
return NULL;
25+
}
26+
27+
const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
28+
{
29+
if (ffSysctlGetString("machdep.cpu_brand", &cpu->name) != NULL)
30+
{
31+
if (ffSysctlGetString("machdep.dmi.processor-version", &cpu->name) != NULL)
32+
return "sysctlbyname(machdep.cpu_brand) failed";
33+
}
34+
35+
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1);
36+
cpu->coresLogical = cpu->coresPhysical;
37+
cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.ncpuonline", cpu->coresLogical);
38+
39+
ffCPUDetectSpeedByCpuid(cpu);
40+
41+
{
42+
struct clockinfo info;
43+
size_t length = sizeof(info);
44+
if (sysctl((int[]) {CTL_KERN, KERN_CLOCKRATE}, 2, &info, &length, NULL, 0) == 0)
45+
cpu->frequencyBase = (uint32_t) info.hz / 1000;
46+
}
47+
48+
cpu->temperature = FF_CPU_TEMP_UNSET;
49+
50+
if (options->temp)
51+
{
52+
if (detectCpuTemp(&cpu->temperature) != NULL)
53+
detectThermalTemp(&cpu->temperature);
54+
}
55+
56+
return NULL;
57+
}

0 commit comments

Comments
 (0)