qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	qemu-devel@nongnu.org, "Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH 20/27] target-i386: do not call x86_cpu_realize() on cpu_x86_init()
Date: Wed, 31 Oct 2012 17:32:33 +0100	[thread overview]
Message-ID: <20121031173233.072f8b45@nial.usersys.redhat.com> (raw)
In-Reply-To: <1351101001-14589-21-git-send-email-ehabkost@redhat.com>

On Wed, 24 Oct 2012 15:49:54 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:

> The PC code will need to run additional steps when initializing the CPU
> object, before x86_cpu_realize(). So, make cpu_x86_init() not call
Killing cpu_x86_init() altogether will make future re-factoring even easier.
For present its code could be duplicated in cpu_init() and pc.c,

and with cpu subclasses cpu_init () would be reduced to
  cpu = object_new(X86CPU.QEMUxx);
  cpu.realize();
and pc_cpus_init()
  cpu = object_new(X86CPU.QEMUxx);
  make cpu a child of /machine ();
  apply custom properties ();
  cpu.realize();

I don't see any benefits in keeping cpu_x86_init() around and if we start
touching it then just lets get rid of it in one step.

> x86_cpu_realize(), and add two x86_cpu_realize() calls:
> 
> - One on cpu_init(), that is called only by *-user
> - One on pc_cpu_init(), that will include the more advanced PC CPU
>   initialization steps
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/pc.c              | 12 +++++++++++-
>  target-i386/cpu.h    | 14 ++++++++++++++
>  target-i386/helper.c | 11 ++++-------
>  3 files changed, 29 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/pc.c b/hw/pc.c
> index 85eab04..c209d3d 100644
> --- a/hw/pc.c
> +++ b/hw/pc.c
> @@ -861,10 +861,20 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int
> level) 
>  static void pc_cpu_init(PCInitArgs *args, int cpu_index)
>  {
> -    if (!cpu_x86_init(args->qemu_args->cpu_model)) {
> +    Error *err = NULL;
> +    X86CPU *cpu;
> +
> +    cpu = cpu_x86_init(args->qemu_args->cpu_model);
> +    if (!cpu) {
>          fprintf(stderr, "Unable to find x86 CPU definition\n");
>          exit(1);
>      }
> +
> +    x86_cpu_realize(OBJECT(cpu), &err);
> +    if (err) {
> +        error_report("pc_cpu_init: %s\n", error_get_pretty(err));
> +        exit(1);
> +    }
>  }
>  
>  void pc_cpus_init(PCInitArgs *args)
> diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> index 871c270..6853b17 100644
> --- a/target-i386/cpu.h
> +++ b/target-i386/cpu.h
> @@ -21,6 +21,7 @@
>  
>  #include "config.h"
>  #include "qemu-common.h"
> +#include "qemu-error.h"
>  
>  #ifdef TARGET_X86_64
>  #define TARGET_LONG_BITS 64
> @@ -1008,12 +1009,25 @@ uint64_t cpu_get_tsc(CPUX86State *env);
>  #define TARGET_VIRT_ADDR_SPACE_BITS 32
>  #endif
>  
> +/* Helper for simple CPU initialization (for target-independent code)
> + *
> + * Note that the PC code doesn't use this function, as it does additional
> + * initialization steps between cpu_x86_init() and cpu_x86_realize() is
> called.
> + */
>  static inline CPUX86State *cpu_init(const char *cpu_model)
>  {
> +    Error *err = NULL;
>      X86CPU *cpu = cpu_x86_init(cpu_model);
>      if (cpu == NULL) {
>          return NULL;
>      }
> +
> +    x86_cpu_realize(OBJECT(cpu), &err);
> +    if (err) {
> +        error_report("cpu_init: %s\n", error_get_pretty(err));
> +        return NULL;
> +    }
> +
>      return &cpu->env;
>  }
>  
> diff --git a/target-i386/helper.c b/target-i386/helper.c
> index 1e5f61f..87a9221 100644
> --- a/target-i386/helper.c
> +++ b/target-i386/helper.c
> @@ -1240,11 +1240,14 @@ int cpu_x86_get_descr_debug(CPUX86State *env,
> unsigned int selector, return 1;
>  }
>  
> +/* Initialize X86CPU object
> + *
> + * Callers must eventually call x86_cpu_realize(), to finish
> initialization.
> + */
>  X86CPU *cpu_x86_init(const char *cpu_model)
>  {
>      X86CPU *cpu;
>      CPUX86State *env;
> -    Error *err = NULL;
>  
>      cpu = X86_CPU(object_new(TYPE_X86_CPU));
>      env = &cpu->env;
> @@ -1255,12 +1258,6 @@ X86CPU *cpu_x86_init(const char *cpu_model)
>          return NULL;
>      }
>  
> -    x86_cpu_realize(OBJECT(cpu), &err);
> -    if (err) {
> -        error_report("cpu_x86_init: %s\n", error_get_pretty(err));
> -        return NULL;
> -    }
> -
>      return cpu;
>  }
>  

  reply	other threads:[~2012-10-31 16:32 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-24 17:49 [Qemu-devel] Subject: [PATCH 00/27] Fix APIC-ID-based CPU topology, take 3 Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 01/27] move I/O-related definitions from qemu-common.h to a new header (qemu-stdio.h) Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 02/27] cpus.h: include qemu-stdio.h Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 03/27] hw/apic.c: rename bit functions to not conflict with bitops.h Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 04/27] target-i386: initialize APIC at CPU level Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 05/27] kvm: create kvm_arch_vcpu_id() function Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 06/27] target-i386: kvm: set vcpu_id to APIC ID instead of CPU index Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 07/27] pc: pc_init1(): always use rom_memory on pc_memory_init() call Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 08/27] pc: pc_init1(): remove MemoryRegion arguments Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 09/27] pc: pc_init1(): get QEMUMachineInitArgs argument Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 10/27] pc: create PCInitArgs struct Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 11/27] pc: add PC_DEFAULT_CPU_MODEL #define Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 12/27] pc: add PCInitArgs parameter to pc_cpus_init() Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 13/27] pc: pass PCInitArgs struct to pc_memory_init() Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 14/27] pc: use FWCfgState* instead of void* for fw_cfg data Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 15/27] pc: rename bochs_bios_init() to pc_bios_init() Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 16/27] pc: pass PCInitArgs struct " Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 17/27] xen_machine_pv: use cpu_init() instead of cpu_x86_init() Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 18/27] pc: isolate the code that create CPUs Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 19/27] cpu_x86_init: check for x86_cpu_realize() errors Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 20/27] target-i386: do not call x86_cpu_realize() on cpu_x86_init() Eduardo Habkost
