lkml.org 
[lkml]   [1999]   [Jan]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: 'Detected 19943xxx Hz processor'-fluctuations...
    Charles Cazabon <charlesc-linux@qcc.sk.ca> wrote:
    >Dag Wieers <dag@digibel.be> wrote:
    >> i don't think it really is random, maybe it differs beause the state of
    >> the processor differs little. can't we use this to statistically measure
    >> something about that processor ?
    >>
    >> the real question is: what causes these fluctuations ?
    >>
    >You're talking +-1000 cycles out of 200 million. This could easily be due
    >to ambient temperature differences or other environmental factors.

    Just for kicks I decided to let mhz.estimate run for a while in a loop, that
    way I get thousands more quite-possibly-less-accurate statistics. Out of
    59000 runs, here are the most deviant 20:

    374.865421
    374.865944
    374.865967
    374.866508
    374.866577
    374.867146
    374.867292
    374.867333
    374.867610
    374.867645
    [...]
    374.947681
    374.947712
    374.947716
    374.947962
    374.952847
    374.960404
    378.688356
    378.688474
    378.689010
    378.725015

    Another interesting statistic:

    cat mhz.estimate.output | wc -l
    59218
    cat mhz.estimate.output | cut -f1 -d' ' | sort | uniq | wc -l
    11147

    After running gnuplot over it, I see a very straight line. It appears my
    motherboard's clock is not affected by temperature. There are some
    interesting dips and jolts but nothing resembling a curve.

    Adding up all the numbers and dividing by 59218 gives us:
    374.929090476, meaning the max deviation is -.063669476/+3.795924524.
    The average deviation, something much more useful, I'm too lazy to
    calculate. :)

    Stripping out anything so deviant to not be in the 374 range, our plot looks
    like so:

    http://frantica.lly.org/~rcw/mhz-plot-19990111.png

    mhz.estimate.c is below:

    #include <stdio.h>
    #include <unistd.h>
    #include <sys/time.h>

    /* returns number of clock cycles since last reboot */
    __inline__ unsigned long long int rdtsc()
    {
    unsigned long long int x;
    __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
    return x;
    }

    main ()
    {
    /* find out the MHz of the processor by dividing
    * clock cycles by seconds */

    struct timezone tz;
    struct timeval tvstart, tvstop;
    unsigned long long int cycles[2]; /* gotta be 64 bit */
    unsigned int microseconds; /* total time taken */

    bzero(&tz, sizeof(tz));

    gettimeofday(&tvstart, &tz);
    cycles[0] = rdtsc();
    gettimeofday(&tvstart, &tz);
    #ifdef VERBOSE
    printf("Clock cycles at start: %Lu\n", cycles[0]);
    #endif
    usleep(1000000);

    cycles[1] = rdtsc();
    gettimeofday(&tvstop, &tz);
    microseconds = ((tvstop.tv_sec-tvstart.tv_sec)*1000000)+(tvstop.tv_usec-tvstart.tv_usec);

    #ifdef VERBOSE
    printf("Clock cycles at end: %Lu\n", cycles[1]);
    printf("Microseconds elapsed: %u\n", microseconds);
    #endif
    printf("%f MHz processor.\n", (float)(cycles[1]-cycles[0])/microseconds);
    }
    --
    Robert Woodcock - rcw@debian.org
    "Unix and C are the ultimate computer viruses" -- Richard Gabriel

    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.rutgers.edu
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2005-03-22 13:49    [W:0.024 / U:1.172 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site