[PATCH 2/2] x86, apic: Add apic timer calibration hook
From: Alok Kataria
Date: Fri Oct 22 2010 - 15:29:22 EST
Add apic timer calibration hook.
From: Alok N Kataria <akataria@xxxxxxxxxx>
Add a new function ptr calibrate_APIC_clock to x86_init_timers structure.
On native this does the usual apic calibration and local apic timer
initialization. On VMware's platform we override it with a routine which
gets that information from the hypervisor and initializes the local apic
timer accordingly.
Signed-off-by: Alok N Kataria <akataria@xxxxxxxxxx>
Index: linux-x86-tree.git/arch/x86/include/asm/apic.h
===================================================================
--- linux-x86-tree.git.orig/arch/x86/include/asm/apic.h 2010-10-22 11:37:47.000000000 -0700
+++ linux-x86-tree.git/arch/x86/include/asm/apic.h 2010-10-22 12:04:58.000000000 -0700
@@ -17,6 +17,10 @@
#define ARCH_APICTIMER_STOPS_ON_C3 1
+/* Clock divisor */
+#define APIC_DIVISOR 16
+#define LAPIC_CAL_LOOPS (HZ/10)
+
/*
* Debugging macros
*/
@@ -238,6 +242,8 @@ extern void setup_boot_APIC_clock(void);
extern void setup_secondary_APIC_clock(void);
extern int APIC_init_uniprocessor(void);
extern void enable_NMI_through_LVT0(void);
+extern int native_calibrate_APIC_clock(void);
+extern int initialize_lapic_timer(long delta, unsigned int calibration_result);
/*
* On 32bit this is mach-xxx local
Index: linux-x86-tree.git/arch/x86/include/asm/x86_init.h
===================================================================
--- linux-x86-tree.git.orig/arch/x86/include/asm/x86_init.h 2010-10-22 11:37:47.000000000 -0700
+++ linux-x86-tree.git/arch/x86/include/asm/x86_init.h 2010-10-22 11:54:45.000000000 -0700
@@ -83,11 +83,14 @@ struct x86_init_paging {
* boot cpu
* @tsc_pre_init: platform function called before TSC init
* @timer_init: initialize the platform timer (default PIT/HPET)
+ * @calibrate_APIC_clock: calibrate APIC clock freq (ticks per HZ) and
+ * initializes the local APIC timer.
*/
struct x86_init_timers {
void (*setup_percpu_clockev)(void);
void (*tsc_pre_init)(void);
void (*timer_init)(void);
+ int (*calibrate_APIC_clock)(void);
};
/**
Index: linux-x86-tree.git/arch/x86/kernel/cpu/vmware.c
===================================================================
--- linux-x86-tree.git.orig/arch/x86/kernel/cpu/vmware.c 2010-10-22 11:37:47.000000000 -0700
+++ linux-x86-tree.git/arch/x86/kernel/cpu/vmware.c 2010-10-22 11:55:27.000000000 -0700
@@ -26,6 +26,7 @@
#include <asm/div64.h>
#include <asm/x86_init.h>
#include <asm/hypervisor.h>
+#include <asm/apic.h>
#define CPUID_VMWARE_INFO_LEAF 0x40000000
#define VMWARE_HYPERVISOR_MAGIC 0x564D5868
@@ -72,17 +73,40 @@ static unsigned long vmware_get_tsc_khz(
return tsc_hz;
}
+static int __init vmware_calibrate_APIC_clock(void)
+{
+ unsigned int calibration_result;
+ uint32_t eax, ebx, ecx, edx;
+ int err;
+ long delta;
+ unsigned long flags;
+
+ VMWARE_PORT(GETHZ, eax, ebx, ecx, edx);
+ BUG_ON(!ecx);
+ calibration_result = ecx / HZ;
+
+ printk(KERN_INFO "APIC bus freq read from hypervisor\n");
+
+ delta = (calibration_result * LAPIC_CAL_LOOPS) / APIC_DIVISOR;
+ local_irq_save(flags);
+ err = initialize_lapic_timer(delta, calibration_result);
+ local_irq_restore(flags);
+
+ return err;
+}
+
static void __init vmware_platform_setup(void)
{
uint32_t eax, ebx, ecx, edx;
VMWARE_PORT(GETHZ, eax, ebx, ecx, edx);
- if (ebx != UINT_MAX)
+ if (ebx != UINT_MAX) {
x86_platform.calibrate_tsc = vmware_get_tsc_khz;
- else
+ x86_init.timers.calibrate_APIC_clock = vmware_calibrate_APIC_clock;
+ } else
printk(KERN_WARNING
- "Failed to get TSC freq from the hypervisor\n");
+ "Failed to setup VMware hypervisor platform\n");
}
/*
Index: linux-x86-tree.git/arch/x86/kernel/x86_init.c
===================================================================
--- linux-x86-tree.git.orig/arch/x86/kernel/x86_init.c 2010-10-22 11:37:47.000000000 -0700
+++ linux-x86-tree.git/arch/x86/kernel/x86_init.c 2010-10-22 11:53:27.000000000 -0700
@@ -68,6 +68,7 @@ struct x86_init_ops x86_init __initdata
.setup_percpu_clockev = setup_boot_APIC_clock,
.tsc_pre_init = x86_init_noop,
.timer_init = hpet_time_init,
+ .calibrate_APIC_clock = native_calibrate_APIC_clock
},
.iommu = {
Index: linux-x86-tree.git/arch/x86/kernel/apic/apic.c
===================================================================
--- linux-x86-tree.git.orig/arch/x86/kernel/apic/apic.c 2010-10-22 11:47:47.000000000 -0700
+++ linux-x86-tree.git/arch/x86/kernel/apic/apic.c 2010-10-22 11:58:30.000000000 -0700
@@ -327,13 +327,6 @@ int lapic_get_maxlvt(void)
}
/*
- * Local APIC timer
- */
-
-/* Clock divisor */
-#define APIC_DIVISOR 16
-
-/*
* This function sets up the local APIC timer, with a timeout of
* 'clocks' APIC bus clock. During calibration we actually call
* this function twice on the boot CPU, once with a bogus timeout
@@ -550,8 +543,6 @@ static void __cpuinit setup_APIC_timer(v
* back to normal later in the boot process).
*/
-#define LAPIC_CAL_LOOPS (HZ/10)
-
static __initdata int lapic_cal_loops = -1;
static __initdata long lapic_cal_t1, lapic_cal_t2;
static __initdata unsigned long long lapic_cal_tsc1, lapic_cal_tsc2;
@@ -677,7 +668,7 @@ int __init initialize_lapic_timer(long d
}
/* Calibrates the APIC clock and initializes the local APIC timer */
-static int __init calibrate_APIC_clock(void)
+int __init native_calibrate_APIC_clock(void)
{
struct clock_event_device *levt = &__get_cpu_var(lapic_events);
void (*real_handler)(struct clock_event_device *dev);
@@ -802,7 +793,7 @@ void __init setup_boot_APIC_clock(void)
apic_printk(APIC_VERBOSE, "Using local APIC timer interrupts.\n"
"calibrating APIC timer ...\n");
- if (calibrate_APIC_clock()) {
+ if (x86_init.timers.calibrate_APIC_clock()) {
/* No broadcast on UP ! */
if (num_possible_cpus() > 1)
setup_APIC_timer();
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/