Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know on which physical processor and on which physical core my code is running

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.

like image 701
semteu Avatar asked May 17 '11 06:05

semteu


1 Answers

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().

like image 97
stepancheg Avatar answered Sep 20 '22 16:09

stepancheg