On Wed, 22 Sep 1999 [EMAIL PROTECTED] wrote:
> Is there any way to determine the CPU clock frequency so that I can divided
> timestamps from the RDTSC by frequency and get microseconds ?
I use the following code:
#define RDTSC2(h,l) __asm__ volatile ("rdtsc" : "=a"(l) , "=d"(h))
#define RDTSC1(l) __asm__ volatile ("rdtsc" : "=a"(l))
unsigned long scaler_ns;
int rt_time_ns_calibrate() {
union {
unsigned long long ll;
struct {unsigned long l,h; } st;
} t1,t2;
long long ns;
RTIME tu1, tu2;
long flags;
rtl_no_interrupts(flags);
RDTSC2(t1.st.h,t1.st.l);
tu1=rt_get_time();
while(rt_get_time() < tu1 + (CALIBR_FOR_us*RT_TICKS_PER_SEC)/1000000);
RDTSC2(t2.st.h,t2.st.l);
tu2=rt_get_time();
rtl_restore_interrupts(flags);
ns=(tu2-tu1)*1000000000LL/RT_TICKS_PER_SEC;
scaler_ns=((t2.ll-t1.ll)<<16)/ns;
return 0;
}
#define ns2clocks(t_ns) ((unsigned long)(((unsigned long long)t_ns*scaler_ns)>>16))
The I use in init_module :
rt_time_ns_calibrate(); /*calibrate ns resolution timer (Pentium only)*/
printk("scaler_ns=%d, this is %d kHz, %d\n",scaler_ns,(long)(((long
long)scaler_ns*1000000)>>16), ns2clocks(1000000));
--
Tomek
--- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
----
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/