Skip to contentSkip to conversation

i386 cleanup

RFC Superseded Claudio Fontana 3 participants 43 messages Nov 26, 2020 – Jan 12, 2021 Arm/Amlogic Meson SoC support

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v6 cover i386 cleanup

Hi all, this is v6 of the i386 cleanup,
with the most interesting patches at the end.

v5 -> v6: remove MODULE_INIT_ACCEL_CPU

instead, use a call to accel_init_interfaces().

* The class lookups are now general and performed in accel/

new AccelCPUClass for new archs are supported as new ones appear in the class hierarchy, no need for stubs.

* Split the code a bit better

Thanks,

Claudio

v4 -> v5: centralized and simplified initializations

I put in Cc: Emilio G. Cota, specifically because in patch 8 I (re)moved for user-mode the call to tcg_regions_init().

The call happens now inside the tcg AccelClass machine_init, (so earlier). This seems to work fine, but thought to get the author opinion on this.

Rebased on "tcg-cpus: split into 3 tcg variants" series (queued by Richard), to avoid some code churn:

https://lists.gnu.org/archive/html/qemu-devel/2020-10/msg04356.html

* Extended AccelClass to user-mode.

user-mode now does not call tcg_exec_init directly, instead it uses the tcg accel class, and its init_machine method.

Since user-mode does not define or use a machine state, the machine is just passed as NULL.

The immediate advantage is that now we can call current_accel() from both user mode and softmmu, so we can work out the correct class to use for accelerator initializations.

* QOMification of CpusAccelOps

simple QOMification of CpusAccelOps abstract class.

* Centralized all accel_cpu_init, so only one per cpu-arch, plus one for all accels will remain.

So we can expect accel_cpu_init() to be limited to:

softmmu/cpus.c - initializes the chosen softmmu accel ops for the cpus module. target/ARCH/cpu.c - initializes the chosen arch-specific cpu accelerator.

These changes are meant to address concerns/issues (Paolo):

1) the use of if (tcg_enabled()) and similar in the module_init call path

2) the excessive number of accel_cpu_init() to hunt down in the codebase.

* Fixed wrong use of host_cpu_class_init (Eduardo)

v3 -> v4: QOMification of X86CPUAccelClass

In this version I basically QOMified X86CPUAccel, taking the suggestions from Eduardo as the starting point,
but stopping just short of making it an actual QOM interface, using a plain abstract class, and then subclasses for the actual objects.

Initialization is still using the existing qemu initialization framework (module_call_init), which is I still think is better than the alternatives proposed, in the current state.

Possibly some improvements could be developed in the future here. In this case, effort should be put in keeping things extendible, in order not to be blocked once accelerators also become modules.

Motivation and higher level steps:

https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg04628.html

Looking forward to your comments on this proposal,

Ciao,

Claudio

Claudio Fontana (11):
i386: move kvm accel files into kvm/
i386: move whpx accel files into whpx/
i386: move hax accel files into hax/
i386: hvf: remove stale MAINTAINERS entry for old hvf stubs
i386: move TCG accel files into tcg/
i386: move cpu dump out of helper.c into cpu-dump.c
i386: move TCG cpu class initialization out of helper.c
accel: extend AccelState and AccelClass to user-mode
accel: replace struct CpusAccel with AccelOpsClass
accel: introduce AccelCPUClass extending CPUClass
i386: split cpu accelerators from cpu.c, using AccelCPUClass

 MAINTAINERS                           |  18 +-
 accel/accel-common.c                  | 104 +++++
 accel/{accel.c => accel-softmmu.c}    |  60 +--
 accel/accel-softmmu.h                 |  15 +
 accel/accel-user.c                    |  24 ++
 accel/kvm/kvm-all.c                   |   2 -
 accel/kvm/kvm-cpus.c                  |  26 +-
 accel/kvm/kvm-cpus.h                  |   2 -
 accel/meson.build                     |   4 +-
 accel/qtest/qtest.c                   |  25 +-
 accel/tcg/meson.build                 |   2 +-
 accel/tcg/tcg-all.c                   |  11 +-
 accel/tcg/tcg-cpus-icount.c           |  11 +-
 accel/tcg/tcg-cpus-icount.h           |   2 +
 accel/tcg/tcg-cpus-mttcg.c            |  12 +-
 accel/tcg/tcg-cpus-mttcg.h            |  19 +
 accel/tcg/tcg-cpus-rr.c               |   7 -
 accel/tcg/tcg-cpus.c                  |  43 ++
 accel/tcg/tcg-cpus.h                  |   4 -
 accel/xen/xen-all.c                   |  24 +-
 bsd-user/main.c                       |  12 +-
 hw/i386/fw_cfg.c                      |   2 +-
 hw/i386/intel_iommu.c                 |   2 +-
 hw/i386/kvm/apic.c                    |   2 +-
 hw/i386/kvm/clock.c                   |   2 +-
 hw/i386/microvm.c                     |   2 +-
 hw/i386/pc.c                          |   2 +-
 hw/i386/pc_piix.c                     |   1 +
 hw/i386/x86.c                         |   2 +-
 include/hw/boards.h                   |   2 +-
 include/hw/core/accel-cpu.h           |  28 ++
 include/hw/core/cpu.h                 |   4 +
 include/{sysemu => qemu}/accel.h      |  16 +-
 include/sysemu/accel-ops.h            |  45 +++
 include/sysemu/cpus.h                 |  26 +-
 include/sysemu/hvf.h                  |   2 +-
 include/sysemu/kvm.h                  |   2 +-
 include/sysemu/kvm_int.h              |   2 +-
 linux-user/main.c                     |   8 +-
 meson.build                           |   1 +
 softmmu/cpus.c                        |  12 +-
 softmmu/memory.c                      |   2 +-
 softmmu/qtest.c                       |   2 +-
 softmmu/vl.c                          |  10 +-
 target/i386/cpu-dump.c                | 538 +++++++++++++++++++++++++
 target/i386/cpu.c                     | 411 +++-----------------
 target/i386/cpu.h                     | 120 +-----
 target/i386/{ => hax}/hax-all.c       |   5 +-
 target/i386/{ => hax}/hax-cpus.c      |  29 +-
 target/i386/{ => hax}/hax-cpus.h      |   2 -
 target/i386/{ => hax}/hax-i386.h      |   6 +-
 target/i386/{ => hax}/hax-interface.h |   0
 target/i386/{ => hax}/hax-mem.c       |   0
 target/i386/{ => hax}/hax-posix.c     |   0
 target/i386/{ => hax}/hax-posix.h     |   0
 target/i386/{ => hax}/hax-windows.c   |   0
 target/i386/{ => hax}/hax-windows.h   |   0
 target/i386/hax/meson.build           |   7 +
 target/i386/helper-tcg.h              | 112 ++++++
 target/i386/helper.c                  | 539 +-------------------------
 target/i386/host-cpu.c                | 198 ++++++++++
 target/i386/host-cpu.h                |  19 +
 target/i386/hvf/cpu.c                 |  65 ++++
 target/i386/hvf/hvf-cpus.c            |  27 +-
 target/i386/hvf/hvf-cpus.h            |   2 -
 target/i386/hvf/hvf-i386.h            |   2 +-
 target/i386/hvf/hvf.c                 |   3 +-
 target/i386/hvf/meson.build           |   1 +
 target/i386/hvf/x86_task.c            |   2 +-
 target/i386/kvm/cpu.c                 | 148 +++++++
 target/i386/{ => kvm}/hyperv-proto.h  |   0
 target/i386/{ => kvm}/hyperv-stub.c   |   0
 target/i386/{ => kvm}/hyperv.c        |   0
 target/i386/{ => kvm}/hyperv.h        |   0
 target/i386/kvm/kvm-cpu.h             |  41 ++
 target/i386/{ => kvm}/kvm-stub.c      |   0
 target/i386/{ => kvm}/kvm.c           |   3 +-
 target/i386/{ => kvm}/kvm_i386.h      |   0
 target/i386/kvm/meson.build           |   8 +
 target/i386/kvm/trace-events          |   7 +
 target/i386/kvm/trace.h               |   1 +
 target/i386/machine.c                 |   4 +-
 target/i386/meson.build               |  39 +-
 target/i386/{ => tcg}/bpt_helper.c    |   1 +
 target/i386/{ => tcg}/cc_helper.c     |   1 +
 target/i386/tcg/cpu.c                 | 173 +++++++++
 target/i386/{ => tcg}/excp_helper.c   |   1 +
 target/i386/{ => tcg}/fpu_helper.c    |  33 +-
 target/i386/{ => tcg}/int_helper.c    |   1 +
 target/i386/{ => tcg}/mem_helper.c    |   1 +
 target/i386/tcg/meson.build           |  14 +
 target/i386/{ => tcg}/misc_helper.c   |   1 +
 target/i386/{ => tcg}/mpx_helper.c    |   1 +
 target/i386/{ => tcg}/seg_helper.c    |   1 +
 target/i386/{ => tcg}/smm_helper.c    |   2 +
 target/i386/{ => tcg}/svm_helper.c    |   1 +
 target/i386/{ => tcg}/tcg-stub.c      |   0
 target/i386/{ => tcg}/translate.c     |   1 +
 target/i386/trace-events              |   6 -
 target/i386/whpx/meson.build          |   4 +
 target/i386/{ => whpx}/whp-dispatch.h |   0
 target/i386/{ => whpx}/whpx-all.c     |   4 +-
 target/i386/{ => whpx}/whpx-cpus.c    |  29 +-
 target/i386/{ => whpx}/whpx-cpus.h    |   2 -
 104 files changed, 1965 insertions(+), 1255 deletions(-)
 create mode 100644 accel/accel-common.c
 rename accel/{accel.c => accel-softmmu.c} (64%)
 create mode 100644 accel/accel-softmmu.h
 create mode 100644 accel/accel-user.c
 create mode 100644 accel/tcg/tcg-cpus-mttcg.h
 create mode 100644 include/hw/core/accel-cpu.h
 rename include/{sysemu => qemu}/accel.h (93%)
 create mode 100644 include/sysemu/accel-ops.h
 create mode 100644 target/i386/cpu-dump.c
 rename target/i386/{ => hax}/hax-all.c (99%)
 rename target/i386/{ => hax}/hax-cpus.c (71%)
 rename target/i386/{ => hax}/hax-cpus.h (95%)
 rename target/i386/{ => hax}/hax-i386.h (95%)
 rename target/i386/{ => hax}/hax-interface.h (100%)
 rename target/i386/{ => hax}/hax-mem.c (100%)
 rename target/i386/{ => hax}/hax-posix.c (100%)
 rename target/i386/{ => hax}/hax-posix.h (100%)
 rename target/i386/{ => hax}/hax-windows.c (100%)
 rename target/i386/{ => hax}/hax-windows.h (100%)
 create mode 100644 target/i386/hax/meson.build
 create mode 100644 target/i386/helper-tcg.h
 create mode 100644 target/i386/host-cpu.c
 create mode 100644 target/i386/host-cpu.h
 create mode 100644 target/i386/hvf/cpu.c
 create mode 100644 target/i386/kvm/cpu.c
 rename target/i386/{ => kvm}/hyperv-proto.h (100%)
 rename target/i386/{ => kvm}/hyperv-stub.c (100%)
 rename target/i386/{ => kvm}/hyperv.c (100%)
 rename target/i386/{ => kvm}/hyperv.h (100%)
 create mode 100644 target/i386/kvm/kvm-cpu.h
 rename target/i386/{ => kvm}/kvm-stub.c (100%)
 rename target/i386/{ => kvm}/kvm.c (99%)
 rename target/i386/{ => kvm}/kvm_i386.h (100%)
 create mode 100644 target/i386/kvm/meson.build
 create mode 100644 target/i386/kvm/trace-events
 create mode 100644 target/i386/kvm/trace.h
 rename target/i386/{ => tcg}/bpt_helper.c (99%)
 rename target/i386/{ => tcg}/cc_helper.c (99%)
 create mode 100644 target/i386/tcg/cpu.c
 rename target/i386/{ => tcg}/excp_helper.c (99%)
 rename target/i386/{ => tcg}/fpu_helper.c (99%)
 rename target/i386/{ => tcg}/int_helper.c (99%)
 rename target/i386/{ => tcg}/mem_helper.c (99%)
 create mode 100644 target/i386/tcg/meson.build
 rename target/i386/{ => tcg}/misc_helper.c (99%)
 rename target/i386/{ => tcg}/mpx_helper.c (99%)
 rename target/i386/{ => tcg}/seg_helper.c (99%)
 rename target/i386/{ => tcg}/smm_helper.c (99%)
 rename target/i386/{ => tcg}/svm_helper.c (99%)
 rename target/i386/{ => tcg}/tcg-stub.c (100%)
 rename target/i386/{ => tcg}/translate.c (99%)
 create mode 100644 target/i386/whpx/meson.build
 rename target/i386/{ => whpx}/whp-dispatch.h (100%)
 rename target/i386/{ => whpx}/whpx-all.c (99%)
 rename target/i386/{ => whpx}/whpx-cpus.c (73%)
 rename target/i386/{ => whpx}/whpx-cpus.h (96%)
Signature · 1 line
2.26.2
#1 lore raw

RFC v6 1/11 i386: move kvm accel files into kvm/

---
 MAINTAINERS                          | 2 +-
 hw/i386/fw_cfg.c                     | 2 +-
 hw/i386/intel_iommu.c                | 2 +-
 hw/i386/kvm/apic.c                   | 2 +-
 hw/i386/kvm/clock.c                  | 2 +-
 hw/i386/microvm.c                    | 2 +-
 hw/i386/pc.c                         | 2 +-
 hw/i386/x86.c                        | 2 +-
 meson.build                          | 1 +
 target/i386/cpu.c                    | 2 +-
 target/i386/cpu.h                    | 2 +-
 target/i386/helper.c                 | 2 +-
 target/i386/{ => kvm}/hyperv-proto.h | 0
 target/i386/{ => kvm}/hyperv-stub.c  | 0
 target/i386/{ => kvm}/hyperv.c       | 0
 target/i386/{ => kvm}/hyperv.h       | 0
 target/i386/{ => kvm}/kvm-stub.c     | 0
 target/i386/{ => kvm}/kvm.c          | 0
 target/i386/{ => kvm}/kvm_i386.h     | 0
 target/i386/kvm/meson.build          | 3 +++
 target/i386/kvm/trace-events         | 7 +++++++
 target/i386/kvm/trace.h              | 1 +
 target/i386/machine.c                | 4 ++--
 target/i386/meson.build              | 4 +---
 target/i386/trace-events             | 6 ------
 25 files changed, 26 insertions(+), 22 deletions(-)
 rename target/i386/{ => kvm}/hyperv-proto.h (100%)
 rename target/i386/{ => kvm}/hyperv-stub.c (100%)
 rename target/i386/{ => kvm}/hyperv.c (100%)
 rename target/i386/{ => kvm}/hyperv.h (100%)
 rename target/i386/{ => kvm}/kvm-stub.c (100%)
 rename target/i386/{ => kvm}/kvm.c (100%)
 rename target/i386/{ => kvm}/kvm_i386.h (100%)
 create mode 100644 target/i386/kvm/meson.build
 create mode 100644 target/i386/kvm/trace-events
 create mode 100644 target/i386/kvm/trace.h
MAINTAINERS +1 -1
index 2e018a0c1d..6a77faccf6 100644
@@ -424,7 +424,7 @@ M: Paolo Bonzini <[email protected]>
 M: Marcelo Tosatti <[email protected]>
 L: [email protected]
 S: Supported
-F: target/i386/kvm.c
+F: target/i386/kvm/
 F: scripts/kvm/vmxcap
 
 Guest CPU Cores (other accelerators)
hw/i386/fw_cfg.c +1 -1
index e06579490c..fae1bb380f 100644
@@ -21,7 +21,7 @@
 #include "hw/timer/hpet.h"
 #include "hw/nvram/fw_cfg.h"
 #include "e820_memory_layout.h"
-#include "kvm_i386.h"
+#include "kvm/kvm_i386.h"
 #include CONFIG_DEVICES
 
 struct hpet_fw_config hpet_cfg = {.count = UINT8_MAX};
hw/i386/intel_iommu.c +1 -1
index 70ac837733..361b6cd238 100644
@@ -37,7 +37,7 @@
 #include "sysemu/kvm.h"
 #include "sysemu/sysemu.h"
 #include "hw/i386/apic_internal.h"
-#include "kvm_i386.h"
+#include "kvm/kvm_i386.h"
 #include "migration/vmstate.h"
 #include "trace.h"
 
hw/i386/kvm/apic.c +1 -1
index dd29906061..07bebc1282 100644
@@ -17,7 +17,7 @@
 #include "hw/pci/msi.h"
 #include "sysemu/hw_accel.h"
 #include "sysemu/kvm.h"
-#include "target/i386/kvm_i386.h"
+#include "kvm/kvm_i386.h"
 
 static inline void kvm_apic_set_reg(struct kvm_lapic_state *kapic,
                                     int reg_id, uint32_t val)
hw/i386/kvm/clock.c +1 -1
index 24fe5091b6..2d8a366369 100644
@@ -20,7 +20,7 @@
 #include "sysemu/kvm.h"
 #include "sysemu/runstate.h"
 #include "sysemu/hw_accel.h"
-#include "kvm_i386.h"
+#include "kvm/kvm_i386.h"
 #include "migration/vmstate.h"
 #include "hw/sysbus.h"
 #include "hw/kvm/clock.h"
hw/i386/microvm.c +1 -1
index 5428448b70..3ed6adff83 100644
@@ -51,7 +51,7 @@
 
 #include "cpu.h"
 #include "elf.h"
-#include "kvm_i386.h"
+#include "kvm/kvm_i386.h"
 #include "hw/xen/start_info.h"
 
 #define MICROVM_QBOOT_FILENAME "qboot.rom"
hw/i386/pc.c +1 -1
index 17b514d1da..299aaba8e9 100644
@@ -61,7 +61,7 @@
 #include "sysemu/qtest.h"
 #include "sysemu/reset.h"
 #include "sysemu/runstate.h"
-#include "kvm_i386.h"
+#include "kvm/kvm_i386.h"
 #include "hw/xen/xen.h"
 #include "hw/xen/start_info.h"
 #include "ui/qemu-spice.h"
hw/i386/x86.c +1 -1
index 5944fc44ed..88d0c70e12 100644
@@ -52,7 +52,7 @@
 #include "elf.h"
 #include "standard-headers/asm-x86/bootparam.h"
 #include CONFIG_DEVICES
-#include "kvm_i386.h"
+#include "kvm/kvm_i386.h"
 
 #define BIOS_FILENAME "bios.bin"
 
meson.build +1 -0
index 5062407c70..d6158172b0 100644
@@ -1468,6 +1468,7 @@ trace_events_subdirs += [
   'target/arm',
   'target/hppa',
   'target/i386',
+  'target/i386/kvm',
   'target/mips',
   'target/ppc',
   'target/riscv',
target/i386/cpu.c +1 -1
index 5a8c96072e..b9bd249c8f 100644
@@ -30,7 +30,7 @@
 #include "sysemu/hvf.h"
 #include "sysemu/cpus.h"
 #include "sysemu/xen.h"
-#include "kvm_i386.h"
+#include "kvm/kvm_i386.h"
 #include "sev_i386.h"
 
 #include "qemu/error-report.h"
target/i386/cpu.h +1 -1
index 88e8586f8f..9ecda75aec 100644
@@ -22,7 +22,7 @@
 
 #include "sysemu/tcg.h"
 #include "cpu-qom.h"
-#include "hyperv-proto.h"
+#include "kvm/hyperv-proto.h"
 #include "exec/cpu-defs.h"
 #include "qapi/qapi-types-common.h"
 
target/i386/helper.c +1 -1
index 034f46bcc2..a1b3367ab2 100644
@@ -24,7 +24,7 @@
 #include "qemu/qemu-print.h"
 #include "sysemu/kvm.h"
 #include "sysemu/runstate.h"
-#include "kvm_i386.h"
+#include "kvm/kvm_i386.h"
 #ifndef CONFIG_USER_ONLY
 #include "sysemu/tcg.h"
 #include "sysemu/hw_accel.h"
target/i386/kvm/hyperv-proto.h renamed from target/i386/hyperv-proto.h +0 -0
similarity index 100%
rename from target/i386/hyperv-proto.h
rename to target/i386/kvm/hyperv-proto.h
target/i386/kvm/hyperv-stub.c renamed from target/i386/hyperv-stub.c +0 -0
similarity index 100%
rename from target/i386/hyperv-stub.c
rename to target/i386/kvm/hyperv-stub.c
target/i386/kvm/hyperv.c renamed from target/i386/hyperv.c +0 -0
similarity index 100%
rename from target/i386/hyperv.c
rename to target/i386/kvm/hyperv.c
target/i386/kvm/hyperv.h renamed from target/i386/hyperv.h +0 -0
similarity index 100%
rename from target/i386/hyperv.h
rename to target/i386/kvm/hyperv.h
target/i386/kvm/kvm-stub.c renamed from target/i386/kvm-stub.c +0 -0
similarity index 100%
rename from target/i386/kvm-stub.c
rename to target/i386/kvm/kvm-stub.c
target/i386/kvm/kvm.c renamed from target/i386/kvm.c +0 -0
similarity index 100%
rename from target/i386/kvm.c
rename to target/i386/kvm/kvm.c
target/i386/kvm/kvm_i386.h renamed from target/i386/kvm_i386.h +0 -0
similarity index 100%
rename from target/i386/kvm_i386.h
rename to target/i386/kvm/kvm_i386.h
target/i386/kvm/meson.build new file +3 -0
new file mode 100644
index 0000000000..1d66559187
@@ -0,0 +1,3 @@
+i386_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
+i386_softmmu_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'))
+i386_softmmu_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_false: files('hyperv-stub.c'))
target/i386/kvm/trace-events new file +7 -0
new file mode 100644
index 0000000000..b4e2d9e4ea
@@ -0,0 +1,7 @@
+# See docs/devel/tracing.txt for syntax documentation.
+
+# kvm.c
+kvm_x86_fixup_msi_error(uint32_t gsi) "VT-d failed to remap interrupt for GSI %" PRIu32
+kvm_x86_add_msi_route(int virq) "Adding route entry for virq %d"
+kvm_x86_remove_msi_route(int virq) "Removing route entry for virq %d"
+kvm_x86_update_msi_routes(int num) "Updated %d MSI routes"
target/i386/kvm/trace.h new file +1 -0
new file mode 100644
index 0000000000..46b75c6942
@@ -0,0 +1 @@
+#include "trace/trace-target_i386_kvm.h"
target/i386/machine.c +2 -2
index 233e46bb70..1614e8c2f8 100644
@@ -3,9 +3,9 @@
 #include "exec/exec-all.h"
 #include "hw/isa/isa.h"
 #include "migration/cpu.h"
-#include "hyperv.h"
+#include "kvm/hyperv.h"
 #include "hw/i386/x86.h"
-#include "kvm_i386.h"
+#include "kvm/kvm_i386.h"
 
 #include "sysemu/kvm.h"
 #include "sysemu/tcg.h"
target/i386/meson.build +1 -3
index a1a02f3e99..0209542a8a 100644
@@ -18,7 +18,6 @@ i386_ss.add(when: 'CONFIG_TCG', if_true: files(
   'smm_helper.c',
   'svm_helper.c',
   'translate.c'), if_false: files('tcg-stub.c'))
-i386_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
 i386_ss.add(when: 'CONFIG_SEV', if_true: files('sev.c'), if_false: files('sev-stub.c'))
 
 i386_softmmu_ss = ss.source_set()
@@ -28,8 +27,6 @@ i386_softmmu_ss.add(files(
   'machine.c',
   'monitor.c',
 ))
-i386_softmmu_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_false: files('hyperv-stub.c'))
-i386_softmmu_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'))
 i386_softmmu_ss.add(when: 'CONFIG_WHPX', if_true: files(
   'whpx-all.c',
   'whpx-cpus.c',
@@ -42,6 +39,7 @@ i386_softmmu_ss.add(when: 'CONFIG_HAX', if_true: files(
 i386_softmmu_ss.add(when: ['CONFIG_HAX', 'CONFIG_POSIX'], if_true: files('hax-posix.c'))
 i386_softmmu_ss.add(when: ['CONFIG_HAX', 'CONFIG_WIN32'], if_true: files('hax-windows.c'))
 
+subdir('kvm')
 subdir('hvf')
 
 target_arch += {'i386': i386_ss}
target/i386/trace-events +0 -6
index 789c700d4a..d166f9d5e0 100644
@@ -1,11 +1,5 @@
 # See docs/devel/tracing.txt for syntax documentation.
 
-# kvm.c
-kvm_x86_fixup_msi_error(uint32_t gsi) "VT-d failed to remap interrupt for GSI %" PRIu32
-kvm_x86_add_msi_route(int virq) "Adding route entry for virq %d"
-kvm_x86_remove_msi_route(int virq) "Removing route entry for virq %d"
-kvm_x86_update_msi_routes(int num) "Updated %d MSI routes"
-
 # sev.c
 kvm_sev_init(void) ""
 kvm_memcrypt_register_region(void *addr, size_t len) "addr %p len 0x%zu"
Signature · 1 line
2.26.2
#2 lore raw

RFC v6 2/11 i386: move whpx accel files into whpx/

In reply to Claudio Fontana
---
 MAINTAINERS                           | 5 +----
 target/i386/meson.build               | 5 +----
 target/i386/whpx/meson.build          | 4 ++++
 target/i386/{ => whpx}/whp-dispatch.h | 0
 target/i386/{ => whpx}/whpx-all.c     | 0
 target/i386/{ => whpx}/whpx-cpus.c    | 0
 target/i386/{ => whpx}/whpx-cpus.h    | 0
 7 files changed, 6 insertions(+), 8 deletions(-)
 create mode 100644 target/i386/whpx/meson.build
 rename target/i386/{ => whpx}/whp-dispatch.h (100%)
 rename target/i386/{ => whpx}/whpx-all.c (100%)
 rename target/i386/{ => whpx}/whpx-cpus.c (100%)
 rename target/i386/{ => whpx}/whpx-cpus.h (100%)
MAINTAINERS +1 -4
index 6a77faccf6..02bc29ea2b 100644
@@ -450,10 +450,7 @@ F: include/sysemu/hvf.h
 WHPX CPUs
 M: Sunil Muthuswamy <[email protected]>
 S: Supported
-F: target/i386/whpx-all.c
-F: target/i386/whpx-cpus.c
-F: target/i386/whp-dispatch.h
-F: accel/stubs/whpx-stub.c
+F: target/i386/whpx/
 F: include/sysemu/whpx.h
 
 Guest CPU Cores (Xen)
target/i386/meson.build +1 -4
index 0209542a8a..62cd042915 100644
@@ -27,10 +27,6 @@ i386_softmmu_ss.add(files(
   'machine.c',
   'monitor.c',
 ))
-i386_softmmu_ss.add(when: 'CONFIG_WHPX', if_true: files(
-  'whpx-all.c',
-  'whpx-cpus.c',
-))
 i386_softmmu_ss.add(when: 'CONFIG_HAX', if_true: files(
   'hax-all.c',
   'hax-mem.c',
@@ -40,6 +36,7 @@ i386_softmmu_ss.add(when: ['CONFIG_HAX', 'CONFIG_POSIX'], if_true: files('hax-po
 i386_softmmu_ss.add(when: ['CONFIG_HAX', 'CONFIG_WIN32'], if_true: files('hax-windows.c'))
 
 subdir('kvm')
+subdir('whpx')
 subdir('hvf')
 
 target_arch += {'i386': i386_ss}
target/i386/whpx/meson.build new file +4 -0
new file mode 100644
index 0000000000..94a72c8efc
@@ -0,0 +1,4 @@
+i386_softmmu_ss.add(when: 'CONFIG_WHPX', if_true: files(
+  'whpx-all.c',
+  'whpx-cpus.c',
+))
target/i386/whpx/whp-dispatch.h renamed from target/i386/whp-dispatch.h +0 -0
similarity index 100%
rename from target/i386/whp-dispatch.h
rename to target/i386/whpx/whp-dispatch.h
target/i386/whpx/whpx-all.c renamed from target/i386/whpx-all.c +0 -0
similarity index 100%
rename from target/i386/whpx-all.c
rename to target/i386/whpx/whpx-all.c
target/i386/whpx/whpx-cpus.c renamed from target/i386/whpx-cpus.c +0 -0
similarity index 100%
rename from target/i386/whpx-cpus.c
rename to target/i386/whpx/whpx-cpus.c
target/i386/whpx/whpx-cpus.h renamed from target/i386/whpx-cpus.h +0 -0
similarity index 100%
rename from target/i386/whpx-cpus.h
rename to target/i386/whpx/whpx-cpus.h
Signature · 1 line
2.26.2
#3 lore raw

RFC v6 3/11 i386: move hax accel files into hax/

In reply to Claudio Fontana
---
 MAINTAINERS                           | 2 +-
 target/i386/{ => hax}/hax-all.c       | 0
 target/i386/{ => hax}/hax-cpus.c      | 0
 target/i386/{ => hax}/hax-cpus.h      | 0
 target/i386/{ => hax}/hax-i386.h      | 6 +++---
 target/i386/{ => hax}/hax-interface.h | 0
 target/i386/{ => hax}/hax-mem.c       | 0
 target/i386/{ => hax}/hax-posix.c     | 0
 target/i386/{ => hax}/hax-posix.h     | 0
 target/i386/{ => hax}/hax-windows.c   | 0
 target/i386/{ => hax}/hax-windows.h   | 0
 target/i386/hax/meson.build           | 7 +++++++
 target/i386/meson.build               | 8 +-------
 13 files changed, 12 insertions(+), 11 deletions(-)
 rename target/i386/{ => hax}/hax-all.c (100%)
 rename target/i386/{ => hax}/hax-cpus.c (100%)
 rename target/i386/{ => hax}/hax-cpus.h (100%)
 rename target/i386/{ => hax}/hax-i386.h (95%)
 rename target/i386/{ => hax}/hax-interface.h (100%)
 rename target/i386/{ => hax}/hax-mem.c (100%)
 rename target/i386/{ => hax}/hax-posix.c (100%)
 rename target/i386/{ => hax}/hax-posix.h (100%)
 rename target/i386/{ => hax}/hax-windows.c (100%)
 rename target/i386/{ => hax}/hax-windows.h (100%)
 create mode 100644 target/i386/hax/meson.build
MAINTAINERS +1 -1
index 02bc29ea2b..463317784c 100644
@@ -490,7 +490,7 @@ W: https://github.com/intel/haxm/issues
 S: Maintained
 F: accel/stubs/hax-stub.c
 F: include/sysemu/hax.h
-F: target/i386/hax-*
+F: target/i386/hax/
 
 Hosts
 -----
target/i386/hax/hax-all.c renamed from target/i386/hax-all.c +0 -0
similarity index 100%
rename from target/i386/hax-all.c
rename to target/i386/hax/hax-all.c
target/i386/hax/hax-cpus.c renamed from target/i386/hax-cpus.c +0 -0
similarity index 100%
rename from target/i386/hax-cpus.c
rename to target/i386/hax/hax-cpus.c
target/i386/hax/hax-cpus.h renamed from target/i386/hax-cpus.h +0 -0
similarity index 100%
rename from target/i386/hax-cpus.h
rename to target/i386/hax/hax-cpus.h
target/i386/hax/hax-i386.h renamed from target/i386/hax-i386.h +3 -3
similarity index 95%
rename from target/i386/hax-i386.h
rename to target/i386/hax/hax-i386.h
index 48c4abe14e..efbb346238 100644
@@ -84,13 +84,13 @@ void hax_memory_init(void);
 
 
 #ifdef CONFIG_POSIX
-#include "target/i386/hax-posix.h"
+#include "hax-posix.h"
 #endif
 
 #ifdef CONFIG_WIN32
-#include "target/i386/hax-windows.h"
+#include "hax-windows.h"
 #endif
 
-#include "target/i386/hax-interface.h"
+#include "hax-interface.h"
 
 #endif
target/i386/hax/hax-interface.h renamed from target/i386/hax-interface.h +0 -0
similarity index 100%
rename from target/i386/hax-interface.h
rename to target/i386/hax/hax-interface.h
target/i386/hax/hax-mem.c renamed from target/i386/hax-mem.c +0 -0
similarity index 100%
rename from target/i386/hax-mem.c
rename to target/i386/hax/hax-mem.c
target/i386/hax/hax-posix.c renamed from target/i386/hax-posix.c +0 -0
similarity index 100%
rename from target/i386/hax-posix.c
rename to target/i386/hax/hax-posix.c
target/i386/hax/hax-posix.h renamed from target/i386/hax-posix.h +0 -0
similarity index 100%
rename from target/i386/hax-posix.h
rename to target/i386/hax/hax-posix.h
target/i386/hax/hax-windows.c renamed from target/i386/hax-windows.c +0 -0
similarity index 100%
rename from target/i386/hax-windows.c
rename to target/i386/hax/hax-windows.c
target/i386/hax/hax-windows.h renamed from target/i386/hax-windows.h +0 -0
similarity index 100%
rename from target/i386/hax-windows.h
rename to target/i386/hax/hax-windows.h
target/i386/hax/meson.build new file +7 -0
new file mode 100644
index 0000000000..77ea431b30
@@ -0,0 +1,7 @@
+i386_softmmu_ss.add(when: 'CONFIG_HAX', if_true: files(
+  'hax-all.c',
+  'hax-mem.c',
+  'hax-cpus.c',
+))
+i386_softmmu_ss.add(when: ['CONFIG_HAX', 'CONFIG_POSIX'], if_true: files('hax-posix.c'))
+i386_softmmu_ss.add(when: ['CONFIG_HAX', 'CONFIG_WIN32'], if_true: files('hax-windows.c'))
target/i386/meson.build +1 -7
index 62cd042915..284d52ab81 100644
@@ -27,15 +27,9 @@ i386_softmmu_ss.add(files(
   'machine.c',
   'monitor.c',
 ))
-i386_softmmu_ss.add(when: 'CONFIG_HAX', if_true: files(
-  'hax-all.c',
-  'hax-mem.c',
-  'hax-cpus.c',
-))
-i386_softmmu_ss.add(when: ['CONFIG_HAX', 'CONFIG_POSIX'], if_true: files('hax-posix.c'))
-i386_softmmu_ss.add(when: ['CONFIG_HAX', 'CONFIG_WIN32'], if_true: files('hax-windows.c'))
 
 subdir('kvm')
+subdir('hax')
 subdir('whpx')
 subdir('hvf')
 
Signature · 1 line
2.26.2
#4 lore raw

RFC v6 4/11 i386: hvf: remove stale MAINTAINERS entry for old hvf stubs

In reply to Claudio Fontana
---
 MAINTAINERS | 1 -
 1 file changed, 1 deletion(-)
MAINTAINERS +0 -1
index 463317784c..e892dd2220 100644
@@ -443,7 +443,6 @@ M: Cameron Esfahani <[email protected]>
 M: Roman Bolshakov <[email protected]>
 W: https://wiki.qemu.org/Features/HVF
 S: Maintained
-F: accel/stubs/hvf-stub.c
 F: target/i386/hvf/
 F: include/sysemu/hvf.h
 
Signature · 1 line
2.26.2
#5 lore raw

RFC v6 5/11 i386: move TCG accel files into tcg/

In reply to Claudio Fontana
---
 target/i386/meson.build             | 14 +-------------
 target/i386/{ => tcg}/bpt_helper.c  |  0
 target/i386/{ => tcg}/cc_helper.c   |  0
 target/i386/{ => tcg}/excp_helper.c |  0
 target/i386/{ => tcg}/fpu_helper.c  |  0
 target/i386/{ => tcg}/int_helper.c  |  0
 target/i386/{ => tcg}/mem_helper.c  |  0
 target/i386/tcg/meson.build         | 13 +++++++++++++
 target/i386/{ => tcg}/misc_helper.c |  0
 target/i386/{ => tcg}/mpx_helper.c  |  0
 target/i386/{ => tcg}/seg_helper.c  |  0
 target/i386/{ => tcg}/smm_helper.c  |  0
 target/i386/{ => tcg}/svm_helper.c  |  0
 target/i386/{ => tcg}/tcg-stub.c    |  0
 target/i386/{ => tcg}/translate.c   |  0
 15 files changed, 14 insertions(+), 13 deletions(-)
 rename target/i386/{ => tcg}/bpt_helper.c (100%)
 rename target/i386/{ => tcg}/cc_helper.c (100%)
 rename target/i386/{ => tcg}/excp_helper.c (100%)
 rename target/i386/{ => tcg}/fpu_helper.c (100%)
 rename target/i386/{ => tcg}/int_helper.c (100%)
 rename target/i386/{ => tcg}/mem_helper.c (100%)
 create mode 100644 target/i386/tcg/meson.build
 rename target/i386/{ => tcg}/misc_helper.c (100%)
 rename target/i386/{ => tcg}/mpx_helper.c (100%)
 rename target/i386/{ => tcg}/seg_helper.c (100%)
 rename target/i386/{ => tcg}/smm_helper.c (100%)
 rename target/i386/{ => tcg}/svm_helper.c (100%)
 rename target/i386/{ => tcg}/tcg-stub.c (100%)
 rename target/i386/{ => tcg}/translate.c (100%)
target/i386/meson.build +1 -13
index 284d52ab81..750471c9f3 100644
@@ -5,19 +5,6 @@ i386_ss.add(files(
   'helper.c',
   'xsave_helper.c',
 ))
-i386_ss.add(when: 'CONFIG_TCG', if_true: files(
-  'bpt_helper.c',
-  'cc_helper.c',
-  'excp_helper.c',
-  'fpu_helper.c',
-  'int_helper.c',
-  'mem_helper.c',
-  'misc_helper.c',
-  'mpx_helper.c',
-  'seg_helper.c',
-  'smm_helper.c',
-  'svm_helper.c',
-  'translate.c'), if_false: files('tcg-stub.c'))
 i386_ss.add(when: 'CONFIG_SEV', if_true: files('sev.c'), if_false: files('sev-stub.c'))
 
 i386_softmmu_ss = ss.source_set()
@@ -32,6 +19,7 @@ subdir('kvm')
 subdir('hax')
 subdir('whpx')
 subdir('hvf')
+subdir('tcg')
 
 target_arch += {'i386': i386_ss}
 target_softmmu_arch += {'i386': i386_softmmu_ss}
target/i386/tcg/bpt_helper.c renamed from target/i386/bpt_helper.c +0 -0
similarity index 100%
rename from target/i386/bpt_helper.c
rename to target/i386/tcg/bpt_helper.c
target/i386/tcg/cc_helper.c renamed from target/i386/cc_helper.c +0 -0
similarity index 100%
rename from target/i386/cc_helper.c
rename to target/i386/tcg/cc_helper.c
target/i386/tcg/excp_helper.c renamed from target/i386/excp_helper.c +0 -0
similarity index 100%
rename from target/i386/excp_helper.c
rename to target/i386/tcg/excp_helper.c
target/i386/tcg/fpu_helper.c renamed from target/i386/fpu_helper.c +0 -0
similarity index 100%
rename from target/i386/fpu_helper.c
rename to target/i386/tcg/fpu_helper.c
target/i386/tcg/int_helper.c renamed from target/i386/int_helper.c +0 -0
similarity index 100%
rename from target/i386/int_helper.c
rename to target/i386/tcg/int_helper.c
target/i386/tcg/mem_helper.c renamed from target/i386/mem_helper.c +0 -0
similarity index 100%
rename from target/i386/mem_helper.c
rename to target/i386/tcg/mem_helper.c
target/i386/tcg/meson.build new file +13 -0
new file mode 100644
index 0000000000..02794226c2
@@ -0,0 +1,13 @@
+i386_ss.add(when: 'CONFIG_TCG', if_true: files(
+  'bpt_helper.c',
+  'cc_helper.c',
+  'excp_helper.c',
+  'fpu_helper.c',
+  'int_helper.c',
+  'mem_helper.c',
+  'misc_helper.c',
+  'mpx_helper.c',
+  'seg_helper.c',
+  'smm_helper.c',
+  'svm_helper.c',
+  'translate.c'), if_false: files('tcg-stub.c'))
target/i386/tcg/misc_helper.c renamed from target/i386/misc_helper.c +0 -0
similarity index 100%
rename from target/i386/misc_helper.c
rename to target/i386/tcg/misc_helper.c
target/i386/tcg/mpx_helper.c renamed from target/i386/mpx_helper.c +0 -0
similarity index 100%
rename from target/i386/mpx_helper.c
rename to target/i386/tcg/mpx_helper.c
target/i386/tcg/seg_helper.c renamed from target/i386/seg_helper.c +0 -0
similarity index 100%
rename from target/i386/seg_helper.c
rename to target/i386/tcg/seg_helper.c
target/i386/tcg/smm_helper.c renamed from target/i386/smm_helper.c +0 -0
similarity index 100%
rename from target/i386/smm_helper.c
rename to target/i386/tcg/smm_helper.c
target/i386/tcg/svm_helper.c renamed from target/i386/svm_helper.c +0 -0
similarity index 100%
rename from target/i386/svm_helper.c
rename to target/i386/tcg/svm_helper.c
target/i386/tcg/tcg-stub.c renamed from target/i386/tcg-stub.c +0 -0
similarity index 100%
rename from target/i386/tcg-stub.c
rename to target/i386/tcg/tcg-stub.c
target/i386/tcg/translate.c renamed from target/i386/translate.c +0 -0
similarity index 100%
rename from target/i386/translate.c
rename to target/i386/tcg/translate.c
Signature · 1 line
2.26.2
#6 lore raw

RFC v6 6/11 i386: move cpu dump out of helper.c into cpu-dump.c

In reply to Claudio Fontana
---
 target/i386/cpu-dump.c  | 538 ++++++++++++++++++++++++++++++++++++++++
 target/i386/cpu.h       |   1 +
 target/i386/helper.c    | 514 --------------------------------------
 target/i386/meson.build |   1 +
 4 files changed, 540 insertions(+), 514 deletions(-)
 create mode 100644 target/i386/cpu-dump.c
target/i386/cpu-dump.c new file +538 -0
new file mode 100644
index 0000000000..1ddc47fb0c
@@ -0,0 +1,538 @@
+/*
+ *  i386 CPU dump to FILE
+ *
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "cpu.h"
+#include "qemu/qemu-print.h"
+#ifndef CONFIG_USER_ONLY
+#include "hw/i386/apic_internal.h"
+#endif
+
+/***********************************************************/
+/* x86 debug */
+
+static const char *cc_op_str[CC_OP_NB] = {
+    "DYNAMIC",
+    "EFLAGS",
+
+    "MULB",
+    "MULW",
+    "MULL",
+    "MULQ",
+
+    "ADDB",
+    "ADDW",
+    "ADDL",
+    "ADDQ",
+
+    "ADCB",
+    "ADCW",
+    "ADCL",
+    "ADCQ",
+
+    "SUBB",
+    "SUBW",
+    "SUBL",
+    "SUBQ",
+
+    "SBBB",
+    "SBBW",
+    "SBBL",
+    "SBBQ",
+
+    "LOGICB",
+    "LOGICW",
+    "LOGICL",
+    "LOGICQ",
+
+    "INCB",
+    "INCW",
+    "INCL",
+    "INCQ",
+
+    "DECB",
+    "DECW",
+    "DECL",
+    "DECQ",
+
+    "SHLB",
+    "SHLW",
+    "SHLL",
+    "SHLQ",
+
+    "SARB",
+    "SARW",
+    "SARL",
+    "SARQ",
+
+    "BMILGB",
+    "BMILGW",
+    "BMILGL",
+    "BMILGQ",
+
+    "ADCX",
+    "ADOX",
+    "ADCOX",
+
+    "CLR",
+};
+
+static void
+cpu_x86_dump_seg_cache(CPUX86State *env, FILE *f,
+                       const char *name, struct SegmentCache *sc)
+{
+#ifdef TARGET_X86_64
+    if (env->hflags & HF_CS64_MASK) {
+        qemu_fprintf(f, "%-3s=%04x %016" PRIx64 " %08x %08x", name,
+                     sc->selector, sc->base, sc->limit,
+                     sc->flags & 0x00ffff00);
+    } else
+#endif
+    {
+        qemu_fprintf(f, "%-3s=%04x %08x %08x %08x", name, sc->selector,
+                     (uint32_t)sc->base, sc->limit,
+                     sc->flags & 0x00ffff00);
+    }
+
+    if (!(env->hflags & HF_PE_MASK) || !(sc->flags & DESC_P_MASK))
+        goto done;
+
+    qemu_fprintf(f, " DPL=%d ",
+                 (sc->flags & DESC_DPL_MASK) >> DESC_DPL_SHIFT);
+    if (sc->flags & DESC_S_MASK) {
+        if (sc->flags & DESC_CS_MASK) {
+            qemu_fprintf(f, (sc->flags & DESC_L_MASK) ? "CS64" :
+                         ((sc->flags & DESC_B_MASK) ? "CS32" : "CS16"));
+            qemu_fprintf(f, " [%c%c", (sc->flags & DESC_C_MASK) ? 'C' : '-',
+                         (sc->flags & DESC_R_MASK) ? 'R' : '-');
+        } else {
+            qemu_fprintf(f, (sc->flags & DESC_B_MASK
+                             || env->hflags & HF_LMA_MASK)
+                         ? "DS  " : "DS16");
+            qemu_fprintf(f, " [%c%c", (sc->flags & DESC_E_MASK) ? 'E' : '-',
+                         (sc->flags & DESC_W_MASK) ? 'W' : '-');
+        }
+        qemu_fprintf(f, "%c]", (sc->flags & DESC_A_MASK) ? 'A' : '-');
+    } else {
+        static const char *sys_type_name[2][16] = {
+            { /* 32 bit mode */
+                "Reserved", "TSS16-avl", "LDT", "TSS16-busy",
+                "CallGate16", "TaskGate", "IntGate16", "TrapGate16",
+                "Reserved", "TSS32-avl", "Reserved", "TSS32-busy",
+                "CallGate32", "Reserved", "IntGate32", "TrapGate32"
+            },
+            { /* 64 bit mode */
+                "<hiword>", "Reserved", "LDT", "Reserved", "Reserved",
+                "Reserved", "Reserved", "Reserved", "Reserved",
+                "TSS64-avl", "Reserved", "TSS64-busy", "CallGate64",
+                "Reserved", "IntGate64", "TrapGate64"
+            }
+        };
+        qemu_fprintf(f, "%s",
+                     sys_type_name[(env->hflags & HF_LMA_MASK) ? 1 : 0]
+                     [(sc->flags & DESC_TYPE_MASK) >> DESC_TYPE_SHIFT]);
+    }
+done:
+    qemu_fprintf(f, "\n");
+}
+
+#ifndef CONFIG_USER_ONLY
+
+/* ARRAY_SIZE check is not required because
+ * DeliveryMode(dm) has a size of 3 bit.
+ */
+static inline const char *dm2str(uint32_t dm)
+{
+    static const char *str[] = {
+        "Fixed",
+        "...",
+        "SMI",
+        "...",
+        "NMI",
+        "INIT",
+        "...",
+        "ExtINT"
+    };
+    return str[dm];
+}
+
+static void dump_apic_lvt(const char *name, uint32_t lvt, bool is_timer)
+{
+    uint32_t dm = (lvt & APIC_LVT_DELIV_MOD) >> APIC_LVT_DELIV_MOD_SHIFT;
+    qemu_printf("%s\t 0x%08x %s %-5s %-6s %-7s %-12s %-6s",
+                name, lvt,
+                lvt & APIC_LVT_INT_POLARITY ? "active-lo" : "active-hi",
+                lvt & APIC_LVT_LEVEL_TRIGGER ? "level" : "edge",
+                lvt & APIC_LVT_MASKED ? "masked" : "",
+                lvt & APIC_LVT_DELIV_STS ? "pending" : "",
+                !is_timer ?
+                    "" : lvt & APIC_LVT_TIMER_PERIODIC ?
+                            "periodic" : lvt & APIC_LVT_TIMER_TSCDEADLINE ?
+                                            "tsc-deadline" : "one-shot",
+                dm2str(dm));
+    if (dm != APIC_DM_NMI) {
+        qemu_printf(" (vec %u)\n", lvt & APIC_VECTOR_MASK);
+    } else {
+        qemu_printf("\n");
+    }
+}
+
+/* ARRAY_SIZE check is not required because
+ * destination shorthand has a size of 2 bit.
+ */
+static inline const char *shorthand2str(uint32_t shorthand)
+{
+    const char *str[] = {
+        "no-shorthand", "self", "all-self", "all"
+    };
+    return str[shorthand];
+}
+
+static inline uint8_t divider_conf(uint32_t divide_conf)
+{
+    uint8_t divide_val = ((divide_conf & 0x8) >> 1) | (divide_conf & 0x3);
+
+    return divide_val == 7 ? 1 : 2 << divide_val;
+}
+
+static inline void mask2str(char *str, uint32_t val, uint8_t size)
+{
+    while (size--) {
+        *str++ = (val >> size) & 1 ? '1' : '0';
+    }
+    *str = 0;
+}
+
+#define MAX_LOGICAL_APIC_ID_MASK_SIZE 16
+
+static void dump_apic_icr(APICCommonState *s, CPUX86State *env)
+{
+    uint32_t icr = s->icr[0], icr2 = s->icr[1];
+    uint8_t dest_shorthand = \
+        (icr & APIC_ICR_DEST_SHORT) >> APIC_ICR_DEST_SHORT_SHIFT;
+    bool logical_mod = icr & APIC_ICR_DEST_MOD;
+    char apic_id_str[MAX_LOGICAL_APIC_ID_MASK_SIZE + 1];
+    uint32_t dest_field;
+    bool x2apic;
+
+    qemu_printf("ICR\t 0x%08x %s %s %s %s\n",
+                icr,
+                logical_mod ? "logical" : "physical",
+                icr & APIC_ICR_TRIGGER_MOD ? "level" : "edge",
+                icr & APIC_ICR_LEVEL ? "assert" : "de-assert",
+                shorthand2str(dest_shorthand));
+
+    qemu_printf("ICR2\t 0x%08x", icr2);
+    if (dest_shorthand != 0) {
+        qemu_printf("\n");
+        return;
+    }
+    x2apic = env->features[FEAT_1_ECX] & CPUID_EXT_X2APIC;
+    dest_field = x2apic ? icr2 : icr2 >> APIC_ICR_DEST_SHIFT;
+
+    if (!logical_mod) {
+        if (x2apic) {
+            qemu_printf(" cpu %u (X2APIC ID)\n", dest_field);
+        } else {
+            qemu_printf(" cpu %u (APIC ID)\n",
+                        dest_field & APIC_LOGDEST_XAPIC_ID);
+        }
+        return;
+    }
+
+    if (s->dest_mode == 0xf) { /* flat mode */
+        mask2str(apic_id_str, icr2 >> APIC_ICR_DEST_SHIFT, 8);
+        qemu_printf(" mask %s (APIC ID)\n", apic_id_str);
+    } else if (s->dest_mode == 0) { /* cluster mode */
+        if (x2apic) {
+            mask2str(apic_id_str, dest_field & APIC_LOGDEST_X2APIC_ID, 16);
+            qemu_printf(" cluster %u mask %s (X2APIC ID)\n",
+                        dest_field >> APIC_LOGDEST_X2APIC_SHIFT, apic_id_str);
+        } else {
+            mask2str(apic_id_str, dest_field & APIC_LOGDEST_XAPIC_ID, 4);
+            qemu_printf(" cluster %u mask %s (APIC ID)\n",
+                        dest_field >> APIC_LOGDEST_XAPIC_SHIFT, apic_id_str);
+        }
+    }
+}
+
+static void dump_apic_interrupt(const char *name, uint32_t *ireg_tab,
+                                uint32_t *tmr_tab)
+{
+    int i, empty = true;
+
+    qemu_printf("%s\t ", name);
+    for (i = 0; i < 256; i++) {
+        if (apic_get_bit(ireg_tab, i)) {
+            qemu_printf("%u%s ", i,
+                        apic_get_bit(tmr_tab, i) ? "(level)" : "");
+            empty = false;
+        }
+    }
+    qemu_printf("%s\n", empty ? "(none)" : "");
+}
+
+void x86_cpu_dump_local_apic_state(CPUState *cs, int flags)
+{
+    X86CPU *cpu = X86_CPU(cs);
+    APICCommonState *s = APIC_COMMON(cpu->apic_state);
+    if (!s) {
+        qemu_printf("local apic state not available\n");
+        return;
+    }
+    uint32_t *lvt = s->lvt;
+
+    qemu_printf("dumping local APIC state for CPU %-2u\n\n",
+                CPU(cpu)->cpu_index);
+    dump_apic_lvt("LVT0", lvt[APIC_LVT_LINT0], false);
+    dump_apic_lvt("LVT1", lvt[APIC_LVT_LINT1], false);
+    dump_apic_lvt("LVTPC", lvt[APIC_LVT_PERFORM], false);
+    dump_apic_lvt("LVTERR", lvt[APIC_LVT_ERROR], false);
+    dump_apic_lvt("LVTTHMR", lvt[APIC_LVT_THERMAL], false);
+    dump_apic_lvt("LVTT", lvt[APIC_LVT_TIMER], true);
+
+    qemu_printf("Timer\t DCR=0x%x (divide by %u) initial_count = %u"
+                " current_count = %u\n",
+                s->divide_conf & APIC_DCR_MASK,
+                divider_conf(s->divide_conf),
+                s->initial_count, apic_get_current_count(s));
+
+    qemu_printf("SPIV\t 0x%08x APIC %s, focus=%s, spurious vec %u\n",
+                s->spurious_vec,
+                s->spurious_vec & APIC_SPURIO_ENABLED ? "enabled" : "disabled",
+                s->spurious_vec & APIC_SPURIO_FOCUS ? "on" : "off",
+                s->spurious_vec & APIC_VECTOR_MASK);
+
+    dump_apic_icr(s, &cpu->env);
+
+    qemu_printf("ESR\t 0x%08x\n", s->esr);
+
+    dump_apic_interrupt("ISR", s->isr, s->tmr);
+    dump_apic_interrupt("IRR", s->irr, s->tmr);
+
+    qemu_printf("\nAPR 0x%02x TPR 0x%02x DFR 0x%02x LDR 0x%02x",
+                s->arb_id, s->tpr, s->dest_mode, s->log_dest);
+    if (s->dest_mode == 0) {
+        qemu_printf("(cluster %u: id %u)",
+                    s->log_dest >> APIC_LOGDEST_XAPIC_SHIFT,
+                    s->log_dest & APIC_LOGDEST_XAPIC_ID);
+    }
+    qemu_printf(" PPR 0x%02x\n", apic_get_ppr(s));
+}
+#else
+void x86_cpu_dump_local_apic_state(CPUState *cs, int flags)
+{
+}
+#endif /* !CONFIG_USER_ONLY */
+
+#define DUMP_CODE_BYTES_TOTAL    50
+#define DUMP_CODE_BYTES_BACKWARD 20
+
+void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags)
+{
+    X86CPU *cpu = X86_CPU(cs);
+    CPUX86State *env = &cpu->env;
+    int eflags, i, nb;
+    char cc_op_name[32];
+    static const char *seg_name[6] = { "ES", "CS", "SS", "DS", "FS", "GS" };
+
+    eflags = cpu_compute_eflags(env);
+#ifdef TARGET_X86_64
+    if (env->hflags & HF_CS64_MASK) {
+        qemu_fprintf(f, "RAX=%016" PRIx64 " RBX=%016" PRIx64 " RCX=%016" PRIx64 " RDX=%016" PRIx64 "\n"
+                     "RSI=%016" PRIx64 " RDI=%016" PRIx64 " RBP=%016" PRIx64 " RSP=%016" PRIx64 "\n"
+                     "R8 =%016" PRIx64 " R9 =%016" PRIx64 " R10=%016" PRIx64 " R11=%016" PRIx64 "\n"
+                     "R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " R15=%016" PRIx64 "\n"
+                     "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d II=%d A20=%d SMM=%d HLT=%d\n",
+                     env->regs[R_EAX],
+                     env->regs[R_EBX],
+                     env->regs[R_ECX],
+                     env->regs[R_EDX],
+                     env->regs[R_ESI],
+                     env->regs[R_EDI],
+                     env->regs[R_EBP],
+                     env->regs[R_ESP],
+                     env->regs[8],
+                     env->regs[9],
+                     env->regs[10],
+                     env->regs[11],
+                     env->regs[12],
+                     env->regs[13],
+                     env->regs[14],
+                     env->regs[15],
+                     env->eip, eflags,
+                     eflags & DF_MASK ? 'D' : '-',
+                     eflags & CC_O ? 'O' : '-',
+                     eflags & CC_S ? 'S' : '-',
+                     eflags & CC_Z ? 'Z' : '-',
+                     eflags & CC_A ? 'A' : '-',
+                     eflags & CC_P ? 'P' : '-',
+                     eflags & CC_C ? 'C' : '-',
+                     env->hflags & HF_CPL_MASK,
+                     (env->hflags >> HF_INHIBIT_IRQ_SHIFT) & 1,
+                     (env->a20_mask >> 20) & 1,
+                     (env->hflags >> HF_SMM_SHIFT) & 1,
+                     cs->halted);
+    } else
+#endif
+    {
+        qemu_fprintf(f, "EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n"
+                     "ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n"
+                     "EIP=%08x EFL=%08x [%c%c%c%c%c%c%c] CPL=%d II=%d A20=%d SMM=%d HLT=%d\n",
+                     (uint32_t)env->regs[R_EAX],
+                     (uint32_t)env->regs[R_EBX],
+                     (uint32_t)env->regs[R_ECX],
+                     (uint32_t)env->regs[R_EDX],
+                     (uint32_t)env->regs[R_ESI],
+                     (uint32_t)env->regs[R_EDI],
+                     (uint32_t)env->regs[R_EBP],
+                     (uint32_t)env->regs[R_ESP],
+                     (uint32_t)env->eip, eflags,
+                     eflags & DF_MASK ? 'D' : '-',
+                     eflags & CC_O ? 'O' : '-',
+                     eflags & CC_S ? 'S' : '-',
+                     eflags & CC_Z ? 'Z' : '-',
+                     eflags & CC_A ? 'A' : '-',
+                     eflags & CC_P ? 'P' : '-',
+                     eflags & CC_C ? 'C' : '-',
+                     env->hflags & HF_CPL_MASK,
+                     (env->hflags >> HF_INHIBIT_IRQ_SHIFT) & 1,
+                     (env->a20_mask >> 20) & 1,
+                     (env->hflags >> HF_SMM_SHIFT) & 1,
+                     cs->halted);
+    }
+
+    for(i = 0; i < 6; i++) {
+        cpu_x86_dump_seg_cache(env, f, seg_name[i], &env->segs[i]);
+    }
+    cpu_x86_dump_seg_cache(env, f, "LDT", &env->ldt);
+    cpu_x86_dump_seg_cache(env, f, "TR", &env->tr);
+
+#ifdef TARGET_X86_64
+    if (env->hflags & HF_LMA_MASK) {
+        qemu_fprintf(f, "GDT=     %016" PRIx64 " %08x\n",
+                     env->gdt.base, env->gdt.limit);
+        qemu_fprintf(f, "IDT=     %016" PRIx64 " %08x\n",
+                     env->idt.base, env->idt.limit);
+        qemu_fprintf(f, "CR0=%08x CR2=%016" PRIx64 " CR3=%016" PRIx64 " CR4=%08x\n",
+                     (uint32_t)env->cr[0],
+                     env->cr[2],
+                     env->cr[3],
+                     (uint32_t)env->cr[4]);
+        for(i = 0; i < 4; i++)
+            qemu_fprintf(f, "DR%d=%016" PRIx64 " ", i, env->dr[i]);
+        qemu_fprintf(f, "\nDR6=%016" PRIx64 " DR7=%016" PRIx64 "\n",
+                     env->dr[6], env->dr[7]);
+    } else
+#endif
+    {
+        qemu_fprintf(f, "GDT=     %08x %08x\n",
+                     (uint32_t)env->gdt.base, env->gdt.limit);
+        qemu_fprintf(f, "IDT=     %08x %08x\n",
+                     (uint32_t)env->idt.base, env->idt.limit);
+        qemu_fprintf(f, "CR0=%08x CR2=%08x CR3=%08x CR4=%08x\n",
+                     (uint32_t)env->cr[0],
+                     (uint32_t)env->cr[2],
+                     (uint32_t)env->cr[3],
+                     (uint32_t)env->cr[4]);
+        for(i = 0; i < 4; i++) {
+            qemu_fprintf(f, "DR%d=" TARGET_FMT_lx " ", i, env->dr[i]);
+        }
+        qemu_fprintf(f, "\nDR6=" TARGET_FMT_lx " DR7=" TARGET_FMT_lx "\n",
+                     env->dr[6], env->dr[7]);
+    }
+    if (flags & CPU_DUMP_CCOP) {
+        if ((unsigned)env->cc_op < CC_OP_NB)
+            snprintf(cc_op_name, sizeof(cc_op_name), "%s", cc_op_str[env->cc_op]);
+        else
+            snprintf(cc_op_name, sizeof(cc_op_name), "[%d]", env->cc_op);
+#ifdef TARGET_X86_64
+        if (env->hflags & HF_CS64_MASK) {
+            qemu_fprintf(f, "CCS=%016" PRIx64 " CCD=%016" PRIx64 " CCO=%-8s\n",
+                         env->cc_src, env->cc_dst,
+                         cc_op_name);
+        } else
+#endif
+        {
+            qemu_fprintf(f, "CCS=%08x CCD=%08x CCO=%-8s\n",
+                         (uint32_t)env->cc_src, (uint32_t)env->cc_dst,
+                         cc_op_name);
+        }
+    }
+    qemu_fprintf(f, "EFER=%016" PRIx64 "\n", env->efer);
+    if (flags & CPU_DUMP_FPU) {
+        int fptag;
+        fptag = 0;
+        for(i = 0; i < 8; i++) {
+            fptag |= ((!env->fptags[i]) << i);
+        }
+        update_mxcsr_from_sse_status(env);
+        qemu_fprintf(f, "FCW=%04x FSW=%04x [ST=%d] FTW=%02x MXCSR=%08x\n",
+                     env->fpuc,
+                     (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11,
+                     env->fpstt,
+                     fptag,
+                     env->mxcsr);
+        for(i=0;i<8;i++) {
+            CPU_LDoubleU u;
+            u.d = env->fpregs[i].d;
+            qemu_fprintf(f, "FPR%d=%016" PRIx64 " %04x",
+                         i, u.l.lower, u.l.upper);
+            if ((i & 1) == 1)
+                qemu_fprintf(f, "\n");
+            else
+                qemu_fprintf(f, " ");
+        }
+        if (env->hflags & HF_CS64_MASK)
+            nb = 16;
+        else
+            nb = 8;
+        for(i=0;i<nb;i++) {
+            qemu_fprintf(f, "XMM%02d=%08x%08x%08x%08x",
+                         i,
+                         env->xmm_regs[i].ZMM_L(3),
+                         env->xmm_regs[i].ZMM_L(2),
+                         env->xmm_regs[i].ZMM_L(1),
+                         env->xmm_regs[i].ZMM_L(0));
+            if ((i & 1) == 1)
+                qemu_fprintf(f, "\n");
+            else
+                qemu_fprintf(f, " ");
+        }
+    }
+    if (flags & CPU_DUMP_CODE) {
+        target_ulong base = env->segs[R_CS].base + env->eip;
+        target_ulong offs = MIN(env->eip, DUMP_CODE_BYTES_BACKWARD);
+        uint8_t code;
+        char codestr[3];
+
+        qemu_fprintf(f, "Code=");
+        for (i = 0; i < DUMP_CODE_BYTES_TOTAL; i++) {
+            if (cpu_memory_rw_debug(cs, base - offs + i, &code, 1, 0) == 0) {
+                snprintf(codestr, sizeof(codestr), "%02x", code);
+            } else {
+                snprintf(codestr, sizeof(codestr), "??");
+            }
+            qemu_fprintf(f, "%s%s%s%s", i > 0 ? " " : "",
+                         i == offs ? "<" : "", codestr, i == offs ? ">" : "");
+        }
+        qemu_fprintf(f, "\n");
+    }
+}
+
target/i386/cpu.h +1 -0
index 9ecda75aec..d6ed45c5d7 100644
@@ -2232,6 +2232,7 @@ void enable_compat_apic_id_mode(void);
 #define APIC_DEFAULT_ADDRESS 0xfee00000
 #define APIC_SPACE_SIZE      0x100000
 
+/* cpu-dump.c */
 void x86_cpu_dump_local_apic_state(CPUState *cs, int flags);
 
 /* cpu.c */
target/i386/helper.c +0 -514

526 lines not on this page · raw message

target/i386/meson.build +1 -0
index 750471c9f3..c4bf20b319 100644
@@ -4,6 +4,7 @@ i386_ss.add(files(
   'gdbstub.c',
   'helper.c',
   'xsave_helper.c',
+  'cpu-dump.c',
 ))
 i386_ss.add(when: 'CONFIG_SEV', if_true: files('sev.c'), if_false: files('sev-stub.c'))
 
Signature · 1 line
2.26.2
#7 lore raw

RFC v6 7/11 i386: move TCG cpu class initialization out of helper.c

In reply to Claudio Fontana
---
 target/i386/cpu.c             |  33 ++++------
 target/i386/cpu.h             |  97 ++---------------------------
 target/i386/helper-tcg.h      | 112 ++++++++++++++++++++++++++++++++++
 target/i386/helper.c          |  23 -------
 target/i386/meson.build       |   1 +
 target/i386/tcg-cpu.c         |  71 +++++++++++++++++++++
 target/i386/tcg-cpu.h         |  15 +++++
 target/i386/tcg/bpt_helper.c  |   1 +
 target/i386/tcg/cc_helper.c   |   1 +
 target/i386/tcg/excp_helper.c |   1 +
 target/i386/tcg/fpu_helper.c  |  33 +++++-----
 target/i386/tcg/int_helper.c  |   1 +
 target/i386/tcg/mem_helper.c  |   1 +
 target/i386/tcg/misc_helper.c |   1 +
 target/i386/tcg/mpx_helper.c  |   1 +
 target/i386/tcg/seg_helper.c  |   1 +
 target/i386/tcg/smm_helper.c  |   2 +
 target/i386/tcg/svm_helper.c  |   1 +
 target/i386/tcg/translate.c   |   1 +
 19 files changed, 244 insertions(+), 153 deletions(-)
 create mode 100644 target/i386/helper-tcg.h
 create mode 100644 target/i386/tcg-cpu.c
 create mode 100644 target/i386/tcg-cpu.h
target/i386/cpu.c +11 -22
index b9bd249c8f..3462d0143f 100644
@@ -24,6 +24,8 @@
 #include "qemu/qemu-print.h"
 
 #include "cpu.h"
+#include "tcg-cpu.h"
+#include "helper-tcg.h"
 #include "exec/exec-all.h"
 #include "sysemu/kvm.h"
 #include "sysemu/reset.h"
@@ -1495,7 +1497,8 @@ static inline uint64_t x86_cpu_xsave_components(X86CPU *cpu)
            cpu->env.features[FEAT_XSAVE_COMP_LO];
 }
 
-const char *get_register_name_32(unsigned int reg)
+/* Return name of 32-bit register, from a R_* constant */
+static const char *get_register_name_32(unsigned int reg)
 {
     if (reg >= CPU_NB_REGS32) {
         return NULL;
@@ -7012,13 +7015,6 @@ static void x86_cpu_set_pc(CPUState *cs, vaddr value)
     cpu->env.eip = value;
 }
 
-static void x86_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
-{
-    X86CPU *cpu = X86_CPU(cs);
-
-    cpu->env.eip = tb->pc - tb->cs_base;
-}
-
 int x86_cpu_pending_interrupt(CPUState *cs, int interrupt_request)
 {
     X86CPU *cpu = X86_CPU(cs);
@@ -7252,17 +7248,18 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     cc->class_by_name = x86_cpu_class_by_name;
     cc->parse_features = x86_cpu_parse_featurestr;
     cc->has_work = x86_cpu_has_work;
+
 #ifdef CONFIG_TCG
-    cc->do_interrupt = x86_cpu_do_interrupt;
-    cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;
-#endif
+    tcg_cpu_common_class_init(cc);
+#endif /* CONFIG_TCG */
+
     cc->dump_state = x86_cpu_dump_state;
     cc->set_pc = x86_cpu_set_pc;
-    cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
     cc->gdb_read_register = x86_cpu_gdb_read_register;
     cc->gdb_write_register = x86_cpu_gdb_write_register;
     cc->get_arch_id = x86_cpu_get_arch_id;
     cc->get_paging_enabled = x86_cpu_get_paging_enabled;
+
 #ifndef CONFIG_USER_ONLY
     cc->asidx_from_attrs = x86_asidx_from_attrs;
     cc->get_memory_mapping = x86_cpu_get_memory_mapping;
@@ -7273,7 +7270,8 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     cc->write_elf32_note = x86_cpu_write_elf32_note;
     cc->write_elf32_qemunote = x86_cpu_write_elf32_qemunote;
     cc->vmsd = &vmstate_x86_cpu;
-#endif
+#endif /* !CONFIG_USER_ONLY */
+
     cc->gdb_arch_name = x86_gdb_arch_name;
 #ifdef TARGET_X86_64
     cc->gdb_core_xml_file = "i386-64bit.xml";
@@ -7281,15 +7279,6 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
 #else
     cc->gdb_core_xml_file = "i386-32bit.xml";
     cc->gdb_num_core_regs = 50;
-#endif
-#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
-    cc->debug_excp_handler = breakpoint_handler;
-#endif
-    cc->cpu_exec_enter = x86_cpu_exec_enter;
-    cc->cpu_exec_exit = x86_cpu_exec_exit;
-#ifdef CONFIG_TCG
-    cc->tcg_initialize = tcg_x86_init;
-    cc->tlb_fill = x86_cpu_tlb_fill;
 #endif
     cc->disas_set_info = x86_disas_set_info;
 
target/i386/cpu.h +6 -91

169 lines not on this page · raw message

target/i386/helper-tcg.h new file +112 -0

112 lines not on this page · raw message

target/i386/helper.c +0 -23
index 6e7e0f507c..6bb0c53182 100644
@@ -24,10 +24,8 @@
 #include "sysemu/runstate.h"
 #include "kvm/kvm_i386.h"
 #ifndef CONFIG_USER_ONLY
-#include "sysemu/tcg.h"
 #include "sysemu/hw_accel.h"
 #include "monitor/monitor.h"
-#include "hw/i386/apic_internal.h"
 #endif
 
 void cpu_sync_bndcs_hflags(CPUX86State *env)
@@ -572,27 +570,6 @@ void do_cpu_sipi(X86CPU *cpu)
 }
 #endif
 
-/* Frob eflags into and out of the CPU temporary format.  */
-
-void x86_cpu_exec_enter(CPUState *cs)
-{
-    X86CPU *cpu = X86_CPU(cs);
-    CPUX86State *env = &cpu->env;
-
-    CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-    env->df = 1 - (2 * ((env->eflags >> 10) & 1));
-    CC_OP = CC_OP_EFLAGS;
-    env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-}
-
-void x86_cpu_exec_exit(CPUState *cs)
-{
-    X86CPU *cpu = X86_CPU(cs);
-    CPUX86State *env = &cpu->env;
-
-    env->eflags = cpu_compute_eflags(env);
-}
-
 #ifndef CONFIG_USER_ONLY
 uint8_t x86_ldub_phys(CPUState *cs, hwaddr addr)
 {
target/i386/meson.build +1 -0
index c4bf20b319..9c20208e5a 100644
@@ -6,6 +6,7 @@ i386_ss.add(files(
   'xsave_helper.c',
   'cpu-dump.c',
 ))
+i386_ss.add(when: 'CONFIG_TCG', if_true: files('tcg-cpu.c'))
 i386_ss.add(when: 'CONFIG_SEV', if_true: files('sev.c'), if_false: files('sev-stub.c'))
 
 i386_softmmu_ss = ss.source_set()
target/i386/tcg-cpu.c new file +71 -0

71 lines not on this page · raw message

target/i386/tcg-cpu.h new file +15 -0
new file mode 100644
index 0000000000..81f02e562e
@@ -0,0 +1,15 @@
+/*
+ * i386 TCG CPU class initialization
+ *
+ * Copyright 2020 SUSE LLC
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef TCG_CPU_H
+#define TCG_CPU_H
+
+void tcg_cpu_common_class_init(CPUClass *cc);
+
+#endif /* TCG_CPU_H */
target/i386/tcg/bpt_helper.c +1 -0
index e6cc2921e2..979230ac12 100644
@@ -21,6 +21,7 @@
 #include "cpu.h"
 #include "exec/exec-all.h"
 #include "exec/helper-proto.h"
+#include "helper-tcg.h"
 
 
 #ifndef CONFIG_USER_ONLY
target/i386/tcg/cc_helper.c +1 -0
index 924dd3cd57..cc7ea9e8b9 100644
@@ -20,6 +20,7 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "exec/helper-proto.h"
+#include "helper-tcg.h"
 
 const uint8_t parity_table[256] = {
     CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
target/i386/tcg/excp_helper.c +1 -0
index 191471749f..a0f44431fe 100644
@@ -23,6 +23,7 @@
 #include "qemu/log.h"
 #include "sysemu/runstate.h"
 #include "exec/helper-proto.h"
+#include "helper-tcg.h"
 
 void helper_raise_interrupt(CPUX86State *env, int intno, int next_eip_addend)
 {
target/i386/tcg/fpu_helper.c +16 -17
index 03b35443a6..13f31b6ac7 100644
@@ -26,6 +26,7 @@
 #include "exec/cpu_ldst.h"
 #include "fpu/softfloat.h"
 #include "fpu/softfloat-macros.h"
+#include "helper-tcg.h"
 
 #ifdef CONFIG_SOFTMMU
 #include "hw/irq.h"
@@ -2986,23 +2987,21 @@ void update_mxcsr_status(CPUX86State *env)
 
 void update_mxcsr_from_sse_status(CPUX86State *env)
 {
-    if (tcg_enabled()) {
-        uint8_t flags = get_float_exception_flags(&env->sse_status);
-        /*
-         * The MXCSR denormal flag has opposite semantics to
-         * float_flag_input_denormal (the softfloat code sets that flag
-         * only when flushing input denormals to zero, but SSE sets it
-         * only when not flushing them to zero), so is not converted
-         * here.
-         */
-        env->mxcsr |= ((flags & float_flag_invalid ? FPUS_IE : 0) |
-                       (flags & float_flag_divbyzero ? FPUS_ZE : 0) |
-                       (flags & float_flag_overflow ? FPUS_OE : 0) |
-                       (flags & float_flag_underflow ? FPUS_UE : 0) |
-                       (flags & float_flag_inexact ? FPUS_PE : 0) |
-                       (flags & float_flag_output_denormal ? FPUS_UE | FPUS_PE :
-                        0));
-    }
+    uint8_t flags = get_float_exception_flags(&env->sse_status);
+    /*
+     * The MXCSR denormal flag has opposite semantics to
+     * float_flag_input_denormal (the softfloat code sets that flag
+     * only when flushing input denormals to zero, but SSE sets it
+     * only when not flushing them to zero), so is not converted
+     * here.
+     */
+    env->mxcsr |= ((flags & float_flag_invalid ? FPUS_IE : 0) |
+                   (flags & float_flag_divbyzero ? FPUS_ZE : 0) |
+                   (flags & float_flag_overflow ? FPUS_OE : 0) |
+                   (flags & float_flag_underflow ? FPUS_UE : 0) |
+                   (flags & float_flag_inexact ? FPUS_PE : 0) |
+                   (flags & float_flag_output_denormal ? FPUS_UE | FPUS_PE :
+                    0));
 }
 
 void helper_update_mxcsr(CPUX86State *env)
target/i386/tcg/int_helper.c +1 -0
index 4f89436b53..87fa7280ee 100644
@@ -24,6 +24,7 @@
 #include "exec/helper-proto.h"
 #include "qapi/error.h"
 #include "qemu/guest-random.h"
+#include "helper-tcg.h"
 
 //#define DEBUG_MULDIV
 
target/i386/tcg/mem_helper.c +1 -0
index 21ca3e3e88..e5cd2de1bf 100644
@@ -25,6 +25,7 @@
 #include "qemu/int128.h"
 #include "qemu/atomic128.h"
 #include "tcg/tcg.h"
+#include "helper-tcg.h"
 
 void helper_cmpxchg8b_unlocked(CPUX86State *env, target_ulong a0)
 {
target/i386/tcg/misc_helper.c +1 -0
index ae259d9145..c99370e5e3 100644
@@ -24,6 +24,7 @@
 #include "exec/exec-all.h"
 #include "exec/cpu_ldst.h"
 #include "exec/address-spaces.h"
+#include "helper-tcg.h"
 
 void helper_outb(CPUX86State *env, uint32_t port, uint32_t data)
 {
target/i386/tcg/mpx_helper.c +1 -0
index fd966174b4..22423eedcd 100644
@@ -22,6 +22,7 @@
 #include "exec/helper-proto.h"
 #include "exec/cpu_ldst.h"
 #include "exec/exec-all.h"
+#include "helper-tcg.h"
 
 
 void helper_bndck(CPUX86State *env, uint32_t fail)
target/i386/tcg/seg_helper.c +1 -0
index 09b6554660..ed3e04a187 100644
@@ -25,6 +25,7 @@
 #include "exec/exec-all.h"
 #include "exec/cpu_ldst.h"
 #include "exec/log.h"
+#include "helper-tcg.h"
 
 //#define DEBUG_PCALL
 
target/i386/tcg/smm_helper.c +2 -0
index d20e8edfdf..62d027abd3 100644
@@ -22,6 +22,8 @@
 #include "cpu.h"
 #include "exec/helper-proto.h"
 #include "exec/log.h"
+#include "helper-tcg.h"
+
 
 /* SMM support */
 
target/i386/tcg/svm_helper.c +1 -0
index 38931586e5..097bb9b83d 100644
@@ -22,6 +22,7 @@
 #include "exec/helper-proto.h"
 #include "exec/exec-all.h"
 #include "exec/cpu_ldst.h"
+#include "helper-tcg.h"
 
 /* Secure Virtual Machine helpers */
 
target/i386/tcg/translate.c +1 -0
index 4c57307e42..5988ea0289 100644
@@ -28,6 +28,7 @@
 
 #include "exec/helper-proto.h"
 #include "exec/helper-gen.h"
+#include "helper-tcg.h"
 
 #include "trace-tcg.h"
 #include "exec/log.h"
Signature · 1 line
2.26.2
#8 lore raw

Re: [RFC v6 07/11] i386: move TCG cpu class initialization out of helper.c

Now that I understand what you are doing here, I have specific questions about the functions you are moving, below:

Quoted 1 line · Claudio Fontana

[...]

Quoted 11 lines
target/i386/cpu.c +2 -1
@@ -1495,7 +1497,8 @@ static inline uint64_t x86_cpu_xsave_components(X86CPU *cpu)
            cpu->env.features[FEAT_XSAVE_COMP_LO];
 }
 
-const char *get_register_name_32(unsigned int reg)
+/* Return name of 32-bit register, from a R_* constant */
+static const char *get_register_name_32(unsigned int reg)
 {
     if (reg >= CPU_NB_REGS32) {
         return NULL;

target/i386/cpu.c static void x86_cpu_set_pc(CPUState *cs, vaddr value) · line 7020

Quoted 9 lines
target/i386/cpu.c +0 -6
@@ -7012,13 +7015,6 @@ static void x86_cpu_set_pc(CPUState *cs, vaddr value)
     cpu->env.eip = value;
 }
 
-static void x86_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
-{
-    X86CPU *cpu = X86_CPU(cs);
-
-    cpu->env.eip = tb->pc - tb->cs_base;
-}

Question to be answered in the commit message: how can somebody be sure this code is not necessary for any other accelerators? The TranslationBlock* argument is a hint, but not a guarantee.

Maybe we should rename CPUClass.synchronize_from_tb to CPUClass.tcg_synchronize_from_tb? Maybe we should have a separate TCGCpuOperations struct to carry TCG-specific methods?

(The same questions above apply to the other methods below)

target/i386/cpu.c static void x86_cpu_common_class_init(ObjectClass *oc, void *data) · line 7257

Quoted 12 lines
target/i386/cpu.c +1 -3
-
 int x86_cpu_pending_interrupt(CPUState *cs, int interrupt_request)
 {
     X86CPU *cpu = X86_CPU(cs);
@@ -7252,17 +7248,18 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     cc->class_by_name = x86_cpu_class_by_name;
     cc->parse_features = x86_cpu_parse_featurestr;
     cc->has_work = x86_cpu_has_work;
+
 #ifdef CONFIG_TCG
-    cc->do_interrupt = x86_cpu_do_interrupt;
-    cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;

These two are in seg_helper.c, so I agree it makes sense to keep it in tcg_cpu_common_class_init().

I'd like to understand why they are TCG-specific, though. Are CPUClass.do_interrupt and CPUClass.cpu_exec_enter TCG-specific on all architectures, or only in x86?

Quoted 26 lines
target/i386/cpu.c +6 -3
-#endif
+    tcg_cpu_common_class_init(cc);
+#endif /* CONFIG_TCG */
+
     cc->dump_state = x86_cpu_dump_state;
     cc->set_pc = x86_cpu_set_pc;
-    cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
     cc->gdb_read_register = x86_cpu_gdb_read_register;
     cc->gdb_write_register = x86_cpu_gdb_write_register;
     cc->get_arch_id = x86_cpu_get_arch_id;
     cc->get_paging_enabled = x86_cpu_get_paging_enabled;
+
 #ifndef CONFIG_USER_ONLY
     cc->asidx_from_attrs = x86_asidx_from_attrs;
     cc->get_memory_mapping = x86_cpu_get_memory_mapping;
@@ -7273,7 +7270,8 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     cc->write_elf32_note = x86_cpu_write_elf32_note;
     cc->write_elf32_qemunote = x86_cpu_write_elf32_qemunote;
     cc->vmsd = &vmstate_x86_cpu;
-#endif
+#endif /* !CONFIG_USER_ONLY */
+
     cc->gdb_arch_name = x86_gdb_arch_name;
 #ifdef TARGET_X86_64
     cc->gdb_core_xml_file = "i386-64bit.xml";

target/i386/cpu.c static void x86_cpu_common_class_init(ObjectClass *oc, void *data) · line 7286

Quoted 6 lines
target/i386/cpu.c +0 -3
@@ -7281,15 +7279,6 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
 #else
     cc->gdb_core_xml_file = "i386-32bit.xml";
     cc->gdb_num_core_regs = 50;
-#endif
-#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
-    cc->debug_excp_handler = breakpoint_handler;

That's in bpt_helper.c, also TCG-specific. Makes sense to move it to tcg_cpu_common_class_init().

Is CPUClass.debug_excp_handler() TCG-specific in all architectures, or only in x86?

target/i386/cpu.c static void x86_cpu_common_class_init(ObjectClass *oc, void *data) · line 7289

Quoted 3 lines
target/i386/cpu.c +0 -3
-#endif
-    cc->cpu_exec_enter = x86_cpu_exec_enter;
-    cc->cpu_exec_exit = x86_cpu_exec_exit;

I have a question about those two functions below[1].

target/i386/cpu.c static void x86_cpu_common_class_init(ObjectClass *oc, void *data) · line 7291

Quoted 2 lines
target/i386/cpu.c +0 -2
-#ifdef CONFIG_TCG
-    cc->tcg_initialize = tcg_x86_init;

The name makes this is obviously TCG-specific, so it makes sense to move it to tcg_cpu_common_class_init().

target/i386/cpu.c static void x86_cpu_common_class_init(ObjectClass *oc, void *data) · line 7292

Quoted 1 line
target/i386/cpu.c +0 -1
-    cc->tlb_fill = x86_cpu_tlb_fill;

This is in excp_helper.c (TCG-specific), so it makes sense to move it to tcg_cpu_common_class_init().

Is CPUClass.tlb_fill TCG-specific in all architectures, or only in x86?

Quoted 3 lines
target/i386/cpu.c +0 -0
 #endif
     cc->disas_set_info = x86_disas_set_info;
 

[...]

Quoted 10 lines
target/i386/helper.c +0 -10
-/* Frob eflags into and out of the CPU temporary format.  */
-
-void x86_cpu_exec_enter(CPUState *cs)
-{
-    X86CPU *cpu = X86_CPU(cs);
-    CPUX86State *env = &cpu->env;
-
-    CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-    env->df = 1 - (2 * ((env->eflags >> 10) & 1));
-    CC_OP = CC_OP_EFLAGS;

target/i386/helper.c void do_cpu_sipi(X86CPU *cpu) · line 594

Quoted 10 lines
target/i386/helper.c +0 -10
-    env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-}
-
-void x86_cpu_exec_exit(CPUState *cs)
-{
-    X86CPU *cpu = X86_CPU(cs);
-    CPUX86State *env = &cpu->env;
-
-    env->eflags = cpu_compute_eflags(env);
-}

[1]

How exactly can we be 100% sure this is not used by other accelerators?

Quoted 4 lines

-
#ifndef CONFIG_USER_ONLY
uint8_t x86_ldub_phys(CPUState *cs, hwaddr addr)
{

[...]

Signature · 1 line
Eduardo
#9 lore raw

Re: [RFC v6 07/11] i386: move TCG cpu class initialization out of helper.c

Hi Eduardo,

Quoted 20 lines · Eduardo Habkost

Now that I understand what you are doing here, I have specific questions about the functions you are moving, below:

Quoted 1 line · Claudio Fontana

[...]

Quoted 14 lines
target/i386/cpu.c +2 -1
@@ -1495,7 +1497,8 @@ static inline uint64_t x86_cpu_xsave_components(X86CPU *cpu)
            cpu->env.features[FEAT_XSAVE_COMP_LO];
 }
 
-const char *get_register_name_32(unsigned int reg)
+/* Return name of 32-bit register, from a R_* constant */
+static const char *get_register_name_32(unsigned int reg)
 {
     if (reg >= CPU_NB_REGS32) {
         return NULL;
@@ -7012,13 +7015,6 @@ static void x86_cpu_set_pc(CPUState *cs, vaddr value)
     cpu->env.eip = value;
 }
 
Quoted 10 lines

target/i386/cpu.c static void x86_cpu_set_pc(CPUState *cs, vaddr value) · line 7020

Quoted 6 lines
target/i386/cpu.c +0 -6
-static void x86_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
-{
-    X86CPU *cpu = X86_CPU(cs);
-
-    cpu->env.eip = tb->pc - tb->cs_base;
-}

Question to be answered in the commit message: how can somebody be sure this code is not necessary for any other accelerators? The TranslationBlock* argument is a hint, but not a guarantee.

easiest is to just trace the calls, but there is a also helpful description of all these methods in hw/core/cpu.h.

$ mkid --include="C"
$ gid synchronize_from_tb

include/hw/core/cpu.h:110: * also implement the synchronize_from_tb hook.
include/hw/core/cpu.h:111: * @synchronize_from_tb: Callback for synchronizing state from a TCG
include/hw/core/cpu.h:194: void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb);
accel/tcg/cpu-exec.c:195: if (cc->synchronize_from_tb) {
accel/tcg/cpu-exec.c:196: cc->synchronize_from_tb(cpu, last_tb);
target/arm/cpu.c:2245: cc->synchronize_from_tb = arm_cpu_synchronize_from_tb;
target/avr/cpu.c:210: cc->synchronize_from_tb = avr_cpu_synchronize_from_tb;
target/hppa/cpu.c:146: cc->synchronize_from_tb = hppa_cpu_synchronize_from_tb;
target/microblaze/cpu.c:325: cc->synchronize_from_tb = mb_cpu_synchronize_from_tb;
target/mips/cpu.c:241: cc->synchronize_from_tb = mips_cpu_synchronize_from_tb;
target/riscv/cpu.c:546: cc->synchronize_from_tb = riscv_cpu_synchronize_from_tb;
target/rx/cpu.c:192: cc->synchronize_from_tb = rx_cpu_synchronize_from_tb;
target/sh4/cpu.c:225: cc->synchronize_from_tb = superh_cpu_synchronize_from_tb;
target/sparc/cpu.c:871: cc->synchronize_from_tb = sparc_cpu_synchronize_from_tb;
target/tricore/cpu.c:165: cc->synchronize_from_tb = tricore_cpu_synchronize_from_tb;
target/i386/tcg/cpu.c:129: cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;

Quoted 2 lines

Maybe we should rename CPUClass.synchronize_from_tb to CPUClass.tcg_synchronize_from_tb? Maybe we should have a

possibly, yes.

Quoted 1 line

separate TCGCpuOperations struct to carry TCG-specific methods?

interesting, will think about it.

Quoted 20 lines

(The same questions above apply to the other methods below)

target/i386/cpu.c static void x86_cpu_common_class_init(ObjectClass *oc, void *data) · line 7257

Quoted 12 lines
target/i386/cpu.c +1 -3
-
 int x86_cpu_pending_interrupt(CPUState *cs, int interrupt_request)
 {
     X86CPU *cpu = X86_CPU(cs);
@@ -7252,17 +7248,18 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     cc->class_by_name = x86_cpu_class_by_name;
     cc->parse_features = x86_cpu_parse_featurestr;
     cc->has_work = x86_cpu_has_work;
+
 #ifdef CONFIG_TCG
-    cc->do_interrupt = x86_cpu_do_interrupt;
-    cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;

These two are in seg_helper.c, so I agree it makes sense to keep it in tcg_cpu_common_class_init().

Quoted 3 lines

I'd like to understand why they are TCG-specific, though. Are CPUClass.do_interrupt and CPUClass.cpu_exec_enter TCG-specific on all architectures, or only in x86?

cpu_exec_enter: yes, tcg only on all archs.

Traces as above, it is only called by

accel/tcg/cpu-exec.c

cc->do_interrupt() is very interesting, it _should_ be the same story, the use of cc->do_interrupt() is normally relegated to accel/tcg/cpu-exec.c, or to the various implementations of cpu_exec_interrupt (also tcg-specific).

_BUT_ there is an exception in arm64 where it seems to be (strangely) used for kvm64:

So in this case the arm kvm64 code is the outlier. There are two calls, one introduced in 2015 and one in 2020:

commit e24fd076a59604c4ba3c05fe9d19ea6fc5320a12

Author: Dongjiu Geng <[email protected]>
Date:   Tue May 12 11:06:08 2020 +0800

target-arm: kvm64: handle SIGBUS signal from kernel or KVM

commit 34c45d53026d9c135415d034a8bc30c1a30acf1c

Author: Alex Bennée <[email protected]>
Date:   Thu Dec 17 13:37:15 2015 +0000

target-arm: kvm - re-inject guest debug exceptions

Maybe Alex and Dongjiu Geng (or maybe Peter?) can shed some light on whether this is intentional, or an oversight?

It is the one and only use of cc->do_interrupt outside of TCG. So strange.

Quoted 52 lines
Quoted 27 lines
target/i386/cpu.c +6 -3
-#endif
+    tcg_cpu_common_class_init(cc);
+#endif /* CONFIG_TCG */
+
     cc->dump_state = x86_cpu_dump_state;
     cc->set_pc = x86_cpu_set_pc;
-    cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
     cc->gdb_read_register = x86_cpu_gdb_read_register;
     cc->gdb_write_register = x86_cpu_gdb_write_register;
     cc->get_arch_id = x86_cpu_get_arch_id;
     cc->get_paging_enabled = x86_cpu_get_paging_enabled;
+
 #ifndef CONFIG_USER_ONLY
     cc->asidx_from_attrs = x86_asidx_from_attrs;
     cc->get_memory_mapping = x86_cpu_get_memory_mapping;
@@ -7273,7 +7270,8 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     cc->write_elf32_note = x86_cpu_write_elf32_note;
     cc->write_elf32_qemunote = x86_cpu_write_elf32_qemunote;
     cc->vmsd = &vmstate_x86_cpu;
-#endif
+#endif /* !CONFIG_USER_ONLY */
+
     cc->gdb_arch_name = x86_gdb_arch_name;
 #ifdef TARGET_X86_64
     cc->gdb_core_xml_file = "i386-64bit.xml";

target/i386/cpu.c static void x86_cpu_common_class_init(ObjectClass *oc, void *data) · line 7286

Quoted 6 lines
target/i386/cpu.c +0 -3
@@ -7281,15 +7279,6 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
 #else
     cc->gdb_core_xml_file = "i386-32bit.xml";
     cc->gdb_num_core_regs = 50;
-#endif
-#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
-    cc->debug_excp_handler = breakpoint_handler;

That's in bpt_helper.c, also TCG-specific. Makes sense to move it to tcg_cpu_common_class_init().

Is CPUClass.debug_excp_handler() TCG-specific in all architectures, or only in x86?

target/i386/cpu.c static void x86_cpu_common_class_init(ObjectClass *oc, void *data) · line 7289

Quoted 3 lines
target/i386/cpu.c +0 -3
-#endif
-    cc->cpu_exec_enter = x86_cpu_exec_enter;
-    cc->cpu_exec_exit = x86_cpu_exec_exit;

I have a question about those two functions below[1].

target/i386/cpu.c static void x86_cpu_common_class_init(ObjectClass *oc, void *data) · line 7291

Quoted 2 lines
target/i386/cpu.c +0 -2
-#ifdef CONFIG_TCG
-    cc->tcg_initialize = tcg_x86_init;

The name makes this is obviously TCG-specific, so it makes sense to move it to tcg_cpu_common_class_init().

Quoted 7 lines

target/i386/cpu.c static void x86_cpu_common_class_init(ObjectClass *oc, void *data) · line 7292

Quoted 1 line
target/i386/cpu.c +0 -1
-    cc->tlb_fill = x86_cpu_tlb_fill;

This is in excp_helper.c (TCG-specific), so it makes sense to move it to tcg_cpu_common_class_init().

Is CPUClass.tlb_fill TCG-specific in all architectures, or only in x86?

TCG-specific on all, real CPU has its own real TLB.

Only accel/tcg/ uses the code.

Quoted 28 lines
Quoted 4 lines
target/i386/cpu.c +0 -0
 #endif
     cc->disas_set_info = x86_disas_set_info;
 

[...]

Quoted 10 lines
target/i386/helper.c +0 -10
-/* Frob eflags into and out of the CPU temporary format.  */
-
-void x86_cpu_exec_enter(CPUState *cs)
-{
-    X86CPU *cpu = X86_CPU(cs);
-    CPUX86State *env = &cpu->env;
-
-    CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-    env->df = 1 - (2 * ((env->eflags >> 10) & 1));
-    CC_OP = CC_OP_EFLAGS;

target/i386/helper.c void do_cpu_sipi(X86CPU *cpu) · line 594

Quoted 10 lines
target/i386/helper.c +0 -10
-    env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-}
-
-void x86_cpu_exec_exit(CPUState *cs)
-{
-    X86CPU *cpu = X86_CPU(cs);
-    CPUX86State *env = &cpu->env;
-
-    env->eflags = cpu_compute_eflags(env);
-}

[1]

Quoted 2 lines

How exactly can we be 100% sure this is not used by other accelerators?

The only calls to these methods are from accel/tcg/cpu-exec.c .

Quoted 7 lines
Quoted 5 lines

-
#ifndef CONFIG_USER_ONLY
uint8_t x86_ldub_phys(CPUState *cs, hwaddr addr)
{

[...]

I think that this exercise has been useful, and btw I am really interested about the possible comments from Alex or Geng DongJiu on the extraordinary use of cc->do_interrupt for kvm64 on AArch64,

Thanks,

Ciao,

Claudio

#10 lore raw

Re: [RFC v6 07/11] i386: move TCG cpu class initialization out of helper.c

Quoted 1 line · Claudio Fontana

On 11/27/20 8:04 PM, Eduardo Habkost wrote:

[...]

Quoted 9 lines
Quoted 2 lines

Maybe we should rename CPUClass.synchronize_from_tb to CPUClass.tcg_synchronize_from_tb? Maybe we should have a

possibly, yes.

Quoted 1 line

separate TCGCpuOperations struct to carry TCG-specific methods?

interesting, will think about it.

I'm working on it at:
https://gitlab.com/ehabkost/qemu/-/commits/work/tcg-cpu-ops

Feel free to reuse it, if you want to do it before your series. Otherwise, I can rebase it after your series is merged.

I didn't touch do_interrupt(), because of the aarch64 weirdness.

Signature · 1 line
Eduardo
#11 lore raw

Re: [RFC v6 07/11] i386: move TCG cpu class initialization out of helper.c

Quoted 13 lines · Eduardo Habkost
Quoted 1 line · Claudio Fontana

On 11/27/20 8:04 PM, Eduardo Habkost wrote:

[...]

Quoted 9 lines
Quoted 2 lines

Maybe we should rename CPUClass.synchronize_from_tb to CPUClass.tcg_synchronize_from_tb? Maybe we should have a

possibly, yes.

Quoted 1 line

separate TCGCpuOperations struct to carry TCG-specific methods?

interesting, will think about it.

Quoted 8 lines

I'm working on it at:
https://gitlab.com/ehabkost/qemu/-/commits/work/tcg-cpu-ops

Feel free to reuse it, if you want to do it before your series. Otherwise, I can rebase it after your series is merged.

I didn't touch do_interrupt(), because of the aarch64 weirdness.

Hi,

yes it makes sense to separate more clearly I think what is tcg only among those operations,

it is a bit tangent to my series in the sense that those methods need to be set one way or another, either in cc-> or in cc->tcg_ops,

but yes, we could put those changes before or after the series, and I think they make sense.

Ciao,

Claudio

#12 lore raw

RFC v6 8/11 accel: extend AccelState and AccelClass to user-mode

In reply to Claudio Fontana
---
 MAINTAINERS                        |  2 +-
 accel/accel-common.c               | 50 ++++++++++++++++++++++++++++++
 accel/{accel.c => accel-softmmu.c} | 27 ++--------------
 accel/accel-user.c                 | 24 ++++++++++++++
 accel/meson.build                  |  4 ++-
 accel/qtest/qtest.c                |  2 +-
 accel/tcg/meson.build              |  2 +-
 accel/tcg/tcg-all.c                |  7 ++++-
 accel/xen/xen-all.c                |  2 +-
 bsd-user/main.c                    |  7 +++--
 include/hw/boards.h                |  2 +-
 include/{sysemu => qemu}/accel.h   | 14 +++++----
 include/sysemu/hvf.h               |  2 +-
 include/sysemu/kvm.h               |  2 +-
 include/sysemu/kvm_int.h           |  2 +-
 linux-user/main.c                  |  7 +++--
 softmmu/memory.c                   |  2 +-
 softmmu/qtest.c                    |  2 +-
 softmmu/vl.c                       |  2 +-
 target/i386/hax/hax-all.c          |  2 +-
 target/i386/hvf/hvf-i386.h         |  2 +-
 target/i386/hvf/hvf.c              |  2 +-
 target/i386/hvf/x86_task.c         |  2 +-
 target/i386/whpx/whpx-all.c        |  2 +-
 24 files changed, 119 insertions(+), 53 deletions(-)
 create mode 100644 accel/accel-common.c
 rename accel/{accel.c => accel-softmmu.c} (75%)
 create mode 100644 accel/accel-user.c
 rename include/{sysemu => qemu}/accel.h (95%)
MAINTAINERS +1 -1
index e892dd2220..d7c212843c 100644
@@ -433,7 +433,7 @@ Overall
 M: Richard Henderson <[email protected]>
 R: Paolo Bonzini <[email protected]>
 S: Maintained
-F: include/sysemu/accel.h
+F: include/qemu/accel.h
 F: accel/accel.c
 F: accel/Makefile.objs
 F: accel/stubs/Makefile.objs
accel/accel-common.c new file +50 -0

50 lines not on this page · raw message

accel/accel-softmmu.c renamed from accel/accel.c +2 -25
similarity index 75%
rename from accel/accel.c
rename to accel/accel-softmmu.c
index cb555e3b06..f89da8f9d1 100644
@@ -1,5 +1,5 @@
 /*
- * QEMU System Emulator, accelerator interfaces
+ * QEMU accel class, system emulation components
  *
  * Copyright (c) 2003-2008 Fabrice Bellard
  * Copyright (c) 2014 Red Hat Inc.
@@ -24,28 +24,12 @@
  */
 
 #include "qemu/osdep.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "hw/boards.h"
 #include "sysemu/arch_init.h"
 #include "sysemu/sysemu.h"
 #include "qom/object.h"
 
-static const TypeInfo accel_type = {
-    .name = TYPE_ACCEL,
-    .parent = TYPE_OBJECT,
-    .class_size = sizeof(AccelClass),
-    .instance_size = sizeof(AccelState),
-};
-
-/* Lookup AccelClass from opt_name. Returns NULL if not found */
-AccelClass *accel_find(const char *opt_name)
-{
-    char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name);
-    AccelClass *ac = ACCEL_CLASS(object_class_by_name(class_name));
-    g_free(class_name);
-    return ac;
-}
-
 int accel_init_machine(AccelState *accel, MachineState *ms)
 {
     AccelClass *acc = ACCEL_GET_CLASS(accel);
@@ -76,10 +60,3 @@ void accel_setup_post(MachineState *ms)
         acc->setup_post(ms, accel);
     }
 }
-
-static void register_accel_types(void)
-{
-    type_register_static(&accel_type);
-}
-
-type_init(register_accel_types);
accel/accel-user.c new file +24 -0
new file mode 100644
index 0000000000..26bdda6236
@@ -0,0 +1,24 @@
+/*
+ * QEMU accel class, user-mode components
+ *
+ * Copyright 2020 SUSE LLC
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/accel.h"
+
+AccelState *current_accel(void)
+{
+    static AccelState *accel;
+
+    if (!accel) {
+        AccelClass *ac = accel_find("tcg");
+
+        g_assert(ac != NULL);
+        accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac)));
+    }
+    return accel;
+}
accel/meson.build +3 -1
index b26cca227a..b44ba30c86 100644
@@ -1,4 +1,6 @@
-softmmu_ss.add(files('accel.c'))
+specific_ss.add(files('accel-common.c'))
+softmmu_ss.add(files('accel-softmmu.c'))
+user_ss.add(files('accel-user.c'))
 
 subdir('qtest')
 subdir('kvm')
accel/qtest/qtest.c +1 -1
index b282cea5cf..b4e731cb2b 100644
@@ -17,7 +17,7 @@
 #include "qemu/module.h"
 #include "qemu/option.h"
 #include "qemu/config-file.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/qtest.h"
 #include "sysemu/cpus.h"
 #include "sysemu/cpu-timers.h"
accel/tcg/meson.build +1 -1
index f39aab0a0c..424d9bb1fc 100644
@@ -1,5 +1,6 @@
 tcg_ss = ss.source_set()
 tcg_ss.add(files(
+  'tcg-all.c',
   'cpu-exec-common.c',
   'cpu-exec.c',
   'tcg-runtime-gvec.c',
@@ -13,7 +14,6 @@ tcg_ss.add(when: 'CONFIG_PLUGIN', if_true: [files('plugin-gen.c'), libdl])
 specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss)
 
 specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files(
-  'tcg-all.c',
   'cputlb.c',
   'tcg-cpus.c',
   'tcg-cpus-mttcg.c',
accel/tcg/tcg-all.c +6 -1
index 1ac0b76515..dcbc6970da 100644
@@ -30,9 +30,12 @@
 #include "tcg/tcg.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
-#include "hw/boards.h"
+#include "qemu/accel.h"
 #include "qapi/qapi-builtin-visit.h"
+
+#ifndef CONFIG_USER_ONLY
 #include "tcg-cpus.h"
+#endif /* CONFIG_USER_ONLY */
 
 struct TCGState {
     AccelState parent_obj;
@@ -110,6 +113,7 @@ static int tcg_init(MachineState *ms)
      */
     tcg_region_init();
 
+#ifndef CONFIG_USER_ONLY
     if (mttcg_enabled) {
         cpus_register_accel(&tcg_cpus_mttcg);
     } else if (icount_enabled()) {
@@ -117,6 +121,7 @@ static int tcg_init(MachineState *ms)
     } else {
         cpus_register_accel(&tcg_cpus_rr);
     }
+#endif /* CONFIG_USER_ONLY */
     return 0;
 }
 
accel/xen/xen-all.c +1 -1
index 878a4089d9..594aaf6b49 100644
@@ -15,7 +15,7 @@
 #include "hw/xen/xen-legacy-backend.h"
 #include "hw/xen/xen_pt.h"
 #include "chardev/char.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/cpus.h"
 #include "sysemu/xen.h"
 #include "sysemu/runstate.h"
bsd-user/main.c +5 -2
index 0a918e8f74..ec1f9d80a4 100644
@@ -20,6 +20,7 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "qemu/units.h"
+#include "qemu/accel.h"
 #include "sysemu/tcg.h"
 #include "qemu-version.h"
 #include <machine/trap.h>
@@ -908,8 +909,11 @@ int main(int argc, char **argv)
     }
 
     /* init tcg before creating CPUs and to get qemu_host_page_size */
-    tcg_exec_init(0);
+    {
+        AccelClass *ac = ACCEL_GET_CLASS(current_accel());
 
+        ac->init_machine(NULL);
+    }
     cpu_type = parse_cpu_option(cpu_model);
     cpu = cpu_create(cpu_type);
     env = cpu->env_ptr;
@@ -988,7 +992,6 @@ int main(int argc, char **argv)
        generating the prologue until now so that the prologue can take
        the real value of GUEST_BASE into account.  */
     tcg_prologue_init(tcg_ctx);
-    tcg_region_init();
 
     /* build Task State */
     memset(ts, 0, sizeof(TaskState));
include/hw/boards.h +1 -1
index a49e3a6b44..b754504afe 100644
@@ -6,7 +6,7 @@
 #include "exec/memory.h"
 #include "sysemu/hostmem.h"
 #include "sysemu/blockdev.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "qapi/qapi-types-machine.h"
 #include "qemu/module.h"
 #include "qom/object.h"
include/qemu/accel.h renamed from include/sysemu/accel.h +8 -6
similarity index 95%
rename from include/sysemu/accel.h
rename to include/qemu/accel.h
index e08b8ab8fa..fac4a18703 100644
@@ -20,8 +20,8 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#ifndef HW_ACCEL_H
-#define HW_ACCEL_H
+#ifndef QEMU_ACCEL_H
+#define QEMU_ACCEL_H
 
 #include "qom/object.h"
 #include "exec/hwaddr.h"
@@ -37,8 +37,8 @@ typedef struct AccelClass {
     /*< public >*/
 
     const char *name;
-#ifndef CONFIG_USER_ONLY
     int (*init_machine)(MachineState *ms);
+#ifndef CONFIG_USER_ONLY
     void (*setup_post)(MachineState *ms, AccelState *accel);
     bool (*has_memory)(MachineState *ms, AddressSpace *as,
                        hwaddr start_addr, hwaddr size);
@@ -67,11 +67,13 @@ typedef struct AccelClass {
     OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL)
 
 AccelClass *accel_find(const char *opt_name);
+AccelState *current_accel(void);
+
+#ifndef CONFIG_USER_ONLY
 int accel_init_machine(AccelState *accel, MachineState *ms);
 
 /* Called just before os_setup_post (ie just before drop OS privs) */
 void accel_setup_post(MachineState *ms);
+#endif /* !CONFIG_USER_ONLY */
 
-AccelState *current_accel(void);
-
-#endif
+#endif /* QEMU_ACCEL_H */
include/sysemu/hvf.h +1 -1
index f893768df9..c98636bc81 100644
@@ -13,7 +13,7 @@
 #ifndef HVF_H
 #define HVF_H
 
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "qom/object.h"
 
 #ifdef CONFIG_HVF
include/sysemu/kvm.h +1 -1
index bb5d5cf497..739682f3c3 100644
@@ -17,7 +17,7 @@
 #include "qemu/queue.h"
 #include "hw/core/cpu.h"
 #include "exec/memattrs.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "qom/object.h"
 
 #ifdef NEED_CPU_H
include/sysemu/kvm_int.h +1 -1
index 65740806da..ccb8869f01 100644
@@ -10,7 +10,7 @@
 #define QEMU_KVM_INT_H
 
 #include "exec/memory.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/kvm.h"
 
 typedef struct KVMSlot
linux-user/main.c +5 -2
index 24d1eb73ad..1825d2b835 100644
@@ -20,6 +20,7 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "qemu/units.h"
+#include "qemu/accel.h"
 #include "sysemu/tcg.h"
 #include "qemu-version.h"
 #include <sys/syscall.h>
@@ -703,8 +704,11 @@ int main(int argc, char **argv, char **envp)
     cpu_type = parse_cpu_option(cpu_model);
 
     /* init tcg before creating CPUs and to get qemu_host_page_size */
-    tcg_exec_init(0);
+    {
+        AccelClass *ac = ACCEL_GET_CLASS(current_accel());
 
+        ac->init_machine(NULL);
+    }
     cpu = cpu_create(cpu_type);
     env = cpu->env_ptr;
     cpu_reset(cpu);
@@ -846,7 +850,6 @@ int main(int argc, char **argv, char **envp)
        generating the prologue until now so that the prologue can take
        the real value of GUEST_BASE into account.  */
     tcg_prologue_init(tcg_ctx);
-    tcg_region_init();
 
     target_cpu_copy_regs(env, regs);
 
softmmu/memory.c +1 -1
index aa393f1bb0..92c8b4fc1f 100644
@@ -32,7 +32,7 @@
 #include "sysemu/kvm.h"
 #include "sysemu/runstate.h"
 #include "sysemu/tcg.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "hw/boards.h"
 #include "migration/vmstate.h"
 
softmmu/qtest.c +1 -1
index 7965dc9a16..130c366615 100644
@@ -20,7 +20,7 @@
 #include "exec/ioport.h"
 #include "exec/memory.h"
 #include "hw/irq.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/cpu-timers.h"
 #include "qemu/config-file.h"
 #include "qemu/option.h"
softmmu/vl.c +1 -1
index e6e0ad5a92..bc20c526d2 100644
@@ -40,7 +40,7 @@
 
 #include "qemu/error-report.h"
 #include "qemu/sockets.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "hw/usb.h"
 #include "hw/isa/isa.h"
 #include "hw/scsi/scsi.h"
target/i386/hax/hax-all.c +1 -1
index fecfe8cd6e..d7f4bb44a7 100644
@@ -28,7 +28,7 @@
 #include "exec/address-spaces.h"
 
 #include "qemu-common.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/reset.h"
 #include "sysemu/runstate.h"
 #include "hw/boards.h"
target/i386/hvf/hvf-i386.h +1 -1
index e0edffd077..50b914fd67 100644
@@ -16,7 +16,7 @@
 #ifndef HVF_I386_H
 #define HVF_I386_H
 
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/hvf.h"
 #include "cpu.h"
 #include "x86.h"
target/i386/hvf/hvf.c +1 -1
index ed9356565c..ffc9efa40f 100644
@@ -69,7 +69,7 @@
 #include "exec/address-spaces.h"
 #include "hw/i386/apic_internal.h"
 #include "qemu/main-loop.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "target/i386/cpu.h"
 
 #include "hvf-cpus.h"
target/i386/hvf/x86_task.c +1 -1
index 6f04478b3a..d66dfd7669 100644
@@ -28,7 +28,7 @@
 
 #include "hw/i386/apic_internal.h"
 #include "qemu/main-loop.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "target/i386/cpu.h"
 
 // TODO: taskswitch handling
target/i386/whpx/whpx-all.c +1 -1
index f4f3e33eac..ee6b606194 100644
@@ -13,7 +13,7 @@
 #include "exec/address-spaces.h"
 #include "exec/ioport.h"
 #include "qemu-common.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/whpx.h"
 #include "sysemu/cpus.h"
 #include "sysemu/runstate.h"
Signature · 1 line
2.26.2
#13 lore raw

Re: [RFC v6 08/11] accel: extend AccelState and AccelClass to user-mode

Hi Richard,

happy new year,

this change of mine breaks with --enable-debug, after your changes related to "splitrw" in tcg/, I am a bit at a loss at what could be going wrong.. any hints?

I am getting assertion failures with --enable-debug in make check-tcg,

in particular in tcg/tcg.c:768

#ifdef CONFIG_DEBUG_TCG
const void *tcg_splitwx_to_rx(void *rw)

{
    /* Pass NULL pointers unchanged. */
    if (rw) {
        g_assert(in_code_gen_buffer(rw)); /* <=== HERE */
        rw += tcg_splitwx_diff;
    }
    return rw;
}

any hints?

Thanks,

Claudio

Quoted 545 lines · Claudio Fontana
---
 MAINTAINERS                        |  2 +-
 accel/accel-common.c               | 50 ++++++++++++++++++++++++++++++
 accel/{accel.c => accel-softmmu.c} | 27 ++--------------
 accel/accel-user.c                 | 24 ++++++++++++++
 accel/meson.build                  |  4 ++-
 accel/qtest/qtest.c                |  2 +-
 accel/tcg/meson.build              |  2 +-
 accel/tcg/tcg-all.c                |  7 ++++-
 accel/xen/xen-all.c                |  2 +-
 bsd-user/main.c                    |  7 +++--
 include/hw/boards.h                |  2 +-
 include/{sysemu => qemu}/accel.h   | 14 +++++----
 include/sysemu/hvf.h               |  2 +-
 include/sysemu/kvm.h               |  2 +-
 include/sysemu/kvm_int.h           |  2 +-
 linux-user/main.c                  |  7 +++--
 softmmu/memory.c                   |  2 +-
 softmmu/qtest.c                    |  2 +-
 softmmu/vl.c                       |  2 +-
 target/i386/hax/hax-all.c          |  2 +-
 target/i386/hvf/hvf-i386.h         |  2 +-
 target/i386/hvf/hvf.c              |  2 +-
 target/i386/hvf/x86_task.c         |  2 +-
 target/i386/whpx/whpx-all.c        |  2 +-
 24 files changed, 119 insertions(+), 53 deletions(-)
 create mode 100644 accel/accel-common.c
 rename accel/{accel.c => accel-softmmu.c} (75%)
 create mode 100644 accel/accel-user.c
 rename include/{sysemu => qemu}/accel.h (95%)
MAINTAINERS +1 -1
index e892dd2220..d7c212843c 100644
@@ -433,7 +433,7 @@ Overall
 M: Richard Henderson <[email protected]>
 R: Paolo Bonzini <[email protected]>
 S: Maintained
-F: include/sysemu/accel.h
+F: include/qemu/accel.h
 F: accel/accel.c
 F: accel/Makefile.objs
 F: accel/stubs/Makefile.objs
accel/accel-common.c new file +50 -0
new file mode 100644
index 0000000000..ddec8cb5ae
@@ -0,0 +1,50 @@
+/*
+ * QEMU accel class, components common to system emulation and user mode
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2014 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/accel.h"
+
+static const TypeInfo accel_type = {
+    .name = TYPE_ACCEL,
+    .parent = TYPE_OBJECT,
+    .class_size = sizeof(AccelClass),
+    .instance_size = sizeof(AccelState),
+};
+
+/* Lookup AccelClass from opt_name. Returns NULL if not found */
+AccelClass *accel_find(const char *opt_name)
+{
+    char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name);
+    AccelClass *ac = ACCEL_CLASS(object_class_by_name(class_name));
+    g_free(class_name);
+    return ac;
+}
+
+static void register_accel_types(void)
+{
+    type_register_static(&accel_type);
+}
+
+type_init(register_accel_types);
accel/accel-softmmu.c renamed from accel/accel.c +2 -25
similarity index 75%
rename from accel/accel.c
rename to accel/accel-softmmu.c
index cb555e3b06..f89da8f9d1 100644
@@ -1,5 +1,5 @@
 /*
- * QEMU System Emulator, accelerator interfaces
+ * QEMU accel class, system emulation components
  *
  * Copyright (c) 2003-2008 Fabrice Bellard
  * Copyright (c) 2014 Red Hat Inc.
@@ -24,28 +24,12 @@
  */
 
 #include "qemu/osdep.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "hw/boards.h"
 #include "sysemu/arch_init.h"
 #include "sysemu/sysemu.h"
 #include "qom/object.h"
 
-static const TypeInfo accel_type = {
-    .name = TYPE_ACCEL,
-    .parent = TYPE_OBJECT,
-    .class_size = sizeof(AccelClass),
-    .instance_size = sizeof(AccelState),
-};
-
-/* Lookup AccelClass from opt_name. Returns NULL if not found */
-AccelClass *accel_find(const char *opt_name)
-{
-    char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name);
-    AccelClass *ac = ACCEL_CLASS(object_class_by_name(class_name));
-    g_free(class_name);
-    return ac;
-}
-
 int accel_init_machine(AccelState *accel, MachineState *ms)
 {
     AccelClass *acc = ACCEL_GET_CLASS(accel);
@@ -76,10 +60,3 @@ void accel_setup_post(MachineState *ms)
         acc->setup_post(ms, accel);
     }
 }
-
-static void register_accel_types(void)
-{
-    type_register_static(&accel_type);
-}
-
-type_init(register_accel_types);
accel/accel-user.c new file +24 -0
new file mode 100644
index 0000000000..26bdda6236
@@ -0,0 +1,24 @@
+/*
+ * QEMU accel class, user-mode components
+ *
+ * Copyright 2020 SUSE LLC
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/accel.h"
+
+AccelState *current_accel(void)
+{
+    static AccelState *accel;
+
+    if (!accel) {
+        AccelClass *ac = accel_find("tcg");
+
+        g_assert(ac != NULL);
+        accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac)));
+    }
+    return accel;
+}
accel/meson.build +3 -1
index b26cca227a..b44ba30c86 100644
@@ -1,4 +1,6 @@
-softmmu_ss.add(files('accel.c'))
+specific_ss.add(files('accel-common.c'))
+softmmu_ss.add(files('accel-softmmu.c'))
+user_ss.add(files('accel-user.c'))
 
 subdir('qtest')
 subdir('kvm')
accel/qtest/qtest.c +1 -1
index b282cea5cf..b4e731cb2b 100644
@@ -17,7 +17,7 @@
 #include "qemu/module.h"
 #include "qemu/option.h"
 #include "qemu/config-file.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/qtest.h"
 #include "sysemu/cpus.h"
 #include "sysemu/cpu-timers.h"
accel/tcg/meson.build +1 -1
index f39aab0a0c..424d9bb1fc 100644
@@ -1,5 +1,6 @@
 tcg_ss = ss.source_set()
 tcg_ss.add(files(
+  'tcg-all.c',
   'cpu-exec-common.c',
   'cpu-exec.c',
   'tcg-runtime-gvec.c',
@@ -13,7 +14,6 @@ tcg_ss.add(when: 'CONFIG_PLUGIN', if_true: [files('plugin-gen.c'), libdl])
 specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss)
 
 specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files(
-  'tcg-all.c',
   'cputlb.c',
   'tcg-cpus.c',
   'tcg-cpus-mttcg.c',
accel/tcg/tcg-all.c +6 -1
index 1ac0b76515..dcbc6970da 100644
@@ -30,9 +30,12 @@
 #include "tcg/tcg.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
-#include "hw/boards.h"
+#include "qemu/accel.h"
 #include "qapi/qapi-builtin-visit.h"
+
+#ifndef CONFIG_USER_ONLY
 #include "tcg-cpus.h"
+#endif /* CONFIG_USER_ONLY */
 
 struct TCGState {
     AccelState parent_obj;
@@ -110,6 +113,7 @@ static int tcg_init(MachineState *ms)
      */
     tcg_region_init();
 
+#ifndef CONFIG_USER_ONLY
     if (mttcg_enabled) {
         cpus_register_accel(&tcg_cpus_mttcg);
     } else if (icount_enabled()) {
@@ -117,6 +121,7 @@ static int tcg_init(MachineState *ms)
     } else {
         cpus_register_accel(&tcg_cpus_rr);
     }
+#endif /* CONFIG_USER_ONLY */
     return 0;
 }
 
accel/xen/xen-all.c +1 -1
index 878a4089d9..594aaf6b49 100644
@@ -15,7 +15,7 @@
 #include "hw/xen/xen-legacy-backend.h"
 #include "hw/xen/xen_pt.h"
 #include "chardev/char.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/cpus.h"
 #include "sysemu/xen.h"
 #include "sysemu/runstate.h"
bsd-user/main.c +5 -2
index 0a918e8f74..ec1f9d80a4 100644
@@ -20,6 +20,7 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "qemu/units.h"
+#include "qemu/accel.h"
 #include "sysemu/tcg.h"
 #include "qemu-version.h"
 #include <machine/trap.h>
@@ -908,8 +909,11 @@ int main(int argc, char **argv)
     }
 
     /* init tcg before creating CPUs and to get qemu_host_page_size */
-    tcg_exec_init(0);
+    {
+        AccelClass *ac = ACCEL_GET_CLASS(current_accel());
 
+        ac->init_machine(NULL);
+    }
     cpu_type = parse_cpu_option(cpu_model);
     cpu = cpu_create(cpu_type);
     env = cpu->env_ptr;
@@ -988,7 +992,6 @@ int main(int argc, char **argv)
        generating the prologue until now so that the prologue can take
        the real value of GUEST_BASE into account.  */
     tcg_prologue_init(tcg_ctx);
-    tcg_region_init();
 
     /* build Task State */
     memset(ts, 0, sizeof(TaskState));
include/hw/boards.h +1 -1
index a49e3a6b44..b754504afe 100644
@@ -6,7 +6,7 @@
 #include "exec/memory.h"
 #include "sysemu/hostmem.h"
 #include "sysemu/blockdev.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "qapi/qapi-types-machine.h"
 #include "qemu/module.h"
 #include "qom/object.h"
include/qemu/accel.h renamed from include/sysemu/accel.h +8 -6
similarity index 95%
rename from include/sysemu/accel.h
rename to include/qemu/accel.h
index e08b8ab8fa..fac4a18703 100644
@@ -20,8 +20,8 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#ifndef HW_ACCEL_H
-#define HW_ACCEL_H
+#ifndef QEMU_ACCEL_H
+#define QEMU_ACCEL_H
 
 #include "qom/object.h"
 #include "exec/hwaddr.h"
@@ -37,8 +37,8 @@ typedef struct AccelClass {
     /*< public >*/
 
     const char *name;
-#ifndef CONFIG_USER_ONLY
     int (*init_machine)(MachineState *ms);
+#ifndef CONFIG_USER_ONLY
     void (*setup_post)(MachineState *ms, AccelState *accel);
     bool (*has_memory)(MachineState *ms, AddressSpace *as,
                        hwaddr start_addr, hwaddr size);
@@ -67,11 +67,13 @@ typedef struct AccelClass {
     OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL)
 
 AccelClass *accel_find(const char *opt_name);
+AccelState *current_accel(void);
+
+#ifndef CONFIG_USER_ONLY
 int accel_init_machine(AccelState *accel, MachineState *ms);
 
 /* Called just before os_setup_post (ie just before drop OS privs) */
 void accel_setup_post(MachineState *ms);
+#endif /* !CONFIG_USER_ONLY */
 
-AccelState *current_accel(void);
-
-#endif
+#endif /* QEMU_ACCEL_H */
include/sysemu/hvf.h +1 -1
index f893768df9..c98636bc81 100644
@@ -13,7 +13,7 @@
 #ifndef HVF_H
 #define HVF_H
 
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "qom/object.h"
 
 #ifdef CONFIG_HVF
include/sysemu/kvm.h +1 -1
index bb5d5cf497..739682f3c3 100644
@@ -17,7 +17,7 @@
 #include "qemu/queue.h"
 #include "hw/core/cpu.h"
 #include "exec/memattrs.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "qom/object.h"
 
 #ifdef NEED_CPU_H
include/sysemu/kvm_int.h +1 -1
index 65740806da..ccb8869f01 100644
@@ -10,7 +10,7 @@
 #define QEMU_KVM_INT_H
 
 #include "exec/memory.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/kvm.h"
 
 typedef struct KVMSlot
linux-user/main.c +5 -2
index 24d1eb73ad..1825d2b835 100644
@@ -20,6 +20,7 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "qemu/units.h"
+#include "qemu/accel.h"
 #include "sysemu/tcg.h"
 #include "qemu-version.h"
 #include <sys/syscall.h>
@@ -703,8 +704,11 @@ int main(int argc, char **argv, char **envp)
     cpu_type = parse_cpu_option(cpu_model);
 
     /* init tcg before creating CPUs and to get qemu_host_page_size */
-    tcg_exec_init(0);
+    {
+        AccelClass *ac = ACCEL_GET_CLASS(current_accel());
 
+        ac->init_machine(NULL);
+    }
     cpu = cpu_create(cpu_type);
     env = cpu->env_ptr;
     cpu_reset(cpu);
@@ -846,7 +850,6 @@ int main(int argc, char **argv, char **envp)
        generating the prologue until now so that the prologue can take
        the real value of GUEST_BASE into account.  */
     tcg_prologue_init(tcg_ctx);
-    tcg_region_init();
 
     target_cpu_copy_regs(env, regs);
 
softmmu/memory.c +1 -1
index aa393f1bb0..92c8b4fc1f 100644
@@ -32,7 +32,7 @@
 #include "sysemu/kvm.h"
 #include "sysemu/runstate.h"
 #include "sysemu/tcg.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "hw/boards.h"
 #include "migration/vmstate.h"
 
softmmu/qtest.c +1 -1
index 7965dc9a16..130c366615 100644
@@ -20,7 +20,7 @@
 #include "exec/ioport.h"
 #include "exec/memory.h"
 #include "hw/irq.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/cpu-timers.h"
 #include "qemu/config-file.h"
 #include "qemu/option.h"
softmmu/vl.c +1 -1
index e6e0ad5a92..bc20c526d2 100644
@@ -40,7 +40,7 @@
 
 #include "qemu/error-report.h"
 #include "qemu/sockets.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "hw/usb.h"
 #include "hw/isa/isa.h"
 #include "hw/scsi/scsi.h"
target/i386/hax/hax-all.c +1 -1
index fecfe8cd6e..d7f4bb44a7 100644
@@ -28,7 +28,7 @@
 #include "exec/address-spaces.h"
 
 #include "qemu-common.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/reset.h"
 #include "sysemu/runstate.h"
 #include "hw/boards.h"
target/i386/hvf/hvf-i386.h +1 -1
index e0edffd077..50b914fd67 100644
@@ -16,7 +16,7 @@
 #ifndef HVF_I386_H
 #define HVF_I386_H
 
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/hvf.h"
 #include "cpu.h"
 #include "x86.h"
target/i386/hvf/hvf.c +1 -1
index ed9356565c..ffc9efa40f 100644
@@ -69,7 +69,7 @@
 #include "exec/address-spaces.h"
 #include "hw/i386/apic_internal.h"
 #include "qemu/main-loop.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "target/i386/cpu.h"
 
 #include "hvf-cpus.h"
target/i386/hvf/x86_task.c +1 -1
index 6f04478b3a..d66dfd7669 100644
@@ -28,7 +28,7 @@
 
 #include "hw/i386/apic_internal.h"
 #include "qemu/main-loop.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "target/i386/cpu.h"
 
 // TODO: taskswitch handling
target/i386/whpx/whpx-all.c +1 -1
index f4f3e33eac..ee6b606194 100644
@@ -13,7 +13,7 @@
 #include "exec/address-spaces.h"
 #include "exec/ioport.h"
 #include "qemu-common.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/whpx.h"
 #include "sysemu/cpus.h"
 #include "sysemu/runstate.h"
#14 lore raw

Re: [RFC v6 08/11] accel: extend AccelState and AccelClass to user-mode

Quoted 22 lines · Claudio Fontana

Hi Richard,

happy new year,

this change of mine breaks with --enable-debug, after your changes related to "splitrw" in tcg/, I am a bit at a loss at what could be going wrong.. any hints?

I am getting assertion failures with --enable-debug in make check-tcg,

in particular in tcg/tcg.c:768

#ifdef CONFIG_DEBUG_TCG
const void *tcg_splitwx_to_rx(void *rw)

{
    /* Pass NULL pointers unchanged. */
    if (rw) {
        g_assert(in_code_gen_buffer(rw)); /* <=== HERE */
        rw += tcg_splitwx_diff;
    }
    return rw;
}
Quoted 1 line

any hints?

Nevermind, I now noticed the new parameter, which needs to be false for USER MODE.

Thanks,

Claudio

Quoted 554 lines

Thanks,

Claudio

Quoted 545 lines · Claudio Fontana
---
 MAINTAINERS                        |  2 +-
 accel/accel-common.c               | 50 ++++++++++++++++++++++++++++++
 accel/{accel.c => accel-softmmu.c} | 27 ++--------------
 accel/accel-user.c                 | 24 ++++++++++++++
 accel/meson.build                  |  4 ++-
 accel/qtest/qtest.c                |  2 +-
 accel/tcg/meson.build              |  2 +-
 accel/tcg/tcg-all.c                |  7 ++++-
 accel/xen/xen-all.c                |  2 +-
 bsd-user/main.c                    |  7 +++--
 include/hw/boards.h                |  2 +-
 include/{sysemu => qemu}/accel.h   | 14 +++++----
 include/sysemu/hvf.h               |  2 +-
 include/sysemu/kvm.h               |  2 +-
 include/sysemu/kvm_int.h           |  2 +-
 linux-user/main.c                  |  7 +++--
 softmmu/memory.c                   |  2 +-
 softmmu/qtest.c                    |  2 +-
 softmmu/vl.c                       |  2 +-
 target/i386/hax/hax-all.c          |  2 +-
 target/i386/hvf/hvf-i386.h         |  2 +-
 target/i386/hvf/hvf.c              |  2 +-
 target/i386/hvf/x86_task.c         |  2 +-
 target/i386/whpx/whpx-all.c        |  2 +-
 24 files changed, 119 insertions(+), 53 deletions(-)
 create mode 100644 accel/accel-common.c
 rename accel/{accel.c => accel-softmmu.c} (75%)
 create mode 100644 accel/accel-user.c
 rename include/{sysemu => qemu}/accel.h (95%)
MAINTAINERS +1 -1
index e892dd2220..d7c212843c 100644
@@ -433,7 +433,7 @@ Overall
 M: Richard Henderson <[email protected]>
 R: Paolo Bonzini <[email protected]>
 S: Maintained
-F: include/sysemu/accel.h
+F: include/qemu/accel.h
 F: accel/accel.c
 F: accel/Makefile.objs
 F: accel/stubs/Makefile.objs
accel/accel-common.c new file +50 -0
new file mode 100644
index 0000000000..ddec8cb5ae
@@ -0,0 +1,50 @@
+/*
+ * QEMU accel class, components common to system emulation and user mode
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2014 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/accel.h"
+
+static const TypeInfo accel_type = {
+    .name = TYPE_ACCEL,
+    .parent = TYPE_OBJECT,
+    .class_size = sizeof(AccelClass),
+    .instance_size = sizeof(AccelState),
+};
+
+/* Lookup AccelClass from opt_name. Returns NULL if not found */
+AccelClass *accel_find(const char *opt_name)
+{
+    char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name);
+    AccelClass *ac = ACCEL_CLASS(object_class_by_name(class_name));
+    g_free(class_name);
+    return ac;
+}
+
+static void register_accel_types(void)
+{
+    type_register_static(&accel_type);
+}
+
+type_init(register_accel_types);
accel/accel-softmmu.c renamed from accel/accel.c +2 -25
similarity index 75%
rename from accel/accel.c
rename to accel/accel-softmmu.c
index cb555e3b06..f89da8f9d1 100644
@@ -1,5 +1,5 @@
 /*
- * QEMU System Emulator, accelerator interfaces
+ * QEMU accel class, system emulation components
  *
  * Copyright (c) 2003-2008 Fabrice Bellard
  * Copyright (c) 2014 Red Hat Inc.
@@ -24,28 +24,12 @@
  */
 
 #include "qemu/osdep.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "hw/boards.h"
 #include "sysemu/arch_init.h"
 #include "sysemu/sysemu.h"
 #include "qom/object.h"
 
-static const TypeInfo accel_type = {
-    .name = TYPE_ACCEL,
-    .parent = TYPE_OBJECT,
-    .class_size = sizeof(AccelClass),
-    .instance_size = sizeof(AccelState),
-};
-
-/* Lookup AccelClass from opt_name. Returns NULL if not found */
-AccelClass *accel_find(const char *opt_name)
-{
-    char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name);
-    AccelClass *ac = ACCEL_CLASS(object_class_by_name(class_name));
-    g_free(class_name);
-    return ac;
-}
-
 int accel_init_machine(AccelState *accel, MachineState *ms)
 {
     AccelClass *acc = ACCEL_GET_CLASS(accel);
@@ -76,10 +60,3 @@ void accel_setup_post(MachineState *ms)
         acc->setup_post(ms, accel);
     }
 }
-
-static void register_accel_types(void)
-{
-    type_register_static(&accel_type);
-}
-
-type_init(register_accel_types);
accel/accel-user.c new file +24 -0
new file mode 100644
index 0000000000..26bdda6236
@@ -0,0 +1,24 @@
+/*
+ * QEMU accel class, user-mode components
+ *
+ * Copyright 2020 SUSE LLC
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/accel.h"
+
+AccelState *current_accel(void)
+{
+    static AccelState *accel;
+
+    if (!accel) {
+        AccelClass *ac = accel_find("tcg");
+
+        g_assert(ac != NULL);
+        accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac)));
+    }
+    return accel;
+}
accel/meson.build +3 -1
index b26cca227a..b44ba30c86 100644
@@ -1,4 +1,6 @@
-softmmu_ss.add(files('accel.c'))
+specific_ss.add(files('accel-common.c'))
+softmmu_ss.add(files('accel-softmmu.c'))
+user_ss.add(files('accel-user.c'))
 
 subdir('qtest')
 subdir('kvm')
accel/qtest/qtest.c +1 -1
index b282cea5cf..b4e731cb2b 100644
@@ -17,7 +17,7 @@
 #include "qemu/module.h"
 #include "qemu/option.h"
 #include "qemu/config-file.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/qtest.h"
 #include "sysemu/cpus.h"
 #include "sysemu/cpu-timers.h"
accel/tcg/meson.build +1 -1
index f39aab0a0c..424d9bb1fc 100644
@@ -1,5 +1,6 @@
 tcg_ss = ss.source_set()
 tcg_ss.add(files(
+  'tcg-all.c',
   'cpu-exec-common.c',
   'cpu-exec.c',
   'tcg-runtime-gvec.c',
@@ -13,7 +14,6 @@ tcg_ss.add(when: 'CONFIG_PLUGIN', if_true: [files('plugin-gen.c'), libdl])
 specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss)
 
 specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files(
-  'tcg-all.c',
   'cputlb.c',
   'tcg-cpus.c',
   'tcg-cpus-mttcg.c',
accel/tcg/tcg-all.c +6 -1
index 1ac0b76515..dcbc6970da 100644
@@ -30,9 +30,12 @@
 #include "tcg/tcg.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
-#include "hw/boards.h"
+#include "qemu/accel.h"
 #include "qapi/qapi-builtin-visit.h"
+
+#ifndef CONFIG_USER_ONLY
 #include "tcg-cpus.h"
+#endif /* CONFIG_USER_ONLY */
 
 struct TCGState {
     AccelState parent_obj;
@@ -110,6 +113,7 @@ static int tcg_init(MachineState *ms)
      */
     tcg_region_init();
 
+#ifndef CONFIG_USER_ONLY
     if (mttcg_enabled) {
         cpus_register_accel(&tcg_cpus_mttcg);
     } else if (icount_enabled()) {
@@ -117,6 +121,7 @@ static int tcg_init(MachineState *ms)
     } else {
         cpus_register_accel(&tcg_cpus_rr);
     }
+#endif /* CONFIG_USER_ONLY */
     return 0;
 }
 
accel/xen/xen-all.c +1 -1
index 878a4089d9..594aaf6b49 100644
@@ -15,7 +15,7 @@
 #include "hw/xen/xen-legacy-backend.h"
 #include "hw/xen/xen_pt.h"
 #include "chardev/char.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/cpus.h"
 #include "sysemu/xen.h"
 #include "sysemu/runstate.h"
bsd-user/main.c +5 -2
index 0a918e8f74..ec1f9d80a4 100644
@@ -20,6 +20,7 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "qemu/units.h"
+#include "qemu/accel.h"
 #include "sysemu/tcg.h"
 #include "qemu-version.h"
 #include <machine/trap.h>
@@ -908,8 +909,11 @@ int main(int argc, char **argv)
     }
 
     /* init tcg before creating CPUs and to get qemu_host_page_size */
-    tcg_exec_init(0);
+    {
+        AccelClass *ac = ACCEL_GET_CLASS(current_accel());
 
+        ac->init_machine(NULL);
+    }
     cpu_type = parse_cpu_option(cpu_model);
     cpu = cpu_create(cpu_type);
     env = cpu->env_ptr;
@@ -988,7 +992,6 @@ int main(int argc, char **argv)
        generating the prologue until now so that the prologue can take
        the real value of GUEST_BASE into account.  */
     tcg_prologue_init(tcg_ctx);
-    tcg_region_init();
 
     /* build Task State */
     memset(ts, 0, sizeof(TaskState));
include/hw/boards.h +1 -1
index a49e3a6b44..b754504afe 100644
@@ -6,7 +6,7 @@
 #include "exec/memory.h"
 #include "sysemu/hostmem.h"
 #include "sysemu/blockdev.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "qapi/qapi-types-machine.h"
 #include "qemu/module.h"
 #include "qom/object.h"
include/qemu/accel.h renamed from include/sysemu/accel.h +8 -6
similarity index 95%
rename from include/sysemu/accel.h
rename to include/qemu/accel.h
index e08b8ab8fa..fac4a18703 100644
@@ -20,8 +20,8 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#ifndef HW_ACCEL_H
-#define HW_ACCEL_H
+#ifndef QEMU_ACCEL_H
+#define QEMU_ACCEL_H
 
 #include "qom/object.h"
 #include "exec/hwaddr.h"
@@ -37,8 +37,8 @@ typedef struct AccelClass {
     /*< public >*/
 
     const char *name;
-#ifndef CONFIG_USER_ONLY
     int (*init_machine)(MachineState *ms);
+#ifndef CONFIG_USER_ONLY
     void (*setup_post)(MachineState *ms, AccelState *accel);
     bool (*has_memory)(MachineState *ms, AddressSpace *as,
                        hwaddr start_addr, hwaddr size);
@@ -67,11 +67,13 @@ typedef struct AccelClass {
     OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL)
 
 AccelClass *accel_find(const char *opt_name);
+AccelState *current_accel(void);
+
+#ifndef CONFIG_USER_ONLY
 int accel_init_machine(AccelState *accel, MachineState *ms);
 
 /* Called just before os_setup_post (ie just before drop OS privs) */
 void accel_setup_post(MachineState *ms);
+#endif /* !CONFIG_USER_ONLY */
 
-AccelState *current_accel(void);
-
-#endif
+#endif /* QEMU_ACCEL_H */
include/sysemu/hvf.h +1 -1
index f893768df9..c98636bc81 100644
@@ -13,7 +13,7 @@
 #ifndef HVF_H
 #define HVF_H
 
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "qom/object.h"
 
 #ifdef CONFIG_HVF
include/sysemu/kvm.h +1 -1
index bb5d5cf497..739682f3c3 100644
@@ -17,7 +17,7 @@
 #include "qemu/queue.h"
 #include "hw/core/cpu.h"
 #include "exec/memattrs.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "qom/object.h"
 
 #ifdef NEED_CPU_H
include/sysemu/kvm_int.h +1 -1
index 65740806da..ccb8869f01 100644
@@ -10,7 +10,7 @@
 #define QEMU_KVM_INT_H
 
 #include "exec/memory.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/kvm.h"
 
 typedef struct KVMSlot
linux-user/main.c +5 -2
index 24d1eb73ad..1825d2b835 100644
@@ -20,6 +20,7 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "qemu/units.h"
+#include "qemu/accel.h"
 #include "sysemu/tcg.h"
 #include "qemu-version.h"
 #include <sys/syscall.h>
@@ -703,8 +704,11 @@ int main(int argc, char **argv, char **envp)
     cpu_type = parse_cpu_option(cpu_model);
 
     /* init tcg before creating CPUs and to get qemu_host_page_size */
-    tcg_exec_init(0);
+    {
+        AccelClass *ac = ACCEL_GET_CLASS(current_accel());
 
+        ac->init_machine(NULL);
+    }
     cpu = cpu_create(cpu_type);
     env = cpu->env_ptr;
     cpu_reset(cpu);
@@ -846,7 +850,6 @@ int main(int argc, char **argv, char **envp)
        generating the prologue until now so that the prologue can take
        the real value of GUEST_BASE into account.  */
     tcg_prologue_init(tcg_ctx);
-    tcg_region_init();
 
     target_cpu_copy_regs(env, regs);
 
softmmu/memory.c +1 -1
index aa393f1bb0..92c8b4fc1f 100644
@@ -32,7 +32,7 @@
 #include "sysemu/kvm.h"
 #include "sysemu/runstate.h"
 #include "sysemu/tcg.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "hw/boards.h"
 #include "migration/vmstate.h"
 
softmmu/qtest.c +1 -1
index 7965dc9a16..130c366615 100644
@@ -20,7 +20,7 @@
 #include "exec/ioport.h"
 #include "exec/memory.h"
 #include "hw/irq.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/cpu-timers.h"
 #include "qemu/config-file.h"
 #include "qemu/option.h"
softmmu/vl.c +1 -1
index e6e0ad5a92..bc20c526d2 100644
@@ -40,7 +40,7 @@
 
 #include "qemu/error-report.h"
 #include "qemu/sockets.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "hw/usb.h"
 #include "hw/isa/isa.h"
 #include "hw/scsi/scsi.h"
target/i386/hax/hax-all.c +1 -1
index fecfe8cd6e..d7f4bb44a7 100644
@@ -28,7 +28,7 @@
 #include "exec/address-spaces.h"
 
 #include "qemu-common.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/reset.h"
 #include "sysemu/runstate.h"
 #include "hw/boards.h"
target/i386/hvf/hvf-i386.h +1 -1
index e0edffd077..50b914fd67 100644
@@ -16,7 +16,7 @@
 #ifndef HVF_I386_H
 #define HVF_I386_H
 
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/hvf.h"
 #include "cpu.h"
 #include "x86.h"
target/i386/hvf/hvf.c +1 -1
index ed9356565c..ffc9efa40f 100644
@@ -69,7 +69,7 @@
 #include "exec/address-spaces.h"
 #include "hw/i386/apic_internal.h"
 #include "qemu/main-loop.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "target/i386/cpu.h"
 
 #include "hvf-cpus.h"
target/i386/hvf/x86_task.c +1 -1
index 6f04478b3a..d66dfd7669 100644
@@ -28,7 +28,7 @@
 
 #include "hw/i386/apic_internal.h"
 #include "qemu/main-loop.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "target/i386/cpu.h"
 
 // TODO: taskswitch handling
target/i386/whpx/whpx-all.c +1 -1
index f4f3e33eac..ee6b606194 100644
@@ -13,7 +13,7 @@
 #include "exec/address-spaces.h"
 #include "exec/ioport.h"
 #include "qemu-common.h"
-#include "sysemu/accel.h"
+#include "qemu/accel.h"
 #include "sysemu/whpx.h"
 #include "sysemu/cpus.h"
 #include "sysemu/runstate.h"
#15 lore raw

RFC v6 9/11 accel: replace struct CpusAccel with AccelOpsClass

In reply to Claudio Fontana

centralize the registration of the cpus.c module
accelerator operations in accel/accel-softmmu.c

---
 MAINTAINERS                  |  3 ++-
 accel/accel-common.c         | 11 +++++++++
 accel/accel-softmmu.c        | 43 +++++++++++++++++++++++++++++++---
 accel/accel-softmmu.h        | 15 ++++++++++++
 accel/kvm/kvm-all.c          |  2 --
 accel/kvm/kvm-cpus.c         | 26 ++++++++++++++++-----
 accel/kvm/kvm-cpus.h         |  2 --
 accel/qtest/qtest.c          | 23 +++++++++++++-----
 accel/tcg/tcg-all.c          | 14 -----------
 accel/tcg/tcg-cpus-icount.c  | 11 +--------
 accel/tcg/tcg-cpus-icount.h  |  2 ++
 accel/tcg/tcg-cpus-mttcg.c   | 12 +++-------
 accel/tcg/tcg-cpus-mttcg.h   | 19 +++++++++++++++
 accel/tcg/tcg-cpus-rr.c      |  7 ------
 accel/tcg/tcg-cpus.c         | 43 ++++++++++++++++++++++++++++++++++
 accel/tcg/tcg-cpus.h         |  4 ----
 accel/xen/xen-all.c          | 22 ++++++++++++------
 bsd-user/main.c              |  3 ++-
 include/qemu/accel.h         |  2 ++
 include/sysemu/accel-ops.h   | 45 ++++++++++++++++++++++++++++++++++++
 include/sysemu/cpus.h        | 26 ++++-----------------
 linux-user/main.c            |  1 +
 softmmu/cpus.c               | 12 +++++-----
 softmmu/vl.c                 |  8 +++++--
 target/i386/hax/hax-all.c    |  3 ---
 target/i386/hax/hax-cpus.c   | 29 +++++++++++++++++------
 target/i386/hax/hax-cpus.h   |  2 --
 target/i386/hvf/hvf-cpus.c   | 27 +++++++++++++++++-----
 target/i386/hvf/hvf-cpus.h   |  2 --
 target/i386/hvf/hvf.c        |  1 -
 target/i386/whpx/whpx-all.c  |  2 --
 target/i386/whpx/whpx-cpus.c | 29 +++++++++++++++++------
 target/i386/whpx/whpx-cpus.h |  2 --
 33 files changed, 320 insertions(+), 133 deletions(-)
 create mode 100644 accel/accel-softmmu.h
 create mode 100644 accel/tcg/tcg-cpus-mttcg.h
 create mode 100644 include/sysemu/accel-ops.h
MAINTAINERS +2 -1
index d7c212843c..df64a0d190 100644
@@ -434,7 +434,8 @@ M: Richard Henderson <[email protected]>
 R: Paolo Bonzini <[email protected]>
 S: Maintained
 F: include/qemu/accel.h
-F: accel/accel.c
+F: include/sysemu/accel-ops.h
+F: accel/accel-*.c
 F: accel/Makefile.objs
 F: accel/stubs/Makefile.objs
 
accel/accel-common.c +11 -0
index ddec8cb5ae..3910b7dbe0 100644
@@ -26,6 +26,10 @@
 #include "qemu/osdep.h"
 #include "qemu/accel.h"
 
+#ifndef CONFIG_USER_ONLY
+#include "accel-softmmu.h"
+#endif /* !CONFIG_USER_ONLY */
+
 static const TypeInfo accel_type = {
     .name = TYPE_ACCEL,
     .parent = TYPE_OBJECT,
@@ -42,6 +46,13 @@ AccelClass *accel_find(const char *opt_name)
     return ac;
 }
 
+void accel_init_interfaces(AccelClass *ac, const char *cpu_type)
+{
+#ifndef CONFIG_USER_ONLY
+    accel_init_ops_interfaces(ac);
+#endif /* !CONFIG_USER_ONLY */
+}
+
 static void register_accel_types(void)
 {
     type_register_static(&accel_type);
accel/accel-softmmu.c +40 -3

52 lines not on this page · raw message

accel/accel-softmmu.h new file +15 -0
new file mode 100644
index 0000000000..2877b5c234
@@ -0,0 +1,15 @@
+/*
+ * QEMU System Emulation accel internal functions
+ *
+ * Copyright 2020 SUSE LLC
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef ACCEL_SOFTMMU_H
+#define ACCEL_SOFTMMU_H
+
+void accel_init_ops_interfaces(AccelClass *ac);
+
+#endif /* ACCEL_SOFTMMU_H */
accel/kvm/kvm-all.c +0 -2
index 9ef5daf4c5..33156cc4c7 100644
@@ -2251,8 +2251,6 @@ static int kvm_init(MachineState *ms)
         ret = ram_block_discard_disable(true);
         assert(!ret);
     }
-
-    cpus_register_accel(&kvm_cpus);
     return 0;
 
 err:
accel/kvm/kvm-cpus.c +20 -6
index d809b1e74c..fc9dda46ae 100644
@@ -74,11 +74,25 @@ static void kvm_start_vcpu_thread(CPUState *cpu)
                        cpu, QEMU_THREAD_JOINABLE);
 }
 
-const CpusAccel kvm_cpus = {
-    .create_vcpu_thread = kvm_start_vcpu_thread,
+static void kvm_cpus_class_init(ObjectClass *oc, void *data)
+{
+    AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
 
-    .synchronize_post_reset = kvm_cpu_synchronize_post_reset,
-    .synchronize_post_init = kvm_cpu_synchronize_post_init,
-    .synchronize_state = kvm_cpu_synchronize_state,
-    .synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm,
+    ops->create_vcpu_thread = kvm_start_vcpu_thread;
+    ops->synchronize_post_reset = kvm_cpu_synchronize_post_reset;
+    ops->synchronize_post_init = kvm_cpu_synchronize_post_init;
+    ops->synchronize_state = kvm_cpu_synchronize_state;
+    ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm;
 };
+static const TypeInfo kvm_cpus_type_info = {
+    .name = ACCEL_OPS_NAME("kvm"),
+
+    .parent = TYPE_ACCEL_OPS,
+    .class_init = kvm_cpus_class_init,
+    .abstract = true,
+};
+static void kvm_cpus_register_types(void)
+{
+    type_register_static(&kvm_cpus_type_info);
+}
+type_init(kvm_cpus_register_types);
accel/kvm/kvm-cpus.h +0 -2
index 3df732b816..bf0bd1bee4 100644
@@ -12,8 +12,6 @@
 
 #include "sysemu/cpus.h"
 
-extern const CpusAccel kvm_cpus;
-
 int kvm_init_vcpu(CPUState *cpu, Error **errp);
 int kvm_cpu_exec(CPUState *cpu);
 void kvm_destroy_vcpu(CPUState *cpu);
accel/qtest/qtest.c +17 -6
index b4e731cb2b..68d86de30f 100644
@@ -25,14 +25,8 @@
 #include "qemu/main-loop.h"
 #include "hw/core/cpu.h"
 
-const CpusAccel qtest_cpus = {
-    .create_vcpu_thread = dummy_start_vcpu_thread,
-    .get_virtual_clock = qtest_get_virtual_clock,
-};
-
 static int qtest_init_accel(MachineState *ms)
 {
-    cpus_register_accel(&qtest_cpus);
     return 0;
 }
 
@@ -52,9 +46,26 @@ static const TypeInfo qtest_accel_type = {
     .class_init = qtest_accel_class_init,
 };
 
+static void qtest_cpus_class_init(ObjectClass *oc, void *data)
+{
+    AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
+
+    ops->create_vcpu_thread = dummy_start_vcpu_thread;
+    ops->get_virtual_clock = qtest_get_virtual_clock;
+};
+
+static const TypeInfo qtest_cpus_type_info = {
+    .name = ACCEL_OPS_NAME("qtest"),
+
+    .parent = TYPE_ACCEL_OPS,
+    .class_init = qtest_cpus_class_init,
+    .abstract = true,
+};
+
 static void qtest_type_init(void)
 {
     type_register_static(&qtest_accel_type);
+    type_register_static(&qtest_cpus_type_info);
 }
 
 type_init(qtest_type_init);
accel/tcg/tcg-all.c +0 -14
index dcbc6970da..2b86df9ba0 100644
@@ -33,10 +33,6 @@
 #include "qemu/accel.h"
 #include "qapi/qapi-builtin-visit.h"
 
-#ifndef CONFIG_USER_ONLY
-#include "tcg-cpus.h"
-#endif /* CONFIG_USER_ONLY */
-
 struct TCGState {
     AccelState parent_obj;
 
@@ -112,16 +108,6 @@ static int tcg_init(MachineState *ms)
      * Initialize TCG regions
      */
     tcg_region_init();
-
-#ifndef CONFIG_USER_ONLY
-    if (mttcg_enabled) {
-        cpus_register_accel(&tcg_cpus_mttcg);
-    } else if (icount_enabled()) {
-        cpus_register_accel(&tcg_cpus_icount);
-    } else {
-        cpus_register_accel(&tcg_cpus_rr);
-    }
-#endif /* CONFIG_USER_ONLY */
     return 0;
 }
 
accel/tcg/tcg-cpus-icount.c +1 -10
index 9f45432275..5445b4d545 100644
@@ -125,7 +125,7 @@ void icount_process_data(CPUState *cpu)
     replay_mutex_unlock();
 }
 
-static void icount_handle_interrupt(CPUState *cpu, int mask)
+void icount_handle_interrupt(CPUState *cpu, int mask)
 {
     int old_mask = cpu->interrupt_request;
 
@@ -136,12 +136,3 @@ static void icount_handle_interrupt(CPUState *cpu, int mask)
         cpu_abort(cpu, "Raised interrupt while not in I/O function");
     }
 }
-
-const CpusAccel tcg_cpus_icount = {
-    .create_vcpu_thread = rr_start_vcpu_thread,
-    .kick_vcpu_thread = rr_kick_vcpu_thread,
-
-    .handle_interrupt = icount_handle_interrupt,
-    .get_virtual_clock = icount_get,
-    .get_elapsed_ticks = icount_get,
-};
accel/tcg/tcg-cpus-icount.h +2 -0
index b695939dfa..d884aa2aaa 100644
@@ -14,4 +14,6 @@ void icount_handle_deadline(void);
 void icount_prepare_for_run(CPUState *cpu);
 void icount_process_data(CPUState *cpu);
 
+void icount_handle_interrupt(CPUState *cpu, int mask);
+
 #endif /* TCG_CPUS_ICOUNT_H */
accel/tcg/tcg-cpus-mttcg.c +3 -9
index 9c3767d260..dabf5ed42e 100644
@@ -33,6 +33,7 @@
 #include "hw/boards.h"
 
 #include "tcg-cpus.h"
+#include "tcg-cpus-mttcg.h"
 
 /*
  * In the multi-threaded case each vCPU has its own thread. The TLS
@@ -103,12 +104,12 @@ static void *mttcg_cpu_thread_fn(void *arg)
     return NULL;
 }
 
-static void mttcg_kick_vcpu_thread(CPUState *cpu)
+void mttcg_kick_vcpu_thread(CPUState *cpu)
 {
     cpu_exit(cpu);
 }
 
-static void mttcg_start_vcpu_thread(CPUState *cpu)
+void mttcg_start_vcpu_thread(CPUState *cpu)
 {
     char thread_name[VCPU_THREAD_NAME_SIZE];
 
@@ -131,10 +132,3 @@ static void mttcg_start_vcpu_thread(CPUState *cpu)
     cpu->hThread = qemu_thread_get_handle(cpu->thread);
 #endif
 }
-
-const CpusAccel tcg_cpus_mttcg = {
-    .create_vcpu_thread = mttcg_start_vcpu_thread,
-    .kick_vcpu_thread = mttcg_kick_vcpu_thread,
-
-    .handle_interrupt = tcg_cpus_handle_interrupt,
-};
accel/tcg/tcg-cpus-mttcg.h new file +19 -0
new file mode 100644
index 0000000000..0af91dd3b3
@@ -0,0 +1,19 @@
+/*
+ * QEMU TCG Multi Threaded vCPUs implementation
+ *
+ * Copyright 2020 SUSE LLC
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef TCG_CPUS_MTTCG_H
+#define TCG_CPUS_MTTCG_H
+
+/* kick MTTCG vCPU thread */
+void mttcg_kick_vcpu_thread(CPUState *cpu);
+
+/* start an mttcg vCPU thread */
+void mttcg_start_vcpu_thread(CPUState *cpu);
+
+#endif /* TCG_CPUS_MTTCG_H */
accel/tcg/tcg-cpus-rr.c +0 -7
index 0181d2e4eb..802c57bb60 100644
@@ -296,10 +296,3 @@ void rr_start_vcpu_thread(CPUState *cpu)
         cpu->created = true;
     }
 }
-
-const CpusAccel tcg_cpus_rr = {
-    .create_vcpu_thread = rr_start_vcpu_thread,
-    .kick_vcpu_thread = rr_kick_vcpu_thread,
-
-    .handle_interrupt = tcg_cpus_handle_interrupt,
-};
accel/tcg/tcg-cpus.c +43 -0

52 lines not on this page · raw message

accel/tcg/tcg-cpus.h +0 -4
index d6893a32f8..923cbace12 100644
@@ -14,10 +14,6 @@
 
 #include "sysemu/cpus.h"
 
-extern const CpusAccel tcg_cpus_mttcg;
-extern const CpusAccel tcg_cpus_icount;
-extern const CpusAccel tcg_cpus_rr;
-
 void tcg_cpus_destroy(CPUState *cpu);
 int tcg_cpus_exec(CPUState *cpu);
 void tcg_cpus_handle_interrupt(CPUState *cpu, int mask);
accel/xen/xen-all.c +15 -7
index 594aaf6b49..cd5aa2b96e 100644
@@ -154,10 +154,6 @@ static void xen_setup_post(MachineState *ms, AccelState *accel)
     }
 }
 
-const CpusAccel xen_cpus = {
-    .create_vcpu_thread = dummy_start_vcpu_thread,
-};
-
 static int xen_init(MachineState *ms)
 {
     MachineClass *mc = MACHINE_GET_CLASS(ms);
@@ -185,9 +181,6 @@ static int xen_init(MachineState *ms)
      * opt out of system RAM being allocated by generic code
      */
     mc->default_ram_id = NULL;
-
-    cpus_register_accel(&xen_cpus);
-
     return 0;
 }
 
@@ -222,9 +215,24 @@ static const TypeInfo xen_accel_type = {
     .class_init = xen_accel_class_init,
 };
 
+static void xen_cpus_class_init(ObjectClass *oc, void *data)
+{
+    AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
+
+    ops->create_vcpu_thread = dummy_start_vcpu_thread;
+};
+static const TypeInfo xen_cpus_type_info = {
+    .name = ACCEL_OPS_NAME("xen"),
+
+    .parent = TYPE_ACCEL_OPS,
+    .class_init = xen_cpus_class_init,
+    .abstract = true,
+};
+
 static void xen_type_init(void)
 {
     type_register_static(&xen_accel_type);
+    type_register_static(&xen_cpus_type_info);
 }
 
 type_init(xen_type_init);
bsd-user/main.c +2 -1
index ec1f9d80a4..25a757c746 100644
@@ -908,13 +908,14 @@ int main(int argc, char **argv)
 #endif
     }
 
+    cpu_type = parse_cpu_option(cpu_model);
     /* init tcg before creating CPUs and to get qemu_host_page_size */
     {
         AccelClass *ac = ACCEL_GET_CLASS(current_accel());
 
         ac->init_machine(NULL);
+        accel_init_interfaces(ac, cpu_type);
     }
-    cpu_type = parse_cpu_option(cpu_model);
     cpu = cpu_create(cpu_type);
     env = cpu->env_ptr;
 #if defined(TARGET_SPARC) || defined(TARGET_PPC)
include/qemu/accel.h +2 -0
index fac4a18703..68a57e040f 100644
@@ -69,6 +69,8 @@ typedef struct AccelClass {
 AccelClass *accel_find(const char *opt_name);
 AccelState *current_accel(void);
 
+void accel_init_interfaces(AccelClass *ac, const char *cpu_type);
+
 #ifndef CONFIG_USER_ONLY
 int accel_init_machine(AccelState *accel, MachineState *ms);
 
include/sysemu/accel-ops.h new file +45 -0

45 lines not on this page · raw message

include/sysemu/cpus.h +5 -21
index e8156728c6..2cd74392e0 100644
@@ -2,30 +2,14 @@
 #define QEMU_CPUS_H
 
 #include "qemu/timer.h"
+#include "sysemu/accel-ops.h"
 
-/* cpus.c */
+/* register accel-specific operations */
+void cpus_register_accel(const AccelOpsClass *i);
 
-/* CPU execution threads */
+/* accel/dummy-cpus.c */
 
-typedef struct CpusAccel {
-    void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY */
-    void (*kick_vcpu_thread)(CPUState *cpu);
-
-    void (*synchronize_post_reset)(CPUState *cpu);
-    void (*synchronize_post_init)(CPUState *cpu);
-    void (*synchronize_state)(CPUState *cpu);
-    void (*synchronize_pre_loadvm)(CPUState *cpu);
-
-    void (*handle_interrupt)(CPUState *cpu, int mask);
-
-    int64_t (*get_virtual_clock)(void);
-    int64_t (*get_elapsed_ticks)(void);
-} CpusAccel;
-
-/* register accel-specific cpus interface implementation */
-void cpus_register_accel(const CpusAccel *i);
-
-/* Create a dummy vcpu for CpusAccel->create_vcpu_thread */
+/* Create a dummy vcpu for AccelOpsClass->create_vcpu_thread */
 void dummy_start_vcpu_thread(CPUState *);
 
 /* interface available for cpus accelerator threads */
linux-user/main.c +1 -0
index 1825d2b835..54e59fce3a 100644
@@ -708,6 +708,7 @@ int main(int argc, char **argv, char **envp)
         AccelClass *ac = ACCEL_GET_CLASS(current_accel());
 
         ac->init_machine(NULL);
+        accel_init_interfaces(ac, cpu_type);
     }
     cpu = cpu_create(cpu_type);
     env = cpu->env_ptr;
softmmu/cpus.c +6 -6
index e46ac68ad0..659617e7ef 100644
@@ -127,7 +127,7 @@ void hw_error(const char *fmt, ...)
 /*
  * The chosen accelerator is supposed to register this.
  */
-static const CpusAccel *cpus_accel;
+static const AccelOpsClass *cpus_accel;
 
 void cpu_synchronize_all_states(void)
 {
@@ -593,11 +593,11 @@ void cpu_remove_sync(CPUState *cpu)
     qemu_mutex_lock_iothread();
 }
 
-void cpus_register_accel(const CpusAccel *ca)
+void cpus_register_accel(const AccelOpsClass *ops)
 {
-    assert(ca != NULL);
-    assert(ca->create_vcpu_thread != NULL); /* mandatory */
-    cpus_accel = ca;
+    assert(ops != NULL);
+    assert(ops->create_vcpu_thread != NULL); /* mandatory */
+    cpus_accel = ops;
 }
 
 void qemu_init_vcpu(CPUState *cpu)
@@ -617,7 +617,7 @@ void qemu_init_vcpu(CPUState *cpu)
         cpu_address_space_init(cpu, 0, "cpu-memory", cpu->memory);
     }
 
