Re: [Qemu-devel] [PATCH v2 02/20] target-i386: move back cpu_exec_init() to init

2016-10-14 Thread Eduardo Habkost
On Fri, Oct 14, 2016 at 04:33:07PM +0200, Igor Mammedov wrote:
> On Fri, 14 Oct 2016 10:48:58 -0300
> Eduardo Habkost  wrote:
> 
> > On Fri, Oct 14, 2016 at 03:34:17PM +0200, Laurent Vivier wrote:
> > > On 14/10/2016 15:33, Eduardo Habkost wrote:  
> > > > On Thu, Oct 13, 2016 at 06:24:44PM +0200, Laurent Vivier wrote:  
> > > >> We have now the cpu_exec_realize() in realize,
> > > >> so the init part must be in init.
> > > >>
> > > >> I've removed the cannot_destroy_with_object_finalize_yet field as
> > > >> unsafe references have been moved to cpu_exec_realize().
> > > >> (tested with QOM command provided by commit 4c315c27 with
> > > >> "athlon-x86_64-cpu")
> > > >>
> > > >> CC: Eduardo Habkost 
> > > >> Signed-off-by: Laurent Vivier   
> > > > 
> > > > Resending the question I asked in my reply to v1:
> > > > 
> > > > Instead of creating requiring each subclass to manually call
> > > > cpu_exec_init()) on instance_init, why don't we move parts of
> > > > cpu_exec_init()/cpu_exec_realize() code to cpu_common_initfn()?
> > > > (TYPE_CPU's instance_init)
> > > > 
> > > > (And if there's any code that needs to be run after the
> > > > subclasses instance_init functions, we can just add a
> > > > instance_post_init function to TYPE_CPU).
> > > >   
> > > 
> > > It's done in PATCH 20/20.
> > > 
> > > Is that what you want?  
> > 
> > Yes (except that I would have inlined the the cpu_exec_init()
> > code inside cpu_common_init()).
> > 
> > I think I expected this to be done in a single step, that
> > wouldn't require touching code for all architectures three times.
> > Something like:
> > 
> > 1) Move cpu->as, cpu->num_ases, cpu->thread_id, cpu->memory
> >initialization, and "memory" property registration from
> >cpu_exec_init() to cpu_common_init() (no architecture code
> >touched).
> > 2) (optional) Rename cpu_exec_init() to cpu_exec_realize() (only
> >trivial changes in architecture code)
> I'd do all of it in 1 step
>   - split cpu_exec_init on init/realize parts
> (comment in cpu_exec_init says that qom/cpu.c can't be used for
>  "memory" property)
>   - call cpu_exec_init() from cpu_common_init()
>   - s/cpu_exec_init/cpu_exec_realize/ in target-*

Personally, I don't mind if it is done in 1 or 2 steps. I would
just like to avoid changing architecture code 3 times.

In addition to make review easier, it would make the decision to
merge it easier for the maintainer who's going to do it (no need
to wait for Acked-bys/Reviewed-bys from multiple architecture
maintainers).

-- 
Eduardo



Re: [Qemu-devel] [PATCH v2 02/20] target-i386: move back cpu_exec_init() to init

2016-10-14 Thread Igor Mammedov
On Fri, 14 Oct 2016 10:48:58 -0300
Eduardo Habkost  wrote:

