justincormack / ljsyscall

LuaJIT Unix syscall FFI
http://www.myriabit.com/ljsyscall/
Other
441 stars 54 forks source link

getcpu() call appears not to work #194

Closed wingo closed 8 years ago

wingo commented 8 years ago

If I getcpu().cpu within a process run with taskset -c 6, it returns 0 for me. However if I S.sched_getaffinity(), that correctly returns the equivalent of {6}.

justincormack commented 8 years ago

Hmm, what does strace say?

kbara commented 8 years ago

The behaviour is the same in the ljsyscall with Snabb as with current master ( 214550af0cac3d07eb6d25ef64d2a4309b8fba1b ).

cat cputestscript.lua

local S = require("syscall")
print("getcpu", S.getcpu().cpu )
print("sched aff", S.sched_getaffinity())

strace taskset -c 3 luajit cputestscript.lua

Strace output includes:

getcpu([0], [0], 0)                     = 0
sched_getaffinity(0, 128, {8, 0, 0, 0}) = 32

The program prints:

getcpu  0
sched aff   {3}
kbara commented 8 years ago

I've PR'd a fix - https://github.com/justincormack/ljsyscall/pull/195 - the problem was basically a typo in the source code ('node' was being given as an argument twice to getcpu, rather than cpu and node being given once each.)

wingo commented 8 years ago

Very nice, @kbara! I stared at that for some time and couldn't figure it out :)

justincormack commented 8 years ago

merged, so closing this.