6

I know that it's possible to get this information - Intel's own TurboBoost sidebar gadget appears to use an ActiveX control to determine the current clock speed of an i3/i5/i7 CPU when TurboBoost is active. However, I'm wanting to do this programmatically in C# - obtaining the CurrentClockSpeed value from WMI tops out at the set maximum clock speed of the CPU, so in TurboBoost mode, it doesn't report the current actual clock speed.

CXL
  • 1,094
  • 2
  • 15
  • 38

2 Answers2

2

I do not believe it's possible to obtain this information with only safe/managed C# code, since WMI does not seem to supply this information. So i think you will need to use the CPUID instruction to get detailed information from the CPU that executes the instruction.

This documentation from Intel might help get you started:

http://www.intel.com/assets/pdf/appnote/241618.pdf

And here's some unsafe code to use with C#:

An attempt to bring CPUID to C#

Also see page 7 of:

Intel® Turbo Boost Technology in Intel® Core™ Microarchitecture (Nehalem) Based Processors

Christian.K
  • 47,778
  • 10
  • 99
  • 143
tgiphil
  • 1,242
  • 10
  • 22
  • Heh..I just found that article in your second link a few minutes ago. It's a bit over my head though, as far as how to use that DLL to obtain the current clock speed from the processor. At the very least, it doesn't appear that this is very simple at all to do. – CXL Jun 11 '10 at 07:09
2

If you want to get the turbo speed, you can make use of the "% Processor Performance" performance counter and multiply it with the WMI "MaxClockSpeed" as follows:

private string GetCPUInfo()
{
  PerformanceCounter cpuCounter = new PerformanceCounter("Processor Information", "% Processor Performance", "_Total");
  double cpuValue = cpuCounter.NextValue();

  Thread loop = new Thread(() => InfiniteLoop());
  loop.Start();

  Thread.Sleep(1000);
  cpuValue = cpuCounter.NextValue();
  loop.Abort();

  foreach (ManagementObject obj in new ManagementObjectSearcher("SELECT *, Name FROM Win32_Processor").Get())
  {
    double maxSpeed = Convert.ToDouble(obj["MaxClockSpeed"]) / 1000;
    double turboSpeed = maxSpeed * cpuValue / 100;
    return string.Format("{0} Running at {1:0.00}Ghz, Turbo Speed: {2:0.00}Ghz",  obj["Name"], maxSpeed, turboSpeed);
  }

  return string.Empty;
}

The InfiniteLoop method is simply an integer that gets 1 added and subtracted:

private void InfiniteLoop()
{
  int i = 0;

  while (true)
    i = i + 1 - 1;
}

The InfiniteLoop method is just added to give the CPU something to do and turbo in the process. The loop is allowed to run for a second before the next value is taken and the loop aborted.

I also posted this answer on this question.

RooiWillie
  • 2,198
  • 1
  • 30
  • 36
  • Thanks. :) This is a very old question, and at the time there were no APIs for acquiring this information natively. In 2010 Core i was still very new. – CXL Sep 18 '19 at 02:55