Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86: use cpu_khz for loops_per_jiffy calculation, cleanup

As suggested by Ingo, remove all references to tsc from init/calibrate.c

TSC is x86 specific, and using tsc in variable names in a generic file should
be avoided. lpj_tsc is now called lpj_fine, since it is related to fine tuning
of lpj value. Also tsc_rate_* is called timer_rate_*

Signed-off-by: Alok N Kataria <akataria@vmware.com>
Cc: Arjan van de Ven <arjan@infradead.org>
Cc: Daniel Hecht <dhecht@vmware.com>
Cc: Tim Mann <mann@vmware.com>
Cc: Zach Amsden <zach@vmware.com>
Cc: Sahil Rihan <srihan@vmware.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

authored by

Alok Kataria and committed by
Ingo Molnar
f3f3149f 6ff10de3

+22 -20
+1 -1
arch/x86/kernel/time_64.c
··· 123 123 (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)) 124 124 cpu_khz = calculate_cpu_khz(); 125 125 126 - lpj_tsc = ((unsigned long)tsc_khz * 1000)/HZ; 126 + lpj_fine = ((unsigned long)tsc_khz * 1000)/HZ; 127 127 128 128 if (unsynchronized_tsc()) 129 129 mark_tsc_unstable("TSCs unsynchronized");
+1 -1
arch/x86/kernel/tsc_32.c
··· 425 425 426 426 lpj = ((u64)tsc_khz * 1000); 427 427 do_div(lpj, HZ); 428 - lpj_tsc = lpj; 428 + lpj_fine = lpj; 429 429 430 430 printk("Detected %lu.%03lu MHz processor.\n", 431 431 (unsigned long)cpu_khz / 1000,
+1 -1
include/linux/delay.h
··· 41 41 #define ndelay(x) ndelay(x) 42 42 #endif 43 43 44 - extern unsigned long lpj_tsc; 44 + extern unsigned long lpj_fine; 45 45 void calibrate_delay(void); 46 46 void msleep(unsigned int msecs); 47 47 unsigned long msleep_interruptible(unsigned int msecs);
+19 -17
init/calibrate.c
··· 10 10 #include <linux/timex.h> 11 11 #include <linux/smp.h> 12 12 13 - unsigned long lpj_tsc; 13 + unsigned long lpj_fine; 14 14 unsigned long preset_lpj; 15 15 static int __init lpj_setup(char *str) 16 16 { ··· 35 35 unsigned long pre_start, start, post_start; 36 36 unsigned long pre_end, end, post_end; 37 37 unsigned long start_jiffies; 38 - unsigned long tsc_rate_min, tsc_rate_max; 39 - unsigned long good_tsc_sum = 0; 40 - unsigned long good_tsc_count = 0; 38 + unsigned long timer_rate_min, timer_rate_max; 39 + unsigned long good_timer_sum = 0; 40 + unsigned long good_timer_count = 0; 41 41 int i; 42 42 43 43 if (read_current_timer(&pre_start) < 0 ) ··· 81 81 } 82 82 read_current_timer(&post_end); 83 83 84 - tsc_rate_max = (post_end - pre_start) / DELAY_CALIBRATION_TICKS; 85 - tsc_rate_min = (pre_end - post_start) / DELAY_CALIBRATION_TICKS; 84 + timer_rate_max = (post_end - pre_start) / 85 + DELAY_CALIBRATION_TICKS; 86 + timer_rate_min = (pre_end - post_start) / 87 + DELAY_CALIBRATION_TICKS; 86 88 87 89 /* 88 - * If the upper limit and lower limit of the tsc_rate is 90 + * If the upper limit and lower limit of the timer_rate is 89 91 * >= 12.5% apart, redo calibration. 90 92 */ 91 93 if (pre_start != 0 && pre_end != 0 && 92 - (tsc_rate_max - tsc_rate_min) < (tsc_rate_max >> 3)) { 93 - good_tsc_count++; 94 - good_tsc_sum += tsc_rate_max; 94 + (timer_rate_max - timer_rate_min) < (timer_rate_max >> 3)) { 95 + good_timer_count++; 96 + good_timer_sum += timer_rate_max; 95 97 } 96 98 } 97 99 98 - if (good_tsc_count) 99 - return (good_tsc_sum/good_tsc_count); 100 + if (good_timer_count) 101 + return (good_timer_sum/good_timer_count); 100 102 101 103 printk(KERN_WARNING "calibrate_delay_direct() failed to get a good " 102 104 "estimate for loops_per_jiffy.\nProbably due to long platform interrupts. Consider using \"lpj=\" boot option.\n"); ··· 113 111 * bit takes on average 1.5/HZ seconds. This (like the original) is a little 114 112 * better than 1% 115 113 * For the boot cpu we can skip the delay calibration and assign it a value 116 - * calculated based on the tsc frequency. 117 - * For the rest of the CPUs we cannot assume that the tsc frequency is same as 114 + * calculated based on the timer frequency. 115 + * For the rest of the CPUs we cannot assume that the timer frequency is same as 118 116 * the cpu frequency, hence do the calibration for those. 119 117 */ 120 118 #define LPS_PREC 8 ··· 128 126 loops_per_jiffy = preset_lpj; 129 127 printk(KERN_INFO 130 128 "Calibrating delay loop (skipped) preset value.. "); 131 - } else if ((smp_processor_id() == 0) && lpj_tsc) { 132 - loops_per_jiffy = lpj_tsc; 129 + } else if ((smp_processor_id() == 0) && lpj_fine) { 130 + loops_per_jiffy = lpj_fine; 133 131 printk(KERN_INFO 134 132 "Calibrating delay loop (skipped), " 135 - "using tsc calculated value.. "); 133 + "value calculated using timer frequency.. "); 136 134 } else if ((loops_per_jiffy = calibrate_delay_direct()) != 0) { 137 135 printk(KERN_INFO 138 136 "Calibrating delay using timer specific routine.. ");