View Full Version : Pentium TSC for Linux _mlOSGetUSTinternal

03-14-2004, 02:18 AM
I was a little bit surprised to see gettimeofday being used for _mlOSGetUSTinternal. As far as I know, this clock is adjusted by the various subsystems used to correct out of sync clocks (like ntpd). For Pentium and later, I think a much better option would be the Pentium TSC (realistically are sub Pentiums being used much for multimedia?, although they should be catered for I guess). It is a single asembler (misspelled to get throught fascist rude word filter) call to get the full 64 bit TSC value:

u_int64_t d;
__asm__ __volatile__ ("rdtsc" : "=&A" (d));

UST is meant to be unadjusted, right? gettimeofday is adjusted.

edit to fix the expletive filter of ***embler -> asembler, sigh!

[ March 14, 2004: Message edited by: tmander ]

03-15-2004, 08:54 AM
Yes, you are correct -- gettimeofday is not at all a good source of UST. In a "production system", this call should not be used.

The way UST is supposed to work in the latest Beta is that one or more modules register a UST handler. The modules are expected to obtain UST timestamps from the hardware they control -- video and audio cards will often have hardware on-board that is suitable for UST. Thus the modules register their ability to provide UST, and the ML library selects one of them to be "the" source on the system.

The function "_mlOSGetUSTInternal" is simply the emergency fall-back for systems that have no suitable hardware.

The CPU's timer is not ideal because on some multi-CPU architectures, the processor timers are not in-sync. Thus, the result of a get-UST call will depend on the CPU currently executing the thread.