qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 21/32] get_env accel wrapper


From: Glauber Costa
Subject: [Qemu-devel] [PATCH 21/32] get_env accel wrapper
Date: Thu, 23 Oct 2008 12:19:05 -0200

From: Glauber Costa <address@hidden>

Allow the current accelerator to provide it's own, customized
address of the CPUState structure used for the env variable.

Signed-off-by: Glauber Costa <address@hidden>
---
 accel.c              |    6 ++++++
 accel.h              |    8 ++++++++
 kqemu.c              |   12 ++++++++++--
 kqemu.h              |   10 ++++++++++
 target-i386/cpu.h    |    1 -
 target-i386/helper.c |    2 +-
 6 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/accel.c b/accel.c
index 0890039..28dd2ee 100644
--- a/accel.c
+++ b/accel.c
@@ -14,6 +14,11 @@ int noaccel_info(CPUState *env, char *buf)
     return snprintf(buf, MAX_INFO_BUF, "no accelerator present.\n");
 }
 
+CPUState *noaccel_get_env(void)
+{
+    return qemu_mallocz(sizeof(CPUState));
+}
+
 #define accel_nop ((void *)_accel_nop)
 
 /* Accelerator wrapper for the no-accel (raw qemu) case */
@@ -21,6 +26,7 @@ QEMUAccel noaccel = {
     .name = "none",
     .cpu_interrupt = accel_nop,
     .init_env = accel_nop,
+    .get_env = noaccel_get_env,
     .start = accel_nop,
     .flush_cache = accel_nop,
     .flush_page = accel_nop,
diff --git a/accel.h b/accel.h
index b37175b..0c5ff33 100644
--- a/accel.h
+++ b/accel.h
@@ -6,6 +6,7 @@
 typedef struct QEMUAccel {
     char *name;
     void (*cpu_interrupt)(CPUState *env);
+    CPUState *(*get_env)(void);
     void (*init_env)(CPUState *env);
     int (*start)(int cpus);
     void (*flush_cache)(CPUState *env, int global);
@@ -33,10 +34,12 @@ extern QEMUAccel *current_accel;
 extern QEMUAccel noaccel;
 #ifdef USE_KQEMU
 extern QEMUAccel kqemu_accel;
+extern QEMUAccel kqemu_kernel_accel;
 #endif
 
 extern QEMUCont *head;
 void *qemu_mallocz(size_t size);
+extern CPUState *noaccel_get_env(void);
 
 static inline int register_qemu_accel(QEMUAccel *accel)
 {
@@ -93,6 +96,11 @@ static inline int accel_start(int cpus)
     return status;
 }
 
+static inline CPUState *accel_get_env(void)
+{
+    return current_accel->get_env();
+}
+
 static inline void accel_init_env(CPUState *env)
 {
     current_accel->init_env(env);
diff --git a/kqemu.c b/kqemu.c
index d38d0e3..5ca0f76 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -1110,23 +1110,31 @@ static int kqemu_profile(CPUState *env, char *buf)
 static void kqemu_trace_io(CPUState *env)
 {
     if (env)
-        env->last_io_time = cpu_get_time_fast();
+        kqemu_cpu_field(env,last_io_time) = cpu_get_time_fast();
 }
 
 static int kqemu_break_loop(CPUState *env)
 {
 #define MIN_CYCLE_BEFORE_SWITCH (100 * 1000)
     if (kqemu_is_ok(env) &&
-        (cpu_get_time_fast() - env->last_io_time) >= MIN_CYCLE_BEFORE_SWITCH) {
+        (cpu_get_time_fast() - kqemu_cpu_field(env,last_io_time)) >= 
MIN_CYCLE_BEFORE_SWITCH) {
         return 1;
     }
     return 0;
 }
 
+static CPUState *kqemu_get_env(void)
+{
+    KQEMUCPUState *kenv;
+    kenv = qemu_mallocz(sizeof(KQEMUCPUState));
+    return &kenv->env;
+}
+
 QEMUAccel kqemu_accel = {
     .name = "KQEMU",
     .cpu_interrupt = kqemu_cpu_interrupt,
     .init_env = kqemu_init_env,
+    .get_env = kqemu_get_env,
     .start = kqemu_start,
     .flush_cache = kqemu_flush,
     .flush_page = kqemu_flush_page,
diff --git a/kqemu.h b/kqemu.h
index 1c7e024..cf14179 100644
--- a/kqemu.h
+++ b/kqemu.h
@@ -157,4 +157,14 @@ struct kqemu_phys_mem {
 #define KQEMU_SET_PHYS_MEM     _IOW('q', 5, struct kqemu_phys_mem)
 #endif
 
+typedef struct KQEMUCPUstate {
+    int kqemu_enabled;
+    int last_io_time;
+    CPUState env;
+} KQEMUCPUState;
+
+#define kqemu_cpu_field(env, field) (*({ \
+    KQEMUCPUState *__c = container_of(env, KQEMUCPUState, env); \
+    &__c->field; }))
+
 #endif /* KQEMU_H */
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 3c11e0f..8a2d797 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -608,7 +608,6 @@ typedef struct CPUX86State {
 
 #ifdef USE_KQEMU
     int kqemu_enabled;
-    int last_io_time;
 #endif
     /* in order to simplify APIC support, we leave this pointer to the
        user */
diff --git a/target-i386/helper.c b/target-i386/helper.c
index b981b92..5ff051f 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -98,7 +98,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
     CPUX86State *env;
     static int inited;
 
-    env = qemu_mallocz(sizeof(CPUX86State));
+    env = accel_get_env();
     if (!env)
         return NULL;
     cpu_exec_init(env);
-- 
1.5.5.1





reply via email to

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