Skip to contentSkip to conversation

target: Toward heterogeneous machine

PATCH New Philippe Mathieu-Daudé via 1 participant 2 messages Feb 15, 2022 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover target: Toward heterogeneous machine

Hi, following last week KVM call [1], I'm posting my playground machine to slowly work toward heterogeneous QEMU. This is orthogonal to Paolo / Markus / Daniel effort to have a qemu-system-qmp CLI entrypoint [2].

After refactoring a bit the headers to remove target-specific dependencies, we can remove the targets (and accelerators) from the picture, to have a target-agnostic QEMU.

This binary helps to find a lot of code abuses where we only expect one target being built, and is useful to clean that.

So far my naive roadmap draft is:

- Ignoring target-specific hardware devices, target-agnostic code should only use the CPUClass and CPUState to interface with the target-specific code.

- CPU objects shouldn't access an unique global accelerator, but should be initialized with a specific accelerator.

- Each target registers as a QEMU module. Should we expose a target API beside the CPU?

- Compile TCG-target-specific objects in each target dir?

- Refactor buildsys to register multiple targets.

- TBC.

[1] https://lore.kernel.org/qemu-devel/[email protected]/
[2] https://lore.kernel.org/qemu-devel/[email protected]/

Based-on: <[email protected]>
"target: Use ArchCPU & CPUArchState as abstract interface to target CPU"
https://lore.kernel.org/qemu-devel/[email protected]/

Philippe Mathieu-Daudé (1):
target: Add system emulation aiming to target any architecture

 configs/devices/any-softmmu/default.mak |  1 +
 configs/targets/any-softmmu.mak         |  3 +++
 hw/any/meson.build                      |  5 +++++
 hw/meson.build                          |  1 +
 include/sysemu/arch_init.h              |  1 +
 meson.build                             |  6 +++--
 qapi/machine.json                       |  2 +-
 target/Kconfig                          |  1 +
 target/any/Kconfig                      |  4 ++++
 target/any/cpu-param.h                  | 30 +++++++++++++++++++++++++
 target/any/cpu.h                        | 26 +++++++++++++++++++++
 target/any/meson.build                  |  8 +++++++
 target/meson.build                      |  1 +
 13 files changed, 86 insertions(+), 3 deletions(-)
 create mode 100644 configs/devices/any-softmmu/default.mak
 create mode 100644 configs/targets/any-softmmu.mak
 create mode 100644 hw/any/meson.build
 create mode 100644 target/any/Kconfig
 create mode 100644 target/any/cpu-param.h
 create mode 100644 target/any/cpu.h
 create mode 100644 target/any/meson.build
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/1 target: Add system emulation aiming to target any architecture

Add the 'any'-architecture target.

- Only consider 64-bit targets
- Do not use any hardware accelerator (except qtest)
- For architecture constants, use:
. max of supported targets phys/virt address space . max of supported targets MMU modes
. min of supported targets variable page bits

Build as:

  $ ../configure --target-list=any-softmmu \
      --disable-tcg --disable-kvm --disable-hvf

Test as:

  $ qemu-system-any -M none,accel=qtest -monitor stdio
  QEMU 6.2.50 monitor - type 'help' for more information
  (qemu) info mtree
  address-space: I/O
    0000000000000000-000000000000ffff (prio 0, i/o): io

address-space: memory

    0000000000000000-ffffffffffffffff (prio 0, i/o): system

(qemu) info qom-tree
/machine (none-machine)

    /peripheral (container)
    /peripheral-anon (container)
    /unattached (container)
      /io[0] (memory-region)
      /sysbus (System)
      /system[0] (memory-region)

(qemu) info qtree
bus: main-system-bus
type System
(qemu) info cpus
(qemu)

---
 configs/devices/any-softmmu/default.mak |  1 +
 configs/targets/any-softmmu.mak         |  3 +++
 hw/any/meson.build                      |  5 +++++
 hw/meson.build                          |  1 +
 include/sysemu/arch_init.h              |  1 +
 meson.build                             |  6 +++--
 qapi/machine.json                       |  2 +-
 target/Kconfig                          |  1 +
 target/any/Kconfig                      |  4 ++++
 target/any/cpu-param.h                  | 30 +++++++++++++++++++++++++
 target/any/cpu.h                        | 26 +++++++++++++++++++++
 target/any/meson.build                  |  8 +++++++
 target/meson.build                      |  1 +
 13 files changed, 86 insertions(+), 3 deletions(-)
 create mode 100644 configs/devices/any-softmmu/default.mak
 create mode 100644 configs/targets/any-softmmu.mak
 create mode 100644 hw/any/meson.build
 create mode 100644 target/any/Kconfig
 create mode 100644 target/any/cpu-param.h
 create mode 100644 target/any/cpu.h
 create mode 100644 target/any/meson.build
