9 #if ! __GLIBC_PREREQ(2, 6)
13 size_t cpu_count(cpu_set_t
const * cpu_set)
17 for (
unsigned int i = 0;
i <
sizeof(cpu_set_t) /
sizeof(__cpu_mask); ++
i)
18 count += __builtin_popcountl(cpu_set->__bits[
i]);
21 #define CPU_COUNT(CPU_SET) cpu_count(CPU_SET)
26 #if defined(__x86_64__)
27 #include <asm/vsyscall.h>
28 #elif defined(__i386__)
29 #include <sys/syscall.h>
33 int sched_getcpu(
void)
37 #if defined(__x86_64__)
38 typedef long (*vgetcpu_t)(
unsigned int *cpu,
unsigned int *
node,
unsigned long *tcache);
39 vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu);
41 #elif defined(__i386__)
42 retval = syscall(SYS_getcpu, &cpu,
NULL,
NULL);
44 return (retval == -1) ? retval : cpu;
47 #endif // ! __GLIBC_PREREQ(2, 6)
54 return sched_getcpu();
67 sched_getaffinity(0,
sizeof(cpu_set_t), & cpu_set);
68 if (CPU_COUNT(& cpu_set) == 1)
85 sched_getaffinity(0,
sizeof(cpu_set_t), & cpu_set);
86 if (CPU_COUNT(& cpu_set) == 1)
93 CPU_SET(current, & cpu_set);
94 sched_setaffinity(0,
sizeof(cpu_set_t), & cpu_set);
95 sched_getaffinity(0,
sizeof(cpu_set_t), & cpu_set);
97 if (CPU_COUNT(& cpu_set) == 1)
static bool bindToCurrentCpu()