Skip to content

Commit ab0bc74

Browse files
committed
build
1 parent db3e622 commit ab0bc74

File tree

6 files changed

+48
-56
lines changed

6 files changed

+48
-56
lines changed

sapi/fpm/fpm/fpm_unix.c

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,6 @@ static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */
432432
/* }}} */
433433

434434
#if HAVE_FPM_CPUAFFINITY
435-
struct fpm_cpuaffinity_conf {
436-
cpu_set_t cset;
437-
long min;
438-
long max;
439-
};
440-
441435
static long fpm_cpumax(void)
442436
{
443437
static long cpuid = LONG_MIN;
@@ -457,71 +451,69 @@ static long fpm_cpumax(void)
457451
return cpuid;
458452
}
459453

460-
static void fpm_cpuaffinity_init(struct fpm_cpuaffinity_conf *c)
454+
static void fpm_cpuaffinity_init(cpu_set_t *c)
461455
{
462-
CPU_ZERO(&c->cset);
456+
CPU_ZERO(c);
463457
}
464458

465-
static void fpm_cpuaffinity_add(struct fpm_cpuaffinity_conf *c)
459+
static void fpm_cpuaffinity_add(cpu_set_t *c, int min, int max)
466460
{
467-
#if defined(HAVE_FPM_CPUAFFINITY)
468461
int i;
469462

470-
for (i = c->min; i <= c->max; i ++) {
471-
if (!CPU_ISSET(i, &c->cset)) {
472-
CPU_SET(i, &c->cset);
463+
for (i = min; i <= max; i ++) {
464+
if (!CPU_ISSET(i, c)) {
465+
CPU_SET(i, c);
473466
}
474467
}
475-
#endif
476468
}
477469

478-
static int fpm_cpuaffinity_set(struct fpm_cpuaffinity_conf *c)
470+
static int fpm_cpuaffinity_set(cpu_set_t *c)
479471
{
480472
#if defined(HAVE_SCHED_SETAFFINITY)
481-
return sched_setaffinity(0, sizeof(c->cset), &c->cset);
473+
return sched_setaffinity(0, sizeof(c), c);
482474
#elif defined(HAVE_CPUSET_SETAFFINITY)
483-
return cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(c->cset), &c->cset);
475+
return cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(c), c);
484476
#endif
485477
}
486478

487479
static int fpm_setcpuaffinity(char *cpu_list)
488480
{
489481
char *token, *buf;
490-
struct fpm_cpuaffinity_conf fconf;
491-
int r, cpumax;
482+
cpu_set_t c;
483+
int r, cpumax, min, max;
492484

493485
r = -1;
494486
cpumax = fpm_cpumax();
495487

496-
fpm_cpuaffinity_init(&fconf);
488+
fpm_cpuaffinity_init(&c);
497489
token = php_strtok_r(cpu_list, ",", &buf);
498490

499491
while (token) {
500492
char *cpu_listsep;
501493

502-
fconf.min = strtol(token, &cpu_listsep, 0);
503-
if (errno || fconf.min < 0 || fconf.min > cpumax) {
494+
min = strtol(token, &cpu_listsep, 0);
495+
if (errno || min < 0 || min > cpumax) {
504496
return -1;
505497
}
506-
fconf.max = fconf.min;
498+
max = min;
507499
if (*cpu_listsep == '-') {
508500
if (strlen(cpu_listsep) > 1) {
509501
char *err;
510-
fconf.max = strtol(cpu_listsep + 1, &err, 0);
511-
if (errno || *err != '\0' || fconf.max < fconf.min || fconf.max > cpumax) {
502+
max = strtol(cpu_listsep + 1, &err, 0);
503+
if (errno || *err != '\0' || max < min || max > cpumax) {
512504
return -1;
513505
}
514506
} else {
515507
return -1;
516508
}
517509
}
518510

519-
fpm_cpuaffinity_add(&fconf);
511+
fpm_cpuaffinity_add(&c, min, max);
520512

521513
token = php_strtok_r(NULL, ";", &buf);
522514
}
523515

524-
r = fpm_cpuaffinity_set(&fconf);
516+
r = fpm_cpuaffinity_set(&c);
525517
return r;
526518
}
527519
#endif
@@ -552,7 +544,6 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
552544
}
553545
#if HAVE_FPM_CPUAFFINITY
554546
if (wp->config->process_cpu_list) {
555-
556547
if (0 > fpm_setcpuaffinity(wp->config->process_cpu_list)) {
557548
zlog(ZLOG_SYSERROR, "[pool %s] failed to fpm_setcpuaffinity(%s)", wp->config->name, wp->config->process_cpu_list);
558549
return -1;

sapi/fpm/php-fpm.conf.in

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,12 @@
129129
;
130130
; Default Value: not set
131131
; Valid syntaxes are:
132-
; process.cpu_list = "cpu id" - to bind to a single core
133-
; process.cpu_list = "min cpu id-max cpu id" - to bind to a core range
134-
from minimum cpu id to max
135-
; process.cpu_list = "[min cpu id-max cpu id],[min cpu id-max cpu id],..."
136-
- to bind to multiple ranges
132+
; process.cpu_list = "cpu id" - bind master process to cpu id
133+
; process.cpu_list = "[min cpu id]-[max cpu id]"
134+
- bind master process from min cpu id
135+
to max cpu id
136+
; process.cpu_list = "[[min cpu id]-[max cpu id],[min cpu id-max cpu id],...]"
137+
- bind master process to cpu id ranges
137138
separated by a comma
138139

139140
;;;;;;;;;;;;;;;;;;;;

sapi/fpm/tests/cpuaffinity-range.phpt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@ if (!str_contains(PHP_OS, 'Linux') && !str_contains(PHP_OS, 'FreeBSD')) {
77
die('skipped supported only on Linux and FreeBSD');
88
}
99

10-
if (str_contains(PHP_OS, 'Linux')) {
11-
$cmd = 'nproc';
12-
} else {
13-
$cmd = 'sysctl hw.ncpus';
14-
}
15-
16-
$nproc = intval(exec($cmd));
17-
if ($nproc < 4) {
10+
if (FPM\Tester::getCores() < 4) {
1811
die('skipped supported only on 4 cores or more environments');
1912
}
2013
?>
@@ -34,7 +27,7 @@ pm.max_children = 1
3427
pm.start_servers = 1
3528
pm.min_spare_servers = 1
3629
pm.max_spare_servers = 1
37-
process.cpu_list = 0-1,2-3
30+
process.cpu_list = 0,2-3
3831
EOT;
3932

4033
$tester = new FPM\Tester($cfg);

sapi/fpm/tests/cpuaffinity.phpt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@ if (!str_contains(PHP_OS, 'Linux') && !str_contains(PHP_OS, 'FreeBSD')) {
77
die('skipped supported only on Linux and FreeBSD');
88
}
99

10-
if (str_contains(PHP_OS, 'Linux')) {
11-
$cmd = 'nproc';
12-
} else {
13-
$cmd = 'sysctl hw.ncpus';
14-
}
15-
16-
$nproc = intval(exec($cmd));
17-
if ($nproc < 2) {
10+
if (FPM\Tester::getCores() < 4) {
1811
die('skipped supported only on multicores environments');
1912
}
2013
?>

sapi/fpm/tests/tester.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,19 @@ class Tester
203203
}
204204
}
205205

206+
static public function getCores()
207+
{
208+
if (str_contains(PHP_OS, 'Linux')) {
209+
$cmd = 'nproc';
210+
} else if (str_contains(PHP_OS, 'FreeBSD') || str_contains(PHP_OS, 'Darwin')) {
211+
$cmd = 'sysctl hw.ncpus';
212+
} else {
213+
return 0;
214+
}
215+
216+
return intval(exec($cmd));
217+
}
218+
206219
/**
207220
* @param int $backTraceIndex
208221
*

sapi/fpm/www.conf.in

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,13 @@ listen = 127.0.0.1:9000
8585
;
8686
; Default Value: inherits master's cpu affinity
8787
; Valid syntaxes are:
88-
; process.cpu_list = "cpu id" - to bind to a single core
89-
; process.cpu_list = "min cpu id-max cpu id" - to bind to a core range
90-
from minimum cpu id to max
91-
; process.cpu_list = "[min cpu id-max cpu id],[min cpu id-max cpu id],..."
92-
- to bind to multiple ranges
93-
separated by a comma
88+
; process.cpu_list = "cpu id" - bind pool process to cpu id
89+
; process.cpu_list = "[min cpu id]-[max cpu id]"
90+
- bind pool process from
91+
min cpu id to max cpu id
92+
; process.cpu_list = "[[min cpu id]-[max cpu id],[min cpu id-max cpu id],...]"
93+
- bind pool process to cpu id
94+
ranges separated by a comma
9495

9596
; Set the process dumpable flag (PR_SET_DUMPABLE prctl for Linux or
9697
; PROC_TRACE_CTL procctl for FreeBSD) even if the process user

0 commit comments

Comments
 (0)