i386 cleanup
v5 cover i386 cleanup
Hi all, this is v5 of the i386 cleanup,
with the most interesting patches at the end.
I put in To: 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.
v4 -> v5: centralized and simplified initializations
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 (12):
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
module: introduce MODULE_INIT_ACCEL_CPU
i386: split cpu accelerators from cpu.c
i386: centralize initialization of cpu accel interfaces
accel: centralize initialization of CpusAccelOps
MAINTAINERS | 14 +-
accel/accel-common.c | 54 +++
accel/{accel.c => accel-softmmu.c} | 27 +-
accel/accel-user.c | 28 ++
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 | 3 +-
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 | 25 +-
bsd-user/main.c | 9 +-
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/{sysemu => qemu}/accel.h | 15 +-
include/qemu/module.h | 2 +
include/sysemu/cpus.h | 39 +-
include/sysemu/hvf.h | 2 +-
include/sysemu/kvm.h | 2 +-
include/sysemu/kvm_int.h | 2 +-
linux-user/main.c | 9 +-
meson.build | 1 +
roms/qboot | 2 +-
softmmu/cpus.c | 51 ++-
softmmu/memory.c | 2 +-
softmmu/qtest.c | 2 +-
softmmu/vl.c | 8 +-
target/i386/cpu-dump.c | 538 +++++++++++++++++++++++++
target/i386/cpu-qom.h | 26 ++
target/i386/cpu.c | 446 ++++-----------------
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 | 67 ++++
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 | 149 +++++++
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 | 172 ++++++++
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 -
103 files changed, 1914 insertions(+), 1247 deletions(-)
create mode 100644 accel/accel-common.c
rename accel/{accel.c => accel-softmmu.c} (75%)
create mode 100644 accel/accel-user.c
create mode 100644 accel/tcg/tcg-cpus-mttcg.h
rename include/{sysemu => qemu}/accel.h (95%)
create mode 100644 target/i386/cpu-dump.c
rename target/i386/{ => hax}/hax-all.c (99%)
rename target/i386/{ => hax}/hax-cpus.c (70%)
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
RFC v5 1/12 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.hMAINTAINERS +1 -1
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
target/i386/kvm/hyperv-stub.c renamed from target/i386/hyperv-stub.c +0 -0
target/i386/kvm/hyperv.c renamed from target/i386/hyperv.c +0 -0
target/i386/kvm/hyperv.h renamed from target/i386/hyperv.h +0 -0
target/i386/kvm/kvm-stub.c renamed from target/i386/kvm-stub.c +0 -0
target/i386/kvm/kvm.c renamed from target/i386/kvm.c +0 -0
target/i386/kvm/kvm_i386.h renamed from target/i386/kvm_i386.h +0 -0
target/i386/kvm/meson.build new file +3 -0
@@ -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
@@ -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
@@ -0,0 +1 @@ +#include "trace/trace-target_i386_kvm.h"
target/i386/machine.c +2 -2
@@ -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
@@ -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
@@ -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
RFC v5 2/12 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
@@ -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
@@ -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
@@ -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
target/i386/whpx/whpx-all.c renamed from target/i386/whpx-all.c +0 -0
target/i386/whpx/whpx-cpus.c renamed from target/i386/whpx-cpus.c +0 -0
target/i386/whpx/whpx-cpus.h renamed from target/i386/whpx-cpus.h +0 -0
Signature · 1 line
2.26.2
RFC v5 3/12 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.buildMAINTAINERS +1 -1
@@ -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
target/i386/hax/hax-cpus.c renamed from target/i386/hax-cpus.c +0 -0
target/i386/hax/hax-cpus.h renamed from target/i386/hax-cpus.h +0 -0
target/i386/hax/hax-i386.h renamed from target/i386/hax-i386.h +3 -3
@@ -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
target/i386/hax/hax-mem.c renamed from target/i386/hax-mem.c +0 -0
target/i386/hax/hax-posix.c renamed from target/i386/hax-posix.c +0 -0
target/i386/hax/hax-posix.h renamed from target/i386/hax-posix.h +0 -0
target/i386/hax/hax-windows.c renamed from target/i386/hax-windows.c +0 -0
target/i386/hax/hax-windows.h renamed from target/i386/hax-windows.h +0 -0
target/i386/hax/meson.build new file +7 -0
@@ -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
@@ -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
RFC v5 4/12 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
@@ -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
RFC v5 5/12 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
@@ -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
target/i386/tcg/cc_helper.c renamed from target/i386/cc_helper.c +0 -0
target/i386/tcg/excp_helper.c renamed from target/i386/excp_helper.c +0 -0
target/i386/tcg/fpu_helper.c renamed from target/i386/fpu_helper.c +0 -0
target/i386/tcg/int_helper.c renamed from target/i386/int_helper.c +0 -0
target/i386/tcg/mem_helper.c renamed from target/i386/mem_helper.c +0 -0
target/i386/tcg/meson.build new file +13 -0
@@ -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
target/i386/tcg/mpx_helper.c renamed from target/i386/mpx_helper.c +0 -0
target/i386/tcg/seg_helper.c renamed from target/i386/seg_helper.c +0 -0
target/i386/tcg/smm_helper.c renamed from target/i386/smm_helper.c +0 -0
target/i386/tcg/svm_helper.c renamed from target/i386/svm_helper.c +0 -0
target/i386/tcg/tcg-stub.c renamed from target/i386/tcg-stub.c +0 -0
target/i386/tcg/translate.c renamed from target/i386/translate.c +0 -0
Signature · 1 line
2.26.2
RFC v5 6/12 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
@@ -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
@@ -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
@@ -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
RFC v5 7/12 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
RFC v5 8/12 accel: extend AccelState and AccelClass to user-mode
In reply to Claudio Fontana---
MAINTAINERS | 2 +-
accel/accel-common.c | 54 ++++++++++++++++++++++++++++++
accel/{accel.c => accel-softmmu.c} | 27 ++-------------
accel/accel-user.c | 28 ++++++++++++++++
accel/meson.build | 4 ++-
accel/qtest/qtest.c | 2 +-
accel/tcg/meson.build | 3 +-
accel/tcg/tcg-all.c | 3 +-
accel/xen/xen-all.c | 2 +-
bsd-user/main.c | 8 +++--
include/hw/boards.h | 2 +-
include/{sysemu => qemu}/accel.h | 15 +++++----
include/sysemu/hvf.h | 2 +-
include/sysemu/kvm.h | 2 +-
include/sysemu/kvm_int.h | 2 +-
linux-user/main.c | 8 +++--
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, 124 insertions(+), 56 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
@@ -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 +54 -0
54 lines not on this page · raw message
accel/accel-softmmu.c renamed from accel/accel.c +2 -25
@@ -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 +28 -0
@@ -0,0 +1,28 @@ +/* +* 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" +#include "hw/boards.h" +#include "sysemu/arch_init.h" +#include "sysemu/sysemu.h" +#include "qom/object.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
@@ -1,4 +1,6 @@ -softmmu_ss.add(files('accel.c')) +common_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
@@ -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 -2
@@ -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',
@@ -11,9 +12,7 @@ tcg_ss.add(when: 'CONFIG_USER_ONLY', if_true: files('user-exec.c')) tcg_ss.add(when: 'CONFIG_SOFTMMU', if_false: files('user-exec-stub.c')) 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 +1 -2
@@ -30,9 +30,8 @@#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" -#include "tcg-cpus.h" struct TCGState {AccelState parent_obj;
accel/xen/xen-all.c +1 -1
@@ -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 +6 -2
@@ -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,12 @@ 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_find ("tcg" ); +g_assert (ac !=NULL ); + ac->init_machine (NULL ); + } cpu_type =parse_cpu_option (cpu_model); cpu =cpu_create (cpu_type); env = cpu->env_ptr;
@@ -988,7 +993,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
@@ -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 -7
@@ -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,12 @@ 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
@@ -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
@@ -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
@@ -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 +6 -2
@@ -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,12 @@ 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_find ("tcg" ); +g_assert (ac !=NULL ); + ac->init_machine (NULL ); + } cpu =cpu_create (cpu_type); env = cpu->env_ptr;cpu_reset (cpu);
@@ -846,7 +851,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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Re: [RFC v5 08/12] accel: extend AccelState and AccelClass to user-mode
Quoted 2 lines · Claudio Fontana
Signed-off-by Claudio Fontana <[email protected]>---
[...]
bsd-user/main.c int main(int argc, char **argv) · line 916
Quoted 10 lines
bsd-user/main.c +4
-1@@ -908,8 +909,12 @@ 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_find ("tcg" ); +g_assert (ac !=NULL ); + ac->init_machine (NULL );
Most init_machine() methods will crash if you call them with a NULL argument.
This looks like another reason for having a
void accel_init(AccelState*)
function and a
void (*init)(AccelState*)
method in AccelClass.
Then the whole code block above would be as trivial as:
accel_init(current_accel());
Quoted 1 line
(quoted diff) +1
-0+ }
[...]
Quoted 1 line
Signature · 1 line
Eduardo
Re: [RFC v5 08/12] accel: extend AccelState and AccelClass to user-mode
Hi Eduardo,
thanks for looking at this,
Quoted 12 lines · Eduardo Habkost
Quoted 2 lines · Claudio Fontana
Signed-off-by Claudio Fontana <[email protected]>---
[...]
Quoted 8 lines
bsd-user/main.c +2
-1@@ -908,8 +909,12 @@ 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_find ("tcg" );
Quoted 5 lines
Review int main(int argc, char **argv) · line 916
Quoted 2 lines
(quoted diff) +2
-0+ g_assert(ac != NULL); + ac->init_machine(NULL);Most
init_machine()methods will crash if you call them with a NULL argument.
not tcg though,
Quoted 10 lines
This looks like another reason for having a
voidaccel_init(AccelState*)
function and a
void (*init)(AccelState*)
method in AccelClass.Then the whole code block above would be as trivial as:
accel_init(current_accel());
but this does look like an attractive result,
thanks!
CLaudio
Quoted 6 lines
Quoted 3 lines
(quoted diff) +1
-0+ }[...]
Quoted 1 line
RFC v5 9/12 module: introduce MODULE_INIT_ACCEL_CPU
In reply to Claudio Fontanaapply this to the registration of the cpus accel interfaces,
but this will be also in preparation for later use of this new module init step to also register per-accel x86 cpu type interfaces.
--- accel/kvm/kvm-all.c | 11 +++++++++-- accel/qtest/qtest.c | 10 +++++++++- accel/tcg/tcg-all.c | 8 -------- accel/tcg/tcg-cpus.c | 15 +++++++++++++++ accel/xen/xen-all.c | 12 +++++++++--- include/qemu/module.h | 2 ++ roms/qboot | 2 +- softmmu/vl.c | 6 ++++++ target/i386/hax/hax-all.c | 12 +++++++++--- target/i386/hvf/hvf.c | 10 +++++++++- target/i386/whpx/whpx-all.c | 11 +++++++++-- 11 files changed, 78 insertions(+), 21 deletions(-)
accel/kvm/kvm-all.c +9 -2
@@ -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:
@@ -3236,3 +3234,12 @@ static void kvm_type_init(void) }type_init (kvm_type_init); + +static void kvm_accel_cpu_init (void ) +{ +if (kvm_enabled ()) { +cpus_register_accel (&kvm_cpus); + } +} + +accel_cpu_init (kvm_accel_cpu_init);
accel/qtest/qtest.c +9 -1
@@ -32,7 +32,6 @@ const CpusAccel qtest_cpus = {static int qtest_init_accel (MachineState *ms) { -cpus_register_accel (&qtest_cpus);return 0 ; }
@@ -58,3 +57,12 @@ static void qtest_type_init(void) }type_init (qtest_type_init); + +static void qtest_accel_cpu_init (void ) +{ +if (qtest_enabled ()) { +cpus_register_accel (&qtest_cpus); + } +} + +accel_cpu_init (qtest_accel_cpu_init);
accel/tcg/tcg-all.c +0 -8
@@ -108,14 +108,6 @@ static int tcg_init(MachineState *ms)* Initialize TCG regions */ tcg_region_init (); - -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); - }return 0 ; }
accel/tcg/tcg-cpus.c +15 -0
@@ -80,3 +80,18 @@ void tcg_cpus_handle_interrupt(CPUState *cpu, int mask)qatomic_set (&cpu_neg (cpu)->icount_decr.u16.high,-1 ); } } + +static void tcg_accel_cpu_init (void ) +{ +if (tcg_enabled ()) { +if (qemu_tcg_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); + } + } +} + +accel_cpu_init (tcg_accel_cpu_init);
accel/xen/xen-all.c +9 -3
@@ -185,9 +185,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 ; }
@@ -228,3 +225,12 @@ static void xen_type_init(void) }type_init (xen_type_init); + +static void xen_accel_cpu_init (void ) +{ +if (xen_enabled ()) { +cpus_register_accel (&xen_cpus); + } +} + +accel_cpu_init (xen_accel_cpu_init);
include/qemu/module.h +2 -0
@@ -44,6 +44,7 @@ typedef enum {MODULE_INIT_BLOCK ,MODULE_INIT_OPTS ,MODULE_INIT_QOM , +MODULE_INIT_ACCEL_CPU ,MODULE_INIT_TRACE ,MODULE_INIT_XEN_BACKEND , MODULE_INIT_LIBQOS,
@@ -54,6 +55,7 @@ typedef enum {#define block_init (function) module_init(function, MODULE_INIT_BLOCK)#define opts_init (function) module_init(function, MODULE_INIT_OPTS)#define type_init (function) module_init(function, MODULE_INIT_QOM) +#define accel_cpu_init (function) module_init(function, MODULE_INIT_ACCEL_CPU)#define trace_init (function) module_init(function, MODULE_INIT_TRACE)#define xen_backend_init (function) module_init(function, \ MODULE_INIT_XEN_BACKEND)
roms/qboot +1 -1
@@ -1 +1 @@ -Subproject commit a5300c4949b8d4de2d34bedfaed66793f48ec948 +Subproject commit cb1c49e0cfac99b9961d136ac0194da62c28cf64
softmmu/vl.c +6 -0
@@ -4173,6 +4173,12 @@ void qemu_init(int argc, char **argv, char **envp)*/ configure_accelerators (argv[0 ]); +/* +* accelerator has been chosen and initialized, now it is time to +* register the cpu accel interface. +*/ +module_call_init (MODULE_INIT_ACCEL_CPU ); +/* * Beware, QOM objects created before this point miss global and * compat properties.
target/i386/hax/hax-all.c +9 -3
@@ -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; }
@@ -1141,3 +1138,12 @@ static void hax_type_init(void) }type_init (hax_type_init); + +static void hax_accel_cpu_init (void ) +{ +if (hax_enabled ()) { +cpus_register_accel (&hax_cpus); + } +} + +accel_cpu_init (hax_accel_cpu_init);
target/i386/hvf/hvf.c +9 -1
@@ -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 ; }
@@ -911,3 +910,12 @@ static void hvf_type_init(void) }type_init (hvf_type_init); + +static void hvf_accel_cpu_init (void ) +{ +if (hvf_enabled ()) { +cpus_register_accel (&hvf_cpus); + } +} + +accel_cpu_init (hvf_accel_cpu_init);
target/i386/whpx/whpx-all.c +9 -2
@@ -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 ;
@@ -1713,3 +1711,12 @@ error: }type_init (whpx_type_init); + +static void whpx_accel_cpu_init (void ) +{ +if (whpx_enabled ()) { +cpus_register_accel (&whpx_cpus); + } +} + +accel_cpu_init (whpx_accel_cpu_init);
Signature · 1 line
2.26.2
Re: [RFC v5 09/12] module: introduce MODULE_INIT_ACCEL_CPU
Quoted 8 lines · Claudio Fontana
apply this to the registration of the cpus accel interfaces,
but this will be also in preparation for later use of this new module init step to also register per-accel x86 cpu type interfaces.
Signed-off-by Claudio Fontana <[email protected]>---
[...]
Quoted 15 lines
accel/qtest/qtest.c +0
-1@@ -32,7 +32,6 @@ const CpusAccel qtest_cpus = {static int qtest_init_accel (MachineState *ms) { -cpus_register_accel (&qtest_cpus);return 0 ; }@@ -58,3 +57,12 @@ static void qtest_type_init(void) }
accel/qtest/qtest.c static void qtest_type_init(void) · line 68
Quoted 10 lines
accel/qtest/qtest.c +9
-0type_init (qtest_type_init); + +static void qtest_accel_cpu_init (void ) +{ +if (qtest_enabled ()) { +cpus_register_accel (&qtest_cpus); + } +} + +accel_cpu_init (qtest_accel_cpu_init);
I don't understand why this (and the similar changes on other accelerators) is an improvement.
You are replacing a trivial AccelClass-specific init method with a module_init() function that has a hidden dependency on runtime state.
Signature · 1 line
Eduardo
Re: [RFC v5 09/12] module: introduce MODULE_INIT_ACCEL_CPU
Quoted 39 lines · Eduardo Habkost
Quoted 8 lines · Claudio Fontana
apply this to the registration of the cpus accel interfaces,
but this will be also in preparation for later use of this new module init step to also register per-accel x86 cpu type interfaces.
Signed-off-by Claudio Fontana <[email protected]>---
[...]
Quoted 15 lines
accel/qtest/qtest.c +0
-1@@ -32,7 +32,6 @@ const CpusAccel qtest_cpus = {static int qtest_init_accel (MachineState *ms) { -cpus_register_accel (&qtest_cpus);return 0 ; }@@ -58,3 +57,12 @@ static void qtest_type_init(void) }accel/qtest/qtest.c static void qtest_type_init(void) · line 68
Quoted 10 lines
accel/qtest/qtest.c +9
-0type_init (qtest_type_init); + +static void qtest_accel_cpu_init (void ) +{ +if (qtest_enabled ()) { +cpus_register_accel (&qtest_cpus); + } +} + +accel_cpu_init (qtest_accel_cpu_init);I don't understand why this (and the similar changes on other accelerators) is an improvement.
Quoted 4 lines
You are replacing a trivial AccelClass-specific init method with a
module_init()function that has a hidden dependency on runtime state.
Not a big advantage I agree,
I think however there is one, in using the existing framework that exists, for the purposes that it was built for.
As I understand it, the global module init framework is supposed to mark the major initialization steps, and this seems to fit the bill.
The "hidden" dependency on the fact that accels need to be initialized at that time, is not hidden at all I think, it is what this module init step is all about.
It is explicitly meaning, "_now that the current accelerator is chosen_, perform these initializations".
But, as you mentioned elsewhere, I will in the meantime anyway squash these things so they do not start fragmented at all, and centralize immediately.
Thanks,
Claudio
Re: [RFC v5 09/12] module: introduce MODULE_INIT_ACCEL_CPU
Quoted 45 lines · Claudio Fontana
Quoted 39 lines · Eduardo Habkost
Quoted 8 lines · Claudio Fontana
apply this to the registration of the cpus accel interfaces,
but this will be also in preparation for later use of this new module init step to also register per-accel x86 cpu type interfaces.
Signed-off-by Claudio Fontana <[email protected]>---
[...]
Quoted 15 lines
accel/qtest/qtest.c +0
-1@@ -32,7 +32,6 @@ const CpusAccel qtest_cpus = {static int qtest_init_accel (MachineState *ms) { -cpus_register_accel (&qtest_cpus);return 0 ; }@@ -58,3 +57,12 @@ static void qtest_type_init(void) }accel/qtest/qtest.c static void qtest_type_init(void) · line 68
Quoted 10 lines
accel/qtest/qtest.c +9
-0type_init (qtest_type_init); + +static void qtest_accel_cpu_init (void ) +{ +if (qtest_enabled ()) { +cpus_register_accel (&qtest_cpus); + } +} + +accel_cpu_init (qtest_accel_cpu_init);I don't understand why this (and the similar changes on other accelerators) is an improvement.
Quoted 4 lines
You are replacing a trivial AccelClass-specific init method with a
module_init()function that has a hidden dependency on runtime state.
Quoted 5 lines
Not a big advantage I agree,
I think however there is one, in using the existing framework that exists, for the purposes that it was built for.As I understand it, the global module init framework is supposed to mark the major initialization steps, and this seems to fit the bill.
That seems to be the main source of disagreement. I don't agree that's the purpose of module_init().
The module init framework is used to unconditionally register module-provided entities like option names, QOM types, block drivers, trace events, etc. The entities registered by module init functions represent a passive dynamically loadable piece of code.
module_init() was never used for initialization of machines, devices, CPUs, or other runtime state. We don't have MODULE_INIT_MONITOR, MODULE_INIT_OBJECTS, MODULE_INIT_MACHINE, MODULE_INIT_CPUS, MODULE_INIT_DEVICES, etc.
And I'm not convinced we should, because it would hide dependencies between initialization steps. It would force us to make initialization functions affect and depend on global state.
I believe this:
int main()
{
result_of_A = init_A(input_for_A);
result_of_B = init_B(input_for_B);
result_of_C = init_C(input_for_C);
}is clearer and more maintainable than:
int main()
{
module_init_call(MODULE_INIT_A); /* result_of_A hidden in global state */
module_init_call(MODULE_INIT_B); /* result_of_B hidden in global state */
module_init_call(MODULE_INIT_C); /* result_of_C hidden in global state */
}Quoted 7 lines
The "hidden" dependency on the fact that accels need to be initialized at that time, is not hidden at all I think, it is what this module init step is all about.
It is explicitly meaning, "
_nowthat the current accelerator ischosen_, perform these initializations".But, as you mentioned elsewhere, I will in the meantime anyway squash these things so they do not start fragmented at all, and centralize immediately.
Agreed. We still need to sort out the disagreement above, or we'll spend a lot of energy arguing about code.
Signature · 1 line
Eduardo
Re: [RFC v5 09/12] module: introduce MODULE_INIT_ACCEL_CPU
Quoted 5 lines · Eduardo Habkost
Quoted 5 lines
Not a big advantage I agree,
I think however there is one, in using the existing framework that exists, for the purposes that it was built for.As I understand it, the global module init framework is supposed to mark the major initialization steps, and this seems to fit the bill.
Quoted 8 lines
That seems to be the main source of disagreement. I don't agree that's the purpose of
module_init().The module init framework is used to unconditionally register module-provided entities like option names, QOM types, block drivers, trace events, etc. The entities registered by module init functions represent a passive dynamically loadable piece of code.
Indeed. Think of module_init() as C++ global constructors.
Anything that has an "if" does not belong in module_init.
If you look at my review of the previous versions, I was not necessarily against MODULE_INIT_ACCEL_CPU, but I was (and am) strongly against calling it in the middle of the machine creation sequence.
Paolo
Re: [RFC v5 09/12] module: introduce MODULE_INIT_ACCEL_CPU
Quoted 17 lines · Paolo Bonzini
Quoted 5 lines · Eduardo Habkost
Quoted 5 lines
Not a big advantage I agree,
I think however there is one, in using the existing framework that exists, for the purposes that it was built for.As I understand it, the global module init framework is supposed to mark the major initialization steps, and this seems to fit the bill.
Quoted 8 lines
That seems to be the main source of disagreement. I don't agree that's the purpose of
module_init().The module init framework is used to unconditionally register module-provided entities like option names, QOM types, block drivers, trace events, etc. The entities registered by module init functions represent a passive dynamically loadable piece of code.
Indeed. Think of
module_init()as C++ global constructors.
Quoted 9 lines
Anything that has an "if" does not belong in
module_init.If you look at my review of the previous versions, I was not necessarily against
MODULE_INIT_ACCEL_CPU, but I was (and am) strongly against calling it in the middle of the machine creation sequence.Paolo
Hi Paolo,
in RFC v5 , module init for ACCEL_CPU is not conditional anymore, right? But the fact that its behavior depends on current_accel() still disqualifies it?
It is called right after the accelerator is chosen and initialized in RFC v5, this still is "in the middle of the machine creation sequence"?
I am trying to find the actual things to fix, since when doing RFC v5 I tried to specifically address two points:
1) no if () inside module init functions
2) no proliferation of module init functions
which I accomplished via AccelClass extension to user mode, current_accel(), and class lookup.
If MODULE_INIT_ACCEL_CPU remains an option, where would you like to see the call so that it is not "in the middle"?
It is interesting for me to try to discern which meaning you folks give to MODULE_INIT.
Keep in mind, I will experiment with Eduardo's option of "one accel_init() to rule them all", without MODULE_INIT_ACCEL_CPU, so I am not focused on using this no matter what.
Ciao,
Claudio
Re: [RFC v5 09/12] module: introduce MODULE_INIT_ACCEL_CPU
Quoted 6 lines · Claudio Fontana
Hi Paolo,
in RFC v5 , module init for
ACCEL_CPUis not conditional anymore, right? But the fact that its behavior depends oncurrent_accel()still disqualifies it? It is called right after the accelerator is chosen and initialized in RFC v5, this still is "in the middle of the machine creation sequence"?
Yes, machine creation basically starts after command line parsing, or perhaps even _with_ command line parsing. Basically once the user can control the flow it is already too late.
Quoted 8 lines
I am trying to find the actual things to fix, since when doing RFC v5 I tried to specifically address two points:
1) no if () inside module init functions
2) no proliferation of module init functions
which I accomplished via AccelClass extension to user mode,
current_accel(), and class lookup.
Yes, the rest is great, I'm just not sure that MODULE_INIT_ACCEL_CPU is useful and if virtual functions on accel and CPU_RESOLVING_TYPE can achieve the same.
Quoted 1 line
If
MODULE_INIT_ACCEL_CPUremains an option, where would you like to see the call so that it is not "in the middle"?
No later than the runstate_init() call, roughly.
Paolo
Re: [RFC v5 09/12] module: introduce MODULE_INIT_ACCEL_CPU
Quoted 24 lines · Paolo Bonzini
Quoted 6 lines · Claudio Fontana
Hi Paolo,
in RFC v5 , module init for
ACCEL_CPUis not conditional anymore, right? But the fact that its behavior depends oncurrent_accel()still disqualifies it? It is called right after the accelerator is chosen and initialized in RFC v5, this still is "in the middle of the machine creation sequence"?Yes, machine creation basically starts after command line parsing, or perhaps even _with_ command line parsing. Basically once the user can control the flow it is already too late.
Quoted 8 lines
I am trying to find the actual things to fix, since when doing RFC v5 I tried to specifically address two points:
1) no if () inside module init functions
2) no proliferation of module init functions
which I accomplished via AccelClass extension to user mode,
current_accel(), and class lookup.Yes, the rest is great, I'm just not sure that
MODULE_INIT_ACCEL_CPUis useful and if virtual functions on accel andCPU_RESOLVING_TYPEcan achieve the same.
Quoted 7 lines
Quoted 1 line
If
MODULE_INIT_ACCEL_CPUremains an option, where would you like to see the call so that it is not "in the middle"?No later than the
runstate_init()call, roughly.Paolo
Aha! Then that solves it, I don't think it is feasible to put it that early with the meaning I intended for it.
Thanks for clarifying this,
Claudio
Re: [RFC v5 09/12] module: introduce MODULE_INIT_ACCEL_CPU
In reply to Paolo BonziniQuoted 24 lines · Paolo Bonzini
Quoted 6 lines · Claudio Fontana
Hi Paolo,
in RFC v5 , module init for
ACCEL_CPUis not conditional anymore, right? But the fact that its behavior depends oncurrent_accel()still disqualifies it? It is called right after the accelerator is chosen and initialized in RFC v5, this still is "in the middle of the machine creation sequence"?Yes, machine creation basically starts after command line parsing, or perhaps even _with_ command line parsing. Basically once the user can control the flow it is already too late.
Quoted 8 lines
I am trying to find the actual things to fix, since when doing RFC v5 I tried to specifically address two points:
1) no if () inside module init functions
2) no proliferation of module init functions
which I accomplished via AccelClass extension to user mode,
current_accel(), and class lookup.Yes, the rest is great, I'm just not sure that
MODULE_INIT_ACCEL_CPUis useful and if virtual functions on accel andCPU_RESOLVING_TYPEcan achieve the same.
Quoted 6 lines
Quoted 1 line
If
MODULE_INIT_ACCEL_CPUremains an option, where would you like to see the call so that it is not "in the middle"?No later than the
runstate_init()call, roughly.Paolo
Hi Paolo, not super-related to the context above,
during the implementation I am trying to offer
accel/accel-softmmu.caccel/accel-common.caccel/accel-user.c
But I don't seem able to use CONFIG_USER_ONLY in accel-common.c .
in accel/meson.build I am saying
common_ss.add(files('accel-common.c'))
softmmu_ss.add(files('accel-softmmu.c'))
user_ss.add(files('accel-user.c'))
But this doesn't work, if I use common_ss. If I use specific_ss, it works.
So the term "common" is a bit overloaded, it means stuff for libcommon and such, not common between softmmu and user, right?
Ciao,
Claudio
Re: [RFC v5 09/12] module: introduce MODULE_INIT_ACCEL_CPU
In reply to Claudio FontanaQuoted 20 lines · Claudio Fontana
apply this to the registration of the cpus accel interfaces,
but this will be also in preparation for later use of this new module init step to also register per-accel x86 cpu type interfaces.
Signed-off-by Claudio Fontana <[email protected]>--- accel/kvm/kvm-all.c | 11 +++++++++-- accel/qtest/qtest.c | 10 +++++++++- accel/tcg/tcg-all.c | 8 -------- accel/tcg/tcg-cpus.c | 15 +++++++++++++++ accel/xen/xen-all.c | 12 +++++++++--- include/qemu/module.h | 2 ++ roms/qboot | 2 +- softmmu/vl.c | 6 ++++++ target/i386/hax/hax-all.c | 12 +++++++++--- target/i386/hvf/hvf.c | 10 +++++++++- target/i386/whpx/whpx-all.c | 11 +++++++++-- 11 files changed, 78 insertions(+), 21 deletions(-)
...
roms/qboot line 1
Quoted 7 lines
roms/qboot +1
-1@@ -1 +1 @@ -Subproject commit a5300c4949b8d4de2d34bedfaed66793f48ec948 +Subproject commit cb1c49e0cfac99b9961d136ac0194da62c28cf64
Hmmm unrelated change I presume.
Re: [RFC v5 09/12] module: introduce MODULE_INIT_ACCEL_CPU
Quoted 22 lines · Philippe Mathieu-Daudé
Quoted 20 lines · Claudio Fontana
apply this to the registration of the cpus accel interfaces,
but this will be also in preparation for later use of this new module init step to also register per-accel x86 cpu type interfaces.
Signed-off-by Claudio Fontana <[email protected]>--- accel/kvm/kvm-all.c | 11 +++++++++-- accel/qtest/qtest.c | 10 +++++++++- accel/tcg/tcg-all.c | 8 -------- accel/tcg/tcg-cpus.c | 15 +++++++++++++++ accel/xen/xen-all.c | 12 +++++++++--- include/qemu/module.h | 2 ++ roms/qboot | 2 +- softmmu/vl.c | 6 ++++++ target/i386/hax/hax-all.c | 12 +++++++++--- target/i386/hvf/hvf.c | 10 +++++++++- target/i386/whpx/whpx-all.c | 11 +++++++++-- 11 files changed, 78 insertions(+), 21 deletions(-)...
Quoted 10 lines
roms/qboot line 1
Quoted 7 lines
roms/qboot +1
-1@@ -1 +1 @@ -Subproject commit a5300c4949b8d4de2d34bedfaed66793f48ec948 +Subproject commit cb1c49e0cfac99b9961d136ac0194da62c28cf64Hmmm unrelated change I presume.
Hi Philippe, yes, clearly,
Thanks!
Ciao,
CLaudio
RFC v5 10/12 i386: split cpu accelerators from cpu.c
In reply to Claudio Fontanasplit 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 cpu type hvf/cpu.c HVF x86 cpu type tcg/cpu.c TCG x86 cpu type
The link to the accel class is set in the X86CPUClass classes at MODULE_INIT_ACCEL_CPU time, when the accelerator is known.
--- MAINTAINERS | 2 +- bsd-user/main.c | 1 + hw/i386/pc_piix.c | 1 + linux-user/main.c | 1 + target/i386/cpu-qom.h | 28 +++ target/i386/cpu.c | 408 ++++++------------------------------ target/i386/cpu.h | 20 +- target/i386/host-cpu.c | 198 +++++++++++++++++ target/i386/host-cpu.h | 19 ++ target/i386/hvf/cpu.c | 76 +++++++ target/i386/hvf/meson.build | 1 + target/i386/kvm/cpu.c | 157 ++++++++++++++ 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 | 181 ++++++++++++++++ target/i386/tcg/meson.build | 3 +- 20 files changed, 792 insertions(+), 449 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
@@ -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/
bsd-user/main.c +1 -0
@@ -915,6 +915,7 @@ int main(int argc, char **argv)g_assert (ac !=NULL ); ac->init_machine (NULL ); } +module_call_init (MODULE_INIT_ACCEL_CPU ); cpu_type =parse_cpu_option (cpu_model); cpu =cpu_create (cpu_type); env = cpu->env_ptr;
hw/i386/pc_piix.c +1 -0
@@ -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
linux-user/main.c +1 -0
@@ -710,6 +710,7 @@ int main(int argc, char **argv, char **envp)g_assert (ac !=NULL ); ac->init_machine (NULL ); } +module_call_init (MODULE_INIT_ACCEL_CPU ); cpu =cpu_create (cpu_type); env = cpu->env_ptr;cpu_reset (cpu);
target/i386/cpu-qom.h +28 -0
@@ -33,6 +33,12 @@OBJECT_DECLARE_TYPE (X86CPU , X86CPUClass, X86_CPU) + +#define TYPE_X86_CPU_ACCEL "accel-" TYPE_X86_CPU +#define X86_CPU_ACCEL_TYPE_NAME (name) (name "-" TYPE_X86_CPU_ACCEL) +typedef struct X86CPUAccelClass X86CPUAccelClass ; +DECLARE_CLASS_CHECKERS(X86CPUAccelClass, X86_CPU_ACCEL, TYPE_X86_CPU_ACCEL) +typedef struct X86CPUModel X86CPUModel ;/**
@@ -69,7 +75,29 @@ struct X86CPUClass {DeviceRealize parent_realize;DeviceUnrealize parent_unrealize;DeviceReset parent_reset; + + const X86CPUAccelClass *accel; +}; + +/** +* X86CPUAccelClass: +* @name: string name of the X86 CPU Accelerator +* +* @common_class_init: initializer for the common cpu +* @instance_init: cpu instance initialization +* @realizefn: realize function, called first in x86 cpu realize +* +* X86 CPU accelerator-specific CPU initializations +*/ + +struct X86CPUAccelClass { +ObjectClass parent_class; + +void (*cpu_common_class_init)(X86CPUClass *xcc); +void (*cpu_instance_init)(X86CPU *cpu); +void (*cpu_realizefn)(X86CPU *cpu,Error **errp); }; +void x86_cpu_accel_init (const char *accel_name);#endif
target/i386/cpu.c +63 -345
564 lines not on this page · raw message
target/i386/cpu.h +8 -12
@@ -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
@@ -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 (X86CPU *cpu,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 +76 -0
76 lines not on this page · raw message
target/i386/hvf/meson.build +1 -0
@@ -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 +157 -0
157 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
@@ -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
@@ -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
@@ -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
@@ -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 +181 -0
181 lines not on this page · raw message
target/i386/tcg/meson.build +2 -1
@@ -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
RFC v5 11/12 i386: centralize initialization of cpu accel interfaces
In reply to Claudio Fontana--- target/i386/cpu-qom.h | 2 -- target/i386/cpu.c | 27 ++++++++++++++++++++------- target/i386/hvf/cpu.c | 9 --------- target/i386/kvm/cpu.c | 8 -------- target/i386/tcg/cpu.c | 9 --------- 5 files changed, 20 insertions(+), 35 deletions(-)
target/i386/cpu-qom.h +0 -2
@@ -98,6 +98,4 @@ struct X86CPUAccelClass { void (*cpu_realizefn)(X86CPU *cpu, Error **errp); }; -void x86_cpu_accel_init (const char *accel_name); -#endif
target/i386/cpu.c +20 -7
@@ -7066,18 +7066,31 @@ type_init(x86_cpu_register_types)static void x86_cpu_accel_init_aux (ObjectClass *klass,void *opaque) {X86CPUClass *xcc =X86_CPU_CLASS (klass); -const X86CPUAccelClass **accel = opaque; +X86CPUAccelClass *accel = opaque; - xcc->accel = *accel; + xcc->accel = accel; xcc->accel->cpu_common_class_init (xcc); } -void x86_cpu_accel_init (const char *accel_name) +static void x86_cpu_accel_init (void ) { -X86CPUAccelClass *acc; +const char *ac_name; +ObjectClass *ac; +char *xac_name; +ObjectClass *xac; - acc =X86_CPU_ACCEL_CLASS (object_class_by_name (accel_name)); -g_assert (acc !=NULL ); + ac =object_get_class (OBJECT (current_accel ())); +g_assert (ac !=NULL ); + ac_name =object_class_get_name (ac); +g_assert (ac_name !=NULL ); -object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, &acc); + xac_name =g_strdup_printf ("%s-%s" , ac_name,TYPE_X86_CPU ); + xac =object_class_by_name (xac_name); +g_free (xac_name); + +if (xac) { +object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, xac); + } } + +accel_cpu_init (x86_cpu_accel_init);
target/i386/hvf/cpu.c +0 -9
@@ -65,12 +65,3 @@ static void hvf_cpu_accel_register_types(void)type_register_static (&hvf_cpu_accel_type_info); }type_init (hvf_cpu_accel_register_types); - -static void hvf_cpu_accel_init (void ) -{ -if (hvf_enabled ()) { -x86_cpu_accel_init (X86_CPU_ACCEL_TYPE_NAME ("hvf" )); - } -} - -accel_cpu_init (hvf_cpu_accel_init);
target/i386/kvm/cpu.c +0 -8
@@ -147,11 +147,3 @@ static void kvm_cpu_accel_register_types(void)type_register_static (&kvm_cpu_accel_type_info); }type_init (kvm_cpu_accel_register_types); - -static void kvm_cpu_accel_init (void ) -{ -if (kvm_enabled ()) { -x86_cpu_accel_init (X86_CPU_ACCEL_TYPE_NAME ("kvm" )); - } -} -accel_cpu_init (kvm_cpu_accel_init);
target/i386/tcg/cpu.c +0 -9
@@ -170,12 +170,3 @@ static void tcg_cpu_accel_register_types(void)type_register_static (&tcg_cpu_accel_type_info); }type_init (tcg_cpu_accel_register_types); - -static void tcg_cpu_accel_init (void ) -{ -if (tcg_enabled ()) { -x86_cpu_accel_init (X86_CPU_ACCEL_TYPE_NAME ("tcg" )); - } -} - -accel_cpu_init (tcg_cpu_accel_init);
Signature · 1 line
2.26.2
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
Quoted 1 line · Claudio Fontana
Signed-off-by Claudio Fontana <[email protected]>
Probably this can be squashed into patch 10/12.
Quoted 52 lines
--- target/i386/cpu-qom.h | 2 -- target/i386/cpu.c | 27 ++++++++++++++++++++------- target/i386/hvf/cpu.c | 9 --------- target/i386/kvm/cpu.c | 8 -------- target/i386/tcg/cpu.c | 9 --------- 5 files changed, 20 insertions(+), 35 deletions(-)target/i386/cpu-qom.h +0
-2@@ -98,6 +98,4 @@ struct X86CPUAccelClass { void (*cpu_realizefn)(X86CPU *cpu, Error **errp); }; -void x86_cpu_accel_init (const char *accel_name); -#endif target/i386/cpu.c +11
-7@@ -7066,18 +7066,31 @@ type_init(x86_cpu_register_types)static void x86_cpu_accel_init_aux (ObjectClass *klass,void *opaque) {X86CPUClass *xcc =X86_CPU_CLASS (klass); -const X86CPUAccelClass **accel = opaque; +X86CPUAccelClass *accel = opaque; - xcc->accel = *accel; + xcc->accel = accel; xcc->accel->cpu_common_class_init (xcc); } -void x86_cpu_accel_init (const char *accel_name) +static void x86_cpu_accel_init (void ) { -X86CPUAccelClass *acc; +const char *ac_name; +ObjectClass *ac; +char *xac_name; +ObjectClass *xac; - acc =X86_CPU_ACCEL_CLASS (object_class_by_name (accel_name)); -g_assert (acc !=NULL ); + ac =object_get_class (OBJECT (current_accel ())); +g_assert (ac !=NULL ); + ac_name =object_class_get_name (ac); +g_assert (ac_name !=NULL ); -object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, &acc);
target/i386/cpu.c type_init(x86_cpu_register_types) · line 7096
Quoted 10 lines
target/i386/cpu.c +9
-0+ xac_name =g_strdup_printf ("%s-%s" , ac_name,TYPE_X86_CPU ); + xac =object_class_by_name (xac_name); +g_free (xac_name); + +if (xac) { +object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, xac); + } } + +accel_cpu_init (x86_cpu_accel_init);
This keeps the hidden initialization ordering dependency between MODULE_INIT_ACCEL_CPU and current_accel(). I thought we were going to get rid of module init functions that depend on runtime state.
This is an improvement to the code in patch 10/12, though. If others believe it is an acceptable (temporary) solution, I won't block it.
I would still prefer to have a
void arch_accel_cpu_init(AccelState*)
function which would call a
void x86_cpu_accel_init(AccelState*)
function. That would make the dependency between x86_cpu_accel_init() and accelerator creation explicit.
Quoted 53 lines
target/i386/hvf/cpu.c +0
-9@@ -65,12 +65,3 @@ static void hvf_cpu_accel_register_types(void)type_register_static (&hvf_cpu_accel_type_info); }type_init (hvf_cpu_accel_register_types); - -static void hvf_cpu_accel_init (void ) -{ -if (hvf_enabled ()) { -x86_cpu_accel_init (X86_CPU_ACCEL_TYPE_NAME ("hvf" )); - } -} - -accel_cpu_init (hvf_cpu_accel_init);target/i386/kvm/cpu.c +0
-8@@ -147,11 +147,3 @@ static void kvm_cpu_accel_register_types(void)type_register_static (&kvm_cpu_accel_type_info); }type_init (kvm_cpu_accel_register_types); - -static void kvm_cpu_accel_init (void ) -{ -if (kvm_enabled ()) { -x86_cpu_accel_init (X86_CPU_ACCEL_TYPE_NAME ("kvm" )); - } -} -accel_cpu_init (kvm_cpu_accel_init);target/i386/tcg/cpu.c +0
-9@@ -170,12 +170,3 @@ static void tcg_cpu_accel_register_types(void)type_register_static (&tcg_cpu_accel_type_info); }type_init (tcg_cpu_accel_register_types); - -static void tcg_cpu_accel_init (void ) -{ -if (tcg_enabled ()) { -x86_cpu_accel_init (X86_CPU_ACCEL_TYPE_NAME ("tcg" )); - } -} - -accel_cpu_init (tcg_cpu_accel_init);Signature · 1 line
2.26.2
Signature · 1 line
Eduardo
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
Quoted 4 lines · Eduardo Habkost
Quoted 1 line · Claudio Fontana
Signed-off-by Claudio Fontana <[email protected]>Probably this can be squashed into patch 10/12.
Yes, you are right, no point building things fragmented and then merging together later.
Quoted 69 lines
Quoted 53 lines
--- target/i386/cpu-qom.h | 2 -- target/i386/cpu.c | 27 ++++++++++++++++++++------- target/i386/hvf/cpu.c | 9 --------- target/i386/kvm/cpu.c | 8 -------- target/i386/tcg/cpu.c | 9 --------- 5 files changed, 20 insertions(+), 35 deletions(-)target/i386/cpu-qom.h +0
-2@@ -98,6 +98,4 @@ struct X86CPUAccelClass { void (*cpu_realizefn)(X86CPU *cpu, Error **errp); }; -void x86_cpu_accel_init (const char *accel_name); -#endif target/i386/cpu.c +11
-7@@ -7066,18 +7066,31 @@ type_init(x86_cpu_register_types)static void x86_cpu_accel_init_aux (ObjectClass *klass,void *opaque) {X86CPUClass *xcc =X86_CPU_CLASS (klass); -const X86CPUAccelClass **accel = opaque; +X86CPUAccelClass *accel = opaque; - xcc->accel = *accel; + xcc->accel = accel; xcc->accel->cpu_common_class_init (xcc); } -void x86_cpu_accel_init (const char *accel_name) +static void x86_cpu_accel_init (void ) { -X86CPUAccelClass *acc; +const char *ac_name; +ObjectClass *ac; +char *xac_name; +ObjectClass *xac; - acc =X86_CPU_ACCEL_CLASS (object_class_by_name (accel_name)); -g_assert (acc !=NULL ); + ac =object_get_class (OBJECT (current_accel ())); +g_assert (ac !=NULL ); + ac_name =object_class_get_name (ac); +g_assert (ac_name !=NULL ); -object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, &acc);target/i386/cpu.c type_init(x86_cpu_register_types) · line 7096
Quoted 10 lines
target/i386/cpu.c +9
-0+ xac_name =g_strdup_printf ("%s-%s" , ac_name,TYPE_X86_CPU ); + xac =object_class_by_name (xac_name); +g_free (xac_name); + +if (xac) { +object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, xac); + } } + +accel_cpu_init (x86_cpu_accel_init);This keeps the hidden initialization ordering dependency between
MODULE_INIT_ACCEL_CPUandcurrent_accel(). I thought we were going to get rid of module init functions that depend on runtime state.
Quoted 3 lines
This is an improvement to the code in patch 10/12, though. If others believe it is an acceptable (temporary) solution, I won't block it.
In the way I thought about it, MODULE_INIT_ACCEL_CPU meant exactly that: initializations to be done after accel is chosen. So in my view the relationship with current_accel() was then following naturally.
Quoted 8 lines
I would still prefer to have a
voidarch_accel_cpu_init(AccelState*)
function which would call a
voidx86_cpu_accel_init(AccelState*)
function. That would make the dependency betweenx86_cpu_accel_init()and accelerator creation explicit.
not a bad idea either,
what I would lose here is a single point to discover the codebase, ie
MODULE_INIT_ACCEL_CPU via a simple grep or gid MODULE_INIT_ACCEL_CPU gives me all initializations done for this phase, not only the arch_ stuff, but also currently the Ops stuff.
Quoted 55 lines
Quoted 54 lines
target/i386/hvf/cpu.c +0
-9@@ -65,12 +65,3 @@ static void hvf_cpu_accel_register_types(void)type_register_static (&hvf_cpu_accel_type_info); }type_init (hvf_cpu_accel_register_types); - -static void hvf_cpu_accel_init (void ) -{ -if (hvf_enabled ()) { -x86_cpu_accel_init (X86_CPU_ACCEL_TYPE_NAME ("hvf" )); - } -} - -accel_cpu_init (hvf_cpu_accel_init);target/i386/kvm/cpu.c +0
-8@@ -147,11 +147,3 @@ static void kvm_cpu_accel_register_types(void)type_register_static (&kvm_cpu_accel_type_info); }type_init (kvm_cpu_accel_register_types); - -static void kvm_cpu_accel_init (void ) -{ -if (kvm_enabled ()) { -x86_cpu_accel_init (X86_CPU_ACCEL_TYPE_NAME ("kvm" )); - } -} -accel_cpu_init (kvm_cpu_accel_init);target/i386/tcg/cpu.c +0
-9@@ -170,12 +170,3 @@ static void tcg_cpu_accel_register_types(void)type_register_static (&tcg_cpu_accel_type_info); }type_init (tcg_cpu_accel_register_types); - -static void tcg_cpu_accel_init (void ) -{ -if (tcg_enabled ()) { -x86_cpu_accel_init (X86_CPU_ACCEL_TYPE_NAME ("tcg" )); - } -} - -accel_cpu_init (tcg_cpu_accel_init);Signature · 1 line
2.26.2
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
In reply to Claudio FontanaQuoted 16 lines · Claudio Fontana
target/i386/cpu.c +9
-4+static void x86_cpu_accel_init (void ) { -X86CPUAccelClass *acc; +const char *ac_name; +ObjectClass *ac; +char *xac_name; +ObjectClass *xac; - acc =X86_CPU_ACCEL_CLASS (object_class_by_name (accel_name)); -g_assert (acc !=NULL ); + ac =object_get_class (OBJECT (current_accel ())); +g_assert (ac !=NULL ); + ac_name =object_class_get_name (ac); +g_assert (ac_name !=NULL ); -object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, &acc);
target/i386/cpu.c type_init(x86_cpu_register_types) · line 7096
Quoted 10 lines
target/i386/cpu.c +9
-0+ xac_name =g_strdup_printf ("%s-%s" , ac_name,TYPE_X86_CPU ); + xac =object_class_by_name (xac_name); +g_free (xac_name); + +if (xac) { +object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, xac); + } } + +accel_cpu_init (x86_cpu_accel_init);
If this and cpus_accel_ops_init are the only call to accel_cpu_init, I'd rather make them functions in CPUClass (which you find and call via CPU_RESOLVING_TYPE) and AccelClass respectively.
Paolo
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
Quoted 21 lines · Paolo Bonzini
Quoted 20 lines · Claudio Fontana
target/i386/cpu.c +15
-4+static void x86_cpu_accel_init (void ) { -X86CPUAccelClass *acc; +const char *ac_name; +ObjectClass *ac; +char *xac_name; +ObjectClass *xac; - acc =X86_CPU_ACCEL_CLASS (object_class_by_name (accel_name)); -g_assert (acc !=NULL ); + ac =object_get_class (OBJECT (current_accel ())); +g_assert (ac !=NULL ); + ac_name =object_class_get_name (ac); +g_assert (ac_name !=NULL ); -object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, &acc); + xac_name =g_strdup_printf ("%s-%s" , ac_name,TYPE_X86_CPU ); + xac =object_class_by_name (xac_name); +g_free (xac_name); + +if (xac) { +object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, xac);
Quoted 8 lines
target/i386/cpu.c type_init(x86_cpu_register_types) · line 7096
Quoted 4 lines
target/i386/cpu.c +3
-0+ } } + +accel_cpu_init (x86_cpu_accel_init);If this and
cpus_accel_ops_initare the only call toaccel_cpu_init, I'd rather make them functions in CPUClass (which you find and call viaCPU_RESOLVING_TYPE) and AccelClass respectively.
Making x86_cpu_accel_init() be a CPUClass method sounds like a good idea. This way we won't need a arch_cpu_accel_init() stub for non-x86.
accel.c can't use cpu.h, correct? We can add a:
CPUClass *arch_base_cpu_type(void)
{
return object_class_by_name(CPU_RESOLVING_TYPE);
}function to arch_init.c, to allow target-independent code call target-specific code.
Signature · 1 line
Eduardo
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
Quoted 31 lines · Eduardo Habkost
Quoted 21 lines · Paolo Bonzini
Quoted 20 lines · Claudio Fontana
target/i386/cpu.c +15
-4+static void x86_cpu_accel_init (void ) { -X86CPUAccelClass *acc; +const char *ac_name; +ObjectClass *ac; +char *xac_name; +ObjectClass *xac; - acc =X86_CPU_ACCEL_CLASS (object_class_by_name (accel_name)); -g_assert (acc !=NULL ); + ac =object_get_class (OBJECT (current_accel ())); +g_assert (ac !=NULL ); + ac_name =object_class_get_name (ac); +g_assert (ac_name !=NULL ); -object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, &acc); + xac_name =g_strdup_printf ("%s-%s" , ac_name,TYPE_X86_CPU ); + xac =object_class_by_name (xac_name); +g_free (xac_name); + +if (xac) { +object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, xac);Quoted 8 lines
target/i386/cpu.c type_init(x86_cpu_register_types) · line 7096
Quoted 4 lines
target/i386/cpu.c +3
-0+ } } + +accel_cpu_init (x86_cpu_accel_init);If this and
cpus_accel_ops_initare the only call toaccel_cpu_init, I'd rather make them functions in CPUClass (which you find and call viaCPU_RESOLVING_TYPE) and AccelClass respectively.
Quoted 3 lines
Making
x86_cpu_accel_init()be a CPUClass method sounds like a good idea. This way we won't need aarch_cpu_accel_init()stub for non-x86.
I really don't like stubs, and trying to link the proper ones for each of the targets we need to build.
It screams "this hasn't been refactored properly yet - sorry!"
If we could avoid them it would be a clear benefit from my perspective.
Quoted 11 lines
accel.ccan't usecpu.h, correct? We can add a:CPUClass *arch_base_cpu_type(void) { return object_class_by_name(CPU_RESOLVING_TYPE); }function to
arch_init.c, to allow target-independent code call target-specific code.
Ciao,
Claudio
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
In reply to Eduardo HabkostQuoted 37 lines · Eduardo Habkost
Quoted 21 lines · Paolo Bonzini
Quoted 20 lines · Claudio Fontana
target/i386/cpu.c +15
-4+static void x86_cpu_accel_init (void ) { -X86CPUAccelClass *acc; +const char *ac_name; +ObjectClass *ac; +char *xac_name; +ObjectClass *xac; - acc =X86_CPU_ACCEL_CLASS (object_class_by_name (accel_name)); -g_assert (acc !=NULL ); + ac =object_get_class (OBJECT (current_accel ())); +g_assert (ac !=NULL ); + ac_name =object_class_get_name (ac); +g_assert (ac_name !=NULL ); -object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, &acc); + xac_name =g_strdup_printf ("%s-%s" , ac_name,TYPE_X86_CPU ); + xac =object_class_by_name (xac_name); +g_free (xac_name); + +if (xac) { +object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, xac);Quoted 8 lines
target/i386/cpu.c type_init(x86_cpu_register_types) · line 7096
Quoted 4 lines
target/i386/cpu.c +3
-0+ } } + +accel_cpu_init (x86_cpu_accel_init);If this and
cpus_accel_ops_initare the only call toaccel_cpu_init, I'd rather make them functions in CPUClass (which you find and call viaCPU_RESOLVING_TYPE) and AccelClass respectively.Making
x86_cpu_accel_init()be a CPUClass method sounds like a good idea. This way we won't need aarch_cpu_accel_init()stub for non-x86.
accel.ccan't usecpu.h, correct? We can add a:
Quoted 8 lines
CPUClass *arch_base_cpu_type(void) { return object_class_by_name(CPU_RESOLVING_TYPE); }function to
arch_init.c, to allow target-independent code call target-specific code.
Hi Eduardo,
we can't use arch-init because it is softmmu only, but we could put this in $(top_srcdir)/cpu.c
however, it would be very useful to put a:
#define TYPE_ACCEL_CPU "accel-" CPU_RESOLVING_TYPE #define ACCEL_CPU_NAME(name) (name "-" TYPE_ACCEL_CPU)
in an H file somewhere, for convenience for the programmer that has to implement subclasses in target/xxx/
But it is tough to find a header where CPU_RESOLVING_TYPE can be used.
We could I guess just use plain "cpu" instead of CPU_RESOLVING_TYPE, maybe that would be acceptable too? The interface ends up in CPUClass, so maybe ok?
So we'd end up having
accel-cpu
instead of the previous
accel-x86_64-cpu
on top of the hierarchy.
Ciao,
Claudio
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
Quoted 43 lines · Claudio Fontana
Quoted 42 lines · Eduardo Habkost
Quoted 21 lines · Paolo Bonzini
Quoted 20 lines · Claudio Fontana
target/i386/cpu.c +15
-4+static void x86_cpu_accel_init (void ) { -X86CPUAccelClass *acc; +const char *ac_name; +ObjectClass *ac; +char *xac_name; +ObjectClass *xac; - acc =X86_CPU_ACCEL_CLASS (object_class_by_name (accel_name)); -g_assert (acc !=NULL ); + ac =object_get_class (OBJECT (current_accel ())); +g_assert (ac !=NULL ); + ac_name =object_class_get_name (ac); +g_assert (ac_name !=NULL ); -object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, &acc); + xac_name =g_strdup_printf ("%s-%s" , ac_name,TYPE_X86_CPU ); + xac =object_class_by_name (xac_name); +g_free (xac_name); + +if (xac) { +object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, xac);Quoted 8 lines
target/i386/cpu.c type_init(x86_cpu_register_types) · line 7096
Quoted 4 lines
target/i386/cpu.c +3
-0+ } } + +accel_cpu_init (x86_cpu_accel_init);If this and
cpus_accel_ops_initare the only call toaccel_cpu_init, I'd rather make them functions in CPUClass (which you find and call viaCPU_RESOLVING_TYPE) and AccelClass respectively.Making
x86_cpu_accel_init()be a CPUClass method sounds like a good idea. This way we won't need aarch_cpu_accel_init()stub for non-x86.
accel.ccan't usecpu.h, correct? We can add a:CPUClass *arch_base_cpu_type(void) { return object_class_by_name(CPU_RESOLVING_TYPE); }
Quoted 7 lines
Quoted 3 lines
function to
arch_init.c, to allow target-independent code call target-specific code.Hi Eduardo,
we can't use arch-init because it is softmmu only, but we could put this in $(top_srcdir)/cpu.c
That would work, too.
Quoted 8 lines
however, it would be very useful to put a:
#define
TYPE_ACCEL_CPU"accel-"CPU_RESOLVING_TYPE#defineACCEL_CPU_NAME(name)(name "-"TYPE_ACCEL_CPU)in an H file somewhere, for convenience for the programmer that has to implement subclasses in target/xxx/
Absolutely.
Quoted 2 lines
But it is tough to find a header where
CPU_RESOLVING_TYPEcan be used.
cpu-all.h?
Quoted 6 lines
We could I guess just use plain "cpu" instead of
CPU_RESOLVING_TYPE, maybe that would be acceptable too? The interface ends up in CPUClass, so maybe ok?So we'd end up having
Quoted 7 lines
accel-cpu
instead of the previous
accel-x86_64-cpu
on top of the hierarchy.
It seems OK to have a accel-cpu type at the top, but I don't see why it solves the problem above. What exactly would be the value of kvm_cpu_accel.name?
Signature · 1 line
Eduardo
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
Quoted 80 lines · Eduardo Habkost
Quoted 43 lines · Claudio Fontana
Quoted 42 lines · Eduardo Habkost
Quoted 21 lines · Paolo Bonzini
Quoted 20 lines · Claudio Fontana
target/i386/cpu.c +15
-4+static void x86_cpu_accel_init (void ) { -X86CPUAccelClass *acc; +const char *ac_name; +ObjectClass *ac; +char *xac_name; +ObjectClass *xac; - acc =X86_CPU_ACCEL_CLASS (object_class_by_name (accel_name)); -g_assert (acc !=NULL ); + ac =object_get_class (OBJECT (current_accel ())); +g_assert (ac !=NULL ); + ac_name =object_class_get_name (ac); +g_assert (ac_name !=NULL ); -object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, &acc); + xac_name =g_strdup_printf ("%s-%s" , ac_name,TYPE_X86_CPU ); + xac =object_class_by_name (xac_name); +g_free (xac_name); + +if (xac) { +object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, xac);Quoted 8 lines
target/i386/cpu.c type_init(x86_cpu_register_types) · line 7096
Quoted 4 lines
target/i386/cpu.c +3
-0+ } } + +accel_cpu_init (x86_cpu_accel_init);If this and
cpus_accel_ops_initare the only call toaccel_cpu_init, I'd rather make them functions in CPUClass (which you find and call viaCPU_RESOLVING_TYPE) and AccelClass respectively.Making
x86_cpu_accel_init()be a CPUClass method sounds like a good idea. This way we won't need aarch_cpu_accel_init()stub for non-x86.
accel.ccan't usecpu.h, correct? We can add a:CPUClass *arch_base_cpu_type(void) { return object_class_by_name(CPU_RESOLVING_TYPE); }Quoted 7 lines
Quoted 3 lines
function to
arch_init.c, to allow target-independent code call target-specific code.Hi Eduardo,
we can't use arch-init because it is softmmu only, but we could put this in $(top_srcdir)/cpu.c
That would work, too.
Quoted 8 lines
however, it would be very useful to put a:
#define
TYPE_ACCEL_CPU"accel-"CPU_RESOLVING_TYPE#defineACCEL_CPU_NAME(name)(name "-"TYPE_ACCEL_CPU)in an H file somewhere, for convenience for the programmer that has to implement subclasses in target/xxx/
Absolutely.
Quoted 2 lines
But it is tough to find a header where
CPU_RESOLVING_TYPEcan be used.
cpu-all.h?Quoted 10 lines
We could I guess just use plain "cpu" instead of
CPU_RESOLVING_TYPE, maybe that would be acceptable too? The interface ends up in CPUClass, so maybe ok?So we'd end up having
accel-cpu
instead of the previous
Quoted 8 lines
Quoted 3 lines
accel-x86_64-cpu
on top of the hierarchy.
It seems OK to have a accel-cpu type at the top, but I don't see why it solves the problem above. What exactly would be the value of
kvm_cpu_accel.name?
It does solve the problem, because we can put then all AccelOpsClass and AccelCPUClass stuff in accel.h, resolve everything in accel/accel-*.c, and make a generic solution fairly self-contained (already tested, will post soonish).
But I'll try cpu-all.h if it's preferred to have accel-x86_64-cpu, accel-XXX-cpu on top, I wonder what the preference would be?
Ciao,
Claudio
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
Quoted 90 lines · Claudio Fontana
Quoted 80 lines · Eduardo Habkost
Quoted 43 lines · Claudio Fontana
Quoted 42 lines · Eduardo Habkost
Quoted 21 lines · Paolo Bonzini
Quoted 20 lines · Claudio Fontana
target/i386/cpu.c +15
-4+static void x86_cpu_accel_init (void ) { -X86CPUAccelClass *acc; +const char *ac_name; +ObjectClass *ac; +char *xac_name; +ObjectClass *xac; - acc =X86_CPU_ACCEL_CLASS (object_class_by_name (accel_name)); -g_assert (acc !=NULL ); + ac =object_get_class (OBJECT (current_accel ())); +g_assert (ac !=NULL ); + ac_name =object_class_get_name (ac); +g_assert (ac_name !=NULL ); -object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, &acc); + xac_name =g_strdup_printf ("%s-%s" , ac_name,TYPE_X86_CPU ); + xac =object_class_by_name (xac_name); +g_free (xac_name); + +if (xac) { +object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, xac);Quoted 8 lines
target/i386/cpu.c type_init(x86_cpu_register_types) · line 7096
Quoted 4 lines
target/i386/cpu.c +3
-0+ } } + +accel_cpu_init (x86_cpu_accel_init);If this and
cpus_accel_ops_initare the only call toaccel_cpu_init, I'd rather make them functions in CPUClass (which you find and call viaCPU_RESOLVING_TYPE) and AccelClass respectively.Making
x86_cpu_accel_init()be a CPUClass method sounds like a good idea. This way we won't need aarch_cpu_accel_init()stub for non-x86.
accel.ccan't usecpu.h, correct? We can add a:CPUClass *arch_base_cpu_type(void) { return object_class_by_name(CPU_RESOLVING_TYPE); }Quoted 7 lines
Quoted 3 lines
function to
arch_init.c, to allow target-independent code call target-specific code.Hi Eduardo,
we can't use arch-init because it is softmmu only, but we could put this in $(top_srcdir)/cpu.c
That would work, too.
Quoted 8 lines
however, it would be very useful to put a:
#define
TYPE_ACCEL_CPU"accel-"CPU_RESOLVING_TYPE#defineACCEL_CPU_NAME(name)(name "-"TYPE_ACCEL_CPU)in an H file somewhere, for convenience for the programmer that has to implement subclasses in target/xxx/
Absolutely.
Quoted 2 lines
But it is tough to find a header where
CPU_RESOLVING_TYPEcan be used.
cpu-all.h?Quoted 10 lines
We could I guess just use plain "cpu" instead of
CPU_RESOLVING_TYPE, maybe that would be acceptable too? The interface ends up in CPUClass, so maybe ok?So we'd end up having
accel-cpu
instead of the previous
Quoted 8 lines
Quoted 3 lines
accel-x86_64-cpu
on top of the hierarchy.
It seems OK to have a accel-cpu type at the top, but I don't see why it solves the problem above. What exactly would be the value of
kvm_cpu_accel.name?
Quoted 4 lines
It does solve the problem, because we can put then all AccelOpsClass and AccelCPUClass stuff in
accel.h, resolve everything inaccel/accel-*.c, and make a generic solution fairly self-contained (already tested, will post soonish).But I'll try
cpu-all.hif it's preferred to have accel-x86_64-cpu, accel-XXX-cpu on top, I wonder what the preference would be?
I don't have a specific preference, but I still wonder how exactly you would name the X86CPUAccel implemented at target/i386/kvm, and how exactly you would look for it when initializing the accelerator.
Signature · 1 line
Eduardo
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
Quoted 94 lines · Eduardo Habkost
Quoted 93 lines · Claudio Fontana
Quoted 80 lines · Eduardo Habkost
Quoted 43 lines · Claudio Fontana
Quoted 42 lines · Eduardo Habkost
Quoted 21 lines · Paolo Bonzini
Quoted 20 lines · Claudio Fontana
(quoted diff) +15
-4+static void x86_cpu_accel_init(void) { - X86CPUAccelClass *acc; + const char *ac_name; + ObjectClass *ac; + char *xac_name; + ObjectClass *xac; - acc = X86_CPU_ACCEL_CLASS(object_class_by_name(accel_name)); - g_assert(acc != NULL); + ac = object_get_class(OBJECT(current_accel())); + g_assert(ac != NULL); + ac_name = object_class_get_name(ac); + g_assert(ac_name != NULL); - object_class_foreach(x86_cpu_accel_init_aux, TYPE_X86_CPU, false, &acc); + xac_name = g_strdup_printf("%s-%s", ac_name, TYPE_X86_CPU); + xac = object_class_by_name(xac_name); + g_free(xac_name); + + if (xac) { + object_class_foreach(x86_cpu_accel_init_aux, TYPE_X86_CPU, false, xac);Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ } } + +accel_cpu_init(x86_cpu_accel_init);If this and
cpus_accel_ops_initare the only call toaccel_cpu_init, I'd rather make them functions in CPUClass (which you find and call viaCPU_RESOLVING_TYPE) and AccelClass respectively.Making
x86_cpu_accel_init()be a CPUClass method sounds like a good idea. This way we won't need aarch_cpu_accel_init()stub for non-x86.
accel.ccan't usecpu.h, correct? We can add a:CPUClass *arch_base_cpu_type(void) { return object_class_by_name(CPU_RESOLVING_TYPE); }Quoted 7 lines
Quoted 3 lines
function to
arch_init.c, to allow target-independent code call target-specific code.Hi Eduardo,
we can't use arch-init because it is softmmu only, but we could put this in $(top_srcdir)/cpu.c
That would work, too.
Quoted 8 lines
however, it would be very useful to put a:
#define
TYPE_ACCEL_CPU"accel-"CPU_RESOLVING_TYPE#defineACCEL_CPU_NAME(name)(name "-"TYPE_ACCEL_CPU)in an H file somewhere, for convenience for the programmer that has to implement subclasses in target/xxx/
Absolutely.
Quoted 2 lines
But it is tough to find a header where
CPU_RESOLVING_TYPEcan be used.
cpu-all.h?Quoted 10 lines
We could I guess just use plain "cpu" instead of
CPU_RESOLVING_TYPE, maybe that would be acceptable too? The interface ends up in CPUClass, so maybe ok?So we'd end up having
accel-cpu
instead of the previous
Quoted 8 lines
Quoted 3 lines
accel-x86_64-cpu
on top of the hierarchy.
It seems OK to have a accel-cpu type at the top, but I don't see why it solves the problem above. What exactly would be the value of
kvm_cpu_accel.name?It does solve the problem, because we can put then all AccelOpsClass and AccelCPUClass stuff in
accel.h, resolve everything inaccel/accel-*.c, and make a generic solution fairly self-contained (already tested, will post soonish).
Quoted 7 lines
Quoted 1 line
But I'll try
cpu-all.hif it's preferred to have accel-x86_64-cpu, accel-XXX-cpu on top, I wonder what the preference would be?I don't have a specific preference, but I still wonder how exactly you would name the X86CPUAccel implemented at target/i386/kvm, and how exactly you would look for it when initializing the accelerator.
If we agree to use "accel-cpu" I would lookup "kvm-accel-cpu"
if we agree to use "accel-x86_64" aka "accel-" CPU_RESOLVING_TYPE, I would lookup "kvm-accel-" CPU_RESOLVING_TYPE
* 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-cpu", ac_name);
acc = object_class_by_name(acc_name);
g_free(acc_name);
if (acc) {
object_class_foreach(accel_init_cpu_interfaces_aux, cpu_type, false, acc);
}
}Ciao,
CLaudio
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
Quoted 97 lines · Claudio Fontana
Quoted 96 lines · Eduardo Habkost
Quoted 94 lines · Claudio Fontana
Quoted 80 lines · Eduardo Habkost
Quoted 43 lines · Claudio Fontana
Quoted 42 lines · Eduardo Habkost
Quoted 21 lines · Paolo Bonzini
Quoted 20 lines · Claudio Fontana
(quoted diff) +15
-4+static void x86_cpu_accel_init(void) { - X86CPUAccelClass *acc; + const char *ac_name; + ObjectClass *ac; + char *xac_name; + ObjectClass *xac; - acc = X86_CPU_ACCEL_CLASS(object_class_by_name(accel_name)); - g_assert(acc != NULL); + ac = object_get_class(OBJECT(current_accel())); + g_assert(ac != NULL); + ac_name = object_class_get_name(ac); + g_assert(ac_name != NULL); - object_class_foreach(x86_cpu_accel_init_aux, TYPE_X86_CPU, false, &acc); + xac_name = g_strdup_printf("%s-%s", ac_name, TYPE_X86_CPU); + xac = object_class_by_name(xac_name); + g_free(xac_name); + + if (xac) { + object_class_foreach(x86_cpu_accel_init_aux, TYPE_X86_CPU, false, xac);Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ } } + +accel_cpu_init(x86_cpu_accel_init);If this and
cpus_accel_ops_initare the only call toaccel_cpu_init, I'd rather make them functions in CPUClass (which you find and call viaCPU_RESOLVING_TYPE) and AccelClass respectively.Making
x86_cpu_accel_init()be a CPUClass method sounds like a good idea. This way we won't need aarch_cpu_accel_init()stub for non-x86.
accel.ccan't usecpu.h, correct? We can add a:CPUClass *arch_base_cpu_type(void) { return object_class_by_name(CPU_RESOLVING_TYPE); }Quoted 7 lines
Quoted 3 lines
function to
arch_init.c, to allow target-independent code call target-specific code.Hi Eduardo,
we can't use arch-init because it is softmmu only, but we could put this in $(top_srcdir)/cpu.c
That would work, too.
Quoted 8 lines
however, it would be very useful to put a:
#define
TYPE_ACCEL_CPU"accel-"CPU_RESOLVING_TYPE#defineACCEL_CPU_NAME(name)(name "-"TYPE_ACCEL_CPU)in an H file somewhere, for convenience for the programmer that has to implement subclasses in target/xxx/
Absolutely.
Quoted 2 lines
But it is tough to find a header where
CPU_RESOLVING_TYPEcan be used.
cpu-all.h?Quoted 10 lines
We could I guess just use plain "cpu" instead of
CPU_RESOLVING_TYPE, maybe that would be acceptable too? The interface ends up in CPUClass, so maybe ok?So we'd end up having
accel-cpu
instead of the previous
Quoted 8 lines
Quoted 3 lines
accel-x86_64-cpu
on top of the hierarchy.
It seems OK to have a accel-cpu type at the top, but I don't see why it solves the problem above. What exactly would be the value of
kvm_cpu_accel.name?It does solve the problem, because we can put then all AccelOpsClass and AccelCPUClass stuff in
accel.h, resolve everything inaccel/accel-*.c, and make a generic solution fairly self-contained (already tested, will post soonish).But I'll try
cpu-all.hif it's preferred to have accel-x86_64-cpu, accel-XXX-cpu on top, I wonder what the preference would be?
Quoted 7 lines
Quoted 5 lines
I don't have a specific preference, but I still wonder how exactly you would name the X86CPUAccel implemented at target/i386/kvm, and how exactly you would look for it when initializing the accelerator.
If we agree to use "accel-cpu" I would lookup "kvm-accel-cpu"
The structure in target/i386/kvm is x86-specific and kvm-specific. If we name it "kvm-accel-cpu", how would you name the equivalent structures at target/s390x/kvm, target/arm/kvm, target/ppc/kvm?
The same question would apply to target/*/tcg*, and to other accelerators.
Quoted 25 lines
if we agree to use "accel-x86_64" aka "accel-"
CPU_RESOLVING_TYPE, I would lookup "kvm-accel-"CPU_RESOLVING_TYPE* 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-cpu", ac_name); acc = object_class_by_name(acc_name); g_free(acc_name); if (acc) { object_class_foreach(accel_init_cpu_interfaces_aux, cpu_type, false, acc); } }Ciao,
CLaudio
Signature · 1 line
Eduardo
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
Quoted 104 lines · Eduardo Habkost
Quoted 103 lines · Claudio Fontana
Quoted 101 lines · Eduardo Habkost
Quoted 90 lines · Claudio Fontana
Quoted 80 lines · Eduardo Habkost
Quoted 43 lines · Claudio Fontana
Quoted 42 lines · Eduardo Habkost
Quoted 21 lines · Paolo Bonzini
Quoted 20 lines · Claudio Fontana
(quoted diff) +15
-4+static void x86_cpu_accel_init(void) { - X86CPUAccelClass *acc; + const char *ac_name; + ObjectClass *ac; + char *xac_name; + ObjectClass *xac; - acc = X86_CPU_ACCEL_CLASS(object_class_by_name(accel_name)); - g_assert(acc != NULL); + ac = object_get_class(OBJECT(current_accel())); + g_assert(ac != NULL); + ac_name = object_class_get_name(ac); + g_assert(ac_name != NULL); - object_class_foreach(x86_cpu_accel_init_aux, TYPE_X86_CPU, false, &acc); + xac_name = g_strdup_printf("%s-%s", ac_name, TYPE_X86_CPU); + xac = object_class_by_name(xac_name); + g_free(xac_name); + + if (xac) { + object_class_foreach(x86_cpu_accel_init_aux, TYPE_X86_CPU, false, xac);Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ } } + +accel_cpu_init(x86_cpu_accel_init);If this and
cpus_accel_ops_initare the only call toaccel_cpu_init, I'd rather make them functions in CPUClass (which you find and call viaCPU_RESOLVING_TYPE) and AccelClass respectively.Making
x86_cpu_accel_init()be a CPUClass method sounds like a good idea. This way we won't need aarch_cpu_accel_init()stub for non-x86.
accel.ccan't usecpu.h, correct? We can add a:CPUClass *arch_base_cpu_type(void) { return object_class_by_name(CPU_RESOLVING_TYPE); }Quoted 7 lines
Quoted 3 lines
function to
arch_init.c, to allow target-independent code call target-specific code.Hi Eduardo,
we can't use arch-init because it is softmmu only, but we could put this in $(top_srcdir)/cpu.c
That would work, too.
Quoted 8 lines
however, it would be very useful to put a:
#define
TYPE_ACCEL_CPU"accel-"CPU_RESOLVING_TYPE#defineACCEL_CPU_NAME(name)(name "-"TYPE_ACCEL_CPU)in an H file somewhere, for convenience for the programmer that has to implement subclasses in target/xxx/
Absolutely.
Quoted 2 lines
But it is tough to find a header where
CPU_RESOLVING_TYPEcan be used.
cpu-all.h?Quoted 10 lines
We could I guess just use plain "cpu" instead of
CPU_RESOLVING_TYPE, maybe that would be acceptable too? The interface ends up in CPUClass, so maybe ok?So we'd end up having
accel-cpu
instead of the previous
Quoted 8 lines
Quoted 3 lines
accel-x86_64-cpu
on top of the hierarchy.
It seems OK to have a accel-cpu type at the top, but I don't see why it solves the problem above. What exactly would be the value of
kvm_cpu_accel.name?Quoted 4 lines
It does solve the problem, because we can put then all AccelOpsClass and AccelCPUClass stuff in
accel.h, resolve everything inaccel/accel-*.c, and make a generic solution fairly self-contained (already tested, will post soonish).But I'll try
cpu-all.hif it's preferred to have accel-x86_64-cpu, accel-XXX-cpu on top, I wonder what the preference would be?I don't have a specific preference, but I still wonder how exactly you would name the X86CPUAccel implemented at target/i386/kvm, and how exactly you would look for it when initializing the accelerator.
Quoted 6 lines
Quoted 1 line
If we agree to use "accel-cpu" I would lookup "kvm-accel-cpu"
The structure in target/i386/kvm is x86-specific and kvm-specific. If we name it "kvm-accel-cpu", how would you name the equivalent structures at target/s390x/kvm, target/arm/kvm, target/ppc/kvm?
The same way; only one of them would be compiled into the target binary, so the lookup would not collide in practice, but I wonder whether we want separate names anyway.
Ciao,
Claudio
Quoted 30 lines
The same question would apply to target/*/tcg*, and to other accelerators.
Quoted 25 lines
if we agree to use "accel-x86_64" aka "accel-"
CPU_RESOLVING_TYPE, I would lookup "kvm-accel-"CPU_RESOLVING_TYPE* 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-cpu", ac_name); acc = object_class_by_name(acc_name); g_free(acc_name); if (acc) { object_class_foreach(accel_init_cpu_interfaces_aux, cpu_type, false, acc); } }Ciao,
CLaudio
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
Quoted 105 lines · Claudio Fontana
Quoted 104 lines · Eduardo Habkost
Quoted 103 lines · Claudio Fontana
Quoted 101 lines · Eduardo Habkost
Quoted 90 lines · Claudio Fontana
Quoted 80 lines · Eduardo Habkost
Quoted 43 lines · Claudio Fontana
Quoted 42 lines · Eduardo Habkost
Quoted 21 lines · Paolo Bonzini
Quoted 20 lines · Claudio Fontana
(quoted diff) +15
-4+static void x86_cpu_accel_init(void) { - X86CPUAccelClass *acc; + const char *ac_name; + ObjectClass *ac; + char *xac_name; + ObjectClass *xac; - acc = X86_CPU_ACCEL_CLASS(object_class_by_name(accel_name)); - g_assert(acc != NULL); + ac = object_get_class(OBJECT(current_accel())); + g_assert(ac != NULL); + ac_name = object_class_get_name(ac); + g_assert(ac_name != NULL); - object_class_foreach(x86_cpu_accel_init_aux, TYPE_X86_CPU, false, &acc); + xac_name = g_strdup_printf("%s-%s", ac_name, TYPE_X86_CPU); + xac = object_class_by_name(xac_name); + g_free(xac_name); + + if (xac) { + object_class_foreach(x86_cpu_accel_init_aux, TYPE_X86_CPU, false, xac);Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ } } + +accel_cpu_init(x86_cpu_accel_init);If this and
cpus_accel_ops_initare the only call toaccel_cpu_init, I'd rather make them functions in CPUClass (which you find and call viaCPU_RESOLVING_TYPE) and AccelClass respectively.Making
x86_cpu_accel_init()be a CPUClass method sounds like a good idea. This way we won't need aarch_cpu_accel_init()stub for non-x86.
accel.ccan't usecpu.h, correct? We can add a:CPUClass *arch_base_cpu_type(void) { return object_class_by_name(CPU_RESOLVING_TYPE); }Quoted 7 lines
Quoted 3 lines
function to
arch_init.c, to allow target-independent code call target-specific code.Hi Eduardo,
we can't use arch-init because it is softmmu only, but we could put this in $(top_srcdir)/cpu.c
That would work, too.
Quoted 8 lines
however, it would be very useful to put a:
#define
TYPE_ACCEL_CPU"accel-"CPU_RESOLVING_TYPE#defineACCEL_CPU_NAME(name)(name "-"TYPE_ACCEL_CPU)in an H file somewhere, for convenience for the programmer that has to implement subclasses in target/xxx/
Absolutely.
Quoted 2 lines
But it is tough to find a header where
CPU_RESOLVING_TYPEcan be used.
cpu-all.h?Quoted 10 lines
We could I guess just use plain "cpu" instead of
CPU_RESOLVING_TYPE, maybe that would be acceptable too? The interface ends up in CPUClass, so maybe ok?So we'd end up having
accel-cpu
instead of the previous
Quoted 8 lines
Quoted 3 lines
accel-x86_64-cpu
on top of the hierarchy.
It seems OK to have a accel-cpu type at the top, but I don't see why it solves the problem above. What exactly would be the value of
kvm_cpu_accel.name?Quoted 4 lines
It does solve the problem, because we can put then all AccelOpsClass and AccelCPUClass stuff in
accel.h, resolve everything inaccel/accel-*.c, and make a generic solution fairly self-contained (already tested, will post soonish).But I'll try
cpu-all.hif it's preferred to have accel-x86_64-cpu, accel-XXX-cpu on top, I wonder what the preference would be?I don't have a specific preference, but I still wonder how exactly you would name the X86CPUAccel implemented at target/i386/kvm, and how exactly you would look for it when initializing the accelerator.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
If we agree to use "accel-cpu" I would lookup "kvm-accel-cpu"
The structure in target/i386/kvm is x86-specific and kvm-specific. If we name it "kvm-accel-cpu", how would you name the equivalent structures at target/s390x/kvm, target/arm/kvm, target/ppc/kvm?
The same way; only one of them would be compiled into the target binary, so the lookup would not collide in practice,
That's not always going to be true. Maybe for KVM it will, but not necessarily for TCG.
Quoted 1 line
but I wonder whether we want separate names anyway.
I believe we do. Avoiding duplicate QOM type names is a good idea in either case.
Signature · 1 line
Eduardo
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
Quoted 115 lines · Eduardo Habkost
Quoted 105 lines · Claudio Fontana
Quoted 104 lines · Eduardo Habkost
Quoted 103 lines · Claudio Fontana
Quoted 101 lines · Eduardo Habkost
Quoted 90 lines · Claudio Fontana
Quoted 80 lines · Eduardo Habkost
Quoted 43 lines · Claudio Fontana
Quoted 42 lines · Eduardo Habkost
Quoted 21 lines · Paolo Bonzini
Quoted 20 lines · Claudio Fontana
(quoted diff) +15
-4+static void x86_cpu_accel_init(void) { - X86CPUAccelClass *acc; + const char *ac_name; + ObjectClass *ac; + char *xac_name; + ObjectClass *xac; - acc = X86_CPU_ACCEL_CLASS(object_class_by_name(accel_name)); - g_assert(acc != NULL); + ac = object_get_class(OBJECT(current_accel())); + g_assert(ac != NULL); + ac_name = object_class_get_name(ac); + g_assert(ac_name != NULL); - object_class_foreach(x86_cpu_accel_init_aux, TYPE_X86_CPU, false, &acc); + xac_name = g_strdup_printf("%s-%s", ac_name, TYPE_X86_CPU); + xac = object_class_by_name(xac_name); + g_free(xac_name); + + if (xac) { + object_class_foreach(x86_cpu_accel_init_aux, TYPE_X86_CPU, false, xac);Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ } } + +accel_cpu_init(x86_cpu_accel_init);If this and
cpus_accel_ops_initare the only call toaccel_cpu_init, I'd rather make them functions in CPUClass (which you find and call viaCPU_RESOLVING_TYPE) and AccelClass respectively.Making
x86_cpu_accel_init()be a CPUClass method sounds like a good idea. This way we won't need aarch_cpu_accel_init()stub for non-x86.
accel.ccan't usecpu.h, correct? We can add a:CPUClass *arch_base_cpu_type(void) { return object_class_by_name(CPU_RESOLVING_TYPE); }Quoted 7 lines
Quoted 3 lines
function to
arch_init.c, to allow target-independent code call target-specific code.Hi Eduardo,
we can't use arch-init because it is softmmu only, but we could put this in $(top_srcdir)/cpu.c
That would work, too.
Quoted 8 lines
however, it would be very useful to put a:
#define
TYPE_ACCEL_CPU"accel-"CPU_RESOLVING_TYPE#defineACCEL_CPU_NAME(name)(name "-"TYPE_ACCEL_CPU)in an H file somewhere, for convenience for the programmer that has to implement subclasses in target/xxx/
Absolutely.
Quoted 2 lines
But it is tough to find a header where
CPU_RESOLVING_TYPEcan be used.
cpu-all.h?Quoted 10 lines
We could I guess just use plain "cpu" instead of
CPU_RESOLVING_TYPE, maybe that would be acceptable too? The interface ends up in CPUClass, so maybe ok?So we'd end up having
accel-cpu
instead of the previous
Quoted 8 lines
Quoted 3 lines
accel-x86_64-cpu
on top of the hierarchy.
It seems OK to have a accel-cpu type at the top, but I don't see why it solves the problem above. What exactly would be the value of
kvm_cpu_accel.name?Quoted 4 lines
It does solve the problem, because we can put then all AccelOpsClass and AccelCPUClass stuff in
accel.h, resolve everything inaccel/accel-*.c, and make a generic solution fairly self-contained (already tested, will post soonish).But I'll try
cpu-all.hif it's preferred to have accel-x86_64-cpu, accel-XXX-cpu on top, I wonder what the preference would be?I don't have a specific preference, but I still wonder how exactly you would name the X86CPUAccel implemented at target/i386/kvm, and how exactly you would look for it when initializing the accelerator.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
If we agree to use "accel-cpu" I would lookup "kvm-accel-cpu"
The structure in target/i386/kvm is x86-specific and kvm-specific. If we name it "kvm-accel-cpu", how would you name the equivalent structures at target/s390x/kvm, target/arm/kvm, target/ppc/kvm?
The same way; only one of them would be compiled into the target binary, so the lookup would not collide in practice,
Quoted 8 lines
That's not always going to be true. Maybe for KVM it will, but not necessarily for TCG.
Quoted 1 line
but I wonder whether we want separate names anyway.
I believe we do. Avoiding duplicate QOM type names is a good idea in either case.
Ok will try, for now I CPU_RESOLVING_TYPE is not playing nice with my attempts..
Ciao,
Claudio
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
In reply to Claudio FontanaQuoted 5 lines · Claudio Fontana
If we agree to use "accel-cpu" I would lookup "kvm-accel-cpu"
if we agree to use "accel-x86_64" aka "accel-"CPU_RESOLVING_TYPE, I would lookup "kvm-accel-"CPU_RESOLVING_TYPE* initialize the arch-specific accel CpuClass interfaces */ static void
accel_init_cpu_interfaces(AccelClass *ac, const char *cpu_type)
Quoted 16 lines
{
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-cpu", ac_name);
acc = object_class_by_name(acc_name);
g_free(acc_name);
if (acc) {
object_class_foreach(accel_init_cpu_interfaces_aux, cpu_type, false, acc);
}
}I would use the second; there's no reason to have allow only one CPU type, it's just a limitation of QEMU.
Paolo
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
In reply to Paolo BonziniQuoted 32 lines · Paolo Bonzini
Quoted 16 lines · Claudio Fontana
target/i386/cpu.c +9
-4+static void x86_cpu_accel_init (void ) { -X86CPUAccelClass *acc; +const char *ac_name; +ObjectClass *ac; +char *xac_name; +ObjectClass *xac; - acc =X86_CPU_ACCEL_CLASS (object_class_by_name (accel_name)); -g_assert (acc !=NULL ); + ac =object_get_class (OBJECT (current_accel ())); +g_assert (ac !=NULL ); + ac_name =object_class_get_name (ac); +g_assert (ac_name !=NULL ); -object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, &acc);target/i386/cpu.c type_init(x86_cpu_register_types) · line 7096
Quoted 10 lines
target/i386/cpu.c +9
-0+ xac_name =g_strdup_printf ("%s-%s" , ac_name,TYPE_X86_CPU ); + xac =object_class_by_name (xac_name); +g_free (xac_name); + +if (xac) { +object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, xac); + } } + +accel_cpu_init (x86_cpu_accel_init);If this and
cpus_accel_ops_initare the only call toaccel_cpu_init, I'd rather make them functions in CPUClass (which you find and call viaCPU_RESOLVING_TYPE) and AccelClass respectively.
Quoted 3 lines
Paolo
I don't expect others (actually I do, but it's going to be one additional call per target).
So based on RFCv5, I would see additional calls to accel_cpu_init for target/arm/cpu.c, target/s390x/cpu.c in patches to come.
I'll look into this.
Thanks,
Claudio
Re: [RFC v5 11/12] i386: centralize initialization of cpu accel interfaces
In reply to Paolo BonziniQuoted 32 lines · Paolo Bonzini
Quoted 16 lines · Claudio Fontana
target/i386/cpu.c +9
-4+static void x86_cpu_accel_init (void ) { -X86CPUAccelClass *acc; +const char *ac_name; +ObjectClass *ac; +char *xac_name; +ObjectClass *xac; - acc =X86_CPU_ACCEL_CLASS (object_class_by_name (accel_name)); -g_assert (acc !=NULL ); + ac =object_get_class (OBJECT (current_accel ())); +g_assert (ac !=NULL ); + ac_name =object_class_get_name (ac); +g_assert (ac_name !=NULL ); -object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, &acc);target/i386/cpu.c type_init(x86_cpu_register_types) · line 7096
Quoted 10 lines
target/i386/cpu.c +9
-0+ xac_name =g_strdup_printf ("%s-%s" , ac_name,TYPE_X86_CPU ); + xac =object_class_by_name (xac_name); +g_free (xac_name); + +if (xac) { +object_class_foreach (x86_cpu_accel_init_aux,TYPE_X86_CPU , false, xac); + } } + +accel_cpu_init (x86_cpu_accel_init);If this and
cpus_accel_ops_initare the only call toaccel_cpu_init, I'd rather make them functions in CPUClass (which you find and call viaCPU_RESOLVING_TYPE) and AccelClass respectively.
Quoted 2 lines
Paolo
Hi Paolo,
this works well.
The only thing is, setting the ops in the AccelClass is basically useless:
we need to cache the AccelClass * in cpus.c anyway, so I ended up not putting it in AccelClass, as nobody ends up using it.
Maybe you could look for this in the series I am posting later today,
Ciao, thanks!
Claudio
RFC v5 12/12 accel: centralize initialization of CpusAccelOps
In reply to Claudio Fontana--- accel/kvm/kvm-all.c | 9 ------- accel/kvm/kvm-cpus.c | 26 +++++++++++++----- accel/kvm/kvm-cpus.h | 2 -- accel/qtest/qtest.c | 31 ++++++++++++---------- 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 | 48 ++++++++++++++++++++++++++------- accel/tcg/tcg-cpus.h | 4 --- accel/xen/xen-all.c | 29 ++++++++++---------- include/sysemu/cpus.h | 39 ++++++++++++++++++++------- softmmu/cpus.c | 51 +++++++++++++++++++++++++++++------- target/i386/hax/hax-all.c | 9 ------- 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 | 9 ------- target/i386/whpx/whpx-all.c | 9 ------- target/i386/whpx/whpx-cpus.c | 29 +++++++++++++++----- target/i386/whpx/whpx-cpus.h | 2 -- 23 files changed, 251 insertions(+), 157 deletions(-) create mode 100644 accel/tcg/tcg-cpus-mttcg.h
accel/kvm/kvm-all.c +0 -9
@@ -3234,12 +3234,3 @@ static void kvm_type_init(void) }type_init (kvm_type_init); - -static void kvm_accel_cpu_init (void ) -{ -if (kvm_enabled ()) { -cpus_register_accel (&kvm_cpus); - } -} - -accel_cpu_init (kvm_accel_cpu_init);
accel/kvm/kvm-cpus.c +20 -6
@@ -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) +{ +CpusAccelOps *ops =CPUS_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 =CPUS_ACCEL_TYPE_NAME ("kvm" ), + + .parent =TYPE_CPUS_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
@@ -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 -14
@@ -25,11 +25,6 @@#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) {return 0 ;
@@ -51,18 +46,26 @@ static const TypeInfo qtest_accel_type = { .class_init = qtest_accel_class_init, }; +static void qtest_cpus_class_init (ObjectClass *oc,void *data) +{ +CpusAccelOps *ops =CPUS_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 =CPUS_ACCEL_TYPE_NAME ("qtest" ), + + .parent =TYPE_CPUS_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); - -static void qtest_accel_cpu_init (void ) -{ -if (qtest_enabled ()) { -cpus_register_accel (&qtest_cpus); - } -} - -accel_cpu_init (qtest_accel_cpu_init);
accel/tcg/tcg-cpus-icount.c +1 -10
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 +38 -10
61 lines not on this page · raw message
accel/tcg/tcg-cpus.h +0 -4
@@ -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 -14
@@ -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);
@@ -219,18 +215,23 @@ static const TypeInfo xen_accel_type = { .class_init = xen_accel_class_init, }; +static void xen_cpus_class_init (ObjectClass *oc,void *data) +{ +CpusAccelOps *ops =CPUS_ACCEL_OPS_CLASS (oc); + + ops->create_vcpu_thread = dummy_start_vcpu_thread; +}; +static const TypeInfo xen_cpus_type_info = { + .name =CPUS_ACCEL_TYPE_NAME ("xen" ), + + .parent =TYPE_CPUS_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); - -static void xen_accel_cpu_init (void ) -{ -if (xen_enabled ()) { -cpus_register_accel (&xen_cpus); - } -} - -accel_cpu_init (xen_accel_cpu_init);
include/sysemu/cpus.h +29 -10
@@ -1,14 +1,39 @@ +/* +* CPUS module (softmmu/cpus.c) Accelerator Ops +* +* 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 QEMU_CPUS_H #define QEMU_CPUS_H #include "qemu/timer.h" +#include "qom/object.h" + +/* accel/dummy-cpus.c */ + +/* Create a dummy vcpu for CpusAccelOps->create_vcpu_thread */ +void dummy_start_vcpu_thread(CPUState *); /* cpus.c */ -/* CPU execution threads */ +#define TYPE_CPUS_ACCEL_OPS "accel-ops" +#define CPUS_ACCEL_TYPE_NAME(name) (name "-" TYPE_CPUS_ACCEL_OPS) -typedef struct CpusAccel { - void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY */ +typedef struct CpusAccelOps CpusAccelOps; +DECLARE_CLASS_CHECKERS(CpusAccelOps, CPUS_ACCEL_OPS, TYPE_CPUS_ACCEL_OPS) + +struct CpusAccelOps { + ObjectClass parent_class; + + /* initialization function called when accel is chosen */ + void (*accel_chosen_init)(CpusAccelOps *ops); + + void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY NON-NULL */ void (*kick_vcpu_thread)(CPUState *cpu); void (*synchronize_post_reset)(CPUState *cpu);
@@ -20,13 +45,7 @@ typedef struct CpusAccel {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 */ -void dummy_start_vcpu_thread (CPUState *); +};/* interface available for cpus accelerator threads */
softmmu/cpus.c +42 -9
72 lines not on this page · raw message
target/i386/hax/hax-all.c +0 -9
@@ -1138,12 +1138,3 @@ static void hax_type_init(void) }type_init (hax_type_init); - -static void hax_accel_cpu_init (void ) -{ -if (hax_enabled ()) { -cpus_register_accel (&hax_cpus); - } -} - -accel_cpu_init (hax_accel_cpu_init);
target/i386/hax/hax-cpus.c +22 -7
@@ -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) +{ +CpusAccelOps *ops =CPUS_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 =CPUS_ACCEL_TYPE_NAME ("hax" ), + + .parent =TYPE_CPUS_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
@@ -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
@@ -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) +{ +CpusAccelOps *ops =CPUS_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 =CPUS_ACCEL_TYPE_NAME ("hvf" ), + + .parent =TYPE_CPUS_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
@@ -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 -9
@@ -910,12 +910,3 @@ static void hvf_type_init(void) }type_init (hvf_type_init); - -static void hvf_accel_cpu_init (void ) -{ -if (hvf_enabled ()) { -cpus_register_accel (&hvf_cpus); - } -} - -accel_cpu_init (hvf_accel_cpu_init);
target/i386/whpx/whpx-all.c +0 -9
@@ -1711,12 +1711,3 @@ error: }type_init (whpx_type_init); - -static void whpx_accel_cpu_init (void ) -{ -if (whpx_enabled ()) { -cpus_register_accel (&whpx_cpus); - } -} - -accel_cpu_init (whpx_accel_cpu_init);
target/i386/whpx/whpx-cpus.c +22 -7
@@ -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) +{ +CpusAccelOps *ops =CPUS_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 =CPUS_ACCEL_TYPE_NAME ("whpx" ), + + .parent =TYPE_CPUS_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
@@ -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
Re: [RFC v5 12/12] accel: centralize initialization of CpusAccelOps
Quoted 50 lines · Claudio Fontana
Signed-off-by Claudio Fontana <[email protected]>--- accel/kvm/kvm-all.c | 9 ------- accel/kvm/kvm-cpus.c | 26 +++++++++++++----- accel/kvm/kvm-cpus.h | 2 -- accel/qtest/qtest.c | 31 ++++++++++++---------- 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 | 48 ++++++++++++++++++++++++++------- accel/tcg/tcg-cpus.h | 4 --- accel/xen/xen-all.c | 29 ++++++++++---------- include/sysemu/cpus.h | 39 ++++++++++++++++++++------- softmmu/cpus.c | 51 +++++++++++++++++++++++++++++------- target/i386/hax/hax-all.c | 9 ------- 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 | 9 ------- target/i386/whpx/whpx-all.c | 9 ------- target/i386/whpx/whpx-cpus.c | 29 +++++++++++++++----- target/i386/whpx/whpx-cpus.h | 2 -- 23 files changed, 251 insertions(+), 157 deletions(-) create mode 100644 accel/tcg/tcg-cpus-mttcg.haccel/kvm/kvm-all.c +0
-9@@ -3234,12 +3234,3 @@ static void kvm_type_init(void) }type_init (kvm_type_init); - -static void kvm_accel_cpu_init (void ) -{ -if (kvm_enabled ()) { -cpus_register_accel (&kvm_cpus); - } -} - -accel_cpu_init (kvm_accel_cpu_init);accel/kvm/kvm-cpus.c +0
-0
accel/kvm/kvm-cpus.c static void kvm_start_vcpu_thread(CPUState *cpu) · line 79
Quoted 8 lines
accel/kvm/kvm-cpus.c +3
-2@@ -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) +{ +CpusAccelOps *ops =CPUS_ACCEL_OPS_CLASS (oc);
Why do you need a separate QOM type hierarchy instead of just doing this inside AccelClass methods and/or existing accel class_init functions?
accel/kvm/kvm-cpus.c static void kvm_start_vcpu_thread(CPUState *cpu) · line 85
Quoted 10 lines
accel/kvm/kvm-cpus.c +5
-4- .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;
All of these could be AccelClass fields.
TCG makes it a bit more complicated because there's a different set of methods chosen for TYPE_TCG_ACCEL depending on the configuration. This could be solved by patching AccelClass at init time, or by moving the method pointers to AccelState.
Alternatively, if you still want to keep the CpusAccel/CpusAccelOps struct, that's OK. You can just add a CpusAccel *cpu_accel_ops field to AccelClass or AccelState. No need for a separate QOM hierarchy, either.
If you _really_ want a separate TYPE_CPU_ACCEL_OPS QOM type, you can still have it. But it can be just an interface implemented by each accel subclass, instead of requiring a separate CPUS_ACCEL_TYPE_NAME(...) type to be registered for each accelerator. (I don't see why you would want it, though.)
Quoted 13 lines
accel/kvm/kvm-cpus.c +12
-0}; +static const TypeInfo kvm_cpus_type_info = { + .name =CPUS_ACCEL_TYPE_NAME ("kvm" ), + + .parent =TYPE_CPUS_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.c
Quoted 10 lines
accel/kvm/kvm-cpus.c +8
-2-typedef struct CpusAccel { - void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY */ +typedef struct CpusAccelOps CpusAccelOps ; +DECLARE_CLASS_CHECKERS(CpusAccelOps, CPUS_ACCEL_OPS, TYPE_CPUS_ACCEL_OPS) + +struct CpusAccelOps { +ObjectClass parent_class; + +/* initialization function called when accel is chosen */ +void (*accel_chosen_init)(CpusAccelOps *ops);
This can be an AccelClass method too. What about just naming it AccelClass.init?
Quoted 11 lines
accel/kvm/kvm-cpus.c +2
-2+ +void (*create_vcpu_thread)(CPUState *cpu);/* MANDATORY NON-NULL */ void (*kick_vcpu_thread)(CPUState *cpu);void (*synchronize_post_reset)(CPUState *cpu);@@ -20,13 +45,7 @@ typedef struct CpusAccel {int64_t (*get_virtual_clock)(void );int64_t (*get_elapsed_ticks)(void ); -} CpusAccel; -
[...]
accel/kvm/kvm-cpus.c
Quoted 3 lines
accel/kvm/kvm-cpus.c +3
-0+ +static void cpus_accel_ops_init (void ) +{
If we move the fields above part of AccelClass, this could be called accel_init().
accel/kvm/kvm-cpus.c
Quoted 7 lines
accel/kvm/kvm-cpus.c +7
-0+const char *ac_name; +ObjectClass *ac; +char *ops_name; +ObjectClass *ops; + + ac =object_get_class (OBJECT (current_accel ())); +g_assert (ac !=NULL );
If you call this function directly from accel_init_machine(), bsd-user:main(), and linux-user:main(), you can get AccelState* as argument, and the dependency on current_accel() becomes explicit instead of implicit.
accel/kvm/kvm-cpus.c
Quoted 6 lines
accel/kvm/kvm-cpus.c +6
-0+ ac_name =object_class_get_name (ac); +g_assert (ac_name !=NULL ); + + ops_name =g_strdup_printf ("%s-ops" , ac_name); + ops =object_class_by_name (ops_name); +g_free (ops_name);
If we make the fields above part of AccelClass, you don't need this lookup trick.
accel/kvm/kvm-cpus.c
Quoted 9 lines
accel/kvm/kvm-cpus.c +9
-0+ +/* +* all accelerators need to define ops, providing at least a mandatory +* non-NULL create_vcpu_thread operation. +*/ +g_assert (ops !=NULL ); + cpus_accel =CPUS_ACCEL_OPS_CLASS (ops); +if (cpus_accel->accel_chosen_init) { + cpus_accel->accel_chosen_init (cpus_accel);
If we move CpusAccelOps.accel_chosen_init to AccelClass.init, this would be just:
AccelClass *acc = ACCEL_GET_CLASS(accel);
if (acc->init) {
acc->init(acc);
}Quoted 1 line
+ }
Additionally, if you call arch_cpu_accel_init() here, you won't need MODULE_INIT_ACCEL_CPU anymore. The
module_call_init(MODULE_INIT_ACCEL_CPU)
call with implicit dependencies on runtime state inside vl.c and *-user/main.c becomes a trivial:
accel_init(accel)
call in accel_init_machine() and *-user:main().
Quoted 211 lines
accel/kvm/kvm-cpus.c +3
-0+} + +accel_cpu_init (cpus_accel_ops_init);target/i386/hax/hax-all.c +0
-9@@ -1138,12 +1138,3 @@ static void hax_type_init(void) }type_init (hax_type_init); - -static void hax_accel_cpu_init (void ) -{ -if (hax_enabled ()) { -cpus_register_accel (&hax_cpus); - } -} - -accel_cpu_init (hax_accel_cpu_init);target/i386/hax/hax-cpus.c +22
-7@@ -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) +{ +CpusAccelOps *ops =CPUS_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 =CPUS_ACCEL_TYPE_NAME ("hax" ), + + .parent =TYPE_CPUS_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@@ -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@@ -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) +{ +CpusAccelOps *ops =CPUS_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 =CPUS_ACCEL_TYPE_NAME ("hvf" ), + + .parent =TYPE_CPUS_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@@ -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
-9@@ -910,12 +910,3 @@ static void hvf_type_init(void) }type_init (hvf_type_init); - -static void hvf_accel_cpu_init (void ) -{ -if (hvf_enabled ()) { -cpus_register_accel (&hvf_cpus); - } -} - -accel_cpu_init (hvf_accel_cpu_init);target/i386/whpx/whpx-all.c +0
-9@@ -1711,12 +1711,3 @@ error: }type_init (whpx_type_init); - -static void whpx_accel_cpu_init (void ) -{ -if (whpx_enabled ()) { -cpus_register_accel (&whpx_cpus); - } -} - -accel_cpu_init (whpx_accel_cpu_init);target/i386/whpx/whpx-cpus.c +22
-7@@ -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) +{ +CpusAccelOps *ops =CPUS_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 =CPUS_ACCEL_TYPE_NAME ("whpx" ), + + .parent =TYPE_CPUS_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@@ -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
Signature · 1 line
Eduardo
Re: [RFC v5 12/12] accel: centralize initialization of CpusAccelOps
Quoted 75 lines · Eduardo Habkost
Quoted 50 lines · Claudio Fontana
Signed-off-by Claudio Fontana <[email protected]>--- accel/kvm/kvm-all.c | 9 ------- accel/kvm/kvm-cpus.c | 26 +++++++++++++----- accel/kvm/kvm-cpus.h | 2 -- accel/qtest/qtest.c | 31 ++++++++++++---------- 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 | 48 ++++++++++++++++++++++++++------- accel/tcg/tcg-cpus.h | 4 --- accel/xen/xen-all.c | 29 ++++++++++---------- include/sysemu/cpus.h | 39 ++++++++++++++++++++------- softmmu/cpus.c | 51 +++++++++++++++++++++++++++++------- target/i386/hax/hax-all.c | 9 ------- 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 | 9 ------- target/i386/whpx/whpx-all.c | 9 ------- target/i386/whpx/whpx-cpus.c | 29 +++++++++++++++----- target/i386/whpx/whpx-cpus.h | 2 -- 23 files changed, 251 insertions(+), 157 deletions(-) create mode 100644 accel/tcg/tcg-cpus-mttcg.haccel/kvm/kvm-all.c +0
-9@@ -3234,12 +3234,3 @@ static void kvm_type_init(void) }type_init (kvm_type_init); - -static void kvm_accel_cpu_init (void ) -{ -if (kvm_enabled ()) { -cpus_register_accel (&kvm_cpus); - } -} - -accel_cpu_init (kvm_accel_cpu_init);accel/kvm/kvm-cpus.c +0
-0accel/kvm/kvm-cpus.c static void kvm_start_vcpu_thread(CPUState *cpu) · line 79
Quoted 8 lines
accel/kvm/kvm-cpus.c +3
-2@@ -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) +{ +CpusAccelOps *ops =CPUS_ACCEL_OPS_CLASS (oc);Why do you need a separate QOM type hierarchy instead of just doing this inside AccelClass methods and/or existing accel
class_initfunctions?accel/kvm/kvm-cpus.c static void kvm_start_vcpu_thread(CPUState *cpu) · line 85
Quoted 10 lines
accel/kvm/kvm-cpus.c +5
-4- .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;
Quoted 1 line
All of these could be AccelClass fields.
Makes sense, and I like also the idea below (to have a pointer from the AccelClass to the Ops). I'll give both a try.
Quoted 4 lines
TCG makes it a bit more complicated because there's a different set of methods chosen for
TYPE_TCG_ACCELdepending on the configuration.
Right, that was a bit painful,
Quoted 2 lines
This could be solved by patching AccelClass at init time, or by moving the method pointers to AccelState.
Ok I'll experiment here.
Quoted 7 lines
Alternatively, if you still want to keep the CpusAccel/CpusAccelOps struct, that's OK. You can just add a
CpusAccel *cpu_accel_opsfield to AccelClass or AccelState. No need for a separate QOM hierarchy, either.If you _really_ want a separate
TYPE_CPU_ACCEL_OPSQOM type, you
No, I do not think I really need a separate QOM type.
Quoted 20 lines
can still have it. But it can be just an interface implemented by each accel subclass, instead of requiring a separate
CPUS_ACCEL_TYPE_NAME(...)type to be registered for each accelerator. (I don't see why you would want it, though.)Quoted 13 lines
accel/kvm/kvm-cpus.c +12
-0}; +static const TypeInfo kvm_cpus_type_info = { + .name =CPUS_ACCEL_TYPE_NAME ("kvm" ), + + .parent =TYPE_CPUS_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);[...]
Quoted 13 lines
accel/kvm/kvm-cpus.c
Quoted 10 lines
accel/kvm/kvm-cpus.c +8
-2-typedef struct CpusAccel { - void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY */ +typedef struct CpusAccelOps CpusAccelOps ; +DECLARE_CLASS_CHECKERS(CpusAccelOps, CPUS_ACCEL_OPS, TYPE_CPUS_ACCEL_OPS) + +struct CpusAccelOps { +ObjectClass parent_class; + +/* initialization function called when accel is chosen */ +void (*accel_chosen_init)(CpusAccelOps *ops);This can be an AccelClass method too. What about just naming it AccelClass.init?
yes, .init is fine for me
Quoted 13 lines
Quoted 12 lines
accel/kvm/kvm-cpus.c +2
-2+ +void (*create_vcpu_thread)(CPUState *cpu);/* MANDATORY NON-NULL */ void (*kick_vcpu_thread)(CPUState *cpu);void (*synchronize_post_reset)(CPUState *cpu);@@ -20,13 +45,7 @@ typedef struct CpusAccel {int64_t (*get_virtual_clock)(void );int64_t (*get_elapsed_ticks)(void ); -} CpusAccel; -[...]
Quoted 6 lines
accel/kvm/kvm-cpus.c
Quoted 3 lines
accel/kvm/kvm-cpus.c +3
-0+ +static void cpus_accel_ops_init (void ) +{If we move the fields above part of AccelClass, this could be called
accel_init().
*nod*
Quoted 9 lines
accel/kvm/kvm-cpus.c
Quoted 8 lines
accel/kvm/kvm-cpus.c +7
-0+const char *ac_name; +ObjectClass *ac; +char *ops_name; +ObjectClass *ops; + + ac =object_get_class (OBJECT (current_accel ())); +g_assert (ac !=NULL );
Quoted 4 lines
If you call this function directly from
accel_init_machine(), bsd-user:main(), and linux-user:main(), you can get AccelState* as argument, and the dependency oncurrent_accel()becomes explicit instead of implicit.
That I must say is a good point.
Quoted 10 lines
accel/kvm/kvm-cpus.c
Quoted 7 lines
accel/kvm/kvm-cpus.c +6
-0+ ac_name =object_class_get_name (ac); +g_assert (ac_name !=NULL ); + + ops_name =g_strdup_printf ("%s-ops" , ac_name); + ops =object_class_by_name (ops_name); +g_free (ops_name);If we make the fields above part of AccelClass, you don't need this lookup trick.
Yes, I will remove this QOM hierarchy completely.
Quoted 11 lines
accel/kvm/kvm-cpus.c
Quoted 10 lines
accel/kvm/kvm-cpus.c +9
-0+ +/* +* all accelerators need to define ops, providing at least a mandatory +* non-NULL create_vcpu_thread operation. +*/ +g_assert (ops !=NULL ); + cpus_accel =CPUS_ACCEL_OPS_CLASS (ops); +if (cpus_accel->accel_chosen_init) { + cpus_accel->accel_chosen_init (cpus_accel);
Quoted 8 lines
If we move CpusAccelOps.accel_chosen_init to AccelClass.init, this would be just:
AccelClass *acc = ACCEL_GET_CLASS(accel); if (acc->init) { acc->init(acc); }
nice...
Quoted 5 lines
Quoted 1 line
+ }
Additionally, if you call
arch_cpu_accel_init()here, you won't needMODULE_INIT_ACCEL_CPUanymore. The
Quoted 8 lines
module_call_init(MODULE_INIT_ACCEL_CPU)call with implicit dependencies on runtime state inside
vl.cand*-user/main.cbecomes a trivial:
accel_init(accel)call in
accel_init_machine()and *-user:main().
I do need a separate thing for the arch cpu accel specialization though,
without MODULE_INIT_ACCEL_CPU that link between all operations done at accel-chosen time is missing..
Quoted 204 lines
Quoted 204 lines
accel/kvm/kvm-cpus.c +3
-0+} + +accel_cpu_init (cpus_accel_ops_init);target/i386/hax/hax-all.c +0
-9@@ -1138,12 +1138,3 @@ static void hax_type_init(void) }type_init (hax_type_init); - -static void hax_accel_cpu_init (void ) -{ -if (hax_enabled ()) { -cpus_register_accel (&hax_cpus); - } -} - -accel_cpu_init (hax_accel_cpu_init);target/i386/hax/hax-cpus.c +22
-7@@ -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) +{ +CpusAccelOps *ops =CPUS_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 =CPUS_ACCEL_TYPE_NAME ("hax" ), + + .parent =TYPE_CPUS_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@@ -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@@ -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) +{ +CpusAccelOps *ops =CPUS_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 =CPUS_ACCEL_TYPE_NAME ("hvf" ), + + .parent =TYPE_CPUS_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@@ -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
-9@@ -910,12 +910,3 @@ static void hvf_type_init(void) }type_init (hvf_type_init); - -static void hvf_accel_cpu_init (void ) -{ -if (hvf_enabled ()) { -cpus_register_accel (&hvf_cpus); - } -} - -accel_cpu_init (hvf_accel_cpu_init);target/i386/whpx/whpx-all.c +0
-9@@ -1711,12 +1711,3 @@ error: }type_init (whpx_type_init); - -static void whpx_accel_cpu_init (void ) -{ -if (whpx_enabled ()) { -cpus_register_accel (&whpx_cpus); - } -} - -accel_cpu_init (whpx_accel_cpu_init);target/i386/whpx/whpx-cpus.c +22
-7@@ -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) +{ +CpusAccelOps *ops =CPUS_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 =CPUS_ACCEL_TYPE_NAME ("whpx" ), + + .parent =TYPE_CPUS_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
-0@@ -12,8 +12,6 @@#include "sysemu/cpus.h"
Quoted 9 lines
Quoted 8 lines
target/i386/whpx/whpx-cpus.h +0
-2-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
Thanks a lot for reading all this!
Back to the drawing board..
Ciao,
Claudio
Re: [RFC v5 12/12] accel: centralize initialization of CpusAccelOps
On Tue, Nov 24, 2020 at 07:52:15PM +0100, Claudio Fontana wrote:
[...]
Quoted 10 lines
Quoted 10 lines
Quoted 1 line
+ }
Additionally, if you call
arch_cpu_accel_init()here, you won't needMODULE_INIT_ACCEL_CPUanymore. The
module_call_init(MODULE_INIT_ACCEL_CPU)call with implicit dependencies on runtime state inside
vl.cand*-user/main.cbecomes a trivial:
Quoted 9 lines
Quoted 3 lines
accel_init(accel)call in
accel_init_machine()and *-user:main().I do need a separate thing for the arch cpu accel specialization though,
withoutMODULE_INIT_ACCEL_CPUthat link between all operations done at accel-chosen time is missing..
I think this is a key point we need to sort out.
What do you mean by "link between all operations done at accel-chosen time" and why that's important?
accel_init_machine() has 2-3 lines of code with side effects. It calls AccelClass.init_machine(), which may may have hundreds of lines of code. accel_setup_post() has one additional method call, which is triggered at a slightly different moment.
You are using MODULE_INIT_ACCEL for 2 additional lines of code:
- the cpus_register_accel() call
- the x86_cpu_accel_init() call
What makes those 2 lines of code so special, to make them deserve a completely new mechanism to trigger them, instead of using trivial function calls inside a accel_init() function?
Signature · 1 line
Eduardo
Re: [RFC v5 12/12] accel: centralize initialization of CpusAccelOps
Quoted 18 lines · Eduardo Habkost
On Tue, Nov 24, 2020 at 07:52:15PM +0100, Claudio Fontana wrote:
[...]Quoted 16 lines
Quoted 13 lines
Quoted 1 line
+ }
Additionally, if you call
arch_cpu_accel_init()here, you won't needMODULE_INIT_ACCEL_CPUanymore. The
module_call_init(MODULE_INIT_ACCEL_CPU)call with implicit dependencies on runtime state inside
vl.cand*-user/main.cbecomes a trivial:
accel_init(accel)call in
accel_init_machine()and *-user:main().
Quoted 8 lines
Quoted 3 lines
I do need a separate thing for the arch cpu accel specialization though,
withoutMODULE_INIT_ACCEL_CPUthat link between all operations done at accel-chosen time is missing..I think this is a key point we need to sort out.
What do you mean by "link between all operations done at accel-chosen time" and why that's important?
For understanding by a reader that tries to figure this out, (see the gid MODULE_INIT_ACCEL_CPU comment elsewhere in the thread).
And it could be that the high level plan to make accelerators fully dynamically loadable plugins in the future also conditioned me to want to have a very clear demarcation line around the choice of the accelerator.
Quoted 3 lines
accel_init_machine()has 2-3 lines of code with side effects. It callsAccelClass.init_machine(), which may may have hundreds of
could we initialize also all arch-dependent stuff in here?
Quoted 11 lines
lines of code.
accel_setup_post()has one additional method call, which is triggered at a slightly different moment.You are using
MODULE_INIT_ACCELfor 2 additional lines of code:
- thecpus_register_accel()call
- thex86_cpu_accel_init()callWhat makes those 2 lines of code so special, to make them deserve a completely new mechanism to trigger them, instead of using trivial function calls inside a
accel_init()function?
...can we do also the x86_cpu_accel_init inside accel_init()?
In any case I'll try also the alternative, it would be nice if I could bring everything together under the same roof, and easily discoverable, both the arch-specific steps that we need to do at accel-chosen time and the non-arch-specific steps.
Hope this helps clarifying where I am coming from,
but I am open to have my mind changed, also trying the alternatives you propose here could help me see first hand how things play out.
Thanks!
Claudio
Re: [RFC v5 12/12] accel: centralize initialization of CpusAccelOps
Quoted 23 lines · Claudio Fontana
Quoted 22 lines · Eduardo Habkost
On Tue, Nov 24, 2020 at 07:52:15PM +0100, Claudio Fontana wrote:
[...]Quoted 19 lines
Quoted 5 lines
Quoted 1 line
+ }
Additionally, if you call
arch_cpu_accel_init()here, you won't needMODULE_INIT_ACCEL_CPUanymore. TheQuoted 8 lines
module_call_init(MODULE_INIT_ACCEL_CPU)call with implicit dependencies on runtime state inside
vl.cand*-user/main.cbecomes a trivial:
accel_init(accel)call in
accel_init_machine()and *-user:main().I do need a separate thing for the arch cpu accel specialization though,
withoutMODULE_INIT_ACCEL_CPUthat link between all operations done at accel-chosen time is missing..
Quoted 8 lines
Quoted 4 lines
I think this is a key point we need to sort out.
What do you mean by "link between all operations done at accel-chosen time" and why that's important?
For understanding by a reader that tries to figure this out, (see the gid
MODULE_INIT_ACCEL_CPUcomment elsewhere in the thread).
Right, but how does the module_call_init(MODULE_INIT_ACCEL_CPU) indirection makes this easier to figure out than just looking at a accel_init() function that makes regular function calls?
Quoted 3 lines
And it could be that the high level plan to make accelerators fully dynamically loadable plugins in the future also conditioned me to want to have a very clear demarcation line around the choice of the accelerator.
We have dynamically loadable modules for other QOM types, already, and they just use type_init(). I don't see why an extra module_init() type makes this easier.
Quoted 8 lines
Quoted 5 lines
accel_init_machine()has 2-3 lines of code with side effects. It callsAccelClass.init_machine(), which may may have hundreds ofcould we initialize also all arch-dependent stuff in here?
You can, if you use a wrapper + stub, like arch_cpu_accel_init().
Quoted 14 lines
Quoted 5 lines
lines of code.
accel_setup_post()has one additional method call, which is triggered at a slightly different moment.Quoted 8 lines
You are using
MODULE_INIT_ACCELfor 2 additional lines of code:
- thecpus_register_accel()call
- thex86_cpu_accel_init()callWhat makes those 2 lines of code so special, to make them deserve a completely new mechanism to trigger them, instead of using trivial function calls inside a
accel_init()function?
Quoted 5 lines
...can we do also the
x86_cpu_accel_initinsideaccel_init()?In any case I'll try also the alternative, it would be nice if I could bring everything together under the same roof, and easily discoverable, both the arch-specific steps that we need to do at accel-chosen time and the non-arch-specific steps.
One way to bring everything together under the same roof is to call everything inside a accel_init() function.
Quoted 3 lines
Hope this helps clarifying where I am coming from,
but I am open to have my mind changed, also trying the alternatives you propose here could help me see first hand how things play out.
Thanks!
Signature · 1 line
Eduardo
Re: [RFC v5 12/12] accel: centralize initialization of CpusAccelOps
Quoted 30 lines · Eduardo Habkost
Quoted 29 lines · Claudio Fontana
Quoted 26 lines · Eduardo Habkost
On Tue, Nov 24, 2020 at 07:52:15PM +0100, Claudio Fontana wrote:
[...]Quoted 10 lines
Quoted 10 lines
Quoted 1 line
+ }
Additionally, if you call
arch_cpu_accel_init()here, you won't needMODULE_INIT_ACCEL_CPUanymore. The
module_call_init(MODULE_INIT_ACCEL_CPU)call with implicit dependencies on runtime state inside
vl.cand*-user/main.cbecomes a trivial:Quoted 9 lines
Quoted 3 lines
accel_init(accel)call in
accel_init_machine()and *-user:main().I do need a separate thing for the arch cpu accel specialization though,
withoutMODULE_INIT_ACCEL_CPUthat link between all operations done at accel-chosen time is missing..I think this is a key point we need to sort out.
What do you mean by "link between all operations done at accel-chosen time" and why that's important?
Quoted 6 lines
Quoted 2 lines
For understanding by a reader that tries to figure this out, (see the gid
MODULE_INIT_ACCEL_CPUcomment elsewhere in the thread).Right, but how does the
module_call_init(MODULE_INIT_ACCEL_CPU)indirection makes this easier to figure out than just looking at aaccel_init()function that makes regular function calls?
I agree, if we accomplish a single accel_init() call that does everything (accelerator initialization and arch independent ops initialization and arch dependent specialization of the x86 cpu), that would be the best outcome in my view also.
Quoted 13 lines
Quoted 5 lines
And it could be that the high level plan to make accelerators fully dynamically loadable plugins in the future also conditioned me to want to have a very clear demarcation line around the choice of the accelerator.
We have dynamically loadable modules for other QOM types, already, and they just use
type_init(). I don't see why an extramodule_init()type makes this easier.Quoted 3 lines
Quoted 3 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
accel_init_machine()has 2-3 lines of code with side effects. It callsAccelClass.init_machine(), which may may have hundreds ofcould we initialize also all arch-dependent stuff in here?
You can, if you use a wrapper + stub, like
arch_cpu_accel_init().
As mentioned elsewhere, I'll try to avoid stubs. One is too many I think in the codebase (well one is probably ok, but you get what I mean, I don't like their proliferation).
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
lines of code.
accel_setup_post()has one additional method call, which is triggered at a slightly different moment.You are using
MODULE_INIT_ACCELfor 2 additional lines of code:
- thecpus_register_accel()call
- thex86_cpu_accel_init()callWhat makes those 2 lines of code so special, to make them deserve a completely new mechanism to trigger them, instead of using trivial function calls inside a
accel_init()function?
Quoted 8 lines
Quoted 5 lines
...can we do also the
x86_cpu_accel_initinsideaccel_init()?In any case I'll try also the alternative, it would be nice if I could bring everything together under the same roof, and easily discoverable, both the arch-specific steps that we need to do at accel-chosen time and the non-arch-specific steps.
One way to bring everything together under the same roof is to call everything inside a
accel_init()function.
Will try!
Quoted 8 lines
Quoted 5 lines
Hope this helps clarifying where I am coming from,
but I am open to have my mind changed, also trying the alternatives you propose here could help me see first hand how things play out.Thanks!
Thanks,
Ciao,
Claudio
Re: [RFC v5 12/12] accel: centralize initialization of CpusAccelOps
Quoted 10 lines · Claudio Fontana
Quoted 9 lines · Eduardo Habkost
Quoted 8 lines · Claudio Fontana
Quoted 7 lines · Eduardo Habkost
On Tue, Nov 24, 2020 at 07:52:15PM +0100, Claudio Fontana wrote:
[...]Quoted 5 lines
Quoted 5 lines
Quoted 1 line
+ }
Additionally, if you call
arch_cpu_accel_init()here, you won't needMODULE_INIT_ACCEL_CPUanymore. The
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
module_call_init(MODULE_INIT_ACCEL_CPU)call with implicit dependencies on runtime state inside
vl.cand*-user/main.cbecomes a trivial:
accel_init(accel)call in
accel_init_machine()and *-user:main().
On this one I see an issue:
the *-user_main() would still need an ac->machine_init() call to initialize tcg itself, currently the accelerator initialization is put into ac->machine_init
(tcg_init, kvm_init, xen_init, etc).
Or are you proposing to move tcg initialization away from the current ->machine_init(), into the new ac->init called by accel_init()?
This would make tcg even more different from the other accelerators.
Or are you proposing for all accelerators to separate the initialization of the accelerator itself from the machine state input, leading to, for example, separating kvm-all.c kvm_init() into two functions, one which takes the input from MachineState and puts it into the AccelState, and another one which actually then initializes kvm proper? And same for all accels?
In my view we could still do in *-user main.c,
ac = ACCEL_GET_CLASS(current_accel())ac->machine_init(NULL);ac->init_cpu_interfaces(ac);
to solve this, or something like that, but also the option of fixing all accelerators to separate the gathering of the input from the MachineState to the actual accelerator initialization is a possibility to me.
Ciao,
Claudio
Quoted 91 lines
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines
Quoted 6 lines
I do need a separate thing for the arch cpu accel specialization though,
withoutMODULE_INIT_ACCEL_CPUthat link between all operations done at accel-chosen time is missing..I think this is a key point we need to sort out.
What do you mean by "link between all operations done at accel-chosen time" and why that's important?
Quoted 6 lines
Quoted 2 lines
For understanding by a reader that tries to figure this out, (see the gid
MODULE_INIT_ACCEL_CPUcomment elsewhere in the thread).Right, but how does the
module_call_init(MODULE_INIT_ACCEL_CPU)indirection makes this easier to figure out than just looking at aaccel_init()function that makes regular function calls?I agree, if we accomplish a single
accel_init()call that does everything (accelerator initialization and arch independent ops initialization and arch dependent specialization of the x86 cpu), that would be the best outcome in my view also.Quoted 13 lines
Quoted 5 lines
And it could be that the high level plan to make accelerators fully dynamically loadable plugins in the future also conditioned me to want to have a very clear demarcation line around the choice of the accelerator.
We have dynamically loadable modules for other QOM types, already, and they just use
type_init(). I don't see why an extramodule_init()type makes this easier.Quoted 3 lines
Quoted 3 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
accel_init_machine()has 2-3 lines of code with side effects. It callsAccelClass.init_machine(), which may may have hundreds ofcould we initialize also all arch-dependent stuff in here?
You can, if you use a wrapper + stub, like
arch_cpu_accel_init().As mentioned elsewhere, I'll try to avoid stubs. One is too many I think in the codebase (well one is probably ok, but you get what I mean, I don't like their proliferation).
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
lines of code.
accel_setup_post()has one additional method call, which is triggered at a slightly different moment.You are using
MODULE_INIT_ACCELfor 2 additional lines of code:
- thecpus_register_accel()call
- thex86_cpu_accel_init()callWhat makes those 2 lines of code so special, to make them deserve a completely new mechanism to trigger them, instead of using trivial function calls inside a
accel_init()function?Quoted 8 lines
Quoted 5 lines
...can we do also the
x86_cpu_accel_initinsideaccel_init()?In any case I'll try also the alternative, it would be nice if I could bring everything together under the same roof, and easily discoverable, both the arch-specific steps that we need to do at accel-chosen time and the non-arch-specific steps.
One way to bring everything together under the same roof is to call everything inside a
accel_init()function.Will try!
Quoted 8 lines
Quoted 5 lines
Hope this helps clarifying where I am coming from,
but I am open to have my mind changed, also trying the alternatives you propose here could help me see first hand how things play out.Thanks!
Thanks,
Ciao,
Claudio
Re: [RFC v5 12/12] accel: centralize initialization of CpusAccelOps
Quoted 23 lines · Claudio Fontana
Quoted 10 lines · Claudio Fontana
Quoted 9 lines · Eduardo Habkost
Quoted 8 lines · Claudio Fontana
Quoted 7 lines · Eduardo Habkost
On Tue, Nov 24, 2020 at 07:52:15PM +0100, Claudio Fontana wrote:
[...]Quoted 5 lines
Quoted 5 lines
Quoted 1 line
+ }
Additionally, if you call
arch_cpu_accel_init()here, you won't needMODULE_INIT_ACCEL_CPUanymore. TheQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
module_call_init(MODULE_INIT_ACCEL_CPU)call with implicit dependencies on runtime state inside
vl.cand*-user/main.cbecomes a trivial:
accel_init(accel)call in
accel_init_machine()and *-user:main().On this one I see an issue:
Quoted 7 lines
the *-user_main() would still need an
ac->machine_init()call to initialize tcg itself, currently the accelerator initialization is put intoac->machine_init(
tcg_init,kvm_init,xen_init, etc).Or are you proposing to move tcg initialization away from the current ->machine_init(), into the new
ac->initcalled byaccel_init()?
Yes. Anything that requires MachineState (and is softmmu-specific) would go to ->machine_init(). Anything that is not softmmu-specific would go to ->init().
Quoted 2 lines
This would make tcg even more different from the other accelerators.
That's true, but isn't this only because TCG is the only one that really needs it?
Quoted 5 lines
Or are you proposing for all accelerators to separate the initialization of the accelerator itself from the machine state input, leading to, for example, separating
kvm-all.ckvm_init()into two functions, one which takes the input from MachineState and puts it into the AccelState, and another one which actually then initializes kvm proper? And same for all accels?
That would be possible (and maybe a good idea), but not necessary to make it work.
Quoted 6 lines
In my view we could still do in *-user
main.c,ac = ACCEL_GET_CLASS(current_accel())
ac->machine_init(NULL);ac->init_cpu_interfaces(ac);
That would work too. I would implement it as an accel_init(NULL) call, however, to avoid duplicating the code from accel_init_machine().
Calling ->machine_init(NULL) is just a bit surprising because of the name (calling machine_init() when there's no machine), and because we know most accelerators will crash if getting a NULL argument.
Anyway, the split between ->machine_init() and ->init() is just a suggestion. Keeping a single init method that accepts a NULL MachineState* as argument is not my favourite option, but it works.
Whatever you choose, my only ask is to document clearly the expectations and requirements of the AccelClass methods you are using.
Quoted 8 lines
to solve this, or something like that, but also the option of fixing all accelerators to separate the gathering of the input from the MachineState to the actual accelerator initialization is a possibility to me.
Ciao,
Claudio
Thank you very much for your patience! I think we're going on the right direction.
Signature · 1 line
Eduardo
Quoted 6 lines · Claudio Fontana
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.
Quoted 7 lines
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.
It's certainly getting there. Thanks for persisting!
Paolo