configs/devices/any-softmmu/default.mak new file +1 -0
new file mode 100644
index 0000000000..315c06b689
@@ -0,0 +1 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
configs/targets/any-softmmu.mak new file +3 -0
new file mode 100644
index 0000000000..2c6cf1edd4
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+TARGET_ARCH=any
hw/any/meson.build new file +5 -0
new file mode 100644
index 0000000000..60e1567e53
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+any_ss = ss.source_set()
+
+hw_arch += {'any': any_ss}
hw/meson.build +1 -0
index b3366c888e..6e7e102bbd 100644
@@ -44,6 +44,7 @@ subdir('xen')
 subdir('xenpv')
 
 subdir('alpha')
+subdir('any')
 subdir('arm')
 subdir('avr')
 subdir('cris')
include/sysemu/arch_init.h +1 -0
index 79c2591425..f86bf4b0cd 100644
@@ -4,6 +4,7 @@
 
 enum {
     QEMU_ARCH_ALL = -1,
+    QEMU_ARCH_ANY = -1,
     QEMU_ARCH_ALPHA = (1 << 0),
     QEMU_ARCH_ARM = (1 << 1),
     QEMU_ARCH_CRIS = (1 << 2),
meson.build +4 -2
index 9460875693..f587f4ba59 100644
@@ -61,7 +61,7 @@ python = import('python').find_installation()
 
 supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux']
 supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv', 'x86', 'x86_64',
-  'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc', 'sparc64']
+  'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc', 'sparc64', 'any']
 
 cpu = host_machine.cpu_family()
 
@@ -1934,7 +1934,9 @@ foreach target : target_dirs
     if default_targets
       continue
     endif
-    error('No accelerator available for target @0@'.format(target))
+    if 'any-softmmu' not in target_dirs
+      error('No accelerator available for target @0@'.format(target))
+    endif
   endif
 
   actual_target_dirs += target
qapi/machine.json +1 -1
index 42fc68403d..4b09831a27 100644
@@ -34,7 +34,7 @@
              'mips64el', 'mipsel', 'nios2', 'or1k', 'ppc',
              'ppc64', 'riscv32', 'riscv64', 'rx', 's390x', 'sh4',
              'sh4eb', 'sparc', 'sparc64', 'tricore',
-             'x86_64', 'xtensa', 'xtensaeb' ] }
+             'x86_64', 'xtensa', 'xtensaeb', 'any' ] }
 
 ##
 # @CpuS390State:
target/Kconfig +1 -0
index ae7f24fc66..ea381d28b5 100644
@@ -1,4 +1,5 @@
 source alpha/Kconfig
+source any/Kconfig
 source arm/Kconfig
 source avr/Kconfig
 source cris/Kconfig
target/any/Kconfig new file +4 -0
new file mode 100644
index 0000000000..8840d70e55
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+config ANY
+    bool
target/any/cpu-param.h new file +30 -0
new file mode 100644
index 0000000000..21cda0ddc2
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef ANY_CPU_PARAM_H
+#define ANY_CPU_PARAM_H
+
+#define TARGET_LONG_BITS 64
+
+#define TARGET_PHYS_ADDR_SPACE_BITS 64 /* MAX(targets) */
+#define TARGET_VIRT_ADDR_SPACE_BITS 64 /* MAX(targets) */
+
+#define TARGET_PAGE_BITS_VARY
+#define TARGET_PAGE_BITS_MIN  10 /* MIN(targets)=ARMv5/ARMv6, ignoring AVR */
+
+#define NB_MMU_MODES 15 /* MAX(targets) = ARM */
+
+#include "hw/core/cpu.h"
+#include "qom/object.h"
+
+#define TYPE_ANY_CPU "any-cpu"
+
+OBJECT_DECLARE_CPU_TYPE(ANYCPU, ANYCPUClass, ANY_CPU)
+
+struct ANYCPUClass {
+    /*< private >*/
+    CPUClass parent_class;
+    /*< public >*/
+    DeviceRealize parent_realize;
+    DeviceReset parent_reset;
+};
+
+#endif
target/any/cpu.h new file +26 -0
new file mode 100644
index 0000000000..f85ebed956
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef TARGET_ANY_CPU_H
+#define TARGET_ANY_CPU_H
+
+#include "exec/cpu-defs.h"
+
+#define ANY_CPU_TYPE_SUFFIX "-" TYPE_ANY_CPU
+#define ANY_CPU_TYPE_NAME(name) (name ANY_CPU_TYPE_SUFFIX)
+#define CPU_RESOLVING_TYPE TYPE_ANY_CPU
+
+struct CPUArchState {
+    /* nothing here */
+};
+
+struct ArchCPU {
+    /*< private >*/
+    CPUState parent_obj;
+    /*< public >*/
+
+    CPUNegativeOffsetState neg;
+    CPUArchState env;
+};
+
+#include "exec/cpu-all.h"
+
+#endif
target/any/meson.build new file +8 -0
new file mode 100644
index 0000000000..1c36a6e3a1
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+any_ss = ss.source_set()
+
+any_softmmu_ss = ss.source_set()
+
+target_arch += {'any': any_ss}
+target_softmmu_arch += {'any': any_softmmu_ss}
target/meson.build +1 -0
index 2f6940255e..ef7f960f6e 100644
@@ -1,4 +1,5 @@
 subdir('alpha')
+subdir('any')
 subdir('arm')
 subdir('avr')
 subdir('cris')
Signature · 1 line
2.34.1