Q&A: Pentium(R) M CPU Frequency Question

Q&A: Pentium(R) M CPU Frequency Question

This is an inquiry received byIntel Software NetworkSupport, followed by the response provided by our Application Engineers:

Q. We are currently updating our PC configuration detection tool and wanted to accurately determine the CPU speed of Intel Pentium M laptops. Do you have any information that could help us?

A. To retrieve the current operating frequency and maximum operating frequency of a Pentium M processor, you should call the CallNtPowerInformation API under Windows* XP or Windows .NET* 2003. This will return a structure in the following format:

typedef struct _PROCESSOR_POWER_INFORMATION {
ULONG Number;
ULONG MaxMhz;
ULONG CurrentMhz;
ULONG MhzLimit;
ULONG MaxIdleState;
ULONG CurrentIdleState;
} PROCESSOR_POWER_INFORMATION, *PPROCESSOR_POWER_INFORMATION;

The member variable CurrentMhz has the current operating frequency, and the member variable MaxMhz has the maximum operating frequency. To call the API, you will need to declare a local variable of type PROCESSOR_POWER_INFORMATION and then call the API using the following prototype:

PROCESSOR_POWER_INFORMATION ppi;

CallNtPowerInformation(ProcessorInformation, NULL, 0, &ppi,
sizeof(PROCESSOR_POWER_INFORMATION));

Library to link: Powrprof.lib

If this API is not available to you, you can still get the maximum operating frequency by calling the CPUID assembly code instruction with input of 80000004H in the EAX register to get the brand string. Then refer to page 3-137 in IA-32 Intel Architecture Software Developers Manual, Volume 2A (http://developer.intel.com/design/Pentium4/documentation.htm) to parse the bits in EDX and ECX to get the maximum processor frequency.

Sample code:

#include

unsigned int max_frequency_Mhz
unsigned int current_frequency_Mhz;

PROCESSOR_POWER_INFORMATION ppi;

CallNtPowerInformation(ProcessorInformation, NULL, 0, &ppi,
sizeof(PROCESSOR_POWER_INFORMATION));

max_frequency_MHz = ppi.MaxMhz
current_frequency_MHz = ppi.CurrentMhz;

==

Lexi S.

IntelSoftware NetworkSupport

http://www.intel.com/software

Contact us

Message Edited by intel.software.network.support on 12-02-2005 08:48 PM

publicaciones de 3 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

A followup Q&A, two years after the original post:

Q. I have been developing a tool which as a minor feature also displays the current CPU frequency. Previously this was done by reading the TSC before and after a short time interval and some calculations. This worked great, even on Banias and other frequency changing CPUs. Well... until the Conroe CPUs arrived.

Sadly I cannot use the TSC anymore on these processors since it is constantly increasing now, no matter what the actual frequency is.

Then I read this forum thread. And on some systems I could get it to work again. On some other systems... not. For example, my Pentium M notebook (which shows the correct clock using the TSC method) shows a constant clock in PROCESSOR_POWER_INFORMATION.

There are Conroe systems where neither method will work, which is very frustrating.

Now, my question is: Is there ONE possibility (without writing a driver) to get the current frequency which works on all processors?

A. You can either write WMI provider using Win32_Processor, use Perfmon formatted/raw counter programmatically, or even write a quick PDH query to get data from existing perfmon counters.

==

Lexi S.

IntelSoftware NetworkSupport

http://www.intel.com/software

Contact us

Anotherengineer's responseto the last question:

You are not correctly taking into account power saving modes. Very likely you are measuring the frequency when the processor is in a lower power state, or your measurement time includes a period of time when you are coming out of that low power state.

Very likely you have BIOS configs that allow the processor to run at lower frequency when not loaded.

These transitions are now supported by newer operating systems -- they did not exist before. the method you describe for getting frequency will work. However, you need to be a bit more clever now. You can do something like this:

do 3 times

get start time and rdtsc

do something active (not sleep!) for 2 or 3 seconds-- do real computation here

get end time and rdtsc

If you print the values from each of these three attempts, you are likely to see a lower frequency the first time, and the correct frequency later times.

As a simpler solution, you might want to use the query_performance_counter from the OS instead of the timestamp counter.

==

Lexi S.

IntelSoftware NetworkSupport

http://www.intel.com/software

Contact us

Deje un comentario

Por favor inicie sesión para agregar un comentario. ¿No es socio? Únase ya