Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPU affinity support for solaris based systems #10230

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/setcpuaffinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
#include <pthread.h>
#include <sched.h>
#endif
#ifdef __sun
#include <sys/pset.h>
#endif
#include "config.h"

#ifdef USE_SETCPUAFFINITY
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 */