Skip to contentSkip to conversation

kvm guest loops_per_jiffy miscalibration under host load

DISCUSSION Marcelo Tosatti 6 participants 13 messages Jul 2, 2008 – Jul 12, 2008

Subsystems (5)
x86 KVM KVM x86 Xen hypervisor x86 +1 more subsystems
lore
Share & tools
lore
#0 lore raw

Hello,

I have been discussing with Glauber and Gerd the problem where KVM guests miscalibrate loops_per_jiffy if there's sufficient load on the host.

calibrate_delay_direct() failed to get a good estimate for loops_per_jiffy.
Probably due to long platform interrupts. Consider using "lpj=" boot option.
Calibrating delay loop... <3>107.00 BogoMIPS (lpj=214016)

While this particular host calculates lpj=1597041.

This means that udelay() can delay for less than what asked for, with fatal results such as:

..MP-BIOS bug: 8254 timer not connected to IO-APIC

Kernel panic - not syncing: IO-APIC + timer doesn't work! Try using the

'noapic' kernel parameter

This bug is easily triggered with a CPU hungry task on nice -20 running only during guest calibration (so that the timer check code on io_apic_{32,64}.c fails to wait long enough for PIT interrupts to fire).

The problem is that the calibration routines assume a stable relation between timer interrupt frequency (PIT at this boot stage) and TSC/execution frequency.

The emulated timer frequency is based on the host system time and therefore virtually resistant against heavy load, while the execution of these routines on the guest is suspectible to scheduling of the QEMU process.

To fix this in a transparent way (without direct "lpj=" boot parameter assignment or a paravirt equivalent), it would be necessary to base the emulated timer frequency on guest execution time instead of host system time. But this can introduce timekeeping issues (recent Linux guests seem to handle lost/late interrupts fine as long as the clocksource is reliable) and just sounds scary.

Possible solutions:

- Require the admin to preset "lpj=". Nasty, not user friendly.
- Pass the proper lpj value via a paravirt interface. Won't cover fullvirt guests.
- Have the management app guarantee a minimum amount of CPU required for proper calibration during guest initialization.

Comments, ideas?

#1 lore raw
Quoted 41 lines · Marcelo Tosatti

Hello,

I have been discussing with Glauber and Gerd the problem where KVM guests miscalibrate loops_per_jiffy if there's sufficient load on the host.

calibrate_delay_direct() failed to get a good estimate for loops_per_jiffy.
Probably due to long platform interrupts. Consider using "lpj=" boot option.
Calibrating delay loop... <3>107.00 BogoMIPS (lpj=214016)

While this particular host calculates lpj=1597041.

This means that udelay() can delay for less than what asked for, with fatal results such as:

..MP-BIOS bug: 8254 timer not connected to IO-APIC

Kernel panic - not syncing: IO-APIC + timer doesn't work! Try using the

'noapic' kernel parameter

This bug is easily triggered with a CPU hungry task on nice -20 running only during guest calibration (so that the timer check code on io_apic_{32,64}.c fails to wait long enough for PIT interrupts to fire).

The problem is that the calibration routines assume a stable relation between timer interrupt frequency (PIT at this boot stage) and TSC/execution frequency.

The emulated timer frequency is based on the host system time and therefore virtually resistant against heavy load, while the execution of these routines on the guest is suspectible to scheduling of the QEMU process.

To fix this in a transparent way (without direct "lpj=" boot parameter assignment or a paravirt equivalent), it would be necessary to base the emulated timer frequency on guest execution time instead of host system time. But this can introduce timekeeping issues (recent Linux guests seem to handle lost/late interrupts fine as long as the clocksource is reliable) and just sounds scary.

Quoted 7 lines

Possible solutions:

- Require the admin to preset "lpj=". Nasty, not user friendly.
- Pass the proper lpj value via a paravirt interface. Won't cover fullvirt guests.
- Have the management app guarantee a minimum amount of CPU required for proper calibration during guest initialization.

I don't like any of these solutions, and won't defend any of "the one". So no hard feelings. But I think the "less worse" among them IMHO is the paravirt one. At least it goes in the general direction of "paravirt if you need to scale over xyz".

I think passing lpj is out of question, and giving the cpu resources for that time is kind of a kludge.

Or maybe we could put the timer expiration alone in a separate thread, with maximum priority (maybe rt priority)? dunno...

#2 lore raw

Hi Glauber,

Quoted 9 lines · Glauber Costa
Quoted 5 lines

- Require the admin to preset "lpj=". Nasty, not user friendly.
- Pass the proper lpj value via a paravirt interface. Won't cover fullvirt guests.
- Have the management app guarantee a minimum amount of CPU required for proper calibration during guest initialization.

I don't like any of these solutions, and won't defend any of "the one". So no hard feelings. But I think the "less worse" among them IMHO is the paravirt one. At least it goes in the general direction of "paravirt if you need to scale over xyz".

What is worse is that this problem can happen with a single guest, given enough lack of CPU power to the qemu process.

Quoted 2 lines

I think passing lpj is out of question, and giving the cpu resources for that time is kind of a kludge.

Yeah, but reserving cpu resources is the only automatic solution I can think of for fullvirt guests.

Quoted 2 lines

Or maybe we could put the timer expiration alone in a separate thread, with maximum priority (maybe rt priority)? dunno...

The timer expiration already has high priority, since its emulated with host kernel timers, so they're pretty close to the real hardware timing.

Problem is if the guest is not given enough CPU power to run the calibration routines.

#3 lore raw
In reply to Glauber Costa
Quoted 44 lines · Glauber Costa
Quoted 43 lines · Marcelo Tosatti

Hello,

I have been discussing with Glauber and Gerd the problem where KVM guests miscalibrate loops_per_jiffy if there's sufficient load on the host.

calibrate_delay_direct() failed to get a good estimate for loops_per_jiffy.
Probably due to long platform interrupts. Consider using "lpj=" boot option.
Calibrating delay loop... <3>107.00 BogoMIPS (lpj=214016)

While this particular host calculates lpj=1597041.

This means that udelay() can delay for less than what asked for, with fatal results such as:

..MP-BIOS bug: 8254 timer not connected to IO-APIC

Kernel panic - not syncing: IO-APIC + timer doesn't work! Try using the

'noapic' kernel parameter

This bug is easily triggered with a CPU hungry task on nice -20 running only during guest calibration (so that the timer check code on io_apic_{32,64}.c fails to wait long enough for PIT interrupts to fire).

The problem is that the calibration routines assume a stable relation between timer interrupt frequency (PIT at this boot stage) and TSC/execution frequency.

The emulated timer frequency is based on the host system time and therefore virtually resistant against heavy load, while the execution of these routines on the guest is suspectible to scheduling of the QEMU process.

To fix this in a transparent way (without direct "lpj=" boot parameter assignment or a paravirt equivalent), it would be necessary to base the emulated timer frequency on guest execution time instead of host system time. But this can introduce timekeeping issues (recent Linux guests seem to handle lost/late interrupts fine as long as the clocksource is reliable) and just sounds scary.

Possible solutions:

Quoted 7 lines
Quoted 5 lines

- Require the admin to preset "lpj=". Nasty, not user friendly.
- Pass the proper lpj value via a paravirt interface. Won't cover fullvirt guests.
- Have the management app guarantee a minimum amount of CPU required for proper calibration during guest initialization.

I don't like any of these solutions, and won't defend any of "the one". So no hard feelings. But I think the "less worse" among them IMHO is the paravirt one. At least it goes in the general direction of "paravirt if you need to scale over xyz".

I agree. A paravirt solution solves the problem.

Quoted 1 line

I think passing lpj is out of question, and giving the cpu resources for that time is kind of a kludge.

It's all heuristics unfortunately.

Quoted 1 line

Or maybe we could put the timer expiration alone in a separate thread, with maximum priority (maybe rt priority)? dunno...

But then if you have high-load because of a lot of guests running, you defeat yourself. Any attempt to guarantee time to a guest will be defeated by lots of guests all attempting calibration at the same time.

Regards,

Anthony Liguori

#12 lore raw
In reply to Marcelo Tosatti
Quoted 11 lines · Marcelo Tosatti

I have been discussing with Glauber and Gerd the problem where KVM guests miscalibrate loops_per_jiffy if there's sufficient load on the host.

calibrate_delay_direct() failed to get a good estimate for loops_per_jiffy.
Probably due to long platform interrupts. Consider using "lpj=" boot option.
Calibrating delay loop... <3>107.00 BogoMIPS (lpj=214016)

While this particular host calculates lpj=1597041.

[snip]

Quoted 7 lines

Possible solutions:

- Require the admin to preset "lpj=". Nasty, not user friendly.
- Pass the proper lpj value via a paravirt interface. Won't cover fullvirt guests.
- Have the management app guarantee a minimum amount of CPU required for proper calibration during guest initialization.

I talked with Marcelo about this latter option - the idea being to have libvirt do set_priority(PRIO_PROC, $pid, -20) on the KVM binary for a short time at startup. The problem with this is that there's no easy way to determine when, or for how long, to provide this priority
boost. During initial startup there is an arbitrary unknown delay
from the BIOS - 3 seconds to choose the boot device, a further 20-60 seconds if you choose PXE before the guest kernel is actually booted, arbitrary delay if booting from CDROM and it has not auto boot timeout, arbitrary user configurable delay in GRUB to choose kernel if booting from harddisk.

So to stand any reasonable chance of working libvirt would have to give the -20 priority boost for a good 60 seconds. If we want to start 2 or more guests at once this soon stops being a viable workaround. And we can't detect reboots triggered by the admin inside the guest. So I don't see how we can reliably solve this from userspace management tools, unless someone has better ideas than a priority boost for a short while.

Daniel

Signature · 4 lines
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#4 lore raw
In reply to Anthony Liguori
Quoted 53 lines · Anthony Liguori
Quoted 52 lines · Glauber Costa
Quoted 49 lines · Marcelo Tosatti

Hello,

I have been discussing with Glauber and Gerd the problem where KVM guests miscalibrate loops_per_jiffy if there's sufficient load on the host.

calibrate_delay_direct() failed to get a good estimate for loops_per_jiffy.
Probably due to long platform interrupts. Consider using "lpj=" boot option.
Calibrating delay loop... <3>107.00 BogoMIPS (lpj=214016)

While this particular host calculates lpj=1597041.

This means that udelay() can delay for less than what asked for, with fatal results such as:

..MP-BIOS bug: 8254 timer not connected to IO-APIC

Kernel panic - not syncing: IO-APIC + timer doesn't work! Try using the

'noapic' kernel parameter

This bug is easily triggered with a CPU hungry task on nice -20 running only during guest calibration (so that the timer check code on io_apic_{32,64}.c fails to wait long enough for PIT interrupts to fire).

The problem is that the calibration routines assume a stable relation between timer interrupt frequency (PIT at this boot stage) and TSC/execution frequency.

The emulated timer frequency is based on the host system time and therefore virtually resistant against heavy load, while the execution of these routines on the guest is suspectible to scheduling of the QEMU process.

To fix this in a transparent way (without direct "lpj=" boot parameter assignment or a paravirt equivalent), it would be necessary to base the emulated timer frequency on guest execution time instead of host system time. But this can introduce timekeeping issues (recent Linux guests seem to handle lost/late interrupts fine as long as the clocksource is reliable) and just sounds scary.

Possible solutions:

- Require the admin to preset "lpj=". Nasty, not user friendly.
- Pass the proper lpj value via a paravirt interface. Won't cover fullvirt guests.
- Have the management app guarantee a minimum amount of CPU required for proper calibration during guest initialization.

Quoted 6 lines
Quoted 4 lines

I don't like any of these solutions, and won't defend any of "the one". So no hard feelings. But I think the "less worse" among them IMHO is the paravirt one. At least it goes in the general direction of "paravirt if you need to scale over xyz".

I agree. A paravirt solution solves the problem.

Please, look at the patch I've attached.

It does __delay with host help. This may have the nice effect of not busy waiting for long-enough delays, and may well.

It is _completely_ PoC, just to show the idea. It's ugly, broken, obviously have to go through pv-ops, etc.

Also, I intend to add a lpj field in the kvm clock memory area. We could do just this later, do both, etc.

If we agree this is a viable solution, I'll start working on a patch

Quoted 21 lines
Quoted 2 lines

I think passing lpj is out of question, and giving the cpu resources for that time is kind of a kludge.

It's all heuristics unfortunately.

Quoted 2 lines

Or maybe we could put the timer expiration alone in a separate thread, with maximum priority (maybe rt priority)? dunno...

But then if you have high-load because of a lot of guests running, you defeat yourself. Any attempt to guarantee time to a guest will be defeated by lots of guests all attempting calibration at the same time.

Regards,

Anthony Liguori

--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 5 lines
Glauber Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."
arch/x86/kvm/x86.c +6 -0
index 63a77ca..4a137d9 100644
@@ -2539,6 +2539,12 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
 	case KVM_HC_MMU_OP:
 		r = kvm_pv_mmu_op(vcpu, a0, hc_gpa(vcpu, a1, a2), &ret);
 		break;
+	case KVM_DELAY: {
+		u32 wait; /* make it 64 */
+		wait = a0 / cpu_data(raw_smp_processor_id()).loops_per_jiffy;
+		ret = schedule_timeout_uninterruptible(wait);
+		break;
+	}
 	default:
 		ret = -KVM_ENOSYS;
 		break;
arch/x86/lib/delay.c +9 -1
index f456860..28fd9a0 100644
@@ -17,6 +17,7 @@
 #include <linux/preempt.h>
 #include <linux/delay.h>
 #include <linux/init.h>
+#include <linux/kvm_para.h>
 
 #include <asm/processor.h>
 #include <asm/delay.h>
@@ -84,6 +85,10 @@ static void delay_tsc(unsigned long loops)
 	preempt_enable();
 }
 
+static void delay_pv(unsigned long loops)
+{
+	kvm_hypercall1(KVM_DELAY, loops);
+}
 /*
  * Since we calibrate only once at boot, this
  * function should be set once at boot and not changed
@@ -106,7 +111,10 @@ int __devinit read_current_timer(unsigned long *timer_val)
 
 void __delay(unsigned long loops)
 {
-	delay_fn(loops);
+	if (paravirt_enabled())
+		delay_pv(loops);
+	else
+		delay_fn(loops);
 }
 EXPORT_SYMBOL(__delay);
 
include/asm-x86/kvm_para.h +1 -0
index bfd9900..00fc997 100644
@@ -23,6 +23,7 @@
 #define KVM_MMU_OP_WRITE_PTE            1
 #define KVM_MMU_OP_FLUSH_TLB	        2
 #define KVM_MMU_OP_RELEASE_PT	        3
+#define KVM_DELAY			4
 
 /* Payload for KVM_HC_MMU_OP */
 struct kvm_mmu_op_header {
#5 lore raw
Quoted 7 lines · Glauber Costa
Quoted 1 line

I agree. A paravirt solution solves the problem.

Please, look at the patch I've attached.

It does __delay with host help. This may have the nice effect of not busy waiting for long-enough delays, and may well.

Quoted 7 lines

It is _completely_ PoC, just to show the idea. It's ugly, broken, obviously have to go through pv-ops, etc.

Also, I intend to add a lpj field in the kvm clock memory area. We could do just this later, do both, etc.

If we agree this is a viable solution, I'll start working on a patch

This stops interrupts from being processed during the delay. And also there are cases like this recently introduced break:

                /* Allow RT tasks to run */
                preempt_enable();
                rep_nop();
                preempt_disable();

I think it would be better to just pass the lpj value via paravirt and let the guest busy-loop as usual.

#6 lore raw
Quoted 20 lines · Marcelo Tosatti
Quoted 7 lines · Glauber Costa
Quoted 2 lines

I agree. A paravirt solution solves the problem.

Please, look at the patch I've attached.

It does __delay with host help. This may have the nice effect of not busy waiting for long-enough delays, and may well.

Quoted 8 lines

It is _completely_ PoC, just to show the idea. It's ugly, broken, obviously have to go through pv-ops, etc.

Also, I intend to add a lpj field in the kvm clock memory area. We could do just this later, do both, etc.

If we agree this is a viable solution, I'll start working on a patch

This stops interrupts from being processed during the delay. And also there are cases like this recently introduced break:

Quoted 8 lines
                /* Allow RT tasks to run */
                preempt_enable();
                rep_nop();
                preempt_disable();

I think it would be better to just pass the lpj value via paravirt and let the guest busy-loop as usual.

I agree. VMI and Xen already pass a cpu_khz paravirt value. Something similar would probably do the trick.

It may be worthwhile having udelay() or spinlocks call into KVM if they've been spinning long enough but I think that's a separate discussion.

Regards,

Anthony Liguori

#7 lore raw
Quoted 30 lines · Anthony Liguori
Quoted 29 lines · Marcelo Tosatti
Quoted 9 lines · Glauber Costa
Quoted 3 lines

I agree. A paravirt solution solves the problem.

Please, look at the patch I've attached.

It does __delay with host help. This may have the nice effect of not busy waiting for long-enough delays, and may well.

Quoted 8 lines

It is _completely_ PoC, just to show the idea. It's ugly, broken, obviously have to go through pv-ops, etc.

Also, I intend to add a lpj field in the kvm clock memory area. We could do just this later, do both, etc.

If we agree this is a viable solution, I'll start working on a patch

This stops interrupts from being processed during the delay. And also there are cases like this recently introduced break:

               /* Allow RT tasks to run */
               preempt_enable();
               rep_nop();
               preempt_disable();
Quoted 6 lines
Quoted 3 lines

I think it would be better to just pass the lpj value via paravirt and let the guest busy-loop as usual.

I agree. VMI and Xen already pass a cpu_khz paravirt value. Something similar would probably do the trick.

yeah, there is a pv-op for this, so I won't have to mess with the clock interface. I'll draft a patch for it, and sent it.

Quoted 2 lines

It may be worthwhile having udelay() or spinlocks call into KVM if they've been spinning long enough but I think that's a separate discussion.

I think it is, but I'd have to back it up with numbers. measurements are on the way.

Quoted 5 lines

Regards,

Anthony Liguori

Signature · 5 lines
Glauber Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."
#8 lore raw
Quoted 33 lines · Glauber Costa
Quoted 26 lines · Anthony Liguori
Quoted 25 lines · Marcelo Tosatti
Quoted 7 lines · Glauber Costa
Quoted 2 lines

I agree. A paravirt solution solves the problem.

Please, look at the patch I've attached.

It does __delay with host help. This may have the nice effect of not busy waiting for long-enough delays, and may well.

Quoted 8 lines

It is _completely_ PoC, just to show the idea. It's ugly, broken, obviously have to go through pv-ops, etc.

Also, I intend to add a lpj field in the kvm clock memory area. We could do just this later, do both, etc.

If we agree this is a viable solution, I'll start working on a patch

This stops interrupts from being processed during the delay. And also there are cases like this recently introduced break:

               /* Allow RT tasks to run */
               preempt_enable();
               rep_nop();
               preempt_disable();
Quoted 5 lines
Quoted 3 lines

I think it would be better to just pass the lpj value via paravirt and let the guest busy-loop as usual.

I agree. VMI and Xen already pass a cpu_khz paravirt value. Something similar would probably do the trick.

Quoted 16 lines

yeah, there is a pv-op for this, so I won't have to mess with the clock interface. I'll draft a patch for it, and sent it.

Quoted 2 lines

It may be worthwhile having udelay() or spinlocks call into KVM if they've been spinning long enough but I think that's a separate discussion.

I think it is, but I'd have to back it up with numbers. measurements are on the way.

Quoted 5 lines

Regards,

Anthony Liguori

How about this? RFC only for now

arch/x86/kernel/kvmclock.c +9 -0
index 87edf1c..8514b04 100644
@@ -78,6 +78,14 @@ static cycle_t kvm_clock_read(void)
 	return ret;
 }
 
