Message ID | 1475696333-8706-2-git-send-email-lvivier@redhat.com |
---|---|
State | New |
Headers | show |
On 5 October 2016 at 12:38, Laurent Vivier <lvivier@redhat.com> wrote: > Extract the realize part to cpu_exec_realize(), update all > calls to cpu_exec_init() to add cpu_exec_realize() to > have no functionnal change. > > Put in cpu_exec_init() what initializes the CPU, > in cpu_exec_realize() what adds it to the environment. > > CC: Paolo Bonzini <pbonzini@redhat.com> > Signed-off-by: Laurent Vivier <lvivier@redhat.com> > --- > exec.c | 8 +++++--- > include/exec/exec-all.h | 1 + > target-alpha/cpu.c | 1 + > target-arm/cpu.c | 1 + > target-cris/cpu.c | 1 + > target-i386/cpu.c | 1 + > target-lm32/cpu.c | 1 + > target-m68k/cpu.c | 1 + > target-microblaze/cpu.c | 1 + > target-mips/cpu.c | 1 + > target-moxie/cpu.c | 1 + > target-openrisc/cpu.c | 1 + > target-ppc/translate_init.c | 5 +++++ > target-s390x/cpu.c | 4 ++++ > target-sh4/cpu.c | 1 + > target-sparc/cpu.c | 1 + > target-tilegx/cpu.c | 1 + > target-tricore/cpu.c | 1 + > target-unicore32/cpu.c | 1 + > target-xtensa/cpu.c | 1 + > 20 files changed, 31 insertions(+), 3 deletions(-) > > diff --git a/exec.c b/exec.c > index c8389f9..95b0aee 100644 > --- a/exec.c > +++ b/exec.c > @@ -614,9 +614,6 @@ void cpu_exec_exit(CPUState *cpu) > > void cpu_exec_init(CPUState *cpu, Error **errp) > { > - CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu); > - Error *local_err ATTRIBUTE_UNUSED = NULL; > - > cpu->as = NULL; > cpu->num_ases = 0; > > @@ -637,6 +634,11 @@ void cpu_exec_init(CPUState *cpu, Error **errp) > cpu->memory = system_memory; > object_ref(OBJECT(cpu->memory)); > #endif > +} > + > +void cpu_exec_realize(CPUState *cpu, Error **errp) > +{ > + CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu); > > cpu_list_add(cpu); I think cpu_list_add() needs to be in init, because this is where we set cpu->cpu_index, and (after patch 5) target-arm assumes that cpu_index has been set by init but before realize. So I guess we should do it in init and then roll back in the destructor? thanks -- PMM
On Wed, Oct 05, 2016 at 01:13:18PM -0700, Peter Maydell wrote: > On 5 October 2016 at 12:38, Laurent Vivier <lvivier@redhat.com> wrote: > > Extract the realize part to cpu_exec_realize(), update all > > calls to cpu_exec_init() to add cpu_exec_realize() to > > have no functionnal change. > > > > Put in cpu_exec_init() what initializes the CPU, > > in cpu_exec_realize() what adds it to the environment. > > > > CC: Paolo Bonzini <pbonzini@redhat.com> > > Signed-off-by: Laurent Vivier <lvivier@redhat.com> > > --- > > exec.c | 8 +++++--- > > include/exec/exec-all.h | 1 + > > target-alpha/cpu.c | 1 + > > target-arm/cpu.c | 1 + > > target-cris/cpu.c | 1 + > > target-i386/cpu.c | 1 + > > target-lm32/cpu.c | 1 + > > target-m68k/cpu.c | 1 + > > target-microblaze/cpu.c | 1 + > > target-mips/cpu.c | 1 + > > target-moxie/cpu.c | 1 + > > target-openrisc/cpu.c | 1 + > > target-ppc/translate_init.c | 5 +++++ > > target-s390x/cpu.c | 4 ++++ > > target-sh4/cpu.c | 1 + > > target-sparc/cpu.c | 1 + > > target-tilegx/cpu.c | 1 + > > target-tricore/cpu.c | 1 + > > target-unicore32/cpu.c | 1 + > > target-xtensa/cpu.c | 1 + > > 20 files changed, 31 insertions(+), 3 deletions(-) > > > > diff --git a/exec.c b/exec.c > > index c8389f9..95b0aee 100644 > > --- a/exec.c > > +++ b/exec.c > > @@ -614,9 +614,6 @@ void cpu_exec_exit(CPUState *cpu) > > > > void cpu_exec_init(CPUState *cpu, Error **errp) > > { > > - CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu); > > - Error *local_err ATTRIBUTE_UNUSED = NULL; > > - > > cpu->as = NULL; > > cpu->num_ases = 0; > > > > @@ -637,6 +634,11 @@ void cpu_exec_init(CPUState *cpu, Error **errp) > > cpu->memory = system_memory; > > object_ref(OBJECT(cpu->memory)); > > #endif > > +} > > + > > +void cpu_exec_realize(CPUState *cpu, Error **errp) > > +{ > > + CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu); > > > > cpu_list_add(cpu); > > I think cpu_list_add() needs to be in init, because > this is where we set cpu->cpu_index, and (after patch 5) > target-arm assumes that cpu_index has been set by > init but before realize. So I guess we should do it > in init and then roll back in the destructor? instance_init is supposed to have no side-effects, that's the main reason cpu_exec_init() was moved to realize. qmp_device_list_properties(), for example, creates new objects to query the available properties. query-cpu-model-expansion and related commands will probably be implemented by many architectures by instantiating actual objects.
On 05/10/2016 22:13, Peter Maydell wrote: > On 5 October 2016 at 12:38, Laurent Vivier <lvivier@redhat.com> wrote: >> Extract the realize part to cpu_exec_realize(), update all >> calls to cpu_exec_init() to add cpu_exec_realize() to >> have no functionnal change. >> >> Put in cpu_exec_init() what initializes the CPU, >> in cpu_exec_realize() what adds it to the environment. >> >> CC: Paolo Bonzini <pbonzini@redhat.com> >> Signed-off-by: Laurent Vivier <lvivier@redhat.com> >> --- >> exec.c | 8 +++++--- >> include/exec/exec-all.h | 1 + >> target-alpha/cpu.c | 1 + >> target-arm/cpu.c | 1 + >> target-cris/cpu.c | 1 + >> target-i386/cpu.c | 1 + >> target-lm32/cpu.c | 1 + >> target-m68k/cpu.c | 1 + >> target-microblaze/cpu.c | 1 + >> target-mips/cpu.c | 1 + >> target-moxie/cpu.c | 1 + >> target-openrisc/cpu.c | 1 + >> target-ppc/translate_init.c | 5 +++++ >> target-s390x/cpu.c | 4 ++++ >> target-sh4/cpu.c | 1 + >> target-sparc/cpu.c | 1 + >> target-tilegx/cpu.c | 1 + >> target-tricore/cpu.c | 1 + >> target-unicore32/cpu.c | 1 + >> target-xtensa/cpu.c | 1 + >> 20 files changed, 31 insertions(+), 3 deletions(-) >> >> diff --git a/exec.c b/exec.c >> index c8389f9..95b0aee 100644 >> --- a/exec.c >> +++ b/exec.c >> @@ -614,9 +614,6 @@ void cpu_exec_exit(CPUState *cpu) >> >> void cpu_exec_init(CPUState *cpu, Error **errp) >> { >> - CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu); >> - Error *local_err ATTRIBUTE_UNUSED = NULL; >> - >> cpu->as = NULL; >> cpu->num_ases = 0; >> >> @@ -637,6 +634,11 @@ void cpu_exec_init(CPUState *cpu, Error **errp) >> cpu->memory = system_memory; >> object_ref(OBJECT(cpu->memory)); >> #endif >> +} >> + >> +void cpu_exec_realize(CPUState *cpu, Error **errp) >> +{ >> + CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu); >> >> cpu_list_add(cpu); > > I think cpu_list_add() needs to be in init, because > this is where we set cpu->cpu_index, and (after patch 5) > target-arm assumes that cpu_index has been set by > init but before realize. So I guess we should do it > in init and then roll back in the destructor? I think in some case cpu_list_add() can fail (no more index available), it's why it has to be in realize. In the case of hotplug we must not kill the machine. See "5a790cc cpu: Add Error argument to cpu_exec_init()" Laurent
On Wed, Oct 05, 2016 at 01:13:18PM -0700, Peter Maydell wrote: > On 5 October 2016 at 12:38, Laurent Vivier <lvivier@redhat.com> wrote: > > Extract the realize part to cpu_exec_realize(), update all > > calls to cpu_exec_init() to add cpu_exec_realize() to > > have no functionnal change. > > > > Put in cpu_exec_init() what initializes the CPU, > > in cpu_exec_realize() what adds it to the environment. > > > > CC: Paolo Bonzini <pbonzini@redhat.com> > > Signed-off-by: Laurent Vivier <lvivier@redhat.com> > > --- > > exec.c | 8 +++++--- > > include/exec/exec-all.h | 1 + > > target-alpha/cpu.c | 1 + > > target-arm/cpu.c | 1 + > > target-cris/cpu.c | 1 + > > target-i386/cpu.c | 1 + > > target-lm32/cpu.c | 1 + > > target-m68k/cpu.c | 1 + > > target-microblaze/cpu.c | 1 + > > target-mips/cpu.c | 1 + > > target-moxie/cpu.c | 1 + > > target-openrisc/cpu.c | 1 + > > target-ppc/translate_init.c | 5 +++++ > > target-s390x/cpu.c | 4 ++++ > > target-sh4/cpu.c | 1 + > > target-sparc/cpu.c | 1 + > > target-tilegx/cpu.c | 1 + > > target-tricore/cpu.c | 1 + > > target-unicore32/cpu.c | 1 + > > target-xtensa/cpu.c | 1 + > > 20 files changed, 31 insertions(+), 3 deletions(-) > > > > diff --git a/exec.c b/exec.c > > index c8389f9..95b0aee 100644 > > --- a/exec.c > > +++ b/exec.c > > @@ -614,9 +614,6 @@ void cpu_exec_exit(CPUState *cpu) > > > > void cpu_exec_init(CPUState *cpu, Error **errp) > > { > > - CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu); > > - Error *local_err ATTRIBUTE_UNUSED = NULL; > > - > > cpu->as = NULL; > > cpu->num_ases = 0; > > > > @@ -637,6 +634,11 @@ void cpu_exec_init(CPUState *cpu, Error **errp) > > cpu->memory = system_memory; > > object_ref(OBJECT(cpu->memory)); > > #endif > > +} > > + > > +void cpu_exec_realize(CPUState *cpu, Error **errp) > > +{ > > + CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu); > > > > cpu_list_add(cpu); > > I think cpu_list_add() needs to be in init, because > this is where we set cpu->cpu_index, and (after patch 5) > target-arm assumes that cpu_index has been set by > init but before realize. So I guess we should do it > in init and then roll back in the destructor? That will need to be fixed on the ARM side then. The whole new cpu_index assignment model (which allows cross-platform hotplug) relies on it not being fixed until realize() time.
On 6 October 2016 at 06:02, David Gibson <david@gibson.dropbear.id.au> wrote: > On Wed, Oct 05, 2016 at 01:13:18PM -0700, Peter Maydell wrote: >> I think cpu_list_add() needs to be in init, because >> this is where we set cpu->cpu_index, and (after patch 5) >> target-arm assumes that cpu_index has been set by >> init but before realize. So I guess we should do it >> in init and then roll back in the destructor? > > That will need to be fixed on the ARM side then. The whole new > cpu_index assignment model (which allows cross-platform hotplug) > relies on it not being fixed until realize() time. OK. I guess we need to audit all the code that can get called between init and realize, which is a bit tedious. Is there anything else we need to look for other than use of cpu_index ? thanks -- PMM
diff --git a/exec.c b/exec.c index c8389f9..95b0aee 100644 --- a/exec.c +++ b/exec.c @@ -614,9 +614,6 @@ void cpu_exec_exit(CPUState *cpu) void cpu_exec_init(CPUState *cpu, Error **errp) { - CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu); - Error *local_err ATTRIBUTE_UNUSED = NULL; - cpu->as = NULL; cpu->num_ases = 0; @@ -637,6 +634,11 @@ void cpu_exec_init(CPUState *cpu, Error **errp) cpu->memory = system_memory; object_ref(OBJECT(cpu->memory)); #endif +} + +void cpu_exec_realize(CPUState *cpu, Error **errp) +{ + CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu); cpu_list_add(cpu); diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 336a57c..649187d 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -58,6 +58,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, int cflags); void cpu_exec_init(CPUState *cpu, Error **errp); +void cpu_exec_realize(CPUState *cpu, Error **errp); void QEMU_NORETURN cpu_loop_exit(CPUState *cpu); void QEMU_NORETURN cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc); diff --git a/target-alpha/cpu.c b/target-alpha/cpu.c index 6d01d7f..19f2eb2 100644 --- a/target-alpha/cpu.c +++ b/target-alpha/cpu.c @@ -267,6 +267,7 @@ static void alpha_cpu_initfn(Object *obj) cs->env_ptr = env; cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); tlb_flush(cs, 1); alpha_translate_init(); diff --git a/target-arm/cpu.c b/target-arm/cpu.c index 1b9540e..5fda716 100644 --- a/target-arm/cpu.c +++ b/target-arm/cpu.c @@ -445,6 +445,7 @@ static void arm_cpu_initfn(Object *obj) cs->env_ptr = &cpu->env; cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); cpu->cp_regs = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free); diff --git a/target-cris/cpu.c b/target-cris/cpu.c index d680cfb..78753ed 100644 --- a/target-cris/cpu.c +++ b/target-cris/cpu.c @@ -188,6 +188,7 @@ static void cris_cpu_initfn(Object *obj) cs->env_ptr = env; cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); env->pregs[PR_VR] = ccc->vr; diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 1c57fce..125a10c 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -3159,6 +3159,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) } } cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); if (tcg_enabled()) { tcg_x86_init(); diff --git a/target-lm32/cpu.c b/target-lm32/cpu.c index a783d46..4b93454 100644 --- a/target-lm32/cpu.c +++ b/target-lm32/cpu.c @@ -161,6 +161,7 @@ static void lm32_cpu_initfn(Object *obj) cs->env_ptr = env; cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); env->flags = 0; diff --git a/target-m68k/cpu.c b/target-m68k/cpu.c index 116b784..307910a 100644 --- a/target-m68k/cpu.c +++ b/target-m68k/cpu.c @@ -177,6 +177,7 @@ static void m68k_cpu_initfn(Object *obj) cs->env_ptr = env; cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); if (tcg_enabled() && !inited) { inited = true; diff --git a/target-microblaze/cpu.c b/target-microblaze/cpu.c index 8edc00a..9ec2c9c 100644 --- a/target-microblaze/cpu.c +++ b/target-microblaze/cpu.c @@ -200,6 +200,7 @@ static void mb_cpu_initfn(Object *obj) cs->env_ptr = env; cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); set_float_rounding_mode(float_round_nearest_even, &env->fp_status); diff --git a/target-mips/cpu.c b/target-mips/cpu.c index 64ad112..8a42213 100644 --- a/target-mips/cpu.c +++ b/target-mips/cpu.c @@ -139,6 +139,7 @@ static void mips_cpu_initfn(Object *obj) cs->env_ptr = env; cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); if (tcg_enabled()) { mips_tcg_init(); diff --git a/target-moxie/cpu.c b/target-moxie/cpu.c index 50a0899..28beff1 100644 --- a/target-moxie/cpu.c +++ b/target-moxie/cpu.c @@ -76,6 +76,7 @@ static void moxie_cpu_initfn(Object *obj) cs->env_ptr = &cpu->env; cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); if (tcg_enabled() && !inited) { inited = 1; diff --git a/target-openrisc/cpu.c b/target-openrisc/cpu.c index 155913f..1f2a084 100644 --- a/target-openrisc/cpu.c +++ b/target-openrisc/cpu.c @@ -96,6 +96,7 @@ static void openrisc_cpu_initfn(Object *obj) cs->env_ptr = &cpu->env; cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); #ifndef CONFIG_USER_ONLY cpu_openrisc_mmu_init(cpu); diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c index b66b40b..5e84e65 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -9683,6 +9683,11 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp) error_propagate(errp, local_err); return; } + cpu_exec_realize(cs, &local_err); + if (local_err != NULL) { + error_propagate(errp, local_err); + return; + } #if !defined(CONFIG_USER_ONLY) cpu->cpu_dt_id = (cs->cpu_index / smp_threads) * max_smt diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c index 35ae2ce..20a88dd 100644 --- a/target-s390x/cpu.c +++ b/target-s390x/cpu.c @@ -211,6 +211,10 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp) if (err != NULL) { goto out; } + cpu_exec_realize(cs, &err); + if (err != NULL) { + goto out; + } scc->next_cpu_id++; #if !defined(CONFIG_USER_ONLY) diff --git a/target-sh4/cpu.c b/target-sh4/cpu.c index f589532..f172516 100644 --- a/target-sh4/cpu.c +++ b/target-sh4/cpu.c @@ -259,6 +259,7 @@ static void superh_cpu_initfn(Object *obj) cs->env_ptr = env; cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); env->movcal_backup_tail = &(env->movcal_backup); diff --git a/target-sparc/cpu.c b/target-sparc/cpu.c index 800a25a..77cc920 100644 --- a/target-sparc/cpu.c +++ b/target-sparc/cpu.c @@ -815,6 +815,7 @@ static void sparc_cpu_initfn(Object *obj) cs->env_ptr = env; cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); if (tcg_enabled()) { gen_intermediate_code_init(env); diff --git a/target-tilegx/cpu.c b/target-tilegx/cpu.c index 7017cb6..f7ec920 100644 --- a/target-tilegx/cpu.c +++ b/target-tilegx/cpu.c @@ -108,6 +108,7 @@ static void tilegx_cpu_initfn(Object *obj) cs->env_ptr = env; cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); if (tcg_enabled() && !tcg_initialized) { tcg_initialized = true; diff --git a/target-tricore/cpu.c b/target-tricore/cpu.c index 35d4ee4..2fd3325 100644 --- a/target-tricore/cpu.c +++ b/target-tricore/cpu.c @@ -96,6 +96,7 @@ static void tricore_cpu_initfn(Object *obj) cs->env_ptr = env; cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); if (tcg_enabled()) { tricore_tcg_init(); diff --git a/target-unicore32/cpu.c b/target-unicore32/cpu.c index e7a4984..2e5466a 100644 --- a/target-unicore32/cpu.c +++ b/target-unicore32/cpu.c @@ -117,6 +117,7 @@ static void uc32_cpu_initfn(Object *obj) cs->env_ptr = env; cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); #ifdef CONFIG_USER_ONLY env->uncached_asr = ASR_MODE_USER; diff --git a/target-xtensa/cpu.c b/target-xtensa/cpu.c index 5ad08a2..fc72726 100644 --- a/target-xtensa/cpu.c +++ b/target-xtensa/cpu.c @@ -118,6 +118,7 @@ static void xtensa_cpu_initfn(Object *obj) cs->env_ptr = env; env->config = xcc->config; cpu_exec_init(cs, &error_abort); + cpu_exec_realize(cs, &error_abort); if (tcg_enabled() && !tcg_inited) { tcg_inited = true;
Extract the realize part to cpu_exec_realize(), update all calls to cpu_exec_init() to add cpu_exec_realize() to have no functionnal change. Put in cpu_exec_init() what initializes the CPU, in cpu_exec_realize() what adds it to the environment. CC: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Laurent Vivier <lvivier@redhat.com> --- exec.c | 8 +++++--- include/exec/exec-all.h | 1 + target-alpha/cpu.c | 1 + target-arm/cpu.c | 1 + target-cris/cpu.c | 1 + target-i386/cpu.c | 1 + target-lm32/cpu.c | 1 + target-m68k/cpu.c | 1 + target-microblaze/cpu.c | 1 + target-mips/cpu.c | 1 + target-moxie/cpu.c | 1 + target-openrisc/cpu.c | 1 + target-ppc/translate_init.c | 5 +++++ target-s390x/cpu.c | 4 ++++ target-sh4/cpu.c | 1 + target-sparc/cpu.c | 1 + target-tilegx/cpu.c | 1 + target-tricore/cpu.c | 1 + target-unicore32/cpu.c | 1 + target-xtensa/cpu.c | 1 + 20 files changed, 31 insertions(+), 3 deletions(-)