x86, apic: Add apic timer calibration hook
Subsystems (2)
PATCH 2/2 x86, apic: Add apic timer calibration hook
Add apic timer calibration hook.
From: Alok N Kataria <[email protected]>
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 <[email protected]>
arch/x86/include/asm/apic.h +6 -0
@@ -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
arch/x86/include/asm/x86_init.h +3 -0
@@ -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 ); };/**
arch/x86/kernel/cpu/vmware.c +27 -3
@@ -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" ); }/*
arch/x86/kernel/x86_init.c +1 -0
@@ -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 = {
arch/x86/kernel/apic/apic.c +2 -11
@@ -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 ();