[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1260850127-9766-3-git-send-email-zamsden@redhat.com>
Date: Mon, 14 Dec 2009 18:08:29 -1000
From: Zachary Amsden <zamsden@...hat.com>
To: kvm@...r.kernel.org
Cc: Zachary Amsden <zamsden@...hat.com>, Avi Kivity <avi@...hat.com>,
Marcelo Tosatti <mtosatti@...hat.com>,
Joerg Roedel <joerg.roedel@....com>,
linux-kernel@...r.kernel.org, Dor Laor <dlaor@...hat.com>
Subject: [PATCH RFC: kvm tsc virtualization 02/20] Add a hotplug notifier to KVM x86 backend
Using a hotplug notifier here gives us direct control for getting the
clock rate, which might be different on power-up. This eliminates a check
from the hot path of entering hardware virtualization, and is a cleaner
way to do things. The notifier must be last, so the cpufreq code has a
chance to run first and figure out the CPU speed.
Signed-off-by: Zachary Amsden <zamsden@...hat.com>
---
arch/x86/kvm/x86.c | 38 ++++++++++++++++++++++++++++----------
1 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1cc51ca..faa467d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3308,10 +3308,37 @@ static struct notifier_block kvmclock_cpufreq_notifier_block = {
.notifier_call = kvmclock_cpufreq_notifier
};
+static int kvm_x86_cpu_hotplug(struct notifier_block *notifier,
+ unsigned long val, void *v)
+{
+ int cpu = (long)v;
+
+ val &= ~CPU_TASKS_FROZEN;
+ switch (val) {
+ case CPU_DYING:
+ case CPU_UP_CANCELED:
+ if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
+ per_cpu(cpu_tsc_khz, cpu) = 0;
+ break;
+
+ case CPU_ONLINE:
+ if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
+ per_cpu(cpu_tsc_khz, cpu) = cpufreq_quick_get(cpu);
+ break;
+ }
+ return NOTIFY_OK;
+}
+
+static struct notifier_block kvm_x86_cpu_notifier = {
+ .notifier_call = kvm_x86_cpu_hotplug,
+ .priority = -INT_MAX, /* we want to be called last */
+};
+
static void kvm_timer_init(void)
{
int cpu;
+ register_cpu_notifier(&kvm_x86_cpu_notifier);
if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) {
cpufreq_register_notifier(&kvmclock_cpufreq_notifier_block,
CPUFREQ_TRANSITION_NOTIFIER);
@@ -3374,6 +3401,7 @@ void kvm_arch_exit(void)
if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
cpufreq_unregister_notifier(&kvmclock_cpufreq_notifier_block,
CPUFREQ_TRANSITION_NOTIFIER);
+ unregister_cpu_notifier(&kvm_x86_cpu_notifier);
kvm_x86_ops = NULL;
kvm_mmu_module_exit();
}
@@ -4904,17 +4932,7 @@ int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu)
int kvm_arch_hardware_enable(void *garbage)
{
- /*
- * Since this may be called from a hotplug notifcation,
- * we can't get the CPU frequency directly.
- */
- if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) {
- int cpu = raw_smp_processor_id();
- per_cpu(cpu_tsc_khz, cpu) = 0;
- }
-
kvm_shared_msr_cpu_online();
-
return kvm_x86_ops->hardware_enable(garbage);
}
--
1.6.5.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists