justincormack / ljsyscall

LuaJIT Unix syscall FFI

Home Page:http://www.myriabit.com/ljsyscall/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getcpu() call appears not to work

wingo opened this issue · comments

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}.

Hmm, what does strace say?

commented

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

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}
commented

I've PR'd a fix - #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.)

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

merged, so closing this.