33#include <sys/resource.h>
34#include <sys/syscall.h>
51static pid_t gettid(
void)
55 pthread_threadid_np(NULL, &tid64);
56 pid_t tid = (pid_t)tid64;
58 pid_t tid = syscall(__NR_gettid);
68int get_cpu_affinity(
void)
70#ifdef HAVE_SCHED_GETAFFINITY
74 if (sched_getaffinity(gettid(),
sizeof(cpu_set_t),&coremask) != 0) {
75 fprintf(stderr,
"Unable to get thread %d affinity. %s\n",gettid(),strerror(errno));
79 for (cpu=0;cpu < CPU_SETSIZE;cpu++) {
80 if (CPU_ISSET(cpu,&coremask)) {
92int get_cpuset(
int fsz,
int *output,
int pe, _Bool debug)
94#ifdef HAVE_SCHED_GETAFFINITY
98 if (sched_getaffinity(gettid(),
sizeof(cpu_set_t),&coremask) != 0) {
99 fprintf(stderr,
"Unable to get thread %d affinity. %s\n",gettid(),strerror(errno));
106 for (cpu=0;cpu < CPU_SETSIZE;cpu++) {
107 if (CPU_ISSET(cpu,&coremask)) {
108 printf(
"=> get_cpuset - pe %d: %d\n",pe, cpu);
114 for (cpu=0;cpu < CPU_SETSIZE;cpu++) {
115 if (CPU_ISSET(cpu,&coremask)) {
132int set_cpu_affinity(
int cpu)
134#ifdef HAVE_SCHED_GETAFFINITY
138 CPU_SET(cpu,&coremask);
139 if (sched_setaffinity(gettid(),
sizeof(cpu_set_t),&coremask) != 0) {