Skip to content

Commit 4ed1835

Browse files
authored
ext/pcntl: cpu affinity support for solaris/illumos. (#14199)
1 parent 0218af8 commit 4ed1835

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

ext/pcntl/config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ if test "$PHP_PCNTL" != "no"; then
1212
getcpuid
1313
getpriority
1414
pidfd_open
15+
pset_bind
1516
pthread_set_qos_class_self_np
1617
rfork
1718
sched_setaffinity

ext/pcntl/pcntl.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,29 @@ typedef cpuset_t *cpu_set_t;
7676
} while(0)
7777
#define PCNTL_CPU_DESTROY(mask) cpuset_destroy(mask)
7878
#define HAVE_SCHED_SETAFFINITY 1
79+
#elif defined(HAVE_PSET_BIND)
80+
#include <sys/pset.h>
81+
typedef psetid_t cpu_set_t;
82+
#define sched_getaffinity(p, c, m) pset_bind(PS_QUERY, P_PID, (p <= 0 ? getpid() : p), &m)
83+
#define sched_setaffinity(p, c, m) pset_bind(m, P_PID, (p <= 0 ? getpid() : p), NULL)
84+
#define PCNTL_CPUSET(mask) mask
85+
#define PCNTL_CPU_ISSET(i, mask) (pset_assign(PS_QUERY, (processorid_t)i, &query) == 0 && query == mask)
86+
#define PCNTL_CPU_SET(i, mask) pset_assign(mask, (processorid_t)i, NULL)
87+
#define PCNTL_CPU_ZERO(mask) \
88+
psetid_t query; \
89+
do { \
90+
if (UNEXPECTED(pset_create(&mask) != 0)) { \
91+
php_error_docref(NULL, E_WARNING, "pset_create: %s", strerror(errno)); \
92+
RETURN_FALSE; \
93+
} \
94+
} while (0)
95+
#define PCNTL_CPU_DESTROY(mask) \
96+
do { \
97+
if (UNEXPECTED(mask != PS_NONE && pset_destroy(mask) != 0)) { \
98+
php_error_docref(NULL, E_WARNING, "pset_destroy: %s", strerror(errno)); \
99+
} \
100+
} while (0)
101+
#define HAVE_SCHED_SETAFFINITY 1
79102
#endif
80103

81104
#if defined(HAVE_GETCPUID)

0 commit comments

Comments
 (0)