View Single Post
  #7   (View Single Post)  
Old 5th June 2008
yurtesen yurtesen is offline
Port Guard
 
Join Date: May 2008
Posts: 18
Default

It is ok. I know that I make this kind of mistakes from time to time. As I said, english is not my native language so I dont always realize what is offensive and not. Thanks for the warning anyway, I will try to be more careful with my choice of words in future.

Back to the subject, I am putting in the source of the chkfreq program below. This is the same program which ships with acpi_ppc. If you are using cpufreq/powerd then please copy/paste this code into a text file and compile and see your processor and check if sysctl is reporting correctly in your case.

I think, most of the time cpufreq is doing nothing but it is saying that it is doing something. I was fooled earlier that I thought cpufreq was working but now I am pretty sure that it is doing nothing.

Code:
/*
 * chkfreq.c
 *
 * usage: chkfreq [count]
 */

#include <sys/types.h>
#include <sys/time.h>

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

static __inline u_int64_t
rdtsc(void)
{
        u_int32_t eax, edx;
        __asm __volatile("rdtsc" : "=a" (eax), "=d" (edx));
        return (((u_int64_t)edx << 32) | (u_int64_t)eax);
}

int
main(int argc, char *argv[])
{
        int n = 1;
        u_int64_t t1, t2;
        struct timeval tv1, tv2;
        struct timespec ts;

        if (argc > 1)
                n = atoi(argv[1]);

        while (n-- > 0) {
                t1 = rdtsc();
                gettimeofday(&tv1, NULL);

                ts.tv_sec = 0;
                ts.tv_nsec = 990000000;
                nanosleep(&ts, NULL);

                do {
                        t2 = rdtsc();
                        gettimeofday(&tv2, NULL);

                        tv2.tv_usec += (tv2.tv_sec - tv1.tv_sec) * 1000000;
                        tv2.tv_usec -= tv1.tv_usec;
                } while (tv2.tv_usec < 1000000);

                printf("%llu\n", t2 - t1);
        }

        return 0;
}
Thanks,
Evren
Reply With Quote