From: Anthony Liguori <anthony-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
To: kvm-devel
<kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Subject: [PATCH] Lazy FPU save/restore
Date: Thu, 15 Feb 2007 19:02:25 -0600 [thread overview]
Message-ID: <45D502A1.5000303@codemonkey.ws> (raw)
[-- Attachment #1: Type: text/plain, Size: 642 bytes --]
The following patch saves the host FPU state and loads the guests FPU
state if !(CR0.MP == 1 && CR0.TS == 1).
When CR0.MP == 1 && CR0.TS == 1, all FPU activity will generate
exceptions. OS's use these exceptions to implement lazy FPU loading to
improve context switch time. Since any FPU activity will generate
traps, we don't have to worry about the guest modifying the host FPU state.
My microbenchmark of choice uses FPU operations so I think the results
are currently tainted. I've only tested on a 32bit SVM system.
Signed-off-by: Anthony Liguori <anthony-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
Regards,
Anthony Liguori
[-- Attachment #2: lazy-fpu.diff --]
[-- Type: text/x-patch, Size: 2767 bytes --]
diff -r 962b18bbd6d9 kernel/kvm.h
--- a/kernel/kvm.h Thu Feb 15 13:58:59 2007 +0000
+++ b/kernel/kvm.h Thu Feb 15 13:23:56 2007 -0600
@@ -17,6 +17,7 @@
#include <linux/kvm_para.h>
#define CR0_PE_MASK (1ULL << 0)
+#define CR0_MP_MASK (1ULL << 1)
#define CR0_TS_MASK (1ULL << 3)
#define CR0_NE_MASK (1ULL << 5)
#define CR0_WP_MASK (1ULL << 16)
@@ -263,6 +264,7 @@ struct kvm_vcpu {
struct kvm_guest_debug guest_debug;
+ int fx_active;
char fx_buf[FX_BUF_SIZE];
char *host_fx_image;
char *guest_fx_image;
diff -r 962b18bbd6d9 kernel/kvm_main.c
--- a/kernel/kvm_main.c Thu Feb 15 13:58:59 2007 +0000
+++ b/kernel/kvm_main.c Thu Feb 15 13:27:17 2007 -0600
@@ -404,6 +404,7 @@ void set_cr0(struct kvm_vcpu *vcpu, unsi
}
+ vcpu->fx_active = !((cr0 & CR0_TS_MASK) && (cr0 & CR0_MP_MASK));
kvm_arch_ops->set_cr0(vcpu, cr0);
vcpu->cr0 = cr0;
@@ -530,6 +531,7 @@ void fx_init(struct kvm_vcpu *vcpu)
fx_image->mxcsr = 0x1f80;
memset(vcpu->guest_fx_image + sizeof(struct fx_image_s),
0, FX_IMAGE_SIZE - sizeof(struct fx_image_s));
+ vcpu->fx_active = 1;
}
EXPORT_SYMBOL_GPL(fx_init);
diff -r 962b18bbd6d9 kernel/svm.c
--- a/kernel/svm.c Thu Feb 15 13:58:59 2007 +0000
+++ b/kernel/svm.c Thu Feb 15 13:30:52 2007 -0600
@@ -1461,8 +1461,10 @@ again:
load_db_regs(vcpu->svm->db_regs);
}
- fx_save(vcpu->host_fx_image);
- fx_restore(vcpu->guest_fx_image);
+ if (vcpu->fx_active) {
+ fx_save(vcpu->host_fx_image);
+ fx_restore(vcpu->guest_fx_image);
+ }
asm volatile (
#ifdef CONFIG_X86_64
@@ -1573,8 +1575,10 @@ again:
#endif
: "cc", "memory" );
- fx_save(vcpu->guest_fx_image);
- fx_restore(vcpu->host_fx_image);
+ if (vcpu->fx_active) {
+ fx_save(vcpu->guest_fx_image);
+ fx_restore(vcpu->host_fx_image);
+ }
if ((vcpu->svm->vmcb->save.dr7 & 0xff))
load_db_regs(vcpu->svm->host_db_regs);
diff -r 962b18bbd6d9 kernel/vmx.c
--- a/kernel/vmx.c Thu Feb 15 13:58:59 2007 +0000
+++ b/kernel/vmx.c Thu Feb 15 13:30:20 2007 -0600
@@ -1764,8 +1764,10 @@ again:
if (vcpu->guest_debug.enabled)
kvm_guest_debug_pre(vcpu);
- fx_save(vcpu->host_fx_image);
- fx_restore(vcpu->guest_fx_image);
+ if (vcpu->fx_active) {
+ fx_save(vcpu->host_fx_image);
+ fx_restore(vcpu->guest_fx_image);
+ }
save_msrs(vcpu->host_msrs, vcpu->nmsrs);
load_msrs(vcpu->guest_msrs, NR_BAD_MSRS);
@@ -1894,8 +1896,11 @@ again:
save_msrs(vcpu->guest_msrs, NR_BAD_MSRS);
load_msrs(vcpu->host_msrs, NR_BAD_MSRS);
- fx_save(vcpu->guest_fx_image);
- fx_restore(vcpu->host_fx_image);
+ if (vcpu->fx_active) {
+ fx_save(vcpu->guest_fx_image);
+ fx_restore(vcpu->host_fx_image);
+ }
+
vcpu->interrupt_window_open = (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & 3) == 0;
asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
[-- Attachment #3: Type: text/plain, Size: 345 bytes --]
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
[-- Attachment #4: Type: text/plain, Size: 186 bytes --]
_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel
next reply other threads:[~2007-02-16 1:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-16 1:02 Anthony Liguori [this message]
[not found] ` <45D502A1.5000303-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2007-02-16 3:23 ` [PATCH] Lazy FPU save/restore Rusty Russell
2007-02-18 9:39 ` Avi Kivity
[not found] ` <45D81EB6.9010407-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-02-18 14:25 ` Avi Kivity
[not found] ` <45D861CD.4020207-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-02-18 16:13 ` Anthony Liguori
[not found] ` <45D87B22.6070403-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2007-02-18 16:17 ` Avi Kivity
[not found] ` <45D87C2E.2090806-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-02-18 18:21 ` Avi Kivity
[not found] ` <45D89917.9090003-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-02-18 22:55 ` Anthony Liguori
[not found] ` <45D8D96B.50104-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2007-02-19 8:13 ` Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45D502A1.5000303@codemonkey.ws \
--to=anthony-rdkfgonbjusknkdkm+me6a@public.gmane.org \
--cc=avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox