Skip to contentSkip to conversation

qemu-kvm.git uq/master queue

GIT PULL In review Marcelo Tosatti 3 participants 9 messages Aug 5, 2011 – Aug 8, 2011 KVM

lore
Share & tools
lore
#1 lore raw

PATCH 1/6 kvmclock: Fix feature detection

In reply to Marcelo Tosatti

From: Jan Kiszka <[email protected]>

Bit-wise or the feature flags and drop the obsolete #ifdef.

---
 hw/kvmclock.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)
hw/kvmclock.c +2 -5
index 692ad18..b73aec4 100644
@@ -101,11 +101,8 @@ static SysBusDeviceInfo kvmclock_info = {
 void kvmclock_create(void)
 {
     if (kvm_enabled() &&
-        first_cpu->cpuid_kvm_features & ((1ULL << KVM_FEATURE_CLOCKSOURCE)
-#ifdef KVM_FEATURE_CLOCKSOURCE2
-        || (1ULL << KVM_FEATURE_CLOCKSOURCE2)
-#endif
-    )) {
+        first_cpu->cpuid_kvm_features & ((1ULL << KVM_FEATURE_CLOCKSOURCE) |
+                                         (1ULL << KVM_FEATURE_CLOCKSOURCE2))) {
         sysbus_create_simple("kvmclock", -1, NULL);
     }
 }
Signature · 1 line
1.7.5.4
#7 lore raw

PATCH 6/6 Remove #ifdef KVM_CAP_TSC_CONTROL

In reply to Marcelo Tosatti
---
 target-i386/kvm.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
target-i386/kvm.c +0 -2
index 923d2d5..31b88b7 100644
@@ -504,7 +504,6 @@ int kvm_arch_init_vcpu(CPUState *env)
     if (r)
 	    return r;
 
-#ifdef KVM_CAP_TSC_CONTROL
     r = kvm_check_extension(env->kvm_state, KVM_CAP_TSC_CONTROL);
     if (r && env->tsc_khz) {
         r = kvm_vcpu_ioctl(env, KVM_SET_TSC_KHZ, env->tsc_khz);
@@ -513,7 +512,6 @@ int kvm_arch_init_vcpu(CPUState *env)
             return r;
         }
     }
-#endif
 
     return 0;
 }
Signature · 1 line
1.7.5.4
#2 lore raw

PATCH 2/6 kvm: Drop obsolete KVM_IOEVENTFD #ifdefs

In reply to Marcelo Tosatti

From: Jan Kiszka <[email protected]>

---
 kvm-all.c |    8 --------
 1 files changed, 0 insertions(+), 8 deletions(-)
kvm-all.c +0 -8
index cbc2532..b9c172b 100644
@@ -1328,7 +1328,6 @@ int kvm_set_signal_mask(CPUState *env, const sigset_t *sigset)
 
 int kvm_set_ioeventfd_mmio_long(int fd, uint32_t addr, uint32_t val, bool assign)
 {
-#ifdef KVM_IOEVENTFD
     int ret;
     struct kvm_ioeventfd iofd;
 
@@ -1353,14 +1352,10 @@ int kvm_set_ioeventfd_mmio_long(int fd, uint32_t addr, uint32_t val, bool assign
     }
 
     return 0;
-#else
-    return -ENOSYS;
-#endif
 }
 
 int kvm_set_ioeventfd_pio_word(int fd, uint16_t addr, uint16_t val, bool assign)
 {
-#ifdef KVM_IOEVENTFD
     struct kvm_ioeventfd kick = {
         .datamatch = val,
         .addr = addr,
@@ -1380,9 +1375,6 @@ int kvm_set_ioeventfd_pio_word(int fd, uint16_t addr, uint16_t val, bool assign)
         return r;
     }
     return 0;
-#else
-    return -ENOSYS;
-#endif
 }
 
 int kvm_on_sigbus_vcpu(CPUState *env, int code, void *addr)
Signature · 1 line
1.7.5.4
#4 lore raw

PATCH 4/6 qemu-x86: Add tsc_freq option to -cpu

In reply to Marcelo Tosatti

From: Joerg Roedel <[email protected]>

To let the user configure the desired tsc frequency for the guest if running in KVM.

---
 target-i386/cpu.h   |    1 +
 target-i386/cpuid.c |   13 +++++++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)
target-i386/cpu.h +1 -0
index dd6c5fa..dcdd95f 100644
@@ -743,6 +743,7 @@ typedef struct CPUX86State {
     uint32_t cpuid_kvm_features;
     uint32_t cpuid_svm_features;
     bool tsc_valid;
+    int tsc_khz;
     
     /* in order to simplify APIC support, we leave this pointer to the
        user */
target-i386/cpuid.c +13 -0
index e1ae3af..89e9623 100644
@@ -224,6 +224,7 @@ typedef struct x86_def_t {
     int family;
     int model;
     int stepping;
+    int tsc_khz;
     uint32_t features, ext_features, ext2_features, ext3_features;
     uint32_t kvm_features, svm_features;
     uint32_t xlevel;
@@ -704,6 +705,17 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
             } else if (!strcmp(featurestr, "model_id")) {
                 pstrcpy(x86_cpu_def->model_id, sizeof(x86_cpu_def->model_id),
                         val);
+            } else if (!strcmp(featurestr, "tsc_freq")) {
+                int64_t tsc_freq;
+                char *err;
+
+                tsc_freq = strtosz_suffix_unit(val, &err,
+                                               STRTOSZ_DEFSUFFIX_B, 1000);
+                if (!*val || *err) {
+                    fprintf(stderr, "bad numerical value %s\n", val);
+                    goto error;
+                }
+                x86_cpu_def->tsc_khz = tsc_freq / 1000;
             } else {
                 fprintf(stderr, "unrecognized feature %s\n", featurestr);
                 goto error;
@@ -872,6 +884,7 @@ int cpu_x86_register (CPUX86State *env, const char *cpu_model)
     env->cpuid_svm_features = def->svm_features;
     env->cpuid_ext4_features = def->ext4_features;
     env->cpuid_xlevel2 = def->xlevel2;
+    env->tsc_khz = def->tsc_khz;
     if (!kvm_enabled()) {
         env->cpuid_features &= TCG_FEATURES;
         env->cpuid_ext_features &= TCG_EXT_FEATURES;
Signature · 1 line
1.7.5.4
#3 lore raw

PATCH 3/6 qemu: Add strtosz_suffix_unit function

In reply to Marcelo Tosatti

From: Joerg Roedel <[email protected]>

This function does the same as the strtosz_suffix function except that it allows to specify the unit to which the k/M/B/T suffixes apply. This function will be used later to parse the tsc-frequency from the command-line.

---
 cutils.c      |   16 +++++++++++-----
 qemu-common.h |    2 ++
 2 files changed, 13 insertions(+), 5 deletions(-)
cutils.c +11 -5
index f9a7e36..28049e0 100644
@@ -322,7 +322,8 @@ int fcntl_setfl(int fd, int flag)
  * value must be terminated by whitespace, ',' or '\0'. Return -1 on
  * error.
  */
-int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
+int64_t strtosz_suffix_unit(const char *nptr, char **end,
+                            const char default_suffix, int64_t unit)
 {
     int64_t retval = -1;
     char *endptr;
@@ -362,20 +363,20 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
         }
         break;
     case STRTOSZ_DEFSUFFIX_KB:
-        mul = 1 << 10;
+        mul = unit;
         break;
     case 0:
         if (mul_required) {
             goto fail;
         }
     case STRTOSZ_DEFSUFFIX_MB:
-        mul = 1ULL << 20;
+        mul = unit * unit;
         break;
     case STRTOSZ_DEFSUFFIX_GB:
-        mul = 1ULL << 30;
+        mul = unit * unit * unit;
         break;
     case STRTOSZ_DEFSUFFIX_TB:
-        mul = 1ULL << 40;
+        mul = unit * unit * unit * unit;
         break;
     default:
         goto fail;
@@ -405,6 +406,11 @@ fail:
     return retval;
 }
 
+int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
+{
+        return strtosz_suffix_unit(nptr, end, default_suffix, 1024);
+}
+
 int64_t strtosz(const char *nptr, char **end)
 {
     return strtosz_suffix(nptr, end, STRTOSZ_DEFSUFFIX_MB);
qemu-common.h +2 -0
index afbd04d..389f4d2 100644
@@ -157,6 +157,8 @@ int fcntl_setfl(int fd, int flag);
 #define STRTOSZ_DEFSUFFIX_B	'B'
 int64_t strtosz(const char *nptr, char **end);
 int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix);
+int64_t strtosz_suffix_unit(const char *nptr, char **end,
+                            const char default_suffix, int64_t unit);
 
 /* path.c */
 void init_paths(const char *prefix);
Signature · 1 line
1.7.5.4
#5 lore raw

PATCH 5/6 qemu-x86: Set tsc_khz in kvm when supported

In reply to Marcelo Tosatti

From: Joerg Roedel <[email protected]>

Make use of the KVM_TSC_CONTROL feature if available.

---
 target-i386/kvm.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
target-i386/kvm.c +17 -1
index 10fb2c4..923d2d5 100644
@@ -354,6 +354,7 @@ int kvm_arch_init_vcpu(CPUState *env)
     uint32_t unused;
     struct kvm_cpuid_entry2 *c;
     uint32_t signature[3];
+    int r;
 
     env->cpuid_features &= kvm_arch_get_supported_cpuid(s, 1, 0, R_EDX);
 
@@ -499,7 +500,22 @@ int kvm_arch_init_vcpu(CPUState *env)
 
     qemu_add_vm_change_state_handler(cpu_update_state, env);
 
-    return kvm_vcpu_ioctl(env, KVM_SET_CPUID2, &cpuid_data);
+    r = kvm_vcpu_ioctl(env, KVM_SET_CPUID2, &cpuid_data);
+    if (r)
+	    return r;
+
+#ifdef KVM_CAP_TSC_CONTROL
+    r = kvm_check_extension(env->kvm_state, KVM_CAP_TSC_CONTROL);
+    if (r && env->tsc_khz) {
+        r = kvm_vcpu_ioctl(env, KVM_SET_TSC_KHZ, env->tsc_khz);
+        if (r < 0) {
+            fprintf(stderr, "KVM_SET_TSC_KHZ failed\n");
+            return r;
+        }
+    }
+#endif
+
+    return 0;
 }
 
 void kvm_arch_reset_vcpu(CPUState *env)
Signature · 1 line
1.7.5.4
#0 lore raw

The following changes since commit 35d7ace74bd07e3d6983c1fd7cbfab4e11175689:

qcow2: Fix L1 table size after bdrv_snapshot_goto (2011-08-05 07:15:47 -0500)

are available in the git repository at:
git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git uq/master

Jan Kiszka (2):
kvmclock: Fix feature detection
kvm: Drop obsolete KVM_IOEVENTFD #ifdefs

Joerg Roedel (3):
qemu: Add strtosz_suffix_unit function
qemu-x86: Add tsc_freq option to -cpu
qemu-x86: Set tsc_khz in kvm when supported

Marcelo Tosatti (1):
Remove #ifdef KVM_CAP_TSC_CONTROL

 cutils.c            |   16 +++++++++++-----
 hw/kvmclock.c       |    7 ++-----
 kvm-all.c           |    8 --------
 qemu-common.h       |    2 ++
 target-i386/cpu.h   |    1 +
 target-i386/cpuid.c |   13 +++++++++++++
 target-i386/kvm.c   |   16 +++++++++++++++-
 7 files changed, 44 insertions(+), 19 deletions(-)
#6 lore raw

Re: [PATCH 5/6] qemu-x86: Set tsc_khz in kvm when supported

In reply to Marcelo Tosatti
Quoted 23 lines · Marcelo Tosatti

From: Joerg Roedel <[email protected]>

Make use of the KVM_TSC_CONTROL feature if available.

---
 target-i386/kvm.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
target-i386/kvm.c +1 -0
index 10fb2c4..923d2d5 100644
@@ -354,6 +354,7 @@ int kvm_arch_init_vcpu(CPUState *env)
     uint32_t unused;
     struct kvm_cpuid_entry2 *c;
     uint32_t signature[3];
+    int r;
 
     env->cpuid_features &= kvm_arch_get_supported_cpuid(s, 1, 0, R_EDX);
 

target-i386/kvm.c int kvm_arch_init_vcpu(CPUState *env) · line 505

Quoted 7 lines
target-i386/kvm.c +3 -1
@@ -499,7 +500,22 @@ int kvm_arch_init_vcpu(CPUState *env)
 
     qemu_add_vm_change_state_handler(cpu_update_state, env);
 
-    return kvm_vcpu_ioctl(env, KVM_SET_CPUID2, &cpuid_data);
+    r = kvm_vcpu_ioctl(env, KVM_SET_CPUID2, &cpuid_data);
+    if (r)
+	    return r;

Coding style...

Jan

#8 lore raw
In reply to Marcelo Tosatti
Quoted 6 lines · Marcelo Tosatti

The following changes since commit 35d7ace74bd07e3d6983c1fd7cbfab4e11175689:

   qcow2: Fix L1 table size after bdrv_snapshot_goto (2011-08-05 07:15:47 -0500)

are available in the git repository at:
git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git uq/master

Pulled. Thanks.

Regards,

Anthony Liguori

Quoted 23 lines

Jan Kiszka (2):
kvmclock: Fix feature detection
kvm: Drop obsolete KVM_IOEVENTFD #ifdefs

Joerg Roedel (3):
qemu: Add strtosz_suffix_unit function
qemu-x86: Add tsc_freq option to -cpu
qemu-x86: Set tsc_khz in kvm when supported

Marcelo Tosatti (1):
Remove #ifdef KVM_CAP_TSC_CONTROL

  cutils.c            |   16 +++++++++++-----
  hw/kvmclock.c       |    7 ++-----
  kvm-all.c           |    8 --------
  qemu-common.h       |    2 ++
  target-i386/cpu.h   |    1 +
  target-i386/cpuid.c |   13 +++++++++++++
  target-i386/kvm.c   |   16 +++++++++++++++-
  7 files changed, 44 insertions(+), 19 deletions(-)