CPU (NetBSD): add support

This commit is contained in:
Carter Li
2024-10-30 23:29:05 +08:00
parent 3f41306c91
commit 229d5f899c
3 changed files with 58 additions and 6 deletions
+1 -1
View File
@@ -682,7 +682,7 @@ elseif(NetBSD)
src/detection/brightness/brightness_bsd.c
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_nbsd.c
src/detection/cpu/cpu_bsd.c
src/detection/cpu/cpu_nbsd.c
src/detection/cpucache/cpucache_nosupport.c
src/detection/cpuusage/cpuusage_bsd.c
src/detection/cursor/cursor_linux.c
-5
View File
@@ -25,13 +25,8 @@ static const char* detectThermalTemp(double* current)
const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
{
#if __NetBSD__
if (ffSysctlGetString("machdep.cpu_brand", &cpu->name) != NULL)
return "sysctlbyname(machdep.cpu_brand) failed";
#else
if (ffSysctlGetString("hw.model", &cpu->name) != NULL)
return "sysctlbyname(hw.model) failed";
#endif
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1);
cpu->coresLogical = cpu->coresPhysical;
+57
View File
@@ -0,0 +1,57 @@
#include "cpu.h"
#include "common/sysctl.h"
#include <sys/sysctl.h>
static const char* detectCpuTemp(double* current)
{
int temp = ffSysctlGetInt("dev.cpu.0.temperature", -999999);
if (temp == -999999)
return "ffSysctlGetInt(\"dev.cpu.0.temperature\") failed";
// In tenth of degrees Kelvin
*current = (double) temp / 10 - 273.15;
return NULL;
}
static const char* detectThermalTemp(double* current)
{
int temp = ffSysctlGetInt("hw.acpi.thermal.tz0.temperature", -999999);
if (temp == -999999)
return "ffSysctlGetInt(\"hw.acpi.thermal.tz0.temperature\") failed";
// In tenth of degrees Kelvin
*current = (double) temp / 10 - 273.15;
return NULL;
}
const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
{
if (ffSysctlGetString("machdep.cpu_brand", &cpu->name) != NULL)
{
if (ffSysctlGetString("machdep.dmi.processor-version", &cpu->name) != NULL)
return "sysctlbyname(machdep.cpu_brand) failed";
}
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1);
cpu->coresLogical = cpu->coresPhysical;
cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.ncpuonline", cpu->coresLogical);
ffCPUDetectSpeedByCpuid(cpu);
{
struct clockinfo info;
size_t length = sizeof(info);
if (sysctl((int[]) {CTL_KERN, KERN_CLOCKRATE}, 2, &info, &length, NULL, 0) == 0)
cpu->frequencyBase = (uint32_t) info.hz / 1000;
}
cpu->temperature = FF_CPU_TEMP_UNSET;
if (options->temp)
{
if (detectCpuTemp(&cpu->temperature) != NULL)
detectThermalTemp(&cpu->temperature);
}
return NULL;
}