45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'ext/raptor_native/raptor_native.c', line 45
static VALUE raptor_native_pin_to_cpu(VALUE self, VALUE cpu) {
(void)self;
#ifdef __linux__
int worker_index = NUM2INT(cpu);
cpu_set_t current;
CPU_ZERO(¤t);
if (sched_getaffinity(0, sizeof(current), ¤t) < 0) rb_sys_fail("sched_getaffinity");
int cpu_id = -1;
int seen = 0;
for (int candidate = 0; candidate < CPU_SETSIZE; candidate++) {
if (!CPU_ISSET(candidate, ¤t)) continue;
if (seen == worker_index) { cpu_id = candidate; break; }
seen++;
}
if (cpu_id < 0) return Qfalse;
cpu_set_t set;
CPU_ZERO(&set);
CPU_SET(cpu_id, &set);
if (sched_setaffinity(0, sizeof(set), &set) < 0) rb_sys_fail("sched_setaffinity");
return Qtrue;
#else
(void)cpu;
return Qfalse;
#endif
}
|