Mail Archives: djgpp/1999/02/20/11:17:15
Engard Ferenc wrote:
> My program does it's timing with empty loop:
>
> void do_delay (unsigned long i)
> { while(i--) ; }
>
> The calibration is nearly the same as the linux-kernel bogomips-computing
> (actually, I have copied it from there... :-)
I never looked at the linux version, but I have tested
such routines several times while advising various people
doing write-your-own-OS projects.
Generally, this method of timing is so full of pitfalls
that I advise against using it. At minimum, it is heavily
dependant on the memory alignment of the code itself.
(I don't know whether it may be suffitiently nonoptimized
by GCC switches that it could also depend on the memory
alignment of the stack). At minimum you must calibrate it
on startup and you MUST use the routine itself in its own
calibration. The common method of calibrating with a
similar (or even identical) loop elsewhere in the code,
is unsound.
After proper calibration, this method *might* work. If
you have another reasonable choice, you shouldn't use this
method at all.
--
http://www.erols.com/johnfine/
http://www.geocities.com/SiliconValley/Peaks/8600/
- Raw text -