2022-09-19 22:23:31 +02:00
|
|
|
#include "cpu.h"
|
2022-09-19 23:16:43 +02:00
|
|
|
#include "common/sysctl.h"
|
2023-06-22 04:06:08 +00:00
|
|
|
#include "detection/temps/temps_bsd.h"
|
2022-09-19 22:23:31 +02:00
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
|
2022-09-19 22:23:31 +02:00
|
|
|
{
|
2023-06-12 09:56:03 +08:00
|
|
|
if (ffSysctlGetString("hw.model", &cpu->name))
|
|
|
|
|
return "sysctlbyname(hw.model) failed";
|
2022-09-24 15:59:36 +02:00
|
|
|
|
2023-06-12 09:56:03 +08:00
|
|
|
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1);
|
|
|
|
|
cpu->coresLogical = cpu->coresPhysical;
|
2024-09-06 15:37:37 +08:00
|
|
|
cpu->coresOnline = (uint16_t) ffSysctlGetInt("kern.smp.cpus", cpu->coresLogical);
|
2023-06-12 09:56:03 +08:00
|
|
|
|
2024-05-18 08:24:46 +08:00
|
|
|
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
|
|
|
|
if (ffSysctlGetString("kern.sched.topology_spec", &buffer) == NULL && buffer.length > 0)
|
|
|
|
|
{
|
|
|
|
|
// <groups>
|
|
|
|
|
// <group level="1" cache-level="3">
|
|
|
|
|
// <cpu count="4" mask="f,0,0,0">0, 1, 2, 3</cpu>
|
|
|
|
|
// <children>
|
|
|
|
|
// <group level="2" cache-level="2">
|
|
|
|
|
// <cpu count="2" mask="3,0,0,0">0, 1</cpu>
|
|
|
|
|
// <flags><flag name="THREAD">THREAD group</flag><flag name="SMT">SMT group</flag></flags>
|
|
|
|
|
// </group>
|
|
|
|
|
// <group level="2" cache-level="2">
|
|
|
|
|
// <cpu count="2" mask="c,0,0,0">2, 3</cpu>
|
|
|
|
|
// <flags><flag name="THREAD">THREAD group</flag><flag name="SMT">SMT group</flag></flags>
|
|
|
|
|
// </group>
|
|
|
|
|
// </children>
|
|
|
|
|
// </group>
|
|
|
|
|
// </groups>
|
|
|
|
|
uint32_t i = 0;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
i = ffStrbufNextIndexS(&buffer, i, "<flag name=\"THREAD\">THREAD group</flag>"); // Find physical core with hyper-threading enabled
|
|
|
|
|
if (i >= buffer.length) break;
|
|
|
|
|
cpu->coresPhysical--;
|
|
|
|
|
i += (uint32_t) strlen("<flag name=\"THREAD\">THREAD group</flag>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-18 17:26:53 +08:00
|
|
|
ffCPUDetectSpeedByCpuid(cpu);
|
|
|
|
|
|
2024-07-17 10:56:30 +08:00
|
|
|
cpu->frequencyBase = (uint32_t) ffSysctlGetInt("hw.clockrate", 0);
|
2023-06-22 04:06:08 +00:00
|
|
|
cpu->temperature = FF_CPU_TEMP_UNSET;
|
2023-06-12 09:56:03 +08:00
|
|
|
|
|
|
|
|
if (options->temp)
|
2023-10-10 09:28:31 +08:00
|
|
|
{
|
2024-09-14 21:53:43 +08:00
|
|
|
if (ffDetectCpuTemp(&cpu->temperature) != NULL)
|
2023-10-10 09:28:31 +08:00
|
|
|
ffDetectThermalTemp(&cpu->temperature);
|
|
|
|
|
}
|
2022-09-24 15:59:36 +02:00
|
|
|
|
2023-06-12 09:56:03 +08:00
|
|
|
return NULL;
|
2022-09-19 22:23:31 +02:00
|
|
|
}
|