How can I know in a C program, on which physical processor and core my code is running? I'm using Linux and gcc 4.4.3.
sched_getcpu()
call returns virtual CPU number. Mapping of virtual CPU to real CPU info is in /proc/cpuinfo.
If your system supports VDSO, then sched_getcpu()
is relatively fast.
CPU number can be also obtained using CPUID
instruction, but it is slower than sched_getcpu()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With