C#:如何在激活 TurboBoost 时获取 Intel i 系列 CPU 的当前时钟速度

标签 c# intel

我知道可以获取此信息 - 英特尔自己的 TurboBoost 边栏小工具似乎使用 ActiveX 控件来确定 TurboBoost 处于事件状态时 i3/i5/i7 CPU 的当前时钟速度。但是,我想在 C# 中以编程方式执行此操作 - 从 WMI 获取 CurrentClockSpeed 值以 CPU 的设置最大时钟速度达到最高,因此在 TurboBoost 模式下,它不会报告当前的实际时钟速度。

最佳答案

如果您想获得加速速度,您可以使用“% Processor Performance”性能计数器并将其与 WMI“MaxClockSpeed”相乘,如下所示:

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;
}

InfiniteLoop 方法只是一个加减 1 的整数:

private void InfiniteLoop()
{
  int i = 0;

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

刚刚添加的 InfiniteLoop 方法是为了让 CPU 有事可做,并在此过程中加速。在获取下一个值并中止循环之前,允许循环运行一秒钟。

我还在 this question 上发布了这个答案.

关于C#:如何在激活 TurboBoost 时获取 Intel i 系列 CPU 的当前时钟速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3020449/

相关文章:

c# - 尝试浏览 *.cshtml 文件时出现 "This type of page is not served."错误

c# - 使用多个用户控件从 Mysql 数据库加载大数据的最佳方法

c# - EF6 数据库初始化错误

c++ - RDTSC 开销的差异

c++ - 同时安装ifort和icc

linux - 并行程序给出错误 "Undefined reference to _Kmpc_ok_to_fork"

memory-management - 为什么 64 位模式(长模式)不使用段寄存器?

c# - 使用 linq 从 select new 返回多行

c# - Microsoft Server 2008 R2 不从任务计划程序写入文本文件

linux - 我怎么知道我是否可以使用 FMA 指令集进行编译?