Accelerators: cleaned up version
cover Accelerators: cleaned up version
So as Anthony requested, here's the current state of accelerators.
It's basically whatever was in the repository, but cleaned up and factored as individual patches. I've run my previous tests on it and it seems to work. So if other folks who were also running it can give a test to make sure it still works for you, it would be awesome.
Anthony, if nobody spots anything obvious in this series, can you merge it?
thanks
PATCH 1/21 split kqemu_init into two
From: Glauber Costa <[email protected]>
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
@@ -495,6 +495,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 }#if defined(CPU_SAVE_VERSION ) && !defined(CONFIG_USER_ONLY )
@@ -2207,7 +2210,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 2/21 introduce QEMUAccel and fill it with interrupt specific driver
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
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.
--- 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
Makefile.target +1 -1
@@ -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
accel.c new file +17 -0
@@ -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, +}; +
accel.h new file +20 -0
@@ -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
exec.c +3 -0
@@ -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 */
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 +5 -12
@@ -149,6 +149,8 @@#define SMBD_COMMAND "/usr/sbin/smbd"#endif +#include "accel.h" +//#define DEBUG_UNUSED_IOPORT //#define DEBUG_IOPORT //#define DEBUG_NET
@@ -1317,11 +1319,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 ; }
@@ -7554,14 +7551,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)void qemu_service_io (void ) {CPUState *env = cpu_single_env; -if (env) { +if (env)cpu_interrupt (env,CPU_INTERRUPT_EXIT ); -#ifdef USE_KQEMU -if (env->kqemu_enabled) { -kqemu_cpu_interrupt (env); - } -#endif - } }/***********************************************************/
@@ -8818,6 +8809,8 @@ int main(int argc, char **argv) }#endif +register_qemu_accel (&noaccel); +register_machines (); machine = first_machine; cpu_model =NULL ;
Signature · 1 line
1.5.5.1
[Qemu-devel] Re: [PATCH 02/21] introduce QEMUAccel and fill it with interrupt specific driver
Quoted 140 lines · Glauber Costa
From: Glauber Costa <[email protected]>
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_interruptfunction, to be called after the rawcpu_interrupt.
This has the side effect of, for the kqemu accelerator, callingkqemu_cpu_interrupteverytime, 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 <[email protected]>Signed-off-by Dmitry Baryshkov <[email protected]>--- 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.hMakefile.target +1
-1@@ -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.oaccel.c new file +17
-0@@ -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, +}; +accel.h new file +20
-0@@ -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 exec.c +3
-0@@ -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 */ kqemu.c +4
-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 ;
kqemu.c void kqemu_init_env(CPUState *env) · line 253
Quoted 7 lines
kqemu.c +3
-0@@ -243,6 +247,11 @@ void kqemu_init_env(CPUState *env) env->kqemu_enabled = kqemu_allowed; } +QEMUAccel kqemu_accel = { + .cpu_interrupt = kqemu_cpu_interrupt, +};
The hook kqemu uses is for CPU_INTERRUPT_EXIT which is basically intended to allow IO to run. The fact that it's done via cpu_interrupt is somewhat hackish.
I think a better hook would be something like run_io_handlers. Since this is called from signal handlers, we have to be clear that this code needs to be signal safe. This is compared to say a generic cpu_interrupt hook which doesn't necessarily need to be signal safe.
Regards,
Anthony Liguori
Re: [Qemu-devel] Re: [PATCH 02/21] introduce QEMUAccel and fill it with interrupt specific driver
Quoted 156 lines · Anthony Liguori
Quoted 143 lines · Glauber Costa
From: Glauber Costa <[email protected]>
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_interruptfunction, to be called after the rawcpu_interrupt. This has the side effect of, for the kqemu accelerator, callingkqemu_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 <[email protected]>Signed-off-by Dmitry Baryshkov <[email protected]>--- 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.hMakefile.target +1
-1@@ -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.oaccel.c new file +17
-0@@ -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, +}; +accel.h new file +20
-0@@ -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 exec.c +3
-0@@ -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 */ kqemu.c +4
-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 ;kqemu.c void kqemu_init_env(CPUState *env) · line 253
Quoted 7 lines
kqemu.c +3
-0@@ -243,6 +247,11 @@ void kqemu_init_env(CPUState *env) env->kqemu_enabled = kqemu_allowed; } +QEMUAccel kqemu_accel = { + .cpu_interrupt = kqemu_cpu_interrupt, +};The hook kqemu uses is for
CPU_INTERRUPT_EXITwhich is basically intended to allow IO to run. The fact that it's done viacpu_interruptis somewhat hackish.
Quoted 4 lines
I think a better hook would be something like
run_io_handlers. Since this is called from signal handlers, we have to be clear that this code needs to be signal safe. This is compared to say a genericcpu_interrupthook which doesn't necessarily need to be signal safe.
KVM has code in cpu interrupt. So even if we move kqemu elsewhere, this one might still be useful.
Quoted 6 lines
Regards,
Anthony Liguori
Signature · 5 lines
Glauber Costa. "Free as in Freedom" http://glommer.net "The less confident you are, the more serious you have to act."
PATCH 3/21 init env made accel driver
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
Yet another accel field: init_env
--- accel.c | 1 + accel.h | 7 +++++++ kqemu.c | 1 + target-i386/helper.c | 6 +++--- 4 files changed, 12 insertions(+), 3 deletions(-)
accel.c +1 -0
@@ -13,5 +13,6 @@ int _accel_nop(void)/* Accelerator wrapper for the no-accel (raw qemu) case */ QEMUAccel noaccel = { .cpu_interrupt = accel_nop, + .init_env = accel_nop, };
accel.h +7 -0
@@ -3,6 +3,7 @@typedef struct QEMUAccel {void (*cpu_interrupt)(CPUState *env); +void (*init_env)(CPUState *env); }QEMUAccel ;extern QEMUAccel *current_accel;
@@ -17,4 +18,10 @@ static inline void accel_cpu_interrupt(CPUState *env) { current_accel->cpu_interrupt (env); } + +static inline void accel_init_env (CPUState *env) +{ + current_accel->init_env (env); +} +#endif
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 4/21 wrap cache flushing functions into accel drivers
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
Yet another accel field: cache flushing functions
--- accel.c | 2 ++ accel.h | 11 +++++++++++ exec.c | 15 +++++++-------- kqemu.c | 15 +++++++++------ 4 files changed, 29 insertions(+), 14 deletions(-)
accel.c +2 -0
@@ -14,5 +14,7 @@ int _accel_nop(void)QEMUAccel noaccel = { .cpu_interrupt = accel_nop, .init_env = accel_nop, + .flush_cache = accel_nop, + .flush_page = accel_nop, };
accel.h +11 -0
@@ -4,6 +4,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;
@@ -24,4 +26,13 @@ static inline void accel_init_env(CPUState *env) current_accel->init_env(env); } +static inline void accel_flush_cache (CPUState *env,int global) +{ + current_accel->flush_cache (env, global); +} + +static inline void accel_flush_page (CPUState *env,target_ulong addr) +{ + current_accel->flush_page (env, addr); +}#endif
exec.c +7 -8
@@ -1684,10 +1684,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++; }
@@ -1730,10 +1730,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
[Qemu-devel] Re: [PATCH 04/21] wrap cache flushing functions into accel drivers
Quoted 57 lines · Glauber Costa
From: Glauber Costa <[email protected]>
Yet another accel field: cache flushing functions
Signed-off-by Glauber Costa <[email protected]>--- accel.c | 2 ++ accel.h | 11 +++++++++++ exec.c | 15 +++++++-------- kqemu.c | 15 +++++++++------ 4 files changed, 29 insertions(+), 14 deletions(-)accel.c +2
-0@@ -14,5 +14,7 @@ int _accel_nop(void)QEMUAccel noaccel = { .cpu_interrupt = accel_nop, .init_env = accel_nop, + .flush_cache = accel_nop, + .flush_page = accel_nop, };accel.h +11
-0@@ -4,6 +4,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;@@ -24,4 +26,13 @@ static inline void accel_init_env(CPUState *env) current_accel->init_env(env); } +static inline void accel_flush_cache (CPUState *env,int global) +{ + current_accel->flush_cache (env, global); +} + +static inline void accel_flush_page (CPUState *env,target_ulong addr) +{ + current_accel->flush_page (env, addr); +}#endif exec.c +0
-0@@ -1684,10 +1684,10 @@ void tlb_flush(CPUState *env, int flush_global)memset (env->tb_jmp_cache,0 ,TB_JMP_CACHE_SIZE *sizeof (void *));
exec.c void tlb_flush(CPUState *env, int flush_global) · line 1691
Quoted 10 lines
exec.c +4
-4-#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 );
Where did this come from?? I understand the rather simple conversion of kqemu_flush to accel_flush_cache but it's not at all clear where this munmap came from.
Quoted 5 lines
exec.c +0
-0#endif tlb_flush_count++;}
exec.c +0
-0@@ -1730,10 +1730,9 @@ void tlb_flush_page(CPUState *env, target_ulong addr)
exec.c void tlb_flush_page(CPUState *env, target_ulong addr) · line 1736
Quoted 10 lines
exec.c +3
-4tlb_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 )
And what is this if() being added for?
Regards,
Anthony Liguori
Re: [Qemu-devel] Re: [PATCH 04/21] wrap cache flushing functions into accel drivers
Quoted 60 lines · Anthony Liguori
Quoted 59 lines · Glauber Costa
From: Glauber Costa <[email protected]>
Yet another accel field: cache flushing functions
Signed-off-by Glauber Costa <[email protected]>--- accel.c | 2 ++ accel.h | 11 +++++++++++ exec.c | 15 +++++++-------- kqemu.c | 15 +++++++++------ 4 files changed, 29 insertions(+), 14 deletions(-)accel.c +2
-0@@ -14,5 +14,7 @@ int _accel_nop(void)QEMUAccel noaccel = { .cpu_interrupt = accel_nop, .init_env = accel_nop, + .flush_cache = accel_nop, + .flush_page = accel_nop, };accel.h +11
-0@@ -4,6 +4,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;@@ -24,4 +26,13 @@ static inline void accel_init_env(CPUState *env) current_accel->init_env(env); } +static inline void accel_flush_cache (CPUState *env,int global) +{ + current_accel->flush_cache (env, global); +} + +static inline void accel_flush_page (CPUState *env,target_ulong addr) +{ + current_accel->flush_page (env, addr); +}#endif exec.c +0
-0@@ -1684,10 +1684,10 @@ void tlb_flush(CPUState *env, int flush_global)memset (env->tb_jmp_cache,0 ,TB_JMP_CACHE_SIZE *sizeof (void *));
Quoted 13 lines
exec.c void tlb_flush(CPUState *env, int flush_global)
Quoted 9 lines
exec.c +4
-4-#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 );Where did this come from?? I understand the rather simple conversion of
kqemu_flushtoaccel_flush_cachebut it's not at all clear where this munmap came from.
Ancient versions of the patch. This code was removed and I didn't notice it.
thanks
Quoted 27 lines
Quoted 7 lines
exec.c +0
-0#endif tlb_flush_count++;}
exec.c +0
-0@@ -1730,10 +1730,9 @@ void tlb_flush_page(CPUState *env, target_ulong addr)exec.c void tlb_flush_page(CPUState *env, target_ulong · line 1737
Quoted 10 lines
exec.c +3
-4tlb_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 )And what is this
if()being added for?Regards,
Anthony Liguori
Signature · 5 lines
Glauber Costa. "Free as in Freedom" http://glommer.net "The less confident you are, the more serious you have to act."
PATCH 5/21 turn info kqemu into generic info accelerator
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
Yet another accel field: info.
Quoted 1 line
From this point on, "info kqemu" is no more. "info accelerator" should
be used instead.
--- accel.c | 6 ++++++ accel.h | 6 ++++++ kqemu.c | 24 ++++++++++++++++++++++++ monitor.c | 36 +++++++++++++----------------------- 4 files changed, 49 insertions(+), 23 deletions(-)
accel.c +6 -0
@@ -8,6 +8,11 @@ int _accel_nop(void)return 0 ; } +int noaccel_info (CPUState *env,char *buf) +{ +return sprintf (buf,"no accelerator present.\n" ); +} +#define accel_nop ((void *)_accel_nop)/* Accelerator wrapper for the no-accel (raw qemu) case */
@@ -16,5 +21,6 @@ QEMUAccel noaccel = { .init_env = accel_nop, .flush_cache = accel_nop, .flush_page = accel_nop, + .info = noaccel_info, };
accel.h +6 -0
@@ -6,6 +6,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,4 +36,9 @@ 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) +{ +return current_accel->info (env, buf); +}#endif
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" #include "migration.h"
@@ -1233,34 +1234,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
@@ -1493,8 +1483,8 @@ static const 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
[Qemu-devel] Re: [PATCH 05/21] turn info kqemu into generic info accelerator
Quoted 19 lines · Glauber Costa
From: Glauber Costa <[email protected]>
Yet another accel field: info.
From this point on, "info kqemu" is no more. "info accelerator" should be used instead.Signed-off-by Glauber Costa <[email protected]>--- accel.c | 6 ++++++ accel.h | 6 ++++++ kqemu.c | 24 ++++++++++++++++++++++++ monitor.c | 36 +++++++++++++----------------------- 4 files changed, 49 insertions(+), 23 deletions(-)accel.c +0
-0
accel.c int _accel_nop(void) · line 14
Quoted 7 lines
accel.c +3
-0@@ -8,6 +8,11 @@ int _accel_nop(void)return 0 ; } +int noaccel_info (CPUState *env,char *buf) +{ +return sprintf (buf,"no accelerator present.\n" );
sprintf() is evil and never should be used. You should refactor this patch for the info callback to take a buffer size and use snprintf().
Regards,
Anthony Liguori
Re: [Qemu-devel] Re: [PATCH 05/21] turn info kqemu into generic info accelerator
In message: <[email protected]>
Anthony Liguori <[email protected]> writes:
: Glauber Costa wrote:
: > From: Glauber Costa <[email protected]>
: >
: > Yet another accel field: info.
: > From this point on, "info kqemu" is no more. "info accelerator" should : > be used instead.
: >
: > Signed-off-by: Glauber Costa <[email protected]>
: > ---
: > accel.c | 6 ++++++ : > accel.h | 6 ++++++ : > kqemu.c | 24 ++++++++++++++++++++++++ : > monitor.c | 36 +++++++++++++----------------------- : > 4 files changed, 49 insertions(+), 23 deletions(-)
: >
: > diff --git a/accel.c b/accel.c
: > index 6776244..466fe67 100644
: > --- a/accel.c
: > +++ b/accel.c
: > @@ -8,6 +8,11 @@ int _accel_nop(void)
: > return 0;
: > }
: >
: > +int noaccel_info(CPUState *env, char *buf)
: > +{
: > + return sprintf(buf, "no accelerator present.\n");
: >
:
: sprintf() is evil and never should be used. You should refactor this : patch for the info callback to take a buffer size and use snprintf().
why use sprintf for this?
Warner
Re: [Qemu-devel] Re: [PATCH 05/21] turn info kqemu into generic info accelerator
Quoted 33 lines · M. Warner Losh
In message: <[email protected]>
Anthony Liguori <[email protected]> writes:
: Glauber Costa wrote:
: > From: Glauber Costa <[email protected]>
: >
: > Yet another accel field: info.
: > From this point on, "info kqemu" is no more. "info accelerator" should : > be used instead.
: >
: > Signed-off-by: Glauber Costa <[email protected]>
: > ---: > accel.c | 6 ++++++ : > accel.h | 6 ++++++ : > kqemu.c | 24 ++++++++++++++++++++++++ : > monitor.c | 36 +++++++++++++----------------------- : > 4 files changed, 49 insertions(+), 23 deletions(-): >
: > diff --gita/accel.cb/accel.c
: > index 6776244..466fe67 100644
: > ---a/accel.c
: > +++b/accel.c
: > @@ -8,6 +8,11 @@ int_accel_nop(void)
: > return 0;
: > }
: >
: > +intnoaccel_info(CPUState *env, char *buf)
: > +{
: > + returnsprintf(buf, "no accelerator present.\n");
: >
:
:sprintf()is evil and never should be used. You should refactor this : patch for the info callback to take a buffer size and usesnprintf().
Quoted 1 line
why use sprintf for this?
Accelerators probably want to display something on their own. Returning a pointer to a string seems even worse to me.
Quoted 5 lines
Warner
Signature · 5 lines
Glauber Costa. "Free as in Freedom" http://glommer.net "The less confident you are, the more serious you have to act."
PATCH 6/21 separate accelerator part of info profiler
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
Yet another accel field: profile.
It allows the accelerators to do part of the profiling their own way.
--- accel.c | 1 + accel.h | 6 ++++++ kqemu.c | 35 +++++++++++++++++++++++++++++++++++ monitor.c | 27 ++++++--------------------- 4 files changed, 48 insertions(+), 21 deletions(-)
accel.c +1 -0
@@ -22,5 +22,6 @@ QEMUAccel noaccel = { .flush_cache = accel_nop, .flush_page = accel_nop, .info = noaccel_info, + .profile = accel_nop, };
accel.h +6 -0
@@ -7,6 +7,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;
@@ -41,4 +42,9 @@ static inline int accel_info(CPUState *env, char *buf) {return current_accel->info (env, buf); } + +static inline int accel_profile (CPUState *env,char *buf) +{ +return current_accel->profile (env, buf); +}#endif
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
@@ -1255,17 +1255,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 ;
@@ -1273,24 +1270,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/21 move kqemu externs to kqemu.h
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
move extern definitions to from cpu-all.h to kqemu.h. Just a step to increase kqemu's degree of separation.
--- cpu-all.h | 5 ----- kqemu.h | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-)
cpu-all.h +0 -5
@@ -1077,14 +1077,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/21 move disabling code to kqemu.c instead of vl.c
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
kqemu is not smp. So instead of testing in vl.c, do the test in kqemu.c, and just refuse to start if smp_cpus > 1.
--- 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
@@ -9463,10 +9463,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
[Qemu-devel] Re: [PATCH 08/21] move disabling code to kqemu.c instead of vl.c
Quoted 5 lines · Glauber Costa
From: Glauber Costa <[email protected]>
kqemu is not smp. So instead of testing in
vl.c, do the test inkqemu.c, and just refuse to start ifsmp_cpus> 1.
Maybe the start accelerator should be passed the number of cpus instead of relying on an extern variable?
Regards,
Anthony Liguori
Re: [Qemu-devel] Re: [PATCH 08/21] move disabling code to kqemu.c instead of vl.c
Quoted 10 lines · Anthony Liguori
Quoted 6 lines · Glauber Costa
From: Glauber Costa <[email protected]>
kqemu is not smp. So instead of testing in
vl.c, do the test inkqemu.c, and just refuse to start ifsmp_cpus> 1.Maybe the start accelerator should be passed the number of cpus instead of relying on an extern variable?
That's actually a good idea.
Quoted 8 lines
Regards,
Anthony Liguori
Signature · 5 lines
Glauber Costa. "Free as in Freedom" http://glommer.net "The less confident you are, the more serious you have to act."
PATCH 9/21 set_notdirty goes through accel wrapper
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
Yet another accel field: set_notdirty
--- accel.c | 1 + accel.h | 6 ++++++ exec-all.h | 2 +- exec.c | 18 +++++++----------- kqemu.c | 23 +++++++++++------------ 5 files changed, 26 insertions(+), 24 deletions(-)
accel.c +1 -0
@@ -23,5 +23,6 @@ QEMUAccel noaccel = { .flush_page = accel_nop, .info = noaccel_info, .profile = accel_nop, + .set_notdirty = accel_nop, };
accel.h +6 -0
@@ -8,6 +8,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;
@@ -47,4 +48,9 @@ static inline int accel_profile(CPUState *env, char *buf) {return current_accel->profile (env, buf); } + +static inline void accel_set_notdirty (target_ulong addr) +{ + current_accel->set_notdirty (addr); +}#endif
exec-all.h +1 -1
@@ -363,7 +363,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
@@ -1780,18 +1780,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/21 wrap modify_page through accel calls
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
Yet another accel field: modify_page
--- accel.c | 1 + accel.h | 7 +++++++ exec-all.h | 2 +- exec.c | 27 ++++++++++++--------------- kqemu.c | 26 +++++++++++++++----------- 5 files changed, 36 insertions(+), 27 deletions(-)
accel.c +1 -0
@@ -24,5 +24,6 @@ QEMUAccel noaccel = { .info = noaccel_info, .profile = accel_nop, .set_notdirty = accel_nop, + .modify_page = accel_nop, };
accel.h +7 -0
@@ -9,6 +9,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;
@@ -53,4 +54,10 @@ 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) +{ + current_accel->modify_page (addr, dirty_flags); +} +#endif
exec-all.h +1 -1
@@ -364,7 +364,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
@@ -2384,12 +2384,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
@@ -2409,12 +2408,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
@@ -2434,12 +2432,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/21 remove kqemu reference from hw/pc.c
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
Instead, route cpu_get_ticks through accel driver.
--- accel.c | 3 +++ accel.h | 12 ++++++++++++ hw/pc.c | 13 ++----------- kqemu.c | 6 ++++++ 4 files changed, 23 insertions(+), 11 deletions(-)
accel.c +3 -0
@@ -25,5 +25,8 @@ QEMUAccel noaccel = { .profile = accel_nop, .set_notdirty = accel_nop, .modify_page = accel_nop, +#ifndef CONFIG_USER_ONLY + .get_real_ticks = cpu_get_ticks, +#endif };
accel.h +12 -0
@@ -10,6 +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 } QEMUAccel;extern QEMUAccel *current_accel;
@@ -60,4 +63,13 @@ 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 ); + +#ifndef CONFIG_USER_ONLY +static inline uint64_t accel_get_real_ticks (void ) +{ +return current_accel->get_real_ticks (); +} +#endif +#endif
hw/pc.c +2 -11
@@ -33,6 +33,7 @@#include "boards.h" #include "console.h" #include "fw_cfg.h" +#include "accel.h" /* output Bochs bios info messages */ //#define DEBUG_BIOS
@@ -75,17 +76,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 */ -#ifdef 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 +6 -0
@@ -444,6 +444,12 @@ QEMUAccel kqemu_accel = { .profile = kqemu_profile, .set_notdirty = kqemu_set_notdirty, .modify_page = kqemu_modify_page, +#ifndef CONFIG_USER_ONLY +/* 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, +#endif };
Signature · 1 line
1.5.5.1
PATCH 12/21 build list of available accelerators
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
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.c | 3 ++ accel.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- exec.c | 3 -- kqemu.c | 5 +-- monitor.c | 12 +++++++++- vl.c | 7 ++++++ 6 files changed, 83 insertions(+), 10 deletions(-)
accel.c +3 -0
@@ -2,6 +2,7 @@#include "accel.h" QEMUAccel *current_accel; +QEMUCont *head =NULL ;int _accel_nop (void ) {
@@ -17,8 +18,10 @@ int noaccel_info(CPUState *env, char *buf)/* Accelerator wrapper for the no-accel (raw qemu) case */ QEMUAccel noaccel = { + .name ="none" , .cpu_interrupt = accel_nop, .init_env = accel_nop, + .start = accel_nop, .flush_cache = accel_nop, .flush_page = accel_nop, .info = noaccel_info,
accel.h +61 -2
87 lines not on this page · raw message
exec.c +0 -3
@@ -497,9 +497,6 @@ void cpu_exec_init_all(unsigned long tb_size)#if !defined(CONFIG_USER_ONLY )io_mem_init ();#endif -#ifdef USE_KQEMU -kqemu_start (); -#endif }#if defined(CPU_SAVE_VERSION ) && !defined(CONFIG_USER_ONLY )
kqemu.c +2 -3
@@ -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,
@@ -452,7 +452,6 @@ QEMUAccel kqemu_accel = {#endif }; -struct fpstate {uint16_t fpuc;uint16_t dummy1;
monitor.c +10 -2
@@ -1234,6 +1234,15 @@ static void mem_info(void) }#endif +static int do_accel_do_list (void ) +{ +QEMUCont *tmp; +for (tmp=get_accel_head (); tmp !=NULL ; tmp = tmp->next) + { +term_printf ("%c %s\n" , tmp->active ?'*' :' ' , tmp->acc->name); + } +} +#define MAX_BUF 1024static void do_info_accelerator (void ) {
@@ -1247,10 +1256,9 @@ static void do_info_accelerator(void)return ; } +do_accel_do_list ();if (accel_info (env, buf))term_printf (buf); -else -term_printf ("No accelerator present\n" ); }#ifdef CONFIG_PROFILER
vl.c +7 -0
@@ -140,6 +140,7 @@#include "disas.h" #include "exec-all.h" +#include "accel.h" #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
@@ -8809,6 +8810,7 @@ int main(int argc, char **argv) }#endif +register_qemu_accel (&kqemu_accel);register_qemu_accel (&noaccel);register_machines ();
@@ -9583,6 +9585,11 @@ int main(int argc, char **argv)/* init the dynamic translator */ cpu_exec_init_all (tb_size *1024 *1024 ); +if (accel_start ()) { +fprintf (stderr,"qemu: error, no suitable accelerator found\n" ); +exit (1 ); + } +bdrv_init ();/* we always create the cdrom drive, even if no disk is there */
Signature · 1 line
1.5.5.1
PATCH 13/21 provide --accel option
In reply to Glauber CostaThe --accel option will provide us the ability of defining which accelerator to pick at run time. It has the advantage of not using the not-well-accepted constructor directives, and also, of stabilishing a way to define priorities among accelerators.
The ones registered first, are tried first.
--- vl.c | 24 +++++++++++++++++++++--- 1 files changed, 21 insertions(+), 3 deletions(-)
vl.c +21 -3
@@ -255,6 +255,13 @@ static QEMUTimer *icount_vm_timer;uint8_t qemu_uuid[16 ]; +QEMUAccel *available_accels[] = { +/* list of available accelerators */ +#ifdef USE_KQEMU + &kqemu_accel, +#endif +}; +#define TFR (expr) do { if ((expr) != -1) break; } while (errno == EINTR)/***********************************************************/
@@ -8349,6 +8356,7 @@ enum { QEMU_OPTION_no_quit, QEMU_OPTION_pidfile, QEMU_OPTION_no_kqemu, + QEMU_OPTION_accel, QEMU_OPTION_kernel_kqemu, QEMU_OPTION_win2k_hack, QEMU_OPTION_usb,
@@ -8436,6 +8444,7 @@ static const QEMUOption qemu_options[] = { { "no-kqemu", 0, QEMU_OPTION_no_kqemu }, { "kernel-kqemu", 0, QEMU_OPTION_kernel_kqemu }, #endif + { "accel", HAS_ARG, QEMU_OPTION_accel}, #if defined(TARGET_PPC) || defined(TARGET_SPARC) { "g", 1, QEMU_OPTION_g }, #endif
@@ -8810,9 +8819,6 @@ int main(int argc, char **argv) }#endif -register_qemu_accel (&kqemu_accel); -register_qemu_accel (&noaccel); -register_machines (); machine = first_machine; cpu_model =NULL ;
@@ -9261,6 +9267,15 @@ int main(int argc, char **argv) kqemu_allowed =2 ;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]); + } + } +break ;case QEMU_OPTION_usb: usb_enabled =1 ;break ;
@@ -9402,6 +9417,9 @@ int main(int argc, char **argv)exit (1 ); } +/* Basic handler for the noaccel case */ +register_qemu_accel (&noaccel); +if (nographic) {if (serial_device_index ==0 ) serial_devices[0 ] ="stdio" ;
Signature · 1 line
1.5.5.1
[Qemu-devel] Re: [PATCH 13/21] provide --accel option
Quoted 7 lines · Glauber Costa
The --accel option will provide us the ability of defining which accelerator to pick at run time. It has the advantage of not using the not-well-accepted constructor directives, and also, of stabilishing a way to define priorities among accelerators.
The ones registered first, are tried first.
Logically speaking, kqemu should be two accelerators, right? -accel kqemu and -accel kqemu-kernel? They should share most of the same obviously.
That would eliminate the need for the various kqemu options.
Regards,
Anthony Liguori
Re: [Qemu-devel] Re: [PATCH 13/21] provide --accel option
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Glauber Costa
The --accel option will provide us the ability of defining which accelerator to pick at run time. It has the advantage of not using the not-well-accepted constructor directives, and also, of stabilishing a way to define priorities among accelerators.
Quoted 7 lines
Quoted 2 lines
The ones registered first, are tried first.
Logically speaking, kqemu should be two accelerators, right? -accel kqemu and -accel kqemu-kernel? They should share most of the same obviously.
That would eliminate the need for the various kqemu options.
Maybe, but it seems to me at first that it would require touching kqemu a little bit heavily.
A quick hack would be accept the two options, only difference being we set the kemu_enabled
variable in there. Are you okay with this path ?
Quoted 8 lines
Regards,
Anthony Liguori
Signature · 5 lines
Glauber Costa. "Free as in Freedom" http://glommer.net "The less confident you are, the more serious you have to act."
Re: [Qemu-devel] Re: [PATCH 13/21] provide --accel option
In reply to Anthony LiguoriQuoted 7 lines · Anthony Liguori
Quoted 6 lines · Glauber Costa
The --accel option will provide us the ability of defining which accelerator to pick at run time. It has the advantage of not using the not-well-accepted constructor directives, and also, of stabilishing a way to define priorities among accelerators.
Quoted 7 lines
Quoted 2 lines
The ones registered first, are tried first.
Logically speaking, kqemu should be two accelerators, right? -accel kqemu and -accel kqemu-kernel? They should share most of the same obviously.
That would eliminate the need for the various kqemu options.
do we want to keep them for the sake of compatibility ?
Quoted 8 lines
Regards,
Anthony Liguori
Signature · 5 lines
Glauber Costa. "Free as in Freedom" http://glommer.net "The less confident you are, the more serious you have to act."
PATCH 14/21 add tsc field to cpu definition
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
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
@@ -580,6 +580,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/21 shift for masks.
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
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/21 add hook to cpu_register_physical_memory
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
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.c | 1 + accel.h | 9 +++++++++ exec.c | 32 +++++++++++++++++++------------- kqemu.c | 3 ++- 4 files changed, 31 insertions(+), 14 deletions(-)
accel.c +1 -0
@@ -31,5 +31,6 @@ QEMUAccel noaccel = {#ifndef CONFIG_USER_ONLY .get_real_ticks = cpu_get_ticks, #endif + .register_physical_memory = accel_nop, };
accel.h +9 -0
@@ -15,6 +15,9 @@ typedef struct QEMUAccel {#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); + } QEMUAccel; typedef struct QEMUCont {
@@ -131,4 +134,10 @@ static inline uint64_t accel_get_real_ticks(void) }#endif +static inline void accel_register_phys_mem (uint64_t start_addr, +ram_addr_t size, +ram_addr_t phys_offset) +{ + current_accel->register_physical_memory (start_addr, size, phys_offset); +}#endif
exec.c +19 -13
@@ -2189,12 +2189,13 @@ static void *subpage_init (target_phys_addr_t base, ram_addr_t *phys, } \ }while (0 ) -/* 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) +/* Use this version of cpu registering physical memory in accel-specific code. It exists +* to avoid chicken and egg problems with code that might need to register memory in qemu, +* but not with the underlying accelerator +*/ +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;
@@ -2202,13 +2203,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 ) {
@@ -2266,6 +2260,18 @@ void cpu_register_physical_memory(target_phys_addr_t start_addr, } } +/* 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) +{ +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 +2 -1
@@ -450,6 +450,7 @@ QEMUAccel kqemu_accel = { performance reasons */ .get_real_ticks = cpu_get_real_ticks, #endif + .register_physical_memory = kqemu_set_phys_mem, }; struct fpstate {
@@ -1104,7 +1105,7 @@ static void qpi_init(void) qpi_io_memory =cpu_register_io_memory (0 , qpi_mem_read, qpi_mem_write,NULL ); -cpu_register_physical_memory (kqemu_comm_base & ~0xfff , +__cpu_register_physical_memory (kqemu_comm_base & ~0xfff , 0x1000, qpi_io_memory); }#endif
Signature · 1 line
1.5.5.1
PATCH 17/21 accel_trace_io
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
kqemu keeps trace of the last io done. Do it through an accel_wrapper.
--- accel.c | 2 ++ accel.h | 13 ++++++++++++- cpu-exec.c | 9 ++------- kqemu.c | 18 ++++++++++++++++++ softmmu_template.h | 10 ++++------ vl.c | 30 ++++++------------------------ 6 files changed, 44 insertions(+), 38 deletions(-)
accel.c +2 -0
@@ -32,5 +32,7 @@ QEMUAccel noaccel = { .get_real_ticks = cpu_get_ticks, #endif .register_physical_memory = accel_nop, + .trace_io = accel_nop, + .break_loop = accel_nop, };
accel.h +12 -1
@@ -17,7 +17,8 @@ typedef struct QEMUAccel {#endif 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 {
@@ -140,4 +141,14 @@ static inline void accel_register_phys_mem(uint64_t start_addr, { current_accel->register_physical_memory (start_addr, size, phys_offset); } + +static inline void accel_trace_io (CPUState *env) +{ + current_accel->trace_io (env); +} + +static inline int accel_break_loop (CPUState *env) +{ +return current_accel->break_loop (env); +}#endif
cpu-exec.c +2 -7
@@ -36,6 +36,7 @@#include <signal.h> #include <sys/ucontext.h> #endif +#include "accel.h" #if defined(__sparc__) && !defined(HOST_SOLARIS )// Work around ugly bugs in glibc that mangle global register contents
@@ -653,13 +654,7 @@ int cpu_exec(CPUState *env1) }/* reset soft MMU for next block (it can currently only be set by a memory fault) */ -#if defined(USE_KQEMU ) -#define MIN_CYCLE_BEFORE_SWITCH (100 * 1000) -if (kqemu_is_ok (env) && - (cpu_get_time_fast () - env->last_io_time) >=MIN_CYCLE_BEFORE_SWITCH ) { -cpu_loop_exit (); - } -#endif +accel_break_loop (env); }/* for(;;) */ }else {env_to_regs ();
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,
@@ -451,6 +467,8 @@ QEMUAccel kqemu_accel = { .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, }; struct fpstate {
softmmu_template.h +4 -6
@@ -47,6 +47,8 @@#define ADDR_READ addr_read#endif +#include "accel.h" +static DATA_TYPE glue (glue (slow_ld ,SUFFIX ),MMUSUFFIX )(target_ulong addr,int mmu_idx,void *retaddr);
@@ -75,9 +77,7 @@ static inline DATA_TYPE glue(io_read, SUFFIX)(target_phys_addr_t physaddr, res |= (uint64_t )io_mem_read[index][2 ](io_mem_opaque[index], physaddr +4 ) <<32 ;#endif #endif /* SHIFT > 2 */ -#ifdef USE_KQEMU - env->last_io_time =cpu_get_time_fast (); -#endif +accel_trace_io (env);return res; }
@@ -220,9 +220,7 @@ static inline void glue(io_write, SUFFIX)(target_phys_addr_t physaddr, io_mem_write[index][2 ](io_mem_opaque[index], physaddr +4 , val >>32 );#endif #endif /* SHIFT > 2 */ -#ifdef USE_KQEMU - env->last_io_time =cpu_get_time_fast (); -#endif +accel_trace_io (env); } void REGPARM glue(glue(__st, SUFFIX), MMUSUFFIX)(target_ulong addr,
vl.c +6 -24
@@ -420,10 +420,7 @@ void cpu_outb(CPUState *env, int addr, int val)fprintf (logfile,"outb: %04x %02x\n" , addr, val);#endif ioport_write (0 , 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)
@@ -433,10 +430,7 @@ void cpu_outw(CPUState *env, int addr, int val)fprintf (logfile,"outw: %04x %04x\n" , addr, val);#endif ioport_write (1 , 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)
@@ -446,10 +440,7 @@ void cpu_outl(CPUState *env, int addr, int val)fprintf (logfile,"outl: %04x %08x\n" , addr, val);#endif ioport_write (2 , 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)
@@ -460,10 +451,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; }
@@ -475,10 +463,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; }
@@ -490,10 +475,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 18/21 get_env accel wrapper
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
Allow the current accelerator to provide it's own, customized address of the CPUState structure used for the env variable.
--- accel.c | 6 ++++++ accel.h | 7 +++++++ kqemu.c | 1 + target-i386/helper.c | 2 +- 4 files changed, 15 insertions(+), 1 deletions(-)
accel.c +6 -0
@@ -14,6 +14,11 @@ int noaccel_info(CPUState *env, char *buf)return sprintf (buf,"no accelerator present.\n" ); } +CPUState *noaccel_get_env (void ) +{ +return qemu_mallocz (sizeof (CPUState)); +} +#define accel_nop ((void *)_accel_nop)/* Accelerator wrapper for the no-accel (raw qemu) case */
@@ -21,6 +26,7 @@ QEMUAccel noaccel = { .name = "none", .cpu_interrupt = accel_nop, .init_env = accel_nop, + .get_env = noaccel_get_env, .start = accel_nop, .flush_cache = accel_nop, .flush_page = accel_nop,
accel.h +7 -0
@@ -4,6 +4,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);
@@ -35,6 +36,7 @@ extern QEMUAccel kqemu_accel;extern QEMUCont *head;void *qemu_mallocz (size_t size); +extern CPUState *noaccel_get_env (void );static inline int register_qemu_accel (QEMUAccel *accel) {
@@ -91,6 +93,11 @@ static inline int accel_start(void)return status; } +static inline CPUState *accel_get_env (void ) +{ +return current_accel->get_env (); +} +static inline void accel_init_env (CPUState *env) { current_accel->init_env (env);
kqemu.c +1 -0
@@ -453,6 +453,7 @@ QEMUAccel kqemu_accel = { .name = "KQEMU", .cpu_interrupt = kqemu_cpu_interrupt, .init_env = kqemu_init_env, + .get_env = noaccel_get_env, .start = kqemu_start, .flush_cache = kqemu_flush, .flush_page = kqemu_flush_page,
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
PATCH 19/21 add next_cpu_index
In reply to Glauber CostaFrom: Glauber Costa <[email protected]>
separate 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 | 22 ++++++++++++++-------- 1 files changed, 14 insertions(+), 8 deletions(-)
exec.c +14 -8
@@ -526,25 +526,31 @@ static int cpu_common_load(QEMUFile *f, void *opaque, int version_id) }#endif -void cpu_exec_init (CPUState *env) +int next_cpu_index (void ) {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 (); env->nb_watchpoints =0 ; - *penv = env; +if (env->cpu_index ==0 ) + first_cpu = env;#if defined(CPU_SAVE_VERSION ) && !defined(CONFIG_USER_ONLY ) -register_savevm ("cpu_common" , cpu_index,CPU_COMMON_SAVE_VERSION , +register_savevm ("cpu_common" , env->cpu_index,CPU_COMMON_SAVE_VERSION , cpu_common_save, cpu_common_load, env); -register_savevm ("cpu" , cpu_index,CPU_SAVE_VERSION , +register_savevm ("cpu" , env->cpu_index,CPU_SAVE_VERSION , cpu_save, cpu_load, env);#endif }
Signature · 1 line
1.5.5.1
PATCH 20/21 check wether kqemu is enabled in open code
In reply to Glauber Costakqemu is still too much spread around. The proper fix usually involves rethinking a bit of kqemu logic so for now, just check whether or not kqemu is enabled. If the kqemu accelerator is not present, consider it not. Otherwise, check env field.
--- cpu-exec.c | 2 +- exec-all.h | 7 +++++-- kqemu.c | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-)
cpu-exec.c +1 -1
@@ -606,7 +606,7 @@ int cpu_exec(CPUState *env1) {if (next_tb !=0 && #ifdef USE_KQEMU - (env->kqemu_enabled !=2 ) && + (!kqemu_kernel_enabled (env)) && #endif tb->page_addr[1 ] ==-1 ) {tb_add_jump ((TranslationBlock *)(next_tb & ~3 ), next_tb &3 , tb);
exec-all.h +5 -2
@@ -370,16 +370,19 @@ void kqemu_set_phys_mem(uint64_t start_addr, ram_addr_t size,void kqemu_cpu_interrupt (CPUState *env);void kqemu_record_dump (void ); +int kqemu_is_enabled (CPUState *env); +int kqemu_kernel_enabled (CPUState *env); +extern uint32_t kqemu_comm_base;static inline int kqemu_is_ok (CPUState *env) { -return (env->kqemu_enabled && +return (kqemu_is_enabled (env) && (env->cr[0 ] &CR0_PE_MASK ) && !(env->hflags &HF_INHIBIT_IRQ_MASK ) && (env->eflags &IF_MASK ) && !(env->eflags &VM_MASK ) && - (env->kqemu_enabled ==2 || + (kqemu_kernel_enabled (env) || ((env->hflags &HF_CPL_MASK ) ==3 && (env->eflags &IOPL_MASK ) !=IOPL_MASK ))); }
kqemu.c +21 -0
@@ -250,6 +250,27 @@ void kqemu_init_env(CPUState *env) env->kqemu_enabled = kqemu_allowed; } +/* FIXME: Should not be needed, since ideally, QEMUAccel would avoid all kqemu tests +* altogether +*/ +int kqemu_is_enabled (CPUState *env) +{ +if (strcasecmp (current_accel->name,"kqemu" )) { +return 0 ; + } + +return env->kqemu_enabled; + +} + +int kqemu_kernel_enabled (CPUState *env) +{ +if (strcasecmp (current_accel->name,"kqemu" )) { +return 0 ; + } +return env->kqemu_enabled ==2 ; +} +void kqemu_flush_page (CPUState *env,target_ulong addr) {#if defined(DEBUG )
Signature · 1 line
1.5.5.1
PATCH 21/21 provide an opaque for accelerator in cpu state
In reply to Glauber CostaConvert kqemu to use it. We also provide a small macro to easy the access to the accelerator fields.
--- accel.h | 2 ++ cpu-defs.h | 1 + exec-all.h | 3 +++ kqemu.c | 19 ++++++++++++------- kqemu.h | 6 ++++++ target-i386/cpu.h | 4 ---- target-i386/op_helper.c | 2 +- 7 files changed, 25 insertions(+), 12 deletions(-)
accel.h +2 -0
@@ -34,6 +34,8 @@ extern QEMUAccel noaccel;extern QEMUAccel kqemu_accel;#endif +#define accel_opaque_field (env, type, field) ((type *)env->accel_opaque)->field +extern QEMUCont *head;void *qemu_mallocz (size_t size);extern CPUState *noaccel_get_env (void );
cpu-defs.h +1 -0
@@ -198,6 +198,7 @@ typedef struct icount_decr_u16 {int running;/* Nonzero if cpu is currently running(usermode). */ \/* user data */ \void *opaque; \ +void *accel_opaque; \ \const char *cpu_model_str;
exec-all.h +3 -0
@@ -375,6 +375,9 @@ int kqemu_kernel_enabled(CPUState *env);extern uint32_t kqemu_comm_base; +#include "accel.h" +#include <kqemu.h> +static inline int kqemu_is_ok (CPUState *env) { return(kqemu_is_enabled(env) &&
kqemu.c +12 -7
@@ -62,6 +62,8 @@#define KQEMU_DEVICE "/dev/kqemu"#endif +struct kqemu_cpu_opaque kqemu_opaque; +static void qpi_init (void );#ifdef _WIN32
@@ -247,7 +249,9 @@ int kqemu_start(void)void kqemu_init_env (CPUState *env) {kqemu_update_cpuid (env); - env->kqemu_enabled = kqemu_allowed; +/* SMP currently not supported, so this is okay */ + kqemu_opaque.kqemu_enabled = kqemu_allowed; + env->accel_opaque = &kqemu_opaque; }/* FIXME: Should not be needed, since ideally, QEMUAccel would avoid all kqemu tests
@@ -259,7 +263,7 @@ int kqemu_is_enabled(CPUState *env)return 0 ; } -return env->kqemu_enabled; +return kqemu_opaque_field (env, kqemu_enabled); }
@@ -268,7 +272,8 @@ int kqemu_kernel_enabled(CPUState *env)if (strcasecmp (current_accel->name,"kqemu" )) {return 0 ; } -return env->kqemu_enabled ==2 ; + +return kqemu_opaque_field (env, kqemu_enabled) ==2 ; }void kqemu_flush_page (CPUState *env,target_ulong addr)
@@ -298,7 +303,7 @@ int kqemu_info(CPUState *env, char *buf) {int val, len; val =0 ; - val = env->kqemu_enabled; + val =kqemu_opaque_field (env, kqemu_enabled); len =sprintf (buf,"kqemu support: " ); buf += len;
@@ -457,14 +462,14 @@ 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 (); +kqemu_opaque_field (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 ) { + (cpu_get_time_fast () -kqemu_opaque_field (env, last_io_time)) >=MIN_CYCLE_BEFORE_SWITCH ) {return 1 ; }return 0 ;
@@ -875,7 +880,7 @@ int kqemu_cpu_exec(CPUState *env) cpl = (env->hflags &HF_CPL_MASK ); kenv->cpl = cpl; kenv->nb_pages_to_flush = nb_pages_to_flush; - kenv->user_only = (env->kqemu_enabled ==1 ); + kenv->user_only = (kqemu_opaque_field (env, kqemu_enabled) ==1 ); kenv->nb_ram_pages_to_update = nb_ram_pages_to_update; nb_ram_pages_to_update =0 ; kenv->nb_modified_ram_pages = nb_modified_ram_pages;
kqemu.h +6 -0
@@ -38,6 +38,12 @@ extern int64_t kqemu_ret_int_count;extern int64_t kqemu_ret_excp_count;extern int64_t kqemu_ret_intr_count; +struct kqemu_cpu_opaque { +int kqemu_enabled; +int last_io_time; +}; +#define kqemu_opaque_field (env, field) accel_opaque_field(env, struct kqemu_cpu_opaque, field) +struct kqemu_segment_cache {uint16_t selector;uint16_t padding1;
target-i386/cpu.h +0 -4
@@ -610,10 +610,6 @@ typedef struct CPUX86State {uint32_t cpuid_ext3_features;uint32_t cpuid_apic_id; -#ifdef USE_KQEMU -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;
target-i386/op_helper.c +1 -1
@@ -3261,7 +3261,7 @@ void helper_rdmsr(void)#endif #ifdef USE_KQEMU case MSR_QPI_COMMBASE : -if (env->kqemu_enabled) { +if (kqemu_opaque_field (env, kqemu_enabled)) { val = kqemu_comm_base; }else { val =0 ;
Signature · 1 line
1.5.5.1
[Qemu-devel] Re: [PATCH 21/21] provide an opaque for accelerator in cpu state
accel.h extern QEMUAccel noaccel; · line 38
Quoted 7 lines · Glauber Costa
Convert kqemu to use it. We also provide a small macro to easy the access to the accelerator fields.
accel.h +2
-0+#define accel_opaque_field (env, type, field) ((type *)env->accel_opaque)->field +
Since we already allow the accelerator to customize the allocation of CPUState, why is this needed?
For example, kqemu would allocate a KqemuCPUState (which has a CPUState field, which is the return value), and use container_of() to get to the kqemu-specific fields.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 2 lines · Glauber Costa
So as Anthony requested, here's the current state of accelerators.
Thanks!
Quoted 7 lines
It's basically whatever was in the repository, but cleaned up and factored as individual patches. I've run my previous tests on it and it seems to work. So if other folks who were also running it can give a test to make sure it still works for you, it would be awesome.
Anthony, if nobody spots anything obvious in this series, can you merge it?
Since it touches kqemu code, Fabrice really needs to Ack it.
Regards,
Anthony Liguori
Quoted 4 lines
thanks