CPU TSC fetch operation especially in multicore-multi-processor environment

后端 未结 4 1955
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 03:12

In Linux world, to get nano seconds precision timer/clockticks one can use :

#include 

int foo()
         


        
4条回答
  •  忘掉有多难
    2020-11-29 03:40

    RTDSC is not synchronized across CPUs. Thus, you cannot rely on it in a multi-processor systems. The only workaround I can think of for Linux would be to actually restricting the process to run on a single CPU by settings its affinity. This can be done externally using using taskset utility or "internally" using sched_setaffinity or pthread_setaffinity_np functions.

提交回复
热议问题