On Wed, 14 Jan 2015 15:27:30 +0800 Zhu Guihua <zhugh.f...@cn.fujitsu.com> wrote:
> From: Gu Zheng <guz.f...@cn.fujitsu.com> > > Add a func to finalize a cpu's instance. When cpu's device_add failed, > and cpu's device_del executed, this func would be invoked. > > Signed-off-by: Gu Zheng <guz.f...@cn.fujitsu.com> > Signed-off-by: Zhu Guihua <zhugh.f...@cn.fujitsu.com> > --- > include/qom/cpu.h | 1 + > target-i386/cpu.c | 8 ++++++++ > 2 files changed, 9 insertions(+) > > diff --git a/include/qom/cpu.h b/include/qom/cpu.h > index 936afcd..f663199 100644 > --- a/include/qom/cpu.h > +++ b/include/qom/cpu.h > @@ -305,6 +305,7 @@ struct CPUState { > QTAILQ_HEAD(CPUTailQ, CPUState); > extern struct CPUTailQ cpus; > #define CPU_NEXT(cpu) QTAILQ_NEXT(cpu, node) > +#define CPU_REMOVE(cpu) QTAILQ_REMOVE(&cpus, cpu, node) > #define CPU_FOREACH(cpu) QTAILQ_FOREACH(cpu, &cpus, node) > #define CPU_FOREACH_SAFE(cpu, next_cpu) \ > QTAILQ_FOREACH_SAFE(cpu, &cpus, node, next_cpu) > diff --git a/target-i386/cpu.c b/target-i386/cpu.c > index 4347948..4746814 100644 > --- a/target-i386/cpu.c > +++ b/target-i386/cpu.c > @@ -2983,6 +2983,13 @@ static void x86_cpu_initfn(Object *obj) > } > } > > +static void x86_cpu_finalizefn(Object *obj) > +{ > + CPUState *cs = CPU(obj); > + > + CPU_REMOVE(cs); > +} issue with reliance on cpu_index is not solved completely, There is still a lot of places that use cpu_index and when we start ignore it in x86 CPU, the rest of the places probably would have a broken logic. Please look at that call sites, and if they are fine with it, especially common files shared with other targets. > + > static int64_t x86_cpu_get_arch_id(CPUState *cs) > { > X86CPU *cpu = X86_CPU(cs); > @@ -3095,6 +3102,7 @@ static const TypeInfo x86_cpu_type_info = { > .parent = TYPE_CPU, > .instance_size = sizeof(X86CPU), > .instance_init = x86_cpu_initfn, > + .instance_finalize = x86_cpu_finalizefn, > .abstract = true, > .class_size = sizeof(X86CPUClass), > .class_init = x86_cpu_common_class_init,