* [Qemu-devel] [PATCH] Avoid allocating TCG resources in non-TCG mode
@ 2011-08-02 14:10 Jan Kiszka
2011-08-03 12:19 ` Anthony PERARD
2011-08-05 16:46 ` Anthony Liguori
0 siblings, 2 replies; 3+ messages in thread
From: Jan Kiszka @ 2011-08-02 14:10 UTC (permalink / raw)
To: Anthony Liguori, qemu-devel
Cc: Anthony PERARD, Alexander Graf, Stefano Stabellini
Do not allocate TCG-only resources like the translation buffer when
running over KVM or XEN. Saves a "few" bytes in the qemu address space
and is also conceptually cleaner.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
Note: Only tested on x86.
bsd-user/main.c | 3 ++-
darwin-user/main.c | 4 ++--
exec.c | 19 ++++++++++++++-----
linux-user/main.c | 3 ++-
qemu-common.h | 5 ++++-
target-i386/helper.c | 4 ++--
target-ppc/helper.c | 4 +++-
target-s390x/helper.c | 2 +-
vl.c | 14 +++++++-------
9 files changed, 37 insertions(+), 21 deletions(-)
diff --git a/bsd-user/main.c b/bsd-user/main.c
index a63b877..cc7d4a3 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -905,7 +905,8 @@ int main(int argc, char **argv)
cpu_model = "any";
#endif
}
- cpu_exec_init_all(0);
+ tcg_exec_init(0);
+ cpu_exec_init_all();
/* NOTE: we need to init the CPU at this stage to get
qemu_host_page_size */
env = cpu_init(cpu_model);
diff --git a/darwin-user/main.c b/darwin-user/main.c
index 72307ad..1a881a0 100644
--- a/darwin-user/main.c
+++ b/darwin-user/main.c
@@ -852,8 +852,8 @@ int main(int argc, char **argv)
#error unsupported CPU
#endif
}
-
- cpu_exec_init_all(0);
+ tcg_exec_init(0);
+ cpu_exec_init_all();
/* NOTE: we need to init the CPU at this stage to get
qemu_host_page_size */
env = cpu_init(cpu_model);
diff --git a/exec.c b/exec.c
index 476b507..2658cb2 100644
--- a/exec.c
+++ b/exec.c
@@ -570,16 +570,12 @@ static void code_gen_alloc(unsigned long tb_size)
/* Must be called before using the QEMU cpus. 'tb_size' is the size
(in bytes) allocated to the translation buffer. Zero means default
size. */
-void cpu_exec_init_all(unsigned long tb_size)
+void tcg_exec_init(unsigned long tb_size)
{
cpu_gen_init();
code_gen_alloc(tb_size);
code_gen_ptr = code_gen_buffer;
page_init();
-#if !defined(CONFIG_USER_ONLY)
- memory_map_init();
- io_mem_init();
-#endif
#if !defined(CONFIG_USER_ONLY) || !defined(CONFIG_USE_GUEST_BASE)
/* There's no guest base to take into account, so go ahead and
initialize the prologue now. */
@@ -587,6 +583,19 @@ void cpu_exec_init_all(unsigned long tb_size)
#endif
}
+bool tcg_enabled(void)
+{
+ return code_gen_buffer != NULL;
+}
+
+void cpu_exec_init_all(void)
+{
+#if !defined(CONFIG_USER_ONLY)
+ memory_map_init();
+ io_mem_init();
+#endif
+}
+
#if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
static int cpu_common_post_load(void *opaque, int version_id)
diff --git a/linux-user/main.c b/linux-user/main.c
index 6a8f4bd..8e15474 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3117,7 +3117,8 @@ int main(int argc, char **argv, char **envp)
cpu_model = "any";
#endif
}
- cpu_exec_init_all(0);
+ tcg_exec_init(0);
+ cpu_exec_init_all();
/* NOTE: we need to init the CPU at this stage to get
qemu_host_page_size */
env = cpu_init(cpu_model);
diff --git a/qemu-common.h b/qemu-common.h
index 1e3c665..3440986 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -273,7 +273,10 @@ typedef struct VirtIODevice VirtIODevice;
typedef uint64_t pcibus_t;
-void cpu_exec_init_all(unsigned long tb_size);
+void tcg_exec_init(unsigned long tb_size);
+bool tcg_enabled(void);
+
+void cpu_exec_init_all(void);
/* CPU save/load. */
void cpu_save(QEMUFile *f, void *opaque);
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 182009a..3332195 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -1243,8 +1243,8 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
cpu_exec_init(env);
env->cpu_model_str = cpu_model;
- /* init various static tables */
- if (!inited) {
+ /* init various static tables used in TCG mode */
+ if (tcg_enabled() && !inited) {
inited = 1;
optimize_flags_init();
#ifndef CONFIG_USER_ONLY
diff --git a/target-ppc/helper.c b/target-ppc/helper.c
index 176128a..e00b3e6 100644
--- a/target-ppc/helper.c
+++ b/target-ppc/helper.c
@@ -3091,7 +3091,9 @@ CPUPPCState *cpu_ppc_init (const char *cpu_model)
env = qemu_mallocz(sizeof(CPUPPCState));
cpu_exec_init(env);
- ppc_translate_init();
+ if (tcg_enabled()) {
+ ppc_translate_init();
+ }
env->cpu_model_str = cpu_model;
cpu_ppc_register_internal(env, def);
diff --git a/target-s390x/helper.c b/target-s390x/helper.c
index 1ce7079..443bb1d 100644
--- a/target-s390x/helper.c
+++ b/target-s390x/helper.c
@@ -81,7 +81,7 @@ CPUS390XState *cpu_s390x_init(const char *cpu_model)
env = qemu_mallocz(sizeof(CPUS390XState));
cpu_exec_init(env);
- if (!inited) {
+ if (tcg_enabled() && !inited) {
inited = 1;
s390x_translate_init();
}
diff --git a/vl.c b/vl.c
index 26bee4e..cc4998f 100644
--- a/vl.c
+++ b/vl.c
@@ -265,6 +265,7 @@ int kvm_allowed = 0;
int xen_allowed = 0;
uint32_t xen_domid;
enum xen_mode xen_mode = XEN_EMULATE;
+static int tcg_tb_size;
static int default_serial = 1;
static int default_parallel = 1;
@@ -1942,6 +1943,7 @@ static QEMUMachine *machine_parse(const char *name)
static int tcg_init(void)
{
+ tcg_exec_init(tcg_tb_size * 1024 * 1024);
return 0;
}
@@ -2102,7 +2104,6 @@ int main(int argc, char **argv, char **envp)
const char *loadvm = NULL;
QEMUMachine *machine;
const char *cpu_model;
- int tb_size;
const char *pid_file = NULL;
const char *incoming = NULL;
#ifdef CONFIG_VNC
@@ -2142,7 +2143,6 @@ int main(int argc, char **argv, char **envp)
nb_numa_nodes = 0;
nb_nics = 0;
- tb_size = 0;
autostart= 1;
/* first pass of option parsing */
@@ -2857,9 +2857,10 @@ int main(int argc, char **argv, char **envp)
configure_rtc(opts);
break;
case QEMU_OPTION_tb_size:
- tb_size = strtol(optarg, NULL, 0);
- if (tb_size < 0)
- tb_size = 0;
+ tcg_tb_size = strtol(optarg, NULL, 0);
+ if (tcg_tb_size < 0) {
+ tcg_tb_size = 0;
+ }
break;
case QEMU_OPTION_icount:
icount_option = optarg;
@@ -3133,8 +3134,7 @@ int main(int argc, char **argv, char **envp)
}
}
- /* init the dynamic translator */
- cpu_exec_init_all(tb_size * 1024 * 1024);
+ cpu_exec_init_all();
bdrv_init_with_whitelist();
--
1.7.3.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] Avoid allocating TCG resources in non-TCG mode
2011-08-02 14:10 [Qemu-devel] [PATCH] Avoid allocating TCG resources in non-TCG mode Jan Kiszka
@ 2011-08-03 12:19 ` Anthony PERARD
2011-08-05 16:46 ` Anthony Liguori
1 sibling, 0 replies; 3+ messages in thread
From: Anthony PERARD @ 2011-08-03 12:19 UTC (permalink / raw)
To: Jan Kiszka
Cc: Anthony Liguori, Stefano Stabellini, qemu-devel, Alexander Graf
On Tue, Aug 2, 2011 at 15:10, Jan Kiszka <jan.kiszka@siemens.com> wrote:
> Do not allocate TCG-only resources like the translation buffer when
> running over KVM or XEN. Saves a "few" bytes in the qemu address space
> and is also conceptually cleaner.
>
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>
> Note: Only tested on x86.
This patch works fine with Xen and looks good.
Thanks,
--
Anthony PERARD
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] Avoid allocating TCG resources in non-TCG mode
2011-08-02 14:10 [Qemu-devel] [PATCH] Avoid allocating TCG resources in non-TCG mode Jan Kiszka
2011-08-03 12:19 ` Anthony PERARD
@ 2011-08-05 16:46 ` Anthony Liguori
1 sibling, 0 replies; 3+ messages in thread
From: Anthony Liguori @ 2011-08-05 16:46 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Anthony PERARD, Stefano Stabellini, qemu-devel, Alexander Graf
On 08/02/2011 09:10 AM, Jan Kiszka wrote:
> Do not allocate TCG-only resources like the translation buffer when
> running over KVM or XEN. Saves a "few" bytes in the qemu address space
> and is also conceptually cleaner.
>
> Signed-off-by: Jan Kiszka<jan.kiszka@siemens.com>
Applied. Thanks.
Regards,
Anthony Liguori
> ---
>
> Note: Only tested on x86.
>
> bsd-user/main.c | 3 ++-
> darwin-user/main.c | 4 ++--
> exec.c | 19 ++++++++++++++-----
> linux-user/main.c | 3 ++-
> qemu-common.h | 5 ++++-
> target-i386/helper.c | 4 ++--
> target-ppc/helper.c | 4 +++-
> target-s390x/helper.c | 2 +-
> vl.c | 14 +++++++-------
> 9 files changed, 37 insertions(+), 21 deletions(-)
>
> diff --git a/bsd-user/main.c b/bsd-user/main.c
> index a63b877..cc7d4a3 100644
> --- a/bsd-user/main.c
> +++ b/bsd-user/main.c
> @@ -905,7 +905,8 @@ int main(int argc, char **argv)
> cpu_model = "any";
> #endif
> }
> - cpu_exec_init_all(0);
> + tcg_exec_init(0);
> + cpu_exec_init_all();
> /* NOTE: we need to init the CPU at this stage to get
> qemu_host_page_size */
> env = cpu_init(cpu_model);
> diff --git a/darwin-user/main.c b/darwin-user/main.c
> index 72307ad..1a881a0 100644
> --- a/darwin-user/main.c
> +++ b/darwin-user/main.c
> @@ -852,8 +852,8 @@ int main(int argc, char **argv)
> #error unsupported CPU
> #endif
> }
> -
> - cpu_exec_init_all(0);
> + tcg_exec_init(0);
> + cpu_exec_init_all();
> /* NOTE: we need to init the CPU at this stage to get
> qemu_host_page_size */
> env = cpu_init(cpu_model);
> diff --git a/exec.c b/exec.c
> index 476b507..2658cb2 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -570,16 +570,12 @@ static void code_gen_alloc(unsigned long tb_size)
> /* Must be called before using the QEMU cpus. 'tb_size' is the size
> (in bytes) allocated to the translation buffer. Zero means default
> size. */
> -void cpu_exec_init_all(unsigned long tb_size)
> +void tcg_exec_init(unsigned long tb_size)
> {
> cpu_gen_init();
> code_gen_alloc(tb_size);
> code_gen_ptr = code_gen_buffer;
> page_init();
> -#if !defined(CONFIG_USER_ONLY)
> - memory_map_init();
> - io_mem_init();
> -#endif
> #if !defined(CONFIG_USER_ONLY) || !defined(CONFIG_USE_GUEST_BASE)
> /* There's no guest base to take into account, so go ahead and
> initialize the prologue now. */
> @@ -587,6 +583,19 @@ void cpu_exec_init_all(unsigned long tb_size)
> #endif
> }
>
> +bool tcg_enabled(void)
> +{
> + return code_gen_buffer != NULL;
> +}
> +
> +void cpu_exec_init_all(void)
> +{
> +#if !defined(CONFIG_USER_ONLY)
> + memory_map_init();
> + io_mem_init();
> +#endif
> +}
> +
> #if defined(CPU_SAVE_VERSION)&& !defined(CONFIG_USER_ONLY)
>
> static int cpu_common_post_load(void *opaque, int version_id)
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 6a8f4bd..8e15474 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -3117,7 +3117,8 @@ int main(int argc, char **argv, char **envp)
> cpu_model = "any";
> #endif
> }
> - cpu_exec_init_all(0);
> + tcg_exec_init(0);
> + cpu_exec_init_all();
> /* NOTE: we need to init the CPU at this stage to get
> qemu_host_page_size */
> env = cpu_init(cpu_model);
> diff --git a/qemu-common.h b/qemu-common.h
> index 1e3c665..3440986 100644
> --- a/qemu-common.h
> +++ b/qemu-common.h
> @@ -273,7 +273,10 @@ typedef struct VirtIODevice VirtIODevice;
>
> typedef uint64_t pcibus_t;
>
> -void cpu_exec_init_all(unsigned long tb_size);
> +void tcg_exec_init(unsigned long tb_size);
> +bool tcg_enabled(void);
> +
> +void cpu_exec_init_all(void);
>
> /* CPU save/load. */
> void cpu_save(QEMUFile *f, void *opaque);
> diff --git a/target-i386/helper.c b/target-i386/helper.c
> index 182009a..3332195 100644
> --- a/target-i386/helper.c
> +++ b/target-i386/helper.c
> @@ -1243,8 +1243,8 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
> cpu_exec_init(env);
> env->cpu_model_str = cpu_model;
>
> - /* init various static tables */
> - if (!inited) {
> + /* init various static tables used in TCG mode */
> + if (tcg_enabled()&& !inited) {
> inited = 1;
> optimize_flags_init();
> #ifndef CONFIG_USER_ONLY
> diff --git a/target-ppc/helper.c b/target-ppc/helper.c
> index 176128a..e00b3e6 100644
> --- a/target-ppc/helper.c
> +++ b/target-ppc/helper.c
> @@ -3091,7 +3091,9 @@ CPUPPCState *cpu_ppc_init (const char *cpu_model)
>
> env = qemu_mallocz(sizeof(CPUPPCState));
> cpu_exec_init(env);
> - ppc_translate_init();
> + if (tcg_enabled()) {
> + ppc_translate_init();
> + }
> env->cpu_model_str = cpu_model;
> cpu_ppc_register_internal(env, def);
>
> diff --git a/target-s390x/helper.c b/target-s390x/helper.c
> index 1ce7079..443bb1d 100644
> --- a/target-s390x/helper.c
> +++ b/target-s390x/helper.c
> @@ -81,7 +81,7 @@ CPUS390XState *cpu_s390x_init(const char *cpu_model)
>
> env = qemu_mallocz(sizeof(CPUS390XState));
> cpu_exec_init(env);
> - if (!inited) {
> + if (tcg_enabled()&& !inited) {
> inited = 1;
> s390x_translate_init();
> }
> diff --git a/vl.c b/vl.c
> index 26bee4e..cc4998f 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -265,6 +265,7 @@ int kvm_allowed = 0;
> int xen_allowed = 0;
> uint32_t xen_domid;
> enum xen_mode xen_mode = XEN_EMULATE;
> +static int tcg_tb_size;
>
> static int default_serial = 1;
> static int default_parallel = 1;
> @@ -1942,6 +1943,7 @@ static QEMUMachine *machine_parse(const char *name)
>
> static int tcg_init(void)
> {
> + tcg_exec_init(tcg_tb_size * 1024 * 1024);
> return 0;
> }
>
> @@ -2102,7 +2104,6 @@ int main(int argc, char **argv, char **envp)
> const char *loadvm = NULL;
> QEMUMachine *machine;
> const char *cpu_model;
> - int tb_size;
> const char *pid_file = NULL;
> const char *incoming = NULL;
> #ifdef CONFIG_VNC
> @@ -2142,7 +2143,6 @@ int main(int argc, char **argv, char **envp)
> nb_numa_nodes = 0;
> nb_nics = 0;
>
> - tb_size = 0;
> autostart= 1;
>
> /* first pass of option parsing */
> @@ -2857,9 +2857,10 @@ int main(int argc, char **argv, char **envp)
> configure_rtc(opts);
> break;
> case QEMU_OPTION_tb_size:
> - tb_size = strtol(optarg, NULL, 0);
> - if (tb_size< 0)
> - tb_size = 0;
> + tcg_tb_size = strtol(optarg, NULL, 0);
> + if (tcg_tb_size< 0) {
> + tcg_tb_size = 0;
> + }
> break;
> case QEMU_OPTION_icount:
> icount_option = optarg;
> @@ -3133,8 +3134,7 @@ int main(int argc, char **argv, char **envp)
> }
> }
>
> - /* init the dynamic translator */
> - cpu_exec_init_all(tb_size * 1024 * 1024);
> + cpu_exec_init_all();
>
> bdrv_init_with_whitelist();
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-08-05 16:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-02 14:10 [Qemu-devel] [PATCH] Avoid allocating TCG resources in non-TCG mode Jan Kiszka
2011-08-03 12:19 ` Anthony PERARD
2011-08-05 16:46 ` Anthony Liguori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).