qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] hook cpu running at a higher level.


From: Glauber Costa
Subject: [Qemu-devel] [PATCH] hook cpu running at a higher level.
Date: Mon, 29 Dec 2008 13:29:22 -0500

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 <address@hidden>
---
 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]