render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 65d750dec286074fc48fdaa64eb3f5029626506f Mon Sep 17 00:00:00 2001
Message-Id: <65d750dec286074fc48fdaa64eb3f5029626506f@dist-git>
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
Date: Tue, 6 May 2014 13:55:44 +0200
Subject: [PATCH] Add invariant TSC cpu flag

Add suport for invariant TSC flag (CPUID 0x80000007, bit 8 of EDX).
If this flag is enabled, the TSC ticks at a constant rate across
all ACPI P-, C- and T-states.

This can be enabled by adding:
<feature name='invtsc'/>
to the <cpu> element.

Migration and saving the domain does not work with this flag.

QEMU support: http://git.qemu.org/?p=qemu.git;a=commitdiff;h=303752a

The feature name "invtsc" differs from the name "" used by the linux kernel:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/arch/x86/kernel/cpu/powerflags.c?id=30321c7b#n18

(cherry picked from commit fba6bc47cbcabbe08d42279691efb0dff3b9c997)
https://bugzilla.redhat.com/show_bug.cgi?id=1185458
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/cpu/cpu_map.xml       |  5 +++++
 src/qemu/qemu_migration.c | 15 +++++++++++++++
 src/qemu/qemu_process.c   | 15 +++++++++++++++
 3 files changed, 35 insertions(+)

diff --git a/src/cpu/cpu_map.xml b/src/cpu/cpu_map.xml
index 6d51283..aa10019 100644
--- a/src/cpu/cpu_map.xml
+++ b/src/cpu/cpu_map.xml
@@ -327,6 +327,11 @@
       <cpuid function='0x00000007' ebx='0x00100000'/>
     </feature>
 
+    <!-- Advanced Power Management edx features -->
+    <feature name='invtsc'>
+      <cpuid function='0x80000007' edx='0x00000100'/>
+    </feature>
+
     <!-- models -->
     <model name='486'>
       <feature name='fpu'/>
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index deacb66..d979d50 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1506,6 +1506,21 @@ qemuMigrationIsAllowed(virQEMUDriverPtr driver, virDomainObjPtr vm,
         return false;
     }
 
+    for (i = 0; i < def->cpu->nfeatures; i++) {
+        virCPUFeatureDefPtr feature = &def->cpu->features[i];
+
+        if (feature->policy != VIR_CPU_FEATURE_REQUIRE)
+            continue;
+
+        /* QEMU blocks migration and save with invariant TSC enabled */
+        if (STREQ(feature->name, "invtsc")) {
+            virReportError(VIR_ERR_OPERATION_INVALID,
+                           _("domain has CPU feature: %s"),
+                           feature->name);
+            return false;
+        }
+    }
+
     return true;
 }
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 3eda15b..8c07397 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3520,6 +3520,7 @@ qemuProcessVerifyGuestCPU(virQEMUDriverPtr driver, virDomainObjPtr vm)
     virCPUDataPtr guestcpu = NULL;
     qemuDomainObjPrivatePtr priv = vm->privateData;
     bool ret = false;
+    size_t i;
 
     switch (arch) {
     case VIR_ARCH_I686:
@@ -3538,6 +3539,20 @@ qemuProcessVerifyGuestCPU(virQEMUDriverPtr driver, virDomainObjPtr vm)
                 goto cleanup;
             }
         }
+
+        for (i = 0; i < def->cpu->nfeatures; i++) {
+            virCPUFeatureDefPtr feature = &def->cpu->features[i];
+
+            if (feature->policy != VIR_CPU_FEATURE_REQUIRE)
+                continue;
+
+            if (STREQ(feature->name, "invtsc") &&
+                !cpuHasFeature(guestcpu, feature->name)) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("host doesn't support invariant TSC"));
+                goto cleanup;
+            }
+        }
         break;
 
     default:
-- 
2.2.2