From patchwork Mon Nov 2 09:26:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 7535171 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7A780BEEA4 for ; Mon, 2 Nov 2015 09:30:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 92A9E205EF for ; Mon, 2 Nov 2015 09:30:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 96C87205EB for ; Mon, 2 Nov 2015 09:30:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752427AbbKBJaX (ORCPT ); Mon, 2 Nov 2015 04:30:23 -0500 Received: from mga11.intel.com ([192.55.52.93]:35016 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751061AbbKBJaW (ORCPT ); Mon, 2 Nov 2015 04:30:22 -0500 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 02 Nov 2015 01:30:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,234,1444719600"; d="scan'208";a="824762617" Received: from hzzhang-optiplex-9020.sh.intel.com (HELO localhost) ([10.239.12.31]) by fmsmga001.fm.intel.com with ESMTP; 02 Nov 2015 01:28:34 -0800 From: Haozhong Zhang To: qemu-devel@nongnu.org, Eduardo Habkost , "Dr. David Alan Gilbert" Cc: "Michael S. Tsirkin" , Paolo Bonzini , Richard Henderson , Peter Maydell , Marcelo Tosatti , James Hogan , Aurelien Jarno , Leon Alrae , Alexander Graf , Christian Borntraeger , Cornelia Huck , kvm@vger.kernel.org, qemu-ppc@nongnu.org, Haozhong Zhang Subject: [PATCH v3 1/3] target-i386: add a subsection for migrating vcpu's TSC rate Date: Mon, 2 Nov 2015 17:26:41 +0800 Message-Id: <1446456403-29909-2-git-send-email-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.4.8 In-Reply-To: <1446456403-29909-1-git-send-email-haozhong.zhang@intel.com> References: <1446456403-29909-1-git-send-email-haozhong.zhang@intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A new subsection 'vmstate_tsc_khz' is added to migrate vcpu's TSC rate. For the backwards compatibility, this subsection is not migrated on pc-*-2.4 and older machine types. Signed-off-by: Haozhong Zhang --- hw/i386/pc.c | 1 + hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + include/hw/i386/pc.h | 1 + target-i386/cpu.h | 1 + target-i386/machine.c | 21 +++++++++++++++++++++ 6 files changed, 26 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 0cb8afd..2f2fc93 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1952,6 +1952,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); pcmc->get_hotplug_handler = mc->get_hotplug_handler; + pcmc->save_tsc_khz = true; mc->get_hotplug_handler = pc_get_hotpug_handler; mc->cpu_index_to_socket_id = pc_cpu_index_to_socket_id; mc->default_boot_order = "cad"; diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 393dcc4..fc71321 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -487,6 +487,7 @@ static void pc_i440fx_2_4_machine_options(MachineClass *m) m->alias = NULL; m->is_default = 0; pcmc->broken_reserved_end = true; + pcmc->save_tsc_khz = false; SET_MACHINE_COMPAT(m, PC_COMPAT_2_4); } diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 2f8f396..858ed69 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -385,6 +385,7 @@ static void pc_q35_2_4_machine_options(MachineClass *m) pc_q35_2_5_machine_options(m); m->alias = NULL; pcmc->broken_reserved_end = true; + pcmc->save_tsc_khz = false; SET_MACHINE_COMPAT(m, PC_COMPAT_2_4); } diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 606dbc2..875d099 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -60,6 +60,7 @@ struct PCMachineClass { /*< public >*/ bool broken_reserved_end; + bool save_tsc_khz; HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev); }; diff --git a/target-i386/cpu.h b/target-i386/cpu.h index 62f7879..4f2f4a3 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -970,6 +970,7 @@ typedef struct CPUX86State { uint32_t sipi_vector; bool tsc_valid; int64_t tsc_khz; + int64_t tsc_khz_saved; void *kvm_xsave_buf; uint64_t mcg_cap; diff --git a/target-i386/machine.c b/target-i386/machine.c index a18e16e..4d8157c 100644 --- a/target-i386/machine.c +++ b/target-i386/machine.c @@ -775,6 +775,26 @@ static const VMStateDescription vmstate_xss = { } }; +static bool tsc_khz_needed(void *opaque) +{ + X86CPU *cpu = opaque; + CPUX86State *env = &cpu->env; + MachineClass *mc = MACHINE_GET_CLASS((qdev_get_machine())); + PCMachineClass *pcmc = PC_MACHINE_CLASS(mc); + return env->tsc_khz_saved && pcmc->save_tsc_khz; +} + +static const VMStateDescription vmstate_tsc_khz = { + .name = "cpu/tsc_khz", + .version_id = 1, + .minimum_version_id = 1, + .needed = tsc_khz_needed, + .fields = (VMStateField[]) { + VMSTATE_INT64(env.tsc_khz_saved, X86CPU), + VMSTATE_END_OF_LIST() + } +}; + VMStateDescription vmstate_x86_cpu = { .name = "cpu", .version_id = 12, @@ -895,6 +915,7 @@ VMStateDescription vmstate_x86_cpu = { &vmstate_msr_hyperv_runtime, &vmstate_avx512, &vmstate_xss, + &vmstate_tsc_khz, NULL } };