-    /* accelerators all implement the CpusAccel interface */
+    /* accelerators all implement the AccelOpsClass */
     g_assert(cpus_accel != NULL && cpus_accel->create_vcpu_thread != NULL);
     cpus_accel->create_vcpu_thread(cpu);
 
softmmu/vl.c +6 -2
index bc20c526d2..8d65058ef1 100644
@@ -2558,7 +2558,7 @@ static bool object_create_initial(const char *type, QemuOpts *opts)
     }
 
     /* Memory allocation by backends needs to be done
-     * after configure_accelerator() (due to the tcg_enabled()
+     * after do_configure_accelerator() (due to the tcg_enabled()
      * checks at memory_region_init_*()).
      *
      * Also, allocation of large amounts of memory may delay
@@ -4186,7 +4186,7 @@ void qemu_init(int argc, char **argv, char **envp)
      *
      * Machine compat properties: object_set_machine_compat_props().
      * Accelerator compat props: object_set_accelerator_compat_props(),
-     * called from configure_accelerator().
+     * called from do_configure_accelerator().
      */
 
     if (!qtest_enabled() && machine_class->deprecation_reason) {
@@ -4322,6 +4322,10 @@ void qemu_init(int argc, char **argv, char **envp)
         current_machine->cpu_type = parse_cpu_option(cpu_option);
     }
 
+    /* cpu has been chosen, initialize the accel interfaces */
+    accel_init_interfaces(ACCEL_GET_CLASS(current_machine->accelerator),
+                          current_machine->cpu_type);
+
     if (current_machine->ram_memdev_id) {
         Object *backend;
         ram_addr_t backend_size;
target/i386/hax/hax-all.c +0 -3
index d7f4bb44a7..ec3c426223 100644
@@ -364,9 +364,6 @@ static int hax_accel_init(MachineState *ms)
                 !ret ? "working" : "not working",
                 !ret ? "fast virt" : "emulation");
     }
-    if (ret == 0) {
-        cpus_register_accel(&hax_cpus);
-    }
     return ret;
 }
 
target/i386/hax/hax-cpus.c +22 -7
index f72c85bd49..2f8424388d 100644
@@ -74,12 +74,27 @@ static void hax_start_vcpu_thread(CPUState *cpu)
 #endif
 }
 
-const CpusAccel hax_cpus = {
-    .create_vcpu_thread = hax_start_vcpu_thread,
-    .kick_vcpu_thread = hax_kick_vcpu_thread,
+static void hax_cpus_class_init(ObjectClass *oc, void *data)
+{
+    AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
 
-    .synchronize_post_reset = hax_cpu_synchronize_post_reset,
-    .synchronize_post_init = hax_cpu_synchronize_post_init,
-    .synchronize_state = hax_cpu_synchronize_state,
-    .synchronize_pre_loadvm = hax_cpu_synchronize_pre_loadvm,
+    ops->create_vcpu_thread = hax_start_vcpu_thread;
+    ops->kick_vcpu_thread = hax_kick_vcpu_thread;
+
+    ops->synchronize_post_reset = hax_cpu_synchronize_post_reset;
+    ops->synchronize_post_init = hax_cpu_synchronize_post_init;
+    ops->synchronize_state = hax_cpu_synchronize_state;
+    ops->synchronize_pre_loadvm = hax_cpu_synchronize_pre_loadvm;
+};
+static const TypeInfo hax_cpus_type_info = {
+    .name = ACCEL_OPS_NAME("hax"),
+
+    .parent = TYPE_ACCEL_OPS,
+    .class_init = hax_cpus_class_init,
+    .abstract = true,
 };
+static void hax_cpus_register_types(void)
+{
+    type_register_static(&hax_cpus_type_info);
+}
+type_init(hax_cpus_register_types);
target/i386/hax/hax-cpus.h +0 -2
index ee8ab7a631..c7698519cd 100644
@@ -12,8 +12,6 @@
 
 #include "sysemu/cpus.h"
 
-extern const CpusAccel hax_cpus;
-
 #include "hax-interface.h"
 #include "hax-i386.h"
 
target/i386/hvf/hvf-cpus.c +21 -6
index 817b3d7452..dd022a84c4 100644
@@ -121,11 +121,26 @@ static void hvf_start_vcpu_thread(CPUState *cpu)
                        cpu, QEMU_THREAD_JOINABLE);
 }
 
-const CpusAccel hvf_cpus = {
-    .create_vcpu_thread = hvf_start_vcpu_thread,
+static void hvf_cpus_class_init(ObjectClass *oc, void *data)
+{
+    AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
 
-    .synchronize_post_reset = hvf_cpu_synchronize_post_reset,
-    .synchronize_post_init = hvf_cpu_synchronize_post_init,
-    .synchronize_state = hvf_cpu_synchronize_state,
-    .synchronize_pre_loadvm = hvf_cpu_synchronize_pre_loadvm,
+    ops->create_vcpu_thread = hvf_start_vcpu_thread;
+
+    ops->synchronize_post_reset = hvf_cpu_synchronize_post_reset;
+    ops->synchronize_post_init = hvf_cpu_synchronize_post_init;
+    ops->synchronize_state = hvf_cpu_synchronize_state;
+    ops->synchronize_pre_loadvm = hvf_cpu_synchronize_pre_loadvm;
+};
+static const TypeInfo hvf_cpus_type_info = {
+    .name = ACCEL_OPS_NAME("hvf"),
+
+    .parent = TYPE_ACCEL_OPS,
+    .class_init = hvf_cpus_class_init,
+    .abstract = true,
 };
+static void hvf_cpus_register_types(void)
+{
+    type_register_static(&hvf_cpus_type_info);
+}
+type_init(hvf_cpus_register_types);
target/i386/hvf/hvf-cpus.h +0 -2
index ced31b82c0..8f992da168 100644
@@ -12,8 +12,6 @@
 
 #include "sysemu/cpus.h"
 
-extern const CpusAccel hvf_cpus;
-
 int hvf_init_vcpu(CPUState *);
 int hvf_vcpu_exec(CPUState *);
 void hvf_cpu_synchronize_state(CPUState *);
target/i386/hvf/hvf.c +0 -1
index ffc9efa40f..bd94bb5243 100644
@@ -887,7 +887,6 @@ static int hvf_accel_init(MachineState *ms)
   
     hvf_state = s;
     memory_listener_register(&hvf_memory_listener, &address_space_memory);
-    cpus_register_accel(&hvf_cpus);
     return 0;
 }
 