+static unsigned long kvm_get_cpu_khz(void)
+{
+	struct pvclock_vcpu_time_info *info;
+
+	info = &per_cpu(hv_clock, 0);
+	return pv_cpu_khz(info);
+}
+
 static struct clocksource kvm_clock = {
 	.name = "kvm-clock",
 	.read = kvm_clock_read,
@@ -153,6 +161,7 @@ void __init kvmclock_init(void)
 		pv_time_ops.get_wallclock = kvm_get_wallclock;
 		pv_time_ops.set_wallclock = kvm_set_wallclock;
 		pv_time_ops.sched_clock = kvm_clock_read;
+		pv_time_ops.get_cpu_khz = kvm_get_cpu_khz;
 #ifdef CONFIG_X86_LOCAL_APIC
 		pv_apic_ops.setup_secondary_clock = kvm_setup_secondary_clock;
 #endif
arch/x86/kernel/pvclock.c +12 -0
index 05fbe9a..2d325ae 100644
@@ -97,6 +97,18 @@ static unsigned pvclock_get_time_values(struct pvclock_shadow_time *dst,
 	return dst->version;
 }
 
+unsigned long pv_cpu_khz(struct pvclock_vcpu_time_info *info)
+{
+	u64 cpu_khz = 1000000ULL << 32;
+
+	do_div(cpu_khz, info->tsc_to_system_mul);
+	if (info->tsc_shift < 0)
+		cpu_khz <<= -info->tsc_shift;
+	else
+		cpu_khz >>= info->tsc_shift;
+	return cpu_khz;
+}
+
 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
 {
 	struct pvclock_shadow_time shadow;
arch/x86/xen/time.c +2 -9
index 64f0038..074cabb 100644
@@ -200,17 +200,10 @@ unsigned long long xen_sched_clock(void)
 /* Get the CPU speed from Xen */
 unsigned long xen_cpu_khz(void)
 {
-	u64 xen_khz = 1000000ULL << 32;
-	const struct pvclock_vcpu_time_info *info =
+	struct pvclock_vcpu_time_info *info =
 		&HYPERVISOR_shared_info->vcpu_info[0].time;
 
-	do_div(xen_khz, info->tsc_to_system_mul);
-	if (info->tsc_shift < 0)
-		xen_khz <<= -info->tsc_shift;
-	else
-		xen_khz >>= info->tsc_shift;
-
-	return xen_khz;
+	return pv_cpu_khz(info);
 }
 
 static cycle_t xen_clocksource_read(void)
include/asm-x86/pvclock.h +1 -0
index 85b1bba..41d816f 100644
@@ -6,6 +6,7 @@
 
 /* some helper functions for xen and kvm pv clock sources */
 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src);
+unsigned long pv_cpu_khz(struct pvclock_vcpu_time_info *info);
 void pvclock_read_wallclock(struct pvclock_wall_clock *wall,
 			    struct pvclock_vcpu_time_info *vcpu,
 			    struct timespec *ts);
#9 lore raw

What's the status with this for full virt guests?

I am still seeing systematic time drifts in RHEL 3 and RHEL4 guests which I've been digging into it the past few days. In the course of it I have been launching guests with boosted priority (both nice -20 and realtime priority (RR 1)) on a nearly 100% idle host.

One host is a PowerEdge 2950 running RHEL5.2 with kvm-70. With the realtime priority boot I have routinely seen bogomips in the guest which do not make sense. e.g.,

ksyms.2:bogomips        : 4639.94
ksyms.2:bogomips        : 4653.05
ksyms.2:bogomips        : 4653.05
ksyms.2:bogomips        : 24.52

and

ksyms.3:bogomips        : 4639.94
ksyms.3:bogomips        : 4653.05
ksyms.3:bogomips        : 16.33
ksyms.3:bogomips        : 12.87

Also, if I launch qemu with the "-no-kvm-pit -tdf" option the panic guests panics with the message Marcelo posted at the start of the thread:

----

Calibrating delay loop... 4653.05 BogoMIPS

CPU: L2 cache: 2048K

Intel machine check reporting enabled on CPU#2.

CPU2: Intel QEMU Virtual CPU version 0.9.1 stepping 03

Booting processor 3/3 eip 2000

Initializing CPU#3

masked ExtINT on CPU#3

ESR value before enabling vector: 00000000

ESR value after enabling vector: 00000000

Calibrating delay loop... 19.60 BogoMIPS

CPU: L2 cache: 2048K

Intel machine check reporting enabled on CPU#3.

CPU3: Intel QEMU Virtual CPU version 0.9.1 stepping 03

Total of 4 processors activated (14031.20 BogoMIPS).

ENABLING IO-APIC IRQs

Setting 4 in the phys_id_present_map
...changing IO-APIC physical APIC ID to 4 ... ok. ..TIMER: vector=0x31 pin1=0 pin2=-1
..MP-BIOS bug: 8254 timer not connected to IO-APIC ...trying to set up timer (IRQ0) through the 8259A ... failed. ...trying to set up timer as Virtual Wire IRQ... failed. ...trying to set up timer as ExtINT IRQ... failed :(.

Kernel panic: IO-APIC + timer doesn't work! pester [email protected]

----

I'm just looking for stable guest times. I'm not planning to keep the boosted guest priority, just using it to ensure the guest is not interrupted as I try to understand why the guest systematically drifts.

david

Quoted 54 lines · Glauber Costa
Quoted 37 lines · Glauber Costa
Quoted 26 lines · Anthony Liguori
Quoted 25 lines · Marcelo Tosatti
Quoted 7 lines · Glauber Costa
Quoted 2 lines

I agree. A paravirt solution solves the problem.

Please, look at the patch I've attached.

It does __delay with host help. This may have the nice effect of not busy waiting for long-enough delays, and may well.

Quoted 8 lines

It is _completely_ PoC, just to show the idea. It's ugly, broken, obviously have to go through pv-ops, etc.

Also, I intend to add a lpj field in the kvm clock memory area. We could do just this later, do both, etc.

If we agree this is a viable solution, I'll start working on a patch

This stops interrupts from being processed during the delay. And also there are cases like this recently introduced break:

               /* Allow RT tasks to run */
               preempt_enable();
               rep_nop();
               preempt_disable();
Quoted 5 lines
Quoted 3 lines

I think it would be better to just pass the lpj value via paravirt and let the guest busy-loop as usual.

I agree. VMI and Xen already pass a cpu_khz paravirt value. Something similar would probably do the trick.

yeah, there is a pv-op for this, so I won't have to mess with the clock interface. I'll draft a patch for it, and sent it.

Quoted 14 lines
Quoted 3 lines

It may be worthwhile having udelay() or spinlocks call into KVM if they've
been spinning long enough but I think that's a separate discussion.

I think it is, but I'd have to back it up with numbers. measurements are on the way.

Quoted 5 lines

Regards,

Anthony Liguori

How about this? RFC only for now

#10 lore raw

Hi David,

Quoted 1 line · David S. Ahern

What's the status with this for full virt guests?

The consensus seems to be that fullvirt guests need assistance from the management app (libvirt) to have boosted priority during their boot stage, so loops_per_jiffy calibration can be performed safely. As Daniel pointed out this is tricky because you can't know for sure how long the boot up will take, if for example PXE is used.

Glauber is working on some paravirt patches to remedy the situation.

But loops_per_jiffy is not directly related to clock drifts, so this is a separate problem.

Quoted 2 lines

I am still seeing systematic time drifts in RHEL 3 and RHEL4 guests which I've been digging into it the past few days.

All time drift issues we were aware of are fixed in kvm-70. Can you please provide more details on how you see the time drifting with RHEL3/4 guests? It slowly but continually drifts or there are large drifts at once? Are they using TSC or ACPIPM as clocksource?

Also, most issues we've seen could only be replicated with dyntick guests.

I'll try to reproduce it locally.

Quoted 3 lines

In the course of it I have been launching guests with boosted priority (both nice -20 and realtime priority (RR 1)) on a nearly 100% idle host.

Can you also see wacked bogomips without boosting the guest priority?

Quoted 10 lines

One host is a PowerEdge 2950 running RHEL5.2 with kvm-70. With the realtime priority boot I have routinely seen bogomips in the guest which do not make sense. e.g.,

ksyms.2:bogomips        : 4639.94
ksyms.2:bogomips        : 4653.05
ksyms.2:bogomips        : 4653.05
ksyms.2:bogomips        : 24.52
Quoted 6 lines

and

ksyms.3:bogomips        : 4639.94
ksyms.3:bogomips        : 4653.05
ksyms.3:bogomips        : 16.33
ksyms.3:bogomips        : 12.87

I'll look into it.

Quoted 53 lines

Also, if I launch qemu with the "-no-kvm-pit -tdf" option the panic guests panics with the message Marcelo posted at the start of the thread:

----

Calibrating delay loop... 4653.05 BogoMIPS

CPU: L2 cache: 2048K

Intel machine check reporting enabled on CPU#2.

CPU2: Intel QEMU Virtual CPU version 0.9.1 stepping 03

Booting processor 3/3 eip 2000

Initializing CPU#3

masked ExtINT on CPU#3

ESR value before enabling vector: 00000000

ESR value after enabling vector: 00000000

Calibrating delay loop... 19.60 BogoMIPS

CPU: L2 cache: 2048K

Intel machine check reporting enabled on CPU#3.

CPU3: Intel QEMU Virtual CPU version 0.9.1 stepping 03

Total of 4 processors activated (14031.20 BogoMIPS).

ENABLING IO-APIC IRQs

Setting 4 in the phys_id_present_map
...changing IO-APIC physical APIC ID to 4 ... ok. ..TIMER: vector=0x31 pin1=0 pin2=-1
..MP-BIOS bug: 8254 timer not connected to IO-APIC ...trying to set up timer (IRQ0) through the 8259A ... failed. ...trying to set up timer as Virtual Wire IRQ... failed. ...trying to set up timer as ExtINT IRQ... failed :(.

Kernel panic: IO-APIC + timer doesn't work! pester [email protected]

----

I'm just looking for stable guest times. I'm not planning to keep the boosted guest priority, just using it to ensure the guest is not interrupted as I try to understand why the guest systematically drifts.

david

#11 lore raw
Quoted 10 lines · Marcelo Tosatti

Hi David,

Quoted 1 line · David S. Ahern

What's the status with this for full virt guests?

The consensus seems to be that fullvirt guests need assistance from the management app (libvirt) to have boosted priority during their boot stage, so loops_per_jiffy calibration can be performed safely. As Daniel pointed out this is tricky because you can't know for sure how long the boot up will take, if for example PXE is used.

I boosted the priority of the guest to investigate an idea that maybe some startup calibration in the guest was off slightly leading to systematic drifting. I was on vacation last week and I am still catching up with traffic on this list. I just happened to see your first message with the panic which aligned with one of my tests.

Quoted 6 lines

Glauber is working on some paravirt patches to remedy the situation.

But loops_per_jiffy is not directly related to clock drifts, so this is a separate problem.

Quoted 7 lines
Quoted 2 lines

I am still seeing systematic time drifts in RHEL 3 and RHEL4 guests which I've been digging into it the past few days.

All time drift issues we were aware of are fixed in kvm-70. Can you please provide more details on how you see the time drifting with RHEL3/4 guests? It slowly but continually drifts or there are large drifts at once? Are they using TSC or ACPIPM as clocksource?

The attached file shows one example of the drift I am seeing. It's for a 4-way RHEL3 guest started with 'nice -20'. After startup each vcpu was pinned to a physical cpu using taskset. The only activity on the host is this one single guest; the guest is relatively idle -- about 4% activity (~1% user, ~3% system time). Host is synchronized to an ntp server; the guest is not. The guest is started with the -localtime parameter. From the file you can see the guest gains about 1-2 seconds every 5 minutes.

Since it's a RHEL3 guest I believe the PIT is the only choice (how to confirm?), though it does read the TSC (ie., use_tsc is 1).

Quoted 11 lines

Also, most issues we've seen could only be replicated with dyntick guests.

I'll try to reproduce it locally.

Quoted 3 lines

In the course of it I have been launching guests with boosted priority (both nice -20 and realtime priority (RR 1)) on a nearly 100% idle host.

Can you also see wacked bogomips without boosting the guest priority?

The wacked bogomips only shows up when started with real-time priority. With the 'nice -20' it's sane and close to what the host shows.

As another data point I restarted the RHEL3 guest using the -no-kvm-pit and -tdf options (nice -20 priority boost). After 22 hours of uptime, the guest is 29 seconds *behind* the host. Using the in-kernel pit the guest time is always fast compared to the host.

I've seen similar drifting in RHEL4 guests, but I have not spent as much time investigating it yet. On ESX adding clock=pit to the boot parameters for RHEL4 guests helps immensely.

david

host-dt   host time    guest time    guest-host-diff
    300   1215748151   1215748262    111
    301   1215748452   1215748563    111
    300   1215748752   1215748865    113
    300   1215749052   1215749165    113
    300   1215749352   1215749466    114
    301   1215749653   1215749768    115
    300   1215749953   1215750069    116
    300   1215750253   1215750369    116
    300   1215750553   1215750671    118
    301   1215750854   1215750972    118
    300   1215751154   1215751273    119
    300   1215751454   1215751575    121
    300   1215751754   1215751875    121
    301   1215752055   1215752176    121
    300   1215752355   1215752477    122
    300   1215752655   1215752780    125
    300   1215752955   1215753083    128
    301   1215753256   1215753385    129
    300   1215753556   1215753686    130
    300   1215753856   1215753988    132
    300   1215754156   1215754289    133
    301   1215754457   1215754592    135
    300   1215754757   1215754894    137
    300   1215755057   1215755198    141
    300   1215755357   1215755499    142
    301   1215755658   1215755799    141
    300   1215755958   1215756101    143
    300   1215756258   1215756402    144
    300   1215756558   1215756702    144
    301   1215756859   1215757005    146
    300   1215757159   1215757307    148
    300   1215757459   1215757609    150
    301   1215757760   1215757910    150
    300   1215758060   1215758211    151
    300   1215758360   1215758515    155
    300   1215758660   1215758816    156
    301   1215758961   1215759118    157
    300   1215759261   1215759418    157
    300   1215759561   1215759720    159
    300   1215759861   1215760022    161
    301   1215760162   1215760323    161
    300   1215760462   1215760625    163
    300   1215760762   1215760927    165
    300   1215761062   1215761229    167
    301   1215761363   1215761532    169
    300   1215761663   1215761833    170
    300   1215761963   1215762136    173
    300   1215762263   1215762439    176
    301   1215762564   1215762741    177
    300   1215762864   1215763043    179
    300   1215763164   1215763348    184
    300   1215763464   1215763649    185
    301   1215763765   1215763950    185
    300   1215764065   1215764251    186
    300   1215764365   1215764552    187
    300   1215764665   1215764854    189
    301   1215764966   1215765154    188
    300   1215765266   1215765455    189
    300   1215765566   1215765757    191
    300   1215765866   1215766058    192
    300   1215766166   1215766358    192
    301   1215766467   1215766666    199
    300   1215766767   1215766966    199
    300   1215767067   1215767269    202
    300   1215767367   1215767571    204
    301   1215767668   1215767871    203
    300   1215767968   1215768173    205
    300   1215768268   1215768476    208
    300   1215768568   1215768777    209
    301   1215768869   1215769078    209
    300   1215769169   1215769379    210
    300   1215769469   1215769682    213
    300   1215769769   1215769984    215
    301   1215770070   1215770286    216
    300   1215770370   1215770589    219
    300   1215770670   1215770890    220
    301   1215770971   1215771191    220
    300   1215771271   1215771496    225
    300   1215771571   1215771798    227
    300   1215771871   1215772100    229
    301   1215772172   1215772403    231
    300   1215772472   1215772704    232
    300   1215772772   1215773007    235
    300   1215773072   1215773307    235
    301   1215773373   1215773613    240
    300   1215773673   1215773916    243
    300   1215773973   1215774220    247
    300   1215774273   1215774520    247
    301   1215774574   1215774822    248
    300   1215774874   1215775122    248
    300   1215775174   1215775425    251
    300   1215775474   1215775725    251
    301   1215775775   1215776027    252
    300   1215776075   1215776327    252
    300   1215776375   1215776628    253
    300   1215776675   1215776928    253
    301   1215776976   1215777230    254
    300   1215777276   1215777531    255
    300   1215777576   1215777833    257
    300   1215777876   1215778136    260
    301   1215778177   1215778435    258
    300   1215778477   1215778736    259
    300   1215778777   1215779037    260
    300   1215779077   1215779337    260
    301   1215779378   1215779640    262
    300   1215779678   1215779941    263
    300   1215779978   1215780241    263
    300   1215780278   1215780544    266
    301   1215780579   1215780843    264
    300   1215780879   1215781146    267
    300   1215781179   1215781448    269
    300   1215781479   1215781749    270
    301   1215782269   1215782544    275
    300   1215782569   1215782844    275
    300   1215782869   1215783145    276
    300   1215783169   1215783447    278
    301   1215783470   1215783749    279
    300   1215783770   1215784050    280
    300   1215784070   1215784352    282
    300   1215784370   1215784654    284
    301   1215784671   1215784955    284
    300   1215784971   1215785258    287
    300   1215785271   1215785559    288
    300   1215785571   1215785861    290
    301   1215785872   1215786162    290
    300   1215786172   1215786463    291
    300   1215786472   1215786767    295
    300   1215786772   1215787068    296
    301   1215787073   1215787369    296
    300   1215787373   1215787670    297