Skip to content

Commit 0b581e4

Browse files
committed
build
1 parent 840c0d2 commit 0b581e4

File tree

6 files changed

+54
-62
lines changed

6 files changed

+54
-62
lines changed

sapi/fpm/fpm/fpm_unix.c

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

405405
#if HAVE_FPM_CPUAFFINITY
406-
struct fpm_cpuaffinity_conf {
407-
cpu_set_t cset;
408-
long min;
409-
long max;
410-
};
411-
412406
static long fpm_cpumax(void)
413407
{
414408
static long cpuid = LONG_MIN;
@@ -428,71 +422,69 @@ static long fpm_cpumax(void)
428422
return cpuid;
429423
}
430424

431-
static void fpm_cpuaffinity_init(struct fpm_cpuaffinity_conf *c)
425+
static void fpm_cpuaffinity_init(cpu_set_t *c)
432426
{
433-
CPU_ZERO(&c->cset);
427+
CPU_ZERO(c);
434428
}
435429

436-
static void fpm_cpuaffinity_add(struct fpm_cpuaffinity_conf *c)
430+
static void fpm_cpuaffinity_add(cpu_set_t *c, int min, int max)
437431
{
438-
#if defined(HAVE_FPM_CPUAFFINITY)
439432
int i;
440433

441-
for (i = c->min; i <= c->max; i ++) {
442-
if (!CPU_ISSET(i, &c->cset)) {
443-
CPU_SET(i, &c->cset);
434+
for (i = min; i <= max; i ++) {
435+
if (!CPU_ISSET(i, c)) {
436+
CPU_SET(i, c);
444437
}
445438
}
446-
#endif
447439
}
448440

449-
static int fpm_cpuaffinity_set(struct fpm_cpuaffinity_conf *c)
441+
static int fpm_cpuaffinity_set(cpu_set_t *c)
450442
{
451443
#if defined(HAVE_SCHED_SETAFFINITY)
452-
return sched_setaffinity(0, sizeof(c->cset), &c->cset);
444+
return sched_setaffinity(0, sizeof(c), c);
453445
#elif defined(HAVE_CPUSET_SETAFFINITY)
454-
return cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(c->cset), &c->cset);
446+
return cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(c), c);
455447
#endif
456448
}
457449

458450
static int fpm_setcpuaffinity(char *cpu_list)
459451
{
460452
char *token, *buf;
461-
struct fpm_cpuaffinity_conf fconf;
462-
int r, cpumax;
453+
cpu_set_t c;
454+
int r, cpumax, min, max;
463455

464456
r = -1;
465457
cpumax = fpm_cpumax();
466458

467-
fpm_cpuaffinity_init(&fconf);
459+
fpm_cpuaffinity_init(&c);
468460
token = php_strtok_r(cpu_list, ",", &buf);
469461

470462
while (token) {
471463
char *cpu_listsep;
472464

473-
fconf.min = strtol(token, &cpu_listsep, 0);
474-
if (errno || fconf.min < 0 || fconf.min > cpumax) {
465+
min = strtol(token, &cpu_listsep, 0);
466+
if (errno || min < 0 || min > cpumax) {
475467
return -1;
476468
}
477-
fconf.max = fconf.min;
469+
max = min;
478470
if (*cpu_listsep == '-') {
479471
if (strlen(cpu_listsep) > 1) {
480472
char *err;
481-
fconf.max = strtol(cpu_listsep + 1, &err, 0);
482-
if (errno || *err != '\0' || fconf.max < fconf.min || fconf.max > cpumax) {
473+
max = strtol(cpu_listsep + 1, &err, 0);
474+
if (errno || *err != '\0' || max < min || max > cpumax) {
483475
return -1;
484476
}
485477
} else {
486478
return -1;
487479
}
488480
}
489481

490-
fpm_cpuaffinity_add(&fconf);
482+
fpm_cpuaffinity_add(&c, min, max);
491483

492484
token = php_strtok_r(NULL, ";", &buf);
493485
}
494486

495-
r = fpm_cpuaffinity_set(&fconf);
487+
r = fpm_cpuaffinity_set(&c);
496488
return r;
497489
}
498490
#endif
@@ -523,7 +515,6 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */
523515
}
524516
#if HAVE_FPM_CPUAFFINITY
525517
if (wp->config->process_cpu_list) {
526-
527518
if (0 > fpm_setcpuaffinity(wp->config->process_cpu_list)) {
528519
zlog(ZLOG_SYSERROR, "[pool %s] failed to fpm_setcpuaffinity(%s)", wp->config->name, wp->config->process_cpu_list);
529520
return -1;

sapi/fpm/php-fpm.conf.in

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

140141
;;;;;;;;;;;;;;;;;;;;

sapi/fpm/tests/cpuaffinity-range.phpt

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@ FPM: cpu affinity test, range
66
if (!str_contains(PHP_OS, 'Linux') && !str_contains(PHP_OS, 'FreeBSD')) {
77
die('skipped supported only on Linux and FreeBSD');
88
}
9-
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) {
18-
die('skipped supported only on 4 cores or more environments');
19-
}
209
?>
2110
--FILE--
2211
<?php
@@ -34,9 +23,13 @@ pm.max_children = 1
3423
pm.start_servers = 1
3524
pm.min_spare_servers = 1
3625
pm.max_spare_servers = 1
37-
process.cpu_list = 0-1,2-3
26+
process.cpu_list = 0,2-3
3827
EOT;
3928

29+
if (FPM\Tester::getCores() < 4) {
30+
die('skipped supported only on 4 cores or more environments');
31+
}
32+
4033
$tester = new FPM\Tester($cfg);
4134
$tester->start();
4235
$tester->expectLogStartNotices();

sapi/fpm/tests/cpuaffinity.phpt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@ FPM: cpu affinity test
66
if (!str_contains(PHP_OS, 'Linux') && !str_contains(PHP_OS, 'FreeBSD')) {
77
die('skipped supported only on Linux and FreeBSD');
88
}
9-
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) {
18-
die('skipped supported only on multicores environments');
19-
}
209
?>
2110
--FILE--
2211
<?php
@@ -37,6 +26,10 @@ pm.max_spare_servers = 1
3726
process.cpu_list = 1
3827
EOT;
3928

29+
if (FPM\Tester::getCores() < 4) {
30+
die('skipped supported only on multicores environments');
31+
}
32+
4033
$tester = new FPM\Tester($cfg);
4134
$tester->start();
4235
$tester->expectLogStartNotices();

sapi/fpm/tests/tester.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,19 @@ class Tester
190190
}
191191
}
192192

193+
static public function getCores()
194+
{
195+
if (str_contains(PHP_OS, 'Linux')) {
196+
$cmd = 'nproc';
197+
} else if (str_contains(PHP_OS, 'FreeBSD') || str_contains(PHP_OS, 'Darwin') {
198+
$cmd = 'sysctl hw.ncpus';
199+
} else {
200+
return 0;
201+
}
202+
203+
return intval(exec($cmd));
204+
}
205+
193206
/**
194207
* @param int $backTraceIndex
195208
*

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)