Forums

How to read a real time measurement on Pentium 3?

Started by Rami April 17, 2005
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.

On 17 Apr 2005 02:25:47 -0700, "Rami" <rami48@gmail.com> wrote:

>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?
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.

Rami wrote:
> 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; }
Bryan Hackney wrote:
> 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...