From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Khkin-0007FN-1g for qemu-devel@nongnu.org; Mon, 22 Sep 2008 08:40:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Khkih-0007CZ-JF for qemu-devel@nongnu.org; Mon, 22 Sep 2008 08:40:54 -0400 Received: from [199.232.76.173] (port=37204 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Khkih-0007CR-BM for qemu-devel@nongnu.org; Mon, 22 Sep 2008 08:40:51 -0400 Received: from thoth.sbs.de ([192.35.17.2]:23008) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Khkie-0000FJ-OS for qemu-devel@nongnu.org; Mon, 22 Sep 2008 08:40:50 -0400 From: Dmitry Baryshkov Date: Mon, 22 Sep 2008 16:37:30 +0400 Message-Id: <1222087050-10180-1-git-send-email-dmitry.baryshkov@siemens.com> Subject: [Qemu-devel] [PATCH] [qemu-accel] Unbreak linux-user targets Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Glauber Costa , Dmitry Baryshkov Currently linux-user targets are broken as current-accel is used but not linked in. Move common accel code to separate file that will be linked with both targets. Signed-off-by: Dmitry Baryshkov Cc: Glauber Costa --- Makefile.target | 2 +- accel.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ accel.h | 27 +++++------------ kqemu.c | 2 + linux-user/main.c | 2 + vl.c | 55 +---------------------------------- 6 files changed, 97 insertions(+), 74 deletions(-) create mode 100644 accel.c diff --git a/Makefile.target b/Makefile.target index dd511ef..d4c20c2 100644 --- a/Makefile.target +++ b/Makefile.target @@ -186,7 +186,7 @@ all: $(PROGS) ######################################################### # cpu emulator library -LIBOBJS=exec.o kqemu.o translate-all.o cpu-exec.o\ +LIBOBJS=accel.o exec.o kqemu.o translate-all.o cpu-exec.o\ translate.o host-utils.o ifdef CONFIG_DYNGEN_OP exec.o: dyngen-opc.h diff --git a/accel.c b/accel.c new file mode 100644 index 0000000..f9618b2 --- /dev/null +++ b/accel.c @@ -0,0 +1,83 @@ +#include "hw/hw.h" +#include "accel.h" + +QEMUAccel *current_accel; +QEMUCont *head = NULL; + +int _accel_nop(void) +{ + return 0; +} + +int noaccel_info(CPUState *env, char *buf) +{ + return sprintf(buf, "no accelerator present.\n"); +} + +CPUState *noaccel_get_env(void) +{ + return qemu_mallocz(sizeof(CPUState)); +} + +/* Accelerator wrapper for the no-accel (raw qemu) case */ +QEMUAccel noaccel = { + .name = NULL, + .cpu_interrupt = accel_nop, + .init_env = accel_nop, + .get_env = noaccel_get_env, + .start = accel_nop, + .flush_cache = accel_nop, + .flush_page = accel_nop, + .info = noaccel_info, + .profile = accel_nop, + .set_notdirty = accel_nop, + .modify_page = accel_nop, +#ifndef CONFIG_USER_ONLY + .get_real_ticks = cpu_get_ticks, +#endif + .register_physical_memory = accel_nop, + .trace_io = accel_nop, + .break_loop = accel_nop, +}; + +QEMUAccel *available_accels[] = { +/* list of available accelerators */ +#ifdef USE_KQEMU + &kqemu_accel, +#endif +}; + +int accel_start(void) +{ + int status = -1; + QEMUCont *tmp; + + /* Basic handler for the noaccel case */ + register_qemu_accel(&noaccel); + + /* 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 */ + tmp = head; + while (tmp) { + if (tmp->acc && tmp->acc->start && (!(tmp->acc->start())) ) { + tmp->active = 1; + current_accel = tmp->acc; + status = 0; + break; + } + tmp = tmp->next; + } + + return status; +} + +void accel_add(const char *name) +{ + int i; + printf("adding %s\n", name); + for (i = 0; i < ARRAY_SIZE(available_accels); i++) { + printf("c %s\n", available_accels[i]->name); + if (!strcasecmp(name, available_accels[i]->name)) + register_qemu_accel(available_accels[i]); + } +} diff --git a/accel.h b/accel.h index 0faecb3..ae72e23 100644 --- a/accel.h +++ b/accel.h @@ -10,7 +10,9 @@ typedef struct QEMUAccel { int (*profile)(CPUState *env, char *buf); void (*set_notdirty)(ram_addr_t addr); void (*modify_page)(ram_addr_t addr, int dirty_flags); +#ifndef CONFIG_USER_ONLY uint64_t (*get_real_ticks)(void); +#endif void (*register_physical_memory)(uint64_t start_addr, ram_addr_t size, ram_addr_t phys_offset); void (*trace_io)(CPUState *env); @@ -73,25 +75,7 @@ static inline void accel_cpu_interrupt(CPUState *env) current_accel->cpu_interrupt(env); } -static inline int accel_start(void) -{ - int status = -1; - - /* 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; - status = 0; - break; - } - tmp = tmp->next; - } - - return status; -} +extern int accel_start(void); static inline CPUState *accel_get_env(void) { @@ -133,12 +117,14 @@ static inline void accel_modify_page(target_ulong addr, int dirty_flags) current_accel->modify_page(addr, dirty_flags); } +#ifndef CONFIG_USER_ONLY int64_t cpu_get_ticks(void); static inline uint64_t accel_get_real_ticks(void) { return current_accel->get_real_ticks(); } +#endif static inline void accel_register_phys_mem(uint64_t start_addr, ram_addr_t size, @@ -156,3 +142,6 @@ static inline int accel_break_loop(CPUState *env) { return current_accel->break_loop(env); } + +extern void accel_add(const char *name); + diff --git a/kqemu.c b/kqemu.c index 5973978..d727b1b 100644 --- a/kqemu.c +++ b/kqemu.c @@ -464,7 +464,9 @@ QEMUAccel kqemu_accel = { /* Note: when using kqemu, it is more logical to return the host TSC because kqemu does not trap the RDTSC instruction for performance reasons */ +#ifndef CONFIG_USER_ONLY .get_real_ticks = cpu_get_real_ticks, +#endif .register_physical_memory = kqemu_set_phys_mem, .trace_io = kqemu_trace_io, .break_loop = kqemu_break_loop, diff --git a/linux-user/main.c b/linux-user/main.c index 4bf739e..f8ac9a1 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -28,6 +28,7 @@ #include "qemu-common.h" /* For tb_lock */ #include "exec-all.h" +#include "accel.h" #define DEBUG_LOGFILE "/tmp/qemu.log" @@ -2354,6 +2355,7 @@ int main(int argc, char **argv) #endif } cpu_exec_init_all(0); + accel_start(); /* NOTE: we need to init the CPU at this stage to get qemu_host_page_size */ env = cpu_init(cpu_model); diff --git a/vl.c b/vl.c index 8fa5f53..a7cc572 100644 --- a/vl.c +++ b/vl.c @@ -259,50 +259,6 @@ static int64_t qemu_icount_bias; QEMUTimer *icount_rt_timer; QEMUTimer *icount_vm_timer; -QEMUAccel *current_accel; -QEMUCont *head = NULL; - -int _accel_nop(void) -{ - return 0; -} - -int noaccel_info(CPUState *env, char *buf) -{ - return sprintf(buf, "no accelerator present.\n"); -} - -CPUState *noaccel_get_env(void) -{ - return qemu_mallocz(sizeof(CPUState)); -} - -/* Accelerator wrapper for the no-accel (raw qemu) case */ -QEMUAccel noaccel = { - .name = NULL, - .cpu_interrupt = accel_nop, - .init_env = accel_nop, - .get_env = noaccel_get_env, - .start = accel_nop, - .flush_cache = accel_nop, - .flush_page = accel_nop, - .info = noaccel_info, - .profile = accel_nop, - .set_notdirty = accel_nop, - .modify_page = accel_nop, - .get_real_ticks = cpu_get_ticks, - .register_physical_memory = accel_nop, - .trace_io = accel_nop, - .break_loop = accel_nop, -}; - -QEMUAccel *available_accels[] = { -/* list of available accelerators */ -#ifdef USE_KQEMU - &kqemu_accel, -#endif -}; - #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR) /***********************************************************/ @@ -8773,13 +8729,7 @@ int main(int argc, char **argv) break; #endif case QEMU_OPTION_accel: - { - int i; - for (i = 0; i < ARRAY_SIZE(available_accels); i++) { - if (!strcasecmp(optarg, available_accels[i]->name)) - register_qemu_accel(available_accels[i]); - } - } + accel_add(optarg); break; case QEMU_OPTION_usb: usb_enabled = 1; @@ -8905,9 +8855,6 @@ int main(int argc, char **argv) } } - /* Basic handler for the noaccel case */ - register_qemu_accel(&noaccel); - if (nographic) { if (serial_device_index == 0) serial_devices[0] = "stdio"; -- 1.5.6.5