target/i386/whpx/whpx-all.c +0 -2
index ee6b606194..90adae9af7 100644
@@ -1642,8 +1642,6 @@ static int whpx_accel_init(MachineState *ms)
 
     whpx_memory_init();
 
-    cpus_register_accel(&whpx_cpus);
-
     printf("Windows Hypervisor Platform accelerator is operational\n");
     return 0;
 
target/i386/whpx/whpx-cpus.c +22 -7
index d9bd5a2d36..8e82974de7 100644
@@ -85,12 +85,27 @@ static void whpx_kick_vcpu_thread(CPUState *cpu)
     }
 }
 
-const CpusAccel whpx_cpus = {
-    .create_vcpu_thread = whpx_start_vcpu_thread,
-    .kick_vcpu_thread = whpx_kick_vcpu_thread,
+static void whpx_cpus_class_init(ObjectClass *oc, void *data)
+{
+    AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
 
-    .synchronize_post_reset = whpx_cpu_synchronize_post_reset,
-    .synchronize_post_init = whpx_cpu_synchronize_post_init,
-    .synchronize_state = whpx_cpu_synchronize_state,
-    .synchronize_pre_loadvm = whpx_cpu_synchronize_pre_loadvm,
+    ops->create_vcpu_thread = whpx_start_vcpu_thread;
+    ops->kick_vcpu_thread = whpx_kick_vcpu_thread;
+
+    ops->synchronize_post_reset = whpx_cpu_synchronize_post_reset;
+    ops->synchronize_post_init = whpx_cpu_synchronize_post_init;
+    ops->synchronize_state = whpx_cpu_synchronize_state;
+    ops->synchronize_pre_loadvm = whpx_cpu_synchronize_pre_loadvm;
+};
+static const TypeInfo whpx_cpus_type_info = {
+    .name = ACCEL_OPS_NAME("whpx"),
+
+    .parent = TYPE_ACCEL_OPS,
+    .class_init = whpx_cpus_class_init,
+    .abstract = true,
 };
+static void whpx_cpus_register_types(void)
+{
+    type_register_static(&whpx_cpus_type_info);
+}
+type_init(whpx_cpus_register_types);
target/i386/whpx/whpx-cpus.h +0 -2
index bdb367d1d0..2dee6d61ea 100644
@@ -12,8 +12,6 @@
 
 #include "sysemu/cpus.h"
 
-extern const CpusAccel whpx_cpus;
-
 int whpx_init_vcpu(CPUState *cpu);
 int whpx_vcpu_exec(CPUState *cpu);
 void whpx_destroy_vcpu(CPUState *cpu);
Signature · 1 line
2.26.2
#16 lore raw

RFC v6 10/11 accel: introduce AccelCPUClass extending CPUClass

In reply to Claudio Fontana

add a new optional interface to CPUClass, which allows accelerators to extend the CPUClass with additional accelerator-specific initializations.

---
 MAINTAINERS                 |  1 +
 accel/accel-common.c        | 43 +++++++++++++++++++++++++++++++++++++
 include/hw/core/accel-cpu.h | 28 ++++++++++++++++++++++++
 include/hw/core/cpu.h       |  4 ++++
 4 files changed, 76 insertions(+)
 create mode 100644 include/hw/core/accel-cpu.h
MAINTAINERS +1 -0
index df64a0d190..b99526e491 100644
@@ -435,6 +435,7 @@ R: Paolo Bonzini <[email protected]>
 S: Maintained
 F: include/qemu/accel.h
 F: include/sysemu/accel-ops.h
+F: include/hw/core/accel-cpu.h
 F: accel/accel-*.c
 F: accel/Makefile.objs
 F: accel/stubs/Makefile.objs
accel/accel-common.c +43 -0

65 lines not on this page · raw message

include/hw/core/accel-cpu.h new file +28 -0
new file mode 100644
index 0000000000..380e1c7436
@@ -0,0 +1,28 @@
+/*
+ * Accelerator interface, specializes CPUClass
+ *
+ * Copyright 2020 SUSE LLC
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef ACCEL_CPU_H
+#define ACCEL_CPU_H
+
+struct AccelCPUClass {
+    /*< private >*/
+    ObjectClass parent_class;
+    /*< public >*/
+
+    void (*cpu_class_init)(CPUClass *cc);
+    void (*cpu_instance_init)(CPUState *cpu);
+    void (*cpu_realizefn)(CPUState *cpu, Error **errp);
+};
+
+#define TYPE_ACCEL_CPU "accel-" CPU_RESOLVING_TYPE
+#define ACCEL_CPU_NAME(name) (name "-" TYPE_ACCEL_CPU)
+typedef struct AccelCPUClass AccelCPUClass;
+DECLARE_CLASS_CHECKERS(AccelCPUClass, ACCEL_CPU, TYPE_ACCEL_CPU)
+
+#endif /* ACCEL_CPU_H */
include/hw/core/cpu.h +4 -0
index 3d92c967ff..75eb1d8199 100644
@@ -76,6 +76,8 @@ typedef struct CPUWatchpoint CPUWatchpoint;
 
 struct TranslationBlock;
 
+struct AccelCPUClass;
+
 /**
  * CPUClass:
  * @class_by_name: Callback to map -cpu command line model name to an
@@ -227,6 +229,8 @@ struct CPUClass {
     /* Keep non-pointer data at the end to minimize holes.  */
     int gdb_num_core_regs;
     bool gdb_stop_before_watchpoint;
