accel: Remove need for AccelCPUClass
v2 cover accel: Remove need for AccelCPUClass
Could get re-review: 4 & 5
Move cpu_init/realize hooks from AccelCPUClass to AccelOpsClass. Specialize them for TCG in TCGCPUOps.
This drastically simplifies the need of per-binary QOM types per accelerator per target (see also the nice diff-stat).
Based-on: tag single-binary-20260528
Ignoring checkpatch.pl:
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
accel/accel-target.c
include/accel/accel-cpu-target.h
include/accel/accel-cpu.h
$ git backport-diff since v1:
[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively
001/ 17:[----] [--] 'target/loongarch: Remove unused 'accel/accel-cpu-target.h' header' 002/ 17:[----] [--] 'accel: Remove AccelCPUClass::cpu_class_init()' 003/ 17:[----] [--] 'accel: Rename AccelOpsClass::cpu_target_realize() -> cpu_realize()' 004/ 17:[----] [--] 'accel/hvf: Remove need for AccelCPUClass::cpu_realize' 005/ 17:[----] [--] 'accel/kvm: Remove need for AccelCPUClass::cpu_realize' 006/ 17:[----] [--] 'accel: Introduce AccelOpsClass::cpu_instance_init handler' 007/ 17:[----] [--] 'accel/whpx: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init' 008/ 17:[0002] [FC] 'accel/nvmm: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init' 009/ 17:[0002] [FC] 'accel/hvf: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init' 010/ 17:[0016] [FC] 'accel/kvm: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init' 011/ 17:[----] [--] 'accel/tcg: Convert AccelCPUClass -> new TCGCPUOps::cpu_instance_init' 012/ 17:[----] [--] 'accel: Remove AccelCPUClass::cpu_instance_init()' 013/ 17:[----] [--] 'accel/tcg: Convert AccelCPUClass -> new TCGCPUOps::cpu_realize' 014/ 17:[----] [--] 'accel/tcg: Convert X86 AccelCPUClass -> TCGCPUOps::cpu_realize' 015/ 17:[----] [--] 'accel/tcg: Convert RISCV AccelCPUClass -> TCGCPUOps::cpu_realize' 016/ 17:[----] [--] 'accel: Remove AccelCPUClass::cpu_target_realize()' 017/ 17:[----] [--] 'accel: Remove AccelCPUClass and 'accel/accel-cpu-target.h''
diff --git a/include/system/kvm.h b/include/system/kvm.h
index 2c31fa6019e..a249f076763 100644
--- a/include/system/kvm.h
+++ b/include/system/kvm.h
@@ -225,0 +226,3 @@ void kvm_irqchip_change_notify(void);
+void kvm_arch_cpu_instance_init(CPUState *cpu);
+bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp);
+
@@ -367,3 +369,0 @@ int kvm_arch_destroy_vcpu(CPUState *cpu);
-void kvm_arch_cpu_instance_init(CPUState *cpu);
-bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp);
-
diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c
index 113a23f2384..edad3c1acea 100644
--- a/accel/kvm/kvm-accel-ops.c
+++ b/accel/kvm/kvm-accel-ops.c
@@ -101 +101 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, const void *data)
- ops->cpu_target_realize = kvm_arch_cpu_realize;
+ ops->cpu_realize = kvm_arch_cpu_realize;
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
index 7d194ea112b..0f1a98b430f 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -1785,0 +1786,9 @@ void kvm_arch_accel_class_init(ObjectClass *oc)
+void kvm_arch_cpu_instance_init(CPUState *cpu)
+{
+}
+
+bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp)
+{
+ return true;
+}
+
diff --git a/target/i386/hvf/hvf-cpu.c b/target/i386/hvf/hvf-cpu.c
index 5d74ca6fd56..536bcecd7d2 100644
--- a/target/i386/hvf/hvf-cpu.c
+++ b/target/i386/hvf/hvf-cpu.c
@@ -58 +58 @@ static void hvf_cpu_xsave_init(void)
-void hvf_arch_cpu_instance_init(CPUState *cpu)
+void hvf_arch_cpu_instance_init(CPUState *cs)
diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c
index 10ab7b2a4dc..2973e28122a 100644
--- a/target/i386/nvmm/nvmm-all.c
+++ b/target/i386/nvmm/nvmm-all.c
@@ -1214 +1214 @@ static const TypeInfo nvmm_accel_type = {
-void nvmm_arch_cpu_instance_init(CPUState *cpu)
+void nvmm_arch_cpu_instance_init(CPUState *cs)
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
index 9d844c4905a..167fdd515be 100644
--- a/target/loongarch/kvm/kvm.c
+++ b/target/loongarch/kvm/kvm.c
@@ -1497,0 +1498,9 @@ void kvm_arch_accel_class_init(ObjectClass *oc)
+
+void kvm_arch_cpu_instance_init(CPUState *cpu)
+{
+}
+
+bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp)
+{
+ return true;
+}
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 013f5e852e1..894962d509f 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -2354,0 +2355,4 @@ static void alter_insns(uint64_t *word, uint64_t flags, bool on)
+void kvm_arch_cpu_instance_init(CPUState *cpu)
+{
+}
+
diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c
index 2e4f435c537..46730e72a92 100644
--- a/target/s390x/kvm/kvm.c
+++ b/target/s390x/kvm/kvm.c
@@ -2613,0 +2614,9 @@ void kvm_arch_accel_class_init(ObjectClass *oc)
+
+void kvm_arch_cpu_instance_init(CPUState *cpu)
+{
+}
+
+bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp)
+{
+ return true;
+}Philippe Mathieu-Daudé (17):
target/loongarch: Remove unused 'accel/accel-cpu-target.h' header
accel: Remove AccelCPUClass::cpu_class_init()
accel: Rename AccelOpsClass::cpu_target_realize() -> cpu_realize() accel/hvf: Remove need for AccelCPUClass::cpu_realize accel/kvm: Remove need for AccelCPUClass::cpu_realize
accel: Introduce AccelOpsClass::cpu_instance_init handler accel/whpx: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init accel/nvmm: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init accel/hvf: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init accel/kvm: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init accel/tcg: Convert AccelCPUClass -> new TCGCPUOps::cpu_instance_init
accel: Remove AccelCPUClass::cpu_instance_init() accel/tcg: Convert AccelCPUClass -> new TCGCPUOps::cpu_realize accel/tcg: Convert X86 AccelCPUClass -> TCGCPUOps::cpu_realize accel/tcg: Convert RISCV AccelCPUClass -> TCGCPUOps::cpu_realize
accel: Remove AccelCPUClass::cpu_target_realize()
accel: Remove AccelCPUClass and 'accel/accel-cpu-target.h'
accel/tcg/tcg-accel-ops.h | 1 + include/accel/accel-cpu-ops.h | 3 +- include/accel/accel-cpu-target.h | 31 -------------- include/accel/accel-cpu.h | 23 ----------- include/accel/tcg/cpu-ops.h | 2 + include/system/hvf_int.h | 1 + include/system/kvm.h | 3 ++ target/i386/nvmm/nvmm-accel-ops.h | 2 + accel/accel-common.c | 68 ++++--------------------------- accel/hvf/hvf-accel-ops.c | 3 +- accel/kvm/kvm-accel-ops.c | 2 + accel/tcg/cpu-exec.c | 15 ++++++- accel/tcg/tcg-accel-ops.c | 1 + accel/whpx/whpx-accel-ops.c | 2 + accel/whpx/whpx-common.c | 17 -------- target/arm/hvf/hvf.c | 4 ++ target/arm/kvm.c | 9 ++++ target/arm/whpx/whpx-all.c | 1 - target/i386/hvf/hvf-cpu.c | 25 ++---------- target/i386/hvf/hvf.c | 5 --- target/i386/kvm/kvm-cpu.c | 25 +----------- target/i386/nvmm/nvmm-accel-ops.c | 2 + target/i386/nvmm/nvmm-all.c | 19 +-------- target/i386/tcg/tcg-cpu.c | 28 ++----------- target/i386/whpx/whpx-all.c | 1 - target/loongarch/kvm/kvm.c | 9 ++++ target/loongarch/tcg/tcg_cpu.c | 1 - target/ppc/kvm.c | 27 +++--------- target/riscv/kvm/kvm-cpu.c | 33 +-------------- target/riscv/tcg/tcg-cpu.c | 28 +++---------- target/s390x/kvm/kvm.c | 9 ++++ 31 files changed, 95 insertions(+), 305 deletions(-) delete mode 100644 include/accel/accel-cpu-target.h delete mode 100644 include/accel/accel-cpu.h
Signature · 1 line
2.53.0
PATCH v2 1/17 target/loongarch: Remove unused 'accel/accel-cpu-target.h' header
"accel/accel-cpu-target.h" is to register accelerator target specific hooks via TypeInfo::ACCEL_CPU_NAME(), which LoongArch TCG frontend does not. Remove as unused header.
--- target/loongarch/tcg/tcg_cpu.c | 1 - 1 file changed, 1 deletion(-)
target/loongarch/tcg/tcg_cpu.c +0 -1
@@ -9,7 +9,6 @@#include "qemu/error-report.h" #include "qemu/log.h" #include "qemu/plugin.h" -#include "accel/accel-cpu-target.h" #include "accel/tcg/cpu-ldst.h" #include "accel/tcg/cpu-ops.h" #include "exec/translation-block.h"
Signature · 1 line
2.53.0
PATCH v2 2/17 accel: Remove AccelCPUClass::cpu_class_init()
In reply to Philippe Mathieu-DaudéLast implementation were removed in commits f50d0f335a6 and a522b04bb9c ("Remove AccelCPUClass::cpu_class_init need"). Remove as dead code.
--- include/accel/accel-cpu.h | 1 - accel/accel-common.c | 33 --------------------------------- 2 files changed, 34 deletions(-)
include/accel/accel-cpu.h +0 -1
@@ -15,7 +15,6 @@typedef struct AccelCPUClass {ObjectClass parent_class; -void (*cpu_class_init)(CPUClass *cc);void (*cpu_instance_init)(CPUState *cpu);bool (*cpu_target_realize)(CPUState *cpu,Error **errp); }AccelCPUClass ;
accel/accel-common.c +0 -33
@@ -32,42 +32,9 @@ const char *current_accel_name(void)return ac->name; } -static void accel_init_cpu_int_aux (ObjectClass *klass,void *opaque) -{ -CPUClass *cc =CPU_CLASS (klass); -AccelCPUClass *accel_cpu = opaque; - - cc->accel_cpu = accel_cpu; -if (accel_cpu->cpu_class_init) { - accel_cpu->cpu_class_init (cc); - } -} - -/* initialize the arch-specific accel CpuClass interfaces */ -static void accel_init_cpu_interfaces (AccelClass *ac) -{ -const char *ac_name;/* AccelClass name */ -char *acc_name;/* AccelCPUClass name */ -ObjectClass *acc;/* AccelCPUClass */ -const char *cpu_resolving_type =target_cpu_type (); - - ac_name =object_class_get_name (OBJECT_CLASS (ac)); -g_assert (ac_name !=NULL ); - - acc_name =g_strdup_printf ("%s-%s" , ac_name, cpu_resolving_type); - acc =object_class_by_name (acc_name); -g_free (acc_name); - -if (acc) { -object_class_foreach (accel_init_cpu_int_aux, - cpu_resolving_type, false, acc); - } -} -void accel_init_interfaces (AccelClass *ac) {accel_init_ops_interfaces (ac); -accel_init_cpu_interfaces (ac); }void accel_cpu_instance_init (CPUState *cpu)
Signature · 1 line
2.53.0
PATCH v2 3/17 accel: Rename AccelOpsClass::cpu_target_realize() -> cpu_realize()
In reply to Philippe Mathieu-Daudécpu_target_realize() is misleading, we simply want the host accelerator to realize its things on a vCPU. Rename more generically.
--- include/accel/accel-cpu-ops.h | 2 +- accel/accel-common.c | 5 +++-- accel/hvf/hvf-accel-ops.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-)
include/accel/accel-cpu-ops.h +1 -1
@@ -34,7 +34,7 @@ struct AccelOpsClass {/* initialization function called when accel is chosen */ void (*ops_init)(AccelClass *ac); -bool (*cpu_target_realize)(CPUState *cpu,Error **errp); +bool (*cpu_realize)(CPUState *cpu,Error **errp);bool (*cpus_are_resettable)(void );void (*cpu_reset_hold)(CPUState *cpu);
accel/accel-common.c +3 -2
@@ -60,9 +60,10 @@ bool accel_cpu_common_realize(CPUState *cpu, Error **errp)if (acc->cpu_common_realize && !acc->cpu_common_realize (cpu, errp)) {return false; } + +/* specialize with target specific realization */ if (acc->ops - && acc->ops->cpu_target_realize - && !acc->ops->cpu_target_realize (cpu, errp)) { + && acc->ops->cpu_realize && !acc->ops->cpu_realize (cpu, errp)) {return false; }
accel/hvf/hvf-accel-ops.c +1 -1
@@ -356,7 +356,7 @@ static void hvf_accel_ops_class_init(ObjectClass *oc, const void *data) {AccelOpsClass *ops =ACCEL_OPS_CLASS (oc); - ops->cpu_target_realize = hvf_arch_cpu_realize; + ops->cpu_realize = hvf_arch_cpu_realize; ops->create_vcpu_thread = hvf_start_vcpu_thread; ops->kick_vcpu_thread = hvf_kick_vcpu_thread;
Signature · 1 line
2.53.0
PATCH v2 4/17 accel/hvf: Remove need for AccelCPUClass::cpu_realize
In reply to Philippe Mathieu-Daudéaccel_cpu_common_realize() first calls accel_cpu->cpu_realize then ops->cpu_realize, which is set to hvf_arch_cpu_realize() on HVF.
We want to remove accel_cpu->cpu_realize, so have hvf_arch_cpu_realize directly call HVF AccelCPUClass target_realize handler.
--- target/i386/hvf/hvf-cpu.c | 6 +++++- target/i386/hvf/hvf.c | 5 ----- 2 files changed, 5 insertions(+), 6 deletions(-)
target/i386/hvf/hvf-cpu.c +5 -1
@@ -73,11 +73,15 @@ static void hvf_cpu_instance_init(CPUState *cs)hvf_cpu_xsave_init (); } +bool hvf_arch_cpu_realize (CPUState *cs,Error **errp) +{ +return host_cpu_realizefn (cs, errp); +} +static void hvf_cpu_accel_class_init (ObjectClass *oc,const void *data) {AccelCPUClass *acc =ACCEL_CPU_CLASS (oc); - acc->cpu_target_realize = host_cpu_realizefn; acc->cpu_instance_init = hvf_cpu_instance_init; }
target/i386/hvf/hvf.c +0 -5
@@ -369,11 +369,6 @@ int hvf_arch_init_vcpu(CPUState *cpu)return 0 ; } -bool hvf_arch_cpu_realize (CPUState *cs,Error **errp) -{ -return true; -} -static void hvf_store_events (CPUState *cpu,uint32_t ins_len,uint64_t idtvec_info) {X86CPU *x86_cpu =X86_CPU (cpu);
Signature · 1 line
2.53.0
PATCH v2 5/17 accel/kvm: Remove need for AccelCPUClass::cpu_realize
In reply to Philippe Mathieu-Daudéaccel_cpu_common_realize() first calls accel_cpu->cpu_realize then ops->cpu_realize.
Rather than having one handler for each host architecture, use a single host-specific method (prefixed with kvm_arch_* like other similar KVM methods). Register it once as AccelOpsClass cpu_realize handler. Add stubs for when a host lacks such method.
PPC's ACCEL_CPU_NAME("kvm") TypeInfo is now empty, remove it.
--- include/system/kvm.h | 2 ++ accel/kvm/kvm-accel-ops.c | 1 + target/arm/kvm.c | 5 +++++ target/i386/kvm/kvm-cpu.c | 3 +-- target/loongarch/kvm/kvm.c | 5 +++++ target/ppc/kvm.c | 23 +---------------------- target/riscv/kvm/kvm-cpu.c | 10 +--------- target/s390x/kvm/kvm.c | 5 +++++ 8 files changed, 21 insertions(+), 33 deletions(-)
include/system/kvm.h +2 -0
@@ -223,6 +223,8 @@ void kvm_irqchip_add_change_notifier(Notifier *n);void kvm_irqchip_remove_change_notifier (Notifier *n);void kvm_irqchip_change_notify (void ); +bool kvm_arch_cpu_realize (CPUState *cpu,Error **errp); +#ifdef COMPILING_PER_TARGET #include "cpu.h"
accel/kvm/kvm-accel-ops.c +1 -0
@@ -97,6 +97,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, const void *data)AccelOpsClass *ops =ACCEL_OPS_CLASS (oc); ops->create_vcpu_thread = kvm_start_vcpu_thread; + ops->cpu_realize = kvm_arch_cpu_realize; ops->cpu_thread_is_idle = kvm_vcpu_thread_is_idle; ops->cpus_are_resettable = kvm_cpus_are_resettable; ops->synchronize_post_reset = kvm_cpu_synchronize_post_reset;
target/arm/kvm.c +5 -0
@@ -1783,6 +1783,11 @@ void kvm_arch_accel_class_init(ObjectClass *oc) "Eager Page Split chunk size for hugepages. (default: 0, disabled)"); } +bool kvm_arch_cpu_realize (CPUState *cpu,Error **errp) +{ +return true; +} +int kvm_arch_insert_hw_breakpoint (vaddr addr,vaddr len,int type) {switch (type) {
target/i386/kvm/kvm-cpu.c +1 -2
@@ -39,7 +39,7 @@ static void kvm_set_guest_phys_bits(CPUState *cs) } } -static bool kvm_cpu_realizefn (CPUState *cs,Error **errp) +bool kvm_arch_cpu_realize (CPUState *cs,Error **errp) {X86CPU *cpu =X86_CPU (cs);X86CPUClass *xcc =X86_CPU_GET_CLASS (cpu);
@@ -237,7 +237,6 @@ static void kvm_cpu_accel_class_init(ObjectClass *oc, const void *data) {AccelCPUClass *acc =ACCEL_CPU_CLASS (oc); - acc->cpu_target_realize = kvm_cpu_realizefn; acc->cpu_instance_init = kvm_cpu_instance_init; }static const TypeInfo kvm_cpu_accel_type_info = {
target/loongarch/kvm/kvm.c +5 -0
@@ -1495,3 +1495,8 @@ int kvm_loongarch_set_interrupt(LoongArchCPU *cpu, int irq, int level)void kvm_arch_accel_class_init (ObjectClass *oc) { } + +bool kvm_arch_cpu_realize (CPUState *cpu,Error **errp) +{ +return true; +}
target/ppc/kvm.c +1 -22
@@ -49,7 +49,6 @@#include "elf.h" #include "system/kvm_int.h" #include "system/kvm.h" -#include "accel/accel-cpu-target.h" #include CONFIG_DEVICES
@@ -2353,7 +2352,7 @@ static void alter_insns(uint64_t *word, uint64_t flags, bool on) } } -static bool kvmppc_cpu_realize (CPUState *cs,Error **errp) +bool kvm_arch_cpu_realize (CPUState *cs,Error **errp) {int ret; const char *vcpu_str = (cs->parent_obj.hotplugged == true) ?
@@ -2995,23 +2994,3 @@ void kvmppc_set_reg_tb_offset(PowerPCCPU *cpu, int64_t tb_offset)void kvm_arch_accel_class_init (ObjectClass *oc) { } - -static void kvm_cpu_accel_class_init (ObjectClass *oc,const void *data) -{ -AccelCPUClass *acc =ACCEL_CPU_CLASS (oc); - - acc->cpu_target_realize = kvmppc_cpu_realize; -} - -static const TypeInfo kvm_cpu_accel_type_info = { - .name =ACCEL_CPU_NAME ("kvm" ), - - .parent =TYPE_ACCEL_CPU , - .class_init = kvm_cpu_accel_class_init, - .abstract = true, -}; -static void kvm_cpu_accel_register_types (void ) -{ -type_register_static (&kvm_cpu_accel_type_info); -} -type_init (kvm_cpu_accel_register_types);
target/riscv/kvm/kvm-cpu.c +1 -9
@@ -1990,14 +1990,7 @@ static void kvm_cpu_instance_init(CPUState *cs)kvm_riscv_add_cpu_user_properties (obj); } -/* -* We'll get here via the following path: -* -* riscv_cpu_realize() -* -> cpu_exec_realizefn() -* -> kvm_cpu_realize() (via accel_cpu_common_realize()) -*/ -static bool kvm_cpu_realize (CPUState *cs,Error **errp) +bool kvm_arch_cpu_realize (CPUState *cs,Error **errp) {RISCVCPU *cpu =RISCV_CPU (cs);int ret;
@@ -2120,7 +2113,6 @@ static void kvm_cpu_accel_class_init(ObjectClass *oc, const void *data)AccelCPUClass *acc =ACCEL_CPU_CLASS (oc); acc->cpu_instance_init = kvm_cpu_instance_init; - acc->cpu_target_realize = kvm_cpu_realize; }static const TypeInfo kvm_cpu_accel_type_info = {
target/s390x/kvm/kvm.c +5 -0
@@ -2611,3 +2611,8 @@ int kvm_s390_topology_set_mtcr(uint64_t attr)void kvm_arch_accel_class_init (ObjectClass *oc) { } + +bool kvm_arch_cpu_realize (CPUState *cpu,Error **errp) +{ +return true; +}
Signature · 1 line
2.53.0
Re: [PATCH v2 05/17] accel/kvm: Remove need for AccelCPUClass::cpu_realize
Quoted 13 lines · Philippe Mathieu-Daudé
accel_cpu_common_realize()first callsaccel_cpu->cpu_realizethenops->cpu_realize.Rather than having one handler for each host architecture, use a single host-specific method (prefixed with kvm_arch_* like other similar KVM methods). Register it once as AccelOpsClass
cpu_realizehandler. Add stubs for when a host lacks such method.PPC's
ACCEL_CPU_NAME("kvm")TypeInfo is now empty, remove it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>Reviewed-by Pierrick Bouvier <[email protected]>
Quoted 10 lines
--- include/system/kvm.h | 2 ++ accel/kvm/kvm-accel-ops.c | 1 + target/arm/kvm.c | 5 +++++ target/i386/kvm/kvm-cpu.c | 3 +-- target/loongarch/kvm/kvm.c | 5 +++++ target/ppc/kvm.c | 23 +---------------------- target/riscv/kvm/kvm-cpu.c | 10 +--------- target/s390x/kvm/kvm.c | 5 +++++ 8 files changed, 21 insertions(+), 33 deletions(-)
For the s390x changes:
PATCH v2 6/17 accel: Introduce AccelOpsClass::cpu_instance_init handler
In reply to Philippe Mathieu-Daudéaccel_cpu_instance_init() currently dispatch via target specific AccelCPUClass which we want to remove. Introduce a similar hook in the generic AccelOpsClass structure.
We will convert implementations from one struct to the other, so add an assertion to be sure only one implementation at a time.
--- include/accel/accel-cpu-ops.h | 1 + accel/accel-common.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-)
include/accel/accel-cpu-ops.h +1 -0
@@ -34,6 +34,7 @@ struct AccelOpsClass {/* initialization function called when accel is chosen */ void (*ops_init)(AccelClass *ac); +void (*cpu_instance_init)(CPUState *cpu);bool (*cpu_realize)(CPUState *cpu,Error **errp);bool (*cpus_are_resettable)(void );void (*cpu_reset_hold)(CPUState *cpu);
accel/accel-common.c +9 -1
@@ -39,7 +39,15 @@ void accel_init_interfaces(AccelClass *ac)void accel_cpu_instance_init (CPUState *cpu) { -if (cpu->cc->accel_cpu && cpu->cc->accel_cpu->cpu_instance_init) { +AccelState *accel =current_accel (); +AccelClass *acc =ACCEL_GET_CLASS (accel); + +if (acc->ops && acc->ops->cpu_instance_init) { +if (cpu->cc->accel_cpu) { +assert (!cpu->cc->accel_cpu->cpu_instance_init); + } + acc->ops->cpu_instance_init (cpu); + }else if (cpu->cc->accel_cpu && cpu->cc->accel_cpu->cpu_instance_init) { cpu->cc->accel_cpu->cpu_instance_init (cpu); } }
Signature · 1 line
2.53.0
PATCH v2 7/17 accel/whpx: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init
In reply to Philippe Mathieu-DaudéRegister the new AccelOpsClass::cpu_instance_init hook.
ACCEL_CPU_NAME("whpx") TypeInfo is now empty, remove it.
--- accel/whpx/whpx-accel-ops.c | 2 ++ accel/whpx/whpx-common.c | 17 ----------------- target/arm/whpx/whpx-all.c | 1 - target/i386/whpx/whpx-all.c | 1 - 4 files changed, 2 insertions(+), 19 deletions(-)
accel/whpx/whpx-accel-ops.c +2 -0
@@ -98,6 +98,8 @@ static void whpx_accel_ops_class_init(ObjectClass *oc, const void *data) ops->handle_interrupt = generic_handle_interrupt; ops->supports_guest_debug = whpx_supports_guest_debug; + ops->cpu_instance_init = whpx_cpu_instance_init; + 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;
accel/whpx/whpx-common.c +0 -17
@@ -24,7 +24,6 @@#include "qapi/qapi-types-common.h" #include "qapi/qapi-visit-common.h" #include "migration/blocker.h" -#include "accel/accel-cpu-target.h" #include <winerror.h> #include "system/whpx-internal.h"
@@ -505,21 +504,6 @@ static void whpx_set_hyperv(Object *obj, Visitor *v, } } -static void whpx_cpu_accel_class_init (ObjectClass *oc,const void *data) -{ -AccelCPUClass *acc =ACCEL_CPU_CLASS (oc); - - acc->cpu_instance_init = whpx_cpu_instance_init; -} - -static const TypeInfo whpx_cpu_accel_type = { - .name =ACCEL_CPU_NAME ("whpx" ), - - .parent =TYPE_ACCEL_CPU , - .class_init = whpx_cpu_accel_class_init, - .abstract = true, -}; -static void whpx_accel_class_init (ObjectClass *oc,const void *data) {AccelClass *ac =ACCEL_CLASS (oc);
@@ -569,7 +553,6 @@ static const TypeInfo whpx_accel_type = {static void whpx_type_init (void ) {type_register_static (&whpx_accel_type); -type_register_static (&whpx_cpu_accel_type); }bool init_whp_dispatch (void )
target/arm/whpx/whpx-all.c +0 -1
@@ -23,7 +23,6 @@#include "qapi/qapi-types-common.h" #include "qapi/qapi-visit-common.h" #include "migration/blocker.h" -#include "accel/accel-cpu-target.h" #include <winerror.h> #include "syndrome.h"
target/i386/whpx/whpx-all.c +0 -1
@@ -33,7 +33,6 @@#include "qapi/qapi-visit-common.h" #include "migration/blocker.h" #include "host-cpu.h" -#include "accel/accel-cpu-target.h" #include <winerror.h> #include "system/whpx-internal.h"
Signature · 1 line
2.53.0
PATCH v2 8/17 accel/nvmm: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init
In reply to Philippe Mathieu-DaudéRegister the new AccelOpsClass::cpu_instance_init hook.
ACCEL_CPU_NAME("nvmm") TypeInfo is now empty, remove it.
--- target/i386/nvmm/nvmm-accel-ops.h | 2 ++ target/i386/nvmm/nvmm-accel-ops.c | 2 ++ target/i386/nvmm/nvmm-all.c | 19 +------------------ 3 files changed, 5 insertions(+), 18 deletions(-)
target/i386/nvmm/nvmm-accel-ops.h +2 -0
@@ -16,6 +16,8 @@ int nvmm_init_vcpu(CPUState *cpu);int nvmm_vcpu_exec (CPUState *cpu);void nvmm_destroy_vcpu (CPUState *cpu); +void nvmm_arch_cpu_instance_init (CPUState *cpu); +void nvmm_cpu_synchronize_state (CPUState *cpu);void nvmm_cpu_synchronize_post_reset (CPUState *cpu);void nvmm_cpu_synchronize_post_init (CPUState *cpu);
target/i386/nvmm/nvmm-accel-ops.c +2 -0
@@ -87,6 +87,8 @@ static void nvmm_accel_ops_class_init(ObjectClass *oc, const void *data) ops->kick_vcpu_thread = nvmm_kick_vcpu_thread; ops->handle_interrupt = generic_handle_interrupt; + ops->cpu_instance_init = nvmm_arch_cpu_instance_init; + ops->synchronize_post_reset = nvmm_cpu_synchronize_post_reset; ops->synchronize_post_init = nvmm_cpu_synchronize_post_init; ops->synchronize_state = nvmm_cpu_synchronize_state;
target/i386/nvmm/nvmm-all.c +1 -18
@@ -22,7 +22,6 @@#include "qemu/error-report.h" #include "qapi/error.h" #include "qemu/queue.h" -#include "accel/accel-cpu-target.h" #include "host-cpu.h" #include "migration/blocker.h" #include "strings.h"
@@ -1212,33 +1211,17 @@ static const TypeInfo nvmm_accel_type = { .class_init = nvmm_accel_class_init, }; -static void nvmm_cpu_instance_init (CPUState *cs) +void nvmm_arch_cpu_instance_init (CPUState *cs) {X86CPU *cpu =X86_CPU (cs);host_cpu_instance_init (cpu); } -static void nvmm_cpu_accel_class_init (ObjectClass *oc,const void *data) -{ -AccelCPUClass *acc =ACCEL_CPU_CLASS (oc); - - acc->cpu_instance_init = nvmm_cpu_instance_init; -} - -static const TypeInfo nvmm_cpu_accel_type = { - .name =ACCEL_CPU_NAME ("nvmm" ), - - .parent =TYPE_ACCEL_CPU , - .class_init = nvmm_cpu_accel_class_init, - .abstract = true, -}; -static void nvmm_type_init (void ) {type_register_static (&nvmm_accel_type); -type_register_static (&nvmm_cpu_accel_type); }type_init (nvmm_type_init);
Signature · 1 line
2.53.0
PATCH v2 9/17 accel/hvf: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init
In reply to Philippe Mathieu-DaudéHVF cpu_instance_init() was only implemented for X86. Add a stub for ARM, allowing to register as generic AccelOpsClass::cpu_instance_init hook.
X86's ACCEL_CPU_NAME("hvf") TypeInfo is now empty, remove it.
--- include/system/hvf_int.h | 1 + accel/hvf/hvf-accel-ops.c | 1 + target/arm/hvf/hvf.c | 4 ++++ target/i386/hvf/hvf-cpu.c | 25 +------------------------ 4 files changed, 7 insertions(+), 24 deletions(-)
include/system/hvf_int.h +1 -0
@@ -109,6 +109,7 @@ int hvf_update_guest_debug(CPUState *cpu);*/ bool hvf_arch_supports_guest_debug (void ); +void hvf_arch_cpu_instance_init (CPUState *cpu);bool hvf_arch_cpu_realize (CPUState *cpu,Error **errp);uint32_t hvf_arch_get_default_ipa_bit_size (void );uint32_t hvf_arch_get_max_ipa_bit_size (void );
accel/hvf/hvf-accel-ops.c +1 -0
@@ -356,6 +356,7 @@ static void hvf_accel_ops_class_init(ObjectClass *oc, const void *data) {AccelOpsClass *ops =ACCEL_OPS_CLASS (oc); + ops->cpu_instance_init = hvf_arch_cpu_instance_init; ops->cpu_realize = hvf_arch_cpu_realize; ops->create_vcpu_thread = hvf_start_vcpu_thread;
target/arm/hvf/hvf.c +4 -0
@@ -1504,6 +1504,10 @@ int hvf_arch_init_vcpu(CPUState *cpu)return 0 ; } +void hvf_arch_cpu_instance_init (CPUState *cpu) +{ +} +bool hvf_arch_cpu_realize (CPUState *cs,Error **errp) {ARMCPU *cpu =ARM_CPU (cs);
target/i386/hvf/hvf-cpu.c +1 -24
@@ -14,7 +14,6 @@#include "system/system.h" #include "hw/core/boards.h" #include "system/hvf.h" -#include "accel/accel-cpu-target.h" #include "hvf-i386.h" static void hvf_cpu_max_instance_init (X86CPU *cpu)
@@ -56,7 +55,7 @@ static void hvf_cpu_xsave_init(void) } } -static void hvf_cpu_instance_init (CPUState *cs) +void hvf_arch_cpu_instance_init (CPUState *cs) {X86CPU *cpu =X86_CPU (cs);X86CPUClass *xcc =X86_CPU_GET_CLASS (cpu);
@@ -77,25 +76,3 @@ bool hvf_arch_cpu_realize(CPUState *cs, Error **errp) {return host_cpu_realizefn (cs, errp); } - -static void hvf_cpu_accel_class_init (ObjectClass *oc,const void *data) -{ -AccelCPUClass *acc =ACCEL_CPU_CLASS (oc); - - acc->cpu_instance_init = hvf_cpu_instance_init; -} - -static const TypeInfo hvf_cpu_accel_type_info = { - .name =ACCEL_CPU_NAME ("hvf" ), - - .parent =TYPE_ACCEL_CPU , - .class_init = hvf_cpu_accel_class_init, - .abstract = true, -}; - -static void hvf_cpu_accel_register_types (void ) -{ -type_register_static (&hvf_cpu_accel_type_info); -} - -type_init (hvf_cpu_accel_register_types);
Signature · 1 line
2.53.0
PATCH v2 10/17 accel/kvm: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init
In reply to Philippe Mathieu-DaudéExpose kvm_arch_cpu_instance_init() and register it as generic AccelOpsClass::cpu_instance_init hook.
Both X86 / RISCV's ACCEL_CPU_NAME("kvm") TypeInfo are now empty, remove them.
--- include/system/kvm.h | 1 + accel/kvm/kvm-accel-ops.c | 1 + target/arm/kvm.c | 4 ++++ target/i386/kvm/kvm-cpu.c | 22 +--------------------- target/loongarch/kvm/kvm.c | 4 ++++ target/ppc/kvm.c | 4 ++++ target/riscv/kvm/kvm-cpu.c | 23 +---------------------- target/s390x/kvm/kvm.c | 4 ++++ 8 files changed, 20 insertions(+), 43 deletions(-)
include/system/kvm.h +1 -0
@@ -223,6 +223,7 @@ void kvm_irqchip_add_change_notifier(Notifier *n);void kvm_irqchip_remove_change_notifier (Notifier *n);void kvm_irqchip_change_notify (void ); +void kvm_arch_cpu_instance_init (CPUState *cpu);bool kvm_arch_cpu_realize (CPUState *cpu,Error **errp);#ifdef COMPILING_PER_TARGET
accel/kvm/kvm-accel-ops.c +1 -0
@@ -97,6 +97,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, const void *data)AccelOpsClass *ops =ACCEL_OPS_CLASS (oc); ops->create_vcpu_thread = kvm_start_vcpu_thread; + ops->cpu_instance_init = kvm_arch_cpu_instance_init; ops->cpu_realize = kvm_arch_cpu_realize; ops->cpu_thread_is_idle = kvm_vcpu_thread_is_idle; ops->cpus_are_resettable = kvm_cpus_are_resettable;
target/arm/kvm.c +4 -0
@@ -1783,6 +1783,10 @@ void kvm_arch_accel_class_init(ObjectClass *oc) "Eager Page Split chunk size for hugepages. (default: 0, disabled)"); } +void kvm_arch_cpu_instance_init (CPUState *cpu) +{ +} +bool kvm_arch_cpu_realize (CPUState *cpu,Error **errp) {return true;
target/i386/kvm/kvm-cpu.c +1 -21
@@ -16,7 +16,6 @@#include "hw/i386/x86.h" #include "kvm_i386.h" -#include "accel/accel-cpu-target.h" static void kvm_set_guest_phys_bits (CPUState *cs) {
@@ -207,7 +206,7 @@ static void x86_cpu_change_kvm_default(const char *prop, const char *value)assert (pv->prop); } -static void kvm_cpu_instance_init (CPUState *cs) +void kvm_arch_cpu_instance_init (CPUState *cs) {X86CPU *cpu =X86_CPU (cs);X86CPUClass *xcc =X86_CPU_GET_CLASS (cpu);
@@ -232,22 +231,3 @@ static void kvm_cpu_instance_init(CPUState *cs)kvm_cpu_xsave_init (); } - -static void kvm_cpu_accel_class_init (ObjectClass *oc,const void *data) -{ -AccelCPUClass *acc =ACCEL_CPU_CLASS (oc); - - acc->cpu_instance_init = kvm_cpu_instance_init; -} -static const TypeInfo kvm_cpu_accel_type_info = { - .name =ACCEL_CPU_NAME ("kvm" ), - - .parent =TYPE_ACCEL_CPU , - .class_init = kvm_cpu_accel_class_init, - .abstract = true, -}; -static void kvm_cpu_accel_register_types (void ) -{ -type_register_static (&kvm_cpu_accel_type_info); -} -type_init (kvm_cpu_accel_register_types);
target/loongarch/kvm/kvm.c +4 -0
@@ -1496,6 +1496,10 @@ void kvm_arch_accel_class_init(ObjectClass *oc) { } +void kvm_arch_cpu_instance_init (CPUState *cpu) +{ +} +bool kvm_arch_cpu_realize (CPUState *cpu,Error **errp) {return true;
target/ppc/kvm.c +4 -0
@@ -2352,6 +2352,10 @@ static void alter_insns(uint64_t *word, uint64_t flags, bool on) } } +void kvm_arch_cpu_instance_init (CPUState *cpu) +{ +} +bool kvm_arch_cpu_realize (CPUState *cs,Error **errp) {int ret;
target/riscv/kvm/kvm-cpu.c +1 -22
@@ -32,7 +32,6 @@#include "system/kvm_int.h" #include "cpu.h" #include "trace.h" -#include "accel/accel-cpu-target.h" #include "hw/pci/pci.h" #include "exec/memattrs.h" #include "system/address-spaces.h"
@@ -1981,7 +1980,7 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, kvm_msi_via_irqfd_allowed = true; } -static void kvm_cpu_instance_init (CPUState *cs) +void kvm_arch_cpu_instance_init (CPUState *cs) {Object *obj =OBJECT (RISCV_CPU (cs));
@@ -2108,26 +2107,6 @@ void riscv_kvm_cpu_finalize_features(RISCVCPU *cpu, Error **errp)kvm_riscv_destroy_scratch_vcpu (&kvmcpu); } -static void kvm_cpu_accel_class_init (ObjectClass *oc,const void *data) -{ -AccelCPUClass *acc =ACCEL_CPU_CLASS (oc); - - acc->cpu_instance_init = kvm_cpu_instance_init; -} - -static const TypeInfo kvm_cpu_accel_type_info = { - .name =ACCEL_CPU_NAME ("kvm" ), - - .parent =TYPE_ACCEL_CPU , - .class_init = kvm_cpu_accel_class_init, - .abstract = true, -}; -static void kvm_cpu_accel_register_types (void ) -{ -type_register_static (&kvm_cpu_accel_type_info); -} -type_init (kvm_cpu_accel_register_types); -static const TypeInfo riscv_kvm_cpu_type_infos[] = { { .name =TYPE_RISCV_CPU_HOST ,
target/s390x/kvm/kvm.c +4 -0
@@ -2612,6 +2612,10 @@ void kvm_arch_accel_class_init(ObjectClass *oc) { } +void kvm_arch_cpu_instance_init (CPUState *cpu) +{ +} +bool kvm_arch_cpu_realize (CPUState *cpu,Error **errp) {return true;
Signature · 1 line
2.53.0
Re: [PATCH v2 10/17] accel/kvm: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init
Quoted 9 lines · Philippe Mathieu-Daudé
Expose
kvm_arch_cpu_instance_init()and register it as genericAccelOpsClass::cpu_instance_inithook.Both X86 / RISCV's
ACCEL_CPU_NAME("kvm")TypeInfo are now empty, remove them.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>Reviewed-by Pierrick Bouvier <[email protected]>
Quoted 11 lines
--- include/system/kvm.h | 1 + accel/kvm/kvm-accel-ops.c | 1 + target/arm/kvm.c | 4 ++++ target/i386/kvm/kvm-cpu.c | 22 +--------------------- target/loongarch/kvm/kvm.c | 4 ++++ target/ppc/kvm.c | 4 ++++ target/riscv/kvm/kvm-cpu.c | 23 +---------------------- target/s390x/kvm/kvm.c | 4 ++++ 8 files changed, 20 insertions(+), 43 deletions(-)
For the s390x changes:
PATCH v2 11/17 accel/tcg: Convert AccelCPUClass -> new TCGCPUOps::cpu_instance_init
In reply to Philippe Mathieu-DaudéIntroduce a TCGCPUOps::cpu_instance_init hook and call it with tcg_cpu_instance_init(). Register tcg_cpu_instance_init() as AccelOpsClass::cpu_instance_init.
At the same time, convert X86 and RISCV AccelCPUClass hooks, after forward-declaring each target method (to avoid moving code around).
--- accel/tcg/tcg-accel-ops.h | 1 + include/accel/tcg/cpu-ops.h | 1 + accel/tcg/cpu-exec.c | 9 +++++++++ accel/tcg/tcg-accel-ops.c | 1 + target/i386/tcg/tcg-cpu.c | 5 +++-- target/riscv/tcg/tcg-cpu.c | 4 +++- 6 files changed, 18 insertions(+), 3 deletions(-)
accel/tcg/tcg-accel-ops.h +1 -0
@@ -14,6 +14,7 @@#include "system/cpus.h" +void tcg_cpu_instance_init (CPUState *cpu);void tcg_cpu_destroy (CPUState *cpu);int tcg_cpu_exec (CPUState *cpu);void tcg_handle_interrupt (CPUState *cpu,int mask);
include/accel/tcg/cpu-ops.h +1 -0
@@ -48,6 +48,7 @@ struct TCGCPUOps {* Called when the first CPU is realized. */ void (*initialize)(void ); +void (*cpu_instance_init)(CPUState *cpu);/** * @translate_code: Translate guest instructions to TCGOps * @cpu: cpu context
accel/tcg/cpu-exec.c +9 -0
@@ -1045,6 +1045,15 @@ int cpu_exec(CPUState *cpu)return ret; } +void tcg_cpu_instance_init (CPUState *cpu) +{ +const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops; + +if (tcg_ops->cpu_instance_init) { + tcg_ops->cpu_instance_init (cpu); + } +} +bool tcg_exec_realizefn (CPUState *cpu,Error **errp) {static bool tcg_target_initialized;
accel/tcg/tcg-accel-ops.c +1 -0
@@ -219,6 +219,7 @@ static void tcg_accel_ops_init(AccelClass *ac) } } + ops->cpu_instance_init = tcg_cpu_instance_init; ops->cpu_reset_hold = tcg_cpu_reset_hold; ops->supports_guest_debug = tcg_supports_guest_debug; ops->insert_breakpoint = tcg_insert_breakpoint;
target/i386/tcg/tcg-cpu.c +3 -2
@@ -157,6 +157,8 @@ static vaddr x86_pointer_wrap(CPUState *cs, int mmu_idx, }#endif +static void x86_tcg_cpu_instance_init (CPUState *cs); +const TCGCPUOps x86_tcg_ops = { .mttcg_supported = true, .precise_smc = true,
@@ -165,6 +167,7 @@ const TCGCPUOps x86_tcg_ops = {*/ .guest_default_memory_order = TCG_MO_ALL & ~TCG_MO_ST_LD, .initialize = tcg_x86_init, + .cpu_instance_init = x86_tcg_cpu_instance_init, .translate_code = x86_translate_code, .get_tb_cpu_state = x86_get_tb_cpu_state, .synchronize_from_tb = x86_cpu_synchronize_from_tb,
@@ -237,8 +240,6 @@ static void x86_tcg_cpu_accel_class_init(ObjectClass *oc, const void *data)#ifndef CONFIG_USER_ONLY acc->cpu_target_realize = tcg_cpu_realizefn;#endif /* CONFIG_USER_ONLY */ - - acc->cpu_instance_init = x86_tcg_cpu_instance_init; }static const TypeInfo x86_tcg_cpu_accel_type_info = { .name =ACCEL_CPU_NAME ("tcg" ),
target/riscv/tcg/tcg-cpu.c +3 -1
@@ -268,11 +268,14 @@ static vaddr riscv_pointer_wrap(CPUState *cs, int mmu_idx, }#endif +static void riscv_tcg_cpu_instance_init (CPUState *cs); +const TCGCPUOps riscv_tcg_ops = { .mttcg_supported = true, .guest_default_memory_order =0 , .initialize = riscv_translate_init, + .cpu_instance_init = riscv_tcg_cpu_instance_init, .translate_code = riscv_translate_code, .get_tb_cpu_state = riscv_get_tb_cpu_state, .synchronize_from_tb = riscv_cpu_synchronize_from_tb,
@@ -1678,7 +1681,6 @@ static void riscv_tcg_cpu_accel_class_init(ObjectClass *oc, const void *data) {AccelCPUClass *acc =ACCEL_CPU_CLASS (oc); - acc->cpu_instance_init = riscv_tcg_cpu_instance_init; acc->cpu_target_realize = riscv_tcg_cpu_realize; }
Signature · 1 line
2.53.0
PATCH v2 12/17 accel: Remove AccelCPUClass::cpu_instance_init()
In reply to Philippe Mathieu-DaudéWe removed all implementations: remove as dead code.
--- include/accel/accel-cpu.h | 1 - accel/accel-common.c | 5 ----- 2 files changed, 6 deletions(-)
include/accel/accel-cpu.h +0 -1
@@ -15,7 +15,6 @@typedef struct AccelCPUClass {ObjectClass parent_class; -void (*cpu_instance_init)(CPUState *cpu);bool (*cpu_target_realize)(CPUState *cpu,Error **errp); }AccelCPUClass ;
accel/accel-common.c +0 -5
@@ -43,12 +43,7 @@ void accel_cpu_instance_init(CPUState *cpu)AccelClass *acc =ACCEL_GET_CLASS (accel);if (acc->ops && acc->ops->cpu_instance_init) { -if (cpu->cc->accel_cpu) { -assert (!cpu->cc->accel_cpu->cpu_instance_init); - } acc->ops->cpu_instance_init (cpu); - }else if (cpu->cc->accel_cpu && cpu->cc->accel_cpu->cpu_instance_init) { - cpu->cc->accel_cpu->cpu_instance_init (cpu); } }
Signature · 1 line
2.53.0
PATCH v2 13/17 accel/tcg: Convert AccelCPUClass -> new TCGCPUOps::cpu_realize
In reply to Philippe Mathieu-DaudéIntroduce a TCGCPUOps::cpu_realize hook and call it at the end of tcg_exec_realizefn().
--- include/accel/tcg/cpu-ops.h | 1 + accel/tcg/cpu-exec.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-)
include/accel/tcg/cpu-ops.h +1 -0
@@ -49,6 +49,7 @@ struct TCGCPUOps {*/ void (*initialize)(void );void (*cpu_instance_init)(CPUState *cpu); +bool (*cpu_realize)(CPUState *cpu,Error **errp);/** * @translate_code: Translate guest instructions to TCGOps * @cpu: cpu context
accel/tcg/cpu-exec.c +5 -1
@@ -1056,11 +1056,11 @@ void tcg_cpu_instance_init(CPUState *cpu)bool tcg_exec_realizefn (CPUState *cpu,Error **errp) { +const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops;static bool tcg_target_initialized;if (!tcg_target_initialized) {/* Check mandatory TCGCPUOps handlers */ -const TCGCPUOps *tcg_ops = cpu->cc->tcg_ops;#ifndef CONFIG_USER_ONLY assert (tcg_ops->cpu_exec_halt);assert (tcg_ops->cpu_exec_interrupt);
@@ -1081,6 +1081,10 @@ bool tcg_exec_realizefn(CPUState *cpu, Error **errp)#endif /* !CONFIG_USER_ONLY */ /* qemu_plugin_vcpu_init_hook delayed until cpu_index assigned. */ +if (tcg_ops->cpu_realize && !tcg_ops->cpu_realize (cpu, errp)) { +return false; + } +return true; }
Signature · 1 line
2.53.0
PATCH v2 14/17 accel/tcg: Convert X86 AccelCPUClass -> TCGCPUOps::cpu_realize
In reply to Philippe Mathieu-DaudéRegister AccelCPUClass::cpu_target_realize as x86_tcg_ops::cpu_realize. X86's ACCEL_CPU_NAME("tcg") TypeInfo is now empty, remove it.
--- target/i386/tcg/tcg-cpu.c | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-)
target/i386/tcg/tcg-cpu.c +1 -22
@@ -21,7 +21,6 @@#include "cpu.h" #include "helper-tcg.h" #include "qemu/accel.h" -#include "accel/accel-cpu-target.h" #include "exec/translation-block.h" #include "exec/target_page.h" #include "accel/tcg/cpu-ops.h"
@@ -180,6 +179,7 @@ const TCGCPUOps x86_tcg_ops = { .record_sigsegv = x86_cpu_record_sigsegv, .record_sigbus = x86_cpu_record_sigbus, #else + .cpu_realize = tcg_cpu_realizefn, .tlb_fill = x86_cpu_tlb_fill, .pointer_wrap = x86_pointer_wrap, .do_interrupt = x86_cpu_do_interrupt,
@@ -232,24 +232,3 @@ static void x86_tcg_cpu_instance_init(CPUState *cs)x86_tcg_cpu_xsave_init (); } - -static void x86_tcg_cpu_accel_class_init (ObjectClass *oc,const void *data) -{ -AccelCPUClass *acc =ACCEL_CPU_CLASS (oc); - -#ifndef CONFIG_USER_ONLY - acc->cpu_target_realize = tcg_cpu_realizefn; -#endif /* CONFIG_USER_ONLY */ -} -static const TypeInfo x86_tcg_cpu_accel_type_info = { - .name =ACCEL_CPU_NAME ("tcg" ), - - .parent =TYPE_ACCEL_CPU , - .class_init = x86_tcg_cpu_accel_class_init, - .abstract = true, -}; -static void x86_tcg_cpu_accel_register_types (void ) -{ -type_register_static (&x86_tcg_cpu_accel_type_info); -} -type_init (x86_tcg_cpu_accel_register_types);
Signature · 1 line
2.53.0
PATCH v2 15/17 accel/tcg: Convert RISCV AccelCPUClass -> TCGCPUOps::cpu_realize
In reply to Philippe Mathieu-DaudéRegister AccelCPUClass::cpu_target_realize as riscv_tcg_ops::cpu_realize. RISCV's ACCEL_CPU_NAME("tcg") TypeInfo is now empty, remove it.
--- target/riscv/tcg/tcg-cpu.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-)
target/riscv/tcg/tcg-cpu.c +2 -22
@@ -30,7 +30,6 @@#include "qemu/accel.h" #include "qemu/error-report.h" #include "qemu/log.h" -#include "accel/accel-cpu-target.h" #include "accel/tcg/cpu-ops.h" #include "tcg/tcg.h" #ifndef CONFIG_USER_ONLY
@@ -269,6 +268,7 @@ static vaddr riscv_pointer_wrap(CPUState *cs, int mmu_idx,#endif static void riscv_tcg_cpu_instance_init (CPUState *cs); +static bool riscv_tcg_cpu_realize (CPUState *cs,Error **errp);const TCGCPUOps riscv_tcg_ops = { .mttcg_supported = true,
@@ -276,6 +276,7 @@ const TCGCPUOps riscv_tcg_ops = { .initialize = riscv_translate_init, .cpu_instance_init = riscv_tcg_cpu_instance_init, + .cpu_realize = riscv_tcg_cpu_realize, .translate_code = riscv_translate_code, .get_tb_cpu_state = riscv_get_tb_cpu_state, .synchronize_from_tb = riscv_cpu_synchronize_from_tb,
@@ -1676,24 +1677,3 @@ static void riscv_tcg_cpu_instance_init(CPUState *cs)riscv_init_max_cpu_extensions (obj); } } - -static void riscv_tcg_cpu_accel_class_init (ObjectClass *oc,const void *data) -{ -AccelCPUClass *acc =ACCEL_CPU_CLASS (oc); - - acc->cpu_target_realize = riscv_tcg_cpu_realize; -} - -static const TypeInfo riscv_tcg_cpu_accel_type_info = { - .name =ACCEL_CPU_NAME ("tcg" ), - - .parent =TYPE_ACCEL_CPU , - .class_init = riscv_tcg_cpu_accel_class_init, - .abstract = true, -}; - -static void riscv_tcg_cpu_accel_register_types (void ) -{ -type_register_static (&riscv_tcg_cpu_accel_type_info); -} -type_init (riscv_tcg_cpu_accel_register_types);
Signature · 1 line
2.53.0
PATCH v2 16/17 accel: Remove AccelCPUClass::cpu_target_realize()
In reply to Philippe Mathieu-DaudéWe removed all implementations of AccelCPUClass::cpu_target_realize, remove the calls in accel_cpu_common_realize().
--- include/accel/accel-cpu.h | 2 -- accel/accel-common.c | 7 ------- 2 files changed, 9 deletions(-)
include/accel/accel-cpu.h +0 -2
@@ -14,8 +14,6 @@typedef struct AccelCPUClass {ObjectClass parent_class; - -bool (*cpu_target_realize)(CPUState *cpu,Error **errp); }AccelCPUClass ;#endif /* ACCEL_CPU_H */
accel/accel-common.c +0 -7
@@ -52,13 +52,6 @@ bool accel_cpu_common_realize(CPUState *cpu, Error **errp)AccelState *accel =current_accel ();AccelClass *acc =ACCEL_GET_CLASS (accel); -/* target specific realization */ -if (cpu->cc->accel_cpu - && cpu->cc->accel_cpu->cpu_target_realize - && !cpu->cc->accel_cpu->cpu_target_realize (cpu, errp)) { -return false; - } -/* generic realization */ if (acc->cpu_common_realize && !acc->cpu_common_realize (cpu, errp)) {return false;
Signature · 1 line
2.53.0
PATCH v2 17/17 accel: Remove AccelCPUClass and 'accel/accel-cpu-target.h'
In reply to Philippe Mathieu-DaudéAccelCPUClass is now an empty class. We removed all uses of the TYPE_ACCEL_CPU definition. Remove as dead code, along with register_accel_target_type().
--- include/accel/accel-cpu-target.h | 31 ------------------------------- include/accel/accel-cpu.h | 19 ------------------- accel/accel-common.c | 16 ---------------- 3 files changed, 66 deletions(-) delete mode 100644 include/accel/accel-cpu-target.h delete mode 100644 include/accel/accel-cpu.h
include/accel/accel-cpu-target.h deleted +0 -31
@@ -1,31 +0,0 @@ -/* -* Accelerator interface, specializes CPUClass -* This header is used only by target-specific code. -* -* Copyright 2021 SUSE LLC -* -* This work is licensed under the terms of the GNU GPL, version 2 or later. -* See the COPYING file in the top-level directory. -*/ - -#ifndef ACCEL_CPU_TARGET_H -#define ACCEL_CPU_TARGET_H - -/* -* This header is used to define new accelerator-specific target-specific -* accelerator cpu subclasses. -* It uses CPU_RESOLVING_TYPE, so this is clearly target-specific. -* -* Do not try to use for any other purpose than the implementation of new -* subclasses in target/, or the accel implementation itself in accel/ -*/ - -#include "qom/object.h" -#include "accel/accel-cpu.h" -#include "cpu.h" - -#define TYPE_ACCEL_CPU "accel-" CPU_RESOLVING_TYPE -#define ACCEL_CPU_NAME (name) (name "-" TYPE_ACCEL_CPU) -DECLARE_CLASS_CHECKERS(AccelCPUClass, ACCEL_CPU, TYPE_ACCEL_CPU) - -#endif /* ACCEL_CPU_H */
include/accel/accel-cpu.h deleted +0 -19
@@ -1,19 +0,0 @@ -/* -* Accelerator interface, specializes CPUClass -* -* Copyright 2021 SUSE LLC -* -* SPDX-License-Identifier: GPL-2.0-or-later -*/ - -#ifndef ACCEL_CPU_H -#define ACCEL_CPU_H - -#include "qom/object.h" -#include "hw/core/cpu.h" - -typedef struct AccelCPUClass { -ObjectClass parent_class; -}AccelCPUClass ; - -#endif /* ACCEL_CPU_H */
accel/accel-common.c +0 -16
@@ -11,7 +11,6 @@#include "qemu/accel.h" #include "qemu/target-info.h" #include "accel/accel-ops.h" -#include "accel/accel-cpu.h" #include "accel/accel-cpu-ops.h" #include "accel-internal.h"
@@ -98,18 +97,3 @@ static const TypeInfo accel_types[] = { };DEFINE_TYPES (accel_types) - -static void register_accel_target_type(void) -{ - g_autofree char *name = g_strconcat("accel-", target_cpu_type(), NULL); -const TypeInfo accel_cpu_type = { - .name = name, - .parent =TYPE_OBJECT , - .abstract = true, - .class_size =sizeof (AccelCPUClass), - }; - -type_register_static (&accel_cpu_type); -} - -type_init (register_accel_target_type);
Signature · 1 line
2.53.0
Quoted 2 lines · Philippe Mathieu-Daudé
Could get re-review: 4 & 5
Looks good, thanks.
Quoted 180 lines
Move cpu_init/realize hooks from AccelCPUClass to AccelOpsClass. Specialize them for TCG in TCGCPUOps.
This drastically simplifies the need of per-binary QOM types per accelerator per target (see also the nice diff-stat).
Based-on: tag single-binary-20260528
Ignoring checkpatch.pl:
WARNING: added, moved or deleted file(s), does
MAINTAINERSneed updating?
accel/accel-target.c
include/accel/accel-cpu-target.h
include/accel/accel-cpu.h$ git backport-diff since v1:[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively001/ 17:[----] [--] 'target/loongarch: Remove unused 'accel/accel-cpu-target.h' header' 002/ 17:[----] [--] 'accel: Remove AccelCPUClass::cpu_class_init()' 003/ 17:[----] [--] 'accel: Rename AccelOpsClass::cpu_target_realize() -> cpu_realize()' 004/ 17:[----] [--] 'accel/hvf: Remove need for AccelCPUClass::cpu_realize' 005/ 17:[----] [--] 'accel/kvm: Remove need for AccelCPUClass::cpu_realize' 006/ 17:[----] [--] 'accel: Introduce AccelOpsClass::cpu_instance_init handler' 007/ 17:[----] [--] 'accel/whpx: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init' 008/ 17:[0002] [FC] 'accel/nvmm: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init' 009/ 17:[0002] [FC] 'accel/hvf: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init' 010/ 17:[0016] [FC] 'accel/kvm: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init' 011/ 17:[----] [--] 'accel/tcg: Convert AccelCPUClass -> new TCGCPUOps::cpu_instance_init' 012/ 17:[----] [--] 'accel: Remove AccelCPUClass::cpu_instance_init()' 013/ 17:[----] [--] 'accel/tcg: Convert AccelCPUClass -> new TCGCPUOps::cpu_realize' 014/ 17:[----] [--] 'accel/tcg: Convert X86 AccelCPUClass -> TCGCPUOps::cpu_realize' 015/ 17:[----] [--] 'accel/tcg: Convert RISCV AccelCPUClass -> TCGCPUOps::cpu_realize' 016/ 17:[----] [--] 'accel: Remove AccelCPUClass::cpu_target_realize()' 017/ 17:[----] [--] 'accel: Remove AccelCPUClass and 'accel/accel-cpu-target.h''diff --git a/include/system/kvm.h b/include/system/kvm.h index 2c31fa6019e..a249f076763 100644 --- a/include/system/kvm.h +++ b/include/system/kvm.h @@ -225,0 +226,3 @@ void kvm_irqchip_change_notify(void); +void kvm_arch_cpu_instance_init(CPUState *cpu); +bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp); + @@ -367,3 +369,0 @@ int kvm_arch_destroy_vcpu(CPUState *cpu); -void kvm_arch_cpu_instance_init(CPUState *cpu); -bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp); - diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c index 113a23f2384..edad3c1acea 100644 --- a/accel/kvm/kvm-accel-ops.c +++ b/accel/kvm/kvm-accel-ops.c @@ -101 +101 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, const void *data) - ops->cpu_target_realize = kvm_arch_cpu_realize; + ops->cpu_realize = kvm_arch_cpu_realize; diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 7d194ea112b..0f1a98b430f 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -1785,0 +1786,9 @@ void kvm_arch_accel_class_init(ObjectClass *oc) +void kvm_arch_cpu_instance_init(CPUState *cpu) +{ +} + +bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp) +{ + return true; +} + diff --git a/target/i386/hvf/hvf-cpu.c b/target/i386/hvf/hvf-cpu.c index 5d74ca6fd56..536bcecd7d2 100644 --- a/target/i386/hvf/hvf-cpu.c +++ b/target/i386/hvf/hvf-cpu.c @@ -58 +58 @@ static void hvf_cpu_xsave_init(void) -void hvf_arch_cpu_instance_init(CPUState *cpu) +void hvf_arch_cpu_instance_init(CPUState *cs) diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c index 10ab7b2a4dc..2973e28122a 100644 --- a/target/i386/nvmm/nvmm-all.c +++ b/target/i386/nvmm/nvmm-all.c @@ -1214 +1214 @@ static const TypeInfo nvmm_accel_type = { -void nvmm_arch_cpu_instance_init(CPUState *cpu) +void nvmm_arch_cpu_instance_init(CPUState *cs) diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c index 9d844c4905a..167fdd515be 100644 --- a/target/loongarch/kvm/kvm.c +++ b/target/loongarch/kvm/kvm.c @@ -1497,0 +1498,9 @@ void kvm_arch_accel_class_init(ObjectClass *oc) + +void kvm_arch_cpu_instance_init(CPUState *cpu) +{ +} + +bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp) +{ + return true; +} diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 013f5e852e1..894962d509f 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -2354,0 +2355,4 @@ static void alter_insns(uint64_t *word, uint64_t flags, bool on) +void kvm_arch_cpu_instance_init(CPUState *cpu) +{ +} + diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c index 2e4f435c537..46730e72a92 100644 --- a/target/s390x/kvm/kvm.c +++ b/target/s390x/kvm/kvm.c @@ -2613,0 +2614,9 @@ void kvm_arch_accel_class_init(ObjectClass *oc) + +void kvm_arch_cpu_instance_init(CPUState *cpu) +{ +} + +bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp) +{ + return true; +}Philippe Mathieu-Daudé (17):
target/loongarch: Remove unused 'accel/accel-cpu-target.h' header
accel: RemoveAccelCPUClass::cpu_class_init()
accel: RenameAccelOpsClass::cpu_target_realize()->cpu_realize()accel/hvf: Remove need forAccelCPUClass::cpu_realizeaccel/kvm: Remove need forAccelCPUClass::cpu_realize
accel: IntroduceAccelOpsClass::cpu_instance_inithandler accel/whpx: Convert AccelCPUClass ->AccelOpsClass::cpu_instance_initaccel/nvmm: Convert AccelCPUClass ->AccelOpsClass::cpu_instance_initaccel/hvf: Convert AccelCPUClass ->AccelOpsClass::cpu_instance_initaccel/kvm: Convert AccelCPUClass ->AccelOpsClass::cpu_instance_initaccel/tcg: Convert AccelCPUClass -> newTCGCPUOps::cpu_instance_init
accel: RemoveAccelCPUClass::cpu_instance_init()accel/tcg: Convert AccelCPUClass -> newTCGCPUOps::cpu_realizeaccel/tcg: Convert X86 AccelCPUClass ->TCGCPUOps::cpu_realizeaccel/tcg: Convert RISCV AccelCPUClass ->TCGCPUOps::cpu_realize
accel: RemoveAccelCPUClass::cpu_target_realize()
accel: Remove AccelCPUClass and 'accel/accel-cpu-target.h'accel/tcg/tcg-accel-ops.h | 1 + include/accel/accel-cpu-ops.h | 3 +- include/accel/accel-cpu-target.h | 31 -------------- include/accel/accel-cpu.h | 23 ----------- include/accel/tcg/cpu-ops.h | 2 + include/system/hvf_int.h | 1 + include/system/kvm.h | 3 ++ target/i386/nvmm/nvmm-accel-ops.h | 2 + accel/accel-common.c | 68 ++++--------------------------- accel/hvf/hvf-accel-ops.c | 3 +- accel/kvm/kvm-accel-ops.c | 2 + accel/tcg/cpu-exec.c | 15 ++++++- accel/tcg/tcg-accel-ops.c | 1 + accel/whpx/whpx-accel-ops.c | 2 + accel/whpx/whpx-common.c | 17 -------- target/arm/hvf/hvf.c | 4 ++ target/arm/kvm.c | 9 ++++ target/arm/whpx/whpx-all.c | 1 - target/i386/hvf/hvf-cpu.c | 25 ++---------- target/i386/hvf/hvf.c | 5 --- target/i386/kvm/kvm-cpu.c | 25 +----------- target/i386/nvmm/nvmm-accel-ops.c | 2 + target/i386/nvmm/nvmm-all.c | 19 +-------- target/i386/tcg/tcg-cpu.c | 28 ++----------- target/i386/whpx/whpx-all.c | 1 - target/loongarch/kvm/kvm.c | 9 ++++ target/loongarch/tcg/tcg_cpu.c | 1 - target/ppc/kvm.c | 27 +++--------- target/riscv/kvm/kvm-cpu.c | 33 +-------------- target/riscv/tcg/tcg-cpu.c | 28 +++---------- target/s390x/kvm/kvm.c | 9 ++++ 31 files changed, 95 insertions(+), 305 deletions(-) delete mode 100644 include/accel/accel-cpu-target.h delete mode 100644 include/accel/accel-cpu.h
Quoted 10 lines · Philippe Mathieu-Daudé
Could get re-review: 4 & 5
Move cpu_init/realize hooks from AccelCPUClass to AccelOpsClass. Specialize them for TCG in TCGCPUOps.
This drastically simplifies the need of per-binary QOM types per accelerator per target (see also the nice diff-stat).
Based-on: tag single-binary-20260528
Hi Philippe,
I have tested this patch series on ppc64 (pseries) in both KVM and TCG acceleration modes and it seems to work as expected. So, feel free to add
I am sharing logs below:
smp as 8 and maxcpus as 64
i) Guest bringup with sockets 2 cores 16 and threads 2
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 64
On-line CPU(s) list: 0-63
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 2
Core(s) per socket: 16
Socket(s): 2
ii) Guest bringup with sockets 2 cores 8 and threads 4
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 4
Core(s) per socket: 2
Socket(s): 1
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 64
On-line CPU(s) list: 0-63
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 4
Core(s) per socket: 8
Socket(s): 2
iii) Guest bringup with sockets 2 cores 4 and threads 8
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 8
Core(s) per socket: 1
Socket(s): 1
After hotplug:
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 64
On-line CPU(s) list: 0-63
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 8
Core(s) per socket: 4
Socket(s): 2
iv) Guest bringup with sockets 4 cores 2 and threads 8
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 8
Core(s) per socket: 1
Socket(s): 1
After cpu hotplug
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 64
On-line CPU(s) list: 0-63
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 8
Core(s) per socket: 2
Socket(s): 4
v) Guest bringup with sockets 8 cores 1 and threads 8
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 8
Core(s) per socket: 1
Socket(s): 1
After hotplug :
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 64
On-line CPU(s) list: 0-63
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 8
Core(s) per socket: 1
Socket(s): 8
Trying all scenarios without any maxcpus :
i) Guest bringup with sockets 8 cores 1 and threads 8
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 64
On-line CPU(s) list: 0-63
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 8
Core(s) per socket: 1
Socket(s): 8
ii) Guest bringup with sockets 8 cores 2 and threads 4
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 64
On-line CPU(s) list: 0-63
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 4
Core(s) per socket: 2
Socket(s): 8
iii) Guest bringup with sockets 8 cores 4 and threads 2
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 64
On-line CPU(s) list: 0-63
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 2
Core(s) per socket: 4
Socket(s): 8
iv) Guest bringup with sockets 4 cores 8 and threads 2
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 64
On-line CPU(s) list: 0-63
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 4
v) Guest bringup with sockets 2 cores 16 and threads 2
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 64
On-line CPU(s) list: 0-63
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 2
Core(s) per socket: 16
Socket(s): 2
vi) Different smp values :
a) 32
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 32
On-line CPU(s) list: 0-31
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 2
b) 16
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 2
Core(s) per socket: 4
Socket(s): 2
c) 8
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 2
d) 4
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 2
Core(s) per socket: 1
Socket(s): 2
e) 2
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 2
Core(s) per socket: 1
Socket(s): 1
f) 1
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
iii) smp without any topology:
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 32
On-line CPU(s) list: 0-31
Model name: Power11 (architected), altivec supported
Model: 2.0 (pvr 0082 0200)
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 32
iv) TCG tests:
a) smp 32 without topology :/home/Anu/qemu/build/qemu-system-ppc64 -name guest=sles16_migrate,debug-threads=on -S -object {"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/lib/libvirt/qemu/domain-18-sles16_migrate/master-key.aes"} -machine pseries-10.2,usb=off,dump-guest-core=off,memory-backend=ppc_spapr.ram -accel tcg -cpu POWER11 -m size=16777216k -object {"qom-type":"memory-backend-ram","id":"ppc_spapr.ram","size":17179869184} -overcommit mem-lock=off -smp 32,sockets=32,cores=1,threads=1
b) smp 16 with topology
Threads 2 :
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Model name: Power11 (architected), altivec supported
Model: 18.0 (pvr 0082 1200)
Thread(s) per core: 2
Core(s) per socket: 1
Socket(s): 8
Threads 4:
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Model name: Power11 (architected), altivec supported
Model: 18.0 (pvr 0082 1200)
Thread(s) per core: 4
Core(s) per socket: 1
Socket(s): 4
Threads 8:
localhost:~ # lscpu
Architecture: ppc64le
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Model name: Power11 (architected), altivec supported
Model: 18.0 (pvr 0082 1200)
Thread(s) per core: 8
Core(s) per socket: 2
Socket(s): 1
Virtualization features:
Thank you
Anushree Mathur
Quoted 171 lines
Ignoring checkpatch.pl:
WARNING: added, moved or deleted file(s), does
MAINTAINERSneed updating?
accel/accel-target.c
include/accel/accel-cpu-target.h
include/accel/accel-cpu.h$ git backport-diff since v1:[----] : patches are identical [####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively 001/ 17:[----] [--] 'target/loongarch: Remove unused 'accel/accel-cpu-target.h' header' 002/ 17:[----] [--] 'accel: Remove AccelCPUClass::cpu_class_init()' 003/ 17:[----] [--] 'accel: Rename AccelOpsClass::cpu_target_realize() -> cpu_realize()' 004/ 17:[----] [--] 'accel/hvf: Remove need for AccelCPUClass::cpu_realize' 005/ 17:[----] [--] 'accel/kvm: Remove need for AccelCPUClass::cpu_realize' 006/ 17:[----] [--] 'accel: Introduce AccelOpsClass::cpu_instance_init handler' 007/ 17:[----] [--] 'accel/whpx: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init' 008/ 17:[0002] [FC] 'accel/nvmm: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init' 009/ 17:[0002] [FC] 'accel/hvf: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init' 010/ 17:[0016] [FC] 'accel/kvm: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init' 011/ 17:[----] [--] 'accel/tcg: Convert AccelCPUClass -> new TCGCPUOps::cpu_instance_init' 012/ 17:[----] [--] 'accel: Remove AccelCPUClass::cpu_instance_init()' 013/ 17:[----] [--] 'accel/tcg: Convert AccelCPUClass -> new TCGCPUOps::cpu_realize' 014/ 17:[----] [--] 'accel/tcg: Convert X86 AccelCPUClass -> TCGCPUOps::cpu_realize' 015/ 17:[----] [--] 'accel/tcg: Convert RISCV AccelCPUClass -> TCGCPUOps::cpu_realize' 016/ 17:[----] [--] 'accel: Remove AccelCPUClass::cpu_target_realize()' 017/ 17:[----] [--] 'accel: Remove AccelCPUClass and 'accel/accel-cpu-target.h'' diff --git a/include/system/kvm.h b/include/system/kvm.h index 2c31fa6019e..a249f076763 100644 --- a/include/system/kvm.h +++ b/include/system/kvm.h @@ -225,0 +226,3 @@ void kvm_irqchip_change_notify(void); +void kvm_arch_cpu_instance_init(CPUState *cpu); +bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp); + @@ -367,3 +369,0 @@ int kvm_arch_destroy_vcpu(CPUState *cpu); -void kvm_arch_cpu_instance_init(CPUState *cpu); -bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp); - diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c index 113a23f2384..edad3c1acea 100644 --- a/accel/kvm/kvm-accel-ops.c +++ b/accel/kvm/kvm-accel-ops.c @@ -101 +101 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, const void *data) - ops->cpu_target_realize = kvm_arch_cpu_realize; + ops->cpu_realize = kvm_arch_cpu_realize; diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 7d194ea112b..0f1a98b430f 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -1785,0 +1786,9 @@ void kvm_arch_accel_class_init(ObjectClass *oc) +void kvm_arch_cpu_instance_init(CPUState *cpu) +{ +} + +bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp) +{ + return true; +} + diff --git a/target/i386/hvf/hvf-cpu.c b/target/i386/hvf/hvf-cpu.c index 5d74ca6fd56..536bcecd7d2 100644 --- a/target/i386/hvf/hvf-cpu.c +++ b/target/i386/hvf/hvf-cpu.c @@ -58 +58 @@ static void hvf_cpu_xsave_init(void) -void hvf_arch_cpu_instance_init(CPUState *cpu) +void hvf_arch_cpu_instance_init(CPUState *cs) diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c index 10ab7b2a4dc..2973e28122a 100644 --- a/target/i386/nvmm/nvmm-all.c +++ b/target/i386/nvmm/nvmm-all.c @@ -1214 +1214 @@ static const TypeInfo nvmm_accel_type = { -void nvmm_arch_cpu_instance_init(CPUState *cpu) +void nvmm_arch_cpu_instance_init(CPUState *cs) diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c index 9d844c4905a..167fdd515be 100644 --- a/target/loongarch/kvm/kvm.c +++ b/target/loongarch/kvm/kvm.c @@ -1497,0 +1498,9 @@ void kvm_arch_accel_class_init(ObjectClass *oc) + +void kvm_arch_cpu_instance_init(CPUState *cpu) +{ +} + +bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp) +{ + return true; +} diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 013f5e852e1..894962d509f 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -2354,0 +2355,4 @@ static void alter_insns(uint64_t *word, uint64_t flags, bool on) +void kvm_arch_cpu_instance_init(CPUState *cpu) +{ +} + diff --git a/target/s390x/kvm/kvm.c b/target/s390x/kvm/kvm.c index 2e4f435c537..46730e72a92 100644 --- a/target/s390x/kvm/kvm.c +++ b/target/s390x/kvm/kvm.c @@ -2613,0 +2614,9 @@ void kvm_arch_accel_class_init(ObjectClass *oc) + +void kvm_arch_cpu_instance_init(CPUState *cpu) +{ +} + +bool kvm_arch_cpu_realize(CPUState *cpu, Error **errp) +{ + return true; +}Philippe Mathieu-Daudé (17):
target/loongarch: Remove unused 'accel/accel-cpu-target.h' header accel: Remove AccelCPUClass::cpu_class_init() accel: Rename AccelOpsClass::cpu_target_realize() -> cpu_realize() accel/hvf: Remove need for AccelCPUClass::cpu_realize accel/kvm: Remove need for AccelCPUClass::cpu_realize accel: Introduce AccelOpsClass::cpu_instance_init handler accel/whpx: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init accel/nvmm: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init accel/hvf: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init accel/kvm: Convert AccelCPUClass -> AccelOpsClass::cpu_instance_init accel/tcg: Convert AccelCPUClass -> new TCGCPUOps::cpu_instance_init accel: Remove AccelCPUClass::cpu_instance_init() accel/tcg: Convert AccelCPUClass -> new TCGCPUOps::cpu_realize accel/tcg: Convert X86 AccelCPUClass -> TCGCPUOps::cpu_realize accel/tcg: Convert RISCV AccelCPUClass -> TCGCPUOps::cpu_realize accel: Remove AccelCPUClass::cpu_target_realize() accel: Remove AccelCPUClass and 'accel/accel-cpu-target.h'accel/tcg/tcg-accel-ops.h | 1 + include/accel/accel-cpu-ops.h | 3 +- include/accel/accel-cpu-target.h | 31 -------------- include/accel/accel-cpu.h | 23 ----------- include/accel/tcg/cpu-ops.h | 2 + include/system/hvf_int.h | 1 + include/system/kvm.h | 3 ++ target/i386/nvmm/nvmm-accel-ops.h | 2 + accel/accel-common.c | 68 ++++--------------------------- accel/hvf/hvf-accel-ops.c | 3 +- accel/kvm/kvm-accel-ops.c | 2 + accel/tcg/cpu-exec.c | 15 ++++++- accel/tcg/tcg-accel-ops.c | 1 + accel/whpx/whpx-accel-ops.c | 2 + accel/whpx/whpx-common.c | 17 -------- target/arm/hvf/hvf.c | 4 ++ target/arm/kvm.c | 9 ++++ target/arm/whpx/whpx-all.c | 1 - target/i386/hvf/hvf-cpu.c | 25 ++---------- target/i386/hvf/hvf.c | 5 --- target/i386/kvm/kvm-cpu.c | 25 +----------- target/i386/nvmm/nvmm-accel-ops.c | 2 + target/i386/nvmm/nvmm-all.c | 19 +-------- target/i386/tcg/tcg-cpu.c | 28 ++----------- target/i386/whpx/whpx-all.c | 1 - target/loongarch/kvm/kvm.c | 9 ++++ target/loongarch/tcg/tcg_cpu.c | 1 - target/ppc/kvm.c | 27 +++--------- target/riscv/kvm/kvm-cpu.c | 33 +-------------- target/riscv/tcg/tcg-cpu.c | 28 +++---------- target/s390x/kvm/kvm.c | 9 ++++ 31 files changed, 95 insertions(+), 305 deletions(-)delete mode 100644
include/accel/accel-cpu-target.hdelete mode 100644include/accel/accel-cpu.h
Quoted 6 lines · Philippe Mathieu-Daudé
Could get re-review: 4 & 5
Move cpu_init/realize hooks from AccelCPUClass to AccelOpsClass. Specialize them for TCG in TCGCPUOps.
snip
Quoted 11 lines
Philippe Mathieu-Daudé (17):
target/loongarch: Remove unused 'accel/accel-cpu-target.h' header
accel: RemoveAccelCPUClass::cpu_class_init()
accel: RenameAccelOpsClass::cpu_target_realize()->cpu_realize()accel/hvf: Remove need forAccelCPUClass::cpu_realizeaccel/kvm: Remove need forAccelCPUClass::cpu_realize
accel: IntroduceAccelOpsClass::cpu_instance_inithandler accel/whpx: Convert AccelCPUClass ->AccelOpsClass::cpu_instance_initaccel/nvmm: Convert AccelCPUClass ->AccelOpsClass::cpu_instance_initaccel/hvf: Convert AccelCPUClass ->AccelOpsClass::cpu_instance_init
Quoted 8 lines
accel/kvm: Convert AccelCPUClass ->
AccelOpsClass::cpu_instance_initaccel/tcg: Convert AccelCPUClass -> newTCGCPUOps::cpu_instance_init
accel: RemoveAccelCPUClass::cpu_instance_init()accel/tcg: Convert AccelCPUClass -> newTCGCPUOps::cpu_realizeaccel/tcg: Convert X86 AccelCPUClass ->TCGCPUOps::cpu_realizeaccel/tcg: Convert RISCV AccelCPUClass ->TCGCPUOps::cpu_realize
accel: RemoveAccelCPUClass::cpu_target_realize()
accel: Remove AccelCPUClass and 'accel/accel-cpu-target.h'
The changes LGTM. For the series:
Thanks,
Amit