Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f3f3149f authored by Alok Kataria's avatar Alok Kataria Committed by Ingo Molnar
Browse files

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: default avatarAlok 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: default avatarIngo Molnar <mingo@elte.hu>
parent 6ff10de3
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -123,7 +123,7 @@ void __init time_init(void)
		(boot_cpu_data.x86_vendor == X86_VENDOR_AMD))
		(boot_cpu_data.x86_vendor == X86_VENDOR_AMD))
		cpu_khz = calculate_cpu_khz();
		cpu_khz = calculate_cpu_khz();


	lpj_tsc = ((unsigned long)tsc_khz * 1000)/HZ;
	lpj_fine = ((unsigned long)tsc_khz * 1000)/HZ;


	if (unsynchronized_tsc())
	if (unsynchronized_tsc())
		mark_tsc_unstable("TSCs unsynchronized");
		mark_tsc_unstable("TSCs unsynchronized");
+1 −1
Original line number Original line Diff line number Diff line
@@ -425,7 +425,7 @@ void __init tsc_init(void)


	lpj = ((u64)tsc_khz * 1000);
	lpj = ((u64)tsc_khz * 1000);
	do_div(lpj, HZ);
	do_div(lpj, HZ);
	lpj_tsc = lpj;
	lpj_fine = lpj;


	printk("Detected %lu.%03lu MHz processor.\n",
	printk("Detected %lu.%03lu MHz processor.\n",
				(unsigned long)cpu_khz / 1000,
				(unsigned long)cpu_khz / 1000,
+1 −1
Original line number Original line Diff line number Diff line
@@ -41,7 +41,7 @@ static inline void ndelay(unsigned long x)
#define ndelay(x) ndelay(x)
#define ndelay(x) ndelay(x)
#endif
#endif


extern unsigned long lpj_tsc;
extern unsigned long lpj_fine;
void calibrate_delay(void);
void calibrate_delay(void);
void msleep(unsigned int msecs);
void msleep(unsigned int msecs);
unsigned long msleep_interruptible(unsigned int msecs);
unsigned long msleep_interruptible(unsigned int msecs);
+19 −17
Original line number Original line Diff line number Diff line
@@ -10,7 +10,7 @@
#include <linux/timex.h>
#include <linux/timex.h>
#include <linux/smp.h>
#include <linux/smp.h>


unsigned long lpj_tsc;
unsigned long lpj_fine;
unsigned long preset_lpj;
unsigned long preset_lpj;
static int __init lpj_setup(char *str)
static int __init lpj_setup(char *str)
{
{
@@ -35,9 +35,9 @@ static unsigned long __cpuinit calibrate_delay_direct(void)
	unsigned long pre_start, start, post_start;
	unsigned long pre_start, start, post_start;
	unsigned long pre_end, end, post_end;
	unsigned long pre_end, end, post_end;
	unsigned long start_jiffies;
	unsigned long start_jiffies;
	unsigned long tsc_rate_min, tsc_rate_max;
	unsigned long timer_rate_min, timer_rate_max;
	unsigned long good_tsc_sum = 0;
	unsigned long good_timer_sum = 0;
	unsigned long good_tsc_count = 0;
	unsigned long good_timer_count = 0;
	int i;
	int i;


	if (read_current_timer(&pre_start) < 0 )
	if (read_current_timer(&pre_start) < 0 )
@@ -81,22 +81,24 @@ static unsigned long __cpuinit calibrate_delay_direct(void)
		}
		}
		read_current_timer(&post_end);
		read_current_timer(&post_end);


		tsc_rate_max = (post_end - pre_start) / DELAY_CALIBRATION_TICKS;
		timer_rate_max = (post_end - pre_start) /
		tsc_rate_min = (pre_end - post_start) / DELAY_CALIBRATION_TICKS;
					DELAY_CALIBRATION_TICKS;
		timer_rate_min = (pre_end - post_start) /
					DELAY_CALIBRATION_TICKS;


		/*
		/*
	 	 * If the upper limit and lower limit of the tsc_rate is
		 * If the upper limit and lower limit of the timer_rate is
		 * >= 12.5% apart, redo calibration.
		 * >= 12.5% apart, redo calibration.
		 */
		 */
		if (pre_start != 0 && pre_end != 0 &&
		if (pre_start != 0 && pre_end != 0 &&
		    (tsc_rate_max - tsc_rate_min) < (tsc_rate_max >> 3)) {
		    (timer_rate_max - timer_rate_min) < (timer_rate_max >> 3)) {
			good_tsc_count++;
			good_timer_count++;
			good_tsc_sum += tsc_rate_max;
			good_timer_sum += timer_rate_max;
		}
		}
	}
	}


	if (good_tsc_count)
	if (good_timer_count)
		return (good_tsc_sum/good_tsc_count);
		return (good_timer_sum/good_timer_count);


	printk(KERN_WARNING "calibrate_delay_direct() failed to get a good "
	printk(KERN_WARNING "calibrate_delay_direct() failed to get a good "
	       "estimate for loops_per_jiffy.\nProbably due to long platform interrupts. Consider using \"lpj=\" boot option.\n");
	       "estimate for loops_per_jiffy.\nProbably due to long platform interrupts. Consider using \"lpj=\" boot option.\n");
@@ -111,8 +113,8 @@ static unsigned long __cpuinit calibrate_delay_direct(void) {return 0;}
 * bit takes on average 1.5/HZ seconds.  This (like the original) is a little
 * bit takes on average 1.5/HZ seconds.  This (like the original) is a little
 * better than 1%
 * better than 1%
 * For the boot cpu we can skip the delay calibration and assign it a value
 * For the boot cpu we can skip the delay calibration and assign it a value
 * calculated based on the tsc frequency.
 * calculated based on the timer frequency.
 * For the rest of the CPUs we cannot assume that the tsc frequency is same as
 * For the rest of the CPUs we cannot assume that the timer frequency is same as
 * the cpu frequency, hence do the calibration for those.
 * the cpu frequency, hence do the calibration for those.
 */
 */
#define LPS_PREC 8
#define LPS_PREC 8
@@ -126,11 +128,11 @@ void __cpuinit calibrate_delay(void)
		loops_per_jiffy = preset_lpj;
		loops_per_jiffy = preset_lpj;
		printk(KERN_INFO
		printk(KERN_INFO
			"Calibrating delay loop (skipped) preset value.. ");
			"Calibrating delay loop (skipped) preset value.. ");
	} else if ((smp_processor_id() == 0) && lpj_tsc) {
	} else if ((smp_processor_id() == 0) && lpj_fine) {
		loops_per_jiffy = lpj_tsc;
		loops_per_jiffy = lpj_fine;
		printk(KERN_INFO
		printk(KERN_INFO
			"Calibrating delay loop (skipped), "
			"Calibrating delay loop (skipped), "
			"using tsc calculated value.. ");
			"value calculated using timer frequency.. ");
	} else if ((loops_per_jiffy = calibrate_delay_direct()) != 0) {
	} else if ((loops_per_jiffy = calibrate_delay_direct()) != 0) {
		printk(KERN_INFO
		printk(KERN_INFO
			"Calibrating delay using timer specific routine.. ");
			"Calibrating delay using timer specific routine.. ");