public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: let 64 bit to use 32 bit calibrate_apic_clock
@ 2008-08-25  5:41 Yinghai Lu
  2008-08-25  7:47 ` Ingo Molnar
  0 siblings, 1 reply; 5+ messages in thread
From: Yinghai Lu @ 2008-08-25  5:41 UTC (permalink / raw)
  To: Ingo Molnar, Thomas Gleixner, H. Peter Anvin, Andrew Morton
  Cc: linux-kernel, Yinghai Lu

Signed-of-by: Yinghai Lu <yhlu.kernel@gmail.com>

---
 arch/x86/kernel/apic.c |   92 ++-----------------------------------------------
 1 file changed, 5 insertions(+), 87 deletions(-)

Index: linux-2.6/arch/x86/kernel/apic.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/apic.c
+++ linux-2.6/arch/x86/kernel/apic.c
@@ -478,90 +478,6 @@ static void __cpuinit setup_APIC_timer(v
 	clockevents_register_device(levt);
 }
 
-#ifdef CONFIG_X86_64
-/*
- * In this function we calibrate APIC bus clocks to the external
- * timer. Unfortunately we cannot use jiffies and the timer irq
- * to calibrate, since some later bootup code depends on getting
- * the first irq? Ugh.
- *
- * We want to do the calibration only once since we
- * want to have local timer irqs syncron. CPUs connected
- * by the same APIC bus have the very same bus frequency.
- * And we want to have irqs off anyways, no accidental
- * APIC irq that way.
- */
-
-#define TICK_COUNT 100000000
-
-static int __init calibrate_APIC_clock(void)
-{
-	unsigned apic, apic_start;
-	unsigned long tsc, tsc_start;
-	int result;
-
-	local_irq_disable();
-
-	/*
-	 * Put whatever arbitrary (but long enough) timeout
-	 * value into the APIC clock, we just want to get the
-	 * counter running for calibration.
-	 *
-	 * No interrupt enable !
-	 */
-	__setup_APIC_LVTT(250000000, 0, 0);
-
-	apic_start = apic_read(APIC_TMCCT);
-#ifdef CONFIG_X86_PM_TIMER
-	if (apic_calibrate_pmtmr && pmtmr_ioport) {
-		pmtimer_wait(5000);  /* 5ms wait */
-		apic = apic_read(APIC_TMCCT);
-		result = (apic_start - apic) * 1000L / 5;
-	} else
-#endif
-	{
-		rdtscll(tsc_start);
-
-		do {
-			apic = apic_read(APIC_TMCCT);
-			rdtscll(tsc);
-		} while ((tsc - tsc_start) < TICK_COUNT &&
-				(apic_start - apic) < TICK_COUNT);
-
-		result = (apic_start - apic) * 1000L * tsc_khz /
-					(tsc - tsc_start);
-	}
-
-	local_irq_enable();
-
-	printk(KERN_DEBUG "APIC timer calibration result %d\n", result);
-
-	printk(KERN_INFO "Detected %d.%03d MHz APIC timer.\n",
-		result / 1000 / 1000, result / 1000 % 1000);
-
-	/* Calculate the scaled math multiplication factor */
-	lapic_clockevent.mult = div_sc(result, NSEC_PER_SEC,
-				       lapic_clockevent.shift);
-	lapic_clockevent.max_delta_ns =
-		clockevent_delta2ns(0x7FFFFF, &lapic_clockevent);
-	lapic_clockevent.min_delta_ns =
-		clockevent_delta2ns(0xF, &lapic_clockevent);
-
-	calibration_result = (result * APIC_DIVISOR) / HZ;
-
-	/*
-	 * Do a sanity check on the APIC calibration result
-	 */
-	if (calibration_result < (1000000 / HZ)) {
-		printk(KERN_WARNING
-			"APIC frequency too slow, disabling apic timer\n");
-		return -1;
-	}
-
-	return 0;
-}
-
-#else
 /*
  * In this functions we calibrate APIC bus clocks to the external timer.
  *
@@ -659,6 +575,7 @@ static int __init calibrate_APIC_clock(v
 	delta = lapic_cal_t1 - lapic_cal_t2;
 	apic_printk(APIC_VERBOSE, "... lapic delta = %ld\n", delta);
 
+#ifdef CONFIG_X86_PM_TIMER
 	/* Check, if the PM timer is available */
 	deltapm = lapic_cal_pm2 - lapic_cal_pm1;
 	apic_printk(APIC_VERBOSE, "... PM timer delta = %ld\n", deltapm);
@@ -687,6 +604,7 @@ static int __init calibrate_APIC_clock(v
 		}
 		pm_referenced = 1;
 	}
+#endif
 
 	/* Calculate the scaled math multiplication factor */
 	lapic_clockevent.mult = div_sc(delta, TICK_NSEC * LAPIC_CAL_LOOPS,
@@ -773,8 +691,6 @@ static int __init calibrate_APIC_clock(v
 	return 0;
 }
 
-#endif
-
 /*
  * Setup the boot APIC
  *

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

* Re: [PATCH] x86: let 64 bit to use 32 bit calibrate_apic_clock
  2008-08-25  5:41 [PATCH] x86: let 64 bit to use 32 bit calibrate_apic_clock Yinghai Lu
@ 2008-08-25  7:47 ` Ingo Molnar
  2008-08-25  8:04   ` Yinghai Lu
  0 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2008-08-25  7:47 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Thomas Gleixner, H. Peter Anvin, Andrew Morton, linux-kernel


* Yinghai Lu <yhlu.kernel@gmail.com> wrote:

> Signed-of-by: Yinghai Lu <yhlu.kernel@gmail.com>

applied to tip/irq/sparseirq - thanks Yinghai.

btw., why was this bit needed:

> @@ -659,6 +575,7 @@ static int __init calibrate_APIC_clock(v
>  	delta = lapic_cal_t1 - lapic_cal_t2;
>  	apic_printk(APIC_VERBOSE, "... lapic delta = %ld\n", delta);
>  
> +#ifdef CONFIG_X86_PM_TIMER
>  	/* Check, if the PM timer is available */
>  	deltapm = lapic_cal_pm2 - lapic_cal_pm1;
>  	apic_printk(APIC_VERBOSE, "... PM timer delta = %ld\n", deltapm);
> @@ -687,6 +604,7 @@ static int __init calibrate_APIC_clock(v
>  		}
>  		pm_referenced = 1;
>  	}
> +#endif

wouldnt this be a (small) fix for the pre-unification 32-bit side as 
well, which we should put into tip/x86/urgent as well?

	Ingo

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

* Re: [PATCH] x86: let 64 bit to use 32 bit calibrate_apic_clock
  2008-08-25  7:47 ` Ingo Molnar
