qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] hook cpu running at a higher level.
@ 2008-12-29 18:29 Glauber Costa
  2008-12-30 10:24 ` [Qemu-devel] " Ian Jackson
  0 siblings, 1 reply; 8+ messages in thread
From: Glauber Costa @ 2008-12-29 18:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: Ian.Jackson, avi, kvm, stefano.stabellini

This patch removes the kvm_enabled() check from cpu-exec.c.
This file is highly tcg-specific, and we'll probably want it
out when tcg is not compiled in (coming soon, in a theathe near you)

Instead, we hook at the main loop level. The amount of code
duplication introduced is at worst, acceptable, and I believe
it pays. The tcg mainloop is likely to be different from the
hypervisors ones, since tcg runs all cpus in lockstep. KVM
(and probably xen), will be able to span threads out for its
vcpus.

Signed-off-by: Glauber Costa <glommer@redhat.com>
---
 cpu-exec.c |    5 -----
 kvm-all.c  |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c       |   16 ++++++++++------
 3 files changed, 60 insertions(+), 11 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index ed1545b..be8ceac 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -333,11 +333,6 @@ int cpu_exec(CPUState *env1)
             }
 #endif
 
-            if (kvm_enabled()) {
-                kvm_cpu_exec(env);
-                longjmp(env->jmp_env, 1);
-            }
-
             next_tb = 0; /* force lookup of first TB */
             for(;;) {
                 interrupt_request = env->interrupt_request;
diff --git a/kvm-all.c b/kvm-all.c
index 11034df..a279d6c 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -663,3 +663,53 @@ int kvm_has_sync_mmu(void)
 
     return 0;
 }
+
+extern CPUState *cur_cpu;
+extern CPUState *next_cpu;
+
+extern int reset_requested;
+extern int shutdown_requested;
+extern int powerdown_requested;
+
+int kvm_main_loop(void)
+{
+
+    int ret, timeout;
+    CPUState *env;
+
+    cur_cpu = first_cpu;
+    next_cpu = first_cpu;
+    env = first_cpu;
+
+    for(;;) {
+        /* get next cpu */
+        cpu_single_env = env;
+        ret = kvm_cpu_exec(env);
+        cpu_single_env = NULL;
+
+        if (shutdown_requested)
+            break;
+        if (reset_requested) {
+            reset_requested = 0;
+            qemu_system_reset();
+            ret = EXCP_INTERRUPT;
+        }
+        if (powerdown_requested) {
+            powerdown_requested = 0;
+            qemu_system_powerdown();
+            ret = EXCP_INTERRUPT;
+        }
+
+        if (ret == EXCP_HALTED) {
+            timeout = 5000;
+        } else {
+            timeout = 0;
+        }
+        
+        main_loop_wait(timeout);
+    }        
+    cpu_disable_ticks();
+    return ret;
+}
+
+
diff --git a/vl.c b/vl.c
index 0a02151..bcaccc3 100644
--- a/vl.c
+++ b/vl.c
@@ -248,8 +248,8 @@ static struct drive_opt {
     char opt[1024];
 } drives_opt[MAX_DRIVES];
 
-static CPUState *cur_cpu;
-static CPUState *next_cpu;
+CPUState *cur_cpu;
+CPUState *next_cpu;
 static int event_pending = 1;
 /* Conversion factor from emulated instructions to virtual clock ticks.  */
 static int icount_time_shift;
@@ -3452,9 +3452,9 @@ typedef struct QEMUResetEntry {
 } QEMUResetEntry;
 
 static QEMUResetEntry *first_reset_entry;
-static int reset_requested;
-static int shutdown_requested;
-static int powerdown_requested;
+int reset_requested;
+int shutdown_requested;
+int powerdown_requested;
 
 int qemu_shutdown_requested(void)
 {
@@ -5535,7 +5535,11 @@ int main(int argc, char **argv, char **envp)
 	close(fd);
     }
 
-    main_loop();
+    if (kvm_enabled())
+        kvm_main_loop();
+    else
+        main_loop();
+
     quit_timers();
     net_cleanup();
 
-- 
1.5.6.5

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

end of thread, other threads:[~2008-12-30 17:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-29 18:29 [Qemu-devel] [PATCH] hook cpu running at a higher level Glauber Costa
2008-12-30 10:24 ` [Qemu-devel] " Ian Jackson
2008-12-30 10:44   ` Avi Kivity
2008-12-30 13:45     ` Ian Jackson
2008-12-30 11:35   ` Glauber Costa
2008-12-30 17:25     ` Ian Jackson
2008-12-30 13:54   ` Avi Kivity
2008-12-30 14:44     ` Ian Jackson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).