> On Fri, Oct 14, 2016 at 03:34:17PM +0200, Laurent Vivier wrote:
> > On 14/10/2016 15:33, Eduardo Habkost wrote:  
> > > On Thu, Oct 13, 2016 at 06:24:44PM +0200, Laurent Vivier wrote:  
> > >> We have now the cpu_exec_realize() in realize,
> > >> so the init part must be in init.
> > >>
> > >> I've removed the cannot_destroy_with_object_finalize_yet field as
> > >> unsafe references have been moved to cpu_exec_realize().
> > >> (tested with QOM command provided by commit 4c315c27 with
> > >> "athlon-x86_64-cpu")
> > >>
> > >> CC: Eduardo Habkost 
> > >> Signed-off-by: Laurent Vivier   
> > > 
> > > Resending the question I asked in my reply to v1:
> > > 
> > > Instead of creating requiring each subclass to manually call
> > > cpu_exec_init()) on instance_init, why don't we move parts of
> > > cpu_exec_init()/cpu_exec_realize() code to cpu_common_initfn()?
> > > (TYPE_CPU's instance_init)
> > > 
> > > (And if there's any code that needs to be run after the
> > > subclasses instance_init functions, we can just add a
> > > instance_post_init function to TYPE_CPU).
> > >   
> > 
> > It's done in PATCH 20/20.
> > 
> > Is that what you want?  
> 
> Yes (except that I would have inlined the the cpu_exec_init()
> code inside cpu_common_init()).
> 
> I think I expected this to be done in a single step, that
> wouldn't require touching code for all architectures three times.
> Something like:
> 
> 1) Move cpu->as, cpu->num_ases, cpu->thread_id, cpu->memory
>initialization, and "memory" property registration from
>cpu_exec_init() to cpu_common_init() (no architecture code
>touched).
> 2) (optional) Rename cpu_exec_init() to cpu_exec_realize() (only
>trivial changes in architecture code)
I'd do all of it in 1 step
  - split cpu_exec_init on init/realize parts
(comment in cpu_exec_init says that qom/cpu.c can't be used for
 "memory" property)
  - call cpu_exec_init() from cpu_common_init()
  - s/cpu_exec_init/cpu_exec_realize/ in target-*

Follow up patches
  2) 1 patch, could move parts of split cpu_exec_init() to cpu_common_init()
  if that makes sense.
  3) 1 patch, could move cpu_exec_realize() into per target *_realizefn()
  it would be not small patch but still trivial
  4) 1 patch, do similar (#3) thing for unrealize
Perhaps #3,4 could be done in a more generic way in qom/cpu.c
but I don't have a good idea how to do it.



Re: [Qemu-devel] [PATCH v2 02/20] target-i386: move back cpu_exec_init() to init

2016-10-14 Thread Eduardo Habkost
On Fri, Oct 14, 2016 at 04:12:20PM +0200, Laurent Vivier wrote:
> 
> 
> On 14/10/2016 15:48, Eduardo Habkost wrote:
> > On Fri, Oct 14, 2016 at 03:34:17PM +0200, Laurent Vivier wrote:
> >> On 14/10/2016 15:33, Eduardo Habkost wrote:
> >>> On Thu, Oct 13, 2016 at 06:24:44PM +0200, Laurent Vivier wrote:
>  We have now the cpu_exec_realize() in realize,
>  so the init part must be in init.
> 
>  I've removed the cannot_destroy_with_object_finalize_yet field as
>  unsafe references have been moved to cpu_exec_realize().
>  (tested with QOM command provided by commit 4c315c27 with
>  "athlon-x86_64-cpu")
> 
>  CC: Eduardo Habkost 
>  Signed-off-by: Laurent Vivier 
> >>>
> >>> Resending the question I asked in my reply to v1:
> >>>
> >>> Instead of creating requiring each subclass to manually call
> >>> cpu_exec_init()) on instance_init, why don't we move parts of
> >>> cpu_exec_init()/cpu_exec_realize() code to cpu_common_initfn()?
> >>> (TYPE_CPU's instance_init)
> >>>
> >>> (And if there's any code that needs to be run after the
> >>> subclasses instance_init functions, we can just add a
> >>> instance_post_init function to TYPE_CPU).
> >>>
> >>
> >> It's done in PATCH 20/20.
> >>
> >> Is that what you want?
> > 
> > Yes (except that I would have inlined the the cpu_exec_init()
> > code inside cpu_common_init()).
> > 
> > I think I expected this to be done in a single step, that
> > wouldn't require touching code for all architectures three times.
> > Something like:
> 
> Well, I've added several steps to help to review and break nothing.

To me, it made review harder. Architecture maintainers have to
review 3 different patches that touch their code, instead of a
single one.

Anyway, I would still give my Reviewed-by line for the i386 part,
if you believe it's better to do it this way.

> 
> > 1) Move cpu->as, cpu->num_ases, cpu->thread_id, cpu->memory
> >initialization, and "memory" property registration from
> >cpu_exec_init() to cpu_common_init() (no architecture code
> >touched).
> 
> system_memory (for the "memory" property) is declared as static in
> exec.c, so we can't move it to cpu_common_init().

In this case we can't inline it, that's true. But it still
doesn't require touching each architecture 3 times (we could just
create a cpu_exec_instance_init() function in exec.c and call it
from cpu_common_init()).

(Or we could move system_memory to MachineState, but that could
be done in a follow-up patch).

-- 
Eduardo



Re: [Qemu-devel] [PATCH v2 02/20] target-i386: move back cpu_exec_init() to init

2016-10-14 Thread Laurent Vivier


On 14/10/2016 15:48, Eduardo Habkost wrote:
> On Fri, Oct 14, 2016 at 03:34:17PM +0200, Laurent Vivier wrote:
>> On 14/10/2016 15:33, Eduardo Habkost wrote:
>>> On Thu, Oct 13, 2016 at 06:24:44PM +0200, Laurent Vivier wrote:
 We have now the cpu_exec_realize() in realize,
 so the init part must be in init.

 I've removed the cannot_destroy_with_object_finalize_yet field as
 unsafe references have been moved to cpu_exec_realize().
 (tested with QOM command provided by commit 4c315c27 with
 "athlon-x86_64-cpu")

 CC: Eduardo Habkost 
 Signed-off-by: Laurent Vivier 
>>>
>>> Resending the question I asked in my reply to v1:
>>>
>>> Instead of creating requiring each subclass to manually call
>>> cpu_exec_init()) on instance_init, why don't we move parts of
>>> cpu_exec_init()/cpu_exec_realize() code to cpu_common_initfn()?
>>> (TYPE_CPU's instance_init)
>>>
>>> (And if there's any code that needs to be run after the
>>> subclasses instance_init functions, we can just add a
>>> instance_post_init function to TYPE_CPU).
>>>
>>
>> It's done in PATCH 20/20.
>>
>> Is that what you want?
> 
> Yes (except that I would have inlined the the cpu_exec_init()
> code inside cpu_common_init()).
> 
> I think I expected this to be done in a single step, that
> wouldn't require touching code for all architectures three times.
> Something like:

Well, I've added several steps to help to review and break nothing.

> 1) Move cpu->as, cpu->num_ases, cpu->thread_id, cpu->memory
>initialization, and "memory" property registration from
>cpu_exec_init() to cpu_common_init() (no architecture code
>touched).

system_memory (for the "memory" property) is declared as static in
exec.c, so we can't move it to cpu_common_init().

Laurent




Re: [Qemu-devel] [PATCH v2 02/20] target-i386: move back cpu_exec_init() to init

2016-10-14 Thread Eduardo Habkost
On Fri, Oct 14, 2016 at 03:34:17PM +0200, Laurent Vivier wrote:
> On 14/10/2016 15:33, Eduardo Habkost wrote:
> > On Thu, Oct 13, 2016 at 06:24:44PM +0200, Laurent Vivier wrote:
> >> We have now the cpu_exec_realize() in realize,
> >> so the init part must be in init.
> >>
> >> I've removed the cannot_destroy_with_object_finalize_yet field as
> >> unsafe references have been moved to cpu_exec_realize().
> >> (tested with QOM command provided by commit 4c315c27 with
> >> "athlon-x86_64-cpu")
> >>
> >> CC: Eduardo Habkost 
> >> Signed-off-by: Laurent Vivier 
> > 
> > Resending the question I asked in my reply to v1:
> > 
> > Instead of creating requiring each subclass to manually call
> > cpu_exec_init()) on instance_init, why don't we move parts of
> > cpu_exec_init()/cpu_exec_realize() code to cpu_common_initfn()?
> > (TYPE_CPU's instance_init)
> > 
> > (And if there's any code that needs to be run after the
> > subclasses instance_init functions, we can just add a
> > instance_post_init function to TYPE_CPU).
> > 
> 
> It's done in PATCH 20/20.
> 
> Is that what you want?

Yes (except that I would have inlined the the cpu_exec_init()
code inside cpu_common_init()).

I think I expected this to be done in a single step, that
wouldn't require touching code for all architectures three times.
Something like:

1) Move cpu->as, cpu->num_ases, cpu->thread_id, cpu->memory
   initialization, and "memory" property registration from
   cpu_exec_init() to cpu_common_init() (no architecture code
   touched).
2) (optional) Rename cpu_exec_init() to cpu_exec_realize() (only
   trivial changes in architecture code)

