New shot at QEMUAccel
cover New shot at QEMUAccel
Hi guys,
This is a new version of the QEMUAccel work. To start with, I decided to keep the name for now. We don't have that many functions that are not cpu-related to justify splitting the structure into many. Plus, this is one of the less confusing names we came up with.
The code I'm posting is tested with kqemu for both i386 and x86_64, and it works. So, if you guys feel like it, I can say it's ready for inclusion (which obviously does not mean bug-free). It is not complete, however.
There are still some pieces of kqemu code that does not work. Specially the interrupt code in cpu-exec.c , which relies on the tricky longjmp.
Comments are very welcome.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 1/13 make cpu_exec_init symmetric
we put all the code that needs to be executed only at cpu0 out of cpu_exec_init(), in exec_init(). It is executed before machine_init(), and only once. With this change, code cpu_exec_init() is completely symmetric.
--- exec-all.h | 1 + exec.c | 15 +++++++++------ vl.c | 1 + 3 files changed, 11 insertions(+), 6 deletions(-)
exec-all.h +1 -0
@@ -82,6 +82,7 @@ int cpu_restore_state_copy(struct TranslationBlock *tb, void *puc);void cpu_resume_from_signal (CPUState *env1,void *puc);void cpu_exec_init (CPUState *env); +void exec_init (void );int page_unprotect (target_ulong address,unsigned long pc,void *puc);void tb_invalidate_phys_page_range (target_phys_addr_t start,target_phys_addr_t end,int is_cpu_write_access);
exec.c +9 -6
@@ -327,17 +327,20 @@ static void tlb_unprotect_code_phys(CPUState *env, ram_addr_t ram_addr, target_ulong vaddr);#endif +/* Must be called once before any of attempts to call cpu_init */ +void exec_init (void ) +{ +cpu_gen_init (); + code_gen_ptr = code_gen_buffer; +page_init (); +io_mem_init (); +} +void cpu_exec_init (CPUState *env) {CPUState **penv;int cpu_index; -if (!code_gen_ptr) { -cpu_gen_init (); - code_gen_ptr = code_gen_buffer; -page_init (); -io_mem_init (); - } env->next_cpu =NULL ; penv = &first_cpu; cpu_index =0 ;
vl.c +1 -0
@@ -8576,6 +8576,7 @@ int main(int argc, char **argv) } } +exec_init (); machine->init (ram_size, vga_ram_size, boot_devices, ds, kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
Signature · 7 lines
1.5.5 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 2/13 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 | 3 +++ kqemu.c | 10 +++++++--- target-i386/helper2.c | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-)
exec.c +3 -0
@@ -334,6 +334,9 @@ void exec_init(void) code_gen_ptr = code_gen_buffer;page_init ();io_mem_init (); +#ifdef USE_KQEMU +kqemu_start (); +#endif }void cpu_exec_init (CPUState *env)
kqemu.c +7 -3
@@ -159,7 +159,7 @@ static void kqemu_update_cpuid(CPUState *env)accelerated code */ } -int kqemu_init (CPUState *env) +int kqemu_start (void ) {struct kqemu_init init;int ret, version;
@@ -238,13 +238,17 @@ 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 ;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/helper2.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 · 7 lines
1.5.5 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 3/13 introduce QEMUAccel and fill it with interrupt specific driver
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.
--- block-raw-posix.c | 5 ----- exec-all.h | 18 +++++++++++++++++- exec.c | 2 ++ kqemu.c | 27 +++++++++++++++++---------- vl.c | 6 +----- 5 files changed, 37 insertions(+), 21 deletions(-)
block-raw-posix.c +0 -5
@@ -250,11 +250,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-all.h +17 -1
@@ -578,6 +578,23 @@ static inline target_ulong get_phys_addr_code(CPUState *env1, target_ulong addr) }#endif +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); +} +#ifdef USE_KQEMU #define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG))
@@ -587,7 +604,6 @@ 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_modify_page (CPUState *env,ram_addr_t ram_addr); -void kqemu_cpu_interrupt (CPUState *env);void kqemu_record_dump (void );static inline int kqemu_is_ok (CPUState *env)
exec.c +2 -0
@@ -1256,6 +1256,8 @@ void cpu_interrupt(CPUState *env, int mask)tb_reset_jump_recursive (tb);resetlock (&interrupt_lock); } + +accel_cpu_interrupt (env); }void cpu_reset_interrupt (CPUState *env,int mask)
kqemu.c +17 -10
@@ -159,6 +159,8 @@ static void kqemu_update_cpuid(CPUState *env)accelerated code */ } +QEMUAccel kqemu_accel; +int kqemu_start (void ) {struct kqemu_init init;
@@ -240,6 +242,7 @@ int kqemu_start(void) } nb_pages_to_flush =0 ; nb_ram_pages_to_update =0 ; +register_qemu_accel (&kqemu_accel);return 0 ; }
@@ -249,6 +252,20 @@ void kqemu_init_env(CPUState *env) env->kqemu_enabled = kqemu_allowed; } +void kqemu_cpu_interrupt (CPUState *env) +{ +#if defined(_WIN32) &&KQEMU_VERSION >=0x010101 +/* cancelling the I/O request causes KQEMU to finish executing the +current block and successfully returning. */ +CancelIo (kqemu_fd); +#endif +} + +QEMUAccel kqemu_accel = { + .cpu_interrupt = kqemu_cpu_interrupt, +}; + +void kqemu_flush_page (CPUState *env,target_ulong addr) {#if defined(DEBUG )
@@ -906,14 +923,4 @@ int kqemu_cpu_exec(CPUState *env) }return 0 ; } - -void kqemu_cpu_interrupt (CPUState *env) -{ -#if defined(_WIN32) &&KQEMU_VERSION >=0x010101 -/* cancelling the I/O request causes KQEMU to finish executing the -current block and successfully returning. */ -CancelIo (kqemu_fd); -#endif -} -#endif
vl.c +1 -5
@@ -239,6 +239,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 +1200,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 · 7 lines
1.5.5 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 4/13 init env made accel driver
--- exec-all.h | 8 +++++++- kqemu.c | 1 + target-i386/helper2.c | 4 +--- 3 files changed, 9 insertions(+), 4 deletions(-)
exec-all.h +7 -1
@@ -580,6 +580,7 @@ static inline target_ulong get_phys_addr_code(CPUState *env1, target_ulong addr)typedef struct QEMUAccel {void (*cpu_interrupt)(CPUState *env); +void (*init_env)(CPUState *env); }QEMUAccel ;extern QEMUAccel *current_accel;
@@ -595,10 +596,15 @@ static inline void accel_cpu_interrupt(CPUState *env) 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); +} +#ifdef USE_KQEMU #define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG)) -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);
kqemu.c +1 -0
@@ -263,6 +263,7 @@ void kqemu_cpu_interrupt(CPUState *env)QEMUAccel kqemu_accel = { .cpu_interrupt = kqemu_cpu_interrupt, + .init_env = kqemu_init_env, };
target-i386/helper2.c +1 -3
@@ -112,9 +112,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 · 7 lines
1.5.5 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 5/13 wrap cache flushing functions into accel drivers
--- exec-all.h | 16 ++++++++++++++-- exec.c | 12 ++---------- kqemu.c | 15 +++++++++------ 3 files changed, 25 insertions(+), 18 deletions(-)
exec-all.h +14 -2
@@ -581,6 +581,8 @@ static inline target_ulong get_phys_addr_code(CPUState *env1, target_ulong addr)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;
@@ -602,12 +604,22 @@ 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); +} +#ifdef USE_KQEMU #define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG))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_modify_page (CPUState *env,ram_addr_t ram_addr);void kqemu_record_dump (void );
exec.c +2 -10
@@ -1438,11 +1438,7 @@ void tlb_flush(CPUState *env, int flush_global)#if !defined(CONFIG_SOFTMMU )munmap ((void *)MMAP_AREA_START ,MMAP_AREA_END -MMAP_AREA_START );#endif -#ifdef USE_KQEMU -if (env->kqemu_enabled) { -kqemu_flush (env, flush_global); - } -#endif +accel_flush_cache (env, flush_global); tlb_flush_count++; }
@@ -1488,11 +1484,7 @@ void tlb_flush_page(CPUState *env, target_ulong addr)if (addr <MMAP_AREA_END )munmap ((void *)addr,TARGET_PAGE_SIZE );#endif -#ifdef USE_KQEMU -if (env->kqemu_enabled) { -kqemu_flush_page (env, addr); - } -#endif +accel_flush_page (env, addr); }/* update the TLBs so that writes to code in the virtual page 'addr'
kqemu.c +9 -6
@@ -261,12 +261,6 @@ void kqemu_cpu_interrupt(CPUState *env)#endif } -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 )
@@ -290,6 +284,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 · 7 lines
1.5.5 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 6/13 turn info kqemu into generic info accelerator
--- exec-all.h | 8 ++++++++ kqemu.c | 24 ++++++++++++++++++++++++ monitor.c | 36 +++++++++++++----------------------- 3 files changed, 45 insertions(+), 23 deletions(-)
exec-all.h +8 -0
@@ -583,6 +583,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;
@@ -616,6 +617,13 @@ static inline void accel_flush_page(CPUState *env, target_ulong addr) 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 ; +} +#ifdef USE_KQEMU #define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG))
kqemu.c +24 -0
@@ -284,11 +284,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 "exec-all.h" #include <dirent.h> #ifdef CONFIG_PROFILER
@@ -1165,34 +1166,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
@@ -1422,8 +1412,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 · 7 lines
1.5.5 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 7/13 separate accelerator part of info profiler
--- exec-all.h | 8 ++++++++ kqemu.c | 35 +++++++++++++++++++++++++++++++++++ monitor.c | 27 ++++++--------------------- 3 files changed, 49 insertions(+), 21 deletions(-)
exec-all.h +8 -0
@@ -584,6 +584,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;
@@ -624,6 +625,13 @@ static inline int accel_info(CPUState *env, char *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 ; +} +#ifdef USE_KQEMU #define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG))
kqemu.c +35 -0
@@ -51,6 +51,10 @@#include <fcntl.h> #include "kqemu.h" +#ifdef CONFIG_PROFILER +#include "qemu-timer.h" /* for ticks_per_sec */ +#endif +/* compatibility stuff */ #ifndef KQEMU_RET_SYSCALL #define KQEMU_RET_SYSCALL 0x0300/* syscall insn */
@@ -307,12 +311,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
@@ -1187,17 +1187,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 ;
@@ -1205,24 +1202,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 · 7 lines
1.5.5 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 8/13 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
@@ -1053,14 +1053,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;extern int64_t dyngen_tb_count1;extern int64_t dyngen_tb_count;
kqemu.h +6 -0
@@ -26,6 +26,12 @@#define KQEMU_VERSION 0x010300 +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 {uint32_t selector;unsigned long base;
Signature · 7 lines
1.5.5 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 9/13 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
@@ -164,6 +164,7 @@ static void kqemu_update_cpuid(CPUState *env) }QEMUAccel kqemu_accel; +extern int smp_cpus;int kqemu_start (void ) {
@@ -173,7 +174,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
@@ -8357,10 +8357,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 · 7 lines
1.5.5 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 10/13 set_notdirty goes through accel wrapper
--- exec-all.h | 8 +++++++- exec.c | 18 +++++++----------- kqemu.c | 23 +++++++++++------------ 3 files changed, 25 insertions(+), 24 deletions(-)
exec-all.h +7 -1
@@ -585,6 +585,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;
@@ -632,11 +633,16 @@ static inline int accel_profile(CPUState *env, char *buf)return 0 ; } +static inline void accel_set_notdirty (target_ulong addr) +{ +if (current_accel && current_accel->set_notdirty) + current_accel->set_notdirty (addr); +} +#ifdef USE_KQEMU #define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG))int kqemu_cpu_exec (CPUState *env); -void kqemu_set_notdirty (CPUState *env,ram_addr_t ram_addr);void kqemu_modify_page (CPUState *env,ram_addr_t ram_addr);void kqemu_record_dump (void );
exec.c +7 -11
@@ -1531,18 +1531,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
@@ -342,18 +342,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 ) {
@@ -369,6 +358,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 · 7 lines
1.5.5 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 11/13 wrap modify_page through accel calls
--- exec-all.h | 8 +++++++- exec.c | 24 +++++++++--------------- kqemu.c | 26 +++++++++++++++----------- 3 files changed, 31 insertions(+), 27 deletions(-)
exec-all.h +7 -1
@@ -586,6 +586,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;
@@ -639,11 +640,16 @@ static inline void accel_set_notdirty(target_ulong addr) 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); +} +#ifdef USE_KQEMU #define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG))int kqemu_cpu_exec (CPUState *env); -void kqemu_modify_page (CPUState *env,ram_addr_t ram_addr);void kqemu_record_dump (void );static inline int kqemu_is_ok (CPUState *env)
exec.c +9 -15
@@ -2185,11 +2185,9 @@ static void notdirty_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t#endif }stb_p ((uint8_t *)(long )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
@@ -2211,11 +2209,9 @@ static void notdirty_mem_writew(void *opaque, target_phys_addr_t addr, uint32_t#endif }stw_p ((uint8_t *)(long )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
@@ -2237,11 +2233,9 @@ static void notdirty_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t#endif }stl_p ((uint8_t *)(long )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
@@ -358,16 +358,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;
@@ -380,7 +370,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;
@@ -388,6 +378,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
@@ -411,6 +403,18 @@ void kqemu_modify_page(CPUState *env, ram_addr_t 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, + .modify_page = kqemu_modify_page, +}; + +struct fpstate {uint16_t fpuc;uint16_t dummy1;
Signature · 7 lines
1.5.5 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 12/13 remove kqemu reference from hw/pc.c
Instead, route cpu_get_ticks through accel driver.
--- exec-all.h | 11 +++++++++++ hw/pc.c | 13 ++----------- kqemu.c | 4 ++++ 3 files changed, 17 insertions(+), 11 deletions(-)
exec-all.h +11 -0
@@ -587,6 +587,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;
@@ -646,6 +647,16 @@ 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 (); +} + +#ifdef USE_KQEMU #define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG))
hw/pc.c +2 -11
@@ -32,6 +32,7 @@#include "smbus.h" #include "boards.h" #include "console.h" +#include "exec-all.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
@@ -412,6 +412,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 · 7 lines
1.5.5 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
PATCH 13/13 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.
--- exec-all.h | 43 +++++++++++++++++++++++++++++++++++++++++-- exec.c | 4 +--- kqemu.c | 11 +++++++++-- monitor.c | 18 ++++++++++++++++-- vl.c | 1 + 5 files changed, 68 insertions(+), 9 deletions(-)
exec-all.h +41 -2
@@ -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)
exec.c +1 -3
@@ -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)
kqemu.c +9 -2
@@ -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;
monitor.c +16 -2
@@ -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 1024static 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" ); }
vl.c +1 -0
@@ -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)
Signature · 7 lines
1.5.5 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/