* [PATCH][uq/master] kvm: x86: Avoid runtime allocation of xsave buffer
@ 2011-10-27 17:25 ` Jan Kiszka
0 siblings, 0 replies; 4+ messages in thread
From: Jan Kiszka @ 2011-10-27 17:25 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: qemu-devel, kvm
Keep a per-VCPU xsave buffer for kvm_put/get_xsave instead of
continuously allocating and freeing it on state sync.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
target-i386/cpu.h | 3 ++-
target-i386/kvm.c | 15 +++++++--------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index a08ce9d..37dde79 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -751,7 +751,8 @@ typedef struct CPUX86State {
uint32_t cpuid_svm_features;
bool tsc_valid;
int tsc_khz;
-
+ void *kvm_xsave_buf;
+
/* in order to simplify APIC support, we leave this pointer to the
user */
struct DeviceState *apic_state;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index ffd6488..23437ee 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -516,6 +516,10 @@ int kvm_arch_init_vcpu(CPUState *env)
}
}
+ if (kvm_has_xsave()) {
+ env->kvm_xsave_buf = qemu_memalign(4096, sizeof(struct kvm_xsave));
+ }
+
return 0;
}
@@ -769,15 +773,14 @@ static int kvm_put_fpu(CPUState *env)
static int kvm_put_xsave(CPUState *env)
{
- int i, r;
- struct kvm_xsave* xsave;
+ struct kvm_xsave* xsave = env->kvm_xsave_buf;
uint16_t cwd, swd, twd;
+ int i, r;
if (!kvm_has_xsave()) {
return kvm_put_fpu(env);
}
- xsave = qemu_memalign(4096, sizeof(struct kvm_xsave));
memset(xsave, 0, sizeof(struct kvm_xsave));
twd = 0;
swd = env->fpus & ~(7 << 11);
@@ -799,7 +802,6 @@ static int kvm_put_xsave(CPUState *env)
memcpy(&xsave->region[XSAVE_YMMH_SPACE], env->ymmh_regs,
sizeof env->ymmh_regs);
r = kvm_vcpu_ioctl(env, KVM_SET_XSAVE, xsave);
- g_free(xsave);
return r;
}
@@ -976,7 +978,7 @@ static int kvm_get_fpu(CPUState *env)
static int kvm_get_xsave(CPUState *env)
{
- struct kvm_xsave* xsave;
+ struct kvm_xsave* xsave = env->kvm_xsave_buf;
int ret, i;
uint16_t cwd, swd, twd;
@@ -984,10 +986,8 @@ static int kvm_get_xsave(CPUState *env)
return kvm_get_fpu(env);
}
- xsave = qemu_memalign(4096, sizeof(struct kvm_xsave));
ret = kvm_vcpu_ioctl(env, KVM_GET_XSAVE, xsave);
if (ret < 0) {
- g_free(xsave);
return ret;
}
@@ -1011,7 +1011,6 @@ static int kvm_get_xsave(CPUState *env)
env->xstate_bv = *(uint64_t *)&xsave->region[XSAVE_XSTATE_BV];
memcpy(env->ymmh_regs, &xsave->region[XSAVE_YMMH_SPACE],
sizeof env->ymmh_regs);
- g_free(xsave);
return 0;
}
--
1.7.3.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH][uq/master] kvm: x86: Avoid runtime allocation of xsave buffer
@ 2011-10-27 17:25 ` Jan Kiszka
0 siblings, 0 replies; 4+ messages in thread
From: Jan Kiszka @ 2011-10-27 17:25 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti; +Cc: qemu-devel, kvm
Keep a per-VCPU xsave buffer for kvm_put/get_xsave instead of
continuously allocating and freeing it on state sync.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
target-i386/cpu.h | 3 ++-
target-i386/kvm.c | 15 +++++++--------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index a08ce9d..37dde79 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -751,7 +751,8 @@ typedef struct CPUX86State {
uint32_t cpuid_svm_features;
bool tsc_valid;
int tsc_khz;
-
+ void *kvm_xsave_buf;
+
/* in order to simplify APIC support, we leave this pointer to the
user */
struct DeviceState *apic_state;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index ffd6488..23437ee 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -516,6 +516,10 @@ int kvm_arch_init_vcpu(CPUState *env)
}
}
+ if (kvm_has_xsave()) {
+ env->kvm_xsave_buf = qemu_memalign(4096, sizeof(struct kvm_xsave));
+ }
+
return 0;
}
@@ -769,15 +773,14 @@ static int kvm_put_fpu(CPUState *env)
static int kvm_put_xsave(CPUState *env)
{
- int i, r;
- struct kvm_xsave* xsave;
+ struct kvm_xsave* xsave = env->kvm_xsave_buf;
uint16_t cwd, swd, twd;
+ int i, r;
if (!kvm_has_xsave()) {
return kvm_put_fpu(env);
}
- xsave = qemu_memalign(4096, sizeof(struct kvm_xsave));
memset(xsave, 0, sizeof(struct kvm_xsave));
twd = 0;
swd = env->fpus & ~(7 << 11);
@@ -799,7 +802,6 @@ static int kvm_put_xsave(CPUState *env)
memcpy(&xsave->region[XSAVE_YMMH_SPACE], env->ymmh_regs,
sizeof env->ymmh_regs);
r = kvm_vcpu_ioctl(env, KVM_SET_XSAVE, xsave);
- g_free(xsave);
return r;
}
@@ -976,7 +978,7 @@ static int kvm_get_fpu(CPUState *env)
static int kvm_get_xsave(CPUState *env)
{
- struct kvm_xsave* xsave;
+ struct kvm_xsave* xsave = env->kvm_xsave_buf;
int ret, i;
uint16_t cwd, swd, twd;
@@ -984,10 +986,8 @@ static int kvm_get_xsave(CPUState *env)
return kvm_get_fpu(env);
}
- xsave = qemu_memalign(4096, sizeof(struct kvm_xsave));
ret = kvm_vcpu_ioctl(env, KVM_GET_XSAVE, xsave);
if (ret < 0) {
- g_free(xsave);
return ret;
}
@@ -1011,7 +1011,6 @@ static int kvm_get_xsave(CPUState *env)
env->xstate_bv = *(uint64_t *)&xsave->region[XSAVE_XSTATE_BV];
memcpy(env->ymmh_regs, &xsave->region[XSAVE_YMMH_SPACE],
sizeof env->ymmh_regs);
- g_free(xsave);
return 0;
}
--
1.7.3.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH][uq/master] kvm: x86: Avoid runtime allocation of xsave buffer
2011-10-27 17:25 ` [Qemu-devel] " Jan Kiszka
@ 2011-11-08 20:44 ` Marcelo Tosatti
-1 siblings, 0 replies; 4+ messages in thread
From: Marcelo Tosatti @ 2011-11-08 20:44 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Avi Kivity, kvm, qemu-devel
On Thu, Oct 27, 2011 at 07:25:58PM +0200, Jan Kiszka wrote:
> Keep a per-VCPU xsave buffer for kvm_put/get_xsave instead of
> continuously allocating and freeing it on state sync.
>
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
> target-i386/cpu.h | 3 ++-
> target-i386/kvm.c | 15 +++++++--------
> 2 files changed, 9 insertions(+), 9 deletions(-)
Applied both, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH][uq/master] kvm: x86: Avoid runtime allocation of xsave buffer
@ 2011-11-08 20:44 ` Marcelo Tosatti
0 siblings, 0 replies; 4+ messages in thread
From: Marcelo Tosatti @ 2011-11-08 20:44 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Avi Kivity, kvm, qemu-devel
On Thu, Oct 27, 2011 at 07:25:58PM +0200, Jan Kiszka wrote:
> Keep a per-VCPU xsave buffer for kvm_put/get_xsave instead of
> continuously allocating and freeing it on state sync.
>
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
> target-i386/cpu.h | 3 ++-
> target-i386/kvm.c | 15 +++++++--------
> 2 files changed, 9 insertions(+), 9 deletions(-)
Applied both, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-11-08 20:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-27 17:25 [PATCH][uq/master] kvm: x86: Avoid runtime allocation of xsave buffer Jan Kiszka
2011-10-27 17:25 ` [Qemu-devel] " Jan Kiszka
2011-11-08 20:44 ` Marcelo Tosatti
2011-11-08 20:44 ` [Qemu-devel] " Marcelo Tosatti
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.