Thursday 15 March 2012

c++ - High resolution timers vs low resolution timers -


I have recently read about high resolution and low resolution timers, and I do not quite understand . how do they work? Do they not work by checking the internal system clock on computer hardware? If this is the case, does it mean that higher resolution only checks resources more often?

Is there something wrong with me when using a low resolution timer and when a high resolution timer starts inside that timer when it is considered to prevent high resolution timers (or soon)? Or will it not work for some reason?

How much does it consume about a high resolution timer compared to the low resolution timer? Typically, a low-resolution timer will fire every X amount in the processor (say, every 1, 5, 10, 16.6667, 17.81291 or 20 mms - Examples, there are several other values ​​that can be). This is used by the OS to switch the work when a task is "too long" as well as the time of waiting events, such as the time of waiting, and such things (for example, sleep < / Code> type function will set itself to call "end time" at the end of the end of sleep).

A high resolution timer is usually a hardware register that continually counts up [up or down] / frequency at high KHz or higher (e.g. 32768Hz, 36KHz, 12MHz, 2.2GHz) Just a few examples are updated, almost anything can happen). Generally, it is used to "read the current value", and whatever you get current count.

This will give a higher resolution timing value, which is useful for measuring short intervals (for example benchmarking or finding out how much time other server takes to respond to ping, or some other Small amounts of time), but you can not actually wait for "600 ms" using a high resolution timer - without least reading, the timer is called a gojiyan bar, why not Nki you can not (in general I tell describes me) "OS here again to start the calculation of the work X number".

(However, sometimes high resolution timers are just hardware similar to low hardware, which are done only in different ways - the difference I mentioned above is still relevant, whether it is one or more Types of time are different units).

Keep in mind that if you want "accurate time", then the OS will have to play well. Most modern OS "dislike" tasks that just sit there and CPU-time (for example "what are we still" type of voting timer), will give the other shorter runtime preference other functions. If you need a high precise time, then the OS needs to help you, you can not stop your work from running as a timely step. To know exactly what you are trying to do, it is difficult to ensure that what is the right solution in your case, though.

No comments:

Post a Comment