[Qemu-devel] [PATCH v2] spapr_cpu_core: cleaning up qdev_get_machine() calls

Greg Kurz posted 1 patch 8 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/150516425752.1593.1536226898929735667.stgit@bahia.lan
Test checkpatch passed
Test docker passed
Test s390x passed
There is a newer version of this series
hw/ppc/spapr_cpu_core.c |    8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
[Qemu-devel] [PATCH v2] spapr_cpu_core: cleaning up qdev_get_machine() calls
Posted by Greg Kurz 8 years, 1 month ago
This patch removes the qdev_get_machine() calls that are made
in spapr_cpu_core.c in situations where we can get an existing
pointer for the MachineState by either passing it as an argument
to the function or by using other already available pointers.

Credits to Daniel Henrique Barboza for the idea and the changelog
text.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
v2: - fixed typo in spapr_cpu_reset()
---
 hw/ppc/spapr_cpu_core.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index dc9df0d393d1..0f32532abe99 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -73,8 +73,8 @@ void spapr_cpu_parse_features(sPAPRMachineState *spapr)
 
 static void spapr_cpu_reset(void *opaque)
 {
-    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
     PowerPCCPU *cpu = opaque;
+    sPAPRMachineState *spapr = SPAPR_MACHINE(cpu->vhyp);
     CPUState *cs = CPU(cpu);
     CPUPPCState *env = &cpu->env;
 
@@ -162,10 +162,10 @@ static void spapr_cpu_core_unrealizefn(DeviceState *dev, Error **errp)
     g_free(sc->threads);
 }
 
-static void spapr_cpu_core_realize_child(Object *child, Error **errp)
+static void spapr_cpu_core_realize_child(Object *child,
+                                         sPAPRMachineState *spapr, Error **errp)
 {
     Error *local_err = NULL;
-    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
     CPUState *cs = CPU(child);
     PowerPCCPU *cpu = POWERPC_CPU(cs);
     Object *obj;
@@ -254,7 +254,7 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
     for (j = 0; j < cc->nr_threads; j++) {
         obj = sc->threads + j * size;
 
-        spapr_cpu_core_realize_child(obj, &local_err);
+        spapr_cpu_core_realize_child(obj, spapr, &local_err);
         if (local_err) {
             goto err;
         }


Re: [Qemu-devel] [PATCH v2] spapr_cpu_core: cleaning up qdev_get_machine() calls
Posted by David Gibson 8 years, 1 month ago
On Mon, Sep 11, 2017 at 11:10:57PM +0200, Greg Kurz wrote:
> This patch removes the qdev_get_machine() calls that are made
> in spapr_cpu_core.c in situations where we can get an existing
> pointer for the MachineState by either passing it as an argument
> to the function or by using other already available pointers.
> 
> Credits to Daniel Henrique Barboza for the idea and the changelog
> text.
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
> v2: - fixed typo in spapr_cpu_reset()

Applied to ppc-for-2.11.

> ---
>  hw/ppc/spapr_cpu_core.c |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> index dc9df0d393d1..0f32532abe99 100644
> --- a/hw/ppc/spapr_cpu_core.c
> +++ b/hw/ppc/spapr_cpu_core.c
> @@ -73,8 +73,8 @@ void spapr_cpu_parse_features(sPAPRMachineState *spapr)
>  
>  static void spapr_cpu_reset(void *opaque)
>  {
> -    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
>      PowerPCCPU *cpu = opaque;
> +    sPAPRMachineState *spapr = SPAPR_MACHINE(cpu->vhyp);
>      CPUState *cs = CPU(cpu);
>      CPUPPCState *env = &cpu->env;
>  
> @@ -162,10 +162,10 @@ static void spapr_cpu_core_unrealizefn(DeviceState *dev, Error **errp)
>      g_free(sc->threads);
>  }
>  
> -static void spapr_cpu_core_realize_child(Object *child, Error **errp)
> +static void spapr_cpu_core_realize_child(Object *child,
> +                                         sPAPRMachineState *spapr, Error **errp)
>  {
>      Error *local_err = NULL;
> -    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
>      CPUState *cs = CPU(child);
>      PowerPCCPU *cpu = POWERPC_CPU(cs);
>      Object *obj;
> @@ -254,7 +254,7 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
>      for (j = 0; j < cc->nr_threads; j++) {
>          obj = sc->threads + j * size;
>  
> -        spapr_cpu_core_realize_child(obj, &local_err);
> +        spapr_cpu_core_realize_child(obj, spapr, &local_err);
>          if (local_err) {
>              goto err;
>          }
> 

-- 
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
Re: [Qemu-devel] [PATCH v2] spapr_cpu_core: cleaning up qdev_get_machine() calls
Posted by David Gibson 8 years, 1 month ago
On Tue, Sep 12, 2017 at 01:27:53PM +1000, David Gibson wrote:
> On Mon, Sep 11, 2017 at 11:10:57PM +0200, Greg Kurz wrote:
> > This patch removes the qdev_get_machine() calls that are made
> > in spapr_cpu_core.c in situations where we can get an existing
> > pointer for the MachineState by either passing it as an argument
> > to the function or by using other already available pointers.
> > 
> > Credits to Daniel Henrique Barboza for the idea and the changelog
> > text.
> > 
> > Signed-off-by: Greg Kurz <groug@kaod.org>
> > ---
> > v2: - fixed typo in spapr_cpu_reset()
> 
> Applied to ppc-for-2.11.

Wait... no.  The second hunk is fine, but the first isn't.

> 
> > ---
> >  hw/ppc/spapr_cpu_core.c |    8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> > index dc9df0d393d1..0f32532abe99 100644
> > --- a/hw/ppc/spapr_cpu_core.c
> > +++ b/hw/ppc/spapr_cpu_core.c
> > @@ -73,8 +73,8 @@ void spapr_cpu_parse_features(sPAPRMachineState *spapr)
> >  
> >  static void spapr_cpu_reset(void *opaque)
> >  {
> > -    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
> >      PowerPCCPU *cpu = opaque;
> > +    sPAPRMachineState *spapr = SPAPR_MACHINE(cpu->vhyp);

Although we prefer to avoid the global when we can, it's preferable to
breaking abstraction by maching the machine reach into the cpu
internals here.

Arguably, instead of having this special machine-registered cpu reset
function we should instead have a hook in vhyp which is called by the
cpu core's reset function, but that would be a different change.

> >      CPUState *cs = CPU(cpu);
> >      CPUPPCState *env = &cpu->env;
> >  
> > @@ -162,10 +162,10 @@ static void spapr_cpu_core_unrealizefn(DeviceState *dev, Error **errp)
> >      g_free(sc->threads);
> >  }
> >  
> > -static void spapr_cpu_core_realize_child(Object *child, Error **errp)
> > +static void spapr_cpu_core_realize_child(Object *child,
> > +                                         sPAPRMachineState *spapr, Error **errp)
> >  {
> >      Error *local_err = NULL;
> > -    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
> >      CPUState *cs = CPU(child);
> >      PowerPCCPU *cpu = POWERPC_CPU(cs);
> >      Object *obj;
> > @@ -254,7 +254,7 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
> >      for (j = 0; j < cc->nr_threads; j++) {
> >          obj = sc->threads + j * size;
> >  
> > -        spapr_cpu_core_realize_child(obj, &local_err);
> > +        spapr_cpu_core_realize_child(obj, spapr, &local_err);
> >          if (local_err) {
> >              goto err;
> >          }
> > 
> 



-- 
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