CPU frequency

CPU frequency

Post by Martin Hick » Mon, 24 Sep 2001 12:34:25

Is there a system call that accurately returns CPU frequency?
Or is a do-it-yourself method the only option?



Use PGP/GnuPG  || DSS PGP Key: 0x4C7F2BEE  
Beer: So much more than just a breakfast drink.


CPU frequency

Post by Logan Sh » Mon, 24 Sep 2001 15:27:43

Quote:>Is there a system call that accurately returns CPU frequency?
>Or is a do-it-yourself method the only option?

Interesting that you should ask that, because right now
one of the highlighted articles at http://www.veryComputer.com/
is called "How to read CPU speed kstat information from a
program".  It shows how to do just that.

I think http://www.veryComputer.com/
will work as a direct link to the article.

  - Logan
 Loves to see              
 Justice done
 On somebody else"     ( Bruce*burn, "Justice", 1981 )


CPU frequency

Post by Daniel Pri » Tue, 25 Sep 2001 09:16:34

>Is there a system call that accurately returns CPU frequency?
>Or is a do-it-yourself method the only option?


The problem you'll encounter is that there isn't just one CPU frequency;
on a multi-cpu system, the OS assumes that CPUs could have different

You probably already know that there is a command to do so: 'psrinfo
-v'.  psrinfo uses the kstat framework to figure this information out.
But psrinfo is pretty opaque.  In Solaris 8 and later you can explore
kstats using the kstat(1M) command (which is actually a perl script you
can examine):

$ kstat -p 'cpu_info:::clock_MHz'
cpu_info:8:cpu_info8:clock_MHz          750
cpu_info:9:cpu_info9:clock_MHz          750
cpu_info:10:cpu_info10:clock_MHz        750
cpu_info:11:cpu_info11:clock_MHz        750
cpu_info:16:cpu_info16:clock_MHz        750
cpu_info:17:cpu_info17:clock_MHz        750
cpu_info:18:cpu_info18:clock_MHz        750
cpu_info:19:cpu_info19:clock_MHz        750

This helps you to find out the names of the kstats you are seeking; the
next step is to take a look at the kstat man pages.  See especially
kstat_lookup(), kstat_open(), kstat_read() and friends.  Something like
this works for me:

$ cat > speeds.c
#include <unistd.h>
#include <kstat.h>

        kstat_ctl_t *kc;
        kstat_t *kstatp;
        kstat_named_t *namedp;

        if ((kc = kstat_open()) == NULL) {

         * Walk the kstat chain; find those whose module name is cpu_info.
         * Read those kstats in, and look up clock_MHz in each one to find
         * the CPU speed of each CPU on the system.
        for (kstatp = kc->kc_chain; kstatp != NULL; kstatp = kstatp->ks_next) {
                if (strcmp(kstatp->ks_module, "cpu_info") == 0) {
                        int cpu = kstatp->ks_instance;

                        if (kstat_read(kc, kstatp, NULL) == -1)

                        namedp = (kstat_named_t *)kstat_data_lookup(kstatp,
                        printf("cpu %d: %d MHz\n", cpu, namedp->value.l);



$ cc -o speeds speeds.c -lkstat
$ ./speeds
cpu 8: 750 MHz
cpu 9: 750 MHz
cpu 10: 750 MHz
cpu 11: 750 MHz
cpu 16: 750 MHz
cpu 17: 750 MHz
cpu 18: 750 MHz
cpu 19: 750 MHz



Expressed in this posting are my opinions. They are in no way related to
opinions held by my employer, Sun Microsystems. Statements on Sun products
included here are not gospel and may be fiction rather than truth.


1. Programs for CPU frequency and temp

there are under kde programs that help me to visualize the frequency of CPU
and more important the temperature of CPU and also if possible of the whole
systems? I have installed a red hat 9 with kernel 2.4.20-8.

Marco Mangiante

2. Free SCO Wabi and Merge

3. CPU frequency

4. test ignor it

5. How to find out the CPU frequency

6. nullify ask to -passthru2 problem

7. BIOS CPU Frequency Setting

8. Making directories crash server?

9. Haw to verify CPU frequency memory size

10. New: Changing the CPU frequency using CPUFREQ hangs the kernel

11. athlon 64: cpu frequency ?

12. CPU frequency

13. CPU Frequency scaling