+
+    struct AccelCPUClass *accel_cpu_interface;
 };
 
 /*
Signature · 1 line
2.26.2
#17 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

accel/accel-common.c AccelClass *accel_find(const char *opt_name) · line 79

Quoted 3 lines · Claudio Fontana
accel/accel-common.c +3 -0
+    if (acc) {
+        object_class_foreach(accel_init_cpu_int_aux, cpu_type, false, acc);
+    }

Any reason to do it for cpu_type only, rather than for all subclasses of CPU_RESOLVING_TYPE? This would remove the cpu_type argument to accel_init_cpu_interfaces and accel_init_interfaces.

Otherwise I haven't done a careful review yet but it looks very nice, thanks!

Paolo

#18 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 5 lines · Paolo Bonzini

accel/accel-common.c AccelClass *accel_find(const char *opt_name) · line 79

Quoted 3 lines · Claudio Fontana
accel/accel-common.c +3 -0
+    if (acc) {
+        object_class_foreach(accel_init_cpu_int_aux, cpu_type, false, acc);
+    }
Quoted 9 lines

Any reason to do it for cpu_type only, rather than for all subclasses of CPU_RESOLVING_TYPE? This would remove the cpu_type argument to accel_init_cpu_interfaces and accel_init_interfaces.

Otherwise I haven't done a careful review yet but it looks very nice, thanks!

Paolo

Hi Paolo,

yes, I thought to pass cpu_type in order to set the interface only for the cpu that is actually used, instead of looping over all cpu models, just to be a bit quicker, but both things should work.

Ciao,

Claudio

#19 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 16 lines · Claudio Fontana
Quoted 5 lines · Paolo Bonzini

accel/accel-common.c AccelClass *accel_find(const char *opt_name) · line 79

Quoted 3 lines · Claudio Fontana
accel/accel-common.c +3 -0
+    if (acc) {
+        object_class_foreach(accel_init_cpu_int_aux, cpu_type, false, acc);
+    }
Quoted 9 lines

Any reason to do it for cpu_type only, rather than for all subclasses of CPU_RESOLVING_TYPE? This would remove the cpu_type argument to accel_init_cpu_interfaces and accel_init_interfaces.

Otherwise I haven't done a careful review yet but it looks very nice, thanks!

Paolo

Quoted 9 lines

Hi Paolo,

yes, I thought to pass cpu_type in order to set the interface only for the cpu that is actually used, instead of looping over all cpu models, just to be a bit quicker, but both things should work.

Ciao,

Claudio

Note that this actually creates a bug that is caught _ONLY_ by

acceptance-system-centos.

The gist of it is that cpu_type (or current_machine->default_cpu_type) is _not_ guaranteed to be set, the code there is a bit misleading I think.

I'll look into it, but just wanted to warn early about it.

Ciao,

Claudio

#20 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 31 lines · Claudio Fontana
Quoted 16 lines · Claudio Fontana
Quoted 5 lines · Paolo Bonzini

accel/accel-common.c AccelClass *accel_find(const char *opt_name) · line 79

Quoted 3 lines · Claudio Fontana
accel/accel-common.c +3 -0
+    if (acc) {
+        object_class_foreach(accel_init_cpu_int_aux, cpu_type, false, acc);
+    }
Quoted 9 lines

Any reason to do it for cpu_type only, rather than for all subclasses of CPU_RESOLVING_TYPE? This would remove the cpu_type argument to accel_init_cpu_interfaces and accel_init_interfaces.

Otherwise I haven't done a careful review yet but it looks very nice, thanks!

Paolo

Quoted 9 lines

Hi Paolo,

yes, I thought to pass cpu_type in order to set the interface only for the cpu that is actually used, instead of looping over all cpu models, just to be a bit quicker, but both things should work.

Ciao,

Claudio

Note that this actually creates a bug that is caught _ONLY_ by

acceptance-system-centos.

Quoted 9 lines

The gist of it is that cpu_type (or current_machine->default_cpu_type) is _not_ guaranteed to be set, the code there is a bit misleading I think.

I'll look into it, but just wanted to warn early about it.

Ciao,

Claudio

This seems to be due to "-machine none", is machine none supposed to have no default cpu_type? Is it expected that for machine none current_machine->cpu_type is NULL, or is it a bug?

Thanks,

Claudio

#21 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 3 lines · Claudio Fontana

This seems to be due to "-machine none", is machine none supposed to have no default cpu_type? Is it expected that for machine none current_machine->cpu_type is NULL, or is it a bug?

"-machine none" has no CPU at all, so I think anything is acceptable. There's also the possibility of emulating big.LITTLE machines in the future with >1 cpu_type, so the cop out of doing it on the whole hierarchy is easiest.

Paolo

#22 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 5 lines · Paolo Bonzini
Quoted 3 lines · Claudio Fontana

This seems to be due to "-machine none", is machine none supposed to have no default cpu_type? Is it expected that for machine none current_machine->cpu_type is NULL, or is it a bug?

Quoted 7 lines

"-machine none" has no CPU at all, so I think anything is acceptable. There's also the possibility of emulating big.LITTLE machines in the future with >1 cpu_type, so the cop out of doing it on the whole hierarchy is easiest.

Paolo

Ok will take that route then.

Thanks!

Claudio

#23 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

In reply to Paolo Bonzini
Quoted 5 lines · Paolo Bonzini

accel/accel-common.c AccelClass *accel_find(const char *opt_name) · line 79

Quoted 3 lines · Claudio Fontana
accel/accel-common.c +3 -0
+    if (acc) {
+        object_class_foreach(accel_init_cpu_int_aux, cpu_type, false, acc);
+    }
Quoted 9 lines

Any reason to do it for cpu_type only, rather than for all subclasses of CPU_RESOLVING_TYPE? This would remove the cpu_type argument to accel_init_cpu_interfaces and accel_init_interfaces.

Otherwise I haven't done a careful review yet but it looks very nice, thanks!

Paolo

Hi Paolo,

going back to this topic:

while doing some experiments in applying the ACCEL_CPU_TYPE classes for all targets (TCG for now, not KVM or other hw accels), and merging all tcg cpu ops,

I did encounter some issue.

For the simplest of targets like hppa for example, it works just fine, we can do:

static void hppa_tcg_cpu_class_init(CPUClass *cc)

{
    cc->tcg_ops.initialize = hppa_translate_init;
    cc->tcg_ops.do_interrupt = hppa_cpu_do_interrupt;
    cc->tcg_ops.cpu_exec_interrupt = hppa_cpu_exec_interrupt;
    cc->tcg_ops.synchronize_from_tb = hppa_cpu_synchronize_from_tb;
    cc->tcg_ops.tlb_fill = hppa_cpu_tlb_fill;
#ifndef CONFIG_USER_ONLY
    cc->tcg_ops.do_unaligned_access = hppa_cpu_do_unaligned_access;

#endif
}

*(later on I will try to change the cc->tcg_ops thing to something that ends up in cc->accel_cpu->tcg_ops->initialize, as I try to merge tcg_ops with accel_cpu, but this is spoiler of the future)*

static void hppa_tcg_cpu_accel_class_init(ObjectClass *oc, void *data)

{
    AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);

    acc->cpu_class_init = hppa_tcg_cpu_class_init;
}

static const TypeInfo hppa_tcg_cpu_accel_type = {
.name = ACCEL_CPU_NAME("tcg"),

.parent = TYPE_ACCEL_CPU,
.class_init = hppa_tcg_cpu_accel_class_init,
};

static void hppa_cpu_register_types(void)

{
    type_register_static(&hppa_cpu_type_info);
    type_register_static(&hppa_tcg_cpu_accel_type);
}

type_init(hppa_cpu_register_types)

So this is good.

But with things like cris/ for example,
the tcg functions to use are actually versioned per each subclass of TYPE_CRIS_CPU.

Different tcg_ops need to be used for different subclasses of the CPU_RESOLVING_TYPE.

So in order to avoid code in the class initialization like this:

if (version1) { then set the tcg ops for version 1; } if (version2) { then set the tcg ops for version 2; ...} etc,

we could define the right tcg op variants corresponding to the cpu variants, so that everything can be matched automatically.

But I think we'd need to pass explicitly the cpu type in accel_init_cpu_interfaces for this to work.. we could still in the future call accel_init_cpu_interfaces multiple times, once for each cpu model we want to use.

Or, we could do something else: we could delay the accel cpu interface initialization and call it in cpu_create(const char *typename), where typename needs to be known for sure.

This last option seems kinda attractive, but any ideas?

Thanks, ciao,

Claudio

#24 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 4 lines · Claudio Fontana

But with things like cris/ for example,
the tcg functions to use are actually versioned per each subclass of TYPE_CRIS_CPU.

Different tcg_ops need to be used for different subclasses of the CPU_RESOLVING_TYPE.

CRIS is not that bad since it's TCG only. You can just make it a field in CRISCPUClass and copy it over to tcg_ops.

I think ARM had something similar though, with different do_interrupt implementations for M and A processors. Somebody from Linaro was cleaning it up as part of some BQL work, but it was never merged. But even in that case, do_interrupt is somewhat special for ARM so making it an xxxCPUClass field makes sense.

Paolo

Quoted 14 lines

So in order to avoid code in the class initialization like this:

if (version1) { then set the tcg ops for version 1; } if (version2) { then set the tcg ops for version 2; ...} etc,

we could define the right tcg op variants corresponding to the cpu variants, so that everything can be matched automatically.

But I think we'd need to pass explicitly the cpu type in accel_init_cpu_interfaces for this to work.. we could still in the future call accel_init_cpu_interfaces multiple times, once for each cpu model we want to use.

Or, we could do something else: we could delay the accel cpu interface initialization and call it in cpu_create(const char *typename), where typename needs to be known for sure.

This last option seems kinda attractive, but any ideas?

#25 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 9 lines · Paolo Bonzini
Quoted 4 lines · Claudio Fontana

But with things like cris/ for example,
the tcg functions to use are actually versioned per each subclass of TYPE_CRIS_CPU.

Different tcg_ops need to be used for different subclasses of the CPU_RESOLVING_TYPE.

CRIS is not that bad since it's TCG only. You can just make it a field in CRISCPUClass and copy it over to tcg_ops.

Quoted 7 lines

I think ARM had something similar though, with different do_interrupt implementations for M and A processors. Somebody from Linaro was cleaning it up as part of some BQL work, but it was never merged. But even in that case, do_interrupt is somewhat special for ARM so making it an xxxCPUClass field makes sense.

Paolo

Ok that's a good alternative,

Quoted 6 lines
Quoted 6 lines

So in order to avoid code in the class initialization like this:

if (version1) { then set the tcg ops for version 1; } if (version2) { then set the tcg ops for version 2; ...} etc,

Quoted 7 lines
Quoted 7 lines

we could define the right tcg op variants corresponding to the cpu variants, so that everything can be matched automatically.

But I think we'd need to pass explicitly the cpu type in accel_init_cpu_interfaces for this to work.. we could still in the future call accel_init_cpu_interfaces multiple times, once for each cpu model we want to use.

Or, we could do something else: we could delay the accel cpu interface initialization and call it in cpu_create(const char *typename), where typename needs to be known for sure.

I take you don't like this idea to initialize the accel cpu interface in cpu_create()? It seems to make sense to me, but any drawbacks?

Ciao thanks!

Claudio

Quoted 2 lines
Quoted 2 lines

This last option seems kinda attractive, but any ideas?

#26 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 35 lines · Claudio Fontana
Quoted 9 lines · Paolo Bonzini
Quoted 4 lines · Claudio Fontana

But with things like cris/ for example,
the tcg functions to use are actually versioned per each subclass of TYPE_CRIS_CPU.

Different tcg_ops need to be used for different subclasses of the CPU_RESOLVING_TYPE.

CRIS is not that bad since it's TCG only. You can just make it a field in CRISCPUClass and copy it over to tcg_ops.

Quoted 7 lines

I think ARM had something similar though, with different do_interrupt implementations for M and A processors. Somebody from Linaro was cleaning it up as part of some BQL work, but it was never merged. But even in that case, do_interrupt is somewhat special for ARM so making it an xxxCPUClass field makes sense.

Paolo

Ok that's a good alternative,

Quoted 6 lines
Quoted 6 lines

So in order to avoid code in the class initialization like this:

if (version1) { then set the tcg ops for version 1; } if (version2) { then set the tcg ops for version 2; ...} etc,

Quoted 7 lines
Quoted 7 lines

we could define the right tcg op variants corresponding to the cpu variants, so that everything can be matched automatically.

But I think we'd need to pass explicitly the cpu type in accel_init_cpu_interfaces for this to work.. we could still in the future call accel_init_cpu_interfaces multiple times, once for each cpu model we want to use.

Or, we could do something else: we could delay the accel cpu interface initialization and call it in cpu_create(const char *typename), where typename needs to be known for sure.

Quoted 12 lines

I take you don't like this idea to initialize the accel cpu interface in cpu_create()? It seems to make sense to me, but any drawbacks?

Ciao thanks!

Claudio

Quoted 2 lines
Quoted 2 lines

This last option seems kinda attractive, but any ideas?

Oh I see, sadly, only user mode code seem to be guaranteed to go through cpu_create(), so there is probably no single code point, where we are guaranteed to see the creation of a cpu, everything is duplicated with explict calls to object_new in multiple places.

Hmm...

Ciao,

Claudio

#27 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 45 lines · Claudio Fontana
Quoted 44 lines · Claudio Fontana
Quoted 9 lines · Paolo Bonzini
Quoted 4 lines · Claudio Fontana

But with things like cris/ for example,
the tcg functions to use are actually versioned per each subclass of TYPE_CRIS_CPU.

Different tcg_ops need to be used for different subclasses of the CPU_RESOLVING_TYPE.

CRIS is not that bad since it's TCG only. You can just make it a field in CRISCPUClass and copy it over to tcg_ops.

Quoted 7 lines

I think ARM had something similar though, with different do_interrupt implementations for M and A processors. Somebody from Linaro was cleaning it up as part of some BQL work, but it was never merged. But even in that case, do_interrupt is somewhat special for ARM so making it an xxxCPUClass field makes sense.

Paolo

Ok that's a good alternative,

Quoted 6 lines
Quoted 6 lines

So in order to avoid code in the class initialization like this:

if (version1) { then set the tcg ops for version 1; } if (version2) { then set the tcg ops for version 2; ...} etc,

Quoted 7 lines
Quoted 7 lines

we could define the right tcg op variants corresponding to the cpu variants, so that everything can be matched automatically.

But I think we'd need to pass explicitly the cpu type in accel_init_cpu_interfaces for this to work.. we could still in the future call accel_init_cpu_interfaces multiple times, once for each cpu model we want to use.

Or, we could do something else: we could delay the accel cpu interface initialization and call it in cpu_create(const char *typename), where typename needs to be known for sure.

I take you don't like this idea to initialize the accel cpu interface in cpu_create()? It seems to make sense to me, but any drawbacks?

Ciao thanks!

Claudio

Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

This last option seems kinda attractive, but any ideas?

Oh I see, sadly, only user mode code seem to be guaranteed to go through cpu_create(), so there is probably no single code point, where we are guaranteed to see the creation of a cpu, everything is duplicated with explict calls to object_new in multiple places.

Hmm...

Well we can actually do it in the right place, that is in cpu_common_intfn, by calling accel_init_cpu_intefaces there, which kinda makes sense anyway... wdyt?

Ciao,

CLaudio

#28 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 50 lines · Claudio Fontana
Quoted 49 lines · Claudio Fontana
Quoted 47 lines · Claudio Fontana
Quoted 9 lines · Paolo Bonzini
Quoted 4 lines · Claudio Fontana

But with things like cris/ for example,
the tcg functions to use are actually versioned per each subclass of TYPE_CRIS_CPU.

Different tcg_ops need to be used for different subclasses of the CPU_RESOLVING_TYPE.

CRIS is not that bad since it's TCG only. You can just make it a field in CRISCPUClass and copy it over to tcg_ops.

Quoted 7 lines

I think ARM had something similar though, with different do_interrupt implementations for M and A processors. Somebody from Linaro was cleaning it up as part of some BQL work, but it was never merged. But even in that case, do_interrupt is somewhat special for ARM so making it an xxxCPUClass field makes sense.

Paolo

Ok that's a good alternative,

Quoted 6 lines
Quoted 6 lines

So in order to avoid code in the class initialization like this:

if (version1) { then set the tcg ops for version 1; } if (version2) { then set the tcg ops for version 2; ...} etc,

Quoted 7 lines
Quoted 7 lines

we could define the right tcg op variants corresponding to the cpu variants, so that everything can be matched automatically.

But I think we'd need to pass explicitly the cpu type in accel_init_cpu_interfaces for this to work.. we could still in the future call accel_init_cpu_interfaces multiple times, once for each cpu model we want to use.

Or, we could do something else: we could delay the accel cpu interface initialization and call it in cpu_create(const char *typename), where typename needs to be known for sure.

I take you don't like this idea to initialize the accel cpu interface in cpu_create()? It seems to make sense to me, but any drawbacks?

Ciao thanks!

Claudio

Quoted 2 lines
Quoted 2 lines

This last option seems kinda attractive, but any ideas?

Quoted 8 lines
Quoted 4 lines

Oh I see, sadly, only user mode code seem to be guaranteed to go through cpu_create(), so there is probably no single code point, where we are guaranteed to see the creation of a cpu, everything is duplicated with explict calls to object_new in multiple places.

Hmm...

Well we can actually do it in the right place, that is in cpu_common_intfn, by calling accel_init_cpu_intefaces there, which kinda makes sense anyway... wdyt?

But then the mapping becomes difficult.. actually I think we/I need to study carefully all targets to figure out the best way to associate a cpu subclass/model with its accel cpu interface. it's going to be next year now.

Happy holidays,

Claudio

#29 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 38 lines · Claudio Fontana
Quoted 37 lines · Claudio Fontana
Quoted 36 lines · Claudio Fontana
Quoted 35 lines · Claudio Fontana
Quoted 9 lines · Paolo Bonzini
Quoted 4 lines · Claudio Fontana

But with things like cris/ for example,
the tcg functions to use are actually versioned per each subclass of TYPE_CRIS_CPU.

Different tcg_ops need to be used for different subclasses of the CPU_RESOLVING_TYPE.

CRIS is not that bad since it's TCG only. You can just make it a field in CRISCPUClass and copy it over to tcg_ops.

Quoted 7 lines

I think ARM had something similar though, with different do_interrupt implementations for M and A processors. Somebody from Linaro was cleaning it up as part of some BQL work, but it was never merged. But even in that case, do_interrupt is somewhat special for ARM so making it an xxxCPUClass field makes sense.

Paolo

Ok that's a good alternative,

Quoted 13 lines
Quoted 13 lines

So in order to avoid code in the class initialization like this:

if (version1) { then set the tcg ops for version 1; } if (version2) { then set the tcg ops for version 2; ...} etc,

we could define the right tcg op variants corresponding to the cpu variants, so that everything can be matched automatically.

But I think we'd need to pass explicitly the cpu type in accel_init_cpu_interfaces for this to work.. we could still in the future call accel_init_cpu_interfaces multiple times, once for each cpu model we want to use.

Or, we could do something else: we could delay the accel cpu interface initialization and call it in cpu_create(const char *typename), where typename needs to be known for sure.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

I take you don't like this idea to initialize the accel cpu interface in cpu_create()? It seems to make sense to me, but any drawbacks?

Ciao thanks!

Claudio

Happy new year,

picking up this topic again, i am looking at at now a different aspect of this problem, of setting the right tcg ops for the right cpu class.

This issue I am highlighting is present because different targets behave differently in this regard.

Ie, we have targets for which we always initialize all cpu classes, as a result of different machine definitions.

This is the case of arm, for example where we end up with backtraces like:

arm_v7m_class_init
type_initialize
object_class_foreach_tramp
g_hash_table_foreach ()
object_class_foreach
object_class_get_list
select_machine ()
qemu_init
main

with the arm_v7m_class_init called even if we are just going to use an aarch64 cpu (so the class initializer for arm_v7m is called even for unused cpus classes),

while in other cases we have the target explicitly relying on the fact that only the right cpu class is initialized, for example in cris we have code like:

target/cris/cpu.c:

static void crisv9_cpu_class_init(ObjectClass *oc, void *data)

{
    CPUClass *cc = CPU_CLASS(oc);
    CRISCPUClass *ccc = CRIS_CPU_CLASS(oc);

    ccc->vr = 9;
    cc->do_interrupt = crisv10_cpu_do_interrupt;
    cc->gdb_read_register = crisv10_cpu_gdb_read_register;
    cc->tcg_initialize = cris_initialize_crisv10_tcg;
}

where the class initialization of the cpu is explicitly setting the methods of CPUClass, therefore implicitly relying on the fact that no other class initializer screws things up.

Given this context, which one of these methods is "right"? Should we rework things so that only used cpu classes are actually initialized? Or should we maybe not do these settings in cpu class_init at all, but rather at cpu initfn time, or at cpu realize time?

any comments/preferences?

Thanks,

Claudio

#30 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 86 lines · Claudio Fontana
Quoted 38 lines · Claudio Fontana
Quoted 37 lines · Claudio Fontana
Quoted 36 lines · Claudio Fontana
Quoted 35 lines · Claudio Fontana
Quoted 9 lines · Paolo Bonzini
Quoted 4 lines · Claudio Fontana

But with things like cris/ for example,
the tcg functions to use are actually versioned per each subclass of TYPE_CRIS_CPU.

Different tcg_ops need to be used for different subclasses of the CPU_RESOLVING_TYPE.

CRIS is not that bad since it's TCG only. You can just make it a field in CRISCPUClass and copy it over to tcg_ops.

Quoted 7 lines

I think ARM had something similar though, with different do_interrupt implementations for M and A processors. Somebody from Linaro was cleaning it up as part of some BQL work, but it was never merged. But even in that case, do_interrupt is somewhat special for ARM so making it an xxxCPUClass field makes sense.

Paolo

Ok that's a good alternative,

Quoted 13 lines
Quoted 13 lines

So in order to avoid code in the class initialization like this:

if (version1) { then set the tcg ops for version 1; } if (version2) { then set the tcg ops for version 2; ...} etc,

we could define the right tcg op variants corresponding to the cpu variants, so that everything can be matched automatically.

But I think we'd need to pass explicitly the cpu type in accel_init_cpu_interfaces for this to work.. we could still in the future call accel_init_cpu_interfaces multiple times, once for each cpu model we want to use.

Or, we could do something else: we could delay the accel cpu interface initialization and call it in cpu_create(const char *typename), where typename needs to be known for sure.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

I take you don't like this idea to initialize the accel cpu interface in cpu_create()? It seems to make sense to me, but any drawbacks?

Ciao thanks!

Claudio

Happy new year,

picking up this topic again, i am looking at at now a different aspect of this problem, of setting the right tcg ops for the right cpu class.

This issue I am highlighting is present because different targets behave differently in this regard.

Ie, we have targets for which we always initialize all cpu classes, as a result of different machine definitions.

This is the case of arm, for example where we end up with backtraces like:

arm_v7m_class_init
type_initialize
object_class_foreach_tramp
g_hash_table_foreach ()
object_class_foreach
object_class_get_list
select_machine ()
qemu_init
main

with the arm_v7m_class_init called even if we are just going to use an aarch64 cpu (so the class initializer for arm_v7m is called even for unused cpus classes),

while in other cases we have the target explicitly relying on the fact that only the right cpu class is initialized, for example in cris we have code like:

target/cris/cpu.c:

static void crisv9_cpu_class_init(ObjectClass *oc, void *data)

{
    CPUClass *cc = CPU_CLASS(oc);
    CRISCPUClass *ccc = CRIS_CPU_CLASS(oc);

    ccc->vr = 9;
    cc->do_interrupt = crisv10_cpu_do_interrupt;
    cc->gdb_read_register = crisv10_cpu_gdb_read_register;
    cc->tcg_initialize = cris_initialize_crisv10_tcg;
}
Quoted 7 lines

where the class initialization of the cpu is explicitly setting the methods of CPUClass, therefore implicitly relying on the fact that no other class initializer screws things up.

Given this context, which one of these methods is "right"? Should we rework things so that only used cpu classes are actually initialized? Or should we maybe not do these settings in cpu class_init at all, but rather at cpu initfn time, or at cpu realize time?

any comments/preferences?

Or is the hierarchy magically fixing this for us (ie, we rely on the class initializers being called again when the cpu we are actually going to be used is going to be created?) That seems the likely solution right?

Thanks,

Claudio

#31 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

In reply to Claudio Fontana
Quoted 1 line · Claudio Fontana

Happy new year,

Hi!

Quoted 19 lines

picking up this topic again, i am looking at at now a different aspect of this problem, of setting the right tcg ops for the right cpu class.

This issue I am highlighting is present because different targets behave differently in this regard.

Ie, we have targets for which we always initialize all cpu classes, as a result of different machine definitions.

This is the case of arm, for example where we end up with backtraces like:

arm_v7m_class_init
type_initialize
object_class_foreach_tramp
g_hash_table_foreach ()
object_class_foreach
object_class_get_list
select_machine ()
qemu_init
main

Quoted 3 lines

with the arm_v7m_class_init called even if we are just going to use an aarch64 cpu (so the class initializer for arm_v7m is called even for unused cpus classes),

while in other cases we have the target explicitly relying on the fact that only the right cpu class is initialized, for example in cris we have code like:

This shouldn't matter at all, because class_init is not supposed to have any side effects outside the corresponding ObjectClass struct.

So, I don't understand what you mean below:

Quoted 14 lines

target/cris/cpu.c:

static void crisv9_cpu_class_init(ObjectClass *oc, void *data)

{
    CPUClass *cc = CPU_CLASS(oc);
    CRISCPUClass *ccc = CRIS_CPU_CLASS(oc);

    ccc->vr = 9;
    cc->do_interrupt = crisv10_cpu_do_interrupt;
    cc->gdb_read_register = crisv10_cpu_gdb_read_register;
    cc->tcg_initialize = cris_initialize_crisv10_tcg;
}
Quoted 1 line

where the class initialization of the cpu is explicitly setting the methods of CPUClass, therefore implicitly relying on the fact that no other class initializer screws things up.

I don't see the problem here. Having all other class initializers being called should be completely OK, because each class has its own ObjectClass struct.

Quoted 3 lines

Given this context, which one of these methods is "right"?
Should we rework things so that only used cpu classes are actually initialized?

This option wouldn't make sense. class_init is supposed to be called on demand on class lookup, and can be triggered by object_class_get_list(), object_class_by_name(), or similar functions. This is by design.

Quoted 1 line

Or should we maybe not do these settings in cpu class_init at all, but rather at cpu initfn time, or at cpu realize time?

If you are talking about initializing ObjectClass/CPUClass/...Class fields, they can always be safely initialized in class_init.

If you are talking about touching anything outside the class struct (like in CPUState), class_init is not the right place to do it.

Signature · 1 line
Eduardo
#32 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 65 lines · Eduardo Habkost
Quoted 1 line · Claudio Fontana

Happy new year,

Hi!

Quoted 19 lines

picking up this topic again, i am looking at at now a different aspect of this problem, of setting the right tcg ops for the right cpu class.

This issue I am highlighting is present because different targets behave differently in this regard.

Ie, we have targets for which we always initialize all cpu classes, as a result of different machine definitions.

This is the case of arm, for example where we end up with backtraces like:

arm_v7m_class_init
type_initialize
object_class_foreach_tramp
g_hash_table_foreach ()
object_class_foreach
object_class_get_list
select_machine ()
qemu_init
main

Quoted 3 lines

with the arm_v7m_class_init called even if we are just going to use an aarch64 cpu (so the class initializer for arm_v7m is called even for unused cpus classes),

while in other cases we have the target explicitly relying on the fact that only the right cpu class is initialized, for example in cris we have code like:

This shouldn't matter at all, because class_init is not supposed to have any side effects outside the corresponding ObjectClass struct.

So, I don't understand what you mean below:

Quoted 14 lines

target/cris/cpu.c:

static void crisv9_cpu_class_init(ObjectClass *oc, void *data)

{
    CPUClass *cc = CPU_CLASS(oc);
    CRISCPUClass *ccc = CRIS_CPU_CLASS(oc);

    ccc->vr = 9;
    cc->do_interrupt = crisv10_cpu_do_interrupt;
    cc->gdb_read_register = crisv10_cpu_gdb_read_register;
    cc->tcg_initialize = cris_initialize_crisv10_tcg;
}
Quoted 1 line

where the class initialization of the cpu is explicitly setting the methods of CPUClass, therefore implicitly relying on the fact that no other class initializer screws things up.

I don't see the problem here. Having all other class initializers being called should be completely OK, because each class has its own ObjectClass struct.

Quoted 3 lines

Given this context, which one of these methods is "right"?
Should we rework things so that only used cpu classes are actually initialized?

This option wouldn't make sense. class_init is supposed to be called on demand on class lookup, and can be triggered by object_class_get_list(), object_class_by_name(), or similar functions. This is by design.

Quoted 5 lines
Quoted 1 line

Or should we maybe not do these settings in cpu class_init at all, but rather at cpu initfn time, or at cpu realize time?

If you are talking about initializing ObjectClass/CPUClass/...Class fields, they can always be safely initialized in class_init.

Ok, so I can initialize the CPUClass fields for the tcg ops in the CPUClass subclass class inits safely..

Thanks for clearing this up!

Claudio

Quoted 5 lines

If you are talking about touching anything outside the class struct (like in CPUState), class_init is not the right place to do it.

#33 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

In reply to Claudio Fontana
Quoted 6 lines · Claudio Fontana

add a new optional interface to CPUClass, which allows accelerators to extend the CPUClass with additional accelerator-specific initializations.

---

[...]

accel/accel-common.c AccelClass *accel_find(const char *opt_name) · line 61

Quoted 10 lines
accel/accel-common.c +10 -0
+static void accel_init_cpu_int_aux(ObjectClass *klass, void *opaque)
+{
+    CPUClass *cc = CPU_CLASS(klass);
+    AccelCPUClass *accel_cpu_interface = opaque;
+
+    cc->accel_cpu_interface = accel_cpu_interface;
+    if (accel_cpu_interface->cpu_class_init) {
+        accel_cpu_interface->cpu_class_init(cc);
+    }
+}

So, now that the approach we're following to trigger the accel_init_cpu*() call is less controversial (thanks for your patience!), we can try to address the monkey patching issue:

Monkey patching classes like this is acceptable as an initial solution, but I'd like us to have a plan to eventually get rid of it. Monkey patching CPU classes makes querying of CPU model information less predictable and subtly dependent on QEMU initialization state.

Removing CPUClass.accel_cpu_interface may be easy, because it should be possible to just call current_accel() when realizing CPUs. Getting rid of CPUClass.cpu_class_init might be more difficult, depending on what the ->cpu_class_init() function is doing.

Quoted 28 lines
accel/accel-common.c +22 -0
+
+/* initialize the arch-specific accel CpuClass interfaces */
+static void accel_init_cpu_interfaces(AccelClass *ac, const char *cpu_type)
+{
+    const char *ac_name; /* AccelClass name */
+    char *acc_name;      /* AccelCPUClass name */
+    ObjectClass *acc;    /* AccelCPUClass */
+
+    ac_name = object_class_get_name(OBJECT_CLASS(ac));
+    g_assert(ac_name != NULL);
+
+    acc_name = g_strdup_printf("%s-%s", ac_name, CPU_RESOLVING_TYPE);
+    acc = object_class_by_name(acc_name);
+    g_free(acc_name);
+
+    if (acc) {
+        object_class_foreach(accel_init_cpu_int_aux, cpu_type, false, acc);
+    }
+}
+
 void accel_init_interfaces(AccelClass *ac, const char *cpu_type)
 {
 #ifndef CONFIG_USER_ONLY
     accel_init_ops_interfaces(ac);
 #endif /* !CONFIG_USER_ONLY */
+
+    accel_init_cpu_interfaces(ac, cpu_type);
 }

[...]

Signature · 1 line
Eduardo
#34 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 23 lines · Eduardo Habkost
Quoted 6 lines · Claudio Fontana

add a new optional interface to CPUClass, which allows accelerators to extend the CPUClass with additional accelerator-specific initializations.

---

[...]

accel/accel-common.c AccelClass *accel_find(const char *opt_name) · line 61

Quoted 10 lines
accel/accel-common.c +10 -0
+static void accel_init_cpu_int_aux(ObjectClass *klass, void *opaque)
+{
+    CPUClass *cc = CPU_CLASS(klass);
+    AccelCPUClass *accel_cpu_interface = opaque;
+
+    cc->accel_cpu_interface = accel_cpu_interface;
+    if (accel_cpu_interface->cpu_class_init) {
+        accel_cpu_interface->cpu_class_init(cc);
+    }
+}

So, now that the approach we're following to trigger the accel_init_cpu*() call is less controversial (thanks for your patience!), we can try to address the monkey patching issue:

Quoted 5 lines

Monkey patching classes like this is acceptable as an initial solution, but I'd like us to have a plan to eventually get rid of it. Monkey patching CPU classes makes querying of CPU model information less predictable and subtly dependent on QEMU initialization state.

The question of QEMU initialization state and the querying of supported functionality, also in relationship with the loadable modules, is I think a larger discussion.

Regardless of the amount of glue code and lipstick, this is hiding the fact that the fundamentals of the object hierarchy for cpus are wrong, and are (unfortunately) codified as part of the external interface.

Quoted 6 lines

Removing CPUClass.accel_cpu_interface may be easy, because it should be possible to just call current_accel() when realizing CPUs. Getting rid of CPUClass.cpu_class_init might be more difficult, depending on what the ->cpu_class_init() function is doing.

This seems to be for a next step to me.

Ciao,

Claudio

Quoted 31 lines
Quoted 29 lines
accel/accel-common.c +22 -0
+
+/* initialize the arch-specific accel CpuClass interfaces */
+static void accel_init_cpu_interfaces(AccelClass *ac, const char *cpu_type)
+{
+    const char *ac_name; /* AccelClass name */
+    char *acc_name;      /* AccelCPUClass name */
+    ObjectClass *acc;    /* AccelCPUClass */
+
+    ac_name = object_class_get_name(OBJECT_CLASS(ac));
+    g_assert(ac_name != NULL);
+
+    acc_name = g_strdup_printf("%s-%s", ac_name, CPU_RESOLVING_TYPE);
+    acc = object_class_by_name(acc_name);
+    g_free(acc_name);
+
+    if (acc) {
+        object_class_foreach(accel_init_cpu_int_aux, cpu_type, false, acc);
+    }
+}
+
 void accel_init_interfaces(AccelClass *ac, const char *cpu_type)
 {
 #ifndef CONFIG_USER_ONLY
     accel_init_ops_interfaces(ac);
 #endif /* !CONFIG_USER_ONLY */
+
+    accel_init_cpu_interfaces(ac, cpu_type);
 }

[...]

#35 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 31 lines · Claudio Fontana
Quoted 23 lines · Eduardo Habkost
Quoted 6 lines · Claudio Fontana

add a new optional interface to CPUClass, which allows accelerators to extend the CPUClass with additional accelerator-specific initializations.

---

[...]

accel/accel-common.c AccelClass *accel_find(const char *opt_name) · line 61

Quoted 10 lines
accel/accel-common.c +10 -0
+static void accel_init_cpu_int_aux(ObjectClass *klass, void *opaque)
+{
+    CPUClass *cc = CPU_CLASS(klass);
+    AccelCPUClass *accel_cpu_interface = opaque;
+
+    cc->accel_cpu_interface = accel_cpu_interface;
+    if (accel_cpu_interface->cpu_class_init) {
+        accel_cpu_interface->cpu_class_init(cc);
+    }
+}

So, now that the approach we're following to trigger the accel_init_cpu*() call is less controversial (thanks for your patience!), we can try to address the monkey patching issue:

Quoted 5 lines

Monkey patching classes like this is acceptable as an initial solution, but I'd like us to have a plan to eventually get rid of it. Monkey patching CPU classes makes querying of CPU model information less predictable and subtly dependent on QEMU initialization state.

Quoted 4 lines

The question of QEMU initialization state and the querying of supported functionality, also in relationship with the loadable modules, is I think a larger discussion.

Regardless of the amount of glue code and lipstick, this is hiding the fact that the fundamentals of the object hierarchy for cpus are wrong, and are (unfortunately) codified as part of the external interface.

That's probably right, and removal of monkey patching might force us to change our external interfaces.

Quoted 11 lines
Quoted 8 lines

Removing CPUClass.accel_cpu_interface may be easy, because it should be possible to just call current_accel() when realizing CPUs. Getting rid of CPUClass.cpu_class_init might be more difficult, depending on what the ->cpu_class_init() function is doing.

This seems to be for a next step to me.

Agreed, although I'd like to understand what makes AccelCPUClass.cpu_class_init() so important in the first version (considering that existing x86_cpu_class_init() has zero tcg_enabled() calls today).

Signature · 1 line
Eduardo
#36 lore raw

Re: [RFC v6 10/11] accel: introduce AccelCPUClass extending CPUClass

Quoted 50 lines · Eduardo Habkost
Quoted 31 lines · Claudio Fontana
Quoted 23 lines · Eduardo Habkost
Quoted 6 lines · Claudio Fontana

add a new optional interface to CPUClass, which allows accelerators to extend the CPUClass with additional accelerator-specific initializations.

---

[...]

accel/accel-common.c AccelClass *accel_find(const char *opt_name) · line 61

Quoted 10 lines
accel/accel-common.c +10 -0
+static void accel_init_cpu_int_aux(ObjectClass *klass, void *opaque)
+{
+    CPUClass *cc = CPU_CLASS(klass);
+    AccelCPUClass *accel_cpu_interface = opaque;
+
+    cc->accel_cpu_interface = accel_cpu_interface;
+    if (accel_cpu_interface->cpu_class_init) {
+        accel_cpu_interface->cpu_class_init(cc);
+    }
+}

So, now that the approach we're following to trigger the accel_init_cpu*() call is less controversial (thanks for your patience!), we can try to address the monkey patching issue:

Quoted 5 lines

Monkey patching classes like this is acceptable as an initial solution, but I'd like us to have a plan to eventually get rid of it. Monkey patching CPU classes makes querying of CPU model information less predictable and subtly dependent on QEMU initialization state.

Quoted 4 lines

The question of QEMU initialization state and the querying of supported functionality, also in relationship with the loadable modules, is I think a larger discussion.

Regardless of the amount of glue code and lipstick, this is hiding the fact that the fundamentals of the object hierarchy for cpus are wrong, and are (unfortunately) codified as part of the external interface.

That's probably right, and removal of monkey patching might force us to change our external interfaces.

Quoted 10 lines
Quoted 8 lines

Removing CPUClass.accel_cpu_interface may be easy, because it should be possible to just call current_accel() when realizing CPUs. Getting rid of CPUClass.cpu_class_init might be more difficult, depending on what the ->cpu_class_init() function is doing.

Quoted 7 lines
Quoted 1 line

This seems to be for a next step to me.

Agreed, although I'd like to understand what makes AccelCPUClass.cpu_class_init() so important in the first version (considering that existing x86_cpu_class_init() has zero tcg_enabled() calls today).

currently x86_cpu_common_class_init() has

#ifdef CONFIG_TCG

and

#ifdef CONFIG_USER_ONLY

I move this code to a tcg specific module,
and I also move the parts that should have been CONFIG_TCG before but were probably just missed.

Ciao,

Claudio

#37 lore raw

RFC v6 11/11 i386: split cpu accelerators from cpu.c, using AccelCPUClass

In reply to Claudio Fontana

i386 is the first user of AccelCPUClass, allowing to split cpu.c into:

cpu.c            cpuid and common x86 cpu functionality
host-cpu.c       host x86 cpu functions and "host" cpu type
kvm/cpu.c        KVM x86 AccelCPUClass
hvf/cpu.c        HVF x86 AccelCPUClass
tcg/cpu.c        TCG x86 AccelCPUClass
---
 MAINTAINERS                 |   2 +-
 hw/i386/pc_piix.c           |   1 +
 target/i386/cpu.c           | 386 ++++--------------------------------
 target/i386/cpu.h           |  20 +-
 target/i386/host-cpu.c      | 198 ++++++++++++++++++
 target/i386/host-cpu.h      |  19 ++
 target/i386/hvf/cpu.c       |  65 ++++++
 target/i386/hvf/meson.build |   1 +
 target/i386/kvm/cpu.c       | 148 ++++++++++++++
 target/i386/kvm/kvm-cpu.h   |  41 ++++
 target/i386/kvm/kvm.c       |   3 +-
 target/i386/kvm/meson.build |   7 +-
 target/i386/meson.build     |   8 +-
 target/i386/tcg-cpu.c       |  71 -------
 target/i386/tcg-cpu.h       |  15 --
 target/i386/tcg/cpu.c       | 173 ++++++++++++++++
 target/i386/tcg/meson.build |   3 +-
 17 files changed, 711 insertions(+), 450 deletions(-)
 create mode 100644 target/i386/host-cpu.c
 create mode 100644 target/i386/host-cpu.h
 create mode 100644 target/i386/hvf/cpu.c
 create mode 100644 target/i386/kvm/cpu.c
 create mode 100644 target/i386/kvm/kvm-cpu.h
 delete mode 100644 target/i386/tcg-cpu.c
 delete mode 100644 target/i386/tcg-cpu.h
 create mode 100644 target/i386/tcg/cpu.c
MAINTAINERS +1 -1
index b99526e491..c7fff31888 100644
@@ -336,7 +336,7 @@ M: Paolo Bonzini <[email protected]>
 M: Richard Henderson <[email protected]>
 M: Eduardo Habkost <[email protected]>
 S: Maintained
-F: target/i386/
+F: target/i386/tcg/
 F: tests/tcg/i386/
 F: tests/tcg/x86_64/
 F: hw/i386/
