All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] Expose tsc deadline timer cpuid to guest
@ 2011-12-28 21:55 ` Liu, Jinsong
  0 siblings, 0 replies; 100+ messages in thread
From: Liu, Jinsong @ 2011-12-28 21:55 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: Avi Kivity, Marcelo Tosatti, Alexey Zaytsev, kvm, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 4323 bytes --]

>From 3a78adf8006ec6189bfe2f55f7ae213e75bf3815 Mon Sep 17 00:00:00 2001
From: Liu Jinsong <jinsong.liu@intel.com>
Date: Thu, 29 Dec 2011 05:28:12 +0800
Subject: [PATCH 2/2] Expose tsc deadline timer cpuid to guest

Depend on several factors:
1. Considering live migration, user enable/disable tsc deadline timer;
2. If guest use kvm apic and kvm emulate tsc deadline timer, expose it;
3. If in the future qemu support tsc deadline timer emulation,
   and guest use qemu apic, add cpuid exposing case then.

Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com>
---
 target-i386/cpu.h   |    2 ++
 target-i386/cpuid.c |    7 ++++++-
 target-i386/kvm.c   |   13 +++++++++++++
 3 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 177d8aa..f2d0ad5 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -399,6 +399,7 @@
 #define CPUID_EXT_X2APIC   (1 << 21)
 #define CPUID_EXT_MOVBE    (1 << 22)
 #define CPUID_EXT_POPCNT   (1 << 23)
+#define CPUID_EXT_TSC_DEADLINE_TIMER (1 << 24)
 #define CPUID_EXT_XSAVE    (1 << 26)
 #define CPUID_EXT_OSXSAVE  (1 << 27)
 #define CPUID_EXT_HYPERVISOR  (1 << 31)
@@ -693,6 +694,7 @@ typedef struct CPUX86State {
 
     uint64_t tsc;
     uint64_t tsc_deadline;
+    bool tsc_deadline_timer_enabled;
 
     uint64_t mcg_status;
     uint64_t msr_ia32_misc_enable;
diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index 0b3af90..fe749e0 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -48,7 +48,7 @@ static const char *ext_feature_name[] = {
     "fma", "cx16", "xtpr", "pdcm",
     NULL, NULL, "dca", "sse4.1|sse4_1",
     "sse4.2|sse4_2", "x2apic", "movbe", "popcnt",
-    NULL, "aes", "xsave", "osxsave",
+    "tsc_deadline", "aes", "xsave", "osxsave",
     "avx", NULL, NULL, "hypervisor",
 };
 static const char *ext2_feature_name[] = {
@@ -225,6 +225,7 @@ typedef struct x86_def_t {
     int model;
     int stepping;
     int tsc_khz;
+    bool tsc_deadline_timer_enabled;
     uint32_t features, ext_features, ext2_features, ext3_features;
     uint32_t kvm_features, svm_features;
     uint32_t xlevel;
@@ -742,6 +743,9 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
     x86_cpu_def->ext3_features &= ~minus_ext3_features;
     x86_cpu_def->kvm_features &= ~minus_kvm_features;
     x86_cpu_def->svm_features &= ~minus_svm_features;
+    /* Defaultly user don't against tsc_deadline_timer */
+    x86_cpu_def->tsc_deadline_timer_enabled =
+        !(minus_ext_features & CPUID_EXT_TSC_DEADLINE_TIMER);
     if (check_cpuid) {
         if (check_features_against_host(x86_cpu_def) && enforce_cpuid)
             goto error;
@@ -885,6 +889,7 @@ int cpu_x86_register (CPUX86State *env, const char *cpu_model)
     env->cpuid_ext4_features = def->ext4_features;
     env->cpuid_xlevel2 = def->xlevel2;
     env->tsc_khz = def->tsc_khz;
+    env->tsc_deadline_timer_enabled = def->tsc_deadline_timer_enabled;
     if (!kvm_enabled()) {
         env->cpuid_features &= TCG_FEATURES;
         env->cpuid_ext_features &= TCG_EXT_FEATURES;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index d50de90..79baf0b 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -370,6 +370,19 @@ int kvm_arch_init_vcpu(CPUState *env)
     i = env->cpuid_ext_features & CPUID_EXT_HYPERVISOR;
     env->cpuid_ext_features &= kvm_arch_get_supported_cpuid(s, 1, 0, R_ECX);
     env->cpuid_ext_features |= i;
+    /*
+     * 1. Considering live migration, user enable/disable tsc deadline timer;
+     * 2. If guest use kvm apic and kvm emulate tsc deadline timer, expose it;
+     * 3. If in the future qemu support tsc deadline timer emulation,
+     *    and guest use qemu apic, add cpuid exposing case then.
+     */
+    env->cpuid_ext_features &= ~CPUID_EXT_TSC_DEADLINE_TIMER;
+    if (env->tsc_deadline_timer_enabled) {
+        if (kvm_irqchip_in_kernel() &&
+            kvm_check_extension(s, KVM_CAP_TSC_DEADLINE_TIMER)) {
+            env->cpuid_ext_features |= CPUID_EXT_TSC_DEADLINE_TIMER;
+        }
+    }
 
     env->cpuid_ext2_features &= kvm_arch_get_supported_cpuid(s, 0x80000001,
                                                              0, R_EDX);
-- 
1.6.5.6

[-- Attachment #2: 0002-Expose-tsc-deadline-timer-cpuid-to-guest.patch --]
[-- Type: application/octet-stream, Size: 4220 bytes --]

From 3a78adf8006ec6189bfe2f55f7ae213e75bf3815 Mon Sep 17 00:00:00 2001
From: Liu Jinsong <jinsong.liu@intel.com>
Date: Thu, 29 Dec 2011 05:28:12 +0800
Subject: [PATCH 2/2] Expose tsc deadline timer cpuid to guest

Depend on several factors:
1. Considering live migration, user enable/disable tsc deadline timer;
2. If guest use kvm apic and kvm emulate tsc deadline timer, expose it;
3. If in the future qemu support tsc deadline timer emulation,
   and guest use qemu apic, add cpuid exposing case then.

Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com>
---
 target-i386/cpu.h   |    2 ++
 target-i386/cpuid.c |    7 ++++++-
 target-i386/kvm.c   |   13 +++++++++++++
 3 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 177d8aa..f2d0ad5 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -399,6 +399,7 @@
 #define CPUID_EXT_X2APIC   (1 << 21)
 #define CPUID_EXT_MOVBE    (1 << 22)
 #define CPUID_EXT_POPCNT   (1 << 23)
+#define CPUID_EXT_TSC_DEADLINE_TIMER (1 << 24)
 #define CPUID_EXT_XSAVE    (1 << 26)
 #define CPUID_EXT_OSXSAVE  (1 << 27)
 #define CPUID_EXT_HYPERVISOR  (1 << 31)
@@ -693,6 +694,7 @@ typedef struct CPUX86State {
 
     uint64_t tsc;
     uint64_t tsc_deadline;
+    bool tsc_deadline_timer_enabled;
 
     uint64_t mcg_status;
     uint64_t msr_ia32_misc_enable;
diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index 0b3af90..fe749e0 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -48,7 +48,7 @@ static const char *ext_feature_name[] = {
     "fma", "cx16", "xtpr", "pdcm",
     NULL, NULL, "dca", "sse4.1|sse4_1",
     "sse4.2|sse4_2", "x2apic", "movbe", "popcnt",
-    NULL, "aes", "xsave", "osxsave",
+    "tsc_deadline", "aes", "xsave", "osxsave",
     "avx", NULL, NULL, "hypervisor",
 };
 static const char *ext2_feature_name[] = {
@@ -225,6 +225,7 @@ typedef struct x86_def_t {
     int model;
     int stepping;
     int tsc_khz;
+    bool tsc_deadline_timer_enabled;
     uint32_t features, ext_features, ext2_features, ext3_features;
     uint32_t kvm_features, svm_features;
     uint32_t xlevel;
@@ -742,6 +743,9 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
     x86_cpu_def->ext3_features &= ~minus_ext3_features;
     x86_cpu_def->kvm_features &= ~minus_kvm_features;
     x86_cpu_def->svm_features &= ~minus_svm_features;
+    /* Defaultly user don't against tsc_deadline_timer */
+    x86_cpu_def->tsc_deadline_timer_enabled =
+        !(minus_ext_features & CPUID_EXT_TSC_DEADLINE_TIMER);
     if (check_cpuid) {
         if (check_features_against_host(x86_cpu_def) && enforce_cpuid)
             goto error;
@@ -885,6 +889,7 @@ int cpu_x86_register (CPUX86State *env, const char *cpu_model)
     env->cpuid_ext4_features = def->ext4_features;
     env->cpuid_xlevel2 = def->xlevel2;
     env->tsc_khz = def->tsc_khz;
+    env->tsc_deadline_timer_enabled = def->tsc_deadline_timer_enabled;
     if (!kvm_enabled()) {
         env->cpuid_features &= TCG_FEATURES;
         env->cpuid_ext_features &= TCG_EXT_FEATURES;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index d50de90..79baf0b 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -370,6 +370,19 @@ int kvm_arch_init_vcpu(CPUState *env)
     i = env->cpuid_ext_features & CPUID_EXT_HYPERVISOR;
     env->cpuid_ext_features &= kvm_arch_get_supported_cpuid(s, 1, 0, R_ECX);
     env->cpuid_ext_features |= i;
+    /*
+     * 1. Considering live migration, user enable/disable tsc deadline timer;
+     * 2. If guest use kvm apic and kvm emulate tsc deadline timer, expose it;
+     * 3. If in the future qemu support tsc deadline timer emulation,
+     *    and guest use qemu apic, add cpuid exposing case then.
+     */
+    env->cpuid_ext_features &= ~CPUID_EXT_TSC_DEADLINE_TIMER;
+    if (env->tsc_deadline_timer_enabled) {
+        if (kvm_irqchip_in_kernel() &&
+            kvm_check_extension(s, KVM_CAP_TSC_DEADLINE_TIMER)) {
+            env->cpuid_ext_features |= CPUID_EXT_TSC_DEADLINE_TIMER;
+        }
+    }
 
     env->cpuid_ext2_features &= kvm_arch_get_supported_cpuid(s, 0x80000001,
                                                              0, R_EDX);
-- 
1.6.5.6


^ permalink raw reply related	[flat|nested] 100+ messages in thread

end of thread, other threads:[~2012-06-14 19:18 UTC | newest]

Thread overview: 100+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-28 21:55 [PATCH 2/2] Expose tsc deadline timer cpuid to guest Liu, Jinsong
2011-12-28 21:55 ` [Qemu-devel] " Liu, Jinsong
2012-01-04 16:48 ` Jan Kiszka
2012-01-04 16:48   ` [Qemu-devel] " Jan Kiszka
2012-01-05 20:07   ` Liu, Jinsong
2012-01-05 20:07     ` [Qemu-devel] " Liu, Jinsong
2012-01-05 20:34     ` Jan Kiszka
2012-01-05 20:34       ` [Qemu-devel] " Jan Kiszka
2012-01-07 18:23       ` Liu, Jinsong
2012-01-07 18:23         ` [Qemu-devel] " Liu, Jinsong
2012-01-08 21:24         ` Jan Kiszka
2012-01-08 21:24           ` [Qemu-devel] " Jan Kiszka
2012-02-27 16:05           ` Liu, Jinsong
2012-02-27 16:05             ` [Qemu-devel] " Liu, Jinsong
2012-02-27 17:18             ` Jan Kiszka
2012-02-27 17:18               ` [Qemu-devel] " Jan Kiszka
2012-02-28 10:30               ` Liu, Jinsong
2012-02-28 10:30                 ` [Qemu-devel] " Liu, Jinsong
2012-03-06  7:49                 ` Liu, Jinsong
2012-03-06  7:49                   ` Liu, Jinsong
2012-03-06 10:14                   ` Jan Kiszka
2012-03-06 10:14                     ` Jan Kiszka
2012-03-09 18:27                     ` Liu, Jinsong
2012-03-09 18:27                       ` [Qemu-devel] " Liu, Jinsong
2012-03-09 18:56                       ` Jan Kiszka
2012-03-09 18:56                         ` Jan Kiszka
2012-03-09 19:09                         ` Liu, Jinsong
2012-03-09 19:09                           ` Liu, Jinsong
2012-03-09 20:52                           ` Jan Kiszka
2012-03-09 20:52                             ` Jan Kiszka
2012-03-10  1:07                             ` Andreas Färber
2012-03-10  1:07                               ` Andreas Färber
2012-03-11 18:54                             ` Liu, Jinsong
2012-03-11 18:54                               ` Liu, Jinsong
2012-03-12 17:21                             ` Eduardo Habkost
2012-03-25  8:51                               ` Liu, Jinsong
2012-03-25  8:51                                 ` [Qemu-devel] " Liu, Jinsong
2012-03-09 19:29                       ` Liu, Jinsong
2012-03-09 19:29                         ` [Qemu-devel] " Liu, Jinsong
2012-03-19 22:35                       ` Rik van Riel
2012-03-20 12:53                         ` Liu, Jinsong
2012-03-20 13:33                           ` Eduardo Habkost
2012-03-20 13:33                             ` Eduardo Habkost
2012-03-23  3:49                             ` Liu, Jinsong
2012-03-23  3:49                               ` Liu, Jinsong
2012-03-23 13:46                               ` Eduardo Habkost
2012-03-23 13:46                                 ` Eduardo Habkost
2012-03-23 14:17                                 ` Liu, Jinsong
2012-03-23 14:17                                   ` Liu, Jinsong
2012-04-19 20:03                                   ` Eduardo Habkost
2012-04-20 10:12                                     ` Jan Kiszka
2012-04-20 15:00                                       ` Eduardo Habkost
2012-04-20 15:19                                         ` [Qemu-devel] " Jan Kiszka
2012-04-20 15:36                                           ` Eduardo Habkost
2012-04-21  7:23                                             ` Jan Kiszka
2012-04-23 14:48                                               ` Eduardo Habkost
2012-04-23 16:31                                                 ` Jan Kiszka
2012-04-23 20:02                                                   ` Eduardo Habkost
2012-04-24 16:06                                                     ` Jan Kiszka
2012-04-24 17:19                                                       ` [Qemu-devel] " Eduardo Habkost
2012-05-07 18:21                                                         ` Semantics of "-cpu host" (was Re: [Qemu-devel] [PATCH 2/2] Expose tsc deadline timer cpuid to guest) Eduardo Habkost
2012-05-07 18:21                                                           ` [Qemu-devel] Semantics of "-cpu host" (was " Eduardo Habkost
2012-05-08  0:58                                                           ` Alexander Graf
2012-05-08  0:58                                                             ` [Qemu-devel] " Alexander Graf
2012-05-08 20:14                                                             ` Semantics of "-cpu host" (was Re: [Qemu-devel] " Eduardo Habkost
2012-05-08 20:14                                                               ` [Qemu-devel] Semantics of "-cpu host" (was " Eduardo Habkost
2012-05-08 22:07                                                               ` Semantics of "-cpu host" (was Re: [Qemu-devel] " Alexander Graf
2012-05-08 22:07                                                                 ` [Qemu-devel] Semantics of "-cpu host" (was " Alexander Graf
2012-05-09  8:14                                                                 ` Gleb Natapov
2012-05-09  8:14                                                                   ` [Qemu-devel] " Gleb Natapov
2012-05-09  8:42                                                                   ` Semantics of "-cpu host" (was Re: [Qemu-devel] " Alexander Graf
2012-05-09  8:42                                                                     ` [Qemu-devel] Semantics of "-cpu host" (was " Alexander Graf
2012-05-09  8:51                                                                     ` Semantics of "-cpu host" (was Re: [Qemu-devel] " Gleb Natapov
2012-05-09  8:51                                                                       ` [Qemu-devel] Semantics of "-cpu host" (was " Gleb Natapov
2012-05-09  9:05                                                                       ` Semantics of "-cpu host" (was Re: [Qemu-devel] " Alexander Graf
2012-05-09  9:05                                                                         ` [Qemu-devel] Semantics of "-cpu host" (was " Alexander Graf
2012-05-09  9:38                                                                         ` Semantics of "-cpu host" (was Re: [Qemu-devel] " Gleb Natapov
2012-05-09  9:38                                                                           ` [Qemu-devel] Semantics of "-cpu host" (was " Gleb Natapov
2012-05-09  9:54                                                                           ` Semantics of "-cpu host" (was Re: [Qemu-devel] " Alexander Graf
2012-05-09  9:54                                                                             ` [Qemu-devel] Semantics of "-cpu host" (was " Alexander Graf
2012-05-09 19:38                                                                           ` Semantics of "-cpu host" (was Re: [Qemu-devel] " Eduardo Habkost
2012-05-09 19:38                                                                             ` [Qemu-devel] Semantics of "-cpu host" (was " Eduardo Habkost
2012-05-09 20:30                                                                             ` Semantics of "-cpu host" (was Re: [Qemu-devel] " Alexander Graf
2012-05-09 20:30                                                                               ` [Qemu-devel] Semantics of "-cpu host" (was " Alexander Graf
2012-05-10 12:53                                                                             ` Gleb Natapov
2012-05-10 12:53                                                                               ` [Qemu-devel] " Gleb Natapov
2012-05-10 13:21                                                                               ` Semantics of "-cpu host" (was Re: [Qemu-devel] " Alexander Graf
2012-05-10 13:21                                                                                 ` [Qemu-devel] Semantics of "-cpu host" (was " Alexander Graf
2012-05-10 13:39                                                                                 ` Semantics of "-cpu host" (was Re: [Qemu-devel] " Gleb Natapov
2012-05-10 13:39                                                                                   ` [Qemu-devel] Semantics of "-cpu host" (was " Gleb Natapov
2012-05-10 14:12                                                                                   ` Semantics of "-cpu host" (was Re: [Qemu-devel] " Eduardo Habkost
2012-05-10 14:12                                                                                     ` [Qemu-devel] Semantics of "-cpu host" (was " Eduardo Habkost
2012-05-09  7:16                                                           ` Semantics of "-cpu host" (was Re: [Qemu-devel] " Andre Przywara
2012-05-09  7:16                                                             ` [Qemu-devel] Semantics of "-cpu host" (was " Andre Przywara
2012-06-14 19:02                                                         ` [Qemu-devel] [PATCH 2/2] Expose tsc deadline timer cpuid to guest Liu, Jinsong
2012-06-14 19:02                                                           ` Liu, Jinsong
2012-06-14 19:12                                                           ` Eduardo Habkost
2012-06-14 19:12                                                             ` Eduardo Habkost
2012-06-14 19:18                                                             ` Liu, Jinsong
2012-06-14 19:18                                                               ` [Qemu-devel] " Liu, Jinsong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.