(Very old) Regression following commit bfc0f59
I recently discovered that an ancient laptop built by Mtech and containing an AMD K6 450/2 CPU was generating errors when using the Cardbus versions of Broadcom cards using either b43 of b43legacy. Expecting some change in those drivers or ssb, I found a kernel old enough to work without the error, and did a bisection. I was very surprised when "x86: merge tsc calibration", which is commit bfc0f5947afa5e3a13e55867f4478c8a92c11dca (dated July 1, 2008), turned out to be the source of the regression. It was verified by generating a reversion patch. One main difference is that the bad code gets a processor speed of 214.398 MHz, whereas reverting the commit yields 428.845 MHz, which is more in keeping with the stated frequency of 450 MHz. As the machine is more than 10 years old, the clock may have drifted considerably.
I did some checking to see what parts of the commit needed to be reverted, and found that the bug is reversed by applying the patch below. I will continue to analyze the code to see if I can find the problem, but I wanted to see if anyone here could spot anything. I expect that it is a specific problem with the AMD K6, as I expect that such problems on current 32-bit CPUs would have been fixed long ago.
Thanks,
Larry
Reversion patch that works:
arch/x86/kernel/tsc_32.c +51 -0
@@ -65,6 +65,57 @@ void set_cyc2ns_scale(unsigned long cpu_local_irq_restore (flags); } +unsigned long native_calculate_cpu_khz (void ) +{ +unsigned long long start, end; +unsigned long count; +u64 delta64 = (u64 )ULLONG_MAX ; +int i; +unsigned long flags; + +local_irq_save (flags); + +/* run 3 times to ensure the cache is warm and to get an accurate reading */ +for (i =0 ; i <3 ; i++) { +mach_prepare_counter (); +rdtscll (start); +mach_countup (&count); +rdtscll (end); + +/* +* Error: ECTCNEVERSET +* The CTC wasn't reliable: we got a hit on the very first read, +* or the CPU was so fast/slow that the quotient wouldn't fit in +* 32 bits.. +*/ +if (count <=1 ) +continue ; + +/* cpu freq too slow: */ +if ((end - start) <=CALIBRATE_TIME_MSEC ) +continue ; + +/* +* We want the minimum time of all runs in case one of them +* is inaccurate due to SMI or other delay +*/ + delta64 =min (delta64, (end - start)); + } + +/* cpu freq too fast (or every run was bad): */ +if (delta64 > (1ULL <<32 )) + goto err; + + delta64 +=CALIBRATE_TIME_MSEC /2 ;/* round for do_div */ +do_div (delta64,CALIBRATE_TIME_MSEC ); + +local_irq_restore (flags); +return (unsigned long )delta64; +err: +local_irq_restore (flags); +return 0 ; +} +#ifdef CONFIG_CPU_FREQ /*
arch/x86/kernel/tsc.c +0 -106
118 lines not on this page · raw message