@ 2008-08-25  8:04   ` Yinghai Lu
  2008-08-25 16:47     ` Cyrill Gorcunov
  0 siblings, 1 reply; 5+ messages in thread
From: Yinghai Lu @ 2008-08-25  8:04 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Thomas Gleixner, H. Peter Anvin, Andrew Morton, linux-kernel

On Mon, Aug 25, 2008 at 12:47 AM, Ingo Molnar <mingo@elte.hu> wrote:
>
> * Yinghai Lu <yhlu.kernel@gmail.com> wrote:
>
>> Signed-of-by: Yinghai Lu <yhlu.kernel@gmail.com>
>
> applied to tip/irq/sparseirq - thanks Yinghai.
>
> btw., why was this bit needed:
>
>> @@ -659,6 +575,7 @@ static int __init calibrate_APIC_clock(v
>>       delta = lapic_cal_t1 - lapic_cal_t2;
>>       apic_printk(APIC_VERBOSE, "... lapic delta = %ld\n", delta);
>>
>> +#ifdef CONFIG_X86_PM_TIMER
>>       /* Check, if the PM timer is available */
>>       deltapm = lapic_cal_pm2 - lapic_cal_pm1;
>>       apic_printk(APIC_VERBOSE, "... PM timer delta = %ld\n", deltapm);
>> @@ -687,6 +604,7 @@ static int __init calibrate_APIC_clock(v
>>               }
>>               pm_referenced = 1;
>>       }
>> +#endif
>
> wouldnt this be a (small) fix for the pre-unification 32-bit side as
> well, which we should put into tip/x86/urgent as well?

64bit have those MACRO, it seems when CONFIG_EMBEDDED is set, could
reduce some size if pm is not selected.

it seems not be urgent for 2.6.27.

YH

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

