Why is clock_gettime so erratic?

前端 未结 2 1464
终归单人心
终归单人心 2020-12-12 18:28

Intro

  • Section Old Question contains the initial question (Further Investigation and Conclusion have been added since).

2条回答
  •  星月不相逢
    2020-12-12 18:36

    Well as CLOCK_THREAD_CPUTIME_ID is implemented using rdtsc it will likely suffer from the same problems as it. The manual page for clock_gettime says:

    The CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID clocks are realized on many platforms using timers from the CPUs (TSC on i386, AR.ITC on Itanium). These registers may differ between CPUs and as a consequence these clocks may return bogus results if a process is migrated to another CPU.

    Which sounds like it might explain your problems? Maybe you should lock your process to one CPU to get stable results?

提交回复
热议问题