2012-10-31 16:32   ` Igor Mammedov [this message]
2012-10-31 16:43     ` Andreas Färber
2012-10-31 17:10       ` Eduardo Habkost
2012-11-01 12:53       ` Igor Mammedov
2012-10-31 17:01     ` Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 21/27] fw_cfg: remove FW_CFG_MAX_CPUS from fw_cfg_init() Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 22/27] pc: set CPU APIC ID explicitly Eduardo Habkost
2012-11-01 14:04   ` Igor Mammedov
2012-11-01 14:30     ` Eduardo Habkost
2012-11-01 14:50       ` Igor Mammedov
2012-10-24 17:49 ` [Qemu-devel] [PATCH 23/27] pc: set fw_cfg data based on APIC ID calculation Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 24/27] tests: support target-specific unit tests Eduardo Habkost
2012-10-24 17:49 ` [Qemu-devel] [PATCH 25/27] target-i386: topology & APIC ID utility functions Eduardo Habkost
2012-10-24 17:50 ` [Qemu-devel] [PATCH 26/27] pc: create separate init function for pc-1.3 Eduardo Habkost
2012-10-24 18:12   ` Michael S. Tsirkin
2012-10-25 13:23     ` Eduardo Habkost
2012-10-24 17:50 ` [Qemu-devel] [PATCH 27/27] pc: generate APIC IDs according to CPU topology Eduardo Habkost
2012-11-01 14:46   ` Igor Mammedov
2012-11-01 15:16     ` Eduardo Habkost

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=20121031173233.072f8b45@nial.usersys.redhat.com \
    --to=imammedo@redhat.com \
    --cc=afaerber@suse.de \
    --cc=ehabkost@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@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).