-- 
Eduardo



Re: [Qemu-devel] [PATCH v2 02/20] target-i386: move back cpu_exec_init() to init

2016-10-14 Thread Eduardo Habkost
On Thu, Oct 13, 2016 at 06:24:44PM +0200, Laurent Vivier wrote:
> We have now the cpu_exec_realize() in realize,
> so the init part must be in init.
> 
> I've removed the cannot_destroy_with_object_finalize_yet field as
> unsafe references have been moved to cpu_exec_realize().
> (tested with QOM command provided by commit 4c315c27 with
> "athlon-x86_64-cpu")
> 
> CC: Eduardo Habkost 
> Signed-off-by: Laurent Vivier 

Resending the question I asked in my reply to v1:

Instead of creating requiring each subclass to manually call
cpu_exec_init()) on instance_init, why don't we move parts of
cpu_exec_init()/cpu_exec_realize() code to cpu_common_initfn()?
(TYPE_CPU's instance_init)

(And if there's any code that needs to be run after the
subclasses instance_init functions, we can just add a
instance_post_init function to TYPE_CPU).

-- 
Eduardo



Re: [Qemu-devel] [PATCH v2 02/20] target-i386: move back cpu_exec_init() to init

2016-10-14 Thread Laurent Vivier


On 14/10/2016 15:33, Eduardo Habkost wrote:
> On Thu, Oct 13, 2016 at 06:24:44PM +0200, Laurent Vivier wrote:
>> We have now the cpu_exec_realize() in realize,
>> so the init part must be in init.
>>
>> I've removed the cannot_destroy_with_object_finalize_yet field as
>> unsafe references have been moved to cpu_exec_realize().
>> (tested with QOM command provided by commit 4c315c27 with
>> "athlon-x86_64-cpu")
>>
>> CC: Eduardo Habkost 
>> Signed-off-by: Laurent Vivier 
> 
> Resending the question I asked in my reply to v1:
> 
> Instead of creating requiring each subclass to manually call
> cpu_exec_init()) on instance_init, why don't we move parts of
> cpu_exec_init()/cpu_exec_realize() code to cpu_common_initfn()?
> (TYPE_CPU's instance_init)
> 
> (And if there's any code that needs to be run after the
> subclasses instance_init functions, we can just add a
> instance_post_init function to TYPE_CPU).
> 

It's done in PATCH 20/20.

Is that what you want?

Thanks,
Laurent



[Qemu-devel] [PATCH v2 02/20] target-i386: move back cpu_exec_init() to init

2016-10-13 Thread Laurent Vivier
We have now the cpu_exec_realize() in realize,
so the init part must be in init.

I've removed the cannot_destroy_with_object_finalize_yet field as
unsafe references have been moved to cpu_exec_realize().
(tested with QOM command provided by commit 4c315c27 with
"athlon-x86_64-cpu")

CC: Eduardo Habkost 
Signed-off-by: Laurent Vivier 
---
 target-i386/cpu.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index b977130..4741dd6 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -3158,8 +3158,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Error 
**errp)
 cpu->phys_bits = 32;
 }
 }
-cpu_exec_init(cs);
-cpu_exec_realize(cs, &error_abort);
+cpu_exec_realize(cs, &local_err);
+if (local_err != NULL) {
+error_propagate(errp, local_err);
+return;
+}
 
 if (tcg_enabled()) {
 tcg_x86_init();
@@ -3365,6 +3368,7 @@ static void x86_cpu_initfn(Object *obj)
 FeatureWord w;
 
 cs->env_ptr = env;
+cpu_exec_init(cs);
 
 object_property_add(obj, "family", "int",
 x86_cpuid_version_get_family,
@@ -3538,11 +3542,6 @@ static void x86_cpu_common_class_init(ObjectClass *oc, 
void *data)
 cc->cpu_exec_exit = x86_cpu_exec_exit;
 
 dc->cannot_instantiate_with_device_add_yet = false;
-/*
- * Reason: x86_cpu_initfn() calls cpu_exec_init(), which saves the
- * object in cpus -> dangling pointer after final object_unref().
- */
-dc->cannot_destroy_with_object_finalize_yet = true;
 }
 
 static const TypeInfo x86_cpu_type_info = {
-- 
2.7.4