From e8ab183fccbfd1f615e14f30cbef4841a012bfbb Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 2 Feb 2022 20:40:02 +0000 Subject: [PATCH] setaffinity solarish based systems implementation proposal. --- src/config.h | 2 +- src/setcpuaffinity.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/config.h b/src/config.h index 210e55a87..7121742ff 100644 --- a/src/config.h +++ b/src/config.h @@ -286,7 +286,7 @@ int pthread_setname_np(const char *name); #endif /* Check if we can use setcpuaffinity(). */ -#if (defined __linux || defined __NetBSD__ || defined __FreeBSD__ || defined __DragonFly__) +#if (defined __linux || defined __NetBSD__ || defined __FreeBSD__ || defined __DragonFly__) || defined(__sun) #define USE_SETCPUAFFINITY void setcpuaffinity(const char *cpulist); #endif diff --git a/src/setcpuaffinity.c b/src/setcpuaffinity.c index 77b162103..840c1f4b1 100644 --- a/src/setcpuaffinity.c +++ b/src/setcpuaffinity.c @@ -44,6 +44,9 @@ #include #include #endif +#ifdef __sun +#include +#endif #include "config.h" #ifdef USE_SETCPUAFFINITY @@ -82,15 +85,22 @@ void setcpuaffinity(const char *cpulist) { #ifdef __NetBSD__ cpuset_t *cpuset; #endif +#ifdef __sun + psetid_t cpuset; +#endif if (!cpulist) return; +#ifndef __sun #ifndef __NetBSD__ CPU_ZERO(&cpuset); #else cpuset = cpuset_create(); #endif +#else + pset_create(&cpuset); +#endif q = cpulist; while (p = q, q = next_token(q, ','), p) { @@ -125,10 +135,14 @@ void setcpuaffinity(const char *cpulist) { return; while (a <= b) { +#ifndef __sun #ifndef __NetBSD__ CPU_SET(a, &cpuset); #else cpuset_set(a, cpuset); +#endif +#else + pset_assign(cpuset, a, NULL); #endif a += s; } @@ -150,6 +164,10 @@ void setcpuaffinity(const char *cpulist) { pthread_setaffinity_np(pthread_self(), cpuset_size(cpuset), cpuset); cpuset_destroy(cpuset); #endif +#ifdef __sun + pset_bind(cpuset, P_PID, P_MYID, NULL); + pset_destroy(cpuset); +#endif } #endif /* USE_SETCPUAFFINITY */