Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Current processor frequency?

by BrowserUk (Patriarch)
on Aug 01, 2007 at 21:14 UTC ( [id://630166]=perlquestion: print w/replies, xml ) Need Help??

BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:

Some cpus, particularly those in notebooks but increasingly in desktops also, have the ability to ramp back the processor clock frequency when system activity (or sometimes battery levels) are low.

Anyone know how to discover the current processor clock frequency?

For now I'm interested in doing this for Intel cpus under Win32, but pointers to the availablity of this information for other hardware and platforms could be useful in the longer term.

Update: To clarify, the clock frequency information I am interested in, is the current clock frequency, when it may have been dynamically adjusted to save power as with Intel SpeedStep technology. AMD has similar technology, and other processor manufactures soon will have if they do not currently. The problem is how to detect this information, as it gets dynamically adjusted up and down, at runtime.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re: Current processor frequency?
by traveler (Parson) on Aug 01, 2007 at 22:57 UTC
    For Win32, SpeedSwitchXP sets it, reports it and has source.

    Microsoft has a page of information on the topic, but it is mostly GUI oriented. WMI seems the most likely way. Sys::Info::CPU seems to use WMI, and maybe it gets the correct speed or can be tweaked to do so: I know nothing about WMI.

    cpuspeed(8) sets it in linux and may be able to report it.

    HTH, --traveler

Re: Current processor frequency?
by FunkyMonk (Chancellor) on Aug 01, 2007 at 21:22 UTC
    On Windows XP it's in the registry:
    Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0] "Component Information"=hex:00,00,00,00,00,00,00,00,00,00,00,00,01,00, +00,00 "Identifier"="x86 Family 6 Model 15 Stepping 6" "Configuration Data"=hex(9):ff,ff,ff,ff,ff,ff,ff,ff,00,00,00,00,00,00, +00,00 "ProcessorNameString"="Intel(R) Core(TM)2 CPU 6600 @ 2.40GHz +" "VendorIdentifier"="GenuineIntel" "FeatureSet"=dword:a0073fff "~MHz"=dword:0000095a "Update Signature"=hex:00,00,00,00,c6,00,00,00 "Update Status"=dword:00000000 "Previous Update Signature"=hex:00,00,00,00,44,00,00,00 "Platform ID"=dword:00000001

    On Debian/GNU (Lenny) Linux it's in /proc/cpuinfo:

    processor : 0 vendor_id : AuthenticAMD cpu family : 15 model : 47 model name : AMD Athlon(tm) 64 Processor 3000+ stepping : 2 cpu MHz : 1808.830 cache size : 512 KB fpu : yes fpu_exception : yes cpuid level : 1 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge + mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_ +opt lm 3dnowext 3dnow up pni lahf_lm bogomips : 3619.93 TLB size : 1024 4K pages clflush size : 64 cache_alignment : 64 address sizes : 40 bits physical, 48 bits virtual power management: ts fid vid ttp tm stc

    In Windows 98SE it might be in the registry:)

    REGEDIT4 [HKEY_LOCAL_MACHINE\Hardware\Description\System\CentralProcessor\0] "VendorIdentifier"="GenuineIntel" "Identifier"="x86 Family 6 Model 8 Stepping 10" "Update Status"=dword:00000002

    It's a Celeron 900MHz, IIRC.

    update: Added 98SE
    update^2: Corrected 98SE entry

        Ah, I see. I have no idea, sorry.

        Not all of that, /proc/cpuinfo reports both model (which would be your rated maximum clock speed) and current speed (cpu MHz), for example:
        model name : Mobile Intel(R) Pentium(R) III CPU - M 1200MHz cpu MHz : 800.00
Re: Current processor frequency?
by mr_mischief (Monsignor) on Aug 01, 2007 at 22:18 UTC
    I'm not an authority on this, but the utilities I've seen that do that sort of reporting usually depend on a device driver that talks to a device on the chipset or through the CPU's Model Specific Registers (MSRs).

    It seems you'd want to study up on these registers for the chips you want to support, as talking to the chipset opens the door to a lot more things to consider.

    Update: Since you did mention that pointers on info for other OSes was perhaps helpful in the future, and since it's Open Source and therefore might give some code hints, here's x86info, which at least dumps MSRs for some CPUs.
Re: Current processor frequency?
by misc (Friar) on Aug 01, 2007 at 22:10 UTC
    On linux it's quite simple, the current cpu frequency is stored in the pseudofile /proc/cpuinfo,
    in the line "^cpu MHz".

    I have however no idea how one could get the freqeuency the processor is capable...
        perhaps it's not as easy I thought..

        to me it shows the current frequency, although I've got a smp kernel. (2.6.18)
        Google said the same for most users.
        e.g. http://docs.huihoo.com/gentoo/resources/document-listing/power-management-guide.html
        So I'd guess it's dependent on the kernel version, I wasn't able to find something more specific in the kernel documentation.
        A short research in the kernel sources didn't answer this, too.

        What google also told me..

        There is more info in the files
        /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
        /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
        /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq

        cpuinfo_cur_freq is only readable by root on my system, so this could lead again into problems.

        At least my question how the max frequency can be determined has been answered. :-)
Re: Current processor frequency?
by Anonymous Monk on Aug 01, 2007 at 22:54 UTC
    Why would you want this? It's a completely useless number!

    On machines with dynamic scaling of the CPU frequency, any number you arrived at would only be valid for the duration of the instruction during which you read it. From the next instruction on, the CPU may have changed speeds.

      On machines with dynamic scaling of the CPU frequency, any number you arrived at would only be valid for the duration of the instruction during which you read it.

      With apologies to NationWide: It doesn't work like that! Or rather, I'm not sure that it does. But in anycase, even if it does, the ability to detect that it varies, even if not exactly when it varies, is still useful information.

      For the why. Go look up the RDTSC instruction and think about how that might be utilised to provide a very high resolution elapsed timer. And then think about how that would be affected if the clock frequency is varying. And finally, how knowing that it does might be used to (at the very least) warn that the VHRT may not be accurate.

      There is also the possibility that (for example) that there might be an interface to disable the variation; or that changes to the clock rate might be disabled for the duration of (say) a critical section; or ...


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      My linux desktop had it built in, its nice to know if i'm sitting here and my CPU's spike for a long period I can check my processes and see whats happening, i can visual monitor my dual cores and see that they are both be used for something, mine also has temperature info on the CPU's which is probably obtained in a similar way and it helped me figure out the best desk configuration to keep my computer cooled. Is this all useful, i don't know, but i like having it, makes me feel powerful. BTW statistically sampling it will provide data even if each individual sample might not be representative. ;)


      ___________
      Eric Hodges

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://630166]
Approved by grep
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-20 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found