Message-ID: <0eec01c2e70c$1f78cef0$0600000a@broadpark.no> From: "Gisle Vanem" To: References: <10303100251 DOT AA12110 AT clio DOT rice DOT edu> Subject: Re: Example uclock() code Date: Mon, 10 Mar 2003 14:51:17 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1123 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1123 Reply-To: djgpp-workers AT delorie DOT com "Charles Sandmann" said: ... > + #define CALIBRATION_TICS 5 /* Testing shows 1.7% std error */ > + static long divider; > + static unsigned long long otsc; > + if (uclock_bss != __bss_count) { > + otics = _farnspeekl(0x46c); > + while ( (tics = _farnspeekl(0x46c)) == otics); A debugger will propably hang indefinitely here. Maybe add a __asm__("sti"). > + otsc = _rdtsc(); > + otics = tics; > + while ( (tics = _farnspeekl(0x46c)) <= otics+CALIBRATION_TICS); > + divider = (_rdtsc() - otsc) / ((tics - otics)*65536); > + if (divider) uclock_bss = __bss_count; > + } Instead of counting the TSC over CALIBRATION_TICS, it's better to *average* the TSC over CALIBRATION_TICS samples. This because of the jitter in the while-wait loops. It doesn't (as you said in original message) really wait N*ticks. BTW. the accuracy will depend on DOS-box setting of "Program | Advanced | Emulation of timekeeper" (or what ever it's called in English Windows). Reading the PIT is not very accurate even when set on. --gv