Computing cpu's clock in cycles per second

JD jd1008 at
Mon Sep 27 18:30:55 UTC 2010

On 09/27/2010 07:34 AM, Wade Hampton wrote:
> Did you look at using the RDTSC instruction to read the
> cycle counter?
> Sample this over an interval to get an estimate
> of the clock frequency based on this counter.
> __inline__ unsigned long long int rdtsc()
> {
>    unsigned long long int x;
>    __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
>    return(x);
> }
> I use gettimeofday() calls to check the wall-clock time,
> usleep(n) to sleep for a long time (second or more),
> and rdtsc to compute the cycles....  Seems to work
> well.
> Cheers,
> --
> Wade Hampton
Thank you very much Wade.
I confirm that using rdtsc, the delta in tsc values, divided by 60 
(using nanosleep)
is  798283074.9833333333 ticks per second, which is almost iddentical
to what is reported by cpuinfo:
cpu MHz        : 798.244

No matter what the load factor on the machine, even when the load 
reached 5 or  6,
it is the same value.
Well, that's what you get for buying a laptop from a crappy manufacturer
that has put in it a fixed unprogrammable clock (oscillator), and put in a
lame BIOS that provides no hooks for setting C2 C3 ...etc.
I will certainly steer friends and family away from this manufacturer.

More information about the users mailing list