x86/lapic: remove the PIT usage to calibrate the lapic timer
RFC PATCH 1/1 x86/lapic: remove the PIT usage to calibrate the lapic timer
And instead use NOW which is based on the TSC. This was already used when running in shim mode, since there's likely no PIT in that environment.
Remove printing the CPU frequency, since it's already printed earlier at boot, and getting the CPU frequency against the TSC without any external reference timer is pointless.
The motivation behind this change is to allow Xen to boot on HyperV gen2 instances, which lack a PIT.
---
I'm not sure about the reason behind the usage of the PIT instead of the TSC, maybe this was done because the TSC wasn't available until the Pentium? Xen certainly doesn't care about such hardware anymore, and the TSC is already used unconditionally in Xen.
Linux seems to prefer to calibrate the lapic timer against the PM timer and has already dropped PIT usage for that.
My early tests on a single box show no differences between the TSC or the PIT for lapic timer calibration, but that's a single box.
The RFC is because I'm not sure I understand the motivation for using the PIT in the first place, so I might be missing something relevant that could make this patch moot.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
--- xen/arch/x86/apic.c | 67 ++------------------------------------------- 1 file changed, 2 insertions(+), 65 deletions(-)
xen/arch/x86/apic.c +2 -65
@@ -1010,46 +1010,6 @@ __next:/* used for system time scaling */ static u32 __read_mostly bus_scale;/* scaling factor: ns -> bus cycles */ -/* -* The timer chip is already set up at HZ interrupts per second here, -* but we do not accept timer interrupts yet. We only allow the BP -* to calibrate. -*/ -static unsigned int __init get_8254_timer_count (void ) -{ -/*extern spinlock_t i8253_lock;*/ -/*unsigned long flags;*/ - -unsigned int count; - -/*spin_lock_irqsave(&i8253_lock, flags);*/ - -outb_p (0x00 ,PIT_MODE ); - count =inb_p (PIT_CH0 ); - count |=inb_p (PIT_CH0 ) <<8 ; - -/*spin_unlock_irqrestore(&i8253_lock, flags);*/ - -return count; -} - -/* next tick in 8254 can be caught by catching timer wraparound */ -static void __init wait_8254_wraparound (void ) -{ -unsigned int curr_count, prev_count; - - curr_count =get_8254_timer_count (); -do { - prev_count = curr_count; - curr_count =get_8254_timer_count (); - -/* workaround for broken Mercury/Neptune */ -if (prev_count >= curr_count +0x100 ) - curr_count =get_8254_timer_count (); - - }while (prev_count >= curr_count); -} -/* * This function sets up the local APIC timer, with a timeout of * 'clocks' APIC bus clock. During calibration we actually call
@@ -1092,7 +1052,7 @@ static void setup_APIC_timer(void)local_irq_restore (flags); } -static void wait_tick_pvh (void ) +static void wait_tick (void ) {u64 lapse_ns =1000000000ULL /HZ ;s_time_t start, curr_time;
@@ -1121,7 +1081,6 @@ static void wait_tick_pvh(void)static int __init calibrate_APIC_clock (void ) { -unsigned long long t1, t2;long tt1, tt2;long result;int i;
@@ -1138,33 +1097,15 @@ static int __init calibrate_APIC_clock(void)*/ __setup_APIC_LVTT (1000000000 ); -if ( !xen_guest ) -/* -* The timer chip counts down to zero. Let's wait -* for a wraparound to start exact measurement: -* (the current tick might have been already half done) -*/ -wait_8254_wraparound (); -else -wait_tick_pvh (); - -/* -* We wrapped around just now. Let's start: -*/ - t1 =rdtsc_ordered (); tt1 =apic_read (APIC_TMCCT );/* * Let's wait LOOPS ticks: */ for (i =0 ; i <LOOPS ; i++) -if ( !xen_guest ) -wait_8254_wraparound (); -else -wait_tick_pvh (); +wait_tick (); tt2 =apic_read (APIC_TMCCT ); - t2 =rdtsc_ordered ();/* * The APIC bus clock counter is 32 bits only, it
@@ -1176,10 +1117,6 @@ static int __init calibrate_APIC_clock(void) result = (tt1-tt2)*APIC_DIVISOR /LOOPS ; -apic_printk (APIC_VERBOSE ,"..... CPU clock speed is %ld.%04ld MHz.\n" , - ((long )(t2 - t1) /LOOPS ) / (1000000 /HZ ), - ((long )(t2 - t1) /LOOPS ) % (1000000 /HZ )); -apic_printk (APIC_VERBOSE ,"..... host bus clock speed is %ld.%04ld MHz.\n" , result / (1000000 /HZ ), result % (1000000 /HZ ));
Signature · 7 lines
2.19.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Roger Pau Monne
And instead use NOW which is based on the TSC. This was already used when running in shim mode, since there's likely no PIT in that environment.
Remove printing the CPU frequency, since it's already printed earlier at boot, and getting the CPU frequency against the TSC without any external reference timer is pointless.
The motivation behind this change is to allow Xen to boot on HyperV gen2 instances, which lack a PIT.
When on Hyper-V, LAPIC frequency can easily be queried from HV_X64_MSR_APIC_FREQUENCY (and that's what Linux does nowdays). This, of course, only if Hyper-V provides the interface but it always does.
Signature · 6 lines
Vitaly _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Roger Pau Monne
And instead use NOW which is based on the TSC. This was already used when running in shim mode, since there's likely no PIT in that environment.
Remove printing the CPU frequency, since it's already printed earlier at boot, and getting the CPU frequency against the TSC without any external reference timer is pointless.
The motivation behind this change is to allow Xen to boot on HyperV gen2 instances, which lack a PIT.
lacks
Quoted 11 lines
Signed-off-by Roger Pau Monné <[email protected]>---
I'm not sure about the reason behind the usage of the PIT instead of the TSC, maybe this was done because the TSC wasn't available until the Pentium? Xen certainly doesn't care about such hardware anymore, and the TSC is already used unconditionally in Xen.Linux seems to prefer to calibrate the lapic timer against the PM timer and has already dropped PIT usage for that.
Quoted 6 lines
My early tests on a single box show no differences between the TSC or the PIT for lapic timer calibration, but that's a single box.
The RFC is because I'm not sure I understand the motivation for using the PIT in the first place, so I might be missing something relevant that could make this patch moot.
I wondered the same.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 19.09.18 at 18:25, <[email protected]> wrote:
And instead use NOW which is based on the TSC. This was already used when running in shim mode, since there's likely no PIT in that environment.
Remove printing the CPU frequency, since it's already printed earlier at boot, and getting the CPU frequency against the TSC without any external reference timer is pointless.
The motivation behind this change is to allow Xen to boot on HyperV gen2 instances, which lack a PIT.
Quoted 6 lines
Signed-off-by Roger Pau Monné <[email protected]>---
I'm not sure about the reason behind the usage of the PIT instead of the TSC, maybe this was done because the TSC wasn't available until the Pentium? Xen certainly doesn't care about such hardware anymore, and the TSC is already used unconditionally in Xen.
How good are the chances that on at least some hardware LAPIC and TSC frequencies derive from the same oscillator? If they do, you'd now basically calibrate a clock against itself, ...
Quoted 2 lines
Linux seems to prefer to calibrate the lapic timer against the PM timer and has already dropped PIT usage for that.
... while this is almost certainly using a completely different timer, with the possible (hypothetical?) exception of SoC-s.
Also, if we were to change the default against which clock to calibrate, I think we'd at least want to have a command line option controllable fallback to the current mode, just in case of unforeseen problems. This could be dropped a couple of releases later, if we really want to get rid of that code.
xen/arch/x86/apic.c static int __init calibrate_APIC_clock(void) · line 1182
Quoted 8 lines
xen/arch/x86/apic.c +0
-4@@ -1176,10 +1117,6 @@ static int __init calibrate_APIC_clock(void) result = (tt1-tt2)*APIC_DIVISOR /LOOPS ; -apic_printk (APIC_VERBOSE ,"..... CPU clock speed is %ld.%04ld MHz.\n" , - ((long )(t2 - t1) /LOOPS ) / (1000000 /HZ ), - ((long )(t2 - t1) /LOOPS ) % (1000000 /HZ )); -
I think I dislike this removal, despite the apparent redundancy, and in particular as part of an unrelated patch. It sitting next to
xen/arch/x86/apic.c static int __init calibrate_APIC_clock(void) · line 1121
Quoted 2 lines
xen/arch/x86/apic.c +0
-0apic_printk (APIC_VERBOSE ,"..... host bus clock speed is %ld.%04ld MHz.\n" , result / (1000000 /HZ ), result % (1000000 /HZ ));
is quite helpful imo, and APIC_VERBOSE mode is off by default anyway.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel