* [Qemu-devel] Re: [PATCH 0/21] Accelerators: cleaned up version
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
@ 2008-10-15 20:16 ` Anthony Liguori
2008-10-15 21:54 ` [Qemu-devel] [PATCH 01/21] split kqemu_init into two Glauber Costa
` (20 subsequent siblings)
21 siblings, 0 replies; 36+ messages in thread
From: Anthony Liguori @ 2008-10-15 20:16 UTC (permalink / raw)
To: Glauber Costa; +Cc: jan.kiszka, jes, qemu-devel, avi, dmitry.baryshkov
Glauber Costa wrote:
> So as Anthony requested, here's the current state of accelerators.
>
Thanks!
> 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
> thanks
>
>
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 01/21] split kqemu_init into two
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
2008-10-15 20:16 ` [Qemu-devel] " Anthony Liguori
@ 2008-10-15 21:54 ` Glauber Costa
2008-10-15 21:54 ` [Qemu-devel] [PATCH 02/21] introduce QEMUAccel and fill it with interrupt specific driver Glauber Costa
` (19 subsequent siblings)
21 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:54 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
we separate kqemu_init() into a part that depends on env,
and other that does not. The later can be initialized earlier
Signed-off-by: Glauber Costa <glommer@redhat.com>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@siemens.com>
---
exec.c | 5 ++++-
kqemu.c | 10 +++++++---
target-i386/helper.c | 2 +-
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/exec.c b/exec.c
index f1fcec8..1cad0be 100644
--- a/exec.c
+++ b/exec.c
@@ -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
diff --git a/kqemu.c b/kqemu.c
index 4783aa2..9b52237 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -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)
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 94c5c74..ee8cc86 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -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;
}
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 02/21] introduce QEMUAccel and fill it with interrupt specific driver
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
2008-10-15 20:16 ` [Qemu-devel] " Anthony Liguori
2008-10-15 21:54 ` [Qemu-devel] [PATCH 01/21] split kqemu_init into two Glauber Costa
@ 2008-10-15 21:54 ` Glauber Costa
2008-10-15 20:20 ` [Qemu-devel] " Anthony Liguori
2008-10-15 21:55 ` [Qemu-devel] [PATCH 03/21] init env made accel driver Glauber Costa
` (18 subsequent siblings)
21 siblings, 1 reply; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:54 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
This patch introduces QEMUAccel, a placeholder for function pointers
that aims at helping qemu to abstract accelerators such as kqemu and
kvm (actually, the 'accelerator' name was proposed by avi kivity, since
he loves referring to kvm that way).
To begin with, the accelerator is given the opportunity to register a
cpu_interrupt function, to be called after the raw cpu_interrupt.
This has the side effect of, for the kqemu accelerator, calling kqemu_cpu_interrupt
everytime, which didn't use to happen. But looking at the code, this seems safe to me.
This patch applies on raw qemu.
Signed-off-by: Glauber Costa <glommer@redhat.com>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@siemens.com>
---
Makefile.target | 2 +-
accel.c | 17 +++++++++++++++++
accel.h | 20 ++++++++++++++++++++
exec.c | 3 +++
kqemu.c | 9 +++++++++
vl.c | 17 +++++------------
6 files changed, 55 insertions(+), 13 deletions(-)
create mode 100644 accel.c
create mode 100644 accel.h
diff --git a/Makefile.target b/Makefile.target
index e2edf9d..623ecd8 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -188,7 +188,7 @@ all: $(PROGS)
#########################################################
# cpu emulator library
LIBOBJS=exec.o kqemu.o translate-all.o cpu-exec.o\
- translate.o host-utils.o
+ translate.o host-utils.o accel.o
ifdef CONFIG_DYNGEN_OP
exec.o: dyngen-opc.h
LIBOBJS+=op.o
diff --git a/accel.c b/accel.c
new file mode 100644
index 0000000..d30460d
--- /dev/null
+++ b/accel.c
@@ -0,0 +1,17 @@
+#include "hw/hw.h"
+#include "accel.h"
+
+QEMUAccel *current_accel;
+
+int _accel_nop(void)
+{
+ return 0;
+}
+
+#define accel_nop ((void *)_accel_nop)
+
+/* Accelerator wrapper for the no-accel (raw qemu) case */
+QEMUAccel noaccel = {
+ .cpu_interrupt = accel_nop,
+};
+
diff --git a/accel.h b/accel.h
new file mode 100644
index 0000000..8e5ddc6
--- /dev/null
+++ b/accel.h
@@ -0,0 +1,20 @@
+#ifndef _ACCEL_H_
+#define _ACCEL_H_
+
+typedef struct QEMUAccel {
+ void (*cpu_interrupt)(CPUState *env);
+} QEMUAccel;
+
+extern QEMUAccel *current_accel;
+extern QEMUAccel noaccel;
+
+static inline void register_qemu_accel(QEMUAccel *accel)
+{
+ current_accel = accel;
+}
+
+static inline void accel_cpu_interrupt(CPUState *env)
+{
+ current_accel->cpu_interrupt(env);
+}
+#endif
diff --git a/exec.c b/exec.c
index 1cad0be..21253cc 100644
--- a/exec.c
+++ b/exec.c
@@ -43,6 +43,8 @@
#include <qemu.h>
#endif
+#include "accel.h"
+
//#define DEBUG_TB_INVALIDATE
//#define DEBUG_FLUSH
//#define DEBUG_TLB
@@ -1430,6 +1432,7 @@ void cpu_single_step(CPUState *env, int enabled)
tb_flush(env);
}
#endif
+ accel_cpu_interrupt(env);
}
/* enable or disable low levels log */
diff --git a/kqemu.c b/kqemu.c
index 9b52237..87c06cd 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -50,6 +50,7 @@
#include <unistd.h>
#include <fcntl.h>
#include "kqemu.h"
+#include "accel.h"
#ifdef _WIN32
#define KQEMU_DEVICE "\\\\.\\kqemu"
@@ -150,6 +151,8 @@ static void kqemu_update_cpuid(CPUState *env)
accelerated code */
}
+QEMUAccel kqemu_accel;
+
int kqemu_start(void)
{
struct kqemu_init kinit;
@@ -232,6 +235,7 @@ int kqemu_start(void)
}
nb_pages_to_flush = 0;
nb_ram_pages_to_update = 0;
+ register_qemu_accel(&kqemu_accel);
qpi_init();
return 0;
@@ -243,6 +247,11 @@ void kqemu_init_env(CPUState *env)
env->kqemu_enabled = kqemu_allowed;
}
+QEMUAccel kqemu_accel = {
+ .cpu_interrupt = kqemu_cpu_interrupt,
+};
+
+
void kqemu_flush_page(CPUState *env, target_ulong addr)
{
#if defined(DEBUG)
diff --git a/vl.c b/vl.c
index 97aca75..f72172f 100644
--- a/vl.c
+++ b/vl.c
@@ -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;
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] Re: [PATCH 02/21] introduce QEMUAccel and fill it with interrupt specific driver
2008-10-15 21:54 ` [Qemu-devel] [PATCH 02/21] introduce QEMUAccel and fill it with interrupt specific driver Glauber Costa
@ 2008-10-15 20:20 ` Anthony Liguori
2008-10-15 20:58 ` Glauber Costa
0 siblings, 1 reply; 36+ messages in thread
From: Anthony Liguori @ 2008-10-15 20:20 UTC (permalink / raw)
To: Glauber Costa
Cc: jan.kiszka, jes, qemu-devel, avi, Glauber Costa, dmitry.baryshkov
Glauber Costa wrote:
> From: Glauber Costa <gcosta@redhat.com>
>
> This patch introduces QEMUAccel, a placeholder for function pointers
> that aims at helping qemu to abstract accelerators such as kqemu and
> kvm (actually, the 'accelerator' name was proposed by avi kivity, since
> he loves referring to kvm that way).
>
> To begin with, the accelerator is given the opportunity to register a
> cpu_interrupt function, to be called after the raw cpu_interrupt.
> This has the side effect of, for the kqemu accelerator, calling kqemu_cpu_interrupt
> everytime, which didn't use to happen. But looking at the code, this seems safe to me.
>
> This patch applies on raw qemu.
>
> Signed-off-by: Glauber Costa <glommer@redhat.com>
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@siemens.com>
> ---
> Makefile.target | 2 +-
> accel.c | 17 +++++++++++++++++
> accel.h | 20 ++++++++++++++++++++
> exec.c | 3 +++
> kqemu.c | 9 +++++++++
> vl.c | 17 +++++------------
> 6 files changed, 55 insertions(+), 13 deletions(-)
> create mode 100644 accel.c
> create mode 100644 accel.h
>
> diff --git a/Makefile.target b/Makefile.target
> index e2edf9d..623ecd8 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -188,7 +188,7 @@ all: $(PROGS)
> #########################################################
> # cpu emulator library
> LIBOBJS=exec.o kqemu.o translate-all.o cpu-exec.o\
> - translate.o host-utils.o
> + translate.o host-utils.o accel.o
> ifdef CONFIG_DYNGEN_OP
> exec.o: dyngen-opc.h
> LIBOBJS+=op.o
> diff --git a/accel.c b/accel.c
> new file mode 100644
> index 0000000..d30460d
> --- /dev/null
> +++ b/accel.c
> @@ -0,0 +1,17 @@
> +#include "hw/hw.h"
> +#include "accel.h"
> +
> +QEMUAccel *current_accel;
> +
> +int _accel_nop(void)
> +{
> + return 0;
> +}
> +
> +#define accel_nop ((void *)_accel_nop)
> +
> +/* Accelerator wrapper for the no-accel (raw qemu) case */
> +QEMUAccel noaccel = {
> + .cpu_interrupt = accel_nop,
> +};
> +
> diff --git a/accel.h b/accel.h
> new file mode 100644
> index 0000000..8e5ddc6
> --- /dev/null
> +++ b/accel.h
> @@ -0,0 +1,20 @@
> +#ifndef _ACCEL_H_
> +#define _ACCEL_H_
> +
> +typedef struct QEMUAccel {
> + void (*cpu_interrupt)(CPUState *env);
> +} QEMUAccel;
> +
> +extern QEMUAccel *current_accel;
> +extern QEMUAccel noaccel;
> +
> +static inline void register_qemu_accel(QEMUAccel *accel)
> +{
> + current_accel = accel;
> +}
> +
> +static inline void accel_cpu_interrupt(CPUState *env)
> +{
> + current_accel->cpu_interrupt(env);
> +}
> +#endif
> diff --git a/exec.c b/exec.c
> index 1cad0be..21253cc 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -43,6 +43,8 @@
> #include <qemu.h>
> #endif
>
> +#include "accel.h"
> +
> //#define DEBUG_TB_INVALIDATE
> //#define DEBUG_FLUSH
> //#define DEBUG_TLB
> @@ -1430,6 +1432,7 @@ void cpu_single_step(CPUState *env, int enabled)
> tb_flush(env);
> }
> #endif
> + accel_cpu_interrupt(env);
> }
>
> /* enable or disable low levels log */
> diff --git a/kqemu.c b/kqemu.c
> index 9b52237..87c06cd 100644
> --- a/kqemu.c
> +++ b/kqemu.c
> @@ -50,6 +50,7 @@
> #include <unistd.h>
> #include <fcntl.h>
> #include "kqemu.h"
> +#include "accel.h"
>
> #ifdef _WIN32
> #define KQEMU_DEVICE "\\\\.\\kqemu"
> @@ -150,6 +151,8 @@ static void kqemu_update_cpuid(CPUState *env)
> accelerated code */
> }
>
> +QEMUAccel kqemu_accel;
> +
> int kqemu_start(void)
> {
> struct kqemu_init kinit;
> @@ -232,6 +235,7 @@ int kqemu_start(void)
> }
> nb_pages_to_flush = 0;
> nb_ram_pages_to_update = 0;
> + register_qemu_accel(&kqemu_accel);
>
> qpi_init();
> return 0;
> @@ -243,6 +247,11 @@ void kqemu_init_env(CPUState *env)
> env->kqemu_enabled = kqemu_allowed;
> }
>
> +QEMUAccel kqemu_accel = {
> + .cpu_interrupt = kqemu_cpu_interrupt,
> +};
>
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
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] Re: [PATCH 02/21] introduce QEMUAccel and fill it with interrupt specific driver
2008-10-15 20:20 ` [Qemu-devel] " Anthony Liguori
@ 2008-10-15 20:58 ` Glauber Costa
0 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 20:58 UTC (permalink / raw)
To: qemu-devel
Cc: jan.kiszka, Glauber Costa, jes, avi, Glauber Costa,
dmitry.baryshkov
On Wed, Oct 15, 2008 at 6:20 PM, Anthony Liguori <aliguori@us.ibm.com> wrote:
> Glauber Costa wrote:
>>
>> From: Glauber Costa <gcosta@redhat.com>
>>
>> This patch introduces QEMUAccel, a placeholder for function pointers
>> that aims at helping qemu to abstract accelerators such as kqemu and
>> kvm (actually, the 'accelerator' name was proposed by avi kivity, since
>> he loves referring to kvm that way).
>>
>> To begin with, the accelerator is given the opportunity to register a
>> cpu_interrupt function, to be called after the raw cpu_interrupt.
>> This has the side effect of, for the kqemu accelerator, calling
>> kqemu_cpu_interrupt
>> everytime, which didn't use to happen. But looking at the code, this seems
>> safe to me.
>>
>> This patch applies on raw qemu.
>>
>> Signed-off-by: Glauber Costa <glommer@redhat.com>
>> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@siemens.com>
>> ---
>> Makefile.target | 2 +-
>> accel.c | 17 +++++++++++++++++
>> accel.h | 20 ++++++++++++++++++++
>> exec.c | 3 +++
>> kqemu.c | 9 +++++++++
>> vl.c | 17 +++++------------
>> 6 files changed, 55 insertions(+), 13 deletions(-)
>> create mode 100644 accel.c
>> create mode 100644 accel.h
>>
>> diff --git a/Makefile.target b/Makefile.target
>> index e2edf9d..623ecd8 100644
>> --- a/Makefile.target
>> +++ b/Makefile.target
>> @@ -188,7 +188,7 @@ all: $(PROGS)
>> #########################################################
>> # cpu emulator library
>> LIBOBJS=exec.o kqemu.o translate-all.o cpu-exec.o\
>> - translate.o host-utils.o
>> + translate.o host-utils.o accel.o
>> ifdef CONFIG_DYNGEN_OP
>> exec.o: dyngen-opc.h
>> LIBOBJS+=op.o
>> diff --git a/accel.c b/accel.c
>> new file mode 100644
>> index 0000000..d30460d
>> --- /dev/null
>> +++ b/accel.c
>> @@ -0,0 +1,17 @@
>> +#include "hw/hw.h"
>> +#include "accel.h"
>> +
>> +QEMUAccel *current_accel;
>> +
>> +int _accel_nop(void)
>> +{
>> + return 0;
>> +}
>> +
>> +#define accel_nop ((void *)_accel_nop)
>> +
>> +/* Accelerator wrapper for the no-accel (raw qemu) case */
>> +QEMUAccel noaccel = {
>> + .cpu_interrupt = accel_nop,
>> +};
>> +
>> diff --git a/accel.h b/accel.h
>> new file mode 100644
>> index 0000000..8e5ddc6
>> --- /dev/null
>> +++ b/accel.h
>> @@ -0,0 +1,20 @@
>> +#ifndef _ACCEL_H_
>> +#define _ACCEL_H_
>> +
>> +typedef struct QEMUAccel {
>> + void (*cpu_interrupt)(CPUState *env);
>> +} QEMUAccel;
>> +
>> +extern QEMUAccel *current_accel;
>> +extern QEMUAccel noaccel;
>> +
>> +static inline void register_qemu_accel(QEMUAccel *accel)
>> +{
>> + current_accel = accel;
>> +}
>> +
>> +static inline void accel_cpu_interrupt(CPUState *env)
>> +{
>> + current_accel->cpu_interrupt(env);
>> +}
>> +#endif
>> diff --git a/exec.c b/exec.c
>> index 1cad0be..21253cc 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -43,6 +43,8 @@
>> #include <qemu.h>
>> #endif
>>
>> +#include "accel.h"
>> +
>> //#define DEBUG_TB_INVALIDATE
>> //#define DEBUG_FLUSH
>> //#define DEBUG_TLB
>> @@ -1430,6 +1432,7 @@ void cpu_single_step(CPUState *env, int enabled)
>> tb_flush(env);
>> }
>> #endif
>> + accel_cpu_interrupt(env);
>> }
>>
>> /* enable or disable low levels log */
>> diff --git a/kqemu.c b/kqemu.c
>> index 9b52237..87c06cd 100644
>> --- a/kqemu.c
>> +++ b/kqemu.c
>> @@ -50,6 +50,7 @@
>> #include <unistd.h>
>> #include <fcntl.h>
>> #include "kqemu.h"
>> +#include "accel.h"
>>
>> #ifdef _WIN32
>> #define KQEMU_DEVICE "\\\\.\\kqemu"
>> @@ -150,6 +151,8 @@ static void kqemu_update_cpuid(CPUState *env)
>> accelerated code */
>> }
>>
>> +QEMUAccel kqemu_accel;
>> +
>> int kqemu_start(void)
>> {
>> struct kqemu_init kinit;
>> @@ -232,6 +235,7 @@ int kqemu_start(void)
>> }
>> nb_pages_to_flush = 0;
>> nb_ram_pages_to_update = 0;
>> + register_qemu_accel(&kqemu_accel);
>>
>> qpi_init();
>> return 0;
>> @@ -243,6 +247,11 @@ void kqemu_init_env(CPUState *env)
>> env->kqemu_enabled = kqemu_allowed;
>> }
>>
>> +QEMUAccel kqemu_accel = {
>> + .cpu_interrupt = kqemu_cpu_interrupt,
>> +};
>>
>
> 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.
KVM has code in cpu interrupt. So even if we move kqemu elsewhere,
this one might still be useful.
> Regards,
>
> Anthony Liguori
>
>
>
--
Glauber Costa.
"Free as in Freedom"
http://glommer.net
"The less confident you are, the more serious you have to act."
^ permalink raw reply [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 03/21] init env made accel driver
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (2 preceding siblings ...)
2008-10-15 21:54 ` [Qemu-devel] [PATCH 02/21] introduce QEMUAccel and fill it with interrupt specific driver Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 21:55 ` [Qemu-devel] [PATCH 04/21] wrap cache flushing functions into accel drivers Glauber Costa
` (17 subsequent siblings)
21 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
Yet another accel field: init_env
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
accel.c | 1 +
accel.h | 7 +++++++
kqemu.c | 1 +
target-i386/helper.c | 6 +++---
4 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/accel.c b/accel.c
index d30460d..3a17dc5 100644
--- a/accel.c
+++ b/accel.c
@@ -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,
};
diff --git a/accel.h b/accel.h
index 8e5ddc6..0d916dc 100644
--- a/accel.h
+++ b/accel.h
@@ -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
diff --git a/kqemu.c b/kqemu.c
index 87c06cd..4759bf3 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -249,6 +249,7 @@ void kqemu_init_env(CPUState *env)
QEMUAccel kqemu_accel = {
.cpu_interrupt = kqemu_cpu_interrupt,
+ .init_env = kqemu_init_env,
};
diff --git a/target-i386/helper.c b/target-i386/helper.c
index ee8cc86..d15e3f9 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -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;
}
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 04/21] wrap cache flushing functions into accel drivers
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (3 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 03/21] init env made accel driver Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 20:23 ` [Qemu-devel] " Anthony Liguori
2008-10-15 21:55 ` [Qemu-devel] [PATCH 05/21] turn info kqemu into generic info accelerator Glauber Costa
` (16 subsequent siblings)
21 siblings, 1 reply; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
Yet another accel field: cache flushing functions
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
accel.c | 2 ++
accel.h | 11 +++++++++++
exec.c | 15 +++++++--------
kqemu.c | 15 +++++++++------
4 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/accel.c b/accel.c
index 3a17dc5..6776244 100644
--- a/accel.c
+++ b/accel.c
@@ -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,
};
diff --git a/accel.h b/accel.h
index 0d916dc..935cfef 100644
--- a/accel.h
+++ b/accel.h
@@ -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
diff --git a/exec.c b/exec.c
index 21253cc..c761f4a 100644
--- a/exec.c
+++ b/exec.c
@@ -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
}
diff --git a/kqemu.c b/kqemu.c
index 4759bf3..56e59fd 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -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
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] Re: [PATCH 04/21] wrap cache flushing functions into accel drivers
2008-10-15 21:55 ` [Qemu-devel] [PATCH 04/21] wrap cache flushing functions into accel drivers Glauber Costa
@ 2008-10-15 20:23 ` Anthony Liguori
2008-10-15 21:02 ` Glauber Costa
0 siblings, 1 reply; 36+ messages in thread
From: Anthony Liguori @ 2008-10-15 20:23 UTC (permalink / raw)
To: Glauber Costa
Cc: jan.kiszka, jes, qemu-devel, avi, Glauber Costa, dmitry.baryshkov
Glauber Costa wrote:
> From: Glauber Costa <gcosta@redhat.com>
>
> Yet another accel field: cache flushing functions
> Signed-off-by: Glauber Costa <glommer@redhat.com>
> ---
> accel.c | 2 ++
> accel.h | 11 +++++++++++
> exec.c | 15 +++++++--------
> kqemu.c | 15 +++++++++------
> 4 files changed, 29 insertions(+), 14 deletions(-)
>
> diff --git a/accel.c b/accel.c
> index 3a17dc5..6776244 100644
> --- a/accel.c
> +++ b/accel.c
> @@ -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,
> };
>
> diff --git a/accel.h b/accel.h
> index 0d916dc..935cfef 100644
> --- a/accel.h
> +++ b/accel.h
> @@ -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
> diff --git a/exec.c b/exec.c
> index 21253cc..c761f4a 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -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);
>
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.
> #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)
>
And what is this if() being added for?
Regards,
Anthony Liguori
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] Re: [PATCH 04/21] wrap cache flushing functions into accel drivers
2008-10-15 20:23 ` [Qemu-devel] " Anthony Liguori
@ 2008-10-15 21:02 ` Glauber Costa
0 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:02 UTC (permalink / raw)
To: qemu-devel
Cc: jan.kiszka, Glauber Costa, jes, avi, Glauber Costa,
dmitry.baryshkov
On Wed, Oct 15, 2008 at 6:23 PM, Anthony Liguori <aliguori@us.ibm.com> wrote:
> Glauber Costa wrote:
>>
>> From: Glauber Costa <gcosta@redhat.com>
>>
>> Yet another accel field: cache flushing functions
>> Signed-off-by: Glauber Costa <glommer@redhat.com>
>> ---
>> accel.c | 2 ++
>> accel.h | 11 +++++++++++
>> exec.c | 15 +++++++--------
>> kqemu.c | 15 +++++++++------
>> 4 files changed, 29 insertions(+), 14 deletions(-)
>>
>> diff --git a/accel.c b/accel.c
>> index 3a17dc5..6776244 100644
>> --- a/accel.c
>> +++ b/accel.c
>> @@ -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,
>> };
>>
>> diff --git a/accel.h b/accel.h
>> index 0d916dc..935cfef 100644
>> --- a/accel.h
>> +++ b/accel.h
>> @@ -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
>> diff --git a/exec.c b/exec.c
>> index 21253cc..c761f4a 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -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);
>>
>
> 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.
Ancient versions of the patch. This code was removed and I didn't notice it.
thanks
>
>> #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)
>>
>
> And what is this if() being added for?
>
>
> Regards,
>
> Anthony Liguori
>
>
>
--
Glauber Costa.
"Free as in Freedom"
http://glommer.net
"The less confident you are, the more serious you have to act."
^ permalink raw reply [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 05/21] turn info kqemu into generic info accelerator
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (4 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 04/21] wrap cache flushing functions into accel drivers Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 20:25 ` [Qemu-devel] " Anthony Liguori
2008-10-15 21:55 ` [Qemu-devel] [PATCH 06/21] separate accelerator part of info profiler Glauber Costa
` (15 subsequent siblings)
21 siblings, 1 reply; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
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 <glommer@redhat.com>
---
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");
+}
+
#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,
};
diff --git a/accel.h b/accel.h
index 935cfef..45a3fca 100644
--- a/accel.h
+++ b/accel.h
@@ -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
diff --git a/kqemu.c b/kqemu.c
index 56e59fd..ac12e17 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -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,
};
diff --git a/monitor.c b/monitor.c
index 4d7c782..c638a38 100644
--- a/monitor.c
+++ b/monitor.c
@@ -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,
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] Re: [PATCH 05/21] turn info kqemu into generic info accelerator
2008-10-15 21:55 ` [Qemu-devel] [PATCH 05/21] turn info kqemu into generic info accelerator Glauber Costa
@ 2008-10-15 20:25 ` Anthony Liguori
2008-10-15 21:23 ` M. Warner Losh
0 siblings, 1 reply; 36+ messages in thread
From: Anthony Liguori @ 2008-10-15 20:25 UTC (permalink / raw)
To: Glauber Costa
Cc: jan.kiszka, jes, qemu-devel, avi, Glauber Costa, dmitry.baryshkov
Glauber Costa wrote:
> From: Glauber Costa <gcosta@redhat.com>
>
> 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 <glommer@redhat.com>
> ---
> 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().
Regards,
Anthony Liguori
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] Re: [PATCH 05/21] turn info kqemu into generic info accelerator
2008-10-15 20:25 ` [Qemu-devel] " Anthony Liguori
@ 2008-10-15 21:23 ` M. Warner Losh
2008-10-15 21:28 ` Glauber Costa
0 siblings, 1 reply; 36+ messages in thread
From: M. Warner Losh @ 2008-10-15 21:23 UTC (permalink / raw)
To: qemu-devel, aliguori
Cc: jan.kiszka, glommer, jes, avi, gcosta, dmitry.baryshkov
In message: <48F651B0.8030502@us.ibm.com>
Anthony Liguori <aliguori@us.ibm.com> writes:
: Glauber Costa wrote:
: > From: Glauber Costa <gcosta@redhat.com>
: >
: > 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 <glommer@redhat.com>
: > ---
: > 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
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] Re: [PATCH 05/21] turn info kqemu into generic info accelerator
2008-10-15 21:23 ` M. Warner Losh
@ 2008-10-15 21:28 ` Glauber Costa
0 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:28 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, glommer, jes, avi, gcosta, dmitry.baryshkov
On Wed, Oct 15, 2008 at 7:23 PM, M. Warner Losh <imp@bsdimp.com> wrote:
> In message: <48F651B0.8030502@us.ibm.com>
> Anthony Liguori <aliguori@us.ibm.com> writes:
> : Glauber Costa wrote:
> : > From: Glauber Costa <gcosta@redhat.com>
> : >
> : > 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 <glommer@redhat.com>
> : > ---
> : > 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?
Accelerators probably want to display something on their own.
Returning a pointer to a string seems even worse to me.
>
> Warner
>
>
>
--
Glauber Costa.
"Free as in Freedom"
http://glommer.net
"The less confident you are, the more serious you have to act."
^ permalink raw reply [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 06/21] separate accelerator part of info profiler
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (5 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 05/21] turn info kqemu into generic info accelerator Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 21:55 ` [Qemu-devel] [PATCH 07/21] move kqemu externs to kqemu.h Glauber Costa
` (14 subsequent siblings)
21 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
Yet another accel field: profile.
It allows the accelerators to do part of the profiling their own way.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
accel.c | 1 +
accel.h | 6 ++++++
kqemu.c | 35 +++++++++++++++++++++++++++++++++++
monitor.c | 27 ++++++---------------------
4 files changed, 48 insertions(+), 21 deletions(-)
diff --git a/accel.c b/accel.c
index 466fe67..af9091c 100644
--- a/accel.c
+++ b/accel.c
@@ -22,5 +22,6 @@ QEMUAccel noaccel = {
.flush_cache = accel_nop,
.flush_page = accel_nop,
.info = noaccel_info,
+ .profile = accel_nop,
};
diff --git a/accel.h b/accel.h
index 45a3fca..754d49f 100644
--- a/accel.h
+++ b/accel.h
@@ -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
diff --git a/kqemu.c b/kqemu.c
index ac12e17..bcbe3cc 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -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,
};
diff --git a/monitor.c b/monitor.c
index c638a38..2f92bcc 100644
--- a/monitor.c
+++ b/monitor.c
@@ -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)
{
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 07/21] move kqemu externs to kqemu.h
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (6 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 06/21] separate accelerator part of info profiler Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 21:55 ` [Qemu-devel] [PATCH 08/21] move disabling code to kqemu.c instead of vl.c Glauber Costa
` (13 subsequent siblings)
21 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
move extern definitions to from cpu-all.h to kqemu.h.
Just a step to increase kqemu's degree of separation.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
cpu-all.h | 5 -----
kqemu.h | 6 ++++++
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/cpu-all.h b/cpu-all.h
index cdd79bc..0150827 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -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 */
diff --git a/kqemu.h b/kqemu.h
index ed25c75..1c7e024 100644
--- a/kqemu.h
+++ b/kqemu.h
@@ -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;
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 08/21] move disabling code to kqemu.c instead of vl.c
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (7 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 07/21] move kqemu externs to kqemu.h Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 20:32 ` [Qemu-devel] " Anthony Liguori
2008-10-15 21:55 ` [Qemu-devel] [PATCH 09/21] set_notdirty goes through accel wrapper Glauber Costa
` (12 subsequent siblings)
21 siblings, 1 reply; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
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.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
kqemu.c | 3 ++-
vl.c | 4 ----
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/kqemu.c b/kqemu.c
index bcbe3cc..bfb7339 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -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
diff --git a/vl.c b/vl.c
index f72172f..55a0c08 100644
--- a/vl.c
+++ b/vl.c
@@ -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;
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] Re: [PATCH 08/21] move disabling code to kqemu.c instead of vl.c
2008-10-15 21:55 ` [Qemu-devel] [PATCH 08/21] move disabling code to kqemu.c instead of vl.c Glauber Costa
@ 2008-10-15 20:32 ` Anthony Liguori
2008-10-15 21:02 ` Glauber Costa
0 siblings, 1 reply; 36+ messages in thread
From: Anthony Liguori @ 2008-10-15 20:32 UTC (permalink / raw)
To: Glauber Costa
Cc: jan.kiszka, jes, qemu-devel, avi, Glauber Costa, dmitry.baryshkov
Glauber Costa wrote:
> From: Glauber Costa <gcosta@redhat.com>
>
> 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.
>
Maybe the start accelerator should be passed the number of cpus instead
of relying on an extern variable?
Regards,
Anthony Liguori
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] Re: [PATCH 08/21] move disabling code to kqemu.c instead of vl.c
2008-10-15 20:32 ` [Qemu-devel] " Anthony Liguori
@ 2008-10-15 21:02 ` Glauber Costa
0 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:02 UTC (permalink / raw)
To: qemu-devel
Cc: jan.kiszka, Glauber Costa, jes, avi, Glauber Costa,
dmitry.baryshkov
On Wed, Oct 15, 2008 at 6:32 PM, Anthony Liguori <aliguori@us.ibm.com> wrote:
> Glauber Costa wrote:
>>
>> From: Glauber Costa <gcosta@redhat.com>
>>
>> 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.
>>
>
> Maybe the start accelerator should be passed the number of cpus instead of
> relying on an extern variable?
That's actually a good idea.
>
> Regards,
>
> Anthony Liguori
>
>
>
>
--
Glauber Costa.
"Free as in Freedom"
http://glommer.net
"The less confident you are, the more serious you have to act."
^ permalink raw reply [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 09/21] set_notdirty goes through accel wrapper
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (8 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 08/21] move disabling code to kqemu.c instead of vl.c Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 21:55 ` [Qemu-devel] [PATCH 10/21] wrap modify_page through accel calls Glauber Costa
` (11 subsequent siblings)
21 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
Yet another accel field: set_notdirty
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
accel.c | 1 +
accel.h | 6 ++++++
exec-all.h | 2 +-
exec.c | 18 +++++++-----------
kqemu.c | 23 +++++++++++------------
5 files changed, 26 insertions(+), 24 deletions(-)
diff --git a/accel.c b/accel.c
index af9091c..56718af 100644
--- a/accel.c
+++ b/accel.c
@@ -23,5 +23,6 @@ QEMUAccel noaccel = {
.flush_page = accel_nop,
.info = noaccel_info,
.profile = accel_nop,
+ .set_notdirty = accel_nop,
};
diff --git a/accel.h b/accel.h
index 754d49f..d404327 100644
--- a/accel.h
+++ b/accel.h
@@ -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
diff --git a/exec-all.h b/exec-all.h
index 6609c9a..2769c27 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -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);
diff --git a/exec.c b/exec.c
index c761f4a..a1a103b 100644
--- a/exec.c
+++ b/exec.c
@@ -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++)
diff --git a/kqemu.c b/kqemu.c
index bfb7339..92b64a7 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -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;
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 10/21] wrap modify_page through accel calls
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (9 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 09/21] set_notdirty goes through accel wrapper Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 21:55 ` [Qemu-devel] [PATCH 11/21] remove kqemu reference from hw/pc.c Glauber Costa
` (10 subsequent siblings)
21 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
Yet another accel field: modify_page
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
accel.c | 1 +
accel.h | 7 +++++++
exec-all.h | 2 +-
exec.c | 27 ++++++++++++---------------
kqemu.c | 26 +++++++++++++++-----------
5 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/accel.c b/accel.c
index 56718af..4cdfaf5 100644
--- a/accel.c
+++ b/accel.c
@@ -24,5 +24,6 @@ QEMUAccel noaccel = {
.info = noaccel_info,
.profile = accel_nop,
.set_notdirty = accel_nop,
+ .modify_page = accel_nop,
};
diff --git a/accel.h b/accel.h
index d404327..1f0d41b 100644
--- a/accel.h
+++ b/accel.h
@@ -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
diff --git a/exec-all.h b/exec-all.h
index 2769c27..d64d587 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -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);
diff --git a/exec.c b/exec.c
index a1a103b..b6f54c2 100644
--- a/exec.c
+++ b/exec.c
@@ -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
diff --git a/kqemu.c b/kqemu.c
index 92b64a7..9c3d0c5 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -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;
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 11/21] remove kqemu reference from hw/pc.c
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (10 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 10/21] wrap modify_page through accel calls Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 21:55 ` [Qemu-devel] [PATCH 12/21] build list of available accelerators Glauber Costa
` (9 subsequent siblings)
21 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
Instead, route cpu_get_ticks through accel driver.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
accel.c | 3 +++
accel.h | 12 ++++++++++++
hw/pc.c | 13 ++-----------
kqemu.c | 6 ++++++
4 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/accel.c b/accel.c
index 4cdfaf5..45ad1ee 100644
--- a/accel.c
+++ b/accel.c
@@ -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
};
diff --git a/accel.h b/accel.h
index 1f0d41b..c305e8c 100644
--- a/accel.h
+++ b/accel.h
@@ -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
diff --git a/hw/pc.c b/hw/pc.c
index 34683e7..2f56c1f 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -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 */
diff --git a/kqemu.c b/kqemu.c
index 9c3d0c5..e1c2dc3 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -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
};
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 12/21] build list of available accelerators
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (11 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 11/21] remove kqemu reference from hw/pc.c Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 21:55 ` [Qemu-devel] [PATCH 13/21] provide --accel option Glauber Costa
` (8 subsequent siblings)
21 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
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.
Signed-off-by: Glauber Costa <glommer@redhat.com>
Signed-off-by: Jes Sorensen <jes@sgi.com>
---
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(-)
diff --git a/accel.c b/accel.c
index 45ad1ee..3186d46 100644
--- a/accel.c
+++ b/accel.c
@@ -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,
diff --git a/accel.h b/accel.h
index c305e8c..c6f0ff3 100644
--- a/accel.h
+++ b/accel.h
@@ -2,8 +2,10 @@
#define _ACCEL_H_
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);
@@ -15,12 +17,51 @@ typedef struct QEMUAccel {
#endif
} QEMUAccel;
+typedef struct QEMUCont {
+ QEMUAccel *acc;
+ int active;
+ struct QEMUCont *next;
+} QEMUCont;
+
extern QEMUAccel *current_accel;
extern QEMUAccel noaccel;
+#ifdef USE_KQEMU
+extern QEMUAccel kqemu_accel;
+#endif
-static inline void register_qemu_accel(QEMUAccel *accel)
+extern QEMUCont *head;
+void *qemu_mallocz(size_t size);
+
+static inline int register_qemu_accel(QEMUAccel *accel)
{
- current_accel = accel;
+ QEMUCont *new, *tmp, *last = NULL;
+
+ for (tmp = head, last; tmp; tmp = tmp->next) {
+ /* we disallow registering the same accelerator twice */
+ if (tmp->acc == accel)
+ return -1;
+
+ if (!tmp->next)
+ last = tmp;
+ }
+
+ new = qemu_mallocz(sizeof(*head));
+
+ new->acc = accel;
+ new->active = 0;
+ new->next = NULL;
+
+ if (!head)
+ head = new;
+ else
+ last->next = new;
+
+ return 0;
+}
+
+static inline QEMUCont *get_accel_head(void)
+{
+ return head;
}
static inline void accel_cpu_interrupt(CPUState *env)
@@ -28,6 +69,24 @@ static inline void accel_cpu_interrupt(CPUState *env)
current_accel->cpu_interrupt(env);
}
+static inline int accel_start(void)
+{
+ int status = -1;
+ /* The top accelerator in the list gets tried first, but if it fails,
+ * keep trying until one of them succeeds or we exhaust the list */
+ QEMUCont *tmp = head;
+ while (tmp) {
+ if (tmp->acc && tmp->acc->start && (!(tmp->acc->start())) ) {
+ tmp->active = 1;
+ current_accel = tmp->acc;
+ status = 0;
+ break;
+ }
+ tmp = tmp->next;
+ }
+ return status;
+}
+
static inline void accel_init_env(CPUState *env)
{
current_accel->init_env(env);
diff --git a/exec.c b/exec.c
index b6f54c2..ac378a5 100644
--- a/exec.c
+++ b/exec.c
@@ -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)
diff --git a/kqemu.c b/kqemu.c
index e1c2dc3..9b4263d 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -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;
diff --git a/monitor.c b/monitor.c
index 2f92bcc..06bd806 100644
--- a/monitor.c
+++ b/monitor.c
@@ -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 1024
static 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
diff --git a/vl.c b/vl.c
index 55a0c08..c5fb2dc 100644
--- a/vl.c
+++ b/vl.c
@@ -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 */
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 13/21] provide --accel option
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (12 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 12/21] build list of available accelerators Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 20:36 ` [Qemu-devel] " Anthony Liguori
2008-10-15 21:55 ` [Qemu-devel] [PATCH 14/21] add tsc field to cpu definition Glauber Costa
` (7 subsequent siblings)
21 siblings, 1 reply; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel; +Cc: jan.kiszka, aliguori, jes, avi, dmitry.baryshkov
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.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
vl.c | 24 +++++++++++++++++++++---
1 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/vl.c b/vl.c
index c5fb2dc..f7a58ef 100644
--- a/vl.c
+++ b/vl.c
@@ -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";
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] Re: [PATCH 13/21] provide --accel option
2008-10-15 21:55 ` [Qemu-devel] [PATCH 13/21] provide --accel option Glauber Costa
@ 2008-10-15 20:36 ` Anthony Liguori
2008-10-15 21:08 ` Glauber Costa
2008-10-16 19:49 ` Glauber Costa
0 siblings, 2 replies; 36+ messages in thread
From: Anthony Liguori @ 2008-10-15 20:36 UTC (permalink / raw)
To: Glauber Costa; +Cc: jan.kiszka, jes, qemu-devel, avi, dmitry.baryshkov
Glauber Costa wrote:
> 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
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] Re: [PATCH 13/21] provide --accel option
2008-10-15 20:36 ` [Qemu-devel] " Anthony Liguori
@ 2008-10-15 21:08 ` Glauber Costa
2008-10-16 19:49 ` Glauber Costa
1 sibling, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:08 UTC (permalink / raw)
To: qemu-devel; +Cc: jan.kiszka, Glauber Costa, jes, avi, dmitry.baryshkov
On Wed, Oct 15, 2008 at 6:36 PM, Anthony Liguori <aliguori@us.ibm.com> wrote:
> Glauber Costa wrote:
>>
>> 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.
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 ?
>
> Regards,
>
> Anthony Liguori
>
>
>
>
--
Glauber Costa.
"Free as in Freedom"
http://glommer.net
"The less confident you are, the more serious you have to act."
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [Qemu-devel] Re: [PATCH 13/21] provide --accel option
2008-10-15 20:36 ` [Qemu-devel] " Anthony Liguori
2008-10-15 21:08 ` Glauber Costa
@ 2008-10-16 19:49 ` Glauber Costa
1 sibling, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-16 19:49 UTC (permalink / raw)
To: qemu-devel
On Wed, Oct 15, 2008 at 6:36 PM, Anthony Liguori <aliguori@us.ibm.com> wrote:
> Glauber Costa wrote:
>>
>> 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.
do we want to keep them for the sake of compatibility ?
>
> Regards,
>
> Anthony Liguori
>
>
>
>
--
Glauber Costa.
"Free as in Freedom"
http://glommer.net
"The less confident you are, the more serious you have to act."
^ permalink raw reply [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 14/21] add tsc field to cpu definition
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (13 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 13/21] provide --accel option Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 21:55 ` [Qemu-devel] [PATCH 15/21] shift for masks Glauber Costa
` (6 subsequent siblings)
21 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
kvm will use it, but it is pretty general
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
target-i386/cpu.h | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 3c11e0f..ab04500 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -580,6 +580,7 @@ typedef struct CPUX86State {
target_ulong kernelgsbase;
#endif
+ uint64_t tsc;
uint64_t pat;
/* exception/interrupt handling */
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 15/21] shift for masks.
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (14 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 14/21] add tsc field to cpu definition Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 21:55 ` [Qemu-devel] [PATCH 16/21] add hook to cpu_register_physical_memory Glauber Costa
` (5 subsequent siblings)
21 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
kvm uses, but pretty general
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
target-i386/cpu.h | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index ab04500..47c9fa6 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -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)
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 16/21] add hook to cpu_register_physical_memory
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (15 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 15/21] shift for masks Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 21:55 ` [Qemu-devel] [PATCH 17/21] accel_trace_io Glauber Costa
` (4 subsequent siblings)
21 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
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.
Signed-off-by: Glauber Costa <gcosta@redhat.com>
---
accel.c | 1 +
accel.h | 9 +++++++++
exec.c | 32 +++++++++++++++++++-------------
kqemu.c | 3 ++-
4 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/accel.c b/accel.c
index 3186d46..99a4eb1 100644
--- a/accel.c
+++ b/accel.c
@@ -31,5 +31,6 @@ QEMUAccel noaccel = {
#ifndef CONFIG_USER_ONLY
.get_real_ticks = cpu_get_ticks,
#endif
+ .register_physical_memory = accel_nop,
};
diff --git a/accel.h b/accel.h
index c6f0ff3..0811aa9 100644
--- a/accel.h
+++ b/accel.h
@@ -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
diff --git a/exec.c b/exec.c
index ac378a5..bd2a26f 100644
--- a/exec.c
+++ b/exec.c
@@ -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)
{
diff --git a/kqemu.c b/kqemu.c
index 9b4263d..248c4f5 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -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
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 17/21] accel_trace_io
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (16 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 16/21] add hook to cpu_register_physical_memory Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 21:55 ` [Qemu-devel] [PATCH 18/21] get_env accel wrapper Glauber Costa
` (3 subsequent siblings)
21 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
kqemu keeps trace of the last io done. Do it through
an accel_wrapper.
Signed-off-by: Glauber Costa <gcosta@redhat.com>
---
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(-)
diff --git a/accel.c b/accel.c
index 99a4eb1..6517af2 100644
--- a/accel.c
+++ b/accel.c
@@ -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,
};
diff --git a/accel.h b/accel.h
index 0811aa9..5f04163 100644
--- a/accel.h
+++ b/accel.h
@@ -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
diff --git a/cpu-exec.c b/cpu-exec.c
index 6d4dcdd..ce4e8a2 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -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();
diff --git a/kqemu.c b/kqemu.c
index 248c4f5..58e9e3f 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -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 {
diff --git a/softmmu_template.h b/softmmu_template.h
index 98dd378..4945352 100644
--- a/softmmu_template.h
+++ b/softmmu_template.h
@@ -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,
diff --git a/vl.c b/vl.c
index f7a58ef..409ae0e 100644
--- a/vl.c
+++ b/vl.c
@@ -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;
}
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 18/21] get_env accel wrapper
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (17 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 17/21] accel_trace_io Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 21:55 ` [Qemu-devel] [PATCH 19/21] add next_cpu_index Glauber Costa
` (2 subsequent siblings)
21 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
Allow the current accelerator to provide it's own, customized
address of the CPUState structure used for the env variable.
Signed-off-by: Glauber Costa <gcosta@redhat.com>
---
accel.c | 6 ++++++
accel.h | 7 +++++++
kqemu.c | 1 +
target-i386/helper.c | 2 +-
4 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/accel.c b/accel.c
index 6517af2..08329a4 100644
--- a/accel.c
+++ b/accel.c
@@ -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,
diff --git a/accel.h b/accel.h
index 5f04163..1d5986a 100644
--- a/accel.h
+++ b/accel.h
@@ -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);
diff --git a/kqemu.c b/kqemu.c
index 58e9e3f..d543e29 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -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,
diff --git a/target-i386/helper.c b/target-i386/helper.c
index d15e3f9..8fc33c6 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -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);
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 19/21] add next_cpu_index
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (18 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 18/21] get_env accel wrapper Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 21:55 ` [Qemu-devel] [PATCH 20/21] check wether kqemu is enabled in open code Glauber Costa
2008-10-15 21:55 ` [Qemu-devel] [PATCH 21/21] provide an opaque for accelerator in cpu state Glauber Costa
21 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel
Cc: aliguori, jan.kiszka, jes, avi, Glauber Costa, dmitry.baryshkov
From: Glauber Costa <gcosta@redhat.com>
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.
Signed-off-by: Glauber Costa <gcosta@redhat.com>
---
exec.c | 22 ++++++++++++++--------
1 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/exec.c b/exec.c
index bd2a26f..7710564 100644
--- a/exec.c
+++ b/exec.c
@@ -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
}
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 20/21] check wether kqemu is enabled in open code
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (19 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 19/21] add next_cpu_index Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-15 21:55 ` [Qemu-devel] [PATCH 21/21] provide an opaque for accelerator in cpu state Glauber Costa
21 siblings, 0 replies; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel; +Cc: jan.kiszka, aliguori, jes, avi, dmitry.baryshkov
kqemu 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.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
cpu-exec.c | 2 +-
exec-all.h | 7 +++++--
kqemu.c | 21 +++++++++++++++++++++
3 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/cpu-exec.c b/cpu-exec.c
index ce4e8a2..a9609d4 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -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);
diff --git a/exec-all.h b/exec-all.h
index d64d587..6230a37 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -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)));
}
diff --git a/kqemu.c b/kqemu.c
index d543e29..8b4561c 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -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)
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] [PATCH 21/21] provide an opaque for accelerator in cpu state
2008-10-15 21:54 [Qemu-devel] [PATCH 0/21] Accelerators: cleaned up version Glauber Costa
` (20 preceding siblings ...)
2008-10-15 21:55 ` [Qemu-devel] [PATCH 20/21] check wether kqemu is enabled in open code Glauber Costa
@ 2008-10-15 21:55 ` Glauber Costa
2008-10-16 9:26 ` [Qemu-devel] " Avi Kivity
21 siblings, 1 reply; 36+ messages in thread
From: Glauber Costa @ 2008-10-15 21:55 UTC (permalink / raw)
To: qemu-devel; +Cc: jan.kiszka, aliguori, jes, avi, dmitry.baryshkov
Convert kqemu to use it. We also provide a small macro
to easy the access to the accelerator fields.
Signed-off-by: Glauber Costa <glommer@redhat.com>
CC: Jes Sorensen <jes@sgi.com>
---
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(-)
diff --git a/accel.h b/accel.h
index 1d5986a..17a868c 100644
--- a/accel.h
+++ b/accel.h
@@ -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);
diff --git a/cpu-defs.h b/cpu-defs.h
index 5dcac74..989e221 100644
--- a/cpu-defs.h
+++ b/cpu-defs.h
@@ -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;
diff --git a/exec-all.h b/exec-all.h
index 6230a37..7f4a947 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -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) &&
diff --git a/kqemu.c b/kqemu.c
index 8b4561c..489c674 100644
--- a/kqemu.c
+++ b/kqemu.c
@@ -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;
diff --git a/kqemu.h b/kqemu.h
index 1c7e024..e121494 100644
--- a/kqemu.h
+++ b/kqemu.h
@@ -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;
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 47c9fa6..3772f54 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -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;
diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
index e9a6942..65d6b36 100644
--- a/target-i386/op_helper.c
+++ b/target-i386/op_helper.c
@@ -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;
--
1.5.5.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [Qemu-devel] Re: [PATCH 21/21] provide an opaque for accelerator in cpu state
2008-10-15 21:55 ` [Qemu-devel] [PATCH 21/21] provide an opaque for accelerator in cpu state Glauber Costa
@ 2008-10-16 9:26 ` Avi Kivity
0 siblings, 0 replies; 36+ messages in thread
From: Avi Kivity @ 2008-10-16 9:26 UTC (permalink / raw)
To: Glauber Costa
Cc: aliguori, jan.kiszka, jes, qemu-devel, avi, dmitry.baryshkov
Glauber Costa wrote:
> Convert kqemu to use it. We also provide a small macro
> to easy the access to the accelerator fields.
>
>
> +#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.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 36+ messages in thread