accel/tcg: Allow tcg_exec_realizefn() initialize multiple frontends
cover accel/tcg: Allow tcg_exec_realizefn() initialize multiple frontends
Little step toward heterogeneous emulation. After few trivial cleanups, allow accel_cpu_common_realize() -> tcg_exec_realizefn() to call frontend TCGCPUOps::initialize() for different targets.
Philippe Mathieu-Daudé (6):
target/ppc: Indent ppc_tcg_ops[] with 4 spaces accel/tcg: Declare local tcg_ops variable in tcg_exec_realizefn() accel/tcg: Rename TCGCPUOps::initialize() as initialize_once()
include: Expose QemuArch in 'qemu/arch_id.h'
accel/tcg: Add TCGCPUOps::arch_id field
accel/tcg: Allow tcg_exec_realizefn() initialize multiple frontends
include/hw/core/tcg-cpu-ops.h | 9 ++++++--- include/qemu/arch_id.h | 28 ++++++++++++++++++++++++++++ include/sysemu/arch_init.h | 28 +++------------------------- accel/tcg/cpu-exec.c | 13 +++++++------ target/alpha/cpu.c | 3 ++- target/arm/cpu.c | 3 ++- target/arm/tcg/cpu-v7m.c | 3 ++- target/avr/cpu.c | 3 ++- target/hexagon/cpu.c | 3 ++- target/hppa/cpu.c | 3 ++- target/i386/tcg/tcg-cpu.c | 3 ++- target/loongarch/cpu.c | 3 ++- target/m68k/cpu.c | 3 ++- target/microblaze/cpu.c | 3 ++- target/mips/cpu.c | 3 ++- target/openrisc/cpu.c | 3 ++- target/ppc/cpu_init.c | 30 +++++++++++++++--------------- target/riscv/tcg/tcg-cpu.c | 3 ++- target/rx/cpu.c | 3 ++- target/s390x/cpu.c | 3 ++- target/sh4/cpu.c | 3 ++- target/sparc/cpu.c | 3 ++- target/tricore/cpu.c | 3 ++- target/xtensa/cpu.c | 3 ++- 24 files changed, 97 insertions(+), 68 deletions(-) create mode 100644 include/qemu/arch_id.h
Signature · 1 line
2.45.2
PATCH 1/6 target/ppc: Indent ppc_tcg_ops[] with 4 spaces
--- target/ppc/cpu_init.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
target/ppc/cpu_init.c +14 -15
@@ -7416,23 +7416,22 @@ static const struct SysemuCPUOps ppc_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps ppc_tcg_ops = { - .initialize = ppc_translate_init, - .restore_state_to_opc = ppc_restore_state_to_opc, - + .initialize = ppc_translate_init, + .restore_state_to_opc = ppc_restore_state_to_opc, #ifdef CONFIG_USER_ONLY - .record_sigsegv = ppc_cpu_record_sigsegv, + .record_sigsegv = ppc_cpu_record_sigsegv, #else - .tlb_fill = ppc_cpu_tlb_fill, - .cpu_exec_interrupt = ppc_cpu_exec_interrupt, - .cpu_exec_halt = ppc_cpu_has_work, - .do_interrupt = ppc_cpu_do_interrupt, - .cpu_exec_enter = ppc_cpu_exec_enter, - .cpu_exec_exit = ppc_cpu_exec_exit, - .do_unaligned_access = ppc_cpu_do_unaligned_access, - .do_transaction_failed = ppc_cpu_do_transaction_failed, - .debug_excp_handler = ppc_cpu_debug_excp_handler, - .debug_check_breakpoint = ppc_cpu_debug_check_breakpoint, - .debug_check_watchpoint = ppc_cpu_debug_check_watchpoint, + .tlb_fill = ppc_cpu_tlb_fill, + .cpu_exec_interrupt = ppc_cpu_exec_interrupt, + .cpu_exec_halt = ppc_cpu_has_work, + .do_interrupt = ppc_cpu_do_interrupt, + .cpu_exec_enter = ppc_cpu_exec_enter, + .cpu_exec_exit = ppc_cpu_exec_exit, + .do_unaligned_access = ppc_cpu_do_unaligned_access, + .do_transaction_failed = ppc_cpu_do_transaction_failed, + .debug_excp_handler = ppc_cpu_debug_excp_handler, + .debug_check_breakpoint = ppc_cpu_debug_check_breakpoint, + .debug_check_watchpoint = ppc_cpu_debug_check_watchpoint, #endif /* !CONFIG_USER_ONLY */ };#endif /* CONFIG_TCG */
Signature · 1 line
2.45.2
Re: [PATCH-for-10.0 1/6] target/ppc: Indent ppc_tcg_ops[] with 4 spaces
Quoted 5 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Acked-by Nicholas Piggin <[email protected]>--- target/ppc/cpu_init.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
Re: [PATCH-for-10.0 1/6] target/ppc: Indent ppc_tcg_ops[] with 4 spaces
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Acked-by Nicholas Piggin <[email protected]>--- target/ppc/cpu_init.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
r~
PATCH 2/6 accel/tcg: Declare local tcg_ops variable in tcg_exec_realizefn()
In reply to Philippe Mathieu-DaudéEase reading code by declaring a local 'tcg_ops' variable.
--- accel/tcg/cpu-exec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
accel/tcg/cpu-exec.c +4 -4
@@ -1070,15 +1070,15 @@ int cpu_exec(CPUState *cpu)bool tcg_exec_realizefn (CPUState *cpu,Error **errp) { -static bool tcg_target_initialized; +const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops;if (!tcg_target_initialized) {/* Check mandatory TCGCPUOps handlers */ #ifndef CONFIG_USER_ONLY -assert (cpu->cc->tcg_ops->cpu_exec_halt); -assert (cpu->cc->tcg_ops->cpu_exec_interrupt); +assert (tcg_ops->cpu_exec_halt); +assert (tcg_ops->cpu_exec_interrupt);#endif /* !CONFIG_USER_ONLY */ - cpu->cc->tcg_ops->initialize (); + tcg_ops->initialize (); tcg_target_initialized = true; }
Signature · 1 line
2.45.2
Re: [PATCH-for-10.0 2/6] accel/tcg: Declare local tcg_ops variable in tcg_exec_realizefn()
Quoted 6 lines · Philippe Mathieu-Daudé
Ease reading code by declaring a local '
tcg_ops' variable.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- accel/tcg/cpu-exec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Re: [PATCH-for-10.0 2/6] accel/tcg: Declare local tcg_ops variable in tcg_exec_realizefn()
In reply to Philippe Mathieu-DaudéQuoted 6 lines · Philippe Mathieu-Daudé
Ease reading code by declaring a local '
tcg_ops' variable.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- accel/tcg/cpu-exec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
r~
Quoted 25 lines
accel/tcg/cpu-exec.c +4
-4@@ -1070,15 +1070,15 @@ int cpu_exec(CPUState *cpu)bool tcg_exec_realizefn (CPUState *cpu,Error **errp) { -static bool tcg_target_initialized; +const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops;if (!tcg_target_initialized) {/* Check mandatory TCGCPUOps handlers */ #ifndef CONFIG_USER_ONLY -assert (cpu->cc->tcg_ops->cpu_exec_halt); -assert (cpu->cc->tcg_ops->cpu_exec_interrupt); +assert (tcg_ops->cpu_exec_halt); +assert (tcg_ops->cpu_exec_interrupt);#endif /* !CONFIG_USER_ONLY */ - cpu->cc->tcg_ops->initialize (); + tcg_ops->initialize (); tcg_target_initialized = true; }
Re: [PATCH-for-10.0 2/6] accel/tcg: Declare local tcg_ops variable in tcg_exec_realizefn()
In reply to Philippe Mathieu-DaudéQuoted 3 lines · Philippe Mathieu-Daudé
bool
tcg_exec_realizefn(CPUState *cpu, Error **errp){
- static booltcg_target_initialized;
Error removing this variable before patch 6.
r~
Quoted 13 lines
accel/tcg/cpu-exec.c +4
-3+const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops;if (!tcg_target_initialized) {/* Check mandatory TCGCPUOps handlers */ #ifndef CONFIG_USER_ONLY -assert (cpu->cc->tcg_ops->cpu_exec_halt); -assert (cpu->cc->tcg_ops->cpu_exec_interrupt); +assert (tcg_ops->cpu_exec_halt); +assert (tcg_ops->cpu_exec_interrupt);#endif /* !CONFIG_USER_ONLY */ - cpu->cc->tcg_ops->initialize (); + tcg_ops->initialize (); tcg_target_initialized = true;
PATCH 3/6 accel/tcg: Rename TCGCPUOps::initialize() as initialize_once()
In reply to Philippe Mathieu-DaudéWhile this handler can be called multiple times, it will only be run once. Clarify by renaming the handler name.
---
We could "optimize" TGC frontends memory use by passing a CPUClass argument, and each initialize() call would initialize TCG registers required for a particular CPUClass which are not yet initialized by previous calls. Not a priority / worth it.
--- include/hw/core/tcg-cpu-ops.h | 6 +++--- accel/tcg/cpu-exec.c | 2 +- target/alpha/cpu.c | 2 +- target/arm/cpu.c | 2 +- target/arm/tcg/cpu-v7m.c | 2 +- target/avr/cpu.c | 2 +- target/hexagon/cpu.c | 2 +- target/hppa/cpu.c | 2 +- target/i386/tcg/tcg-cpu.c | 2 +- target/loongarch/cpu.c | 2 +- target/m68k/cpu.c | 2 +- target/microblaze/cpu.c | 2 +- target/mips/cpu.c | 2 +- target/openrisc/cpu.c | 2 +- target/ppc/cpu_init.c | 2 +- target/riscv/tcg/tcg-cpu.c | 2 +- target/rx/cpu.c | 2 +- target/s390x/cpu.c | 2 +- target/sh4/cpu.c | 2 +- target/sparc/cpu.c | 2 +- target/tricore/cpu.c | 2 +- target/xtensa/cpu.c | 2 +- 22 files changed, 24 insertions(+), 24 deletions(-)
include/hw/core/tcg-cpu-ops.h +3 -3
@@ -19,11 +19,11 @@struct TCGCPUOps {/** -* @initialize: Initialize TCG state +* @initialize_once: Initialize TCG state * -* Called when the first CPU is realized. +* Called once when the first CPU is realized. */ -void (*initialize)(void ); +void (*initialize_once)(void );/** * @synchronize_from_tb: Synchronize state from a TCG #TranslationBlock *
accel/tcg/cpu-exec.c +1 -1
@@ -1078,7 +1078,7 @@ bool tcg_exec_realizefn(CPUState *cpu, Error **errp)assert (tcg_ops->cpu_exec_halt);assert (tcg_ops->cpu_exec_interrupt);#endif /* !CONFIG_USER_ONLY */ - tcg_ops->initialize (); + tcg_ops->initialize_once (); tcg_target_initialized = true; }
target/alpha/cpu.c +1 -1
@@ -220,7 +220,7 @@ static const struct SysemuCPUOps alpha_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps alpha_tcg_ops = { - .initialize = alpha_translate_init, + .initialize_once = alpha_translate_init, .synchronize_from_tb = alpha_cpu_synchronize_from_tb, .restore_state_to_opc = alpha_restore_state_to_opc,
target/arm/cpu.c +1 -1
@@ -2671,7 +2671,7 @@ static const struct SysemuCPUOps arm_sysemu_ops = {#ifdef CONFIG_TCG static const TCGCPUOps arm_tcg_ops = { - .initialize = arm_translate_init, + .initialize_once = arm_translate_init, .synchronize_from_tb = arm_cpu_synchronize_from_tb, .debug_excp_handler = arm_debug_excp_handler, .restore_state_to_opc = arm_restore_state_to_opc,
target/arm/tcg/cpu-v7m.c +1 -1
@@ -233,7 +233,7 @@ static void cortex_m55_initfn(Object *obj) }static const TCGCPUOps arm_v7m_tcg_ops = { - .initialize = arm_translate_init, + .initialize_once = arm_translate_init, .synchronize_from_tb = arm_cpu_synchronize_from_tb, .debug_excp_handler = arm_debug_excp_handler, .restore_state_to_opc = arm_restore_state_to_opc,
target/avr/cpu.c +1 -1
@@ -206,7 +206,7 @@ static const struct SysemuCPUOps avr_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps avr_tcg_ops = { - .initialize = avr_cpu_tcg_init, + .initialize_once = avr_cpu_tcg_init, .synchronize_from_tb = avr_cpu_synchronize_from_tb, .restore_state_to_opc = avr_restore_state_to_opc, .cpu_exec_interrupt = avr_cpu_exec_interrupt,
target/hexagon/cpu.c +1 -1
@@ -322,7 +322,7 @@ static void hexagon_cpu_init(Object *obj)#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps hexagon_tcg_ops = { - .initialize = hexagon_translate_init, + .initialize_once = hexagon_translate_init, .synchronize_from_tb = hexagon_cpu_synchronize_from_tb, .restore_state_to_opc = hexagon_restore_state_to_opc, };
target/hppa/cpu.c +1 -1
@@ -221,7 +221,7 @@ static const struct SysemuCPUOps hppa_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps hppa_tcg_ops = { - .initialize = hppa_translate_init, + .initialize_once = hppa_translate_init, .synchronize_from_tb = hppa_cpu_synchronize_from_tb, .restore_state_to_opc = hppa_restore_state_to_opc,
target/i386/tcg/tcg-cpu.c +1 -1
@@ -107,7 +107,7 @@ static bool x86_debug_check_breakpoint(CPUState *cs)#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps x86_tcg_ops = { - .initialize = tcg_x86_init, + .initialize_once = tcg_x86_init, .synchronize_from_tb = x86_cpu_synchronize_from_tb, .restore_state_to_opc = x86_restore_state_to_opc, .cpu_exec_enter = x86_cpu_exec_enter,
target/loongarch/cpu.c +1 -1
@@ -793,7 +793,7 @@ void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags)#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps loongarch_tcg_ops = { - .initialize = loongarch_translate_init, + .initialize_once = loongarch_translate_init, .synchronize_from_tb = loongarch_cpu_synchronize_from_tb, .restore_state_to_opc = loongarch_restore_state_to_opc,
target/m68k/cpu.c +1 -1
@@ -546,7 +546,7 @@ static const struct SysemuCPUOps m68k_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps m68k_tcg_ops = { - .initialize = m68k_tcg_init, + .initialize_once = m68k_tcg_init, .restore_state_to_opc = m68k_restore_state_to_opc, #ifndef CONFIG_USER_ONLY
target/microblaze/cpu.c +1 -1
@@ -420,7 +420,7 @@ static const struct SysemuCPUOps mb_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps mb_tcg_ops = { - .initialize = mb_tcg_init, + .initialize_once = mb_tcg_init, .synchronize_from_tb = mb_cpu_synchronize_from_tb, .restore_state_to_opc = mb_restore_state_to_opc,
target/mips/cpu.c +1 -1
@@ -551,7 +551,7 @@ static Property mips_cpu_properties[] = {* mips hardware (see hw/mips/jazz.c). */ static const TCGCPUOps mips_tcg_ops = { - .initialize = mips_tcg_init, + .initialize_once = mips_tcg_init, .synchronize_from_tb = mips_cpu_synchronize_from_tb, .restore_state_to_opc = mips_restore_state_to_opc,
target/openrisc/cpu.c +1 -1
@@ -232,7 +232,7 @@ static const struct SysemuCPUOps openrisc_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps openrisc_tcg_ops = { - .initialize = openrisc_translate_init, + .initialize_once = openrisc_translate_init, .synchronize_from_tb = openrisc_cpu_synchronize_from_tb, .restore_state_to_opc = openrisc_restore_state_to_opc,
target/ppc/cpu_init.c +1 -1
@@ -7416,7 +7416,7 @@ static const struct SysemuCPUOps ppc_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps ppc_tcg_ops = { - .initialize = ppc_translate_init, + .initialize_once = ppc_translate_init, .restore_state_to_opc = ppc_restore_state_to_opc, #ifdef CONFIG_USER_ONLY .record_sigsegv = ppc_cpu_record_sigsegv,
target/riscv/tcg/tcg-cpu.c +1 -1
@@ -133,7 +133,7 @@ static void riscv_restore_state_to_opc(CPUState *cs, }static const TCGCPUOps riscv_tcg_ops = { - .initialize = riscv_translate_init, + .initialize_once = riscv_translate_init, .synchronize_from_tb = riscv_cpu_synchronize_from_tb, .restore_state_to_opc = riscv_restore_state_to_opc,
target/rx/cpu.c +1 -1
@@ -192,7 +192,7 @@ static const struct SysemuCPUOps rx_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps rx_tcg_ops = { - .initialize = rx_translate_init, + .initialize_once = rx_translate_init, .synchronize_from_tb = rx_cpu_synchronize_from_tb, .restore_state_to_opc = rx_restore_state_to_opc, .tlb_fill = rx_cpu_tlb_fill,
target/s390x/cpu.c +1 -1
@@ -357,7 +357,7 @@ void cpu_get_tb_cpu_state(CPUS390XState *env, vaddr *pc, }static const TCGCPUOps s390_tcg_ops = { - .initialize = s390x_translate_init, + .initialize_once = s390x_translate_init, .restore_state_to_opc = s390x_restore_state_to_opc, #ifdef CONFIG_USER_ONLY
target/sh4/cpu.c +1 -1
@@ -247,7 +247,7 @@ static const struct SysemuCPUOps sh4_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps superh_tcg_ops = { - .initialize = sh4_translate_init, + .initialize_once = sh4_translate_init, .synchronize_from_tb = superh_cpu_synchronize_from_tb, .restore_state_to_opc = superh_restore_state_to_opc,
target/sparc/cpu.c +1 -1
@@ -927,7 +927,7 @@ static const struct SysemuCPUOps sparc_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps sparc_tcg_ops = { - .initialize = sparc_tcg_init, + .initialize_once = sparc_tcg_init, .synchronize_from_tb = sparc_cpu_synchronize_from_tb, .restore_state_to_opc = sparc_restore_state_to_opc,
target/tricore/cpu.c +1 -1
@@ -170,7 +170,7 @@ static const struct SysemuCPUOps tricore_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps tricore_tcg_ops = { - .initialize = tricore_tcg_init, + .initialize_once = tricore_tcg_init, .synchronize_from_tb = tricore_cpu_synchronize_from_tb, .restore_state_to_opc = tricore_restore_state_to_opc, .tlb_fill = tricore_cpu_tlb_fill,
target/xtensa/cpu.c +1 -1
@@ -227,7 +227,7 @@ static const struct SysemuCPUOps xtensa_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps xtensa_tcg_ops = { - .initialize = xtensa_translate_init, + .initialize_once = xtensa_translate_init, .debug_excp_handler = xtensa_breakpoint_handler, .restore_state_to_opc = xtensa_restore_state_to_opc,
Signature · 1 line
2.45.2
Re: [PATCH-for-10.0 3/6] accel/tcg: Rename TCGCPUOps::initialize() as initialize_once()
Quoted 11 lines · Philippe Mathieu-Daudé
While this handler can be called multiple times, it will only be run once. Clarify by renaming the handler name.
Signed-off-by Philippe Mathieu-Daudé<[email protected]>---
We could "optimize" TGC frontends memory use by passing a CPUClass argument, and eachinitialize()call would initialize TCG registers required for a particular CPUClass which are not yet initialized by previous calls. Not a priority / worth it.
---
r~
PATCH 4/6 include: Expose QemuArch in 'qemu/arch_id.h'
In reply to Philippe Mathieu-DaudéWhile QEMU architecture bitmask values are only used by system emulation code, they can be used in generic code like TCG accelerator.
Move the declarations to "qemu/arch_id.h" and add the QemuArch type definition.
--- include/qemu/arch_id.h | 28 ++++++++++++++++++++++++++++ include/sysemu/arch_init.h | 28 +++------------------------- 2 files changed, 31 insertions(+), 25 deletions(-) create mode 100644 include/qemu/arch_id.h
include/qemu/arch_id.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef QEMU_ARCH_ID_H +#define QEMU_ARCH_ID_H + +typedef enum QemuArch {/* FIXME this is not an enum */ +QEMU_ARCH_ALL =-1 , +QEMU_ARCH_ALPHA = (1 <<0 ), +QEMU_ARCH_ARM = (1 <<1 ), +QEMU_ARCH_I386 = (1 <<3 ), +QEMU_ARCH_M68K = (1 <<4 ), +QEMU_ARCH_MICROBLAZE = (1 <<6 ), +QEMU_ARCH_MIPS = (1 <<7 ), +QEMU_ARCH_PPC = (1 <<8 ), +QEMU_ARCH_S390X = (1 <<9 ), +QEMU_ARCH_SH4 = (1 <<10 ), +QEMU_ARCH_SPARC = (1 <<11 ), +QEMU_ARCH_XTENSA = (1 <<12 ), +QEMU_ARCH_OPENRISC = (1 <<13 ), +QEMU_ARCH_TRICORE = (1 <<16 ), +QEMU_ARCH_HPPA = (1 <<18 ), +QEMU_ARCH_RISCV = (1 <<19 ), +QEMU_ARCH_RX = (1 <<20 ), +QEMU_ARCH_AVR = (1 <<21 ), +QEMU_ARCH_HEXAGON = (1 <<22 ), +QEMU_ARCH_LOONGARCH = (1 <<23 ), +}QemuArch ; + +#endif
include/sysemu/arch_init.h +3 -25
@@ -1,29 +1,7 @@ -#ifndef QEMU_ARCH_INIT_H -#define QEMU_ARCH_INIT_H +#ifndef SYSEMU_ARCH_INIT_H +#define SYSEMU_ARCH_INIT_H - -enum { -QEMU_ARCH_ALL =-1 , -QEMU_ARCH_ALPHA = (1 <<0 ), -QEMU_ARCH_ARM = (1 <<1 ), -QEMU_ARCH_I386 = (1 <<3 ), -QEMU_ARCH_M68K = (1 <<4 ), -QEMU_ARCH_MICROBLAZE = (1 <<6 ), -QEMU_ARCH_MIPS = (1 <<7 ), -QEMU_ARCH_PPC = (1 <<8 ), -QEMU_ARCH_S390X = (1 <<9 ), -QEMU_ARCH_SH4 = (1 <<10 ), -QEMU_ARCH_SPARC = (1 <<11 ), -QEMU_ARCH_XTENSA = (1 <<12 ), -QEMU_ARCH_OPENRISC = (1 <<13 ), -QEMU_ARCH_TRICORE = (1 <<16 ), -QEMU_ARCH_HPPA = (1 <<18 ), -QEMU_ARCH_RISCV = (1 <<19 ), -QEMU_ARCH_RX = (1 <<20 ), -QEMU_ARCH_AVR = (1 <<21 ), -QEMU_ARCH_HEXAGON = (1 <<22 ), -QEMU_ARCH_LOONGARCH = (1 <<23 ), -}; +#include "qemu/arch_id.h" extern const uint32_t arch_type;
Signature · 1 line
2.45.2
Re: [PATCH-for-10.0 4/6] include: Expose QemuArch in 'qemu/arch_id.h'
Quoted 11 lines · Philippe Mathieu-Daudé
While QEMU architecture bitmask values are only used by system emulation code, they can be used in generic code like TCG accelerator.
Move the declarations to "
qemu/arch_id.h" and add the QemuArch type definition.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/qemu/arch_id.h | 28 ++++++++++++++++++++++++++++ include/sysemu/arch_init.h | 28 +++-------------------------
Alternatively we can restrict TCGCPUOps::arch_id to system emulation, using in the next patch:
-- >8 --
include/hw/core/tcg-cpu-ops.h +1 -2
@@ -19,8 +19,6 @@#include "exec/vaddr.h" struct TCGCPUOps { -QemuArch arch_id; -/** * @initialize_once: Initialize TCG state *
@@ -58,6 +56,7 @@ struct TCGCPUOps {void (*debug_excp_handler)(CPUState *cpu);#ifdef CONFIG_USER_ONLY +QemuArch arch_id;/** * @fake_user_interrupt: Callback for 'fake exception' handling. *
accel/tcg/cpu-exec.c +7 -3
@@ -1072,15 +1072,20 @@ bool tcg_exec_realizefn(CPUState *cpu, Error **errp) {static unsigned initialized_targets;const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops; +#ifndef CONFIG_USER_ONLY +unsigned arch_id = tcg_ops->arch_id; +#else +unsigned arch_id =1 ; +#endif -if (!(initialized_targets & tcg_ops->arch_id)) { +if (!(initialized_targets & arch_id)) {/* Check mandatory TCGCPUOps handlers */ #ifndef CONFIG_USER_ONLY assert (tcg_ops->cpu_exec_halt);assert (tcg_ops->cpu_exec_interrupt);#endif /* !CONFIG_USER_ONLY */ tcg_ops->initialize_once (); - initialized_targets |= tcg_ops->arch_id; + initialized_targets |= arch_id; } ---
But it add more #ifdef'ry and doesn't seem worthwhile IMHO.
Re: [PATCH-for-10.0 4/6] include: Expose QemuArch in 'qemu/arch_id.h'
Quoted 53 lines · Philippe Mathieu-Daudé
Alternatively we can restrict
TCGCPUOps::arch_idto system emulation, using in the next patch:-- >8 --
include/hw/core/tcg-cpu-ops.h +1
-2@@ -19,8 +19,6 @@ #include "exec/vaddr.h" struct TCGCPUOps { - QemuArch arch_id; - /*** @initialize_once: Initialize TCG state * @@ -58,6 +56,7 @@ struct TCGCPUOps { void (*debug_excp_handler)(CPUState *cpu); #ifdef CONFIG_USER_ONLY + QemuArch arch_id; /*** @fake_user_interrupt: Callback for 'fake exception' handling. * accel/tcg/cpu-exec.c +7
-3@@ -1072,15 +1072,20 @@ bool tcg_exec_realizefn(CPUState *cpu, Error **errp) { static unsigned initialized_targets; const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops; +#ifndef CONFIG_USER_ONLY + unsigned arch_id = tcg_ops->arch_id; +#else + unsigned arch_id = 1; +#endif - if (!(initialized_targets & tcg_ops->arch_id)) { + if (!(initialized_targets & arch_id)) { /* Check mandatory TCGCPUOps handlers */ #ifndef CONFIG_USER_ONLY assert(tcg_ops->cpu_exec_halt); assert(tcg_ops->cpu_exec_interrupt); #endif /* !CONFIG_USER_ONLY */ tcg_ops->initialize_once(); - initialized_targets |= tcg_ops->arch_id; + initialized_targets |= arch_id; } ---
Quoted 1 line
But it add more #ifdef'ry and doesn't seem worthwhile IMHO.
I agree, not worthwhile.
r~
Re: [PATCH-for-10.0 4/6] include: Expose QemuArch in 'qemu/arch_id.h'
In reply to Philippe Mathieu-DaudéQuoted 20 lines · Philippe Mathieu-Daudé
While QEMU architecture bitmask values are only used by system emulation code, they can be used in generic code like TCG accelerator.
Move the declarations to "
qemu/arch_id.h" and add the QemuArch type definition.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/qemu/arch_id.h | 28 ++++++++++++++++++++++++++++ include/sysemu/arch_init.h | 28 +++------------------------- 2 files changed, 31 insertions(+), 25 deletions(-)create mode 100644
include/qemu/arch_id.hinclude/qemu/arch_id.h new file +0
-0
include/qemu/arch_id.h line 5
Quoted 5 lines
include/qemu/arch_id.h new file +5
-0@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef QEMU_ARCH_ID_H +#define QEMU_ARCH_ID_H + +typedef enum QemuArch { /* FIXME this is not an enum */
The comment is not useful.
C enums are backed by an implementation type that can hold all values.
Quoted 1 line
include/qemu/arch_id.h new file +1
-0+ QEMU_ARCH_ALL = -1,
...
Quoted 1 line
+
QEMU_ARCH_LOONGARCH= (1 << 23),
... which in this case means int32_t or int64_t, at the compiler's discretion. If you change QEMU_ARCH_ALL to (1 << 24) - 1, then uint32_t and uint64_t become possible implementation types.
Are you perhaps being confused by C++ enums, which are more semantically restrictive?
Anyway, the code movement is fine.
r~
PATCH 5/6 accel/tcg: Add TCGCPUOps::arch_id field
In reply to Philippe Mathieu-DaudéWhen using multiple TCG frontends concurrently, we need to be able to discriminate by target architecture. While we can infer that from the CPUClass, it can be quicker to get it from a direct field in TCGCPUOps.
--- include/hw/core/tcg-cpu-ops.h | 3 +++ target/alpha/cpu.c | 1 + target/arm/cpu.c | 1 + target/arm/tcg/cpu-v7m.c | 1 + target/avr/cpu.c | 1 + target/hexagon/cpu.c | 1 + target/hppa/cpu.c | 1 + target/i386/tcg/tcg-cpu.c | 1 + target/loongarch/cpu.c | 1 + target/m68k/cpu.c | 1 + target/microblaze/cpu.c | 1 + target/mips/cpu.c | 1 + target/openrisc/cpu.c | 1 + target/ppc/cpu_init.c | 1 + target/riscv/tcg/tcg-cpu.c | 1 + target/rx/cpu.c | 1 + target/s390x/cpu.c | 1 + target/sh4/cpu.c | 1 + target/sparc/cpu.c | 1 + target/tricore/cpu.c | 1 + target/xtensa/cpu.c | 1 + 21 files changed, 23 insertions(+)
include/hw/core/tcg-cpu-ops.h +3 -0
@@ -10,6 +10,7 @@#ifndef TCG_CPU_OPS_H #define TCG_CPU_OPS_H +#include "qemu/arch_id.h" #include "exec/breakpoint.h" #include "exec/hwaddr.h" #include "exec/memattrs.h"
@@ -18,6 +19,8 @@#include "exec/vaddr.h" struct TCGCPUOps { +QemuArch arch_id; +/** * @initialize_once: Initialize TCG state *
target/alpha/cpu.c +1 -0
@@ -220,6 +220,7 @@ static const struct SysemuCPUOps alpha_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps alpha_tcg_ops = { + .arch_id =QEMU_ARCH_ALPHA , .initialize_once = alpha_translate_init, .synchronize_from_tb = alpha_cpu_synchronize_from_tb, .restore_state_to_opc = alpha_restore_state_to_opc,
target/arm/cpu.c +1 -0
@@ -2671,6 +2671,7 @@ static const struct SysemuCPUOps arm_sysemu_ops = {#ifdef CONFIG_TCG static const TCGCPUOps arm_tcg_ops = { + .arch_id =QEMU_ARCH_ARM , .initialize_once = arm_translate_init, .synchronize_from_tb = arm_cpu_synchronize_from_tb, .debug_excp_handler = arm_debug_excp_handler,
target/arm/tcg/cpu-v7m.c +1 -0
@@ -233,6 +233,7 @@ static void cortex_m55_initfn(Object *obj) }static const TCGCPUOps arm_v7m_tcg_ops = { + .arch_id =QEMU_ARCH_ARM , .initialize_once = arm_translate_init, .synchronize_from_tb = arm_cpu_synchronize_from_tb, .debug_excp_handler = arm_debug_excp_handler,
target/avr/cpu.c +1 -0
@@ -206,6 +206,7 @@ static const struct SysemuCPUOps avr_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps avr_tcg_ops = { + .arch_id =QEMU_ARCH_AVR , .initialize_once = avr_cpu_tcg_init, .synchronize_from_tb = avr_cpu_synchronize_from_tb, .restore_state_to_opc = avr_restore_state_to_opc,
target/hexagon/cpu.c +1 -0
@@ -322,6 +322,7 @@ static void hexagon_cpu_init(Object *obj)#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps hexagon_tcg_ops = { + .arch_id =QEMU_ARCH_HEXAGON , .initialize_once = hexagon_translate_init, .synchronize_from_tb = hexagon_cpu_synchronize_from_tb, .restore_state_to_opc = hexagon_restore_state_to_opc,
target/hppa/cpu.c +1 -0
@@ -221,6 +221,7 @@ static const struct SysemuCPUOps hppa_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps hppa_tcg_ops = { + .arch_id =QEMU_ARCH_HPPA , .initialize_once = hppa_translate_init, .synchronize_from_tb = hppa_cpu_synchronize_from_tb, .restore_state_to_opc = hppa_restore_state_to_opc,
target/i386/tcg/tcg-cpu.c +1 -0
@@ -107,6 +107,7 @@ static bool x86_debug_check_breakpoint(CPUState *cs)#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps x86_tcg_ops = { + .arch_id =QEMU_ARCH_I386 , .initialize_once = tcg_x86_init, .synchronize_from_tb = x86_cpu_synchronize_from_tb, .restore_state_to_opc = x86_restore_state_to_opc,
target/loongarch/cpu.c +1 -0
@@ -793,6 +793,7 @@ void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags)#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps loongarch_tcg_ops = { + .arch_id =QEMU_ARCH_LOONGARCH , .initialize_once = loongarch_translate_init, .synchronize_from_tb = loongarch_cpu_synchronize_from_tb, .restore_state_to_opc = loongarch_restore_state_to_opc,
target/m68k/cpu.c +1 -0
@@ -546,6 +546,7 @@ static const struct SysemuCPUOps m68k_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps m68k_tcg_ops = { + .arch_id =QEMU_ARCH_M68K , .initialize_once = m68k_tcg_init, .restore_state_to_opc = m68k_restore_state_to_opc,
target/microblaze/cpu.c +1 -0
@@ -420,6 +420,7 @@ static const struct SysemuCPUOps mb_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps mb_tcg_ops = { + .arch_id =QEMU_ARCH_MICROBLAZE , .initialize_once = mb_tcg_init, .synchronize_from_tb = mb_cpu_synchronize_from_tb, .restore_state_to_opc = mb_restore_state_to_opc,
target/mips/cpu.c +1 -0
@@ -551,6 +551,7 @@ static Property mips_cpu_properties[] = {* mips hardware (see hw/mips/jazz.c). */ static const TCGCPUOps mips_tcg_ops = { + .arch_id =QEMU_ARCH_MIPS , .initialize_once = mips_tcg_init, .synchronize_from_tb = mips_cpu_synchronize_from_tb, .restore_state_to_opc = mips_restore_state_to_opc,
target/openrisc/cpu.c +1 -0
@@ -232,6 +232,7 @@ static const struct SysemuCPUOps openrisc_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps openrisc_tcg_ops = { + .arch_id =QEMU_ARCH_OPENRISC , .initialize_once = openrisc_translate_init, .synchronize_from_tb = openrisc_cpu_synchronize_from_tb, .restore_state_to_opc = openrisc_restore_state_to_opc,
target/ppc/cpu_init.c +1 -0
@@ -7416,6 +7416,7 @@ static const struct SysemuCPUOps ppc_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps ppc_tcg_ops = { + .arch_id =QEMU_ARCH_PPC , .initialize_once = ppc_translate_init, .restore_state_to_opc = ppc_restore_state_to_opc, #ifdef CONFIG_USER_ONLY
target/riscv/tcg/tcg-cpu.c +1 -0
@@ -133,6 +133,7 @@ static void riscv_restore_state_to_opc(CPUState *cs, }static const TCGCPUOps riscv_tcg_ops = { + .arch_id =QEMU_ARCH_RISCV , .initialize_once = riscv_translate_init, .synchronize_from_tb = riscv_cpu_synchronize_from_tb, .restore_state_to_opc = riscv_restore_state_to_opc,
target/rx/cpu.c +1 -0
@@ -192,6 +192,7 @@ static const struct SysemuCPUOps rx_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps rx_tcg_ops = { + .arch_id =QEMU_ARCH_RX , .initialize_once = rx_translate_init, .synchronize_from_tb = rx_cpu_synchronize_from_tb, .restore_state_to_opc = rx_restore_state_to_opc,
target/s390x/cpu.c +1 -0
@@ -357,6 +357,7 @@ void cpu_get_tb_cpu_state(CPUS390XState *env, vaddr *pc, }static const TCGCPUOps s390_tcg_ops = { + .arch_id =QEMU_ARCH_S390X , .initialize_once = s390x_translate_init, .restore_state_to_opc = s390x_restore_state_to_opc,
target/sh4/cpu.c +1 -0
@@ -247,6 +247,7 @@ static const struct SysemuCPUOps sh4_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps superh_tcg_ops = { + .arch_id =QEMU_ARCH_SH4 , .initialize_once = sh4_translate_init, .synchronize_from_tb = superh_cpu_synchronize_from_tb, .restore_state_to_opc = superh_restore_state_to_opc,
target/sparc/cpu.c +1 -0
@@ -927,6 +927,7 @@ static const struct SysemuCPUOps sparc_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps sparc_tcg_ops = { + .arch_id =QEMU_ARCH_SPARC , .initialize_once = sparc_tcg_init, .synchronize_from_tb = sparc_cpu_synchronize_from_tb, .restore_state_to_opc = sparc_restore_state_to_opc,
target/tricore/cpu.c +1 -0
@@ -170,6 +170,7 @@ static const struct SysemuCPUOps tricore_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps tricore_tcg_ops = { + .arch_id =QEMU_ARCH_TRICORE , .initialize_once = tricore_tcg_init, .synchronize_from_tb = tricore_cpu_synchronize_from_tb, .restore_state_to_opc = tricore_restore_state_to_opc,
target/xtensa/cpu.c +1 -0
@@ -227,6 +227,7 @@ static const struct SysemuCPUOps xtensa_sysemu_ops = {#include "hw/core/tcg-cpu-ops.h" static const TCGCPUOps xtensa_tcg_ops = { + .arch_id =QEMU_ARCH_XTENSA , .initialize_once = xtensa_translate_init, .debug_excp_handler = xtensa_breakpoint_handler, .restore_state_to_opc = xtensa_restore_state_to_opc,
Signature · 1 line
2.45.2
Re: [PATCH-for-10.0 5/6] accel/tcg: Add TCGCPUOps::arch_id field
Quoted 21 lines · Philippe Mathieu-Daudé
When using multiple TCG frontends concurrently, we need to be able to discriminate by target architecture. While we can infer that from the CPUClass, it can be quicker to get it from a direct field in TCGCPUOps.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/core/tcg-cpu-ops.h | 3 +++ target/alpha/cpu.c | 1 + target/arm/cpu.c | 1 + target/arm/tcg/cpu-v7m.c | 1 + target/avr/cpu.c | 1 + target/hexagon/cpu.c | 1 + target/hppa/cpu.c | 1 + target/i386/tcg/tcg-cpu.c | 1 + target/loongarch/cpu.c | 1 + target/m68k/cpu.c | 1 + target/microblaze/cpu.c | 1 + target/mips/cpu.c | 1 + target/openrisc/cpu.c | 1 + target/ppc/cpu_init.c | 1 +
Quoted 8 lines
target/riscv/tcg/tcg-cpu.c | 1 + target/rx/cpu.c | 1 + target/s390x/cpu.c | 1 + target/sh4/cpu.c | 1 + target/sparc/cpu.c | 1 + target/tricore/cpu.c | 1 + target/xtensa/cpu.c | 1 + 21 files changed, 23 insertions(+)
Re: [PATCH-for-10.0 5/6] accel/tcg: Add TCGCPUOps::arch_id field
In reply to Philippe Mathieu-DaudéQuoted 3 lines · Philippe Mathieu-Daudé
When using multiple TCG frontends concurrently, we need to be able to discriminate by target architecture. While we can infer that from the CPUClass,
Can we? I thought the only place this got set is arch_type in system/arch_init.c.
Quoted 1 line
it can be quicker to get it from a direct field in TCGCPUOps.
Since it's not currently relevant to other accelerators, this seems ok.
Other possibilities collecting a set of pointers (e.g. the called initialize_once), or requiring that the initialize function notice the second call (e.g. a TCGv non-null).
Anyway,
r~
PATCH 6/6 accel/tcg: Allow tcg_exec_realizefn() initialize multiple frontends
In reply to Philippe Mathieu-DaudéRather than initializing the first random target architecture and ignore the following ones when a global boolean is set, use a bitmask allowing different frontend targets to be initialized.
--- accel/tcg/cpu-exec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
accel/tcg/cpu-exec.c +3 -2
@@ -1070,16 +1070,17 @@ int cpu_exec(CPUState *cpu)bool tcg_exec_realizefn (CPUState *cpu,Error **errp) { +static unsigned initialized_targets;const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops; -if (!tcg_target_initialized) { +if (!(initialized_targets & tcg_ops->arch_id)) {/* Check mandatory TCGCPUOps handlers */ #ifndef CONFIG_USER_ONLY assert (tcg_ops->cpu_exec_halt);assert (tcg_ops->cpu_exec_interrupt);#endif /* !CONFIG_USER_ONLY */ tcg_ops->initialize_once (); - tcg_target_initialized = true; + initialized_targets |= tcg_ops->arch_id; } cpu->tb_jmp_cache =g_new0 (CPUJumpCache,1 );
Signature · 1 line
2.45.2
Quoted 37 lines · Philippe Mathieu-Daudé
Rather than initializing the first random target architecture and ignore the following ones when a global boolean is set, use a bitmask allowing different frontend targets to be initialized.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- accel/tcg/cpu-exec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)accel/tcg/cpu-exec.c +3
-2@@ -1070,16 +1070,17 @@ int cpu_exec(CPUState *cpu)bool tcg_exec_realizefn (CPUState *cpu,Error **errp) { +static unsigned initialized_targets;const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops; -if (!tcg_target_initialized) { +if (!(initialized_targets & tcg_ops->arch_id)) {/* Check mandatory TCGCPUOps handlers */ #ifndef CONFIG_USER_ONLY assert (tcg_ops->cpu_exec_halt);assert (tcg_ops->cpu_exec_interrupt);#endif /* !CONFIG_USER_ONLY */ tcg_ops->initialize_once (); - tcg_target_initialized = true; + initialized_targets |= tcg_ops->arch_id; } cpu->tb_jmp_cache =g_new0 (CPUJumpCache,1 );Signature · 1 line
2.45.2
Only suggestion would be to assert that arch_id is set, might save some headache in the future.
Richard Henderson
Reviewed-byQuoted 34 lines · Anton Johansson
Quoted 33 lines · Philippe Mathieu-Daudé
Rather than initializing the first random target architecture and ignore the following ones when a global boolean is set, use a bitmask allowing different frontend targets to be initialized.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- accel/tcg/cpu-exec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)accel/tcg/cpu-exec.c +3
-2@@ -1070,16 +1070,17 @@ int cpu_exec(CPUState *cpu)bool tcg_exec_realizefn (CPUState *cpu,Error **errp) { +static unsigned initialized_targets;const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops; -if (!tcg_target_initialized) { +if (!(initialized_targets & tcg_ops->arch_id)) {/* Check mandatory TCGCPUOps handlers */ #ifndef CONFIG_USER_ONLY assert (tcg_ops->cpu_exec_halt);assert (tcg_ops->cpu_exec_interrupt);#endif /* !CONFIG_USER_ONLY */ tcg_ops->initialize_once (); - tcg_target_initialized = true; + initialized_targets |= tcg_ops->arch_id; }
Quoted 7 lines
Quoted 4 lines
accel/tcg/cpu-exec.c +0
-0cpu->tb_jmp_cache =g_new0 (CPUJumpCache,1 );Signature · 1 line
2.45.2Only suggestion would be to assert that
arch_idis set, might save some headache in the future.
Yep.
r~