delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/04/03:20:37

Message-Id: <199803040823.KAA53802@ieva06.lanet.lv>
From: "Andris Pavenis" <pavenis AT laima DOT acad DOT latnet DOT lv>
To: djgpp AT delorie DOT com, Nate Eldredge <eldredge AT ap DOT net>
Date: Wed, 4 Mar 1998 10:20:16 +0000
MIME-Version: 1.0
Subject: Re: A question about DJGPP's clock?()
In-reply-to: <199803040137.RAA07815@adit.ap.net>

> >If You really don't nead portability and You using PENTIUM OR BETTER
> >CPU then why not to use Pentium timestamp counter. It is very easy to
> >read it.
> [snipped]
> >should get time in variable A; Note that timestamp counter counts
> >CPU clocks so You need to divide result with CPU clock frequency to
> >get seconds.
> 
> But beware that finding the clock frequency through software is a difficult
> task! It's fine if you're only going to use it on your own machine, but
> otherwise, it may not be worth it.
> 
Read clocks count twice or more times from timer interrupt handler. RTC
interrupt handler could also be used. Then the finding clock frequency is
easy with rather food accuracy.

One of possible uses of rdtsc instruction is for profiling program to find
program fragments that eats most CPU time. Such use does not require
knowledge of clock frequency at all and the corresponding code is more
likely to be removed before release of software.

> > This code should work also under Linux.
> 
> If I'm correct, RDTSC is a privileged instruction, so it may give a fatal
> signal instead. I think the system can set a bit in a control register to
> allow user programs to use the TSC, but I don't know whether Linux does.
> Have you tried it? (I would, but I don't have a Pentium.)
> 
Yes I have tried it also under Linux (with another macrodefinition) and it 
worked OK. Commands RDMSR and WRMSR requires program to be run 
in ring 0 but I'm perhaps will not mess with them. Under Linux 
I used different macrodefinitions. 

Some more information is available at:
 	http://www.goof.com/pcg/data/djgpp/p5prof.zip
	http://www.goof.com/pcg/binaries-djgpp.html

Andris

- Raw text -


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