tcg: Move TCG arch-specific initialization inside TCG code
cover tcg: Move TCG arch-specific initialization inside TCG code
Many architectures manually call arch-specific TCG initialization at CPU init time[1], instead of having tcg_init() doing all initialization steps. This series introduces a tcg_arch_init() function that may be implemented by architecture-specific code for TCG initialization.
[1] You can see it by grepping for "inited" on target-*/cpu.c.
Eduardo Habkost (2):
tcg: Introduce tcg_arch_init() function
target-i386: Implement tcg_arch_init()
include/qemu-common.h | 1 + stubs/Makefile.objs | 1 + stubs/tcg.c | 5 +++++ target-i386/cpu.c | 7 ------- target-i386/translate.c | 2 +- translate-all.c | 1 + 6 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 stubs/tcg.c
Signature · 1 line
1.9.3
PATCH 1/2 tcg: Introduce tcg_arch_init() function
Many architectures have arch-specific initialization functions that are called from CPU initialization at target-*/cpu.c.
Instead of requiring the CPU code to keep track of TCG initialization, let an arch-specific init function to be defined, and it will get called by tcg_exec_init().
--- include/qemu-common.h | 1 + stubs/Makefile.objs | 1 + stubs/tcg.c | 5 +++++ translate-all.c | 1 + 4 files changed, 8 insertions(+) create mode 100644 stubs/tcg.c
include/qemu-common.h +1 -0
@@ -269,6 +269,7 @@ typedef struct PCIHostDeviceAddress {void tcg_exec_init (unsigned long tb_size);bool tcg_enabled (void ); +void tcg_arch_init (void );void cpu_exec_init_all (void );
stubs/Makefile.objs +1 -0
@@ -40,3 +40,4 @@ stub-obj-$(CONFIG_WIN32) += fd-register.o stub-obj-y += cpus.o stub-obj-y += kvm.o stub-obj-y += qmp_pc_dimm_device_list.o +stub-obj-y += tcg.o
stubs/tcg.c new file +5 -0
@@ -0,0 +1,5 @@ +#include "qemu-common.h" + +void tcg_arch_init (void ) +{ +}
translate-all.c +1 -0
@@ -702,6 +702,7 @@ void tcg_exec_init(unsigned long tb_size)initialize the prologue now. */ tcg_prologue_init (&tcg_ctx);#endif +tcg_arch_init (); }bool tcg_enabled (void )
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 1/2] tcg: Introduce tcg_arch_init() function
Quoted 1 line · Eduardo Habkost
+void
tcg_arch_init(void);
I'm not keen on the name, because it's fairly ambiguous whether "arch" is talking about the host or target. It doesn't help that "tcg_target" is the host. ;-P
Assuming we do this (see hook discussion), what about "translator" instead?
r~
PATCH 2/2 target-i386: Implement tcg_arch_init()
In reply to Eduardo HabkostWith tcg_arch_init(), we can finally remove the "inited" variable from x86_cpu_initfn().
--- target-i386/cpu.c | 7 ------- target-i386/translate.c | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-)
target-i386/cpu.c +0 -7
@@ -2885,7 +2885,6 @@ static void x86_cpu_initfn(Object *obj)X86CPU *cpu =X86_CPU (obj);X86CPUClass *xcc =X86_CPU_GET_CLASS (obj);CPUX86State *env = &cpu->env; -static int inited; cs->env_ptr = env;cpu_exec_init (env);
@@ -2928,12 +2927,6 @@ static void x86_cpu_initfn(Object *obj) env->cpuid_apic_id =x86_cpu_apic_id_from_index (cs->cpu_index);x86_cpu_load_def (cpu, xcc->cpu_def, &error_abort); - -/* init various static tables used in TCG mode */ -if (tcg_enabled () && !inited) { - inited =1 ; -optimize_flags_init (); - } }static int64_t x86_cpu_get_arch_id (CPUState *cs)
target-i386/translate.c +1 -1
@@ -7841,7 +7841,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,return s->pc; } -void optimize_flags_init (void ) +void tcg_arch_init (void ) {static const char reg_names[CPU_NB_REGS ][4 ] = { #ifdef TARGET_X86_64
Signature · 1 line
1.9.3
Am 19.12.2014 um 05:26 schrieb Eduardo Habkost:
Quoted 4 lines
Many architectures manually call arch-specific TCG initialization at CPU init time[1], instead of having
tcg_init()doing all initialization steps. This series introduces atcg_arch_init()function that may be implemented by architecture-specific code for TCG initialization.
How do you imagine this to work with multiple CPU types? From the looks of it, this is for the target CPU, not the TCG architecture, so tcg_arch_init() limits us to one implementation unlike now. On the other hand it doesn't seem to be a per-CPU, i.e. CPUClass, initialization either...
Regards,
Andreas
Signature · 2 lines
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 21284 AG Nürnberg
Quoted 5 lines · Andreas Färber
How do you imagine this to work with multiple CPU types? From the looks of it, this is for the target CPU, not the TCG architecture, so
tcg_arch_init()limits us to one implementation unlike now. On the other hand it doesn't seem to be a per-CPU, i.e. CPUClass, initialization either...
I think these should go in a separate CPUClass method that is called by tcg_exec_init (only for first_cpu now; later for all CPUs if each CPU gets a separate tcg_ctx).
Paolo
Quoted 10 lines · Paolo Bonzini
Quoted 5 lines · Andreas Färber
How do you imagine this to work with multiple CPU types? From the looks of it, this is for the target CPU, not the TCG architecture, so
tcg_arch_init()limits us to one implementation unlike now. On the other hand it doesn't seem to be a per-CPU, i.e. CPUClass, initialization either...I think these should go in a separate CPUClass method that is called by
tcg_exec_init(only forfirst_cpunow; later for all CPUs if each CPU gets a separatetcg_ctx).
configure_accelerator() (and tcg_exec_init()) is called before machine_class->init() (where the CPUs are created).
I have work in progress that introduces arch-specific TYPE_ACCEL subclasses. With this, we can then make tcg_arch_init() a TYPE_TCG_ACCEL method that arch-specific TYPE_TCG_ACCEL subclasses can implement.
Is it already possible to build a QEMU binary with multiple TCG arches, today?
Signature · 1 line
Eduardo