qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Glauber Costa <gcosta@redhat.com>
To: qemu-devel@nongnu.org
Cc: kvm-devel@lists.sourceforge.net, mtosatti@redhat.com,
	Glauber Costa <gcosta@redhat.com>
Subject: [Qemu-devel] [PATCH 1/4] [PATCH] introduce QEMUAccel and fill it with interrupt specific driver
Date: Fri,  2 May 2008 14:49:10 -0300	[thread overview]
Message-ID: <1209750562292-git-send-email-gcosta@redhat.com> (raw)
In-Reply-To: <12097505533742-git-send-email-gcosta@redhat.com>

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.

Signed-off-by: Glauber Costa <gcosta@redhat.com>
---
 block-raw-posix.c |    5 -----
 exec-all.h        |   18 +++++++++++++++++-
 exec.c            |    2 ++
 kqemu.c           |   26 ++++++++++++++++----------
 vl.c              |    6 +-----
 5 files changed, 36 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 3ce8242..5162307 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -574,6 +574,23 @@ static inline target_ulong get_phys_addr_code(CPUState *env, 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))
 
@@ -583,7 +600,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 48dabd6..93d9b01 100644
--- a/exec.c
+++ b/exec.c
@@ -1226,6 +1226,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 148a52f..c46698c 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -158,6 +158,19 @@ static void kqemu_update_cpuid(CPUState *env)
        accelerated code */
 }
 
+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,
+};
+
 int kqemu_init(CPUState *env)
 {
     struct kqemu_init init;
@@ -239,6 +252,9 @@ int kqemu_init(CPUState *env)
     }
     kqemu_update_cpuid(env);
     env->kqemu_enabled = kqemu_allowed;
+    if (env->kqemu_enabled)
+        register_qemu_accel(&kqemu_accel);
+
     nb_pages_to_flush = 0;
     nb_ram_pages_to_update = 0;
     return 0;
@@ -901,14 +917,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 9289982..9272541 100644
--- a/vl.c
+++ b/vl.c
@@ -240,6 +240,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)
 
@@ -1200,11 +1201,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.0.6

  reply	other threads:[~2008-05-02 17:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-02 17:49 [Qemu-devel] [PATCH 0/4] Presenting accelerators for better abstraction Glauber Costa
2008-05-02 17:49 ` Glauber Costa [this message]
2008-05-02 17:49   ` [Qemu-devel] [PATCH 2/4] [PATCH] exec interrupt made abstract by accel_yyy() Glauber Costa
2008-05-02 17:49     ` [Qemu-devel] [PATCH 3/4] [PATCH] init env made accel driver Glauber Costa
2008-05-02 17:49       ` [Qemu-devel] [PATCH 4/4] [PATCH] wrap cache flushing functions into accel drivers Glauber Costa
2008-05-02 18:16   ` [Qemu-devel] [PATCH 1/4] [PATCH] introduce QEMUAccel and fill it with interrupt specific driver Jamie Lokier
2008-05-02 19:49     ` Glauber Costa
2008-05-02 20:16       ` Paul Brook
2008-05-02 20:17         ` Glauber Costa

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=1209750562292-git-send-email-gcosta@redhat.com \
    --to=gcosta@redhat.com \
    --cc=kvm-devel@lists.sourceforge.net \
    --cc=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).