CPU (FreeBSD): bind process to the first 2 cores

This commit is contained in:
李通洲
2025-01-04 18:42:04 +08:00
parent 1bc41dfa54
commit 17e3853f38
+13 -1
View File
@@ -1,6 +1,9 @@
#include "cpu.h"
#include "common/sysctl.h"
#include <sys/param.h>
#include <sys/cpuset.h>
static const char* detectCpuTemp(double* current)
{
int temp = ffSysctlGetInt("dev.cpu.0.temperature", -999999);
@@ -60,9 +63,18 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
}
}
#if __x86_64__ || __i386__
// Bind current process to the first two cores, which is *usually* a performance core
cpuset_t currentCPU;
CPU_ZERO(&currentCPU);
CPU_SET(1, &currentCPU);
CPU_SET(2, &currentCPU);
cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset_t), &currentCPU);
ffCPUDetectSpeedByCpuid(cpu);
#endif
cpu->frequencyBase = (uint32_t) ffSysctlGetInt("hw.clockrate", 0);
uint32_t clockrate = (uint32_t) ffSysctlGetInt("hw.clockrate", 0);
if (clockrate > cpu->frequencyBase) cpu->frequencyBase = clockrate;
cpu->temperature = FF_CPU_TEMP_UNSET;
if (options->temp)