* [PATCH 0/2] Initial TSC-Scaling support for uq/master
@ 2011-06-17 14:00 ` Joerg Roedel
0 siblings, 0 replies; 8+ messages in thread
From: Joerg Roedel @ 2011-06-17 14:00 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, qemu-devel, Anthony Liguori
Hi,
these two patches implement initial tsc-scaling support for qemu. The
TSC frequency for the guest can be configured with -cpu ,tsc_khz=x. If
supported by the kernel module qemu will pass the frequency to KVM. The
patches apply against current uq/master branch.
Regards,
Joerg
Diffstat:
target-i386/cpu.h | 1 +
target-i386/cpuid.c | 10 ++++++++++
target-i386/kvm.c | 11 +++++++++++
3 files changed, 22 insertions(+), 0 deletions(-)
Shortlog:
Joerg Roedel (2):
qemu-x86: Add tsc_khz option to -cpu
qemu-x86: Set tsc_khz in kvm when supported
^ permalink raw reply [flat|nested] 8+ messages in thread* [Qemu-devel] [PATCH 0/2] Initial TSC-Scaling support for uq/master @ 2011-06-17 14:00 ` Joerg Roedel 0 siblings, 0 replies; 8+ messages in thread From: Joerg Roedel @ 2011-06-17 14:00 UTC (permalink / raw) To: Avi Kivity, Marcelo Tosatti; +Cc: Anthony Liguori, qemu-devel, kvm Hi, these two patches implement initial tsc-scaling support for qemu. The TSC frequency for the guest can be configured with -cpu ,tsc_khz=x. If supported by the kernel module qemu will pass the frequency to KVM. The patches apply against current uq/master branch. Regards, Joerg Diffstat: target-i386/cpu.h | 1 + target-i386/cpuid.c | 10 ++++++++++ target-i386/kvm.c | 11 +++++++++++ 3 files changed, 22 insertions(+), 0 deletions(-) Shortlog: Joerg Roedel (2): qemu-x86: Add tsc_khz option to -cpu qemu-x86: Set tsc_khz in kvm when supported ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] qemu-x86: Add tsc_khz option to -cpu 2011-06-17 14:00 ` [Qemu-devel] " Joerg Roedel @ 2011-06-17 14:00 ` Joerg Roedel -1 siblings, 0 replies; 8+ messages in thread From: Joerg Roedel @ 2011-06-17 14:00 UTC (permalink / raw) To: Avi Kivity, Marcelo Tosatti Cc: kvm, qemu-devel, Anthony Liguori, Joerg Roedel To let the user configure the desired tsc frequency for the guest if running in KVM. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com> --- target-i386/cpu.h | 1 + target-i386/cpuid.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 0 deletions(-) diff --git a/target-i386/cpu.h b/target-i386/cpu.h index 0b039d4..a381c34 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -753,6 +753,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 */ diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c index 79e7580..2b59e66 100644 --- a/target-i386/cpuid.c +++ b/target-i386/cpuid.c @@ -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,14 @@ 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_khz")) { + char *err; + numvalue = strtoul(val, &err, 0); + if (!*val || *err) { + fprintf(stderr, "bad numerical value %s\n", val); + goto error; + } + x86_cpu_def->tsc_khz = numvalue; } else { fprintf(stderr, "unrecognized feature %s\n", featurestr); goto error; @@ -872,6 +881,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; -- 1.7.4.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH 1/2] qemu-x86: Add tsc_khz option to -cpu @ 2011-06-17 14:00 ` Joerg Roedel 0 siblings, 0 replies; 8+ messages in thread From: Joerg Roedel @ 2011-06-17 14:00 UTC (permalink / raw) To: Avi Kivity, Marcelo Tosatti Cc: Joerg Roedel, Anthony Liguori, qemu-devel, kvm To let the user configure the desired tsc frequency for the guest if running in KVM. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com> --- target-i386/cpu.h | 1 + target-i386/cpuid.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 0 deletions(-) diff --git a/target-i386/cpu.h b/target-i386/cpu.h index 0b039d4..a381c34 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -753,6 +753,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 */ diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c index 79e7580..2b59e66 100644 --- a/target-i386/cpuid.c +++ b/target-i386/cpuid.c @@ -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,14 @@ 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_khz")) { + char *err; + numvalue = strtoul(val, &err, 0); + if (!*val || *err) { + fprintf(stderr, "bad numerical value %s\n", val); + goto error; + } + x86_cpu_def->tsc_khz = numvalue; } else { fprintf(stderr, "unrecognized feature %s\n", featurestr); goto error; @@ -872,6 +881,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; -- 1.7.4.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] qemu-x86: Add tsc_khz option to -cpu 2011-06-17 14:00 ` [Qemu-devel] " Joerg Roedel @ 2011-06-19 11:32 ` Avi Kivity -1 siblings, 0 replies; 8+ messages in thread From: Avi Kivity @ 2011-06-19 11:32 UTC (permalink / raw) To: Joerg Roedel; +Cc: Marcelo Tosatti, kvm, qemu-devel, Anthony Liguori On 06/17/2011 05:00 PM, Joerg Roedel wrote: > To let the user configure the desired tsc frequency for the > guest if running in KVM. > > @@ -704,6 +705,14 @@ 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_khz")) { > + char *err; > + numvalue = strtoul(val,&err, 0); > + if (!*val || *err) { > + fprintf(stderr, "bad numerical value %s\n", val); > + goto error; > + } > + x86_cpu_def->tsc_khz = numvalue; > } else { > fprintf(stderr, "unrecognized feature %s\n", featurestr); > goto error; Frequency should be in Hz, not kHz. We can use [kMG] suffixes for simpler specification (but 1GHz = 10^9 Hz, not the binary thing). -- error compiling committee.c: too many arguments to function ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH 1/2] qemu-x86: Add tsc_khz option to -cpu @ 2011-06-19 11:32 ` Avi Kivity 0 siblings, 0 replies; 8+ messages in thread From: Avi Kivity @ 2011-06-19 11:32 UTC (permalink / raw) To: Joerg Roedel; +Cc: Anthony Liguori, Marcelo Tosatti, qemu-devel, kvm On 06/17/2011 05:00 PM, Joerg Roedel wrote: > To let the user configure the desired tsc frequency for the > guest if running in KVM. > > @@ -704,6 +705,14 @@ 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_khz")) { > + char *err; > + numvalue = strtoul(val,&err, 0); > + if (!*val || *err) { > + fprintf(stderr, "bad numerical value %s\n", val); > + goto error; > + } > + x86_cpu_def->tsc_khz = numvalue; > } else { > fprintf(stderr, "unrecognized feature %s\n", featurestr); > goto error; Frequency should be in Hz, not kHz. We can use [kMG] suffixes for simpler specification (but 1GHz = 10^9 Hz, not the binary thing). -- error compiling committee.c: too many arguments to function ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] qemu-x86: Set tsc_khz in kvm when supported 2011-06-17 14:00 ` [Qemu-devel] " Joerg Roedel @ 2011-06-17 14:00 ` Joerg Roedel -1 siblings, 0 replies; 8+ messages in thread From: Joerg Roedel @ 2011-06-17 14:00 UTC (permalink / raw) To: Avi Kivity, Marcelo Tosatti Cc: kvm, qemu-devel, Anthony Liguori, Joerg Roedel Make use of the KVM_TSC_CONTROL feature if available. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com> --- target-i386/kvm.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 1ae2d61..2d89544 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -528,6 +528,17 @@ int kvm_arch_init_vcpu(CPUState *env) } #endif +#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 + qemu_add_vm_change_state_handler(cpu_update_state, env); return kvm_vcpu_ioctl(env, KVM_SET_CPUID2, &cpuid_data); -- 1.7.4.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH 2/2] qemu-x86: Set tsc_khz in kvm when supported @ 2011-06-17 14:00 ` Joerg Roedel 0 siblings, 0 replies; 8+ messages in thread From: Joerg Roedel @ 2011-06-17 14:00 UTC (permalink / raw) To: Avi Kivity, Marcelo Tosatti Cc: Joerg Roedel, Anthony Liguori, qemu-devel, kvm Make use of the KVM_TSC_CONTROL feature if available. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com> --- target-i386/kvm.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 1ae2d61..2d89544 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -528,6 +528,17 @@ int kvm_arch_init_vcpu(CPUState *env) } #endif +#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 + qemu_add_vm_change_state_handler(cpu_update_state, env); return kvm_vcpu_ioctl(env, KVM_SET_CPUID2, &cpuid_data); -- 1.7.4.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2011-06-19 11:33 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-06-17 14:00 [PATCH 0/2] Initial TSC-Scaling support for uq/master Joerg Roedel 2011-06-17 14:00 ` [Qemu-devel] " Joerg Roedel 2011-06-17 14:00 ` [PATCH 1/2] qemu-x86: Add tsc_khz option to -cpu Joerg Roedel 2011-06-17 14:00 ` [Qemu-devel] " Joerg Roedel 2011-06-19 11:32 ` Avi Kivity 2011-06-19 11:32 ` [Qemu-devel] " Avi Kivity 2011-06-17 14:00 ` [PATCH 2/2] qemu-x86: Set tsc_khz in kvm when supported Joerg Roedel 2011-06-17 14:00 ` [Qemu-devel] " Joerg Roedel
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.