386/486 clock frequency
Hi,
The following patch provides a resonable estimate of the clock
frequency for the 386 & 486. It is based on the bogomips (aka loops_per_jiffy) and an estimate of the cycles per loop in the delay routine. Some values I have seen:
ALR Business VEISA (with 386@33 MHz cpu card): 32.704 above system with 486DX2@66 cpu card and a Kingston TurboChip (AMD 5x86): 132.710 Nec VersaM/100 (kernel 2.2.12): 99.5328 Patch is against 2.4.31.
Documentation/Configure.help +15 -0
@@ -20640,6 +20640,21 @@ For pentium machines the mce support defaults to off as the mainboard support is not always present. You must activate it as a boot option. +386/486 Clock Speed Guess +CONFIG_386_CLK_GUESS + This will include code to guesstimate the 386 clock speed from the + computed loops per jiffy value and knowledge of the number of cycles + that each loop in the delay routine takes + +Override Default Cycles Per Loop +CONFIG_386_CLK_CPL + This allows you to override the default cycles per loop value used to + guess the clock speed. The defaults are 10 for the 386 and 4 for the 486. + A non-zero value overrides the defaults. This can also be used to compensate + for known wait states. Especially useful if your 386 cache card blows up. + The actual computation is: + hz = loops_per_jiffy * HZ * cycles_per_loop + Toshiba Laptop support CONFIG_TOSHIBA This adds a driver to safely access the System Management Mode of
arch/i386/config.in +7 -0
@@ -192,6 +192,13 @@ define_bool CONFIG_X86_F00F_WORKS_OK y fi +if [ "$CONFIG_M386" = "y" -o "$CONFIG_M486" = "y" -o "$CONFIG_M586" = "y"]; then + bool 'Enable 386 Clock Guess' CONFIG_386_CLK_GUESS + if [ "$CONFIG_386_CLK_GUESS" = "y" ]; then + int ' Override default cycles per loop' CONFIG_386_CLK_CPL 0 + fi +fi + bool 'Machine Check Exception' CONFIG_X86_MCE tristate 'Toshiba Laptop support' CONFIG_TOSHIBA
arch/i386/kernel/setup.c +1 -1
@@ -3112,7 +3112,7 @@else seq_printf (m,"stepping\t: unknown\n" ); -if (test_bit (X86_FEATURE_TSC , &c->x86_capability) ) { +if ( cpu_khz ) {seq_printf (m,"cpu MHz\t\t: %lu.%03lu\n" , cpu_khz /1000 , (cpu_khz %1000 )); }
arch/i386/kernel/time.c +36 -0
@@ -841,6 +841,8 @@ xtime.tv_sec =get_cmos_time (); xtime.tv_usec =0 ; + cpu_khz =0 ; +/* * If we have APM enabled or the CPU clock speed is variable * (CPU stops clock on HLT or slows clock to save power)
@@ -924,3 +926,37 @@setup_irq (0 , &irq0);#endif } + +#ifdef CONFIG_386_CLK_GUESS +/* +* Need this to run AFTER the delay loop has been calibrated +*/ +void __init init_386_clock (void ) +{ +/* +* If already computed just bail +*/ +if (cpu_khz)return ; + +if (boot_cpu_data.x86==3 || boot_cpu_data.x86==4 ) { +/* +* Each loop in __delay() takes 10 cycles on a 386 and 4? +* on a 486. Allow these to be overriden during config for +* mutant 386 and 486 clones. +*/ +#if CONFIG_386_CLK_CPL !=0 + cpu_khz=CONFIG_386_CLK_CPL ; +#else + cpu_khz=(boot_cpu_data.x86==3 )?10 :4 ; +#endif + + + cpu_khz=boot_cpu_data.loops_per_jiffy*HZ *cpu_khz; + cpu_khz=(cpu_khz+500 )/1000 ; +printk ("Guesstimated %lu.%03lu MHz processor.\n" , cpu_khz /1000 , cpu_khz %1000 ); + } +} + +__initcall (init_386_clock); +#endif +
arch/i386/lib/delay.c +5 -0
@@ -47,6 +47,11 @@static void __loop_delay (unsigned long loops) {int d0; + +/* +* If this is changed the cycles for loop estimates will need to be +* looked at for the 386/486 clock estimation code in kernel/time.c +*/ __asm__ __volatile__("\tjmp 1f\n" ".align 16\n"