diff --git a/ext/pcntl/config.m4 b/ext/pcntl/config.m4 index c9da0fbb64399..658cff7d0dc61 100644 --- a/ext/pcntl/config.m4 +++ b/ext/pcntl/config.m4 @@ -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 diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index 83905d5d80206..e1451188bb1da 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -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 +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)