Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 116518
b: refs/heads/master
c: b189892
h: refs/heads/master
v: v3
  • Loading branch information
Cyrill Gorcunov authored and Ingo Molnar committed Oct 16, 2008
1 parent a286dd2 commit a13454e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 35 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 08ad776e3c54e6fe8b50939f176538063b69f89e
refs/heads/master: b189892de4da4634560657aedd774752094dbfa0
81 changes: 47 additions & 34 deletions trunk/arch/x86/kernel/apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,51 @@ static void __init lapic_cal_handler(struct clock_event_device *dev)
}
}

static int __init calibrate_by_pmtimer(long deltapm, long *delta)
{
const long pm_100ms = PMTMR_TICKS_PER_SEC / 10;
const long pm_thresh = pm_100ms / 100;
unsigned long mult;
u64 res;

#ifndef CONFIG_X86_PM_TIMER
return -1;
#endif

apic_printk(APIC_VERBOSE, "... PM timer delta = %ld\n", deltapm);

/* Check, if the PM timer is available */
if (!deltapm)
return -1;

mult = clocksource_hz2mult(PMTMR_TICKS_PER_SEC, 22);

if (deltapm > (pm_100ms - pm_thresh) &&
deltapm < (pm_100ms + pm_thresh)) {
apic_printk(APIC_VERBOSE, "... PM timer result ok\n");
} else {
res = (((u64)deltapm) * mult) >> 22;
do_div(res, 1000000);
printk(KERN_WARNING "APIC calibration not consistent "
"with PM Timer: %ldms instead of 100ms\n",
(long)res);
/* Correct the lapic counter value */
res = (((u64)(*delta)) * pm_100ms);
do_div(res, deltapm);
printk(KERN_INFO "APIC delta adjusted to PM-Timer: "
"%lu (%ld)\n", (unsigned long)res, *delta);
*delta = (long)res;
}

return 0;
}

static int __init calibrate_APIC_clock(void)
{
struct clock_event_device *levt = &__get_cpu_var(lapic_events);
const long pm_100ms = PMTMR_TICKS_PER_SEC/10;
const long pm_thresh = pm_100ms/100;
void (*real_handler)(struct clock_event_device *dev);
unsigned long deltaj;
long delta, deltapm;
long delta;
int pm_referenced = 0;

local_irq_disable();
Expand Down Expand Up @@ -575,36 +612,9 @@ static int __init calibrate_APIC_clock(void)
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);

if (deltapm) {
unsigned long mult;
u64 res;

mult = clocksource_hz2mult(PMTMR_TICKS_PER_SEC, 22);

if (deltapm > (pm_100ms - pm_thresh) &&
deltapm < (pm_100ms + pm_thresh)) {
apic_printk(APIC_VERBOSE, "... PM timer result ok\n");
} else {
res = (((u64) deltapm) * mult) >> 22;
do_div(res, 1000000);
printk(KERN_WARNING "APIC calibration not consistent "
"with PM Timer: %ldms instead of 100ms\n",
(long)res);
/* Correct the lapic counter value */
res = (((u64) delta) * pm_100ms);
do_div(res, deltapm);
printk(KERN_INFO "APIC delta adjusted to PM-Timer: "
"%lu (%ld)\n", (unsigned long) res, delta);
delta = (long) res;
}
pm_referenced = 1;
}
#endif
/* we trust the PM based calibration if possible */
pm_referenced = !calibrate_by_pmtimer(lapic_cal_pm2 - lapic_cal_pm1,
&delta);

/* Calculate the scaled math multiplication factor */
lapic_clockevent.mult = div_sc(delta, TICK_NSEC * LAPIC_CAL_LOOPS,
Expand Down Expand Up @@ -646,7 +656,10 @@ static int __init calibrate_APIC_clock(void)

levt->features &= ~CLOCK_EVT_FEAT_DUMMY;

/* We trust the pm timer based calibration */
/*
* PM timer calibration failed or not turned on
* so lets try APIC timer based calibration
*/
if (!pm_referenced) {
apic_printk(APIC_VERBOSE, "... verify APIC timer\n");

Expand Down

0 comments on commit a13454e

Please sign in to comment.