delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/04/20/18:46:53

Sender: nate AT cartsys DOT com
Message-ID: <371D1089.1E3B4979@cartsys.com>
Date: Tue, 20 Apr 1999 16:40:57 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.2.5 i586)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: high resolution timer
References: <8D53104ECD0CD211AF4000A0C9D60AE30130456A AT probe-2 DOT acclaim-euro DOT net> <371ca5ef DOT 2477952 AT noticias DOT iies DOT es>
Reply-To: djgpp AT delorie DOT com

Guillermo Rodriguez Garcia wrote:
 
> > Another option
> >would be to use the Pentium clock register, but that wouldn't
> >work on 486 and below...
> 
> But the Pentium clock register depends on the processor clock rate,
> thus it is system-dependet, isn't it? I may be wrong; could you please
> ellaborate this a bit more?

Yes.  But if you borrow a real-time timer for a little while at first,
you can run it against the clock counter and estimate the clock speed. 
Then you can use that to calibrate your measurements/delays/whatever.

Pseudocode:

volatile int tick;
void int_handler(void) { tick++; }

void calibrate()
{
   install_timer_interrupt(int_handler);
   set_timer_frequency(arbitrary_freq);
   tick = 0;
   while (!tick) /* loop */ ;
   start = rdtsc();
   tick = 0;
   while (!tick) /* loop */ ;
   end = rdtsc();
   clock_ticks_per_sec = (end - start) * arbitrary_freq;
}

-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019