QEMU Accel patch
cover QEMU Accel patch
First of all, very sorry. I mistyped qemu's mailing list address. So this message only reached kvm list and the people in CC. I'm resending, but this means a lot of you will receive the messages twice. Mail is cheap... but sorry again anyway!
Introductory message follows:
Hi folks.
Here's a new version of the qemu accel patches. This version works with kqemu 1.4.0pre1 in my tests, and I feel it is close to be in inclusion state. Patches are all split to ease review.
Those patches does not include any code for kvm. The reason is some parts of kvm will need significant rework, and I'd rather do it once we're set up with those interfaces, to avoid time waste. Furthermore, there's work on the radar, such as pbrook's ongoing effort to make qemu more thread-friendly that would affect kvm a lot (recall kvm uses threads for the vcpus, which heavily defines how the main loop works, for instance), so I'd wait anyway.
However, I do have a PoC for kvm with _basic_ functionality, that can be seen at http://glommer.net/kvm-accel-PoC
Comments are welcome.
PATCH 1/20 split kqemu_init into two
we separate kqemu_init() into a part that depends on env, and other that does not. The later can be initialized earlier
--- exec.c | 5 ++++- kqemu.c | 10 +++++++--- target-i386/helper.c | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-)
exec.c +4 -1
@@ -433,6 +433,9 @@ void cpu_exec_init_all(unsigned long tb_size)#if !defined(CONFIG_USER_ONLY )io_mem_init ();#endif +#ifdef USE_KQEMU +kqemu_start (); +#endif }void cpu_exec_init (CPUState *env)
@@ -2078,7 +2081,7 @@ void cpu_register_physical_memory(target_phys_addr_t start_addr,#ifdef USE_KQEMU /* XXX: should not depend on cpu context */ env = first_cpu; -if (env->kqemu_enabled) { +if (env && env->kqemu_enabled) {kqemu_set_phys_mem (start_addr, size, phys_offset); }#endif
kqemu.c +7 -3
@@ -150,7 +150,7 @@ static void kqemu_update_cpuid(CPUState *env)accelerated code */ } -int kqemu_init (CPUState *env) +int kqemu_start (void ) {struct kqemu_init kinit;int ret, version;
@@ -230,8 +230,6 @@ int kqemu_init(CPUState *env) kqemu_fd =KQEMU_INVALID_FD ;return -1 ; } -kqemu_update_cpuid (env); - env->kqemu_enabled = kqemu_allowed; nb_pages_to_flush =0 ; nb_ram_pages_to_update =0 ;
@@ -239,6 +237,12 @@ int kqemu_init(CPUState *env)return 0 ; } +void kqemu_init_env (CPUState *env) +{ +kqemu_update_cpuid (env); + env->kqemu_enabled = kqemu_allowed; +} +void kqemu_flush_page (CPUState *env,target_ulong addr) {#if defined(DEBUG )
target-i386/helper.c +1 -1
@@ -113,7 +113,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model) }cpu_reset (env);#ifdef USE_KQEMU -kqemu_init (env); +kqemu_init_env (env);#endif return env; }
Signature · 1 line
1.5.5.1
PATCH 3/20 init env made accel driver
In reply to Glauber Costa--- accel.h | 8 ++++++++ kqemu.c | 1 + target-i386/helper.c | 6 +++--- 3 files changed, 12 insertions(+), 3 deletions(-)
accel.h +8 -0
@@ -1,5 +1,6 @@typedef struct QEMUAccel {void (*cpu_interrupt)(CPUState *env); +void (*init_env)(CPUState *env); }QEMUAccel ;extern QEMUAccel *current_accel;
@@ -14,3 +15,10 @@ static inline void accel_cpu_interrupt(CPUState *env)if (current_accel && current_accel->cpu_interrupt) current_accel->cpu_interrupt (env); } + +static inline void accel_init_env (CPUState *env) +{ +if (current_accel && current_accel->init_env) + current_accel->init_env (env); +} +
kqemu.c +1 -0
@@ -249,6 +249,7 @@ void kqemu_init_env(CPUState *env)QEMUAccel kqemu_accel = { .cpu_interrupt = kqemu_cpu_interrupt, + .init_env = kqemu_init_env, };
target-i386/helper.c +3 -3
@@ -30,6 +30,8 @@#include "svm.h" #include "qemu-common.h" +#include "accel.h" +//#define DEBUG_MMU static int cpu_x86_register (CPUX86State *env,const char *cpu_model);
@@ -112,9 +114,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)return NULL ; }cpu_reset (env); -#ifdef USE_KQEMU -kqemu_init_env (env); -#endif +accel_init_env (env);return env; }
Signature · 1 line
1.5.5.1
PATCH 2/20 introduce QEMUAccel and fill it with interrupt specific driver
In reply to Glauber CostaThis 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.
--- accel.h | 16 ++++++++++++++++ block-raw-posix.c | 5 ----- exec.c | 3 +++ kqemu.c | 9 +++++++++ vl.c | 8 +++----- 5 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 accel.h
accel.h new file +16 -0
@@ -0,0 +1,16 @@ +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); +}
block-raw-posix.c +0 -5
@@ -439,11 +439,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 }
exec.c +3 -0
@@ -41,6 +41,8 @@#include <qemu.h> #endif +#include "accel.h" +//#define DEBUG_TB_INVALIDATE //#define DEBUG_FLUSH //#define DEBUG_TLB
@@ -1391,6 +1393,7 @@ void cpu_interrupt(CPUState *env, int mask) resetlock(&interrupt_lock); }#endif +accel_cpu_interrupt (env); }void cpu_reset_interrupt (CPUState *env,int mask)
kqemu.c +9 -0
@@ -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, +}; + +void kqemu_flush_page (CPUState *env,target_ulong addr) {#if defined(DEBUG )
vl.c +3 -5
@@ -131,6 +131,8 @@ int inet_aton(const char *cp, struct in_addr *ia);#include "exec-all.h" +#include "accel.h" +#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"#ifdef __sun__
@@ -239,6 +241,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)
@@ -1199,11 +1202,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 ; }
Signature · 1 line
1.5.5.1
PATCH 4/20 wrap cache flushing functions into accel drivers
In reply to Glauber Costa--- accel.h | 13 +++++++++++++ exec.c | 15 +++++++-------- kqemu.c | 15 +++++++++------ 3 files changed, 29 insertions(+), 14 deletions(-)
accel.h +13 -0
@@ -1,6 +1,8 @@typedef struct QEMUAccel {void (*cpu_interrupt)(CPUState *env);void (*init_env)(CPUState *env); +void (*flush_cache)(CPUState *env,int global); +void (*flush_page)(CPUState *env,target_ulong addr); }QEMUAccel ;extern QEMUAccel *current_accel;
@@ -22,3 +24,14 @@ static inline void accel_init_env(CPUState *env) current_accel->init_env (env); } +static inline void accel_flush_cache (CPUState *env,int global) +{ +if (current_accel && current_accel->flush_cache) + current_accel->flush_cache (env, global); +} + +static inline void accel_flush_page (CPUState *env,target_ulong addr) +{ +if (current_accel && current_accel->flush_page) + current_accel->flush_page (env, addr); +}
exec.c +7 -8
@@ -1566,10 +1566,10 @@ void tlb_flush(CPUState *env, int flush_global)memset (env->tb_jmp_cache,0 ,TB_JMP_CACHE_SIZE *sizeof (void *)); -#ifdef USE_KQEMU -if (env->kqemu_enabled) { -kqemu_flush (env, flush_global); - } +accel_flush_cache (env, flush_global); + +#if !defined(CONFIG_SOFTMMU ) +munmap ((void *)MMAP_AREA_START ,MMAP_AREA_END -MMAP_AREA_START );#endif tlb_flush_count++; }
@@ -1612,10 +1612,9 @@ void tlb_flush_page(CPUState *env, target_ulong addr)tlb_flush_jmp_cache (env, addr); -#ifdef USE_KQEMU -if (env->kqemu_enabled) { -kqemu_flush_page (env, addr); - } +accel_flush_page (env, addr); +#if !defined(CONFIG_SOFTMMU ) + if (addr < MMAP_AREA_END)#endif }
kqemu.c +9 -6
@@ -247,12 +247,6 @@ void kqemu_init_env(CPUState *env) env->kqemu_enabled = kqemu_allowed; } -QEMUAccel kqemu_accel = { - .cpu_interrupt = kqemu_cpu_interrupt, - .init_env = kqemu_init_env, -}; - -void kqemu_flush_page (CPUState *env,target_ulong addr) {#if defined(DEBUG )
@@ -276,6 +270,15 @@ void kqemu_flush(CPUState *env, int global) nb_pages_to_flush =KQEMU_FLUSH_ALL ; } +QEMUAccel kqemu_accel = { + .cpu_interrupt = kqemu_cpu_interrupt, + .init_env = kqemu_init_env, + .flush_cache = kqemu_flush, + .flush_page = kqemu_flush_page, +}; + + +void kqemu_set_notdirty (CPUState *env,ram_addr_t ram_addr) {#ifdef DEBUG
Signature · 1 line
1.5.5.1
PATCH 5/20 turn info kqemu into generic info accelerator
--- accel.h | 8 ++++++++ kqemu.c | 24 ++++++++++++++++++++++++ monitor.c | 36 +++++++++++++----------------------- 3 files changed, 45 insertions(+), 23 deletions(-)
accel.h +8 -0
@@ -3,6 +3,7 @@ typedef struct QEMUAccel {void (*init_env)(CPUState *env);void (*flush_cache)(CPUState *env,int global);void (*flush_page)(CPUState *env,target_ulong addr); +int (*info)(CPUState *env,char *buf); } QEMUAccel;extern QEMUAccel *current_accel;
@@ -35,3 +36,10 @@ static inline void accel_flush_page(CPUState *env, target_ulong addr)if (current_accel && current_accel->flush_page) current_accel->flush_page (env, addr); } + +static inline int accel_info (CPUState *env,char *buf) +{ +if (current_accel && current_accel->info) +return current_accel->info (env, buf); +return 0 ; +}
kqemu.c +24 -0
@@ -270,11 +270,35 @@ void kqemu_flush(CPUState *env, int global) nb_pages_to_flush =KQEMU_FLUSH_ALL ; } +int kqemu_info (CPUState *env,char *buf) +{ +int val, len; + val =0 ; + val = env->kqemu_enabled; + len =sprintf (buf,"kqemu support: " ); + buf += len; + +switch (val) { +default : + len +=sprintf (buf,"present, but bogus value\n" ); +break ; +case 1 : + len +=sprintf (buf,"enabled for user code\n" ); +break ; +case 2 : + len +=sprintf (buf,"enabled for user and kernel code\n" ); +break ; + } + +return len; +} +QEMUAccel kqemu_accel = { .cpu_interrupt = kqemu_cpu_interrupt, .init_env = kqemu_init_env, .flush_cache = kqemu_flush, .flush_page = kqemu_flush_page, + .info = kqemu_info, };
monitor.c +13 -23
@@ -34,6 +34,7 @@#include "block.h" #include "audio/audio.h" #include "disas.h" +#include "accel.h" #include <dirent.h> #include "qemu-timer.h"
@@ -1217,34 +1218,23 @@ static void mem_info(void) }#endif -static void do_info_kqemu (void ) +#define MAX_BUF 1024 +static void do_info_accelerator (void ) { -#ifdef USE_KQEMU +char buf[MAX_BUF ];CPUState *env; -int val; - val =0 ; + env =mon_get_cpu (); +if (!env) {term_printf ("No cpu initialized yet" );return ; } - val = env->kqemu_enabled; -term_printf ("kqemu support: " ); -switch (val) { -default : -case 0 : -term_printf ("disabled\n" ); -break ; -case 1 : -term_printf ("enabled for user code\n" ); -break ; -case 2 : -term_printf ("enabled for user and kernel code\n" ); -break ; - } -#else -term_printf ("kqemu support: not compiled\n" ); -#endif + +if (accel_info (env, buf)) +term_printf (buf); +else +term_printf ("No accelerator present\n" ); }#ifdef CONFIG_PROFILER
@@ -1474,8 +1464,8 @@ static term_cmd_t info_cmds[] = {#endif {"jit" ,"" , do_info_jit, "", "show dynamic compiler info", }, - { "kqemu", "", do_info_kqemu, - "", "show kqemu information", }, + { "accelerator", "", do_info_accelerator, + "", "show accelerator information", }, { "usb", "", usb_info, "", "show guest USB devices", }, { "usbhost", "", usb_host_info,
Signature · 1 line
1.5.5.1
PATCH 6/20 separate accelerator part of info profiler
--- accel.h | 8 ++++++++ kqemu.c | 35 +++++++++++++++++++++++++++++++++++ monitor.c | 27 ++++++--------------------- 3 files changed, 49 insertions(+), 21 deletions(-)
accel.h +8 -0
@@ -4,6 +4,7 @@ typedef struct QEMUAccel {void (*flush_cache)(CPUState *env,int global);void (*flush_page)(CPUState *env,target_ulong addr);int (*info)(CPUState *env,char *buf); +int (*profile)(CPUState *env,char *buf); } QEMUAccel;extern QEMUAccel *current_accel;
@@ -43,3 +44,10 @@ static inline int accel_info(CPUState *env, char *buf)return current_accel->info (env, buf);return 0 ; } + +static inline int accel_profile (CPUState *env,char *buf) +{ +if (current_accel && current_accel->profile) +return current_accel->profile (env, buf); +return 0 ; +}
kqemu.c +35 -0
@@ -52,6 +52,10 @@#include "kqemu.h" #include "accel.h" +#ifdef CONFIG_PROFILER +#include "qemu-timer.h" /* for ticks_per_sec */ +#endif +#ifdef _WIN32#define KQEMU_DEVICE "\\\\.\\kqemu"#else
@@ -293,12 +297,43 @@ int kqemu_info(CPUState *env, char *buf)return len; } +int64_t kqemu_time; +int64_t kqemu_exec_count; +int64_t kqemu_ret_int_count; +int64_t kqemu_ret_excp_count; +int64_t kqemu_ret_intr_count; +extern int64_t qemu_time; + +int kqemu_profile (CPUState *env,char *buf) +{ +int len =0 ; +#ifdef CONFIG_PROFILER + len =sprintf (buf,"kqemu time %" PRId64" (%0.3f %0.1f%%) count=%" PRId64 +" int=%" PRId64" excp=%" PRId64" intr=%" PRId64"\n" , + kqemu_time, kqemu_time / (double )ticks_per_sec, + kqemu_time / qemu_time *100.0 , + kqemu_exec_count, + kqemu_ret_int_count, + kqemu_ret_excp_count, + kqemu_ret_intr_count); + + kqemu_time =0 ; + kqemu_exec_count =0 ; + kqemu_ret_int_count =0 ; + kqemu_ret_excp_count =0 ; + kqemu_ret_intr_count =0 ; +kqemu_record_dump (); +#endif +return len; +} +QEMUAccel kqemu_accel = { .cpu_interrupt = kqemu_cpu_interrupt, .init_env = kqemu_init_env, .flush_cache = kqemu_flush, .flush_page = kqemu_flush_page, .info = kqemu_info, + .profile = kqemu_profile, };
monitor.c +6 -21
@@ -1239,17 +1239,14 @@ static void do_info_accelerator(void)#ifdef CONFIG_PROFILER -int64_t kqemu_time;int64_t qemu_time; -int64_t kqemu_exec_count;int64_t dev_time; -int64_t kqemu_ret_int_count; -int64_t kqemu_ret_excp_count; -int64_t kqemu_ret_intr_count; -static void do_info_profile (void ) {int64_t total; +char buf[MAX_BUF ]; +CPUState *env =mon_get_cpu (); + total = qemu_time;if (total ==0 ) total =1 ;
@@ -1257,24 +1254,12 @@ static void do_info_profile(void) dev_time, dev_time / (double)ticks_per_sec);term_printf ("qemu time %" PRId64" (%0.3f)\n" , qemu_time, qemu_time / (double )ticks_per_sec); -term_printf ("kqemu time %" PRId64" (%0.3f %0.1f%%) count=%" PRId64" int=%" PRId64" excp=%" PRId64" intr=%" PRId64"\n" , - kqemu_time, kqemu_time / (double )ticks_per_sec, - kqemu_time / (double )total *100.0 , - kqemu_exec_count, - kqemu_ret_int_count, - kqemu_ret_excp_count, - kqemu_ret_intr_count); +if (accel_profile (env, buf)) +term_printf (buf); qemu_time =0 ; - kqemu_time =0 ; - kqemu_exec_count =0 ; dev_time = 0; - kqemu_ret_int_count =0 ; - kqemu_ret_excp_count =0 ; - kqemu_ret_intr_count =0 ; -#ifdef USE_KQEMU -kqemu_record_dump (); -#endif } +#else static void do_info_profile (void ) {
Signature · 1 line
1.5.5.1
PATCH 7/20 move kqemu externs to kqemu.h
--- cpu-all.h | 5 ----- kqemu.h | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-)
cpu-all.h +0 -5
@@ -1107,14 +1107,9 @@ static inline int64_t profile_getclock(void)return cpu_get_real_ticks (); } -extern int64_t kqemu_time, kqemu_time_start;extern int64_t qemu_time, qemu_time_start;extern int64_t tlb_flush_time; -extern int64_t kqemu_exec_count;extern int64_t dev_time; -extern int64_t kqemu_ret_int_count; -extern int64_t kqemu_ret_excp_count; -extern int64_t kqemu_ret_intr_count;#endif #endif /* CPU_ALL_H */
kqemu.h +6 -0
@@ -32,6 +32,12 @@#define KQEMU_VERSION 0x010400 +extern int64_t kqemu_time, kqemu_time_start; +extern int64_t kqemu_exec_count; +extern int64_t kqemu_ret_int_count; +extern int64_t kqemu_ret_excp_count; +extern int64_t kqemu_ret_intr_count; +struct kqemu_segment_cache {uint16_t selector;uint16_t padding1;
Signature · 1 line
1.5.5.1
PATCH 8/20 move disabling code to kqemu.c instead of vl.c
this is for the case in which we run more than one cpu
--- kqemu.c | 3 ++- vl.c | 4 ---- 2 files changed, 2 insertions(+), 5 deletions(-)
kqemu.c +2 -1
@@ -156,6 +156,7 @@ static void kqemu_update_cpuid(CPUState *env) }QEMUAccel kqemu_accel; +extern int smp_cpus;int kqemu_start (void ) {
@@ -165,7 +166,7 @@ int kqemu_start(void)DWORD temp;#endif -if (!kqemu_allowed) +if (!kqemu_allowed || smp_cpus >1 )return -1 ;#ifdef _WIN32
vl.c +0 -4
@@ -8372,10 +8372,6 @@ int main(int argc, char **argv)exit (1 ); } -#ifdef USE_KQEMU -if (smp_cpus >1 ) - kqemu_allowed =0 ; -#endif linux_boot = (kernel_filename !=NULL ); net_boot = (boot_devices_bitmap >> ('n' -'a' )) &0xF ;
Signature · 1 line
1.5.5.1
PATCH 9/20 set_notdirty goes through accel wrapper
--- accel.h | 7 +++++++ exec-all.h | 2 +- exec.c | 18 +++++++----------- kqemu.c | 23 +++++++++++------------ 4 files changed, 26 insertions(+), 24 deletions(-)
accel.h +7 -0
@@ -5,6 +5,7 @@ typedef struct QEMUAccel {void (*flush_page)(CPUState *env,target_ulong addr);int (*info)(CPUState *env,char *buf);int (*profile)(CPUState *env,char *buf); +void (*set_notdirty)(ram_addr_t addr); } QEMUAccel;extern QEMUAccel *current_accel;
@@ -51,3 +52,9 @@ static inline int accel_profile(CPUState *env, char *buf)return current_accel->profile (env, buf);return 0 ; } + +static inline void accel_set_notdirty (target_ulong addr) +{ +if (current_accel && current_accel->set_notdirty) + current_accel->set_notdirty (addr); +}
exec-all.h +1 -1
@@ -375,7 +375,7 @@ int kqemu_init(CPUState *env);int kqemu_cpu_exec (CPUState *env);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_set_notdirty (ram_addr_t ram_addr);void kqemu_modify_page (CPUState *env,ram_addr_t ram_addr);void kqemu_set_phys_mem (uint64_t start_addr,ram_addr_t size,ram_addr_t phys_offset);
exec.c +7 -11
@@ -1662,18 +1662,14 @@ void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end,if (length ==0 )return ; len = length >>TARGET_PAGE_BITS ; -#ifdef USE_KQEMU -/* XXX: should not depend on cpu context */ - env = first_cpu; -if (env->kqemu_enabled) { -ram_addr_t addr; - addr = start; -for (i =0 ; i < len; i++) { -kqemu_set_notdirty (env, addr); - addr +=TARGET_PAGE_SIZE ; - } + +ram_addr_t addr; + addr = start; +for (i =0 ; i < len; i++) { +accel_set_notdirty (addr); + addr +=TARGET_PAGE_SIZE ; } -#endif + mask = ~dirty_flags; p = phys_ram_dirty + (start >>TARGET_PAGE_BITS );for (i =0 ; i < len; i++)
kqemu.c +11 -12
@@ -328,18 +328,7 @@ int kqemu_profile(CPUState *env, char *buf)return len; } -QEMUAccel kqemu_accel = { - .cpu_interrupt = kqemu_cpu_interrupt, - .init_env = kqemu_init_env, - .flush_cache = kqemu_flush, - .flush_page = kqemu_flush_page, - .info = kqemu_info, - .profile = kqemu_profile, -}; - - - -void kqemu_set_notdirty (CPUState *env,ram_addr_t ram_addr) +void kqemu_set_notdirty (ram_addr_t ram_addr) {#ifdef DEBUG if (loglevel &CPU_LOG_INT ) {
@@ -356,6 +345,16 @@ void kqemu_set_notdirty(CPUState *env, ram_addr_t ram_addr) ram_pages_to_update[nb_ram_pages_to_update++] = ram_addr; } +QEMUAccel kqemu_accel = { + .cpu_interrupt = kqemu_cpu_interrupt, + .init_env = kqemu_init_env, + .flush_cache = kqemu_flush, + .flush_page = kqemu_flush_page, + .info = kqemu_info, + .profile = kqemu_profile, + .set_notdirty = kqemu_set_notdirty, +}; +static void kqemu_reset_modified_ram_pages (void ) {int i;
Signature · 1 line
1.5.5.1
PATCH 10/20 wrap modify_page through accel calls
--- accel.h | 8 ++++++++ exec-all.h | 2 +- exec.c | 27 ++++++++++++--------------- kqemu.c | 26 +++++++++++++++----------- 4 files changed, 36 insertions(+), 27 deletions(-)
accel.h +8 -0
@@ -6,6 +6,7 @@ typedef struct QEMUAccel {int (*info)(CPUState *env,char *buf);int (*profile)(CPUState *env,char *buf);void (*set_notdirty)(ram_addr_t addr); +void (*modify_page)(ram_addr_t addr,int dirty_flags); } QEMUAccel;extern QEMUAccel *current_accel;
@@ -58,3 +59,10 @@ static inline void accel_set_notdirty(target_ulong addr)if (current_accel && current_accel->set_notdirty) current_accel->set_notdirty (addr); } + +static inline void accel_modify_page (target_ulong addr,int dirty_flags) +{ +if (current_accel && current_accel->modify_page) + current_accel->modify_page (addr, dirty_flags); +} +
exec-all.h +1 -1
@@ -376,7 +376,7 @@ int kqemu_cpu_exec(CPUState *env);void kqemu_flush_page (CPUState *env,target_ulong addr);void kqemu_flush (CPUState *env,int global);void kqemu_set_notdirty (ram_addr_t ram_addr); -void kqemu_modify_page (CPUState *env,ram_addr_t ram_addr); +void kqemu_modify_page (ram_addr_t ram_addr,int dirty_flags);void kqemu_set_phys_mem (uint64_t start_addr,ram_addr_t size,ram_addr_t phys_offset);void kqemu_cpu_interrupt (CPUState *env);
exec.c +12 -15
@@ -2217,12 +2217,11 @@ static void notdirty_mem_writeb(void *opaque, target_phys_addr_t ram_addr, dirty_flags = phys_ram_dirty[ram_addr >>TARGET_PAGE_BITS ];#endif } +stb_p (phys_ram_base + ram_addr, val); -#ifdef USE_KQEMU -if (cpu_single_env->kqemu_enabled && - (dirty_flags &KQEMU_MODIFY_PAGE_MASK ) !=KQEMU_MODIFY_PAGE_MASK ) -kqemu_modify_page (cpu_single_env, ram_addr); -#endif + +accel_modify_page (ram_addr, dirty_flags); + dirty_flags |= (0xff & ~CODE_DIRTY_FLAG ); phys_ram_dirty[ram_addr >>TARGET_PAGE_BITS ] = dirty_flags;/* we remove the notdirty callback only if the code has been
@@ -2242,12 +2241,11 @@ static void notdirty_mem_writew(void *opaque, target_phys_addr_t ram_addr, dirty_flags = phys_ram_dirty[ram_addr >>TARGET_PAGE_BITS ];#endif } +stw_p (phys_ram_base + ram_addr, val); -#ifdef USE_KQEMU -if (cpu_single_env->kqemu_enabled && - (dirty_flags &KQEMU_MODIFY_PAGE_MASK ) !=KQEMU_MODIFY_PAGE_MASK ) -kqemu_modify_page (cpu_single_env, ram_addr); -#endif + +accel_modify_page (ram_addr, dirty_flags); + dirty_flags |= (0xff & ~CODE_DIRTY_FLAG ); phys_ram_dirty[ram_addr >>TARGET_PAGE_BITS ] = dirty_flags;/* we remove the notdirty callback only if the code has been
@@ -2267,12 +2265,11 @@ static void notdirty_mem_writel(void *opaque, target_phys_addr_t ram_addr, dirty_flags = phys_ram_dirty[ram_addr >>TARGET_PAGE_BITS ];#endif } +stl_p (phys_ram_base + ram_addr, val); -#ifdef USE_KQEMU -if (cpu_single_env->kqemu_enabled && - (dirty_flags &KQEMU_MODIFY_PAGE_MASK ) !=KQEMU_MODIFY_PAGE_MASK ) -kqemu_modify_page (cpu_single_env, ram_addr); -#endif + +accel_modify_page (ram_addr, dirty_flags); + dirty_flags |= (0xff & ~CODE_DIRTY_FLAG ); phys_ram_dirty[ram_addr >>TARGET_PAGE_BITS ] = dirty_flags;/* we remove the notdirty callback only if the code has been
kqemu.c +15 -11
@@ -345,16 +345,6 @@ void kqemu_set_notdirty(ram_addr_t ram_addr) ram_pages_to_update[nb_ram_pages_to_update++] = ram_addr; } -QEMUAccel kqemu_accel = { - .cpu_interrupt = kqemu_cpu_interrupt, - .init_env = kqemu_init_env, - .flush_cache = kqemu_flush, - .flush_page = kqemu_flush_page, - .info = kqemu_info, - .profile = kqemu_profile, - .set_notdirty = kqemu_set_notdirty, -}; -static void kqemu_reset_modified_ram_pages (void ) {int i;
@@ -367,7 +357,7 @@ static void kqemu_reset_modified_ram_pages(void) nb_modified_ram_pages =0 ; } -void kqemu_modify_page (CPUState *env,ram_addr_t ram_addr) +void kqemu_modify_page (ram_addr_t ram_addr,int dirty_flags) {unsigned long page_index;int ret;
@@ -375,6 +365,8 @@ void kqemu_modify_page(CPUState *env, ram_addr_t ram_addr)DWORD temp;#endif +if ((dirty_flags &KQEMU_MODIFY_PAGE_MASK ) !=KQEMU_MODIFY_PAGE_MASK ) +return ; page_index = ram_addr >>TARGET_PAGE_BITS ;if (!modified_ram_pages_table[page_index]) {#if 0
@@ -443,6 +435,18 @@ void kqemu_set_phys_mem(uint64_t start_addr, ram_addr_t size, } } +QEMUAccel kqemu_accel = { + .cpu_interrupt = kqemu_cpu_interrupt, + .init_env = kqemu_init_env, + .flush_cache = kqemu_flush, + .flush_page = kqemu_flush_page, + .info = kqemu_info, + .profile = kqemu_profile, + .set_notdirty = kqemu_set_notdirty, + .modify_page = kqemu_modify_page, +}; + +struct fpstate {uint16_t fpuc;uint16_t dummy1;
Signature · 1 line
1.5.5.1
PATCH 11/20 remove kqemu reference from hw/pc.c
Instead, route cpu_get_ticks through accel driver.
--- accel.h | 9 +++++++++ hw/pc.c | 13 ++----------- kqemu.c | 4 ++++ 3 files changed, 15 insertions(+), 11 deletions(-)
accel.h +9 -0
@@ -7,6 +7,7 @@ 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); +uint64_t (*get_real_ticks)(void ); } QEMUAccel;extern QEMUAccel *current_accel;
@@ -66,3 +67,11 @@ static inline void accel_modify_page(target_ulong addr, int dirty_flags) current_accel->modify_page (addr, dirty_flags); } +int64_t cpu_get_ticks (void ); + +static inline uint64_t accel_get_real_ticks (void ) +{ +if (current_accel && current_accel->get_real_ticks) +return current_accel->get_real_ticks (); +return cpu_get_ticks (); +}
hw/pc.c +2 -11
@@ -32,6 +32,7 @@#include "smbus.h" #include "boards.h" #include "console.h" +#include "accel.h" /* output Bochs bios info messages */ //#define DEBUG_BIOS
@@ -73,17 +74,7 @@ static void ioportF0_write(void *opaque, uint32_t addr, uint32_t data)/* TSC handling */ uint64_t cpu_get_tsc (CPUX86State *env) { -/* Note: when using kqemu, it is more logical to return the host TSC -because kqemu does not trap the RDTSC instruction for -performance reasons */ -#if USE_KQEMU -if (env->kqemu_enabled) { -return cpu_get_real_ticks (); - } else -#endif - { -return cpu_get_ticks (); - } +return accel_get_real_ticks (); }/* SMM support */
kqemu.c +4 -0
@@ -444,6 +444,10 @@ QEMUAccel kqemu_accel = { .profile = kqemu_profile, .set_notdirty = kqemu_set_notdirty, .modify_page = kqemu_modify_page, +/* Note: when using kqemu, it is more logical to return the host TSC +because kqemu does not trap the RDTSC instruction for +performance reasons */ + .get_real_ticks = cpu_get_real_ticks, };
Signature · 1 line
1.5.5.1
PATCH 12/20 build list of available accelerators
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.
--- accel.h | 43 +++++++++++++++++++++++++++++++++++++++++-- exec.c | 4 +--- kqemu.c | 11 +++++++++-- monitor.c | 18 ++++++++++++++++-- vl.c | 1 + 5 files changed, 68 insertions(+), 9 deletions(-)
accel.h +41 -2
@@ -1,6 +1,8 @@ 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);
@@ -10,11 +12,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 void register_qemu_accel (QEMUAccel *accel) +static inline int register_qemu_accel (QEMUAccel *accel) { - current_accel = accel; +QEMUCont *new; + + new =qemu_mallocz (sizeof (*head)); + + new->acc = accel; + new->active =0 ; + new->next = head; + head = new; + +return 0 ; +} + +static inline QEMUCont *get_accel_head (void ) +{ +return head; }static inline void accel_cpu_interrupt (CPUState *env)
@@ -23,6 +47,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)
exec.c +1 -3
@@ -435,9 +435,7 @@ void cpu_exec_init_all(unsigned long tb_size)#if !defined(CONFIG_USER_ONLY )io_mem_init ();#endif -#ifdef USE_KQEMU -kqemu_start (); -#endif +accel_start (); }void cpu_exec_init (CPUState *env)
kqemu.c +9 -2
@@ -155,7 +155,6 @@ static void kqemu_update_cpuid(CPUState *env)accelerated code */ } -QEMUAccel kqemu_accel;extern int smp_cpus;int kqemu_start (void )
@@ -240,7 +239,6 @@ int kqemu_start(void) } nb_pages_to_flush =0 ; nb_ram_pages_to_update =0 ; -register_qemu_accel (&kqemu_accel);qpi_init ();return 0 ;
@@ -436,8 +434,10 @@ void kqemu_set_phys_mem(uint64_t start_addr, ram_addr_t size, }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,
@@ -450,6 +450,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;
monitor.c +16 -2
@@ -1218,6 +1218,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 1024static void do_info_accelerator (void ) {
@@ -1231,8 +1243,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" ); }
vl.c +1 -0
@@ -242,6 +242,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)
Signature · 1 line
1.5.5.1
PATCH 13/20 decorate application name
--- accel.h | 10 ++++++++++ sdl.c | 7 +++++-- vl.c | 12 ++++++++++++ vnc.c | 6 ++++-- 4 files changed, 31 insertions(+), 4 deletions(-)
accel.h +10 -0
@@ -47,6 +47,15 @@ static inline void accel_cpu_interrupt(CPUState *env) current_accel->cpu_interrupt (env); } +static inline char *accel_get_name (void ) +{ +if (current_accel && current_accel->name) +return current_accel->name; +return NULL ; +} + +void decorate_app_name (void ); +static inline void accel_start (void ) {/* The top accelerator in the list gets tried first, but if it fails,
@@ -56,6 +65,7 @@ static inline void accel_start(void)if (tmp->acc && tmp->acc->start && (!(tmp->acc->start ())) ) { tmp->active =1 ; current_accel = tmp->acc; +decorate_app_name ();break ; } tmp = tmp->next;
sdl.c +5 -2
@@ -218,9 +218,12 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)kbd_put_keycode (keycode &0x7f ); } +extern char qemu_app_name[]; +static void sdl_update_caption (void ) {char buf[1024 ]; +char qemu_app_namei[512 ] ="QEMU" ;const char *status ="" ;if (!vm_running)
@@ -233,9 +236,9 @@ static void sdl_update_caption(void) }if (qemu_name) -snprintf (buf,sizeof (buf),"QEMU (%s)%s" , qemu_name, status); +snprintf (buf,sizeof (buf),"%s (%s)%s" , qemu_app_name, qemu_name, status);else -snprintf (buf,sizeof (buf),"QEMU%s" , status); +snprintf (buf,sizeof (buf),"%s%s" , qemu_app_name, status);SDL_WM_SetCaption (buf,"QEMU" ); }
vl.c +12 -0
@@ -241,8 +241,20 @@ struct drive_opt {static CPUState *cur_cpu;static CPUState *next_cpu;static int event_pending =1 ; +QEMUAccel *current_accel;QEMUCont *head =NULL ; +char qemu_app_name[20 ] ="QEMU" ; + +void decorate_app_name (void ) +{ +char *name =accel_get_name (); + +if (!name) +sprintf (qemu_app_name,"QEMU" ); +else +sprintf (qemu_app_name,"QEMU/%s" , name); +}#define TFR (expr) do { if ((expr) != -1) break; } while (errno == EINTR)
vnc.c +4 -2
@@ -1265,6 +1265,8 @@ static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len)return 0 ; } +extern char qemu_app_name[]; +static int protocol_client_init (VncState *vs,uint8_t *data,size_t len) {char pad[3 ] = {0 ,0 ,0 };
@@ -1315,9 +1317,9 @@ static int protocol_client_init(VncState *vs, uint8_t *data, size_t len)vnc_write (vs, pad,3 );/* padding */ if (qemu_name) - size =snprintf (buf,sizeof (buf),"QEMU (%s)" , qemu_name); + size =snprintf (buf,sizeof (buf),"%s (%s)" , qemu_app_name, qemu_name);else - size =snprintf (buf,sizeof (buf),"QEMU" ); + size =snprintf (buf,sizeof (buf),"%s" , qemu_app_name);vnc_write_u32 (vs, size);vnc_write (vs, buf, size);
Signature · 1 line
1.5.5.1
PATCH 14/20 tsc: kvm will use it, but it is pretty general
--- target-i386/cpu.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
target-i386/cpu.h +1 -0
@@ -559,6 +559,7 @@ typedef struct CPUX86State {target_ulong kernelgsbase;#endif +uint64_t tsc;uint64_t pat;/* exception/interrupt handling */
Signature · 1 line
1.5.5.1
PATCH 15/20 shift for masks.
kvm uses, but pretty general
--- target-i386/cpu.h | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
target-i386/cpu.h +5 -2
@@ -178,8 +178,11 @@#define HF2_NMI_MASK (1 << HF2_NMI_SHIFT)#define HF2_VINTR_MASK (1 << HF2_VINTR_SHIFT) -#define CR0_PE_MASK (1 << 0) -#define CR0_MP_MASK (1 << 1) +#define CR0_PE_SHIFT 0 +#define CR0_MP_SHIFT 1 + +#define CR0_PE_MASK (1 << CR0_PE_SHIFT) +#define CR0_MP_MASK (1 << CR0_MP_SHIFT)#define CR0_EM_MASK (1 << 2)#define CR0_TS_MASK (1 << 3)#define CR0_ET_MASK (1 << 4)
Signature · 1 line
1.5.5.1
PATCH 16/20 small changes in headers needed to acomodate kvm files as is.
--- cpu-defs.h | 1 + target-i386/cpu.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletions(-)
cpu-defs.h +1 -0
@@ -169,6 +169,7 @@ typedef struct CPUTLBEntry {void *next_cpu;/* next CPU sharing TB cache */ \int cpu_index;/* CPU index (informative) */ \int running;/* Nonzero if cpu is currently running(usermode). */ \ +int thread_id; \/* user data */ \void *opaque; \ \
target-i386/cpu.h +3 -1
@@ -199,7 +199,8 @@#define CR4_PAE_MASK (1 << 5)#define CR4_PGE_MASK (1 << 7)#define CR4_PCE_MASK (1 << 8) -#define CR4_OSFXSR_MASK (1 << 9) +#define CR4_OSFXSR_SHIFT 9 +#define CR4_OSFXSR_MASK (1 << CR4_OSFXSR_SHIFT)#define CR4_OSXMMEXCPT_MASK (1 << 10)#define PG_PRESENT_BIT 0
@@ -595,6 +596,7 @@ typedef struct CPUX86State {int kqemu_enabled;int last_io_time;#endif +/* in order to simplify APIC support, we leave this pointer to the user */ struct APICState *apic_state;
Signature · 1 line
1.5.5.1
PATCH 17/20 add hook to cpu_register_physical_memory
kqemu has a hook in it, so add an accel wrapper. However, we still provide a double underlined version which does not call the wrapper. That's basically because kqemu call cpu_register_physical_memory itself during its initialization.
--- accel.h | 11 +++++++++++ exec.c | 22 ++++++++++++---------- kqemu.c | 1 + 3 files changed, 24 insertions(+), 10 deletions(-)
accel.h +11 -0
@@ -10,6 +10,9 @@ typedef struct QEMUAccel {void (*set_notdirty)(ram_addr_t addr);void (*modify_page)(ram_addr_t addr,int dirty_flags);uint64_t (*get_real_ticks)(void ); +void (*register_physical_memory)(uint64_t start_addr, +ram_addr_t size,ram_addr_t phys_offset); + } QEMUAccel; typedef struct QEMUCont {
@@ -124,3 +127,11 @@ static inline uint64_t accel_get_real_ticks(void)return current_accel->get_real_ticks ();return cpu_get_ticks (); } + +static inline void accel_register_phys_mem (uint64_t start_addr, +ram_addr_t size, +ram_addr_t phys_offset) +{ +if (current_accel && current_accel->register_physical_memory) + current_accel->register_physical_memory (start_addr, size, phys_offset); +}
exec.c +12 -10
@@ -2064,9 +2064,9 @@ static void *subpage_init (target_phys_addr_t base, ram_addr_t *phys,/* register physical memory. 'size' must be a multiple of the target page size. If (phys_offset & ~TARGET_PAGE_MASK) != 0, then it is an io memory page */ -void cpu_register_physical_memory (target_phys_addr_t start_addr, -ram_addr_t size, -ram_addr_t phys_offset) +void __cpu_register_physical_memory (target_phys_addr_t start_addr, +ram_addr_t size, +ram_addr_t phys_offset) {target_phys_addr_t addr, end_addr;PhysPageDesc *p;
@@ -2074,13 +2074,6 @@ void cpu_register_physical_memory(target_phys_addr_t start_addr,ram_addr_t orig_size = size;void *subpage; -#ifdef USE_KQEMU -/* XXX: should not depend on cpu context */ - env = first_cpu; -if (env && env->kqemu_enabled) { -kqemu_set_phys_mem (start_addr, size, phys_offset); - } -#endif size = (size +TARGET_PAGE_SIZE -1 ) &TARGET_PAGE_MASK ; end_addr = start_addr + (target_phys_addr_t )size;for (addr = start_addr; addr != end_addr; addr +=TARGET_PAGE_SIZE ) {
@@ -2138,6 +2131,15 @@ void cpu_register_physical_memory(target_phys_addr_t start_addr, } } +void cpu_register_physical_memory (target_phys_addr_t start_addr, +ram_addr_t size, +ram_addr_t phys_offset) +{ +accel_register_phys_mem (start_addr, size, phys_offset); + +__cpu_register_physical_memory (start_addr, size, phys_offset); +} +/* XXX: temporary until new memory mapping API */ ram_addr_t cpu_get_physical_page_desc (target_phys_addr_t addr) {
kqemu.c +1 -0
@@ -448,6 +448,7 @@ QEMUAccel kqemu_accel = {because kqemu does not trap the RDTSC instruction for performance reasons */ .get_real_ticks = cpu_get_real_ticks, + .register_physical_memory = kqemu_set_phys_mem, };static void __attribute__((constructor))register_kqemu (void )
Signature · 1 line
1.5.5.1
PATCH 18/20 accel_trace_io
kqemu keeps trace of the last io done. Do it through an accel_wrapper.
--- accel.h | 16 +++++++++++++++- kqemu.c | 18 ++++++++++++++++++ vl.c | 30 ++++++------------------------ 3 files changed, 39 insertions(+), 25 deletions(-)
accel.h +15 -1
@@ -12,7 +12,8 @@ typedef struct QEMUAccel {uint64_t (*get_real_ticks)(void );void (*register_physical_memory)(uint64_t start_addr,ram_addr_t size,ram_addr_t phys_offset); - +void (*trace_io)(CPUState *env); +int (*break_loop)(CPUState *env); } QEMUAccel; typedef struct QEMUCont {
@@ -135,3 +136,16 @@ static inline void accel_register_phys_mem(uint64_t start_addr,if (current_accel && current_accel->register_physical_memory) current_accel->register_physical_memory (start_addr, size, phys_offset); } + +static inline void accel_trace_io (CPUState *env) +{ +if (current_accel && current_accel->trace_io) + current_accel->trace_io (env); +} + +static inline int accel_break_loop (CPUState *env) +{ +if (current_accel && current_accel->break_loop) +return current_accel->break_loop (env); +return 0 ; +}
kqemu.c +18 -0
@@ -433,6 +433,22 @@ void kqemu_set_phys_mem(uint64_t start_addr, ram_addr_t size, } } +void kqemu_trace_io (CPUState *env) +{ +if (env) + env->last_io_time =cpu_get_time_fast (); +} + +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 ) { +return 1 ; + } +return 0 ; +} +QEMUAccel kqemu_accel = { .name ="KQEMU" , .cpu_interrupt = kqemu_cpu_interrupt,
@@ -449,6 +465,8 @@ QEMUAccel kqemu_accel = {performance reasons */ .get_real_ticks = cpu_get_real_ticks, .register_physical_memory = kqemu_set_phys_mem, + .trace_io = kqemu_trace_io, + .break_loop = kqemu_break_loop, };static void __attribute__((constructor))register_kqemu (void )
vl.c +6 -24
@@ -399,10 +399,7 @@ void cpu_outb(CPUState *env, int addr, int val)fprintf (logfile,"outb: %04x %02x\n" , addr, val);#endif ioport_write_table[0 ][addr](ioport_opaque[addr], addr, val); -#ifdef USE_KQEMU -if (env) - env->last_io_time =cpu_get_time_fast (); -#endif +accel_trace_io (env); }void cpu_outw (CPUState *env,int addr,int val)
@@ -412,10 +409,7 @@ void cpu_outw(CPUState *env, int addr, int val)fprintf (logfile,"outw: %04x %04x\n" , addr, val);#endif ioport_write_table[1 ][addr](ioport_opaque[addr], addr, val); -#ifdef USE_KQEMU -if (env) - env->last_io_time =cpu_get_time_fast (); -#endif +accel_trace_io (env); }void cpu_outl (CPUState *env,int addr,int val)
@@ -425,10 +419,7 @@ void cpu_outl(CPUState *env, int addr, int val)fprintf (logfile,"outl: %04x %08x\n" , addr, val);#endif ioport_write_table[2 ][addr](ioport_opaque[addr], addr, val); -#ifdef USE_KQEMU -if (env) - env->last_io_time =cpu_get_time_fast (); -#endif +accel_trace_io (env); }int cpu_inb (CPUState *env,int addr)
@@ -439,10 +430,7 @@ int cpu_inb(CPUState *env, int addr)if (loglevel &CPU_LOG_IOPORT )fprintf (logfile,"inb : %04x %02x\n" , addr, val);#endif -#ifdef USE_KQEMU -if (env) - env->last_io_time =cpu_get_time_fast (); -#endif +accel_trace_io (env);return val; }
@@ -454,10 +442,7 @@ int cpu_inw(CPUState *env, int addr)if (loglevel &CPU_LOG_IOPORT )fprintf (logfile,"inw : %04x %04x\n" , addr, val);#endif -#ifdef USE_KQEMU -if (env) - env->last_io_time =cpu_get_time_fast (); -#endif +accel_trace_io (env);return val; }
@@ -469,10 +454,7 @@ int cpu_inl(CPUState *env, int addr)if (loglevel &CPU_LOG_IOPORT )fprintf (logfile,"inl : %04x %08x\n" , addr, val);#endif -#ifdef USE_KQEMU -if (env) - env->last_io_time =cpu_get_time_fast (); -#endif +accel_trace_io (env);return val; }
Signature · 1 line
1.5.5.1
PATCH 20/20 add next_cpu_index
In reply to Glauber Costaseparate the logic for calculating the next cpu index from cpu creation. It will allow others to query what's the next cpu index to be created before cpu creation.
--- exec.c | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-)
exec.c +12 -6
@@ -438,21 +438,27 @@ void cpu_exec_init_all(unsigned long tb_size)accel_start (); } -void cpu_exec_init (CPUState *env) +int next_cpu_index () {CPUState **penv; -int cpu_index; +int cpu_index =0 ; - env->next_cpu =NULL ; penv = &first_cpu; - cpu_index =0 ; +while (*penv !=NULL ) { penv = (CPUState **)&(*penv)->next_cpu; cpu_index++; } - env->cpu_index = cpu_index; +return cpu_index; +} + +void cpu_exec_init (CPUState *env) +{ + env->next_cpu =NULL ; + env->cpu_index =next_cpu_index (); +if (env->cpu_index ==0 ) + first_cpu = env; env->nb_watchpoints =0 ; - *penv = env; }static inline void invalidate_page_bitmap (PageDesc *p)
Signature · 1 line
1.5.5.1
PATCH 19/20 get_env accel wrapper
In reply to Glauber CostaAllow the current accelerator to provide it's own, customized address of the CPUState structure used for the env variable.
--- accel.h | 8 ++++++++ target-i386/helper.c | 2 +- 2 files changed, 9 insertions(+), 1 deletions(-)
accel.h +8 -0
@@ -1,6 +1,7 @@ typedef struct QEMUAccel { char *name; void (*cpu_interrupt)(CPUState *env); + CPUState *(*get_env)(void); void (*init_env)(CPUState *env); int (*start)(void); void (*flush_cache)(CPUState *env, int global);
@@ -76,6 +77,13 @@ static inline void accel_start(void) } } +static inline CPUState *accel_get_env (void ) +{ +if (current_accel && current_accel->get_env) +return current_accel->get_env (); +return qemu_mallocz (sizeof (CPUState)); +} +static inline void accel_init_env (CPUState *env) {if (current_accel && current_accel->init_env)
target-i386/helper.c +1 -1
@@ -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);
Signature · 1 line
1.5.5.1