public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][UPDATE] shortcut for lightweight VM Exit
@ 2007-04-30  7:01 Dong, Eddie
       [not found] ` <10EA09EFD8728347A513008B6B0DA77A015EDDA8-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Dong, Eddie @ 2007-04-30  7:01 UTC (permalink / raw)
  To: kvm-devel


[-- Attachment #1.1: Type: text/plain, Size: 4131 bytes --]

This patch provides short cut handling for light weight VM Exit, which
can boost KB performance 11% under FC5 guest. 
 
Any comments?
Thx,eddie
 
 
Signed-off-by:  Yaozu(Eddie) Dong Eddie.Dong-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

 
 
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 41634fd..11eb25e 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -251,6 +251,7 @@ struct kvm_stat {
  u32 halt_exits;
  u32 request_irq_exits;
  u32 irq_exits;
+ u32 light_exits;
 };
 
 struct kvm_vcpu {
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 4c5b8db..0945c7f 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -71,6 +71,7 @@ static struct kvm_stats_debugfs_item {
  { "halt_exits", STAT_OFFSET(halt_exits) },
  { "request_irq", STAT_OFFSET(request_irq_exits) },
  { "irq_exits", STAT_OFFSET(irq_exits) },
+ { "light_exits", STAT_OFFSET(light_exits) },
  { NULL }
 };
 
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 74d058e..c279326 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -1815,7 +1815,6 @@ static int vmx_vcpu_run(struct kvm_vcpu *vcpu,
struct kvm_run *kvm_run)
  int fs_gs_ldt_reload_needed;
  int r;
 
-again:
  /*
   * Set host fs and gs selectors.  Unfortunately, 22.2.3 does not
   * allow segment selectors with cpl > 0 or ti == 1.
@@ -1858,6 +1857,7 @@ again:
  }
 #endif
 
+again:
  asm (
   /* Store host registers */
   "pushf \n\t"
@@ -1977,6 +1977,47 @@ again:
   [cr2]"i"(offsetof(struct kvm_vcpu, cr2))
        : "cc", "memory" );
 
+ ++vcpu->stat.exits;
+
+ vcpu->interrupt_window_open =
(vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & 3) == 0;
+
+ asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
+
+ if (fail) {
+  kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
+  kvm_run->fail_entry.hardware_entry_failure_reason
+   = vmcs_read32(VM_INSTRUCTION_ERROR);
+  r = 0;
+ } else {
+  /*
+   * Profile KVM exit RIPs:
+   */
+  if (unlikely(prof_on == KVM_PROFILING))
+   profile_hit(KVM_PROFILING, (void *)vmcs_readl(GUEST_RIP));
+
+  vcpu->launched = 1;
+  r = kvm_handle_exit(kvm_run, vcpu);
+  if (r > 0) {
+   r = -EINTR;
+   kvm_run->exit_reason = KVM_EXIT_INTR;
+   /* Give scheduler a change to reschedule. */
+   if (signal_pending(current)) {
+    ++vcpu->stat.signal_exits;
+    goto out;
+   }
+
+   if (dm_request_for_irq_injection(vcpu, kvm_run)) {
+    ++vcpu->stat.request_irq_exits;
+    goto out;
+   }
+   if (!need_resched()) {
+    ++vcpu->stat.light_exits;
+    goto again;
+   }
+  }
+ }
+
+out:
  /*
   * Reload segment selectors ASAP. (it's needed for a functional
   * kernel: x86 relies on having __KERNEL_PDA in %fs and x86_64
@@ -1998,8 +2039,6 @@ again:
 
   reload_tss();
  }
- ++vcpu->stat.exits;
-
 #ifdef CONFIG_X86_64
  if (is_long_mode(vcpu)) {
   save_msrs(vcpu->guest_msrs, NR_BAD_MSRS);
@@ -2012,45 +2051,6 @@ again:
   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));
-
- if (fail) {
-  kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
-  kvm_run->fail_entry.hardware_entry_failure_reason
-   = vmcs_read32(VM_INSTRUCTION_ERROR);
-  r = 0;
- } else {
-  /*
-   * Profile KVM exit RIPs:
-   */
-  if (unlikely(prof_on == KVM_PROFILING))
-   profile_hit(KVM_PROFILING, (void *)vmcs_readl(GUEST_RIP));
-
-  vcpu->launched = 1;
-  r = kvm_handle_exit(kvm_run, vcpu);
-  if (r > 0) {
-   /* Give scheduler a change to reschedule. */
-   if (signal_pending(current)) {
-    ++vcpu->stat.signal_exits;
-    post_kvm_run_save(vcpu, kvm_run);
-    kvm_run->exit_reason = KVM_EXIT_INTR;
-    return -EINTR;
-   }
-
-   if (dm_request_for_irq_injection(vcpu, kvm_run)) {
-    ++vcpu->stat.request_irq_exits;
-    post_kvm_run_save(vcpu, kvm_run);
-    kvm_run->exit_reason = KVM_EXIT_INTR;
-    return -EINTR;
-   }
-
-   kvm_resched(vcpu);
-   goto again;
-  }
- }
-
  post_kvm_run_save(vcpu, kvm_run);
  return r;
 }


[-- Attachment #1.2: Type: text/html, Size: 6824 bytes --]

[-- Attachment #2: lightweight3.patch --]
[-- Type: application/octet-stream, Size: 3730 bytes --]

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 41634fd..11eb25e 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -251,6 +251,7 @@ struct kvm_stat {
 	u32 halt_exits;
 	u32 request_irq_exits;
 	u32 irq_exits;
+	u32 light_exits;
 };
 
 struct kvm_vcpu {
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 4c5b8db..0945c7f 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -71,6 +71,7 @@ static struct kvm_stats_debugfs_item {
 	{ "halt_exits", STAT_OFFSET(halt_exits) },
 	{ "request_irq", STAT_OFFSET(request_irq_exits) },
 	{ "irq_exits", STAT_OFFSET(irq_exits) },
+	{ "light_exits", STAT_OFFSET(light_exits) },
 	{ NULL }
 };
 
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 74d058e..c279326 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -1815,7 +1815,6 @@ static int vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 	int fs_gs_ldt_reload_needed;
 	int r;
 
-again:
 	/*
 	 * Set host fs and gs selectors.  Unfortunately, 22.2.3 does not
 	 * allow segment selectors with cpl > 0 or ti == 1.
@@ -1858,6 +1857,7 @@ again:
 	}
 #endif
 
+again:
 	asm (
 		/* Store host registers */
 		"pushf \n\t"
@@ -1977,6 +1977,47 @@ again:
 		[cr2]"i"(offsetof(struct kvm_vcpu, cr2))
 	      : "cc", "memory" );
 
+	++vcpu->stat.exits;
+
+	vcpu->interrupt_window_open = (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & 3) == 0;
+
+	asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
+
+	if (fail) {
+		kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
+		kvm_run->fail_entry.hardware_entry_failure_reason
+			= vmcs_read32(VM_INSTRUCTION_ERROR);
+		r = 0;
+	} else {
+		/*
+		 * Profile KVM exit RIPs:
+		 */
+		if (unlikely(prof_on == KVM_PROFILING))
+			profile_hit(KVM_PROFILING, (void *)vmcs_readl(GUEST_RIP));
+
+		vcpu->launched = 1;
+		r = kvm_handle_exit(kvm_run, vcpu);
+		if (r > 0) {
+			r = -EINTR;
+			kvm_run->exit_reason = KVM_EXIT_INTR;
+			/* Give scheduler a change to reschedule. */
+			if (signal_pending(current)) {
+				++vcpu->stat.signal_exits;
+				goto out;
+			}
+
+			if (dm_request_for_irq_injection(vcpu, kvm_run)) {
+				++vcpu->stat.request_irq_exits;
+				goto out;
+			}
+			if (!need_resched()) {
+				++vcpu->stat.light_exits;
+				goto again;
+			}
+		}
+	}
+
+out:
 	/*
 	 * Reload segment selectors ASAP. (it's needed for a functional
 	 * kernel: x86 relies on having __KERNEL_PDA in %fs and x86_64
@@ -1998,8 +2039,6 @@ again:
 
 		reload_tss();
 	}
-	++vcpu->stat.exits;
-
 #ifdef CONFIG_X86_64
 	if (is_long_mode(vcpu)) {
 		save_msrs(vcpu->guest_msrs, NR_BAD_MSRS);
@@ -2012,45 +2051,6 @@ again:
 		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));
-
-	if (fail) {
-		kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
-		kvm_run->fail_entry.hardware_entry_failure_reason
-			= vmcs_read32(VM_INSTRUCTION_ERROR);
-		r = 0;
-	} else {
-		/*
-		 * Profile KVM exit RIPs:
-		 */
-		if (unlikely(prof_on == KVM_PROFILING))
-			profile_hit(KVM_PROFILING, (void *)vmcs_readl(GUEST_RIP));
-
-		vcpu->launched = 1;
-		r = kvm_handle_exit(kvm_run, vcpu);
-		if (r > 0) {
-			/* Give scheduler a change to reschedule. */
-			if (signal_pending(current)) {
-				++vcpu->stat.signal_exits;
-				post_kvm_run_save(vcpu, kvm_run);
-				kvm_run->exit_reason = KVM_EXIT_INTR;
-				return -EINTR;
-			}
-
-			if (dm_request_for_irq_injection(vcpu, kvm_run)) {
-				++vcpu->stat.request_irq_exits;
-				post_kvm_run_save(vcpu, kvm_run);
-				kvm_run->exit_reason = KVM_EXIT_INTR;
-				return -EINTR;
-			}
-
-			kvm_resched(vcpu);
-			goto again;
-		}
-	}
-
 	post_kvm_run_save(vcpu, kvm_run);
 	return r;
 }

[-- Attachment #3: Type: text/plain, Size: 286 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

[-- 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

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

end of thread, other threads:[~2007-05-08 11:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-30  7:01 [PATCH][UPDATE] shortcut for lightweight VM Exit Dong, Eddie
     [not found] ` <10EA09EFD8728347A513008B6B0DA77A015EDDA8-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-04-30  7:49   ` Avi Kivity
     [not found]     ` <46359F90.9010306-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-04-30 11:23       ` Dong, Eddie
     [not found]         ` <10EA09EFD8728347A513008B6B0DA77A015EDE49-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-04-30 13:10           ` Avi Kivity
     [not found]             ` <4635EAD7.1030405-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-08  5:08               ` Dong, Eddie
2007-05-08  9:59           ` [PATCH][UPDATE] Shortcut MSR save/restore for lightweight VM Exit (was: RE: shortcut for lightweight VM Exit) Dong, Eddie
     [not found]             ` <10EA09EFD8728347A513008B6B0DA77A0165CEA9-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-05-08 11:15               ` [PATCH][UPDATE] Shortcut MSR save/restore for lightweight VM Exit Avi Kivity
     [not found]                 ` <46405BC6.1030001-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-08 11:51                   ` Dong, Eddie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox