怎么快速计算CPU的频率 要的是动态频率,和cpuz看到的同步,大家都看上吧

如何快速计算CPU的频率 要的是动态频率,和cpuz看到的同步,大家都看下吧
之前我一直用的是 读取smbus 得到cpu 的fsb,然后再乘 cpu倍频...
但我想有更好的方法..

要速度快,1s内可以完成至少三次以上运算吧..我那旧方法执行效率很快....

以下是我在网上搜索到的计算cpu clock的方法,但不理想

C/C++ code

float Cxxx::GetCpuClock(void)
{
    /*
    RdTSC:
    It's the Pentium instruction "ReaD Time Stamp Counter". It measures the
    number of clock cycles that have passed since the processor was reset, as a
    64-bit number. That's what the _emit lines do.*/
#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 the current value of the performance counter:
    QueryPerformanceCounter((LARGE_INTEGER *) &nCtrStop);

    // add the frequency to the counter-value:
    nCtrStop += nFreq;

    _asm
    {// retrieve the clock-cycles for the start value:
        RdTSC
            mov DWORD PTR cyclesStart, eax
            mov DWORD PTR [cyclesStart + 4], edx
    }

    do{// retrieve the value of the performance counter until 1 sec has gone by:
        QueryPerformanceCounter((LARGE_INTEGER *) &nCtr);
    }while (nCtr < nCtrStop);

    _asm
    {// retrieve again the clock-cycles after 1 sec. has gone by:
        RdTSC
            mov DWORD PTR cyclesStop, eax
            mov DWORD PTR [cyclesStop + 4], edx
    }

    // stop-start is speed in Hz divided by 1,000,000 is speed in MHz
    return    ((float)cyclesStop-(float)cyclesStart) / 1000000;
}





------解决方案--------------------
通用的话,估计都要用BIOS或底层汇编等来获取硬件信息...CPUz也不一定就获取那么快,可以自己插入一些假的信息
------解决方案--------------------
好高深,我是来接分的
------解决方案--------------------
硬件信息WIN32有取硬件信息的函数,用WMI的一组函数
------解决方案--------------------
反汇编它不就可以了么~~ 

------解决方案--------------------
很有难度
------解决方案--------------------
探讨
cpuz 获取的信息是正确,与我从smbus读到的fsb * cpu ration 的值是差不多的,他只是有小数值,并且,他支持所有板子,说明他不是用这种方法的,肯定用了别的方法...

我就是想知道有没有别的方法,我帖子上的那代码,运行效率太差了

cpu clock 要是动态的,比如 c1e的时候,频率会降的,那程序获取到的也会动态降....

------解决方案--------------------
探讨
反汇编它不就可以了么~~

------解决方案--------------------
。。。还在,我觉得通吃不现实!
------解决方案--------------------
在WndProc顺藤摸瓜找一找,看看它调用了什么函数,WIN32API还是什么的