setaffinity solarish based systems implementation proposal.

This commit is contained in:
David Carlier 2022-02-02 20:40:02 +00:00
parent 8eb19cc251
commit e8ab183fcc
2 changed files with 19 additions and 1 deletions

View file

@ -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

View file

@ -44,6 +44,9 @@
#include <pthread.h>
#include <sched.h>
#endif
#ifdef __sun
#include <sys/pset.h>
#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 */