34 #include "ac/pthread.h"
40 #include <sys/ioctl.h>
41 #endif // HAVE_TASK2CPU
44 #ifdef USE_PTHREAD_SETAFFINITY_NP
52 static pthread_mutex_t mbdyn_task2cpu_mutex = PTHREAD_MUTEX_INITIALIZER;
61 pthread_mutex_lock(&::mbdyn_task2cpu_mutex);
65 fd = open(
"/dev/TASK2CPU", O_RDWR);
71 int save_errno = errno;
72 char *err_msg = strerror(save_errno);
74 silent_cerr(
"Error opening /dev/TASK2CPU ("
75 << save_errno <<
": " << err_msg <<
";"
76 " ignored)" << std::endl);
79 #elif defined(USE_PTHREAD_SETAFFINITY_NP)
82 CPU_SET(cpu, &cpuset);
84 const pthread_t thread = pthread_self();
86 int s = pthread_setaffinity_np(thread,
sizeof(cpuset), &cpuset);
89 silent_cerr(
"warning: pthread_setaffinity_np failed with status " << s << std::endl);
94 s = pthread_getaffinity_np(thread,
sizeof(cpuset), &cpuset);
97 DEBUGCERR(
"warning: pthread_getaffinity_np failed with status " << s << std::endl);
101 for (
int i = 0; i < CPU_SETSIZE; ++i) {
102 if (CPU_ISSET(i, &cpuset)) {
103 DEBUGCERR(
"thread " << cpu + 1 <<
" running at CPU " << i << std::endl);
114 silent_cerr(
"/dev/TASK2CPU or pthread_getaffinity_np are not available" << std::endl);
119 pthread_mutex_unlock(&::mbdyn_task2cpu_mutex);
int mbdyn_task2cpu(int cpu)
static bool mbdyn_task2cpu_disabled