cpus: Convert cpu_index into a bitmap
RFC PATCH 1/1 cpus: Convert cpu_index into a bitmap
From: Bharata B Rao <[email protected]>
Currently CPUState.cpu_index is monotonically increasing and a newly created CPU always gets the next higher index. The next available index is calculated by counting the existing number of CPUs. This is fine as long as we only add CPUs, but there are architectures which are starting to support CPU removal too. For an architecture like PowerPC which derives its CPU identifier (device tree ID) from cpu_index, the existing logic of generating cpu_index values causes problems.
With the currently proposed method of handling vCPU removal by parking the vCPU fd in QEMU
(Ref: http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02604.html),
generating cpu_index this way will not work for PowerPC.
This patch changes the way cpu_index is handed out by maintaining a bit map of the CPUs that tracks both addition and removal of CPUs.
I am not sure if this is the right and an acceptable approach. The alternative is to do something similar for PowerPC alone and not depend on cpu_index.
I have tested this with out-of-the-tree patches for CPU hot plug and removal on x86 and sPAPR PowerPC.
--- exec.c | 39 +++++++++++++++++++++++++++++---------- include/exec/exec-all.h | 1 + target-alpha/cpu.c | 6 ++++++ target-arm/cpu.c | 1 + target-cris/cpu.c | 6 ++++++ target-i386/cpu.c | 6 ++++++ target-lm32/cpu.c | 6 ++++++ target-m68k/cpu.c | 6 ++++++ target-microblaze/cpu.c | 6 ++++++ target-mips/cpu.c | 6 ++++++ target-moxie/cpu.c | 6 ++++++ target-openrisc/cpu.c | 6 ++++++ target-ppc/translate_init.c | 6 ++++++ target-s390x/cpu.c | 1 + target-sh4/cpu.c | 6 ++++++ target-sparc/cpu.c | 1 + target-tricore/cpu.c | 5 +++++ target-unicore32/cpu.c | 6 ++++++ target-xtensa/cpu.c | 6 ++++++ 19 files changed, 116 insertions(+), 10 deletions(-)
exec.c +29 -10
@@ -530,21 +530,40 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) }#endif +static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS); + +#ifdef CONFIG_USER_ONLY +int max_cpus =1 ;/* TODO: Check if this is correct ? */ +#endif + +static int cpu_get_free_index (void ) +{ +int cpu =find_first_zero_bit (cpu_index_map, max_cpus); + +if (cpu == max_cpus) { +fprintf (stderr,"WARNING: qemu: Trying to use more " +"CPUs than allowed max of %d\n" , max_cpus); +return max_cpus; + }else { +bitmap_set (cpu_index_map, cpu,1 ); +return cpu; + } +} + +void cpu_exec_exit (CPUState *cpu) +{ +bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); +} +void cpu_exec_init (CPUArchState *env) {CPUState *cpu =ENV_GET_CPU (env);CPUClass *cc =CPU_GET_CLASS (cpu); -CPUState *some_cpu; -int cpu_index;#if defined(CONFIG_USER_ONLY )cpu_list_lock ();#endif - cpu_index =0 ; -CPU_FOREACH (some_cpu) { - cpu_index++; - } - cpu->cpu_index = cpu_index; + cpu->cpu_index =cpu_get_free_index (); cpu->numa_node =0 ;QTAILQ_INIT (&cpu->breakpoints);QTAILQ_INIT (&cpu->watchpoints);
@@ -558,16 +577,16 @@ void cpu_exec_init(CPUArchState *env)cpu_list_unlock ();#endif if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { -vmstate_register (NULL , cpu_index, &vmstate_cpu_common, cpu); +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); }#if defined(CPU_SAVE_VERSION ) && !defined(CONFIG_USER_ONLY ) -register_savevm (NULL ,"cpu" , cpu_index,CPU_SAVE_VERSION , +register_savevm (NULL ,"cpu" , cpu->cpu_index,CPU_SAVE_VERSION , cpu_save, cpu_load, env);assert (cc->vmsd ==NULL );assert (qdev_get_vmsd (DEVICE (cpu)) ==NULL );#endif if (cc->vmsd !=NULL ) { -vmstate_register (NULL , cpu_index, cc->vmsd, cpu); +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); } }
include/exec/exec-all.h +1 -0
@@ -89,6 +89,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc, target_ulong cs_base, int flags, int cflags);void cpu_exec_init (CPUArchState *env); +void cpu_exec_exit (CPUState *cpu); void QEMU_NORETURN cpu_loop_exit(CPUState *cpu);int page_unprotect (target_ulong address,uintptr_t pc,void *puc); void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,
target-alpha/cpu.c +6 -0
@@ -250,6 +250,11 @@ static const TypeInfo ev68_cpu_type_info = { .parent = TYPE("ev67"), }; +static void alpha_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void alpha_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
@@ -305,6 +310,7 @@ static const TypeInfo alpha_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(AlphaCPU), .instance_init = alpha_cpu_initfn, + .instance_finalize = alpha_cpu_finalize, .abstract = true, .class_size = sizeof(AlphaCPUClass), .class_init = alpha_cpu_class_init,
target-arm/cpu.c +1 -0
@@ -454,6 +454,7 @@ static void arm_cpu_finalizefn(Object *obj) {ARMCPU *cpu =ARM_CPU (obj);g_hash_table_destroy (cpu->cp_regs); +cpu_exec_exit (CPU (obj)); }static void arm_cpu_realizefn (DeviceState *dev,Error **errp)
target-cris/cpu.c +6 -0
@@ -161,6 +161,11 @@ static void cris_cpu_set_irq(void *opaque, int irq, int level) }#endif +static void cris_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void cris_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
@@ -299,6 +304,7 @@ static const TypeInfo cris_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(CRISCPU), .instance_init = cris_cpu_initfn, + .instance_finalize = cris_cpu_finalize, .abstract = true, .class_size = sizeof(CRISCPUClass), .class_init = cris_cpu_class_init,
target-i386/cpu.c +6 -0
@@ -2822,6 +2822,11 @@ out: } } +static void x86_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void x86_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
@@ -2994,6 +2999,7 @@ static const TypeInfo x86_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(X86CPU), .instance_init = x86_cpu_initfn, + .instance_finalize = x86_cpu_finalize, .abstract = true, .class_size = sizeof(X86CPUClass), .class_init = x86_cpu_common_class_init,
target-lm32/cpu.c +6 -0
@@ -143,6 +143,11 @@ static void lm32_cpu_realizefn(DeviceState *dev, Error **errp) lcc->parent_realize (dev, errp); } +static void lm32_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void lm32_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
@@ -294,6 +299,7 @@ static const TypeInfo lm32_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(LM32CPU), .instance_init = lm32_cpu_initfn, + .instance_finalize = lm32_cpu_finalize, .abstract = true, .class_size = sizeof(LM32CPUClass), .class_init = lm32_cpu_class_init,
target-m68k/cpu.c +6 -0
@@ -160,6 +160,11 @@ static void m68k_cpu_realizefn(DeviceState *dev, Error **errp) mcc->parent_realize (dev, errp); } +static void m68k_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void m68k_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
@@ -231,6 +236,7 @@ static const TypeInfo m68k_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(M68kCPU), .instance_init = m68k_cpu_initfn, + .instance_finalize = m68k_cpu_finalize, .abstract = true, .class_size = sizeof(M68kCPUClass), .class_init = m68k_cpu_class_init,
target-microblaze/cpu.c +6 -0
@@ -122,6 +122,11 @@ static void mb_cpu_realizefn(DeviceState *dev, Error **errp) mcc->parent_realize (dev, errp); } +static void mb_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void mb_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
@@ -190,6 +195,7 @@ static const TypeInfo mb_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(MicroBlazeCPU), .instance_init = mb_cpu_initfn, + .instance_finalize = mb_cpu_finalize, .class_size = sizeof(MicroBlazeCPUClass), .class_init = mb_cpu_class_init, };
target-mips/cpu.c +6 -0
@@ -108,6 +108,11 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp) mcc->parent_realize (dev, errp); } +static void mips_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void mips_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
@@ -160,6 +165,7 @@ static const TypeInfo mips_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(MIPSCPU), .instance_init = mips_cpu_initfn, + .instance_finalize = mips_cpu_finalize, .abstract = false, .class_size = sizeof(MIPSCPUClass), .class_init = mips_cpu_class_init,
target-moxie/cpu.c +6 -0
@@ -59,6 +59,11 @@ static void moxie_cpu_realizefn(DeviceState *dev, Error **errp) mcc->parent_realize (dev, errp); } +static void moxie_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void moxie_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
@@ -160,6 +165,7 @@ static const TypeInfo moxie_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(MoxieCPU), .instance_init = moxie_cpu_initfn, + .instance_finalize = moxie_cpu_finalize, .class_size = sizeof(MoxieCPUClass), .class_init = moxie_cpu_class_init, };
target-openrisc/cpu.c +6 -0
@@ -85,6 +85,11 @@ static void openrisc_cpu_realizefn(DeviceState *dev, Error **errp) occ->parent_realize (dev, errp); } +static void openrisc_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void openrisc_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
@@ -198,6 +203,7 @@ static const TypeInfo openrisc_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(OpenRISCCPU), .instance_init = openrisc_cpu_initfn, + .instance_finalize = openrisc_cpu_finalize, .abstract = true, .class_size = sizeof(OpenRISCCPUClass), .class_init = openrisc_cpu_class_init,
target-ppc/translate_init.c +6 -0
@@ -9625,6 +9625,11 @@ static bool ppc_cpu_is_big_endian(CPUState *cs) }#endif +static void ppc_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void ppc_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
@@ -9738,6 +9743,7 @@ static const TypeInfo ppc_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(PowerPCCPU), .instance_init = ppc_cpu_initfn, + .instance_finalize = ppc_cpu_finalize, .abstract = true, .class_size = sizeof(PowerPCCPUClass), .class_init = ppc_cpu_class_init,
target-s390x/cpu.c +1 -0
@@ -214,6 +214,7 @@ static void s390_cpu_finalize(Object *obj)qemu_unregister_reset (s390_cpu_machine_reset_cb, cpu);#endif +cpu_exec_exit (CPU (obj)); }#if !defined(CONFIG_USER_ONLY )
target-sh4/cpu.c +6 -0
@@ -240,6 +240,11 @@ static void superh_cpu_realizefn(DeviceState *dev, Error **errp) scc->parent_realize (dev, errp); } +static void superh_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void superh_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
@@ -296,6 +301,7 @@ static const TypeInfo superh_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(SuperHCPU), .instance_init = superh_cpu_initfn, + .instance_finalize = superh_cpu_finalize, .abstract = true, .class_size = sizeof(SuperHCPUClass), .class_init = superh_cpu_class_init,
target-sparc/cpu.c +1 -0
@@ -815,6 +815,7 @@ static void sparc_cpu_uninitfn(Object *obj)CPUSPARCState *env = &cpu->env;g_free (env->def); +cpu_exec_exit (CPU (obj)); }static void sparc_cpu_class_init (ObjectClass *oc,void *data)
target-tricore/cpu.c +5 -0
@@ -80,6 +80,10 @@ static void tricore_cpu_realizefn(DeviceState *dev, Error **errp) tcc->parent_realize (dev, errp); } +static void tricore_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +}static void tricore_cpu_initfn (Object *obj) {
@@ -180,6 +184,7 @@ static const TypeInfo tricore_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(TriCoreCPU), .instance_init = tricore_cpu_initfn, + .instance_finalize = tricore_cpu_finalize, .abstract = true, .class_size = sizeof(TriCoreCPUClass), .class_init = tricore_cpu_class_init,
target-unicore32/cpu.c +6 -0
@@ -103,6 +103,11 @@ static void uc32_cpu_realizefn(DeviceState *dev, Error **errp) ucc->parent_realize (dev, errp); } +static void uc32_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void uc32_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
@@ -174,6 +179,7 @@ static const TypeInfo uc32_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(UniCore32CPU), .instance_init = uc32_cpu_initfn, + .instance_finalize = uc32_cpu_finalize, .abstract = true, .class_size = sizeof(UniCore32CPUClass), .class_init = uc32_cpu_class_init,
target-xtensa/cpu.c +6 -0
@@ -104,6 +104,11 @@ static void xtensa_cpu_realizefn(DeviceState *dev, Error **errp) xcc->parent_realize (dev, errp); } +static void xtensa_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void xtensa_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
@@ -162,6 +167,7 @@ static const TypeInfo xtensa_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(XtensaCPU), .instance_init = xtensa_cpu_initfn, + .instance_finalize = xtensa_cpu_finalize, .abstract = true, .class_size = sizeof(XtensaCPUClass), .class_init = xtensa_cpu_class_init,
Signature · 1 line
2.1.0
Quoted 149 lines · Bharata B Rao
From: Bharata B Rao <[email protected]>
Currently CPUState.cpu_index is monotonically increasing and a newly created CPU always gets the next higher index. The next available index is calculated by counting the existing number of CPUs. This is fine as long as we only add CPUs, but there are architectures which are starting to support CPU removal too. For an architecture like PowerPC which derives its CPU identifier (device tree ID) from
cpu_index, the existing logic of generatingcpu_indexvalues causes problems.With the currently proposed method of handling vCPU removal by parking the vCPU fd in QEMU
(Ref: http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02604.html),
generatingcpu_indexthis way will not work for PowerPC.This patch changes the way
cpu_indexis handed out by maintaining a bit map of the CPUs that tracks both addition and removal of CPUs.I am not sure if this is the right and an acceptable approach. The alternative is to do something similar for PowerPC alone and not depend on
cpu_index.I have tested this with out-of-the-tree patches for CPU hot plug and removal on x86 and sPAPR PowerPC.
Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 39 +++++++++++++++++++++++++++++---------- include/exec/exec-all.h | 1 + target-alpha/cpu.c | 6 ++++++ target-arm/cpu.c | 1 + target-cris/cpu.c | 6 ++++++ target-i386/cpu.c | 6 ++++++ target-lm32/cpu.c | 6 ++++++ target-m68k/cpu.c | 6 ++++++ target-microblaze/cpu.c | 6 ++++++ target-mips/cpu.c | 6 ++++++ target-moxie/cpu.c | 6 ++++++ target-openrisc/cpu.c | 6 ++++++ target-ppc/translate_init.c | 6 ++++++ target-s390x/cpu.c | 1 + target-sh4/cpu.c | 6 ++++++ target-sparc/cpu.c | 1 + target-tricore/cpu.c | 5 +++++ target-unicore32/cpu.c | 6 ++++++ target-xtensa/cpu.c | 6 ++++++ 19 files changed, 116 insertions(+), 10 deletions(-)exec.c +29
-10@@ -530,21 +530,40 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) }#endif +static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS); + +#ifdef CONFIG_USER_ONLY +int max_cpus =1 ;/* TODO: Check if this is correct ? */ +#endif + +static int cpu_get_free_index (void ) +{ +int cpu =find_first_zero_bit (cpu_index_map, max_cpus); + +if (cpu == max_cpus) { +fprintf (stderr,"WARNING: qemu: Trying to use more " +"CPUs than allowed max of %d\n" , max_cpus); +return max_cpus; + }else { +bitmap_set (cpu_index_map, cpu,1 ); +return cpu; + } +} + +void cpu_exec_exit (CPUState *cpu) +{ +bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); +} +void cpu_exec_init (CPUArchState *env) {CPUState *cpu =ENV_GET_CPU (env);CPUClass *cc =CPU_GET_CLASS (cpu); -CPUState *some_cpu; -int cpu_index;#if defined(CONFIG_USER_ONLY )cpu_list_lock ();#endif - cpu_index =0 ; -CPU_FOREACH (some_cpu) { - cpu_index++; - } - cpu->cpu_index = cpu_index; + cpu->cpu_index =cpu_get_free_index (); cpu->numa_node =0 ;QTAILQ_INIT (&cpu->breakpoints);QTAILQ_INIT (&cpu->watchpoints);@@ -558,16 +577,16 @@ void cpu_exec_init(CPUArchState *env)cpu_list_unlock ();#endif if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { -vmstate_register (NULL , cpu_index, &vmstate_cpu_common, cpu); +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); }#if defined(CPU_SAVE_VERSION ) && !defined(CONFIG_USER_ONLY ) -register_savevm (NULL ,"cpu" , cpu_index,CPU_SAVE_VERSION , +register_savevm (NULL ,"cpu" , cpu->cpu_index,CPU_SAVE_VERSION , cpu_save, cpu_load, env);assert (cc->vmsd ==NULL );assert (qdev_get_vmsd (DEVICE (cpu)) ==NULL );#endif if (cc->vmsd !=NULL ) { -vmstate_register (NULL , cpu_index, cc->vmsd, cpu); +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); } }include/exec/exec-all.h +1
-0@@ -89,6 +89,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc, target_ulong cs_base, int flags, int cflags);void cpu_exec_init (CPUArchState *env); +void cpu_exec_exit (CPUState *cpu); void QEMU_NORETURN cpu_loop_exit(CPUState *cpu);int page_unprotect (target_ulong address,uintptr_t pc,void *puc); void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,target-alpha/cpu.c +5
-0@@ -250,6 +250,11 @@ static const TypeInfo ev68_cpu_type_info = { .parent = TYPE("ev67"), }; +static void alpha_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void alpha_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
target-alpha/cpu.c static const TypeInfo alpha_cpu_type_info = { · line 313
Quoted 4 lines
target-alpha/cpu.c +1
-0@@ -305,6 +310,7 @@ static const TypeInfo alpha_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(AlphaCPU), .instance_init = alpha_cpu_initfn, + .instance_finalize = alpha_cpu_finalize,
Would it be possible to put this into TYPE_CPU->instance_finalize instead?
Alex
Quoted 143 lines · Alexander Graf
Quoted 140 lines · Bharata B Rao
From: Bharata B Rao <[email protected]>
Currently CPUState.cpu_index is monotonically increasing and a newly created CPU always gets the next higher index. The next available index is calculated by counting the existing number of CPUs. This is fine as long as we only add CPUs, but there are architectures which are starting to support CPU removal too. For an architecture like PowerPC which derives its CPU identifier (device tree ID) from
cpu_index, the existing logic of generatingcpu_indexvalues causes problems.With the currently proposed method of handling vCPU removal by parking the vCPU fd in QEMU
(Ref: http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02604.html),
generatingcpu_indexthis way will not work for PowerPC.This patch changes the way
cpu_indexis handed out by maintaining a bit map of the CPUs that tracks both addition and removal of CPUs.I am not sure if this is the right and an acceptable approach. The alternative is to do something similar for PowerPC alone and not depend on
cpu_index.I have tested this with out-of-the-tree patches for CPU hot plug and removal on x86 and sPAPR PowerPC.
Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 39 +++++++++++++++++++++++++++++---------- include/exec/exec-all.h | 1 + target-alpha/cpu.c | 6 ++++++ target-arm/cpu.c | 1 + target-cris/cpu.c | 6 ++++++ target-i386/cpu.c | 6 ++++++ target-lm32/cpu.c | 6 ++++++ target-m68k/cpu.c | 6 ++++++ target-microblaze/cpu.c | 6 ++++++ target-mips/cpu.c | 6 ++++++ target-moxie/cpu.c | 6 ++++++ target-openrisc/cpu.c | 6 ++++++ target-ppc/translate_init.c | 6 ++++++ target-s390x/cpu.c | 1 + target-sh4/cpu.c | 6 ++++++ target-sparc/cpu.c | 1 + target-tricore/cpu.c | 5 +++++ target-unicore32/cpu.c | 6 ++++++ target-xtensa/cpu.c | 6 ++++++ 19 files changed, 116 insertions(+), 10 deletions(-)exec.c +29
-10@@ -530,21 +530,40 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) }#endif +static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS); + +#ifdef CONFIG_USER_ONLY +int max_cpus =1 ;/* TODO: Check if this is correct ? */ +#endif + +static int cpu_get_free_index (void ) +{ +int cpu =find_first_zero_bit (cpu_index_map, max_cpus); + +if (cpu == max_cpus) { +fprintf (stderr,"WARNING: qemu: Trying to use more " +"CPUs than allowed max of %d\n" , max_cpus); +return max_cpus; + }else { +bitmap_set (cpu_index_map, cpu,1 ); +return cpu; + } +} + +void cpu_exec_exit (CPUState *cpu) +{ +bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); +} +void cpu_exec_init (CPUArchState *env) {CPUState *cpu =ENV_GET_CPU (env);CPUClass *cc =CPU_GET_CLASS (cpu); -CPUState *some_cpu; -int cpu_index;#if defined(CONFIG_USER_ONLY )cpu_list_lock ();#endif - cpu_index =0 ; -CPU_FOREACH (some_cpu) { - cpu_index++; - } - cpu->cpu_index = cpu_index; + cpu->cpu_index =cpu_get_free_index (); cpu->numa_node =0 ;QTAILQ_INIT (&cpu->breakpoints);QTAILQ_INIT (&cpu->watchpoints);@@ -558,16 +577,16 @@ void cpu_exec_init(CPUArchState *env)cpu_list_unlock ();#endif if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { -vmstate_register (NULL , cpu_index, &vmstate_cpu_common, cpu); +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); }#if defined(CPU_SAVE_VERSION ) && !defined(CONFIG_USER_ONLY ) -register_savevm (NULL ,"cpu" , cpu_index,CPU_SAVE_VERSION , +register_savevm (NULL ,"cpu" , cpu->cpu_index,CPU_SAVE_VERSION , cpu_save, cpu_load, env);assert (cc->vmsd ==NULL );assert (qdev_get_vmsd (DEVICE (cpu)) ==NULL );#endif if (cc->vmsd !=NULL ) { -vmstate_register (NULL , cpu_index, cc->vmsd, cpu); +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); } }include/exec/exec-all.h +1
-0@@ -89,6 +89,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc, target_ulong cs_base, int flags, int cflags);void cpu_exec_init (CPUArchState *env); +void cpu_exec_exit (CPUState *cpu); void QEMU_NORETURN cpu_loop_exit(CPUState *cpu);int page_unprotect (target_ulong address,uintptr_t pc,void *puc); void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,target-alpha/cpu.c +0
-0@@ -250,6 +250,11 @@ static const TypeInfo ev68_cpu_type_info = { .parent = TYPE("ev67"), };
Quoted 15 lines
target-alpha/cpu.c static const TypeInfo alpha_cpu_type_info = { · line 313
Quoted 13 lines
target-alpha/cpu.c +6
-0+static void alpha_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void alpha_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);@@ -305,6 +310,7 @@ static const TypeInfo alpha_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(AlphaCPU), .instance_init = alpha_cpu_initfn, + .instance_finalize = alpha_cpu_finalize,Would it be possible to put this into
TYPE_CPU->instance_finalizeinstead?
Yes possible and that would be much cleaner since I wouldn't have to touch all archs. But it will be asymmetric in some sense as cpu_exec_init() is called from all individual cpus' instance_init but cpu_exec_exit() will be called from parent's (TYPE_CPU) instance_finalize. If that is fine, I shall post v2 with this change.
Regards,
Bharata.
Am 13.03.2015 um 12:56 schrieb Bharata B Rao:
Quoted 53 lines
From: Bharata B Rao <[email protected]>
Currently CPUState.cpu_index is monotonically increasing and a newly created CPU always gets the next higher index. The next available index is calculated by counting the existing number of CPUs. This is fine as long as we only add CPUs, but there are architectures which are starting to support CPU removal too. For an architecture like PowerPC which derives its CPU identifier (device tree ID) from
cpu_index, the existing logic of generatingcpu_indexvalues causes problems.With the currently proposed method of handling vCPU removal by parking the vCPU fd in QEMU
(Ref: http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02604.html),
generatingcpu_indexthis way will not work for PowerPC.This patch changes the way
cpu_indexis handed out by maintaining a bit map of the CPUs that tracks both addition and removal of CPUs.I am not sure if this is the right and an acceptable approach. The alternative is to do something similar for PowerPC alone and not depend on
cpu_index.I have tested this with out-of-the-tree patches for CPU hot plug and removal on x86 and sPAPR PowerPC.
Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 39 +++++++++++++++++++++++++++++---------- include/exec/exec-all.h | 1 + target-alpha/cpu.c | 6 ++++++ target-arm/cpu.c | 1 + target-cris/cpu.c | 6 ++++++ target-i386/cpu.c | 6 ++++++ target-lm32/cpu.c | 6 ++++++ target-m68k/cpu.c | 6 ++++++ target-microblaze/cpu.c | 6 ++++++ target-mips/cpu.c | 6 ++++++ target-moxie/cpu.c | 6 ++++++ target-openrisc/cpu.c | 6 ++++++ target-ppc/translate_init.c | 6 ++++++ target-s390x/cpu.c | 1 + target-sh4/cpu.c | 6 ++++++ target-sparc/cpu.c | 1 + target-tricore/cpu.c | 5 +++++ target-unicore32/cpu.c | 6 ++++++ target-xtensa/cpu.c | 6 ++++++ 19 files changed, 116 insertions(+), 10 deletions(-)exec.c +0
-0
exec.c void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) · line 533
Quoted 4 lines
exec.c +1
-0@@ -530,21 +530,40 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) }#endif +static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS);
I don't see this constant being defined in this patch. How large is it? I wonder whether this might be stolen from an x86 ACPI/NUMA context and forced onto all architectures now?
exec.c void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) · line 536
Quoted 3 lines
exec.c +3
-0+ +#ifdef CONFIG_USER_ONLY +int max_cpus =1 ;/* TODO: Check if this is correct ? */
This strikes me as wrong, as forking will create a copy of the initial CPUState, see cpu_copy(). The cpu_index might get overwritten inside the CPUState, not sure about that, but this here is global state.
Can't we just keep the current code for CONFIG_USER_ONLY and skip all the bitmap functions?
exec.c void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) · line 545
Quoted 9 lines
exec.c +9
-0+#endif + +static int cpu_get_free_index (void ) +{ +int cpu =find_first_zero_bit (cpu_index_map, max_cpus); + +if (cpu == max_cpus) { +fprintf (stderr,"WARNING: qemu: Trying to use more " +"CPUs than allowed max of %d\n" , max_cpus);
This is a bad API. :) If we can't handle it, use an Error** errp argument to pass that info outwards. Imagine this happening from QMP device-add, then this warning will go unnoticed on stderr.
(Also, error_report() would use the real executable name.)
exec.c void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) · line 558
Quoted 13 lines
exec.c +12
-0+return max_cpus; + }else { +bitmap_set (cpu_index_map, cpu,1 ); +return cpu; + } +} + +void cpu_exec_exit (CPUState *cpu) +{ +bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); +} +void cpu_exec_init (CPUArchState *env)
[snip]
Regards,
Andreas
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu, Graham Norton; HRB 21284 (AG Nürnberg)
Am 17.03.2015 um 09:39 schrieb Bharata B Rao:
Quoted 160 lines · Alexander Graf
Quoted 143 lines · Bharata B Rao
Quoted 140 lines
From: Bharata B Rao <[email protected]>
Currently CPUState.cpu_index is monotonically increasing and a newly created CPU always gets the next higher index. The next available index is calculated by counting the existing number of CPUs. This is fine as long as we only add CPUs, but there are architectures which are starting to support CPU removal too. For an architecture like PowerPC which derives its CPU identifier (device tree ID) from
cpu_index, the existing logic of generatingcpu_indexvalues causes problems.With the currently proposed method of handling vCPU removal by parking the vCPU fd in QEMU
(Ref: http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02604.html),
generatingcpu_indexthis way will not work for PowerPC.This patch changes the way
cpu_indexis handed out by maintaining a bit map of the CPUs that tracks both addition and removal of CPUs.I am not sure if this is the right and an acceptable approach. The alternative is to do something similar for PowerPC alone and not depend on
cpu_index.I have tested this with out-of-the-tree patches for CPU hot plug and removal on x86 and sPAPR PowerPC.
Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 39 +++++++++++++++++++++++++++++---------- include/exec/exec-all.h | 1 + target-alpha/cpu.c | 6 ++++++ target-arm/cpu.c | 1 + target-cris/cpu.c | 6 ++++++ target-i386/cpu.c | 6 ++++++ target-lm32/cpu.c | 6 ++++++ target-m68k/cpu.c | 6 ++++++ target-microblaze/cpu.c | 6 ++++++ target-mips/cpu.c | 6 ++++++ target-moxie/cpu.c | 6 ++++++ target-openrisc/cpu.c | 6 ++++++ target-ppc/translate_init.c | 6 ++++++ target-s390x/cpu.c | 1 + target-sh4/cpu.c | 6 ++++++ target-sparc/cpu.c | 1 + target-tricore/cpu.c | 5 +++++ target-unicore32/cpu.c | 6 ++++++ target-xtensa/cpu.c | 6 ++++++ 19 files changed, 116 insertions(+), 10 deletions(-)exec.c +29
-10@@ -530,21 +530,40 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) }#endif +static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS); + +#ifdef CONFIG_USER_ONLY +int max_cpus =1 ;/* TODO: Check if this is correct ? */ +#endif + +static int cpu_get_free_index (void ) +{ +int cpu =find_first_zero_bit (cpu_index_map, max_cpus); + +if (cpu == max_cpus) { +fprintf (stderr,"WARNING: qemu: Trying to use more " +"CPUs than allowed max of %d\n" , max_cpus); +return max_cpus; + }else { +bitmap_set (cpu_index_map, cpu,1 ); +return cpu; + } +} + +void cpu_exec_exit (CPUState *cpu) +{ +bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); +} +void cpu_exec_init (CPUArchState *env) {CPUState *cpu =ENV_GET_CPU (env);CPUClass *cc =CPU_GET_CLASS (cpu); -CPUState *some_cpu; -int cpu_index;#if defined(CONFIG_USER_ONLY )cpu_list_lock ();#endif - cpu_index =0 ; -CPU_FOREACH (some_cpu) { - cpu_index++; - } - cpu->cpu_index = cpu_index; + cpu->cpu_index =cpu_get_free_index (); cpu->numa_node =0 ;QTAILQ_INIT (&cpu->breakpoints);QTAILQ_INIT (&cpu->watchpoints);@@ -558,16 +577,16 @@ void cpu_exec_init(CPUArchState *env)cpu_list_unlock ();#endif if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { -vmstate_register (NULL , cpu_index, &vmstate_cpu_common, cpu); +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); }#if defined(CPU_SAVE_VERSION ) && !defined(CONFIG_USER_ONLY ) -register_savevm (NULL ,"cpu" , cpu_index,CPU_SAVE_VERSION , +register_savevm (NULL ,"cpu" , cpu->cpu_index,CPU_SAVE_VERSION , cpu_save, cpu_load, env);assert (cc->vmsd ==NULL );assert (qdev_get_vmsd (DEVICE (cpu)) ==NULL );#endif if (cc->vmsd !=NULL ) { -vmstate_register (NULL , cpu_index, cc->vmsd, cpu); +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); } }include/exec/exec-all.h +1
-0@@ -89,6 +89,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc, target_ulong cs_base, int flags, int cflags);void cpu_exec_init (CPUArchState *env); +void cpu_exec_exit (CPUState *cpu); void QEMU_NORETURN cpu_loop_exit(CPUState *cpu);int page_unprotect (target_ulong address,uintptr_t pc,void *puc); void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,target-alpha/cpu.c +0
-0@@ -250,6 +250,11 @@ static const TypeInfo ev68_cpu_type_info = { .parent = TYPE("ev67"), };Quoted 15 lines
target-alpha/cpu.c static const TypeInfo alpha_cpu_type_info = { · line 313
Quoted 13 lines
target-alpha/cpu.c +6
-0+static void alpha_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void alpha_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);@@ -305,6 +310,7 @@ static const TypeInfo alpha_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(AlphaCPU), .instance_init = alpha_cpu_initfn, + .instance_finalize = alpha_cpu_finalize,Would it be possible to put this into
TYPE_CPU->instance_finalizeinstead?
Quoted 5 lines
Yes possible and that would be much cleaner since I wouldn't have to touch all archs. But it will be asymmetric in some sense as
cpu_exec_init()is called from all individual cpus'instance_initbutcpu_exec_exit()will be called from parent's (TYPE_CPU)instance_finalize. If that is fine, I shall post v2 with this change.
Could you check: Wasn't there a patch from Fujitsu to move cpu_exec_init() to generic code? If both were generic, that would be fine. If that is problematic, I would accept the mismatch as long as it is "safe". That is, instance_finalize needs to handle any state of the object, and I think these two are better suited for realize/unrealize than instance_init/instance_finalize.
The unanswered question around the Fujitsu patches is mostly whether some of such code movements impact timing in the sense of breaking migration compatibility by changing the relative order.
Probably something my CPU test case should be extended with.
Regards,
Andreas
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu, Graham Norton; HRB 21284 (AG Nürnberg)
Quoted 18 lines · Bharata B Rao
From: Bharata B Rao <[email protected]>
Currently CPUState.cpu_index is monotonically increasing and a newly created CPU always gets the next higher index. The next available index is calculated by counting the existing number of CPUs. This is fine as long as we only add CPUs, but there are architectures which are starting to support CPU removal too. For an architecture like PowerPC which derives its CPU identifier (device tree ID) from
cpu_index, the existing logic of generatingcpu_indexvalues causes problems.With the currently proposed method of handling vCPU removal by parking the vCPU fd in QEMU
(Ref: http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02604.html),
generatingcpu_indexthis way will not work for PowerPC.This patch changes the way
cpu_indexis handed out by maintaining a bit map of the CPUs that tracks both addition and removal of CPUs.
Quoted 6 lines
I am not sure if this is the right and an acceptable approach. The alternative is to do something similar for PowerPC alone and not depend on
cpu_index.I have tested this with out-of-the-tree patches for CPU hot plug and removal on x86 and sPAPR PowerPC.
How does this interact with the tweaking of cpu indexes that spapr does in order to configure the guest SMT mode on POWER7 and POWER8 systems?
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 167 lines · Andreas Färber
Am 17.03.2015 um 09:39 schrieb Bharata B Rao:
Quoted 160 lines · Alexander Graf
Quoted 143 lines · Bharata B Rao
Quoted 140 lines
From: Bharata B Rao <[email protected]>
Currently CPUState.cpu_index is monotonically increasing and a newly created CPU always gets the next higher index. The next available index is calculated by counting the existing number of CPUs. This is fine as long as we only add CPUs, but there are architectures which are starting to support CPU removal too. For an architecture like PowerPC which derives its CPU identifier (device tree ID) from
cpu_index, the existing logic of generatingcpu_indexvalues causes problems.With the currently proposed method of handling vCPU removal by parking the vCPU fd in QEMU
(Ref: http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02604.html),
generatingcpu_indexthis way will not work for PowerPC.This patch changes the way
cpu_indexis handed out by maintaining a bit map of the CPUs that tracks both addition and removal of CPUs.I am not sure if this is the right and an acceptable approach. The alternative is to do something similar for PowerPC alone and not depend on
cpu_index.I have tested this with out-of-the-tree patches for CPU hot plug and removal on x86 and sPAPR PowerPC.
Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 39 +++++++++++++++++++++++++++++---------- include/exec/exec-all.h | 1 + target-alpha/cpu.c | 6 ++++++ target-arm/cpu.c | 1 + target-cris/cpu.c | 6 ++++++ target-i386/cpu.c | 6 ++++++ target-lm32/cpu.c | 6 ++++++ target-m68k/cpu.c | 6 ++++++ target-microblaze/cpu.c | 6 ++++++ target-mips/cpu.c | 6 ++++++ target-moxie/cpu.c | 6 ++++++ target-openrisc/cpu.c | 6 ++++++ target-ppc/translate_init.c | 6 ++++++ target-s390x/cpu.c | 1 + target-sh4/cpu.c | 6 ++++++ target-sparc/cpu.c | 1 + target-tricore/cpu.c | 5 +++++ target-unicore32/cpu.c | 6 ++++++ target-xtensa/cpu.c | 6 ++++++ 19 files changed, 116 insertions(+), 10 deletions(-)exec.c +29
-10@@ -530,21 +530,40 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) }#endif +static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS); + +#ifdef CONFIG_USER_ONLY +int max_cpus =1 ;/* TODO: Check if this is correct ? */ +#endif + +static int cpu_get_free_index (void ) +{ +int cpu =find_first_zero_bit (cpu_index_map, max_cpus); + +if (cpu == max_cpus) { +fprintf (stderr,"WARNING: qemu: Trying to use more " +"CPUs than allowed max of %d\n" , max_cpus); +return max_cpus; + }else { +bitmap_set (cpu_index_map, cpu,1 ); +return cpu; + } +} + +void cpu_exec_exit (CPUState *cpu) +{ +bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); +} +void cpu_exec_init (CPUArchState *env) {CPUState *cpu =ENV_GET_CPU (env);CPUClass *cc =CPU_GET_CLASS (cpu); -CPUState *some_cpu; -int cpu_index;#if defined(CONFIG_USER_ONLY )cpu_list_lock ();#endif - cpu_index =0 ; -CPU_FOREACH (some_cpu) { - cpu_index++; - } - cpu->cpu_index = cpu_index; + cpu->cpu_index =cpu_get_free_index (); cpu->numa_node =0 ;QTAILQ_INIT (&cpu->breakpoints);QTAILQ_INIT (&cpu->watchpoints);@@ -558,16 +577,16 @@ void cpu_exec_init(CPUArchState *env)cpu_list_unlock ();#endif if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { -vmstate_register (NULL , cpu_index, &vmstate_cpu_common, cpu); +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); }#if defined(CPU_SAVE_VERSION ) && !defined(CONFIG_USER_ONLY ) -register_savevm (NULL ,"cpu" , cpu_index,CPU_SAVE_VERSION , +register_savevm (NULL ,"cpu" , cpu->cpu_index,CPU_SAVE_VERSION , cpu_save, cpu_load, env);assert (cc->vmsd ==NULL );assert (qdev_get_vmsd (DEVICE (cpu)) ==NULL );#endif if (cc->vmsd !=NULL ) { -vmstate_register (NULL , cpu_index, cc->vmsd, cpu); +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); } }include/exec/exec-all.h +1
-0@@ -89,6 +89,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc, target_ulong cs_base, int flags, int cflags);void cpu_exec_init (CPUArchState *env); +void cpu_exec_exit (CPUState *cpu); void QEMU_NORETURN cpu_loop_exit(CPUState *cpu);int page_unprotect (target_ulong address,uintptr_t pc,void *puc); void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,target-alpha/cpu.c +0
-0@@ -250,6 +250,11 @@ static const TypeInfo ev68_cpu_type_info = { .parent = TYPE("ev67"), };Quoted 15 lines
target-alpha/cpu.c static const TypeInfo alpha_cpu_type_info = { · line 313
Quoted 13 lines
target-alpha/cpu.c +6
-0+static void alpha_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void alpha_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);@@ -305,6 +310,7 @@ static const TypeInfo alpha_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(AlphaCPU), .instance_init = alpha_cpu_initfn, + .instance_finalize = alpha_cpu_finalize,Would it be possible to put this into
TYPE_CPU->instance_finalizeinstead?Quoted 5 lines
Yes possible and that would be much cleaner since I wouldn't have to touch all archs. But it will be asymmetric in some sense as
cpu_exec_init()is called from all individual cpus'instance_initbutcpu_exec_exit()will be called from parent's (TYPE_CPU)instance_finalize. If that is fine, I shall post v2 with this change.
Quoted 5 lines
Could you check: Wasn't there a patch from Fujitsu to move
cpu_exec_init()to generic code? If both were generic, that would be fine. If that is problematic, I would accept the mismatch as long as it is "safe". That is,instance_finalizeneeds to handle any state of the object,
There is a patch from Zhu to move only vmstate_register related bits from cpu_exec_init to cpu_common_realizefn.
http://lists.gnu.org/archive/html/qemu-devel/2015-01/msg01550.html
Quoted 2 lines
and I think these two are better suited for realize/unrealize than instance_init/instance_finalize.
And Eduardo has a patch to move cpu_exec_init call from instance_init to realize for target-i386.
https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg01056.html
So if the preferred way is to call cpu_exec_init from realize, then Eduardo - Can you do this for all archs ? My limited testing shows that it (moving cpu_exec_init from instance_init to realize) works for sPAPR PowerPC too, but not sure about other targets.
After there is consensus on the above two patches, I can do the cpu_index to bitmap changes.
Regards,
Bharata.
Quoted 57 lines · Andreas Färber
Am 13.03.2015 um 12:56 schrieb Bharata B Rao:
Quoted 56 lines
From: Bharata B Rao <[email protected]>
Currently CPUState.cpu_index is monotonically increasing and a newly created CPU always gets the next higher index. The next available index is calculated by counting the existing number of CPUs. This is fine as long as we only add CPUs, but there are architectures which are starting to support CPU removal too. For an architecture like PowerPC which derives its CPU identifier (device tree ID) from
cpu_index, the existing logic of generatingcpu_indexvalues causes problems.With the currently proposed method of handling vCPU removal by parking the vCPU fd in QEMU
(Ref: http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02604.html),
generatingcpu_indexthis way will not work for PowerPC.This patch changes the way
cpu_indexis handed out by maintaining a bit map of the CPUs that tracks both addition and removal of CPUs.I am not sure if this is the right and an acceptable approach. The alternative is to do something similar for PowerPC alone and not depend on
cpu_index.I have tested this with out-of-the-tree patches for CPU hot plug and removal on x86 and sPAPR PowerPC.
Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 39 +++++++++++++++++++++++++++++---------- include/exec/exec-all.h | 1 + target-alpha/cpu.c | 6 ++++++ target-arm/cpu.c | 1 + target-cris/cpu.c | 6 ++++++ target-i386/cpu.c | 6 ++++++ target-lm32/cpu.c | 6 ++++++ target-m68k/cpu.c | 6 ++++++ target-microblaze/cpu.c | 6 ++++++ target-mips/cpu.c | 6 ++++++ target-moxie/cpu.c | 6 ++++++ target-openrisc/cpu.c | 6 ++++++ target-ppc/translate_init.c | 6 ++++++ target-s390x/cpu.c | 1 + target-sh4/cpu.c | 6 ++++++ target-sparc/cpu.c | 1 + target-tricore/cpu.c | 5 +++++ target-unicore32/cpu.c | 6 ++++++ target-xtensa/cpu.c | 6 ++++++ 19 files changed, 116 insertions(+), 10 deletions(-)exec.c +0
-0@@ -530,21 +530,40 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) }#endif
Quoted 5 lines
exec.c void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) · line 533
Quoted 1 line
exec.c +1
-0+static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS);I don't see this constant being defined in this patch. How large is it? I wonder whether this might be stolen from an x86 ACPI/NUMA context and forced onto all architectures now?
I thought MAX_CPUMASK_BITS defines the max cpus possible.
Quoted 1 line
From
include/sysemu/sysemu.h
/* The following shall be true for all CPUs:
* cpu->cpu_index < max_cpus <= MAX_CPUMASK_BITS
*
* Note that cpu->get_arch_id() may be larger than MAX_CPUMASK_BITS. */
#define MAX_CPUMASK_BITS 255
Quoted 11 lines
exec.c void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) · line 536
Quoted 4 lines
exec.c +3
-0+ +#ifdef CONFIG_USER_ONLY +int max_cpus =1 ;/* TODO: Check if this is correct ? */ This strikes me as wrong, as forking will create a copy of the initial CPUState, see
cpu_copy(). Thecpu_indexmight get overwritten inside the CPUState, not sure about that, but this here is global state.Can't we just keep the current code for
CONFIG_USER_ONLYand skip all the bitmap functions?
Yes that would better than to touch CONFIG_USER_ONLY.
Quoted 14 lines
exec.c void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) · line 545
Quoted 10 lines
exec.c +9
-0+#endif + +static int cpu_get_free_index (void ) +{ +int cpu =find_first_zero_bit (cpu_index_map, max_cpus); + +if (cpu == max_cpus) { +fprintf (stderr,"WARNING: qemu: Trying to use more " +"CPUs than allowed max of %d\n" , max_cpus);This is a bad API. :) If we can't handle it, use an Error** errp argument to pass that info outwards. Imagine this happening from QMP device-add, then this warning will go unnoticed on stderr.
I wanted to have an Error argument, but realized that instance_init doesn't take an Error argument and as a consequence, it appears that object_new() can't fail. So I depended on (cpu->cpu_index >= max_cpus) or equivalent check in realize call to catch this error.
But as being discussed in other thread on the same subject, if cpu_exec_init call moves to realize, this will get solved neatly.
Regards,
Bharata.
Quoted 23 lines · David Gibson
Quoted 22 lines · Bharata B Rao
From: Bharata B Rao <[email protected]>
Currently CPUState.cpu_index is monotonically increasing and a newly created CPU always gets the next higher index. The next available index is calculated by counting the existing number of CPUs. This is fine as long as we only add CPUs, but there are architectures which are starting to support CPU removal too. For an architecture like PowerPC which derives its CPU identifier (device tree ID) from
cpu_index, the existing logic of generatingcpu_indexvalues causes problems.With the currently proposed method of handling vCPU removal by parking the vCPU fd in QEMU
(Ref: http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02604.html),
generatingcpu_indexthis way will not work for PowerPC.This patch changes the way
cpu_indexis handed out by maintaining a bit map of the CPUs that tracks both addition and removal of CPUs.I am not sure if this is the right and an acceptable approach. The alternative is to do something similar for PowerPC alone and not depend on
cpu_index.
Quoted 6 lines
Quoted 2 lines
I have tested this with out-of-the-tree patches for CPU hot plug and removal on x86 and sPAPR PowerPC.
How does this interact with the tweaking of cpu indexes that spapr does in order to configure the guest SMT mode on POWER7 and POWER8 systems?
I am not changing the mapping of cpu_index to cpu_dt_id. So nothing should be change. Can you please point me to the piece of tweaking code that you are referring to above ?
Regards,
Bharata.
Quoted 27 lines · Bharata B Rao
Quoted 26 lines · David Gibson
Quoted 24 lines · Bharata B Rao
From: Bharata B Rao <[email protected]>
Currently CPUState.cpu_index is monotonically increasing and a newly created CPU always gets the next higher index. The next available index is calculated by counting the existing number of CPUs. This is fine as long as we only add CPUs, but there are architectures which are starting to support CPU removal too. For an architecture like PowerPC which derives its CPU identifier (device tree ID) from
cpu_index, the existing logic of generatingcpu_indexvalues causes problems.With the currently proposed method of handling vCPU removal by parking the vCPU fd in QEMU
(Ref: http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02604.html),
generatingcpu_indexthis way will not work for PowerPC.This patch changes the way
cpu_indexis handed out by maintaining a bit map of the CPUs that tracks both addition and removal of CPUs.I am not sure if this is the right and an acceptable approach. The alternative is to do something similar for PowerPC alone and not depend on
cpu_index.I have tested this with out-of-the-tree patches for CPU hot plug and removal on x86 and sPAPR PowerPC.
Quoted 7 lines
Quoted 3 lines
How does this interact with the tweaking of cpu indexes that spapr does in order to configure the guest SMT mode on POWER7 and POWER8 systems?
I am not changing the mapping of
cpu_indextocpu_dt_id. So nothing should be change. Can you please point me to the piece of tweaking code that you are referring to above ?
Ah, I thought it actually adjusted the cpu_index values, rather than mapping them to different cpu_dt_id values. Maybe it used to, or maybe I just misremembered.
Never mind, should be fine.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 7 lines · Bharata B Rao
Quoted 6 lines · Andreas Färber
Am 17.03.2015 um 09:39 schrieb Bharata B Rao:
Quoted 5 lines · Alexander Graf
Quoted 4 lines · Bharata B Rao
Quoted 1 line
From: Bharata B Rao <[email protected]>
[...]
Quoted 40 lines
Quoted 23 lines
Quoted 17 lines
Quoted 16 lines
Quoted 10 lines
target-alpha/cpu.c +5
-0+static void alpha_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void alpha_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);target-alpha/cpu.c static const TypeInfo alpha_cpu_type_info = { · line 313
Quoted 4 lines
target-alpha/cpu.c +1
-0@@ -305,6 +310,7 @@ static const TypeInfo alpha_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(AlphaCPU), .instance_init = alpha_cpu_initfn, + .instance_finalize = alpha_cpu_finalize,Would it be possible to put this into
TYPE_CPU->instance_finalizeinstead?Quoted 5 lines
Yes possible and that would be much cleaner since I wouldn't have to touch all archs. But it will be asymmetric in some sense as
cpu_exec_init()is called from all individual cpus'instance_initbutcpu_exec_exit()will be called from parent's (TYPE_CPU)instance_finalize. If that is fine, I shall post v2 with this change.Quoted 5 lines
Could you check: Wasn't there a patch from Fujitsu to move
cpu_exec_init()to generic code? If both were generic, that would be fine. If that is problematic, I would accept the mismatch as long as it is "safe". That is,instance_finalizeneeds to handle any state of the object,There is a patch from Zhu to move only
vmstate_registerrelated bits fromcpu_exec_inittocpu_common_realizefn.http://lists.gnu.org/archive/html/qemu-devel/2015-01/msg01550.html
Quoted 2 lines
and I think these two are better suited for realize/unrealize than instance_init/instance_finalize.
And Eduardo has a patch to move
cpu_exec_initcall frominstance_initto realize for target-i386.
Quoted 6 lines
https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg01056.html
So if the preferred way is to call
cpu_exec_initfrom realize, then Eduardo - Can you do this for all archs ? My limited testing shows that it (movingcpu_exec_initfrominstance_initto realize) works for sPAPR PowerPC too, but not sure about other targets.
I can submit a RFC for all arches, but I don't have the ability to test all of them. I think it is likely that some architectures have additional code inside instance_init that depends on cpu_exec_init() being called (i386 was one of them, until we removed cpu_index-based default apic_id calculation).
We need to call cpu_exec_init() from realize because instance_init shouldn't have any side-effects except on the state of the object itself. See the discussion at:
http://thread.gmane.org/gmane.comp.emulators.qemu/326307
Subject: [PATCH] qdev: Make -device FOO, help help again when FOO is not pluggable
Message-Id: <[email protected]>
Signature · 1 line
Eduardo
Quoted 187 lines · Bharata B Rao
Quoted 167 lines · Andreas Färber
Am 17.03.2015 um 09:39 schrieb Bharata B Rao:
Quoted 160 lines · Alexander Graf
Quoted 143 lines · Bharata B Rao
Quoted 140 lines
From: Bharata B Rao <[email protected]>
Currently CPUState.cpu_index is monotonically increasing and a newly created CPU always gets the next higher index. The next available index is calculated by counting the existing number of CPUs. This is fine as long as we only add CPUs, but there are architectures which are starting to support CPU removal too. For an architecture like PowerPC which derives its CPU identifier (device tree ID) from
cpu_index, the existing logic of generatingcpu_indexvalues causes problems.With the currently proposed method of handling vCPU removal by parking the vCPU fd in QEMU
(Ref: http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02604.html),
generatingcpu_indexthis way will not work for PowerPC.This patch changes the way
cpu_indexis handed out by maintaining a bit map of the CPUs that tracks both addition and removal of CPUs.I am not sure if this is the right and an acceptable approach. The alternative is to do something similar for PowerPC alone and not depend on
cpu_index.I have tested this with out-of-the-tree patches for CPU hot plug and removal on x86 and sPAPR PowerPC.
Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 39 +++++++++++++++++++++++++++++---------- include/exec/exec-all.h | 1 + target-alpha/cpu.c | 6 ++++++ target-arm/cpu.c | 1 + target-cris/cpu.c | 6 ++++++ target-i386/cpu.c | 6 ++++++ target-lm32/cpu.c | 6 ++++++ target-m68k/cpu.c | 6 ++++++ target-microblaze/cpu.c | 6 ++++++ target-mips/cpu.c | 6 ++++++ target-moxie/cpu.c | 6 ++++++ target-openrisc/cpu.c | 6 ++++++ target-ppc/translate_init.c | 6 ++++++ target-s390x/cpu.c | 1 + target-sh4/cpu.c | 6 ++++++ target-sparc/cpu.c | 1 + target-tricore/cpu.c | 5 +++++ target-unicore32/cpu.c | 6 ++++++ target-xtensa/cpu.c | 6 ++++++ 19 files changed, 116 insertions(+), 10 deletions(-)exec.c +29
-10@@ -530,21 +530,40 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) }#endif +static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS); + +#ifdef CONFIG_USER_ONLY +int max_cpus =1 ;/* TODO: Check if this is correct ? */ +#endif + +static int cpu_get_free_index (void ) +{ +int cpu =find_first_zero_bit (cpu_index_map, max_cpus); + +if (cpu == max_cpus) { +fprintf (stderr,"WARNING: qemu: Trying to use more " +"CPUs than allowed max of %d\n" , max_cpus); +return max_cpus; + }else { +bitmap_set (cpu_index_map, cpu,1 ); +return cpu; + } +} + +void cpu_exec_exit (CPUState *cpu) +{ +bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); +} +void cpu_exec_init (CPUArchState *env) {CPUState *cpu =ENV_GET_CPU (env);CPUClass *cc =CPU_GET_CLASS (cpu); -CPUState *some_cpu; -int cpu_index;#if defined(CONFIG_USER_ONLY )cpu_list_lock ();#endif - cpu_index =0 ; -CPU_FOREACH (some_cpu) { - cpu_index++; - } - cpu->cpu_index = cpu_index; + cpu->cpu_index =cpu_get_free_index (); cpu->numa_node =0 ;QTAILQ_INIT (&cpu->breakpoints);QTAILQ_INIT (&cpu->watchpoints);@@ -558,16 +577,16 @@ void cpu_exec_init(CPUArchState *env)cpu_list_unlock ();#endif if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { -vmstate_register (NULL , cpu_index, &vmstate_cpu_common, cpu); +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); }#if defined(CPU_SAVE_VERSION ) && !defined(CONFIG_USER_ONLY ) -register_savevm (NULL ,"cpu" , cpu_index,CPU_SAVE_VERSION , +register_savevm (NULL ,"cpu" , cpu->cpu_index,CPU_SAVE_VERSION , cpu_save, cpu_load, env);assert (cc->vmsd ==NULL );assert (qdev_get_vmsd (DEVICE (cpu)) ==NULL );#endif if (cc->vmsd !=NULL ) { -vmstate_register (NULL , cpu_index, cc->vmsd, cpu); +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); } }include/exec/exec-all.h +1
-0@@ -89,6 +89,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc, target_ulong cs_base, int flags, int cflags);void cpu_exec_init (CPUArchState *env); +void cpu_exec_exit (CPUState *cpu); void QEMU_NORETURN cpu_loop_exit(CPUState *cpu);int page_unprotect (target_ulong address,uintptr_t pc,void *puc); void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,target-alpha/cpu.c +0
-0@@ -250,6 +250,11 @@ static const TypeInfo ev68_cpu_type_info = { .parent = TYPE("ev67"), };Quoted 15 lines
target-alpha/cpu.c static const TypeInfo alpha_cpu_type_info = { · line 313
Quoted 13 lines
target-alpha/cpu.c +6
-0+static void alpha_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void alpha_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);@@ -305,6 +310,7 @@ static const TypeInfo alpha_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(AlphaCPU), .instance_init = alpha_cpu_initfn, + .instance_finalize = alpha_cpu_finalize,Would it be possible to put this into
TYPE_CPU->instance_finalizeinstead?Quoted 5 lines
Yes possible and that would be much cleaner since I wouldn't have to touch all archs. But it will be asymmetric in some sense as
cpu_exec_init()is called from all individual cpus'instance_initbutcpu_exec_exit()will be called from parent's (TYPE_CPU)instance_finalize. If that is fine, I shall post v2 with this change.Quoted 5 lines
Could you check: Wasn't there a patch from Fujitsu to move
cpu_exec_init()to generic code? If both were generic, that would be fine. If that is problematic, I would accept the mismatch as long as it is "safe". That is,instance_finalizeneeds to handle any state of the object,There is a patch from Zhu to move only
vmstate_registerrelated bits fromcpu_exec_inittocpu_common_realizefn.http://lists.gnu.org/archive/html/qemu-devel/2015-01/msg01550.html
Quoted 2 lines
and I think these two are better suited for realize/unrealize than instance_init/instance_finalize.
And Eduardo has a patch to move
cpu_exec_initcall frominstance_initto realize for target-i386.https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg01056.html
Quoted 7 lines
So if the preferred way is to call
cpu_exec_initfrom realize, then Eduardo - Can you do this for all archs ? My limited testing shows that it (movingcpu_exec_initfrominstance_initto realize) works for sPAPR PowerPC too, but not sure about other targets.After there is consensus on the above two patches, I can do the
cpu_indexto bitmap changes.
I was planning to re-post this patch now, but wanted to know the plan regarding the related two patchsets that I have mentioned above.
1. Patch by Eduardo to move cpu_exec_init from instance_init to realizefn
2. Patch by Zhu to move vmstate_register related bits from cpu_exec_init to cpu_common_realizefn.
I don't see any more updates on this, are these obsolete or still under consideration ?
Regards,
Bharata.
Quoted 199 lines · Bharata B Rao
Quoted 187 lines · Bharata B Rao
Quoted 167 lines · Andreas Färber
Am 17.03.2015 um 09:39 schrieb Bharata B Rao:
Quoted 160 lines · Alexander Graf
Quoted 143 lines · Bharata B Rao
Quoted 140 lines
From: Bharata B Rao <[email protected]>
Currently CPUState.cpu_index is monotonically increasing and a newly created CPU always gets the next higher index. The next available index is calculated by counting the existing number of CPUs. This is fine as long as we only add CPUs, but there are architectures which are starting to support CPU removal too. For an architecture like PowerPC which derives its CPU identifier (device tree ID) from
cpu_index, the existing logic of generatingcpu_indexvalues causes problems.With the currently proposed method of handling vCPU removal by parking the vCPU fd in QEMU
(Ref: http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02604.html),
generatingcpu_indexthis way will not work for PowerPC.This patch changes the way
cpu_indexis handed out by maintaining a bit map of the CPUs that tracks both addition and removal of CPUs.I am not sure if this is the right and an acceptable approach. The alternative is to do something similar for PowerPC alone and not depend on
cpu_index.I have tested this with out-of-the-tree patches for CPU hot plug and removal on x86 and sPAPR PowerPC.
Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 39 +++++++++++++++++++++++++++++---------- include/exec/exec-all.h | 1 + target-alpha/cpu.c | 6 ++++++ target-arm/cpu.c | 1 + target-cris/cpu.c | 6 ++++++ target-i386/cpu.c | 6 ++++++ target-lm32/cpu.c | 6 ++++++ target-m68k/cpu.c | 6 ++++++ target-microblaze/cpu.c | 6 ++++++ target-mips/cpu.c | 6 ++++++ target-moxie/cpu.c | 6 ++++++ target-openrisc/cpu.c | 6 ++++++ target-ppc/translate_init.c | 6 ++++++ target-s390x/cpu.c | 1 + target-sh4/cpu.c | 6 ++++++ target-sparc/cpu.c | 1 + target-tricore/cpu.c | 5 +++++ target-unicore32/cpu.c | 6 ++++++ target-xtensa/cpu.c | 6 ++++++ 19 files changed, 116 insertions(+), 10 deletions(-)exec.c +29
-10@@ -530,21 +530,40 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) }#endif +static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS); + +#ifdef CONFIG_USER_ONLY +int max_cpus =1 ;/* TODO: Check if this is correct ? */ +#endif + +static int cpu_get_free_index (void ) +{ +int cpu =find_first_zero_bit (cpu_index_map, max_cpus); + +if (cpu == max_cpus) { +fprintf (stderr,"WARNING: qemu: Trying to use more " +"CPUs than allowed max of %d\n" , max_cpus); +return max_cpus; + }else { +bitmap_set (cpu_index_map, cpu,1 ); +return cpu; + } +} + +void cpu_exec_exit (CPUState *cpu) +{ +bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); +} +void cpu_exec_init (CPUArchState *env) {CPUState *cpu =ENV_GET_CPU (env);CPUClass *cc =CPU_GET_CLASS (cpu); -CPUState *some_cpu; -int cpu_index;#if defined(CONFIG_USER_ONLY )cpu_list_lock ();#endif - cpu_index =0 ; -CPU_FOREACH (some_cpu) { - cpu_index++; - } - cpu->cpu_index = cpu_index; + cpu->cpu_index =cpu_get_free_index (); cpu->numa_node =0 ;QTAILQ_INIT (&cpu->breakpoints);QTAILQ_INIT (&cpu->watchpoints);@@ -558,16 +577,16 @@ void cpu_exec_init(CPUArchState *env)cpu_list_unlock ();#endif if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { -vmstate_register (NULL , cpu_index, &vmstate_cpu_common, cpu); +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); }#if defined(CPU_SAVE_VERSION ) && !defined(CONFIG_USER_ONLY ) -register_savevm (NULL ,"cpu" , cpu_index,CPU_SAVE_VERSION , +register_savevm (NULL ,"cpu" , cpu->cpu_index,CPU_SAVE_VERSION , cpu_save, cpu_load, env);assert (cc->vmsd ==NULL );assert (qdev_get_vmsd (DEVICE (cpu)) ==NULL );#endif if (cc->vmsd !=NULL ) { -vmstate_register (NULL , cpu_index, cc->vmsd, cpu); +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); } }include/exec/exec-all.h +1
-0@@ -89,6 +89,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc, target_ulong cs_base, int flags, int cflags);void cpu_exec_init (CPUArchState *env); +void cpu_exec_exit (CPUState *cpu); void QEMU_NORETURN cpu_loop_exit(CPUState *cpu);int page_unprotect (target_ulong address,uintptr_t pc,void *puc); void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,target-alpha/cpu.c +0
-0@@ -250,6 +250,11 @@ static const TypeInfo ev68_cpu_type_info = { .parent = TYPE("ev67"), };Quoted 15 lines
target-alpha/cpu.c static const TypeInfo alpha_cpu_type_info = { · line 313
Quoted 13 lines
target-alpha/cpu.c +6
-0+static void alpha_cpu_finalize (Object *obj) +{ +cpu_exec_exit (CPU (obj)); +} +static void alpha_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);@@ -305,6 +310,7 @@ static const TypeInfo alpha_cpu_type_info = { .parent = TYPE_CPU, .instance_size = sizeof(AlphaCPU), .instance_init = alpha_cpu_initfn, + .instance_finalize = alpha_cpu_finalize,Would it be possible to put this into
TYPE_CPU->instance_finalizeinstead?Quoted 5 lines
Yes possible and that would be much cleaner since I wouldn't have to touch all archs. But it will be asymmetric in some sense as
cpu_exec_init()is called from all individual cpus'instance_initbutcpu_exec_exit()will be called from parent's (TYPE_CPU)instance_finalize. If that is fine, I shall post v2 with this change.Quoted 5 lines
Could you check: Wasn't there a patch from Fujitsu to move
cpu_exec_init()to generic code? If both were generic, that would be fine. If that is problematic, I would accept the mismatch as long as it is "safe". That is,instance_finalizeneeds to handle any state of the object,There is a patch from Zhu to move only
vmstate_registerrelated bits fromcpu_exec_inittocpu_common_realizefn.http://lists.gnu.org/archive/html/qemu-devel/2015-01/msg01550.html
Quoted 2 lines
and I think these two are better suited for realize/unrealize than instance_init/instance_finalize.
And Eduardo has a patch to move
cpu_exec_initcall frominstance_initto realize for target-i386.https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg01056.html
Quoted 7 lines
So if the preferred way is to call
cpu_exec_initfrom realize, then Eduardo - Can you do this for all archs ? My limited testing shows that it (movingcpu_exec_initfrominstance_initto realize) works for sPAPR PowerPC too, but not sure about other targets.After there is consensus on the above two patches, I can do the
cpu_indexto bitmap changes.I was planning to re-post this patch now, but wanted to know the plan regarding the related two patchsets that I have mentioned above.
Quoted 6 lines
1. Patch by Eduardo to move
cpu_exec_initfrominstance_initto realizefn
2. Patch by Zhu to movevmstate_registerrelated bits fromcpu_exec_inittocpu_common_realizefn.I don't see any more updates on this, are these obsolete or still under consideration ?
#1 is still planned for x86. Other architectures probably need it, but I think it should be done by somebody familiar with each architecture. There may be subtle initialization ordering requirements in arch-specific CPU init code (that happened on x86, when we had cpu_index-based apic_id initialization on initfn).
I don't know if this was suggested before: if you make cpu_exec_exit() idempotent (and safe to call even if cpu_exec_init() wasn't called), we can simply call it unconditionally in CPUClass::instance_finalize, because if the CPU object is already being destroyed, we know it must be removed from the global CPU list.
Later, arch-specific code may decide to call cpu_exec_exit() earlier, if appropriate (on unrealizefn, for example). But at least we don't need to force all architectures to provide a instance_finalize function just because of cpu_exec_exit().
Signature · 1 line
Eduardo