I am having difficulties with the different clocks which can be accessed by clock_gettime. Especially I am interested in:
CLOCK_REALTIMECLOCK_PROCESS_CPUTIME_IDCLOCK_THREAD_COUTIME_ID
I read the manpage, but it didn’t help me very much. I use clock_gettime in order to generate timestamps for my profiler when it sends the gathered data via socket. I have noticed the following differences:
CLOCK_REALTIME
The events I receive from my profiler with this clocks are sometimes, in a wrong order. The timestamps start with a higher value, though not very much higher. Often the last messages (those with a higher timestamp) appear first and later the timestamps with a lower value.
CLOCK_PROCESS_CPUTIME_IDCLOCK_THREAD_COUTIME_ID
I found no difference on both clocks, though they start with a lesser value and are always correctly ordered.
I cannot explain this behavior.
Your system clock source is probably set to TSC instead of HPET.
On modern multi-core systems in general, HPET is a newer system that is more accurate and consistent, and TSC is an older system that is more performant.
On openSUSE, you can find out what your current clocksource is by
cat /sys/devices/system/clocksource/clocksource0/current_clocksourceTo set your clock source to HPET on openSUSE, do
echo 'hpet' > /sys/devices/system/clocksource/clocksource0/current_clocksourceFurther reading:
http://en.wikipedia.org/wiki/HPET
http://en.wikipedia.org/wiki/Time_Stamp_Counter