Skip to contentSkip to conversation

accel/tcg: Allow tcg_exec_realizefn() initialize multiple frontends

PATCH In review Philippe Mathieu-Daudé 3 participants 20 messages Nov 27, 2024 RISC-V

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index efcb80d1c25..daf7f8a93bd 100644
@@ -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
#4 lore raw

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
index 8163295f34b..18d9cf0ea58 100644
@@ -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
Reviewed-by on v1 2/6
#6 lore raw

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.

---
  accel/tcg/cpu-exec.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)

r~

Quoted 25 lines
accel/tcg/cpu-exec.c +4 -4
index 8163295f34b..18d9cf0ea58 100644
@@ -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;
      }
 
#7 lore raw

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 bool tcg_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;
#8 lore raw

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
index 663efb9133c..9a01eb87bfb 100644
@@ -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
index 18d9cf0ea58..ab77740c954 100644
@@ -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
index 5d75c941f7a..4a20b0c5d16 100644
@@ -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
index 6938161b954..f5b0c33a6dc 100644
@@ -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
index 58e54578d67..7a887a29b75 100644
@@ -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
index 3132842d565..e69b5a6af9b 100644
@@ -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
index 020038fc490..6f7777c607e 100644
@@ -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
index c38439c1800..e654f133636 100644
@@ -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
index cca19cd40e8..b44d2f370d1 100644
@@ -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
index 57cc4f314bf..32aa5468ceb 100644
@@ -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
index 5fe335558aa..230057b7375 100644
@@ -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
index 710eb1146c1..f75e1cf5ab1 100644
@@ -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
index d0a43b6d5c7..4f7d9c03599 100644
@@ -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
index b96561d1f26..24125eea1e7 100644
@@ -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
index daf7f8a93bd..9f90de7f6bd 100644
@@ -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
index c62c2216961..2be43b90908 100644
@@ -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
index 65a74ce720f..7c338b584e8 100644
@@ -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
index 514c70f3010..a5ab2a083b5 100644
@@ -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
index 8f07261dcfd..75d6504293f 100644
@@ -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
index dd7af86de73..d803c329650 100644
@@ -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
index 1a261715907..19c583ed326 100644
@@ -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
index 6f9039abaee..71c0a10ef0c 100644
@@ -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
Reviewed-by on v1 3/6
#9 lore raw

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.

---
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.
---

r~

#10 lore raw

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
new file mode 100644
index 00000000000..e3e8cf5e724
@@ -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
index 5b1c1026f3a..01106de5bcb 100644
@@ -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
#11 lore raw

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.

---
  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
index ec3d2b50a9e..6fe0e1a7e97 100644
@@ -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
index b37995f7d0c..31a2ab18e7c 100644
@@ -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.

#12 lore raw

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_id to system emulation, using in the next patch:

-- >8 --

include/hw/core/tcg-cpu-ops.h +1 -2
index ec3d2b50a9e..6fe0e1a7e97 100644
@@ -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
index b37995f7d0c..31a2ab18e7c 100644
@@ -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~

#13 lore raw

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.

---
  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 +0 -0
new file mode 100644
index 00000000000..e3e8cf5e724

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~

#14 lore raw

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
index 9a01eb87bfb..ec3d2b50a9e 100644
@@ -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
index 4a20b0c5d16..e020b4ce173 100644
@@ -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
index f5b0c33a6dc..9b088c893bf 100644
@@ -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
index 7a887a29b75..7a316561acc 100644
@@ -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
index e69b5a6af9b..a9cce351755 100644
@@ -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
index 6f7777c607e..2a3b2e5fb4f 100644
@@ -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
index e654f133636..9bee8ef24f6 100644
@@ -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
index b44d2f370d1..0577d6237a9 100644
@@ -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
index 32aa5468ceb..96ae8c4ef05 100644
@@ -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
index 230057b7375..8a45fbe9d2f 100644
@@ -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
index f75e1cf5ab1..e2cfbbbbefd 100644
@@ -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
index 4f7d9c03599..769f25551c7 100644
@@ -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
index 24125eea1e7..ac041b4427b 100644
@@ -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
index 9f90de7f6bd..13295b9dfcb 100644
@@ -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
index 2be43b90908..ad00183a830 100644
@@ -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
index 7c338b584e8..12ed4a4101f 100644
@@ -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
index a5ab2a083b5..984cacce2d4 100644
@@ -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
index 75d6504293f..cd7336bd7f2 100644
@@ -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
index d803c329650..7e89c4033b2 100644
@@ -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
index 19c583ed326..a8864955201 100644
@@ -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
index 71c0a10ef0c..5d115328ffb 100644
@@ -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
Reviewed-by Anton Johansson on v1 5/6
#15 lore raw

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.

---
 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(+)
Reviewed-by on v1 5/6
#16 lore raw

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~

#17 lore raw

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
index ab77740c954..b37995f7d0c 100644
@@ -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
Reviewed-by Anton Johansson on v1 6/6
#18 lore raw
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.

---
 accel/tcg/cpu-exec.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
accel/tcg/cpu-exec.c +3 -2
index ab77740c954..b37995f7d0c 100644
@@ -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.

Reviewed-by
#19 lore raw
Quoted 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.

---
  accel/tcg/cpu-exec.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
accel/tcg/cpu-exec.c +3 -2
index ab77740c954..b37995f7d0c 100644
@@ -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 -0
      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.

Yep.

r~