Re: High Resolution Callback Timer (microseconds)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Tom Widmer (tom_usenet_at_hotmail.com)
Date: 03/10/05


Date: Thu, 10 Mar 2005 11:47:05 +0000

Michael Evans wrote:
> Anyone,
>
> I'm looking for a way to setup a callback function in our VC++ .net
> 2003 7.1 console application using a higher resolution timer. The
> multimedia timer is too low resolution at 1 millisecond. We need
> microsecond resolution to guarantee an exact update rate (60 or 70 Hz
> for example.)
>
> We use the Performance Counter to get microsecond resolution when
> measuring elapsed time, but there doesn't appear to be any tools for
> generating callbacks or interrupts, etc. at that higher resolution.
>
> Any ideas would be greatly appreciated. Thanks,

This isn't generally possible even with realtime operating systems.
Typically, OSes service timers at a particular resolution, such as every
1 ms, or whatever. If a timer callback or event is supposed to fire at
microsecond 123456, it will actually fire at the first kernel tick after
that time, say at microsecond 124000 (+ any kernel and scheduling latency).

The two approaches Carl mentioned are the two feasible ones. A realtime
operating system will give you almost perfect timings every time using
either (as long as priorities are set appropriately), while Windows will
give you, on average, reasonable timings (as long as priorities are set
appropriately), but with no guarantees. Remember to boost the priority
of the timing process and thread as high as possible, at least during
the critical regions (e.g. during the polling stage using technique 1).

If you are just updating a display, if you use DirectX, you shouldn't
need any timers better than 1ms accuracy. What exactly are you doing?

Tom



Relevant Pages

  • Re: [patch 00/21] hrtimer - High-resolution timer subsystem
    ... Right now the primary function of the state is to tell whether the timer ... > Of course if you consider the possibility of including high resolution ... problem requires solving problems in the clock abstraction first, ...
    (Linux-Kernel)
  • Re: [patch 00/21] hrtimer - High-resolution timer subsystem
    ... >> This way the list head is only necessary for the high resolution case. ... > (e.g. wakeup + timer restart). ... Even if the clock ...
    (Linux-Kernel)
  • Re: [PATCH] ktimers subsystem 2.6.14-rc2-kt5
    ... >>The cleanup I pointed out for the posix timer interval timers is pretty ... >>the posix timer structure. ... The rounding to the resolution value is explicitly required by the ... This says a) round to the next resolution, and b) don't allow the resulting timer to expire early. ...
    (Linux-Kernel)
  • Re: [PATCH] ktimers subsystem 2.6.14-rc2-kt5
    ... > a clock with a better resolution. ... > resolution than the physical clock has. ... reaches this count the timer is expired. ... OTOH We could also do this at the timer interrupt: ...
    (Linux-Kernel)
  • Re: VB6 code runs different speeds on different PCs
    ... As you've discovered, the minimum Sleep period can be different on different machines (5 milliseconds on my own WinXP system, but longer than that on others I think). ... You can get whatever "game rate" you want in a closed loop of course, by checking a high resolution timing source. ... If I were you I would use a proper Timer with a higher resolution that the standard VB Timer and run your entire game in the Timer event. ... Admittedly, updating their positions more than once every ten milliseconds does appear to give smoother animation (even though the video frame rate simply cannot draw a new frame at a rate greater than every 10 milliseconds,or so, depending on your display settings) because it tends iron out the differences more. ...
    (microsoft.public.vb.general.discussion)