qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kurz <groug@kaod.org>
To: Igor Mammedov <imammedo@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>,
	qemu-ppc@nongnu.org, qemu-devel@nongnu.org,
	Bharata B Rao <bharata@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [Qemu-ppc] [PATCH] spapr: move registration of "host" CPU core type to machine code
Date: Wed, 27 Sep 2017 17:32:32 +0200	[thread overview]
Message-ID: <20170927173232.3a305c99@bahia.lan> (raw)
In-Reply-To: <20170927141956.1bd6a3bd@nial.brq.redhat.com>

On Wed, 27 Sep 2017 14:19:56 +0200
Igor Mammedov <imammedo@redhat.com> wrote:

> On Mon, 25 Sep 2017 23:47:30 +0200
> Greg Kurz <groug@kaod.org> wrote:
> 
> > On Mon, 25 Sep 2017 17:48:57 +0200
> > Greg Kurz <groug@kaod.org> wrote:
> >   
> > > On Mon, 25 Sep 2017 15:41:34 +0200
> > > Igor Mammedov <imammedo@redhat.com> wrote:
> > >     
> > > > On Mon, 25 Sep 2017 11:47:33 +0200
> > > > Greg Kurz <groug@kaod.org> wrote:
> > > >       
> > > > > The CPU core abstraction belongs to the machine code. This also gets
> > > > > rid of some code duplication.
> > > > > 
> > > > > Signed-off-by: Greg Kurz <groug@kaod.org>
> > > > > ---
> > > > > 
> > > > > hw/ppc/spapr_cpu_core.h is also included elsewhere in target/ppc/kvm.c
> > > > > but this is already handled by the following cleanup patch:
> > > > > 
> > > > > https://patchwork.ozlabs.org/patch/817598/
> > > > > ---
> > > > >  hw/ppc/spapr.c                  |    4 ++++
> > > > >  hw/ppc/spapr_cpu_core.c         |   34 ++++++++++++++++++++++------------
> > > > >  include/hw/ppc/spapr_cpu_core.h |    2 +-
> > > > >  target/ppc/kvm.c                |   12 ------------
> > > > >  4 files changed, 27 insertions(+), 25 deletions(-)
> > > > > 
> > > > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> > > > > index 0ce3ec87ac59..e82c8532ffb0 100644
> > > > > --- a/hw/ppc/spapr.c
> > > > > +++ b/hw/ppc/spapr.c
> > > > > @@ -2349,6 +2349,10 @@ static void ppc_spapr_init(MachineState *machine)
> > > > >      }
> > > > >  
> > > > >      /* init CPUs */
> > > > > +    if (kvm_enabled()) {
> > > > > +        spapr_cpu_core_register_host_type();
> > > > > +    }        
> > > > why don't we create it statically in hw/ppc/spapr_cpu_core.c
> > > > like it's done in x86, i.e.
> > > > 
> > > >   static void x86_cpu_register_types(void)                                         
> > > >   {                                                                                
> > > >   ...                              
> > > >   #ifdef CONFIG_KVM                                                                
> > > >       type_register_static(&host_x86_cpu_type_info);                               
> > > >   #endif                                                                           
> > > >   } 
> > > >   type_init(x86_cpu_register_types)
> > > > 
> > > > and do the same for host CPU as well?
> > > >       
> > > 
> > > Hi Igor,
> > > 
> > > Not sure yet why we use dynamic types, but I'd be glad to dig a bit more.    
> > 
> > So the problem is that it was decided to make the host CPU class a
> > subclass of the host's CPU model, and this requires all the CPU model
> > classes to be registered beforehand.
> > 
> > commit 5ba4576b858c0d6056f59abb7e17a2b63f7905f3
> > Author: Andreas Färber <afaerber@suse.de>
> > Date:   Sat Feb 23 11:22:12 2013 +0000
> > 
> >     target-ppc: Make host CPU a subclass of the host's CPU model
> >     
> >     This avoids assigning individual class fields and contributors
> >     forgetting to add field assignments in KVM-only code.
> >     
> >     ppc_cpu_class_find_by_pvr() requires the CPU model classes to be
> >     registered, so defer host CPU type registration to kvm_arch_init().
> >     
> >     Only register the host CPU type if there is a class with matching PVR.
> >     This lets us drop error handling from instance_init.
> >     
> >     Signed-off-by: Andreas Färber <afaerber@suse.de>
> >     Signed-off-by: Alexander Graf <agraf@suse.de>
> > 
> > I can't think of an alternate way to do this. Any suggestion ?  
> I don't see from this commit a reason why it can't be done in cpu-models.c
> dependencies here are
>   mfpvr() - which probably should work without KVM

Correct.

>   ppc_cpu_class_by_pvr() - should work fine if 'host' type is being
>                            registered as the last among the other CPU types

We have:

ppc_cpu_class_by_pvr()
 object_class_get_list()
  object_class_foreach()
   object_class_foreach_tramp()
    type_initialize()
     type_get_parent()

type_initialize() recursively initializes all parent types, and
type_get_parent() aborts if the parent type isn't registered yet,
which may happen as long as all type_init() functions haven't been
called => ppc_cpu_class_by_pvr() cannot be safely called from a
type_init() function.

--
Greg

  reply	other threads:[~2017-09-27 15:33 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-25  9:47 [Qemu-devel] [PATCH] spapr: move registration of "host" CPU core type to machine code Greg Kurz
2017-09-25 13:41 ` Igor Mammedov
2017-09-25 15:48   ` Greg Kurz
2017-09-25 21:47     ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2017-09-27 12:19       ` Igor Mammedov
2017-09-27 15:32         ` Greg Kurz [this message]
2017-09-29  6:41           ` Igor Mammedov
2017-09-29  7:25             ` Greg Kurz
2017-09-26  2:57 ` [Qemu-devel] " David Gibson
2017-09-26  7:19   ` Greg Kurz
2017-09-26  8:29     ` Igor Mammedov
2017-09-27  6:39       ` David Gibson
2017-09-27 12:11         ` Igor Mammedov
2017-09-28  4:01           ` David Gibson
2017-09-27  6:21     ` David Gibson
2017-09-27  8:13       ` Igor Mammedov
2017-09-27 11:49       ` [Qemu-devel] [RFC] ppc: define spapr core types statically Igor Mammedov
2017-09-27 16:18         ` Greg Kurz
2017-09-28  4:22           ` David Gibson
2017-09-29  6:44           ` Igor Mammedov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170927173232.3a305c99@bahia.lan \
    --to=groug@kaod.org \
    --cc=bharata@linux.vnet.ibm.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=imammedo@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).