diff mbox

[v2,2/3] target-i386: calculate vcpu's TSC rate to be migrated

Message ID 1445325774-7195-3-git-send-email-haozhong.zhang@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Haozhong Zhang Oct. 20, 2015, 7:22 a.m. UTC
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 mbox

Patch

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;