Skip to content

Commit 557a88a

Browse files
committed
porting the feature for FreeBSD < 13.1 and testing the build on CI.
Above, it uses the same api as Linux.
1 parent 4215542 commit 557a88a

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ strings.h \
406406
sched.h \
407407
syslog.h \
408408
sysexits.h \
409+
sys/cpuset.h \
409410
sys/ioctl.h \
410411
sys/file.h \
411412
sys/mman.h \
@@ -569,6 +570,7 @@ AC_CHECK_FUNCS(
569570
alphasort \
570571
asctime_r \
571572
chroot \
573+
cpuset_setaffinity \
572574
ctime_r \
573575
explicit_memset \
574576
fdatasync \

sapi/fpm/fpm/fpm_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
# define HAVE_FPM_LQ 0
7777
#endif
7878

79-
#if defined(HAVE_SCHED_SETAFFINITY)
79+
#if defined(HAVE_SCHED_SETAFFINITY) || defined(HAVE_CPUSET_SETAFFINITY)
8080
/*
8181
* to expand to other platforms capable of this granularity (some BSD, solaris, ...).
8282
* macOS is a specific case with an api working fine on intel architecture

sapi/fpm/fpm/fpm_unix.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
#include <sched.h>
4040
#endif
4141

42+
#ifdef HAVE_SYS_CPUSET_H
43+
#include <sys/cpuset.h>
44+
typedef cpuset_t cpu_set_t;
45+
#endif
46+
4247
#include "fpm.h"
4348
#include "fpm_conf.h"
4449
#include "fpm_cleanup.h"
@@ -393,7 +398,7 @@ static int fpm_cpusrange(char *cpumask, int *min, int *max) {
393398

394399
static int fpm_setcpuaffinity(int min, int max)
395400
{
396-
#ifdef HAVE_SCHED_SETAFFINITY
401+
#if defined(HAVE_SCHED_SETAFFINITY) || defined(HAVE_CPUSET_SETAFFINITY)
397402
cpu_set_t cset;
398403
int i;
399404

@@ -404,7 +409,11 @@ static int fpm_setcpuaffinity(int min, int max)
404409
}
405410
}
406411

412+
#if defined(HAVE_SCHED_SETAFFINITY)
407413
return sched_setaffinity(0, sizeof(cset), &cset);
414+
#else
415+
return cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(cset), &cset);
416+
#endif
408417
#endif
409418
}
410419
#endif

0 commit comments

Comments
 (0)