<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Allegro Timer Routine</title>
		<link>http://www.allegro.cc/forums/view/605621</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 25 Nov 2010 16:51:44 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi,<br />Interesting observation and wondered if anyone knew firstly why this has happened and secondly how I can get round it...</p><p>I have a couple of timers running - installed via:</p><p>  if ( install_int_ex(timer_proc, BPS_TO_TIMER(16)) &lt; 0 ) etc...</p><p>Anyway this updates a counter so that in the main loop I can flash a small &#39;alive&#39; rectangle on-screen...</p><p>Now I have recently installed ntpd (network time protocol daemon) and when the date/time gets updated (usually after about a minute or so after startup), the timer_proc() function no longer gets called...</p><p>Any comments/ideas?</p><p>Kev</p><p>EDIT:<br />Have got around this by incrementing an fps counter in the main loop and resetting it in the timer.. in the main loop I detect when this counter exceeds an expected range and reinstall the timers if this happens.</p><p>Still wonder what&#39;s happening though... <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>EDIT2:<br />Mmmm.... re-installing the timers doesn&#39;t work... <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kev Callahan)</author>
		<pubDate>Wed, 24 Nov 2010 16:38:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605621/891803#target">Kev Callahan</a> said:</div><div class="quote"><p>Mmmm.... re-installing the timers doesn&#39;t work...</p></div></div><p>Just how far off does your clock get? Might want to allow your distro/OS to set the clock on shut down, or get a new motherboard battery so it remembers the time <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /></p><p>Also, try <span class="source-code"><a href="http://www.allegro.cc/manual/remove_timer" target="_blank"><span class="a">remove_timer</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></span> then <span class="source-code"><a href="http://www.allegro.cc/manual/install_timer" target="_blank"><span class="a">install_timer</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></span> when reinitializing timers. Due to the way I seem to remember allegro timer&#39;s working, allegro registers ONE single os timer, and keeps track of time to handle fireing off individual user timers.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 25 Nov 2010 03:00:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605621/891892#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p> Just how far off does your clock get? Might want to allow your distro/OS to set the clock on shut down, or get a new motherboard battery so it remembers the time <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /></p></div></div><p>What?  I thought that every OS used the programmable timer that gets set on boot up from the battery-backed real time clock.  The one you had to enter the time every boot on the original PC because it didn&#39;t have a real time clock.  The one that DJGPP reprogrammed for finer granularity.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 25 Nov 2010 03:18:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605621/891901#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>What? I thought that every OS used the programmable timer that gets set on boot up from the battery-backed real time clock.</p></div></div><p>If your mobo battery is dead, the RTC on the mobo won&#39;t run when the machine is off, and will loose time.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 25 Nov 2010 04:01:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>But the time <i>intervals</i> will still be the same.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 25 Nov 2010 04:02:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605621/891912#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>But the time intervals will still be the same.</p></div></div><p>If allegro does its timing using absolute time values, then if the clock gets changed far enough, it may never get caught up.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 25 Nov 2010 04:29:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Once the boot process is complete, the motherboard timer runs at the correct rate, although not matched up to the wall clock.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 25 Nov 2010 04:32:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605621/891923#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>Once the boot process is complete, the motherboard timer runs at the correct rate, although not matched up to the wall clock</p></div></div><p>Not talking about the bios or the os. But Allegro itself. On windows its implemented in a thread that runs at a specific rate, and fires off installed timers. If its using the time from the OS to manage the timers, a large change in time will cause bad things to happen.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 25 Nov 2010 04:35:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>On Windows, doesn&#39;t it use QueryPerformanceCounter, which in turn uses the Pentium cycle count?  Nothing to do with timer chips at all.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 25 Nov 2010 04:46:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605621/891929#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>On Windows, doesn&#39;t it use QueryPerformanceCounter, which in turn uses the Pentium cycle count?</p></div></div><p>That would make it depend on the speed of the cpu would it not?</p><p>What I&#39;m saying is, if the time gets set via ntp, it&#39;ll skew the clock, which allegro <u>may</u> be using to know when to fire off timers. Not saying thats what is actually happens, just a possibility.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 25 Nov 2010 04:48:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605621/891930#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p> That would make it depend on the speed of the cpu would it not?</p></div></div><p>That&#39;s what QueryPerformanceFrequency() is for.  Or you mean the Cool&#39;n&#39;Quiet thing?  I think Windows adjusts for that with some sort of hook.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 25 Nov 2010 04:51:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605621/891931#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>That&#39;s what QueryPerformanceFrequency() is for.</p></div></div><p>the performance counter is not run at a fixed speed. The faster the cpu, the faster it increments afaik.</p><p>Also, took a look at the unix timer driver for allegro 4.4. It uses gettimeofday, so if the clock was set back far enough, it seems like it would indeed stop running user timers till the time caught up. Though I&#39;m not sure what select would do on a negative sleep period <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 25 Nov 2010 04:57:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I remember a couple of years ago this computer wouldn&#39;t keep a charge on the CMOS battery so I removed the battery altogether and set the time and optimized defaults every time I powered it up.  It ran fine until the next time it was powered down for 30 seconds or more.  Eventually it turned out to be a bad stick of RAM.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 25 Nov 2010 05:03:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605621/891935#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p> the performance counter is not run at a fixed speed. The faster the cpu, the faster it increments afaik.</p></div></div><p>Yes, hence QueryPerformanceFrequency(). That gives you the frequency at which the performance counter increases.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/605621/891942#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p> I remember a couple of years ago this computer wouldn&#39;t keep a charge on the CMOS battery so I removed the battery altogether and set the time and optimized defaults every time I powered it up.</p></div></div><p>I have a box here that does a similar thing. The battery never goes dead, though after the PSU stops applying standby power to the mobo, it will lose its settings. That box has no video card in it either at the moment, so I&#39;m very careful that it keeps power. It&#39;s sitting on a UPS and is configured to shut down conservatively, giving it plenty of time to remain powered to ride out all but the longest outages. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Thu, 25 Nov 2010 13:35:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Wow..! Thanks for the replies guys <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>I&#39;ll have a look at removing the timer first (probably a very sensible idea!) using remove_int().</p><p>Note this is on a small LX800 processor board running my hacked linux kernel and it has no built-in battery - hence why I&#39;m using NTP...</p><p>The first time-update from NTP is effectively 7 years(!) so can understand it could have a detrimental effect on the timer when it changes. Could have looked at the timer routines in allegro, but thought asking the question here would be easier <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> and more interesting.</p><p>Interestingly enough in my tests, this problem only manifests itself 30% of the time..</p><p>Will report in a moment back with success/failure of removing the timer first - thought it would be unnecessary as allegro would just overwrite the previous timer, which in hindsight was very naive of me..!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kev Callahan)</author>
		<pubDate>Thu, 25 Nov 2010 15:12:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>As far as I know allegro will just change the timer&#39;s freq if you give it the same timer function again. At least thats how I seem to remember it <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 25 Nov 2010 15:55:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, that was what I&#39;d expected... <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> maybe it was working - but have added the remove_int() call just in case and also tidied up some other code wrt displaying the date/time and all appears okay after 6 resets...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kev Callahan)</author>
		<pubDate>Thu, 25 Nov 2010 16:51:44 +0000</pubDate>
	</item>
</rss>
