From patchwork Tue Dec 15 04:08:29 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zachary Amsden X-Patchwork-Id: 67481 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nBF4QSLu016846 for ; Tue, 15 Dec 2009 04:26:32 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759294AbZLOENV (ORCPT ); Mon, 14 Dec 2009 23:13:21 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1759296AbZLOEMv (ORCPT ); Mon, 14 Dec 2009 23:12:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:10873 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754271AbZLOEG4 (ORCPT ); Mon, 14 Dec 2009 23:06:56 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBF46teq024543 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 14 Dec 2009 23:06:55 -0500 Received: from localhost.localdomain (vpn-9-100.rdu.redhat.com [10.11.9.100]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBF46m8u031119; Mon, 14 Dec 2009 23:06:52 -0500 From: Zachary Amsden To: kvm@vger.kernel.org Cc: Zachary Amsden , Avi Kivity , Marcelo Tosatti , Joerg Roedel , linux-kernel@vger.kernel.org, Dor Laor Subject: [PATCH RFC: kvm tsc virtualization 02/20] Add a hotplug notifier to KVM x86 backend Date: Mon, 14 Dec 2009 18:08:29 -1000 Message-Id: <1260850127-9766-3-git-send-email-zamsden@redhat.com> In-Reply-To: <1260850127-9766-2-git-send-email-zamsden@redhat.com> References: <1260850127-9766-1-git-send-email-zamsden@redhat.com> <1260850127-9766-2-git-send-email-zamsden@redhat.com> Organization: Frobozz Magic Timekeeping Company X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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); }