qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Haozhong Zhang <haozhong.zhang@intel.com>
To: qemu-devel@nongnu.org
Cc: Haozhong Zhang <haozhong.zhang@intel.com>,
	Eduardo Habkost <ehabkost@redhat.com>,
	kvm@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	afaerber@suse.de, Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [PATCH v2 2/3] target-i386: calculate vcpu's TSC rate to be migrated
Date: Tue, 20 Oct 2015 15:22:53 +0800	[thread overview]
Message-ID: <1445325774-7195-3-git-send-email-haozhong.zhang@intel.com> (raw)
In-Reply-To: <1445325774-7195-1-git-send-email-haozhong.zhang@intel.com>

If vcpu's TSC rate is not specified by the cpu option 'tsc-freq', we
will use the value returned by KVM_GET_TSC_KHZ; otherwise, we use the
user-specified value.

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
 target-i386/kvm.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 80d1a7e..698524a 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -2213,6 +2213,35 @@ static int kvm_get_debugregs(X86CPU *cpu)
     return 0;
 }
 
+static int kvm_setup_tsc_khz(X86CPU *cpu, int level)
+{
+    CPUState *cs = CPU(cpu);
+    CPUX86State *env = &cpu->env;
+    int r;
+
+    if (level < KVM_PUT_FULL_STATE)
+        return 0;
+
+    /*
+     * Prepare the vcpu's TSC rate (ie. env->tsc_khz_incoming) to be migrated.
+     * 1. If no user-specified value is provided, we will use the value from
+     *    KVM;
+     * 2. Otherwise, we just use the user-specified value.
+     */
+    if (!env->tsc_khz) {
+        r = kvm_vcpu_ioctl(cs, KVM_GET_TSC_KHZ);
+        if (r < 0) {
+            fprintf(stderr, "KVM_GET_TSC_KHZ failed\n");
+            return r;
+        }
+        env->tsc_khz_incoming = r;
+    } else {
+        env->tsc_khz_incoming = env->tsc_khz;
+    }
+
+    return 0;
+}
+
 int kvm_arch_put_registers(CPUState *cpu, int level)
 {
     X86CPU *x86_cpu = X86_CPU(cpu);
@@ -2248,6 +2277,10 @@ int kvm_arch_put_registers(CPUState *cpu, int level)
     if (ret < 0) {
         return ret;
     }
+    ret = kvm_setup_tsc_khz(x86_cpu, level);
+    if (ret < 0) {
+        return ret;
+    }
     ret = kvm_put_msrs(x86_cpu, level);
     if (ret < 0) {
         return ret;
-- 
2.4.8

  parent reply	other threads:[~2015-10-20  7:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-20  7:22 [Qemu-devel] [PATCH v2 0/3] target-i386: save/restore vcpu's TSC rate during migration Haozhong Zhang
2015-10-20  7:22 ` [Qemu-devel] [PATCH v2 1/3] target-i386: add a subsection for migrating vcpu's TSC rate Haozhong Zhang
2015-10-20  7:22 ` Haozhong Zhang [this message]
2015-10-20  7:22 ` [Qemu-devel] [PATCH v2 3/3] target-i386: load the migrated " Haozhong Zhang
2015-10-22 18:11   ` Eduardo Habkost
2015-10-23  3:04     ` Haozhong Zhang
2015-10-23  3:14     ` Haozhong Zhang
2015-10-23 14:58       ` Eduardo Habkost
2015-10-26  2:09         ` haozhong.zhang
2015-10-22 18:45 ` [Qemu-devel] [PATCH v2 0/3] target-i386: save/restore vcpu's TSC rate during migration Eduardo Habkost
2015-10-23  2:27   ` Haozhong Zhang
2015-10-23 14:45     ` Eduardo Habkost
2015-10-26  2:09       ` haozhong.zhang
2015-10-26 18:41         ` Eduardo Habkost
2015-10-27  1:09           ` haozhong.zhang
2015-10-23 10:35   ` Marcelo Tosatti
2015-10-23 12:22     ` Eduardo Habkost
2015-10-23 12:45     ` Haozhong Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1445325774-7195-3-git-send-email-haozhong.zhang@intel.com \
    --to=haozhong.zhang@intel.com \
    --cc=afaerber@suse.de \
    --cc=ehabkost@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).