public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] x86:Use cpu_khz for loops_per_jiffy calculation
@ 2008-06-04  0:41 Alok Kataria
  2008-06-04  1:20 ` Arjan van de Ven
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Alok Kataria @ 2008-06-04  0:41 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar
  Cc: LKML, Dan Hecht, Tim Mann, Zachary Amsden, Sahil Rihan

On X86 platform we can use the value of cpu_khz computed during tsc calibration
to calculate the loops_per_jiffy value. Its very important to keep the error in
lpj values to minimum as any error in that may result in kernel panic in
check_timer. 
In virtualization environment on a highly overloaded host, the guest delay
calibration may sometimes result in errors beyond the ~50% that timer_irq_works
can handle, resulting in the guest panicking.

This change could also help large MP systems in reducing their booting time.

Patch also does some formating changes to lpj_setup code to now have a single
printk to print the calculated bogomips value.

On top of current git.

Signed-off-by: Alok N Kataria <akataria@vmware.com>

Index: linux-2.6/arch/x86/kernel/time_64.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/time_64.c	2008-05-23 16:56:24.000000000 -0700
+++ linux-2.6/arch/x86/kernel/time_64.c	2008-06-03 17:28:46.000000000 -0700
@@ -123,6 +123,8 @@
 		(boot_cpu_data.x86_vendor == X86_VENDOR_AMD))
 		cpu_khz = calculate_cpu_khz();
 
+	lpj_tsc = ((unsigned long)cpu_khz * 1000)/HZ;
+
 	if (unsynchronized_tsc())
 		mark_tsc_unstable("TSCs unsynchronized");
 
Index: linux-2.6/include/linux/delay.h
===================================================================
--- linux-2.6.orig/include/linux/delay.h	2008-05-23 16:56:24.000000000 -0700
+++ linux-2.6/include/linux/delay.h	2008-06-03 17:28:46.000000000 -0700
@@ -41,6 +41,7 @@
 #define ndelay(x) ndelay(x)
 #endif
 
+extern unsigned long lpj_tsc;
 void calibrate_delay(void);
 void msleep(unsigned int msecs);
 unsigned long msleep_interruptible(unsigned int msecs);
Index: linux-2.6/init/calibrate.c
===================================================================
--- linux-2.6.orig/init/calibrate.c	2008-05-23 16:56:24.000000000 -0700
+++ linux-2.6/init/calibrate.c	2008-06-03 17:28:46.000000000 -0700
@@ -9,6 +9,7 @@
 #include <linux/init.h>
 #include <linux/timex.h>
 
+unsigned long lpj_tsc;
 unsigned long preset_lpj;
 static int __init lpj_setup(char *str)
 {
@@ -118,16 +119,14 @@
 
 	if (preset_lpj) {
 		loops_per_jiffy = preset_lpj;
-		printk("Calibrating delay loop (skipped)... "
-			"%lu.%02lu BogoMIPS preset\n",
-			loops_per_jiffy/(500000/HZ),
-			(loops_per_jiffy/(5000/HZ)) % 100);
+		printk("Calibrating delay loop skipped, "
+			"using preset value.. ");
+	} else if (lpj_tsc) {
+		loops_per_jiffy = lpj_tsc;
+		printk("Calibrating delay loop skipped, "
+			"using value calculated from tsc.. ");
 	} else if ((loops_per_jiffy = calibrate_delay_direct()) != 0) {
 		printk("Calibrating delay using timer specific routine.. ");
-		printk("%lu.%02lu BogoMIPS (lpj=%lu)\n",
-			loops_per_jiffy/(500000/HZ),
-			(loops_per_jiffy/(5000/HZ)) % 100,
-			loops_per_jiffy);
 	} else {
 		loops_per_jiffy = (1<<12);
 
@@ -161,12 +160,7 @@
 			if (jiffies != ticks)	/* longer than 1 tick */
 				loops_per_jiffy &= ~loopbit;
 		}
-
-		/* Round the value and print it */
-		printk("%lu.%02lu BogoMIPS (lpj=%lu)\n",
-			loops_per_jiffy/(500000/HZ),
-			(loops_per_jiffy/(5000/HZ)) % 100,
-			loops_per_jiffy);
 	}
-
+	printk("%lu.%02lu BogoMIPS (lpj=%lu)\n", loops_per_jiffy/(500000/HZ),
+		(loops_per_jiffy/(5000/HZ)) % 100, loops_per_jiffy);
 }
Index: linux-2.6/arch/x86/kernel/tsc_32.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/tsc_32.c	2008-05-27 12:28:16.000000000 -0700
+++ linux-2.6/arch/x86/kernel/tsc_32.c	2008-06-03 17:28:46.000000000 -0700
@@ -401,6 +401,7 @@
 void __init tsc_init(void)
 {
 	int cpu;
+	u64 lpj;
 
 	if (!cpu_has_tsc || tsc_disabled) {
 		/* Disable the TSC in case of !cpu_has_tsc */
@@ -421,6 +422,10 @@
 		return;
 	}
 
+	lpj = ((u64)cpu_khz * 1000);
+	do_div(lpj, HZ);
+	lpj_tsc = lpj;
+
 	printk("Detected %lu.%03lu MHz processor.\n",
 				(unsigned long)cpu_khz / 1000,
 				(unsigned long)cpu_khz % 1000);



^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2008-06-27  8:11 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-04  0:41 [RFC PATCH] x86:Use cpu_khz for loops_per_jiffy calculation Alok Kataria
2008-06-04  1:20 ` Arjan van de Ven
2008-06-04  4:01   ` Alok kataria
2008-06-04 13:16     ` Arjan van de Ven
2008-06-05 18:37       ` Alok Kataria
2008-06-20  1:22       ` Alok Kataria
2008-06-20 11:39         ` Ingo Molnar
2008-06-20 22:06           ` Alok Kataria
2008-06-23 20:54             ` Ingo Molnar
2008-06-23 23:21             ` Ingo Molnar
2008-06-23 23:34               ` Alok Kataria
2008-06-23 23:47                 ` Ingo Molnar
2008-06-24  1:21                   ` Alok Kataria
2008-06-24 11:54                     ` Ingo Molnar
2008-06-24 17:57             ` Pavel Machek
2008-06-26 17:20               ` Alok Kataria
2008-06-26 17:35                 ` Pavel Machek
2008-06-26 18:10                   ` Alok Kataria
2008-06-26 22:16                     ` Pavel Machek
2008-06-26 23:10                       ` Alok Kataria
2008-06-27  8:12                         ` Pavel Machek
2008-06-04 14:17 ` Pavel Machek
2008-06-09 13:11 ` Ingo Molnar
2008-06-09 17:55   ` Alok Kataria

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox