MINOR: init: Fix CPU affinity setting on FreeBSD.

Use a cpuset_t instead of assuming the cpu mask is an unsigned long.
This should fix setting the CPU affinity on FreeBSD >= 11.

This patch should be backported to stable releases.
This commit is contained in:
Olivier Houchard 2017-08-16 17:29:11 +02:00 committed by Willy Tarreau
parent 0d00593361
commit 97148f60b8

View File

@ -2558,7 +2558,18 @@ int main(int argc, char **argv)
proc < LONGBITS && /* only the first 32/64 processes may be pinned */ proc < LONGBITS && /* only the first 32/64 processes may be pinned */
global.cpu_map[proc]) /* only do this if the process has a CPU map */ global.cpu_map[proc]) /* only do this if the process has a CPU map */
#ifdef __FreeBSD__ #ifdef __FreeBSD__
cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(unsigned long), (void *)&global.cpu_map[proc]); {
cpuset_t cpuset;
int i;
unsigned long cpu_map = global.cpu_map[proc];
CPU_ZERO(&cpuset);
while ((i = ffsl(cpu_map)) > 0) {
CPU_SET(i - 1, &cpuset);
cpu_map &= ~(1 << (i - 1));
}
ret = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(cpuset), &cpuset);
}
#else #else
sched_setaffinity(0, sizeof(unsigned long), (void *)&global.cpu_map[proc]); sched_setaffinity(0, sizeof(unsigned long), (void *)&global.cpu_map[proc]);
#endif #endif