diff mbox

[RFC:,tsc,virtualization,02/20] Add a hotplug notifier to KVM x86 backend

Message ID 1260850127-9766-3-git-send-email-zamsden@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Zachary Amsden Dec. 15, 2009, 4:08 a.m. UTC
None
diff mbox

Patch

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);
 }