diff --git a/CMakeLists.txt b/CMakeLists.txt index 88f9eb0ae..2ac35be9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1103,7 +1103,7 @@ elseif(Haiku) src/detection/brightness/brightness_nosupport.c src/detection/btrfs/btrfs_nosupport.c src/detection/chassis/chassis_nosupport.c - src/detection/cpu/cpu_nosupport.c + src/detection/cpu/cpu_haiku.c src/detection/cpucache/cpucache_nosupport.c src/detection/cpuusage/cpuusage_nosupport.c src/detection/cursor/cursor_nosupport.c diff --git a/src/detection/cpu/cpu_haiku.c b/src/detection/cpu/cpu_haiku.c new file mode 100644 index 000000000..ec993a05c --- /dev/null +++ b/src/detection/cpu/cpu_haiku.c @@ -0,0 +1,64 @@ +#include "cpu.h" +#include "util/mallocHelper.h" + +#include +#include + +const char* ffDetectCPUImpl(FF_MAYBE_UNUSED const FFCPUOptions* options, FFCPUResult* cpu) +{ + system_info sysInfo; + if (get_system_info(&sysInfo) != B_OK) + return "get_system_info() failed"; + + uint32_t topoNodeCount = 0; + get_cpu_topology_info(NULL, &topoNodeCount); + if (topoNodeCount == 0) + return "get_cpu_topology_info(NULL) failed"; + + FF_AUTO_FREE cpu_topology_node_info* topology = malloc(sizeof(*topology) * topoNodeCount); + if (get_cpu_topology_info(topology, &topoNodeCount) != B_OK) + return "get_cpu_topology_info(topology) failed"; + + enum cpu_platform platform = B_CPU_UNKNOWN; + enum cpu_vendor cpuVendor = B_CPU_VENDOR_UNKNOWN; + uint32 cpuModel = 0, frequency = 0; + uint16_t packages = 0, cores = 0; + + for (uint32 i = 0; i < topoNodeCount; i++) + { + switch (topology[i].type) { + case B_TOPOLOGY_ROOT: + platform = topology[i].data.root.platform; + break; + + case B_TOPOLOGY_PACKAGE: + cpuVendor = topology[i].data.package.vendor; + ++packages; + break; + + case B_TOPOLOGY_CORE: + cpuModel = topology[i].data.core.model; + uint32_t freq = (uint32_t) (topology[i].data.core.default_frequency / 1000000); + frequency = freq > frequency ? freq : frequency; + ++cores; + break; + + default: + break; + } + } + + const char *model = get_cpu_model_string(platform, cpuVendor, cpuModel); + if (model) + ffStrbufSetS(&cpu->name, model); + else + ffStrbufSetF(&cpu->name, "(Unknown %" B_PRIx32 ")", cpuModel); + ffStrbufSetS(&cpu->vendor, get_cpu_vendor_string(cpuVendor)); + + ffCPUDetectSpeedByCpuid(cpu); + if (cpu->frequencyBase < frequency) cpu->frequencyBase = frequency; + cpu->packages = packages; + cpu->coresPhysical = cores; + cpu->coresOnline = cpu->coresLogical = (uint16_t) sysInfo.cpu_count; + return NULL; +}