KVM: x86: Add module parameter for lapic periodic timer limit
authorJan Kiszka <jan.kiszka@siemens.com>
Mon, 12 Sep 2011 12:10:22 +0000 (14:10 +0200)
committerAvi Kivity <avi@redhat.com>
Sun, 25 Sep 2011 16:52:44 +0000 (19:52 +0300)
Certain guests, specifically RTOSes, request faster periodic timers than
what we allow by default. Add a module parameter to adjust the limit for
non-standard setups. Also add a rate-limited warning in case the guest
requested more.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
arch/x86/kvm/lapic.c

index 4b53b811d1c1a2b53ea14235fa8ecffa0b42e618..2fb20caae5d8b7453efa989ac44e1ba029577b26 100644 (file)
@@ -68,6 +68,9 @@
 #define VEC_POS(v) ((v) & (32 - 1))
 #define REG_POS(v) (((v) >> 5) << 4)
 
+static unsigned int min_timer_period_us = 500;
+module_param(min_timer_period_us, uint, S_IRUGO | S_IWUSR);
+
 static inline u32 apic_get_reg(struct kvm_lapic *apic, int reg_off)
 {
        return *((u32 *) (apic->regs + reg_off));
@@ -677,8 +680,16 @@ static void start_apic_timer(struct kvm_lapic *apic)
         * scheduler.
         */
        if (apic_lvtt_period(apic)) {
-               if (apic->lapic_timer.period < NSEC_PER_MSEC/2)
-                       apic->lapic_timer.period = NSEC_PER_MSEC/2;
+               s64 min_period = min_timer_period_us * 1000LL;
+
+               if (apic->lapic_timer.period < min_period) {
+                       pr_info_ratelimited(
+                               "kvm: vcpu %i: requested %lld ns "
+                               "lapic timer period limited to %lld ns\n",
+                               apic->vcpu->vcpu_id, apic->lapic_timer.period,
+                               min_period);
+                       apic->lapic_timer.period = min_period;
+               }
        }
 
        hrtimer_start(&apic->lapic_timer.timer,