finding out cpu clk speed

  • Follow


Hi,
        Is there a syscall which I can use within a C program to find out what is
the CPU frequency ? Reading /proc/cpuinfo doesn't work for my purposes :-(
-- 
Sayantan Sur

Graduate Research Assistant
Dept. of Computer Science
The Ohio State University.
0
Reply surs.deletethis (24) 9/8/2003 4:37:54 PM

On Mon, 08 Sep 2003 12:37:54 -0400, Sayantan Sur staggered into the
Black Sun and said:
> Is there a syscall which I can use within a C program to find out
> what is the CPU frequency ?

Nope.  Clock frequency is calculated at boot time on the x86 via a tight
loop, and the information is stored in kernel data structures that are
accessible via /proc/cpuinfo .  Why waste a syscall on information you
can get with open() and read() ?

> Reading /proc/cpuinfo doesn't work for my purposes

Why not?  Explain more fully, please.

-- 
Matt G|There is no Darkness in Eternity/But only Light too dim for us to see
Brainbench MVP for Linux Admin / 
http://www.brainbench.com     /  "He is a rhythmic movement of the
-----------------------------/    penguins, is Tux." --MegaHAL
0
Reply danceswithcrows (534) 9/8/2003 4:45:27 PM


>> Reading /proc/cpuinfo doesn't work for my purposes
> 
> Why not?  Explain more fully, please.

I found out that read() of /proc/cpuinfo does infact work for me. Here is
how,

f = popen("/bin/sed -n '/cpu MHz/s/[^:]*://p' /proc/cpuinfo", "r");

Thanks,

-- 
Sayantan Sur

Graduate Research Assistant
Dept. of Computer Science
The Ohio State University.
0
Reply surs.deletethis (24) 9/8/2003 5:52:23 PM

On Mon, 08 Sep 2003 13:52:23 -0400, Sayantan Sur
<surs.deletethis@cis.ohio-state.edu> wrote:

>
>>> Reading /proc/cpuinfo doesn't work for my purposes
>> 
>> Why not?  Explain more fully, please.
>
>I found out that read() of /proc/cpuinfo does infact work for me. Here is
>how,
>
>f = popen("/bin/sed -n '/cpu MHz/s/[^:]*://p' /proc/cpuinfo", "r");
>
>Thanks,

Will produce unexpected results for smp machines. I suggest you add a
|  head -1 to be certain.

Steve
0
Reply steve1960 (42) 9/9/2003 4:15:06 PM

3 Replies
57 Views

(page loaded in 0.102 seconds)

Similiar Articles:













7/23/2012 6:19:24 PM


Reply: