文章目錄
- Not related to CPU frequency in general
CSDN部落格太不給力了,沒事刪我文章,想啥呢。
本部落格從今起記錄我在IT方面學習的道路上積累的經驗,為以後回首留下美好記憶,也為其他遇到與我一樣困難的人分享經驗。
先記下三天前想寫的兩個內容
一、windows的電源管理API
VOID CALLBACK TimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime){ std::cout << "hello" << std::endl;}int main(int argc, char *argv[]) { SYSTEM_POWER_STATUS spsPwr; int timer1 = 1; HWND hwndTimer; MSG msg; SetTimer(NULL,timer1,500,NULL); while (GetMessage(&msg,NULL,NULL,NULL)!= 0) { if (msg.message == WM_TIMER) { if(GetSystemPowerStatus(&spsPwr)) { if(static_cast<double>(spsPwr.ACLineStatus)!=1) { system("d:\\ttplayer\\TTPlayer.exe \"c:\\a.mp3\""); } } } } return 0;}
GetSystemPowerStatus(&SYSTEM_POWER_STATUS),能返回當前AC是否接入,電池是否接入,電池電量等資訊。
二、關於精確計時,常用CPU時間戳記和CPU頻率來完成,我一直疑惑CPU的頻率是會動態調節的,這樣計時還是否準確。測試了一下,不會。
LARGE_INTEGER litmp; LONGLONG QPart1; double dfFreq; //獲得計時器的時鐘頻率 QueryPerformanceFrequency(&litmp); dfFreq = (double)litmp.QuadPart; QueryPerformanceCounter(&litmp); QPart1 = litmp.QuadPart;
這裡用QueryPerformanceFrequence得到的頻率值非常穩 定,絲毫不變。在我的電腦上是2.2GHz(2208009),有意思的是我電腦標稱頻率為2.26GHz(266*8.5),並在CPU-Z和win8 工作管理員中都顯示2.26GHz。微軟msdn中說
Not related to CPU frequency in generalThe high frequency counter need not be tied to the CPU frequency at all. It will only resemble the CPU frequency is the system actually uses the TSC (TimeStampCounter) underneath. As the TSC is generally unreliable on multi-core systems it tends not to be used. When the TSC is not used the ACPI Power Management Timer (pmtimer) may be used. You can tell if your system uses the ACPI PMT by checking if QueryPerformanceFrequency returns the signature value of 3,579,545 (ie 3.57MHz). If you see a value around 1.19Mhz then your system is using the old 8245 PIT chip. Otherwise you should see a value approximately that of your CPU frequency (modulo any speed throttling or power-management that might be in effect.)
If you have a newer system with an invariant TSC (ie
constant frequency TSC) then that is the frequency that will be
returned (if Windows uses it). Again this is not necessarily the CPU
frequency.
也就是這個頻率和CPU頻率沒什麼關係,這隻是時間戳記頻率。時間戳記頻率是恒定的。