| delorie.com/archives/browse.cgi | search |
| Message-ID: | <0eec01c2e70c$1f78cef0$0600000a@broadpark.no> |
| From: | "Gisle Vanem" <giva AT bgnett DOT no> |
| To: | <djgpp-workers AT delorie DOT com> |
| 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 |
| 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" <sandmann AT clio DOT rice DOT edu> 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
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |