This patch introduces QEMUAccel, a placeholder for function pointers
that aims at helping qemu to abstract accelerators such as kqemu and
kvm (actually, the 'accelerator' name was proposed by avi kivity, since
he loves referring to kvm that way).

To begin with, the accelerator is given the opportunity to register a
cpu_interrupt function, to be called after the raw cpu_interrupt.
This has the side effect of, for the kqemu accelerator, calling 
kqemu_cpu_interrupt
everytime, which didn't use to happen. But looking at the code, this seems safe 
to me.

This patch applies on raw qemu.
---
 block-raw-posix.c |    5 -----
 exec-all.h        |   18 +++++++++++++++++-
 exec.c            |    2 ++
 kqemu.c           |   27 +++++++++++++++++----------
 vl.c              |    6 +-----
 5 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/block-raw-posix.c b/block-raw-posix.c
index 6b0009e..61c23ba 100644
--- a/block-raw-posix.c
+++ b/block-raw-posix.c
@@ -250,11 +250,6 @@ static void aio_signal_handler(int signum)
     if (env) {
         /* stop the currently executing cpu because a timer occured */
         cpu_interrupt(env, CPU_INTERRUPT_EXIT);
-#ifdef USE_KQEMU
-        if (env->kqemu_enabled) {
-            kqemu_cpu_interrupt(env);
-        }
-#endif
     }
 #endif
 }
diff --git a/exec-all.h b/exec-all.h
index 8c32858..7b2d97d 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -578,6 +578,23 @@ static inline target_ulong get_phys_addr_code(CPUState 
*env1, target_ulong addr)
 }
 #endif
 
+typedef struct QEMUAccel {
+    void (*cpu_interrupt)(CPUState *env);
+} QEMUAccel;
+
+extern QEMUAccel *current_accel;
+
+static inline void register_qemu_accel(QEMUAccel *accel)
+{
+    current_accel = accel;
+}
+
+static inline void accel_cpu_interrupt(CPUState *env)
+{
+    if (current_accel && current_accel->cpu_interrupt)
+        current_accel->cpu_interrupt(env);
+}
+
 #ifdef USE_KQEMU
 #define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG))
 
@@ -587,7 +604,6 @@ void kqemu_flush_page(CPUState *env, target_ulong addr);
 void kqemu_flush(CPUState *env, int global);
 void kqemu_set_notdirty(CPUState *env, ram_addr_t ram_addr);
 void kqemu_modify_page(CPUState *env, ram_addr_t ram_addr);
-void kqemu_cpu_interrupt(CPUState *env);
 void kqemu_record_dump(void);
 
 static inline int kqemu_is_ok(CPUState *env)
diff --git a/exec.c b/exec.c
index dfedfc3..73360d3 100644
--- a/exec.c
+++ b/exec.c
@@ -1256,6 +1256,8 @@ void cpu_interrupt(CPUState *env, int mask)
         tb_reset_jump_recursive(tb);
         resetlock(&interrupt_lock);
     }
+
+    accel_cpu_interrupt(env);
 }
 
 void cpu_reset_interrupt(CPUState *env, int mask)
diff --git a/kqemu.c b/kqemu.c
index 0e38d52..f875e0e 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -159,6 +159,8 @@ static void kqemu_update_cpuid(CPUState *env)
        accelerated code */
 }
 
+QEMUAccel kqemu_accel;
+
 int kqemu_start(void)
 {
     struct kqemu_init init;
@@ -240,6 +242,7 @@ int kqemu_start(void)
     }
     nb_pages_to_flush = 0;
     nb_ram_pages_to_update = 0;
+    register_qemu_accel(&kqemu_accel);
     return 0;
 }
 
@@ -249,6 +252,20 @@ void kqemu_init_env(CPUState *env)
     env->kqemu_enabled = kqemu_allowed;
 }
 
+void kqemu_cpu_interrupt(CPUState *env)
+{
+#if defined(_WIN32) && KQEMU_VERSION >= 0x010101
+    /* cancelling the I/O request causes KQEMU to finish executing the
+       current block and successfully returning. */
+    CancelIo(kqemu_fd);
+#endif
+}
+
+QEMUAccel kqemu_accel = {
+    .cpu_interrupt = kqemu_cpu_interrupt,
+};
+
+
 void kqemu_flush_page(CPUState *env, target_ulong addr)
 {
 #if defined(DEBUG)
@@ -906,14 +923,4 @@ int kqemu_cpu_exec(CPUState *env)
     }
     return 0;
 }
-
-void kqemu_cpu_interrupt(CPUState *env)
-{
-#if defined(_WIN32) && KQEMU_VERSION >= 0x010101
-    /* cancelling the I/O request causes KQEMU to finish executing the
-       current block and successfully returning. */
-    CancelIo(kqemu_fd);
-#endif
-}
-
 #endif
diff --git a/vl.c b/vl.c
index 5999b37..26c1677 100644
--- a/vl.c
+++ b/vl.c
@@ -239,6 +239,7 @@ struct drive_opt {
 static CPUState *cur_cpu;
 static CPUState *next_cpu;
 static int event_pending = 1;
+QEMUAccel *current_accel;
 
 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
 
@@ -1199,11 +1200,6 @@ static void host_alarm_handler(int host_signum)
         if (env) {
             /* stop the currently executing cpu because a timer occured */
             cpu_interrupt(env, CPU_INTERRUPT_EXIT);
-#ifdef USE_KQEMU
-            if (env->kqemu_enabled) {
-                kqemu_cpu_interrupt(env);
-            }
-#endif
         }
         event_pending = 1;
     }
-- 
1.5.5


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel

Reply via email to