27 #include <sys/resource.h> 28 #include <sys/syscall.h> 33 return syscall(SYS_gettid);
35 return syscall(__NR_gettid);
49 if (sched_getaffinity(
gettid(),
sizeof(cpu_set_t),&coremask) != 0) {
50 fprintf(stderr,
"Unable to get thread %d affinity. %s\n",
gettid(),strerror(errno));
56 for (cpu=0;cpu < CPU_SETSIZE;cpu++) {
57 if (CPU_ISSET(cpu,&coremask)) {
58 if (first_cpu == -1) {
66 if (last_cpu != -1) {
return (first_cpu);}
67 return (last_cpu == -1) ? first_cpu : -1;
81 CPU_SET(cpu,&coremask);
82 if (sched_setaffinity(
gettid(),
sizeof(cpu_set_t),&coremask) != 0) {
83 fprintf(stderr,
"Unable to set thread %d affinity. %s\n",
gettid(),strerror(errno));
void set_cpu_affinity_(int *cpu)
int get_cpu_affinity_(void)
static pid_t gettid(void)
int get_cpu_affinity(void)
void set_cpu_affinity(int cpu)