我刚买了一个漂亮的MBA 13"Core i7.我被告知CPU速度会自动变化,而且非常疯狂.我真的希望能用一个简单的应用来监控它.
是否有任何Cocoa或C调用来查找当前时钟速度,而不会实际影响它?
编辑:我可以使用终端呼叫以及程序化来获得答案.
谢谢!
我正在构建一个微基准来测量性能变化,因为我在一些原始图像处理操作中尝试使用SIMD指令内在函数.但是,编写有用的微基准测试很困难,因此我想首先了解(如果可能的话)消除尽可能多的变异和误差源.
我必须考虑的一个因素是测量代码本身的开销.我正在使用RDTSC进行测量,我正在使用以下代码来查找测量开销:
extern inline unsigned long long __attribute__((always_inline)) rdtsc64() {
unsigned int hi, lo;
__asm__ __volatile__(
"xorl %%eax, %%eax\n\t"
"cpuid\n\t"
"rdtsc"
: "=a"(lo), "=d"(hi)
: /* no inputs */
: "rbx", "rcx");
return ((unsigned long long)hi << 32ull) | (unsigned long long)lo;
}
unsigned int find_rdtsc_overhead() {
const int trials = 1000000;
std::vector<unsigned long long> times;
times.resize(trials, 0.0);
for (int i = 0; i < trials; ++i) {
unsigned long long t_begin = rdtsc64();
unsigned long long t_end = rdtsc64(); …Run Code Online (Sandbox Code Playgroud) 我试图使用RDTSC,但似乎我的方法可能是错误的获得核心速度:
#include "stdafx.h"
#include <windows.h>
#include <process.h>
#include <iostream>
using namespace std;
struct Core
{
int CoreNumber;
};
static void startMonitoringCoreSpeeds(void *param)
{
Core core = *((Core *)param);
SetThreadAffinityMask(GetCurrentThread(), 1 << core.CoreNumber);
while (true)
{
DWORD64 first = __rdtsc();
Sleep(1000);
DWORD64 second = __rdtsc();
cout << "Core " << core.CoreNumber << " has frequency " << ((second - first)*pow(10, -6)) << " MHz" << endl;
}
}
int GetNumberOfProcessorCores()
{
DWORD process, system;
if (GetProcessAffinityMask(GetCurrentProcess(), &process, &system))
{
int count …Run Code Online (Sandbox Code Playgroud) 我使用以下代码来分析我的操作,以优化我的函数中的cpu周期.
static __inline__ unsigned long GetCC(void)
{
unsigned a, d;
asm volatile("rdtsc" : "=a" (a), "=d" (d));
return ((unsigned long)a) | (((unsigned long)d) << 32);
}
Run Code Online (Sandbox Code Playgroud)
我不认为这是最好的,因为即使连续两次通话也给了我"33"的差异.有什么建议 ?
我正在尝试制作一个C#软件来读取有关CPU的信息并将其显示给用户(就像CPU-Z一样).我目前的问题是我找不到显示CPU频率的方法.
起初我尝试使用Win32_Processor类的简单方法.事实证明它非常有效,除非CPU超频(或低频).
然后,我发现我的注册表在 HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0中包含CPU的"标准"时钟(即使超频).问题是在现代CPU中,当CPU不需要它的全功率时,核心乘法器正在减少,因此CPU频率也在变化,但是注册表中的值保持不变.
我的下一步是尝试使用RdTSC来实际计算CPU频率.我使用C++是因为如果方法正常,我可以将它嵌入到C#项目中.我在http://www.codeproject.com/Articles/7340/Get-the-Processor-Speed-in-two-simple-ways找到了下一个代码, 但问题是一样的:程序只给出了我的最大频率(比如在注册表值,1-2 Mhz的差异),它看起来像它加载CPU超过它应该(我甚至有CPU负载峰值).
#include "stdafx.h"
#include <windows.h>
#include <cstdlib>
#include "intrin.h"
#include <WinError.h>
#include <winnt.h>
float ProcSpeedCalc() {
#define RdTSC __asm _emit 0x0f __asm _emit 0x31
// variables for the clock-cycles:
__int64 cyclesStart = 0, cyclesStop = 0;
// variables for the High-Res Preformance Counter:
unsigned __int64 nCtr = 0, nFreq = 0, nCtrStop = 0;
// retrieve performance-counter frequency per second:
if(!QueryPerformanceFrequency((LARGE_INTEGER *) &nFreq))
return 0;
// retrieve …Run Code Online (Sandbox Code Playgroud)