Blog activation, and two programming experiences within three days (CPU frequency and timing, Windows power management API)

Source: Internet
Author: User
ArticleDirectory
    • Not related to CPU frequency in general

The csdn blog is too bad. It's okay to delete my article. What do you want.

This blog has recorded my experience on the IT field from now on, leaving a good memory for future study and sharing experiences with others who have encountered the same difficulties as me.

 

Write down the two items you want to write three days ago.

 

I. Windows power management API

 

 Void callback timerproc (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; settimer (null, timer1,  500  , Null );  While (Getmessage (& MSG, 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), which can return information such as whether the current ac is connected, whether the battery is connected, and whether the battery is powered on.

 

II. For precise timing, we often use the CPU Timestamp and CPU frequency to complete the tasks. I have always wondered whether the CPU frequency will be dynamically adjusted so that the timing is accurate. I tested it. No.

 
Large_integer litmp; Longlong qpart1;DoubleDffreq;//Obtain the timer clock frequencyQueryperformancefrequency (&Litmp); dffreq= (Double) Litmp. quadpart; queryperformancecounter (&Litmp); qpart1= Litmp. quadpart;

 

The frequency value obtained using queryperformancefrequence is very stable and remains unchanged. On my computer it is 2.2 GHz (2208009) and interestingly my computer is nominal at 2.26 GHz (266*8.5) and shows 2.26 GHz in both CPU-Z and Win8 task manager. Microsoft says on 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.57 MHz ). if you see a value around und 1.19 MHz then your system is using the old 8245 pit chip. otherwise you shocould 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.

That is, this frequency has nothing to do with the CPU frequency. This is only the timestamp frequency. The timestamp frequency is constant.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.