qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 13/13] [PATCH] build list of available accelerators


From: Glauber Costa
Subject: [Qemu-devel] [PATCH 13/13] [PATCH] build list of available accelerators
Date: Thu, 15 May 2008 11:09:33 -0300

instead of hardcoding kqemu_start() in exec.c, which would require
such a hack for all available accelerators, semantics of register_qemu_accel()
is changed a little bit. It only builds a list of available accelerators.
The last one registered is the first tried.

This is a temporary solution, since we don't control exactly the order in which
things are loaded by the constructor attributes. The final goal is to have 
command
line switches and priority lists to determine that.

"info accelerator" is changed to accomodate it. It now prints a list of 
available
accelerators, and only if one of them is active, a detailed description of it 
is printed.
---
 exec-all.h |   43 +++++++++++++++++++++++++++++++++++++++++--
 exec.c     |    4 +---
 kqemu.c    |   11 +++++++++--
 monitor.c  |   18 ++++++++++++++++--
 vl.c       |    1 +
 5 files changed, 68 insertions(+), 9 deletions(-)

diff --git a/exec-all.h b/exec-all.h
index f62ff38..eca5cdb 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -579,8 +579,10 @@ static inline target_ulong get_phys_addr_code(CPUState 
*env1, target_ulong addr)
 #endif
 
 typedef struct QEMUAccel {
+    char *name;
     void (*cpu_interrupt)(CPUState *env);
     void (*init_env)(CPUState *env);
+    int (*start)(void);
     void (*flush_cache)(CPUState *env, int global);
     void (*flush_page)(CPUState *env, target_ulong addr);
     int (*info)(CPUState *env, char *buf);
@@ -590,11 +592,33 @@ typedef struct QEMUAccel {
     uint64_t (*get_real_ticks)(void);
 } QEMUAccel;
 
+typedef struct QEMUCont {
+    QEMUAccel *acc;
+    int active;
+    struct QEMUCont *next;
+} QEMUCont;
+
 extern QEMUAccel *current_accel;
+extern QEMUCont *head;
+void *qemu_mallocz(size_t size);
+
+static inline int register_qemu_accel(QEMUAccel *accel)
+{
+    QEMUCont *new;
+
+    new = qemu_mallocz(sizeof(*head));
+
+    new->acc = accel;
+    new->active = 0;
+    new->next = head;
+    head = new;
+
+    return 0;
+}
 
-static inline void register_qemu_accel(QEMUAccel *accel)
+static inline QEMUCont *get_accel_head(void)
 {
-    current_accel = accel;
+    return head;
 }
 
 static inline void accel_cpu_interrupt(CPUState *env)
@@ -603,6 +627,21 @@ static inline void accel_cpu_interrupt(CPUState *env)
         current_accel->cpu_interrupt(env);
 }
 
+static inline void accel_start(void)
+{
+    /* The top accelerator in the list gets tried first, but if it fails,
+     * keep trying until one of them succeeds or we exhaust the list */
+    QEMUCont *tmp = head;
+    while (tmp) {
+        if (tmp->acc && tmp->acc->start && (!(tmp->acc->start())) ) {
+            tmp->active = 1;
+            current_accel = tmp->acc;
+            break;
+        }
+        tmp = tmp->next; 
+    }
+}
+
 static inline void accel_init_env(CPUState *env)
 {
     if (current_accel && current_accel->init_env)
diff --git a/exec.c b/exec.c
index 92f1552..c885f7d 100644
--- a/exec.c
+++ b/exec.c
@@ -334,9 +334,7 @@ void exec_init(void)
     code_gen_ptr = code_gen_buffer;
     page_init();
     io_mem_init();
-#ifdef USE_KQEMU
-    kqemu_start();
-#endif
+    accel_start();
 }
 
 void cpu_exec_init(CPUState *env)
diff --git a/kqemu.c b/kqemu.c
index fbd8b66..996538d 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -163,7 +163,6 @@ static void kqemu_update_cpuid(CPUState *env)
        accelerated code */
 }
 
-QEMUAccel kqemu_accel;
 extern int smp_cpus;
 
 int kqemu_start(void)
@@ -247,7 +246,6 @@ int kqemu_start(void)
     }
     nb_pages_to_flush = 0;
     nb_ram_pages_to_update = 0;
-    register_qemu_accel(&kqemu_accel);
     return 0;
 }
 
@@ -404,8 +402,10 @@ void kqemu_modify_page(ram_addr_t ram_addr, int 
dirty_flags)
 }
 
 QEMUAccel kqemu_accel = {
+    .name = "kqemu",
     .cpu_interrupt = kqemu_cpu_interrupt,
     .init_env = kqemu_init_env,
+    .start = kqemu_start,
     .flush_cache = kqemu_flush,
     .flush_page = kqemu_flush_page,
     .info = kqemu_info,
@@ -418,6 +418,13 @@ QEMUAccel kqemu_accel = {
     .get_real_ticks = cpu_get_real_ticks,
 };
 
+static void __attribute__((constructor)) register_kqemu(void)
+{
+    if (register_qemu_accel(&kqemu_accel) < 0)
+        fprintf(logfile, "kqemu: could not register accelerator \n");
+}
+
+
 
 struct fpstate {
     uint16_t fpuc;
diff --git a/monitor.c b/monitor.c
index 2ee5b0c..49efa2d 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1166,6 +1166,18 @@ static void mem_info(void)
 }
 #endif
 
+static int do_accel_do_list(void)
+{
+    QEMUCont *tmp;
+    int active = 0;
+    for (tmp= get_accel_head(); tmp != NULL; tmp = tmp->next)
+    {
+        term_printf("%c %s\n", tmp->active ? '*' : ' ', tmp->acc->name);
+        active |= tmp->active;
+    }
+    return active;
+}
+
 #define MAX_BUF 1024
 static void do_info_accelerator(void)
 {
@@ -1179,8 +1191,10 @@ static void do_info_accelerator(void)
         return;
     }
 
-    if (accel_info(env, buf))
-        term_printf(buf);
+    if (do_accel_do_list()) {
+        if (accel_info(env, buf))
+            term_printf(buf);
+    }
     else
         term_printf("No accelerator present\n");
 }
diff --git a/vl.c b/vl.c
index 8104e33..cd9af69 100644
--- a/vl.c
+++ b/vl.c
@@ -240,6 +240,7 @@ static CPUState *cur_cpu;
 static CPUState *next_cpu;
 static int event_pending = 1;
 QEMUAccel *current_accel;
+QEMUCont *head = NULL;
 
 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
 
-- 
1.5.5





reply via email to

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