thx!
![Cool 8)](./images/smilies/icon_cool.gif)
More here: http://en.wikipedia.org/wiki/BogoMipsWiki wrote:BogoMips (from "bogus" and MIPS) is an unscientific measurement of CPU speed made by the Linux kernel when it boots, to calibrate an internal busy-loop. An oft-quoted definition of the term is "the number of million times per second a processor can do absolutely nothing".
BogoMips can be used to see whether it is in the proper range for the particular processor, its clock frequency, and the potentially present CPU cache. It is not usable for performance comparison between different CPUs.
Code: Select all
#define LPS_PREC 8
unsigned long loops_per_jiffy = (1<<12);
extern unsigned int HZ; // should be 100
extern volatile unsigned long long total_ticks; // total tick count
extern void delay_loops(int loops);
void delay_loops(int loops)
{
long i;
for (i = loops; i >= 0 ; i--);
}
int calibrate_delay(void)
{
unsigned long ticks, loopbit;
int lps_precision = LPS_PREC;
loops_per_jiffy = (1<<12);
while (loops_per_jiffy <<= 1)
{
ticks = total_ticks;
while (ticks == total_ticks);
ticks = total_ticks;
delay_loops(loops_per_jiffy);
ticks = total_ticks - ticks;
if (ticks)
break;
}
loops_per_jiffy >>= 1;
loopbit = loops_per_jiffy;
while ( lps_precision-- && (loopbit >>= 1) )
{
loops_per_jiffy |= loopbit;
ticks = total_ticks;
while (ticks == total_ticks);
ticks = total_ticks;
delay_loops(loops_per_jiffy);
if (total_ticks != ticks)
loops_per_jiffy &= ~loopbit;
}
return loops_per_jiffy/(500000/HZ);
}
http://www.opengroup.org/onlinepubs/009 ... clock.htmlSUS wrote:The clock() function shall return the implementation's best approximation to the processor time used by the process since the beginning of an implementation-defined era related only to the process invocation.
Well, "clock()" doesn't return the time "since" the system started, I advise you to read the function description againGLneo wrote:well HZ is 100, it is an extern variable, it is set else ware, as for the total_ticks, it is the number of clock ticks sense system start, i figured sense it is volatile it should just change and you wont have to keep calling clock().
Code: Select all
void delay_loops(int loops)
{
long i;
for (i = loops; i >= 0 ; i--) {
in_byte(dummy_IO_port);
}
}
I don't like the Linux kernel maintainers either, but this is unjust. The BogoMips delay loop is intended to be used for extremly short timespans only, where "the time is too short and/or needs to be too exact for a non-busy-loop method of waiting" (quoted from the BogoMips FAQ).Brendan wrote:A better approach is to use a timer for timing, but Linux programmers don't think like that...
Strangly enough with given the arguments above about power management, SMI, thermal throttling and the fact that the use of rdtsc is discouraged because of these reasons. It seems rather contradictory or odd to use the phrase ""the time is too short and/or needs to be too exact for a non-busy-loop method of waiting". BogoMips is not accurate. Yet the suggestion made by Brendan about using IO i find more acceptable. I have done some measurements with the outportb(0x80,0x80) suggested by linux and found out that on and AMD X2 it takes about .7 microsecconds and on an intel about 1 microsecond. So that is rather accurate what processes need a higher resolution?Solar wrote:The BogoMips delay loop is intended to be used for extremly short timespans only, where "the time is too short and/or needs to be too exact for a non-busy-loop method of waiting" (quoted from the BogoMips FAQ).
That phrase was the reason why BogoMips were originally invented, and also the reason why "using a timer" isn't really the alternative.os64dev wrote:Strangly enough with given the arguments above about power management, SMI, thermal throttling and the fact that the use of rdtsc is discouraged because of these reasons. It seems rather contradictory or odd to use the phrase...
...and thus "calibrated your delay loop", only with a port operation instead of BogoMips.I have done some measurements...
As I said, when Bogomips was first invented CPUs ran at a fixed frequency, and Bogomips was a perfectly valid and correct method at that time.Solar wrote:That phrase was the reason why BogoMips were originally invented, and also the reason why "using a timer" isn't really the alternative.os64dev wrote:Strangly enough with given the arguments above about power management, SMI, thermal throttling and the fact that the use of rdtsc is discouraged because of these reasons. It seems rather contradictory or odd to use the phrase...
Code: Select all
if( CPU_has_fixed_frequency_RDTSC ) {
use_calibrated_RDTSC();
} else if( CPU_has_localAPIC() ) {
use_calibrated_LAPIC_count();
} else if( HPET_is_supported() ) {
use_HPET();
} else if( CPU_is_fixed_cycles_per_second() ) {
use_calibrated_LOOP();
} else {
use_PIT_channel2_count();
}
The only nasty part of 0x80 is that it happens to be a nice dummy port, which Bochs nicely happens to report as invalid DMA port (because that's why it's nice dummy port) when you enable DMA debuggin in Bochs, which will make the debug messages for DMA a total flood and it'll be impossible to find the really relevant lines..os64dev wrote: I have done some measurements with the outportb(0x80,0x80) suggested by linux and found out that on and AMD X2 it takes about .7 microsecconds and on an intel about 1 microsecond. So that is rather accurate what processes need a higher resolution?