How to read a real time measurement on Pentium 3?

Apr 17, 2005 4 Replies

Hi, I'm running VxWorks Os on a Pentium 3 processor. The VxWorks timers are based on the OS ticks (several mili seconds), but I need a way to measure small time intervals of micro seconds. Is there a Real Time clock register to read, or a cotinueosly running counter register to calculate the interval time from it? Thanks.



The 64 bit Time Stamp Counter (TSC) and the RDTSC instruction should be available on all Pentiums. It counts clock cycles, so you need some means (e.g. the CMOS clock) to first measure the clock frequency, which is quite temperature dependent.

Especially mobile processors entering some kind of sleep mode may give erratic readings.

Paul

Thanks. This should do the job. How can I access this register in C code using the GNU compiler? Since RDTSC loads the counter to EDX:EAX, I tried something like this: __asm__("RDTSC"); __asm__("MOV %0,EAX" : "=r"(ulVar) : ");

The code compiled, but downloading it to the target gave an error regarding EAX. Any Ideas? Thank you.

inline unsigned long long rdtsc( ) { unsigned long long ull; __asm__ __volatile__ ( "rdtsc" : "=&A" ( ull ) : ); return ull; }

... And don't forget to handle the illegal instruction trap on non-Intel processors that don't do RDTSC...

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required