hw/i386/pc_piix.c +1 -0
index 13d1628f13..d3f013f3a1 100644
@@ -64,6 +64,7 @@
 #include "hw/hyperv/vmbus-bridge.h"
 #include "hw/mem/nvdimm.h"
 #include "hw/i386/acpi-build.h"
+#include "kvm/kvm-cpu.h"
 
 #define MAX_IDE_BUS 2
 
target/i386/cpu.c +40 -346

550 lines not on this page · raw message

target/i386/cpu.h +8 -12
index a0d64613dc..b3e39fc631 100644
@@ -1905,13 +1905,20 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo,
                            void *puc);
 
 /* cpu.c */
+void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,
+                              uint32_t vendor2, uint32_t vendor3);
+typedef struct PropValue {
+    const char *prop, *value;
+} PropValue;
+void x86_cpu_apply_props(X86CPU *cpu, PropValue *props);
+
+/* cpu.c other functions (cpuid) */
 void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
                    uint32_t *eax, uint32_t *ebx,
                    uint32_t *ecx, uint32_t *edx);
 void cpu_clear_apic_feature(CPUX86State *env);
 void host_cpuid(uint32_t function, uint32_t count,
                 uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
-void host_vendor_fms(char *vendor, int *family, int *model, int *stepping);
 
 /* helper.c */
 void x86_cpu_set_a20(X86CPU *cpu, int a20_state);
@@ -2111,17 +2118,6 @@ void cpu_report_tpr_access(CPUX86State *env, TPRAccess access);
 void apic_handle_tpr_access_report(DeviceState *d, target_ulong ip,
                                    TPRAccess access);
 
-
-/* Change the value of a KVM-specific default
- *
- * If value is NULL, no default will be set and the original
- * value from the CPU model table will be kept.
- *
- * It is valid to call this function only for properties that
- * are already present in the kvm_default_props table.
- */
-void x86_cpu_change_kvm_default(const char *prop, const char *value);
-
 /* Special values for X86CPUVersion: */
 
 /* Resolve to latest CPU version */
target/i386/host-cpu.c new file +198 -0

198 lines not on this page · raw message

target/i386/host-cpu.h new file +19 -0
new file mode 100644
index 0000000000..d1f2644422
@@ -0,0 +1,19 @@
+/*
+ * x86 host CPU type initialization and host CPU functions
+ *
+ * Copyright 2020 SUSE LLC
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef HOST_CPU_H
+#define HOST_CPU_H
+
+void host_cpu_instance_init(X86CPU *cpu);
+void host_cpu_max_instance_init(X86CPU *cpu);
+void host_cpu_realizefn(CPUState *cs, Error **errp);
+
+void host_cpu_vendor_fms(char *vendor, int *family, int *model, int *stepping);
+
+#endif /* HOST_CPU_H */
target/i386/hvf/cpu.c new file +65 -0

65 lines not on this page · raw message

target/i386/hvf/meson.build +1 -0
index 409c9a3f14..a7fba5724c 100644
@@ -10,4 +10,5 @@ i386_softmmu_ss.add(when: [hvf, 'CONFIG_HVF'], if_true: files(
   'x86_mmu.c',
   'x86_task.c',
   'x86hvf.c',
+  'cpu.c',
 ))
target/i386/kvm/cpu.c new file +148 -0

148 lines not on this page · raw message

target/i386/kvm/kvm-cpu.h new file +41 -0

41 lines not on this page · raw message

target/i386/kvm/kvm.c +2 -1
index a2934dda02..35c86fdba6 100644
@@ -22,6 +22,7 @@
 #include "standard-headers/asm-x86/kvm_para.h"
 
 #include "cpu.h"
+#include "host-cpu.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/hw_accel.h"
 #include "sysemu/kvm_int.h"
@@ -285,7 +286,7 @@ static bool host_tsx_broken(void)
     int family, model, stepping;\
     char vendor[CPUID_VENDOR_SZ + 1];
 
-    host_vendor_fms(vendor, &family, &model, &stepping);
+    host_cpu_vendor_fms(vendor, &family, &model, &stepping);
 
     /* Check if we are running on a Haswell host known to have broken TSX */
     return !strcmp(vendor, CPUID_VENDOR_INTEL) &&
target/i386/kvm/meson.build +6 -1
index 1d66559187..0bc3724eb3 100644
@@ -1,3 +1,8 @@
 i386_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
-i386_softmmu_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'))
+
+i386_softmmu_ss.add(when: 'CONFIG_KVM', if_true: files(
+  'kvm.c',
+  'cpu.c',
+))
+
 i386_softmmu_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_false: files('hyperv-stub.c'))
target/i386/meson.build +6 -2
index 9c20208e5a..4e6e915e7f 100644
@@ -6,8 +6,12 @@ i386_ss.add(files(
   'xsave_helper.c',
   'cpu-dump.c',
 ))
-i386_ss.add(when: 'CONFIG_TCG', if_true: files('tcg-cpu.c'))
-i386_ss.add(when: 'CONFIG_SEV', if_true: files('sev.c'), if_false: files('sev-stub.c'))
+
+i386_ss.add(when: 'CONFIG_SEV', if_true: files('host-cpu.c', 'sev.c'), if_false: files('sev-stub.c'))
+
+# x86 cpu type
+i386_ss.add(when: 'CONFIG_KVM', if_true: files('host-cpu.c'))
+i386_ss.add(when: 'CONFIG_HVF', if_true: files('host-cpu.c'))
 
 i386_softmmu_ss = ss.source_set()
 i386_softmmu_ss.add(files(
target/i386/tcg-cpu.c deleted +0 -71

71 lines not on this page · raw message

target/i386/tcg-cpu.h deleted +0 -15
deleted file mode 100644
index 81f02e562e..0000000000
@@ -1,15 +0,0 @@
-/*
- * i386 TCG CPU class initialization
- *
- * Copyright 2020 SUSE LLC
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#ifndef TCG_CPU_H
-#define TCG_CPU_H
-
-void tcg_cpu_common_class_init(CPUClass *cc);
-
-#endif /* TCG_CPU_H */
target/i386/tcg/cpu.c new file +173 -0

173 lines not on this page · raw message

target/i386/tcg/meson.build +2 -1
index 02794226c2..9e439df9c7 100644
@@ -10,4 +10,5 @@ i386_ss.add(when: 'CONFIG_TCG', if_true: files(
   'seg_helper.c',
   'smm_helper.c',
   'svm_helper.c',
-  'translate.c'), if_false: files('tcg-stub.c'))
+  'translate.c',
+  'cpu.c'), if_false: files('tcg-stub.c'))
Signature · 1 line
2.26.2
#38 lore raw

Re: [RFC v6 11/11] i386: split cpu accelerators from cpu.c, using AccelCPUClass

Quoted 11 lines · Claudio Fontana

i386 is the first user of AccelCPUClass, allowing to split cpu.c into:

cpu.c            cpuid and common x86 cpu functionality
host-cpu.c       host x86 cpu functions and "host" cpu type
kvm/cpu.c        KVM x86 AccelCPUClass
hvf/cpu.c        HVF x86 AccelCPUClass
tcg/cpu.c        TCG x86 AccelCPUClass

---

[...]

Quoted 1 line

+static void tcg_cpu_class_init(CPUClass *cc)

Is this the only case where we need to provide an
AccelCPUClass.cpu_class_init method?

target/i386/tcg/cpu.c line 136

Quoted 11 lines
target/i386/tcg/cpu.c new file +11 -0
+{
+    cc->do_interrupt = x86_cpu_do_interrupt;
+    cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;
+    cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
+    cc->cpu_exec_enter = x86_cpu_exec_enter;
+    cc->cpu_exec_exit = x86_cpu_exec_exit;
+    cc->tcg_initialize = tcg_x86_init;
+    cc->tlb_fill = x86_cpu_tlb_fill;
+#ifndef CONFIG_USER_ONLY
+    cc->debug_excp_handler = breakpoint_handler;
+#endif /* !CONFIG_USER_ONLY */

I find the need for these method overrides suspicious.

Comparing this with the code on qemu.git master:

static void x86_cpu_common_class_init(ObjectClass *oc, void *data)

{
    [...]
#ifdef CONFIG_TCG
    cc->do_interrupt = x86_cpu_do_interrupt;
    cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;
#endif
    [...]
    cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
    [...]
#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
    cc->debug_excp_handler = breakpoint_handler;
#endif
    cc->cpu_exec_enter = x86_cpu_exec_enter;
    cc->cpu_exec_exit = x86_cpu_exec_exit;
#ifdef CONFIG_TCG
    cc->tcg_initialize = tcg_x86_init;
    cc->tlb_fill = x86_cpu_tlb_fill;
#endif
    [...]
}

So, we have two kinds of CPUClass fields above:
* Code that was never conditional on CONFIG_TCG, and now is conditional (synchronize_from_tb, cpu_exec_enter, cpu_exec_exit).
* Code that was conditional on CONFIG_TCG at compile time, and is now conditional on TCG being enabled at runtime.

On both cases, we are replacing static initialization of CPUClass fields with dynamically initialization of CPUClass depending on the chosen accelerator. What makes this necessary?

Quoted 52 lines
target/i386/tcg/cpu.c new file +37 -0
+}
+
+/*
+ * TCG-specific defaults that override all CPU models when using TCG
+ */
+static PropValue tcg_default_props[] = {
+    { "vme", "off" },
+    { NULL, NULL },
+};
+
+static void tcg_cpu_instance_init(CPUState *cs)
+{
+    X86CPU *cpu = X86_CPU(cs);
+    /* Special cases not set in the X86CPUDefinition structs: */
+    x86_cpu_apply_props(cpu, tcg_default_props);
+}
+
+static void tcg_cpu_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
+
+    acc->cpu_realizefn = tcg_cpu_realizefn;
+    acc->cpu_class_init = tcg_cpu_class_init;
+    acc->cpu_instance_init = tcg_cpu_instance_init;
+}
+static const TypeInfo tcg_cpu_accel_type_info = {
+    .name = ACCEL_CPU_NAME("tcg"),
+
+    .parent = TYPE_ACCEL_CPU,
+    .class_init = tcg_cpu_accel_class_init,
+    .abstract = true,
+};
+static void tcg_cpu_accel_register_types(void)
+{
+    type_register_static(&tcg_cpu_accel_type_info);
+}
+type_init(tcg_cpu_accel_register_types);
target/i386/tcg/meson.build +2 -1
index 02794226c2..9e439df9c7 100644
@@ -10,4 +10,5 @@ i386_ss.add(when: 'CONFIG_TCG', if_true: files(
   'seg_helper.c',
   'smm_helper.c',
   'svm_helper.c',
-  'translate.c'), if_false: files('tcg-stub.c'))
+  'translate.c',
+  'cpu.c'), if_false: files('tcg-stub.c'))
Signature · 1 line
2.26.2
Signature · 1 line
Eduardo
#39 lore raw

Re: [RFC v6 11/11] i386: split cpu accelerators from cpu.c, using AccelCPUClass

Quoted 19 lines · Eduardo Habkost
Quoted 11 lines · Claudio Fontana

i386 is the first user of AccelCPUClass, allowing to split cpu.c into:

cpu.c            cpuid and common x86 cpu functionality
host-cpu.c       host x86 cpu functions and "host" cpu type
kvm/cpu.c        KVM x86 AccelCPUClass
hvf/cpu.c        HVF x86 AccelCPUClass
tcg/cpu.c        TCG x86 AccelCPUClass

---

[...]

Quoted 1 line

+static void tcg_cpu_class_init(CPUClass *cc)

Is this the only case where we need to provide an
AccelCPUClass.cpu_class_init method?

Quoted 13 lines

target/i386/tcg/cpu.c line 136

Quoted 11 lines
target/i386/tcg/cpu.c new file +11 -0
+{
+    cc->do_interrupt = x86_cpu_do_interrupt;
+    cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;
+    cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
+    cc->cpu_exec_enter = x86_cpu_exec_enter;
+    cc->cpu_exec_exit = x86_cpu_exec_exit;
+    cc->tcg_initialize = tcg_x86_init;
+    cc->tlb_fill = x86_cpu_tlb_fill;
+#ifndef CONFIG_USER_ONLY
+    cc->debug_excp_handler = breakpoint_handler;
+#endif /* !CONFIG_USER_ONLY */

I find the need for these method overrides suspicious.

These mechanisms are preexistent. My refactoring only makes them more visible.

Quoted 25 lines

Comparing this with the code on qemu.git master:

static void x86_cpu_common_class_init(ObjectClass *oc, void *data)

{
    [...]
#ifdef CONFIG_TCG
    cc->do_interrupt = x86_cpu_do_interrupt;
    cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;
#endif
    [...]
    cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
    [...]
#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
    cc->debug_excp_handler = breakpoint_handler;
#endif
    cc->cpu_exec_enter = x86_cpu_exec_enter;
    cc->cpu_exec_exit = x86_cpu_exec_exit;
#ifdef CONFIG_TCG
    cc->tcg_initialize = tcg_x86_init;
    cc->tlb_fill = x86_cpu_tlb_fill;
#endif
    [...]
}
Quoted 4 lines

So, we have two kinds of CPUClass fields above:
* Code that was never conditional on CONFIG_TCG, and now is conditional (synchronize_from_tb, cpu_exec_enter, cpu_exec_exit).

synchronize_from_tb, cpu_exec_enter and cpu_exec_exit only makes sense for TCG, and their code should not be compiled in for non-TCG.

This is part of the effort to separate away non-pertinent code into accelerator-specific builds (and in the future modules).

The fact that they were unconditionally compiled in before was a mistake, or at least this is the assumption I am making when changing this.

Quoted 6 lines

* Code that was conditional on CONFIG_TCG at compile time, and is now conditional on TCG being enabled at runtime.

On both cases, we are replacing static initialization of CPUClass fields with dynamically initialization of CPUClass depending on the chosen accelerator. What makes this necessary?

I am not sure about the definitions of "static" and "dynamic" you are using here, as all the above looks "dynamic" to me, before and after.

The overrides and additional fields in the CPUClass are only necessary for TCG, and all that code should not be compiled in if TCG is not built-in.

Ciao,

Claudio

Quoted 55 lines
Quoted 54 lines
target/i386/tcg/cpu.c new file +37 -0
+}
+
+/*
+ * TCG-specific defaults that override all CPU models when using TCG
+ */
+static PropValue tcg_default_props[] = {
+    { "vme", "off" },
+    { NULL, NULL },
+};
+
+static void tcg_cpu_instance_init(CPUState *cs)
+{
+    X86CPU *cpu = X86_CPU(cs);
+    /* Special cases not set in the X86CPUDefinition structs: */
+    x86_cpu_apply_props(cpu, tcg_default_props);
+}
+
+static void tcg_cpu_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
+
+    acc->cpu_realizefn = tcg_cpu_realizefn;
+    acc->cpu_class_init = tcg_cpu_class_init;
+    acc->cpu_instance_init = tcg_cpu_instance_init;
+}
+static const TypeInfo tcg_cpu_accel_type_info = {
+    .name = ACCEL_CPU_NAME("tcg"),
+
+    .parent = TYPE_ACCEL_CPU,
+    .class_init = tcg_cpu_accel_class_init,
+    .abstract = true,
+};
+static void tcg_cpu_accel_register_types(void)
+{
+    type_register_static(&tcg_cpu_accel_type_info);
+}
+type_init(tcg_cpu_accel_register_types);
target/i386/tcg/meson.build +2 -1
index 02794226c2..9e439df9c7 100644
@@ -10,4 +10,5 @@ i386_ss.add(when: 'CONFIG_TCG', if_true: files(
   'seg_helper.c',
   'smm_helper.c',
   'svm_helper.c',
-  'translate.c'), if_false: files('tcg-stub.c'))
+  'translate.c',
+  'cpu.c'), if_false: files('tcg-stub.c'))
Signature · 1 line
2.26.2
#40 lore raw

Re: [RFC v6 11/11] i386: split cpu accelerators from cpu.c, using AccelCPUClass

Quoted 68 lines · Claudio Fontana
Quoted 19 lines · Eduardo Habkost
Quoted 11 lines · Claudio Fontana

i386 is the first user of AccelCPUClass, allowing to split cpu.c into:

cpu.c            cpuid and common x86 cpu functionality
host-cpu.c       host x86 cpu functions and "host" cpu type
kvm/cpu.c        KVM x86 AccelCPUClass
hvf/cpu.c        HVF x86 AccelCPUClass
tcg/cpu.c        TCG x86 AccelCPUClass

---

[...]

Quoted 1 line

+static void tcg_cpu_class_init(CPUClass *cc)

Is this the only case where we need to provide an
AccelCPUClass.cpu_class_init method?

Quoted 13 lines

target/i386/tcg/cpu.c line 136

Quoted 11 lines
target/i386/tcg/cpu.c new file +11 -0
+{
+    cc->do_interrupt = x86_cpu_do_interrupt;
+    cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;
+    cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
+    cc->cpu_exec_enter = x86_cpu_exec_enter;
+    cc->cpu_exec_exit = x86_cpu_exec_exit;
+    cc->tcg_initialize = tcg_x86_init;
+    cc->tlb_fill = x86_cpu_tlb_fill;
+#ifndef CONFIG_USER_ONLY
+    cc->debug_excp_handler = breakpoint_handler;
+#endif /* !CONFIG_USER_ONLY */

I find the need for these method overrides suspicious.

These mechanisms are preexistent. My refactoring only makes them more visible.

Quoted 25 lines

Comparing this with the code on qemu.git master:

static void x86_cpu_common_class_init(ObjectClass *oc, void *data)

{
    [...]
#ifdef CONFIG_TCG
    cc->do_interrupt = x86_cpu_do_interrupt;
    cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;
#endif
    [...]
    cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
    [...]
#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
    cc->debug_excp_handler = breakpoint_handler;
#endif
    cc->cpu_exec_enter = x86_cpu_exec_enter;
    cc->cpu_exec_exit = x86_cpu_exec_exit;
#ifdef CONFIG_TCG
    cc->tcg_initialize = tcg_x86_init;
    cc->tlb_fill = x86_cpu_tlb_fill;
#endif
    [...]
}
Quoted 4 lines

So, we have two kinds of CPUClass fields above:
* Code that was never conditional on CONFIG_TCG, and now is conditional (synchronize_from_tb, cpu_exec_enter, cpu_exec_exit).

Quoted 6 lines

synchronize_from_tb, cpu_exec_enter and cpu_exec_exit only makes sense for TCG, and their code should not be compiled in for non-TCG.

This is part of the effort to separate away non-pertinent code into accelerator-specific builds (and in the future modules).

The fact that they were unconditionally compiled in before was a mistake, or at least this is the assumption I am making when changing this.

Can you clarify why that was a mistake? Patch 07/11 makes existing functions TCG-specific, but doesn't explain why.

Quoted 5 lines
Quoted 5 lines

* Code that was conditional on CONFIG_TCG at compile time, and is now conditional on TCG being enabled at runtime.

Quoted 8 lines
Quoted 3 lines

On both cases, we are replacing static initialization of CPUClass fields with dynamically initialization of CPUClass depending on the chosen accelerator. What makes this necessary?

I am not sure about the definitions of "static" and "dynamic" you are using here, as all the above looks "dynamic" to me, before and after.

The existing code initializes all CPUClass fields as soon as possible (at class_init), and we can be 100% sure the CPUClass methods above are always pointing to the right function and will never change.

This patch makes those CPUClass fields change at runtime, after accelerator initialization.

This might be a reasonable approach if we have a good reason for it, but what can we do to simplify this? If those methods really depend on the accelerator (and not the CPU class), why aren't they part of the CpusAccel struct instead of CPUClass?

Quoted 65 lines

The overrides and additional fields in the CPUClass are only necessary for TCG, and all that code should not be compiled in if TCG is not built-in.

Ciao,

Claudio

Quoted 55 lines
Quoted 54 lines
target/i386/tcg/cpu.c new file +37 -0
+}
+
+/*
+ * TCG-specific defaults that override all CPU models when using TCG
+ */
+static PropValue tcg_default_props[] = {
+    { "vme", "off" },
+    { NULL, NULL },
+};
+
+static void tcg_cpu_instance_init(CPUState *cs)
+{
+    X86CPU *cpu = X86_CPU(cs);
+    /* Special cases not set in the X86CPUDefinition structs: */
+    x86_cpu_apply_props(cpu, tcg_default_props);
+}
+
+static void tcg_cpu_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
+
+    acc->cpu_realizefn = tcg_cpu_realizefn;
+    acc->cpu_class_init = tcg_cpu_class_init;
+    acc->cpu_instance_init = tcg_cpu_instance_init;
+}
+static const TypeInfo tcg_cpu_accel_type_info = {
+    .name = ACCEL_CPU_NAME("tcg"),
+
+    .parent = TYPE_ACCEL_CPU,
+    .class_init = tcg_cpu_accel_class_init,
+    .abstract = true,
+};
+static void tcg_cpu_accel_register_types(void)
+{
+    type_register_static(&tcg_cpu_accel_type_info);
+}
+type_init(tcg_cpu_accel_register_types);
target/i386/tcg/meson.build +2 -1
index 02794226c2..9e439df9c7 100644
@@ -10,4 +10,5 @@ i386_ss.add(when: 'CONFIG_TCG', if_true: files(
   'seg_helper.c',
   'smm_helper.c',
   'svm_helper.c',
-  'translate.c'), if_false: files('tcg-stub.c'))
+  'translate.c',
+  'cpu.c'), if_false: files('tcg-stub.c'))
Signature · 1 line
2.26.2
Signature · 1 line
Eduardo
#41 lore raw

Re: [RFC v6 11/11] i386: split cpu accelerators from cpu.c, using AccelCPUClass

Quoted 72 lines · Eduardo Habkost
Quoted 71 lines · Claudio Fontana
Quoted 19 lines · Eduardo Habkost
Quoted 11 lines · Claudio Fontana

i386 is the first user of AccelCPUClass, allowing to split cpu.c into:

cpu.c            cpuid and common x86 cpu functionality
host-cpu.c       host x86 cpu functions and "host" cpu type
kvm/cpu.c        KVM x86 AccelCPUClass
hvf/cpu.c        HVF x86 AccelCPUClass
tcg/cpu.c        TCG x86 AccelCPUClass

---

[...]

Quoted 1 line

+static void tcg_cpu_class_init(CPUClass *cc)

Is this the only case where we need to provide an
AccelCPUClass.cpu_class_init method?

Quoted 13 lines

target/i386/tcg/cpu.c line 136

Quoted 11 lines
target/i386/tcg/cpu.c new file +11 -0
+{
+    cc->do_interrupt = x86_cpu_do_interrupt;
+    cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;
+    cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
+    cc->cpu_exec_enter = x86_cpu_exec_enter;
+    cc->cpu_exec_exit = x86_cpu_exec_exit;
+    cc->tcg_initialize = tcg_x86_init;
+    cc->tlb_fill = x86_cpu_tlb_fill;
+#ifndef CONFIG_USER_ONLY
+    cc->debug_excp_handler = breakpoint_handler;
+#endif /* !CONFIG_USER_ONLY */

I find the need for these method overrides suspicious.

These mechanisms are preexistent. My refactoring only makes them more visible.

Quoted 25 lines

Comparing this with the code on qemu.git master:

static void x86_cpu_common_class_init(ObjectClass *oc, void *data)

{
    [...]
#ifdef CONFIG_TCG
    cc->do_interrupt = x86_cpu_do_interrupt;
    cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;
#endif
    [...]
    cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
    [...]
#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
    cc->debug_excp_handler = breakpoint_handler;
#endif
    cc->cpu_exec_enter = x86_cpu_exec_enter;
    cc->cpu_exec_exit = x86_cpu_exec_exit;
#ifdef CONFIG_TCG
    cc->tcg_initialize = tcg_x86_init;
    cc->tlb_fill = x86_cpu_tlb_fill;
#endif
    [...]
}
Quoted 4 lines

So, we have two kinds of CPUClass fields above:
* Code that was never conditional on CONFIG_TCG, and now is conditional (synchronize_from_tb, cpu_exec_enter, cpu_exec_exit).

synchronize_from_tb, cpu_exec_enter and cpu_exec_exit only makes sense for TCG, and their code should not be compiled in for non-TCG.

Quoted 6 lines
Quoted 3 lines

This is part of the effort to separate away non-pertinent code into accelerator-specific builds (and in the future modules).

The fact that they were unconditionally compiled in before was a mistake, or at least this is the assumption I am making when changing this.

Can you clarify why that was a mistake? Patch 07/11 makes existing functions TCG-specific, but doesn't explain why.

They are functions called only for TCG. You don't need translation blocks and cpu_exec() for other accelerators. I can add this information in the commit message.

Quoted 95 lines
Quoted 6 lines
Quoted 6 lines

* Code that was conditional on CONFIG_TCG at compile time, and is now conditional on TCG being enabled at runtime.

Quoted 8 lines
Quoted 3 lines

On both cases, we are replacing static initialization of CPUClass fields with dynamically initialization of CPUClass depending on the chosen accelerator. What makes this necessary?

I am not sure about the definitions of "static" and "dynamic" you are using here, as all the above looks "dynamic" to me, before and after.

The existing code initializes all CPUClass fields as soon as possible (at class_init), and we can be 100% sure the CPUClass methods above are always pointing to the right function and will never change.

This patch makes those CPUClass fields change at runtime, after accelerator initialization.

This might be a reasonable approach if we have a good reason for it, but what can we do to simplify this? If those methods really depend on the accelerator (and not the CPU class), why aren't they part of the CpusAccel struct instead of CPUClass?

Quoted 65 lines

The overrides and additional fields in the CPUClass are only necessary for TCG, and all that code should not be compiled in if TCG is not built-in.

Ciao,

Claudio

Quoted 55 lines
Quoted 54 lines
target/i386/tcg/cpu.c new file +37 -0
+}
+
+/*
+ * TCG-specific defaults that override all CPU models when using TCG
+ */
+static PropValue tcg_default_props[] = {
+    { "vme", "off" },
+    { NULL, NULL },
+};
+
+static void tcg_cpu_instance_init(CPUState *cs)
+{
+    X86CPU *cpu = X86_CPU(cs);
+    /* Special cases not set in the X86CPUDefinition structs: */
+    x86_cpu_apply_props(cpu, tcg_default_props);
+}
+
+static void tcg_cpu_accel_class_init(ObjectClass *oc, void *data)
+{
+    AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
+
+    acc->cpu_realizefn = tcg_cpu_realizefn;
+    acc->cpu_class_init = tcg_cpu_class_init;
+    acc->cpu_instance_init = tcg_cpu_instance_init;
+}
+static const TypeInfo tcg_cpu_accel_type_info = {
+    .name = ACCEL_CPU_NAME("tcg"),
+
+    .parent = TYPE_ACCEL_CPU,
+    .class_init = tcg_cpu_accel_class_init,
+    .abstract = true,
+};
+static void tcg_cpu_accel_register_types(void)
+{
+    type_register_static(&tcg_cpu_accel_type_info);
+}
+type_init(tcg_cpu_accel_register_types);
target/i386/tcg/meson.build +2 -1
index 02794226c2..9e439df9c7 100644
@@ -10,4 +10,5 @@ i386_ss.add(when: 'CONFIG_TCG', if_true: files(
   'seg_helper.c',
   'smm_helper.c',
   'svm_helper.c',
-  'translate.c'), if_false: files('tcg-stub.c'))
+  'translate.c',
+  'cpu.c'), if_false: files('tcg-stub.c'))
Signature · 1 line
2.26.2
#42 lore raw

Re: [RFC v6 11/11] i386: split cpu accelerators from cpu.c, using AccelCPUClass

Quoted 77 lines · Claudio Fontana
Quoted 76 lines · Eduardo Habkost
Quoted 74 lines · Claudio Fontana
Quoted 19 lines · Eduardo Habkost
Quoted 11 lines · Claudio Fontana

i386 is the first user of AccelCPUClass, allowing to split cpu.c into:

cpu.c            cpuid and common x86 cpu functionality
host-cpu.c       host x86 cpu functions and "host" cpu type
kvm/cpu.c        KVM x86 AccelCPUClass
hvf/cpu.c        HVF x86 AccelCPUClass
tcg/cpu.c        TCG x86 AccelCPUClass

---

[...]

Quoted 1 line

+static void tcg_cpu_class_init(CPUClass *cc)

Is this the only case where we need to provide an
AccelCPUClass.cpu_class_init method?

Quoted 13 lines

target/i386/tcg/cpu.c line 136

Quoted 11 lines
target/i386/tcg/cpu.c new file +11 -0
+{
+    cc->do_interrupt = x86_cpu_do_interrupt;
+    cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;
+    cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
+    cc->cpu_exec_enter = x86_cpu_exec_enter;
+    cc->cpu_exec_exit = x86_cpu_exec_exit;
+    cc->tcg_initialize = tcg_x86_init;
+    cc->tlb_fill = x86_cpu_tlb_fill;
+#ifndef CONFIG_USER_ONLY
+    cc->debug_excp_handler = breakpoint_handler;
+#endif /* !CONFIG_USER_ONLY */

I find the need for these method overrides suspicious.

These mechanisms are preexistent. My refactoring only makes them more visible.

Quoted 25 lines

Comparing this with the code on qemu.git master:

static void x86_cpu_common_class_init(ObjectClass *oc, void *data)

{
    [...]
#ifdef CONFIG_TCG
    cc->do_interrupt = x86_cpu_do_interrupt;
    cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;
#endif
    [...]
    cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
    [...]
#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
    cc->debug_excp_handler = breakpoint_handler;
#endif
    cc->cpu_exec_enter = x86_cpu_exec_enter;
    cc->cpu_exec_exit = x86_cpu_exec_exit;
#ifdef CONFIG_TCG
    cc->tcg_initialize = tcg_x86_init;
    cc->tlb_fill = x86_cpu_tlb_fill;
#endif
    [...]
}
Quoted 4 lines

So, we have two kinds of CPUClass fields above:
* Code that was never conditional on CONFIG_TCG, and now is conditional (synchronize_from_tb, cpu_exec_enter, cpu_exec_exit).

synchronize_from_tb, cpu_exec_enter and cpu_exec_exit only makes sense for TCG, and their code should not be compiled in for non-TCG.

This is part of the effort to separate away non-pertinent code into accelerator-specific builds (and in the future modules).

The fact that they were unconditionally compiled in before was a mistake, or at least this is the assumption I am making when changing this.

Quoted 7 lines
Quoted 2 lines

Can you clarify why that was a mistake? Patch 07/11 makes existing functions TCG-specific, but doesn't explain why.

They are functions called only for TCG. You don't need translation blocks and cpu_exec() for other accelerators. I can add this information in the commit message.

Thanks! I believe we can clarify in patch 07/11 why some methods that were not conditional on CONFIG_TCG were moved to tcg_cpu_common_class_init().

Do you think it would be too complicated to move those methods from CPUClass to CpusAccel? If they are really accel-specific, CPUClass looks like the wrong place for them.

Quoted 1 line

[...]

Signature · 1 line
Eduardo