qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v2 2/3] target-i386: calculate vcpu's TSC rate to be


From: Haozhong Zhang
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

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 <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]