* Re: [PATCH] x86: let 64 bit to use 32 bit calibrate_apic_clock
  2008-08-25  8:04   ` Yinghai Lu
@ 2008-08-25 16:47     ` Cyrill Gorcunov
  2008-08-25 20:05       ` Yinghai Lu
  0 siblings, 1 reply; 5+ messages in thread
From: Cyrill Gorcunov @ 2008-08-25 16:47 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Ingo Molnar, Thomas Gleixner, H. Peter Anvin, Andrew Morton,
	linux-kernel

[Yinghai Lu - Mon, Aug 25, 2008 at 01:04:34AM -0700]
| On Mon, Aug 25, 2008 at 12:47 AM, Ingo Molnar <mingo@elte.hu> wrote:
| >
| > * Yinghai Lu <yhlu.kernel@gmail.com> wrote:
| >
| >> Signed-of-by: Yinghai Lu <yhlu.kernel@gmail.com>
| >
| > applied to tip/irq/sparseirq - thanks Yinghai.
| >
| > btw., why was this bit needed:
| >
| >> @@ -659,6 +575,7 @@ static int __init calibrate_APIC_clock(v
| >>       delta = lapic_cal_t1 - lapic_cal_t2;
| >>       apic_printk(APIC_VERBOSE, "... lapic delta = %ld\n", delta);
| >>
| >> +#ifdef CONFIG_X86_PM_TIMER
| >>       /* Check, if the PM timer is available */
| >>       deltapm = lapic_cal_pm2 - lapic_cal_pm1;
| >>       apic_printk(APIC_VERBOSE, "... PM timer delta = %ld\n", deltapm);
| >> @@ -687,6 +604,7 @@ static int __init calibrate_APIC_clock(v
| >>               }
| >>               pm_referenced = 1;
| >>       }
| >> +#endif
| >
| > wouldnt this be a (small) fix for the pre-unification 32-bit side as
| > well, which we should put into tip/x86/urgent as well?
| 
| 64bit have those MACRO, it seems when CONFIG_EMBEDDED is set, could
| reduce some size if pm is not selected.
| 
| it seems not be urgent for 2.6.27.
| 
| YH
| 

Hey, APIC_DIVISOR is now wrong - it should be 16 for both modes
then, shouldn't it? :)

		- Cyrill -

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

* Re: [PATCH] x86: let 64 bit to use 32 bit calibrate_apic_clock
  2008-08-25 16:47     ` Cyrill Gorcunov
@ 2008-08-25 20:05       ` Yinghai Lu
  0 siblings, 0 replies; 5+ messages in thread
From: Yinghai Lu @ 2008-08-25 20:05 UTC (permalink / raw)
  To: Cyrill Gorcunov
  Cc: Ingo Molnar, Thomas Gleixner, H. Peter Anvin, Andrew Morton,
	linux-kernel

On Mon, Aug 25, 2008 at 9:47 AM, Cyrill Gorcunov <gorcunov@gmail.com> wrote:
> [Yinghai Lu - Mon, Aug 25, 2008 at 01:04:34AM -0700]
> | On Mon, Aug 25, 2008 at 12:47 AM, Ingo Molnar <mingo@elte.hu> wrote:
> | >
> | > * Yinghai Lu <yhlu.kernel@gmail.com> wrote:
> | >
> | >> Signed-of-by: Yinghai Lu <yhlu.kernel@gmail.com>
> | >
> | > applied to tip/irq/sparseirq - thanks Yinghai.
> | >
> | > btw., why was this bit needed:
> | >
> | >> @@ -659,6 +575,7 @@ static int __init calibrate_APIC_clock(v
> | >>       delta = lapic_cal_t1 - lapic_cal_t2;
> | >>       apic_printk(APIC_VERBOSE, "... lapic delta = %ld\n", delta);
> | >>
> | >> +#ifdef CONFIG_X86_PM_TIMER
> | >>       /* Check, if the PM timer is available */
> | >>       deltapm = lapic_cal_pm2 - lapic_cal_pm1;
> | >>       apic_printk(APIC_VERBOSE, "... PM timer delta = %ld\n", deltapm);
> | >> @@ -687,6 +604,7 @@ static int __init calibrate_APIC_clock(v
> | >>               }
> | >>               pm_referenced = 1;
> | >>       }
> | >> +#endif
> | >
> | > wouldnt this be a (small) fix for the pre-unification 32-bit side as
> | > well, which we should put into tip/x86/urgent as well?
> |
> | 64bit have those MACRO, it seems when CONFIG_EMBEDDED is set, could
> | reduce some size if pm is not selected.
> |
> | it seems not be urgent for 2.6.27.
> |
> | YH
> |
>
> Hey, APIC_DIVISOR is now wrong - it should be 16 for both modes

why?

calibration_result = (delta * APIC_DIVISOR) / LAPIC_CAL_LOOPS;

> then, shouldn't it? :)

could make for 64 to use 16 too.

YH

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

end of thread, other threads:[~2008-08-25 20:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-25  5:41 [PATCH] x86: let 64 bit to use 32 bit calibrate_apic_clock Yinghai Lu
2008-08-25  7:47 ` Ingo Molnar
2008-08-25  8:04   ` Yinghai Lu
2008-08-25 16:47     ` Cyrill Gorcunov
2008-08-25 20:05       ` Yinghai Lu

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