X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: "Rod Pemberton" Newsgroups: comp.os.msdos.djgpp Subject: Re: Performance enhancement for gettimeofday()? Date: Tue, 9 Jan 2007 03:46:03 -0500 Organization: Aioe.org NNTP Server Lines: 70 Message-ID: References: NNTP-Posting-Host: IVw7K97ih4IohxRqyKkqFw.user.aioe.org X-Complaints-To: abuse AT aioe DOT org X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Priority: 3 X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MSMail-Priority: Normal To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com wrote in message news:OF1B107D53 DOT 1922E890-ON8725725D DOT 005F267B-8725725D DOT 00633021 AT seagate DOT com... > I was indeed talking about the 18.2 per second timer - which appears to be > the one that DOS is using internally. So that staleness of the hundredths > field is already an issue just using the CMOS. Here's a snippet of > documentation on this: http://www.merlyn.demon.co.uk/prog2000.htm#MSF > I've also dug through the FreeDOS source code and confirmed that this is > how FD behaves. Interesting... Thanks for that. Looks like some more good info there too. > Use the following for proof: > > #include > #include > > int main() > { > int i; > for (i = 0; i < 400; i++) { > uclock_t start; > struct timeval tp; > > gettimeofday(&tp, NULL); > printf("%ld\t", tp.tv_usec); > // Uncomment if your machine is too fast... > // start = uclock(); > // while (uclock() < start + UCLOCKS_PER_SEC / 500); > } > printf("\n"); > return 0; > } > I'm sure I'll get around to trying it eventually. Seems like I have some need for everything six months or so later... :-) > The clock frequency should be (1.193*10^6) / 65536 Hz, which works out to > 18.203 or so. I'm modifying my code to use the more accurate calculation > starting with the crystal frequency instead of CLOCKS_PER_SEC (it means > doing floating-point math but it's still so much faster than the original > that it's still worth it). I believe this it the math you'll need: 14.318Mhz=4*3.58Mhz=4*(4.5Mhz*455/572) (4.5Mhz US TV bandwith/channel, 455 colorburst phase changes/line, 572 total lines/frame including sync) 14.318Mhz/12=1.93182Mhz 1.93182Mhz/65536=18.2065Hz > # I had hoped someone much more familiar with the issues you bring up would > # respond to you first... > > No worries. I've also posted some actual code over on DJGPP-Workers, > since this didn't seem like the appropriate place for it... I'll link > to it though: > http://www.delorie.com/djgpp/mail-archives/browse.cgi?p=djgpp-workers/2007/01/05/17:36:42 > Yes, thanks for that too. I usually only look at mail archives if GMANE NNTP-izes it. Rod Pemberton