From: Glauber Costa <address@hidden>
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 <address@hidden>
Signed-off-by: Dmitry Baryshkov <address@hidden>
---
Makefile.target | 2 +-
accel.c | 17 +++++++++++++++++
accel.h | 20 ++++++++++++++++++++
exec.c | 3 +++
kqemu.c | 9 +++++++++
vl.c | 17 +++++------------
6 files changed, 55 insertions(+), 13 deletions(-)
create mode 100644 accel.c
create mode 100644 accel.h
diff --git a/Makefile.target b/Makefile.target
index e2edf9d..623ecd8 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -188,7 +188,7 @@ all: $(PROGS)
#########################################################
# cpu emulator library
LIBOBJS=exec.o kqemu.o translate-all.o cpu-exec.o\
- translate.o host-utils.o
+ translate.o host-utils.o accel.o
ifdef CONFIG_DYNGEN_OP
exec.o: dyngen-opc.h
LIBOBJS+=op.o
diff --git a/accel.c b/accel.c
new file mode 100644
index 0000000..d30460d
--- /dev/null
+++ b/accel.c
@@ -0,0 +1,17 @@
+#include "hw/hw.h"
+#include "accel.h"
+
+QEMUAccel *current_accel;
+
+int _accel_nop(void)
+{
+ return 0;
+}
+
+#define accel_nop ((void *)_accel_nop)
+
+/* Accelerator wrapper for the no-accel (raw qemu) case */
+QEMUAccel noaccel = {
+ .cpu_interrupt = accel_nop,
+};
+
diff --git a/accel.h b/accel.h
new file mode 100644
index 0000000..8e5ddc6
--- /dev/null
+++ b/accel.h
@@ -0,0 +1,20 @@
+#ifndef _ACCEL_H_
+#define _ACCEL_H_
+
+typedef struct QEMUAccel {
+ void (*cpu_interrupt)(CPUState *env);
+} QEMUAccel;
+
+extern QEMUAccel *current_accel;
+extern QEMUAccel noaccel;
+
+static inline void register_qemu_accel(QEMUAccel *accel)
+{
+ current_accel = accel;
+}
+
+static inline void accel_cpu_interrupt(CPUState *env)
+{
+ current_accel->cpu_interrupt(env);
+}
+#endif
diff --git a/exec.c b/exec.c
index 1cad0be..21253cc 100644
--- a/exec.c
+++ b/exec.c
@@ -43,6 +43,8 @@
#include <qemu.h>
#endif
+#include "accel.h"
+
//#define DEBUG_TB_INVALIDATE
//#define DEBUG_FLUSH
//#define DEBUG_TLB
@@ -1430,6 +1432,7 @@ void cpu_single_step(CPUState *env, int enabled)
tb_flush(env);
}
#endif
+ accel_cpu_interrupt(env);
}
/* enable or disable low levels log */
diff --git a/kqemu.c b/kqemu.c
index 9b52237..87c06cd 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -50,6 +50,7 @@
#include <unistd.h>
#include <fcntl.h>
#include "kqemu.h"
+#include "accel.h"
#ifdef _WIN32
#define KQEMU_DEVICE "\\\\.\\kqemu"
@@ -150,6 +151,8 @@ static void kqemu_update_cpuid(CPUState *env)
accelerated code */
}
+QEMUAccel kqemu_accel;
+
int kqemu_start(void)
{
struct kqemu_init kinit;
@@ -232,6 +235,7 @@ int kqemu_start(void)
}
nb_pages_to_flush = 0;
nb_ram_pages_to_update = 0;
+ register_qemu_accel(&kqemu_accel);
qpi_init();
return 0;
@@ -243,6 +247,11 @@ void kqemu_init_env(CPUState *env)
env->kqemu_enabled = kqemu_allowed;
}
+QEMUAccel kqemu_accel = {
+ .cpu_interrupt = kqemu_cpu_interrupt,
+};