ext/pcntl: cpu affinity support for solaris/illumos. (#14199)

This commit is contained in:
David CARLIER 2024-05-15 19:43:27 +01:00 committed by GitHub
parent 0218af87f2
commit 4ed1835f00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View file

@ -12,6 +12,7 @@ if test "$PHP_PCNTL" != "no"; then
getcpuid
getpriority
pidfd_open
pset_bind
pthread_set_qos_class_self_np
rfork
sched_setaffinity

View file

@ -76,6 +76,29 @@ typedef cpuset_t *cpu_set_t;
} while(0)
#define PCNTL_CPU_DESTROY(mask) cpuset_destroy(mask)
#define HAVE_SCHED_SETAFFINITY 1
#elif defined(HAVE_PSET_BIND)
#include <sys/pset.h>
typedef psetid_t cpu_set_t;
#define sched_getaffinity(p, c, m) pset_bind(PS_QUERY, P_PID, (p <= 0 ? getpid() : p), &m)
#define sched_setaffinity(p, c, m) pset_bind(m, P_PID, (p <= 0 ? getpid() : p), NULL)
#define PCNTL_CPUSET(mask) mask
#define PCNTL_CPU_ISSET(i, mask) (pset_assign(PS_QUERY, (processorid_t)i, &query) == 0 && query == mask)
#define PCNTL_CPU_SET(i, mask) pset_assign(mask, (processorid_t)i, NULL)
#define PCNTL_CPU_ZERO(mask) \
psetid_t query; \
do { \
if (UNEXPECTED(pset_create(&mask) != 0)) { \
php_error_docref(NULL, E_WARNING, "pset_create: %s", strerror(errno)); \
RETURN_FALSE; \
} \
} while (0)
#define PCNTL_CPU_DESTROY(mask) \
do { \
if (UNEXPECTED(mask != PS_NONE && pset_destroy(mask) != 0)) { \
php_error_docref(NULL, E_WARNING, "pset_destroy: %s", strerror(errno)); \
} \
} while (0)
#define HAVE_SCHED_SETAFFINITY 1
#endif
#if defined(HAVE_GETCPUID)