Skip to content

Commit 17e3853

Browse files
committed
CPU (FreeBSD): bind process to the first 2 cores
1 parent 1bc41df commit 17e3853

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/detection/cpu/cpu_bsd.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "cpu.h"
22
#include "common/sysctl.h"
33

4+
#include <sys/param.h>
5+
#include <sys/cpuset.h>
6+
47
static const char* detectCpuTemp(double* current)
58
{
69
int temp = ffSysctlGetInt("dev.cpu.0.temperature", -999999);
@@ -60,9 +63,18 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
6063
}
6164
}
6265

66+
#if __x86_64__ || __i386__
67+
// Bind current process to the first two cores, which is *usually* a performance core
68+
cpuset_t currentCPU;
69+
CPU_ZERO(&currentCPU);
70+
CPU_SET(1, &currentCPU);
71+
CPU_SET(2, &currentCPU);
72+
cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset_t), &currentCPU);
6373
ffCPUDetectSpeedByCpuid(cpu);
74+
#endif
6475

65-
cpu->frequencyBase = (uint32_t) ffSysctlGetInt("hw.clockrate", 0);
76+
uint32_t clockrate = (uint32_t) ffSysctlGetInt("hw.clockrate", 0);
77+
if (clockrate > cpu->frequencyBase) cpu->frequencyBase = clockrate;
6678
cpu->temperature = FF_CPU_TEMP_UNSET;
6779

6880
if (options->temp)

0 commit comments

Comments
 (0)