Merge branch 'linus' into x86/delay
authorIngo Molnar <mingo@elte.hu>
Wed, 25 Jun 2008 10:30:10 +0000 (12:30 +0200)
committerIngo Molnar <mingo@elte.hu>
Wed, 25 Jun 2008 10:30:10 +0000 (12:30 +0200)
Conflicts:

arch/x86/kernel/tsc_32.c

Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/x86/kernel/time_64.c
arch/x86/kernel/tsc_32.c
arch/x86/lib/delay_32.c
include/linux/delay.h
init/calibrate.c

index c737849..39ae851 100644 (file)
@@ -123,6 +123,8 @@ void __init time_init(void)
                (boot_cpu_data.x86_vendor == X86_VENDOR_AMD))
                cpu_khz = calculate_cpu_khz();
 
+       lpj_fine = ((unsigned long)tsc_khz * 1000)/HZ;
+
        if (unsynchronized_tsc())
                mark_tsc_unstable("TSCs unsynchronized");
 
index 65b7063..0065426 100644 (file)
@@ -1,6 +1,7 @@
 #include <linux/sched.h>
 #include <linux/clocksource.h>
 #include <linux/workqueue.h>
+#include <linux/delay.h>
 #include <linux/cpufreq.h>
 #include <linux/jiffies.h>
 #include <linux/init.h>
@@ -404,6 +405,7 @@ static inline void check_geode_tsc_reliable(void) { }
 void __init tsc_init(void)
 {
        int cpu;
+       u64 lpj;
 
        if (!cpu_has_tsc || tsc_disabled > 0)
                return;
@@ -416,6 +418,10 @@ void __init tsc_init(void)
                return;
        }
 
+       lpj = ((u64)tsc_khz * 1000);
+       do_div(lpj, HZ);
+       lpj_fine = lpj;
+
        /* now allow native_sched_clock() to use rdtsc */
        tsc_disabled = 0;
 
index d710f2d..ef69131 100644 (file)
@@ -3,6 +3,7 @@
  *
  *     Copyright (C) 1993 Linus Torvalds
  *     Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
+ *     Copyright (C) 2008 Jiri Hladky <hladky _dot_ jiri _at_ gmail _dot_ com>
  *
  *     The __delay function must _NOT_ be inlined as its execution time
  *     depends wildly on alignment on many x86 processors. The additional
 /* simple loop based delay: */
 static void delay_loop(unsigned long loops)
 {
-       int d0;
-
        __asm__ __volatile__(
-               "\tjmp 1f\n"
-               ".align 16\n"
-               "1:\tjmp 2f\n"
-               ".align 16\n"
-               "2:\tdecl %0\n\tjns 2b"
-               :"=&a" (d0)
-               :"0" (loops));
+               "       test %0,%0      \n"
+               "       jz 3f           \n"
+               "       jmp 1f          \n"
+
+               ".align 16              \n"
+               "1:     jmp 2f          \n"
+
+               ".align 16              \n"
+               "2:     decl %0         \n"
+               "       jnz 2b          \n"
+               "3:     decl %0         \n"
+
+               : /* we don't need output */
+               :"a" (loops)
+       );
 }
 
 /* TSC based delay: */
index 54552d2..fd832c6 100644 (file)
@@ -41,6 +41,7 @@ static inline void ndelay(unsigned long x)
 #define ndelay(x) ndelay(x)
 #endif
 
+extern unsigned long lpj_fine;
 void calibrate_delay(void);
 void msleep(unsigned int msecs);
 unsigned long msleep_interruptible(unsigned int msecs);
index ecb3822..7963e3f 100644 (file)
@@ -8,7 +8,9 @@
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/timex.h>
+#include <linux/smp.h>
 
+unsigned long lpj_fine;
 unsigned long preset_lpj;
 static int __init lpj_setup(char *str)
 {
@@ -33,9 +35,9 @@ static unsigned long __cpuinit calibrate_delay_direct(void)
        unsigned long pre_start, start, post_start;
        unsigned long pre_end, end, post_end;
        unsigned long start_jiffies;
-       unsigned long tsc_rate_min, tsc_rate_max;
-       unsigned long good_tsc_sum = 0;
-       unsigned long good_tsc_count = 0;
+       unsigned long timer_rate_min, timer_rate_max;
+       unsigned long good_timer_sum = 0;
+       unsigned long good_timer_count = 0;
        int i;
 
        if (read_current_timer(&pre_start) < 0 )
@@ -79,22 +81,24 @@ static unsigned long __cpuinit calibrate_delay_direct(void)
                }
                read_current_timer(&post_end);
 
-               tsc_rate_max = (post_end - pre_start) / DELAY_CALIBRATION_TICKS;
-               tsc_rate_min = (pre_end - post_start) / DELAY_CALIBRATION_TICKS;
+               timer_rate_max = (post_end - pre_start) /
+                                       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.
                 */
                if (pre_start != 0 && pre_end != 0 &&
-                   (tsc_rate_max - tsc_rate_min) < (tsc_rate_max >> 3)) {
-                       good_tsc_count++;
-                       good_tsc_sum += tsc_rate_max;
+                   (timer_rate_max - timer_rate_min) < (timer_rate_max >> 3)) {
+                       good_timer_count++;
+                       good_timer_sum += timer_rate_max;
                }
        }
 
-       if (good_tsc_count)
-               return (good_tsc_sum/good_tsc_count);
+       if (good_timer_count)
+               return (good_timer_sum/good_timer_count);
 
        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");
@@ -108,6 +112,10 @@ static unsigned long __cpuinit calibrate_delay_direct(void) {return 0;}
  * This is the number of bits of precision for the loops_per_jiffy.  Each
  * bit takes on average 1.5/HZ seconds.  This (like the original) is a little
  * better than 1%
+ * For the boot cpu we can skip the delay calibration and assign it a value
+ * calculated based on the timer frequency.
+ * 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.
  */
 #define LPS_PREC 8
 
@@ -118,20 +126,20 @@ void __cpuinit calibrate_delay(void)
 
        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(KERN_INFO
+                       "Calibrating delay loop (skipped) preset value.. ");
+       } else if ((smp_processor_id() == 0) && lpj_fine) {
+               loops_per_jiffy = lpj_fine;
+               printk(KERN_INFO
+                       "Calibrating delay loop (skipped), "
+                       "value calculated using timer frequency.. ");
        } 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);
+               printk(KERN_INFO
+                       "Calibrating delay using timer specific routine.. ");
        } else {
                loops_per_jiffy = (1<<12);
 
-               printk(KERN_DEBUG "Calibrating delay loop... ");
+               printk(KERN_INFO "Calibrating delay loop... ");
                while ((loops_per_jiffy <<= 1) != 0) {
                        /* wait for "start of" clock tick */
                        ticks = jiffies;
@@ -161,12 +169,8 @@ void __cpuinit calibrate_delay(void)
                        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(KERN_INFO "%lu.%02lu BogoMIPS (lpj=%lu)\n",
+                       loops_per_jiffy/(500000/HZ),
+                       (loops_per_jiffy/(5000/HZ)) % 100, loops_per_jiffy);
 }