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

前端 未结 5 1082
抹茶落季
抹茶落季 2020-12-01 22:06

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.

5条回答
  •  执笔经年
    2020-12-01 22:38

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

提交回复
热议问题