qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] target-i386: move CPU object creation to cpu.c
@ 2012-12-11  0:30 Eduardo Habkost
  2012-12-11  0:30 ` [Qemu-devel] [PATCH 1/2] " Eduardo Habkost
  2012-12-11  0:30 ` [Qemu-devel] [PATCH 2/2] target-i386: make cpu_x86_create() get Error argument Eduardo Habkost
  0 siblings, 2 replies; 9+ messages in thread
From: Eduardo Habkost @ 2012-12-11  0:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber

This small series moves the X86CPU object creation to the cpu.c code, as the
object creation will depend on the CPU class lookup, that will be done inside
cpu.c.

I expect this to make the x86 CPU subclass work simpler. Maybe it will help
simplify some of the CPU properties work, too.

Eduardo Habkost (2):
  target-i386: move CPU object creation to cpu.c
  target-i386: make cpu_x86_create() get Error argument

 target-i386/cpu.c    | 23 ++++++++++++++++++-----
 target-i386/cpu.h    |  2 +-
 target-i386/helper.c | 26 ++++++++++++++------------
 3 files changed, 33 insertions(+), 18 deletions(-)

-- 
1.7.11.7

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 1/2] target-i386: move CPU object creation to cpu.c
  2012-12-11  0:30 [Qemu-devel] [PATCH 0/2] target-i386: move CPU object creation to cpu.c Eduardo Habkost
@ 2012-12-11  0:30 ` Eduardo Habkost
  2012-12-11 13:21   ` Eduardo Habkost
  2012-12-11 13:33   ` Igor Mammedov
  2012-12-11  0:30 ` [Qemu-devel] [PATCH 2/2] target-i386: make cpu_x86_create() get Error argument Eduardo Habkost
  1 sibling, 2 replies; 9+ messages in thread
From: Eduardo Habkost @ 2012-12-11  0:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber

As we will need to create the CPU object after splitting the CPU model
string (because we're going to use different subclasses for each CPU
model), move the CPU object creation to cpu_x86_register(), and at the
same time rename cpu_x86_register() to cpu_x86_create().

This will also simplify the CPU creation code to a trivial
cpu_x86_create()+cpu_x86_realize() sequence. This will be useful for
code that have to set additional properties before cpu_x86_realize() is
called (e.g. the PC CPU initialization code, that needs to set APIC IDs
depending on the CPU cores/threads topology).

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c    | 17 +++++++++++++----
 target-i386/cpu.h    |  2 +-
 target-i386/helper.c |  9 ++-------
 3 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 7be3ad8..044e2d9 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1488,14 +1488,22 @@ static void filter_features_for_kvm(X86CPU *cpu)
 }
 #endif
 
-int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
+/* Create and initialize a X86CPU object, based on the full CPU model string
+ * (that may include "+feature,-feature,feature=xxx" feature strings)
+ */
+X86CPU *cpu_x86_create(const char *cpu_model)
 {
-    CPUX86State *env = &cpu->env;
+    X86CPU *cpu;
+    CPUX86State *env;
     x86_def_t def1, *def = &def1;
     Error *error = NULL;
     char *name, *features;
     gchar **model_pieces;
 
+    cpu = X86_CPU(object_new(TYPE_X86_CPU));
+    env = &cpu->env;
+    env->cpu_model_str = cpu_model;
+
     memset(def, 0, sizeof(*def));
 
     model_pieces = g_strsplit(cpu_model, ",", 2);
@@ -1572,10 +1580,11 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
     }
 
     g_strfreev(model_pieces);
-    return 0;
+    return cpu;
 error:
+    object_delete(OBJECT(cpu));
     g_strfreev(model_pieces);
-    return -1;
+    return NULL;
 }
 
 #if !defined(CONFIG_USER_ONLY)
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 386c4f6..3ebaae9 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -980,7 +980,7 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo,
 void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
                    uint32_t *eax, uint32_t *ebx,
                    uint32_t *ecx, uint32_t *edx);
-int cpu_x86_register(X86CPU *cpu, const char *cpu_model);
+X86CPU *cpu_x86_create(const char *cpu_model);
 void cpu_clear_apic_feature(CPUX86State *env);
 void host_cpuid(uint32_t function, uint32_t count,
                 uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
diff --git a/target-i386/helper.c b/target-i386/helper.c
index bf206cf..23af4a8 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -1243,15 +1243,10 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector,
 X86CPU *cpu_x86_init(const char *cpu_model)
 {
     X86CPU *cpu;
-    CPUX86State *env;
     Error *error = NULL;
 
-    cpu = X86_CPU(object_new(TYPE_X86_CPU));
-    env = &cpu->env;
-    env->cpu_model_str = cpu_model;
-
-    if (cpu_x86_register(cpu, cpu_model) < 0) {
-        object_delete(OBJECT(cpu));
+    cpu = cpu_x86_create(cpu_model);
+    if (!cpu) {
         return NULL;
     }
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 2/2] target-i386: make cpu_x86_create() get Error argument
  2012-12-11  0:30 [Qemu-devel] [PATCH 0/2] target-i386: move CPU object creation to cpu.c Eduardo Habkost
  2012-12-11  0:30 ` [Qemu-devel] [PATCH 1/2] " Eduardo Habkost
@ 2012-12-11  0:30 ` Eduardo Habkost
  1 sibling, 0 replies; 9+ messages in thread
From: Eduardo Habkost @ 2012-12-11  0:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber

Instead of forcing the caller to guess what went wrong while creating
the CPU object, return error information in a Error argument.

Also, as cpu_x86_create() won't print error messages itself anymore,
change cpu_x86_init() to print any error returned by cpu_x86_create()
or cpu_x86_realize().

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c    |  8 ++++++--
 target-i386/cpu.h    |  2 +-
 target-i386/helper.c | 21 ++++++++++++++-------
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 044e2d9..3276653 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1491,7 +1491,7 @@ static void filter_features_for_kvm(X86CPU *cpu)
 /* Create and initialize a X86CPU object, based on the full CPU model string
  * (that may include "+feature,-feature,feature=xxx" feature strings)
  */
-X86CPU *cpu_x86_create(const char *cpu_model)
+X86CPU *cpu_x86_create(const char *cpu_model, Error **errp)
 {
     X86CPU *cpu;
     CPUX86State *env;
@@ -1508,16 +1508,20 @@ X86CPU *cpu_x86_create(const char *cpu_model)
 
     model_pieces = g_strsplit(cpu_model, ",", 2);
     if (!model_pieces[0]) {
+        error_setg(errp, "invalid CPU model string: %s", cpu_model);
         goto error;
     }
     name = model_pieces[0];
     features = model_pieces[1];
 
     if (cpu_x86_find_by_name(def, name) < 0) {
+        error_setg(errp, "CPU model not found: %s", name);
         goto error;
     }
 
     if (cpu_x86_parse_featurestr(def, features) < 0) {
+        error_setg(errp, "Error parsing feature string: %s",
+                   features ? features : "(none)");
         goto error;
     }
     if (def->vendor1) {
@@ -1574,7 +1578,7 @@ X86CPU *cpu_x86_create(const char *cpu_model)
     }
     object_property_set_str(OBJECT(cpu), def->model_id, "model-id", &error);
     if (error) {
-        fprintf(stderr, "%s\n", error_get_pretty(error));
+        error_propagate(errp, error);
         error_free(error);
         goto error;
     }
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 3ebaae9..8ce9b9f 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -980,7 +980,7 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo,
 void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
                    uint32_t *eax, uint32_t *ebx,
                    uint32_t *ecx, uint32_t *edx);
-X86CPU *cpu_x86_create(const char *cpu_model);
+X86CPU *cpu_x86_create(const char *cpu_model, Error **errp);
 void cpu_clear_apic_feature(CPUX86State *env);
 void host_cpuid(uint32_t function, uint32_t count,
                 uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 23af4a8..dafa666 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -23,6 +23,7 @@
 #include "sysemu.h"
 #include "monitor.h"
 #endif
+#include "qemu-error.h"
 
 //#define DEBUG_MMU
 
@@ -1242,21 +1243,27 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector,
 
 X86CPU *cpu_x86_init(const char *cpu_model)
 {
-    X86CPU *cpu;
+    X86CPU *cpu = NULL;
     Error *error = NULL;
 
-    cpu = cpu_x86_create(cpu_model);
-    if (!cpu) {
-        return NULL;
+    cpu = cpu_x86_create(cpu_model, &error);
+    if (error) {
+        goto error;
     }
 
     x86_cpu_realize(OBJECT(cpu), &error);
     if (error) {
-        error_free(error);
-        object_delete(OBJECT(cpu));
-        return NULL;
+        goto error;
     }
     return cpu;
+
+error:
+    if (cpu) {
+        object_delete(OBJECT(cpu));
+    }
+    error_report("%s", error_get_pretty(error));
+    error_free(error);
+    return NULL;
 }
 
 #if !defined(CONFIG_USER_ONLY)
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] target-i386: move CPU object creation to cpu.c
  2012-12-11  0:30 ` [Qemu-devel] [PATCH 1/2] " Eduardo Habkost
@ 2012-12-11 13:21   ` Eduardo Habkost
  2012-12-11 13:33   ` Igor Mammedov
  1 sibling, 0 replies; 9+ messages in thread
From: Eduardo Habkost @ 2012-12-11 13:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber

On Mon, Dec 10, 2012 at 10:30:42PM -0200, Eduardo Habkost wrote:
> As we will need to create the CPU object after splitting the CPU model
> string (because we're going to use different subclasses for each CPU
> model), move the CPU object creation to cpu_x86_register(), and at the
> same time rename cpu_x86_register() to cpu_x86_create().
> 
> This will also simplify the CPU creation code to a trivial
> cpu_x86_create()+cpu_x86_realize() sequence. This will be useful for
> code that have to set additional properties before cpu_x86_realize() is
> called (e.g. the PC CPU initialization code, that needs to set APIC IDs
> depending on the CPU cores/threads topology).
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>

Igor just sent "[PATCH 0/6] x86 CPU cleanup (wave 2)", that conflicts
a little with this series.

As the series he sent is larger and some of the patches got some reviews
and comments previously, I will rebase this on top of his series and
resubmit.


> ---
>  target-i386/cpu.c    | 17 +++++++++++++----
>  target-i386/cpu.h    |  2 +-
>  target-i386/helper.c |  9 ++-------
>  3 files changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 7be3ad8..044e2d9 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -1488,14 +1488,22 @@ static void filter_features_for_kvm(X86CPU *cpu)
>  }
>  #endif
>  
> -int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
> +/* Create and initialize a X86CPU object, based on the full CPU model string
> + * (that may include "+feature,-feature,feature=xxx" feature strings)
> + */
> +X86CPU *cpu_x86_create(const char *cpu_model)
>  {
> -    CPUX86State *env = &cpu->env;
> +    X86CPU *cpu;
> +    CPUX86State *env;
>      x86_def_t def1, *def = &def1;
>      Error *error = NULL;
>      char *name, *features;
>      gchar **model_pieces;
>  
> +    cpu = X86_CPU(object_new(TYPE_X86_CPU));
> +    env = &cpu->env;
> +    env->cpu_model_str = cpu_model;
> +
>      memset(def, 0, sizeof(*def));
>  
>      model_pieces = g_strsplit(cpu_model, ",", 2);
> @@ -1572,10 +1580,11 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
>      }
>  
>      g_strfreev(model_pieces);
> -    return 0;
> +    return cpu;
>  error:
> +    object_delete(OBJECT(cpu));
>      g_strfreev(model_pieces);
> -    return -1;
> +    return NULL;
>  }
>  
>  #if !defined(CONFIG_USER_ONLY)
> diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> index 386c4f6..3ebaae9 100644
> --- a/target-i386/cpu.h
> +++ b/target-i386/cpu.h
> @@ -980,7 +980,7 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo,
>  void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
>                     uint32_t *eax, uint32_t *ebx,
>                     uint32_t *ecx, uint32_t *edx);
> -int cpu_x86_register(X86CPU *cpu, const char *cpu_model);
> +X86CPU *cpu_x86_create(const char *cpu_model);
>  void cpu_clear_apic_feature(CPUX86State *env);
>  void host_cpuid(uint32_t function, uint32_t count,
>                  uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
> diff --git a/target-i386/helper.c b/target-i386/helper.c
> index bf206cf..23af4a8 100644
> --- a/target-i386/helper.c
> +++ b/target-i386/helper.c
> @@ -1243,15 +1243,10 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector,
>  X86CPU *cpu_x86_init(const char *cpu_model)
>  {
>      X86CPU *cpu;
> -    CPUX86State *env;
>      Error *error = NULL;
>  
> -    cpu = X86_CPU(object_new(TYPE_X86_CPU));
> -    env = &cpu->env;
> -    env->cpu_model_str = cpu_model;
> -
> -    if (cpu_x86_register(cpu, cpu_model) < 0) {
> -        object_delete(OBJECT(cpu));
> +    cpu = cpu_x86_create(cpu_model);
> +    if (!cpu) {
>          return NULL;
>      }
>  
> -- 
> 1.7.11.7
> 
> 

-- 
Eduardo

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] target-i386: move CPU object creation to cpu.c
  2012-12-11  0:30 ` [Qemu-devel] [PATCH 1/2] " Eduardo Habkost
  2012-12-11 13:21   ` Eduardo Habkost
@ 2012-12-11 13:33   ` Igor Mammedov
  2012-12-11 13:46     ` Eduardo Habkost
  1 sibling, 1 reply; 9+ messages in thread
From: Igor Mammedov @ 2012-12-11 13:33 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: qemu-devel, Andreas Färber

On Mon, 10 Dec 2012 22:30:42 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:

> As we will need to create the CPU object after splitting the CPU model
> string (because we're going to use different subclasses for each CPU
> model), move the CPU object creation to cpu_x86_register(), and at the
> same time rename cpu_x86_register() to cpu_x86_create().
perhaps it would be better to move cpu_x86_init() inside cpu.c and embed
cpu_x86_register() in it, as you have done in one of yours series, and avoid
creating intermediate cpu_x86_create() when the end result of cpu subclasses
& properties should become a simple cpu_x86_init():
 1. lookup class name, 2. get cpu instance , 3. set properties, 4. realize() 

> 
> This will also simplify the CPU creation code to a trivial
> cpu_x86_create()+cpu_x86_realize() sequence. This will be useful for
> code that have to set additional properties before cpu_x86_realize() is
> called (e.g. the PC CPU initialization code, that needs to set APIC IDs
> depending on the CPU cores/threads topology).
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  target-i386/cpu.c    | 17 +++++++++++++----
>  target-i386/cpu.h    |  2 +-
>  target-i386/helper.c |  9 ++-------
>  3 files changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 7be3ad8..044e2d9 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -1488,14 +1488,22 @@ static void filter_features_for_kvm(X86CPU *cpu)
>  }
>  #endif
>  
> -int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
> +/* Create and initialize a X86CPU object, based on the full CPU model
> string
> + * (that may include "+feature,-feature,feature=xxx" feature strings)
> + */
> +X86CPU *cpu_x86_create(const char *cpu_model)
>  {
> -    CPUX86State *env = &cpu->env;
> +    X86CPU *cpu;
> +    CPUX86State *env;
>      x86_def_t def1, *def = &def1;
>      Error *error = NULL;
>      char *name, *features;
>      gchar **model_pieces;
>  
> +    cpu = X86_CPU(object_new(TYPE_X86_CPU));
> +    env = &cpu->env;
> +    env->cpu_model_str = cpu_model;
> +
>      memset(def, 0, sizeof(*def));
>  
>      model_pieces = g_strsplit(cpu_model, ",", 2);
> @@ -1572,10 +1580,11 @@ int cpu_x86_register(X86CPU *cpu, const char
> *cpu_model) }
>  
>      g_strfreev(model_pieces);
> -    return 0;
> +    return cpu;
>  error:
> +    object_delete(OBJECT(cpu));
>      g_strfreev(model_pieces);
> -    return -1;
> +    return NULL;
>  }
>  
>  #if !defined(CONFIG_USER_ONLY)
> diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> index 386c4f6..3ebaae9 100644
> --- a/target-i386/cpu.h
> +++ b/target-i386/cpu.h
> @@ -980,7 +980,7 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo,
>  void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
>                     uint32_t *eax, uint32_t *ebx,
>                     uint32_t *ecx, uint32_t *edx);
> -int cpu_x86_register(X86CPU *cpu, const char *cpu_model);
> +X86CPU *cpu_x86_create(const char *cpu_model);
>  void cpu_clear_apic_feature(CPUX86State *env);
>  void host_cpuid(uint32_t function, uint32_t count,
>                  uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t
> *edx); diff --git a/target-i386/helper.c b/target-i386/helper.c
> index bf206cf..23af4a8 100644
> --- a/target-i386/helper.c
> +++ b/target-i386/helper.c
> @@ -1243,15 +1243,10 @@ int cpu_x86_get_descr_debug(CPUX86State *env,
> unsigned int selector, X86CPU *cpu_x86_init(const char *cpu_model)
>  {
>      X86CPU *cpu;
> -    CPUX86State *env;
>      Error *error = NULL;
>  
> -    cpu = X86_CPU(object_new(TYPE_X86_CPU));
> -    env = &cpu->env;
> -    env->cpu_model_str = cpu_model;
> -
> -    if (cpu_x86_register(cpu, cpu_model) < 0) {
> -        object_delete(OBJECT(cpu));
> +    cpu = cpu_x86_create(cpu_model);
> +    if (!cpu) {
>          return NULL;
>      }
>  

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] target-i386: move CPU object creation to cpu.c
  2012-12-11 13:33   ` Igor Mammedov
@ 2012-12-11 13:46     ` Eduardo Habkost
  0 siblings, 0 replies; 9+ messages in thread
From: Eduardo Habkost @ 2012-12-11 13:46 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, Andreas Färber

On Tue, Dec 11, 2012 at 02:33:24PM +0100, Igor Mammedov wrote:
> On Mon, 10 Dec 2012 22:30:42 -0200
> Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
> > As we will need to create the CPU object after splitting the CPU model
> > string (because we're going to use different subclasses for each CPU
> > model), move the CPU object creation to cpu_x86_register(), and at the
> > same time rename cpu_x86_register() to cpu_x86_create().
> perhaps it would be better to move cpu_x86_init() inside cpu.c and embed
> cpu_x86_register() in it, as you have done in one of yours series, and avoid
> creating intermediate cpu_x86_create() when the end result of cpu subclasses
> & properties should become a simple cpu_x86_init():
>  1. lookup class name, 2. get cpu instance , 3. set properties, 4. realize() 

I don't think cpu_x86_create() is an intermediate code, it is becoming
what will be the final CPU creation code.

cpu_x86_create() is now doing all steps you suggest above above, except
for step 4 (realize). But leaving the realize() call outside of cpu.c is
actually a feature, because some code will need to do additional
initialization steps between steps 3 and 4 (so that code will become a
simple create()+[additional steps]+realize() function).

I believe that moving the object creation to cpu.c only (instead of the
whole cpu_x86_init() function) ended up being much simpler than the
original approach I used (that was moving the entire cpu_x86_init()
function to cpu.c).

cpu_x86_init() is now just a create()+realize() helper, and nothing
else, and I believe we won't need to touch it anymore except at some
point in the future when (hopefully) we will kill it and replace with a
generic target-independent function.


> 
> > 
> > This will also simplify the CPU creation code to a trivial
> > cpu_x86_create()+cpu_x86_realize() sequence. This will be useful for
> > code that have to set additional properties before cpu_x86_realize() is
> > called (e.g. the PC CPU initialization code, that needs to set APIC IDs
> > depending on the CPU cores/threads topology).
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> >  target-i386/cpu.c    | 17 +++++++++++++----
> >  target-i386/cpu.h    |  2 +-
> >  target-i386/helper.c |  9 ++-------
> >  3 files changed, 16 insertions(+), 12 deletions(-)
> > 
> > diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> > index 7be3ad8..044e2d9 100644
> > --- a/target-i386/cpu.c
> > +++ b/target-i386/cpu.c
> > @@ -1488,14 +1488,22 @@ static void filter_features_for_kvm(X86CPU *cpu)
> >  }
> >  #endif
> >  
> > -int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
> > +/* Create and initialize a X86CPU object, based on the full CPU model
> > string
> > + * (that may include "+feature,-feature,feature=xxx" feature strings)
> > + */
> > +X86CPU *cpu_x86_create(const char *cpu_model)
> >  {
> > -    CPUX86State *env = &cpu->env;
> > +    X86CPU *cpu;
> > +    CPUX86State *env;
> >      x86_def_t def1, *def = &def1;
> >      Error *error = NULL;
> >      char *name, *features;
> >      gchar **model_pieces;
> >  
> > +    cpu = X86_CPU(object_new(TYPE_X86_CPU));
> > +    env = &cpu->env;
> > +    env->cpu_model_str = cpu_model;
> > +
> >      memset(def, 0, sizeof(*def));
> >  
> >      model_pieces = g_strsplit(cpu_model, ",", 2);
> > @@ -1572,10 +1580,11 @@ int cpu_x86_register(X86CPU *cpu, const char
> > *cpu_model) }
> >  
> >      g_strfreev(model_pieces);
> > -    return 0;
> > +    return cpu;
> >  error:
> > +    object_delete(OBJECT(cpu));
> >      g_strfreev(model_pieces);
> > -    return -1;
> > +    return NULL;
> >  }
> >  
> >  #if !defined(CONFIG_USER_ONLY)
> > diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> > index 386c4f6..3ebaae9 100644
> > --- a/target-i386/cpu.h
> > +++ b/target-i386/cpu.h
> > @@ -980,7 +980,7 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo,
> >  void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
> >                     uint32_t *eax, uint32_t *ebx,
> >                     uint32_t *ecx, uint32_t *edx);
> > -int cpu_x86_register(X86CPU *cpu, const char *cpu_model);
> > +X86CPU *cpu_x86_create(const char *cpu_model);
> >  void cpu_clear_apic_feature(CPUX86State *env);
> >  void host_cpuid(uint32_t function, uint32_t count,
> >                  uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t
> > *edx); diff --git a/target-i386/helper.c b/target-i386/helper.c
> > index bf206cf..23af4a8 100644
> > --- a/target-i386/helper.c
> > +++ b/target-i386/helper.c
> > @@ -1243,15 +1243,10 @@ int cpu_x86_get_descr_debug(CPUX86State *env,
> > unsigned int selector, X86CPU *cpu_x86_init(const char *cpu_model)
> >  {
> >      X86CPU *cpu;
> > -    CPUX86State *env;
> >      Error *error = NULL;
> >  
> > -    cpu = X86_CPU(object_new(TYPE_X86_CPU));
> > -    env = &cpu->env;
> > -    env->cpu_model_str = cpu_model;
> > -
> > -    if (cpu_x86_register(cpu, cpu_model) < 0) {
> > -        object_delete(OBJECT(cpu));
> > +    cpu = cpu_x86_create(cpu_model);
> > +    if (!cpu) {
> >          return NULL;
> >      }
> >  
> 

-- 
Eduardo

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 1/2] target-i386: move CPU object creation to cpu.c
  2012-12-12 18:16 [Qemu-devel] [PATCH 0/2] target-i386: move CPU object creation to cpu.c (v2) Eduardo Habkost
@ 2012-12-12 18:16 ` Eduardo Habkost
  2012-12-14 10:26   ` Igor Mammedov
  0 siblings, 1 reply; 9+ messages in thread
From: Eduardo Habkost @ 2012-12-12 18:16 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber

As we will need to create the CPU object after splitting the CPU model
string (because we're going to use different subclasses for each CPU
model), move the CPU object creation to cpu_x86_register(), and at the
same time rename cpu_x86_register() to cpu_x86_create().

This will also simplify the CPU creation code to a trivial
cpu_x86_create()+cpu_x86_realize() sequence. This will be useful for
code that have to set additional properties before cpu_x86_realize() is
called (e.g. the PC CPU initialization code, that needs to set APIC IDs
depending on the CPU cores/threads topology).

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c    | 16 +++++++++++++---
 target-i386/cpu.h    |  2 +-
 target-i386/helper.c |  9 ++-------
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 3b9bbfe..b242bf1 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1539,13 +1539,22 @@ static void filter_features_for_kvm(X86CPU *cpu)
 }
 #endif
 
-int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
+/* Create and initialize a X86CPU object, based on the full CPU model string
+ * (that may include "+feature,-feature,feature=xxx" feature strings)
+ */
+X86CPU *cpu_x86_create(const char *cpu_model)
 {
+    X86CPU *cpu;
+    CPUX86State *env;
     x86_def_t def1, *def = &def1;
     Error *error = NULL;
     char *name, *features;
     gchar **model_pieces;
 
+    cpu = X86_CPU(object_new(TYPE_X86_CPU));
+    env = &cpu->env;
+    env->cpu_model_str = cpu_model;
+
     memset(def, 0, sizeof(*def));
 
     model_pieces = g_strsplit(cpu_model, ",", 2);
@@ -1578,10 +1587,11 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
     }
 
     g_strfreev(model_pieces);
-    return 0;
+    return cpu;
 error:
+    object_delete(OBJECT(cpu));
     g_strfreev(model_pieces);
-    return -1;
+    return NULL;
 }
 
 #if !defined(CONFIG_USER_ONLY)
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 386c4f6..3ebaae9 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -980,7 +980,7 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo,
 void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
                    uint32_t *eax, uint32_t *ebx,
                    uint32_t *ecx, uint32_t *edx);
-int cpu_x86_register(X86CPU *cpu, const char *cpu_model);
+X86CPU *cpu_x86_create(const char *cpu_model);
 void cpu_clear_apic_feature(CPUX86State *env);
 void host_cpuid(uint32_t function, uint32_t count,
                 uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
diff --git a/target-i386/helper.c b/target-i386/helper.c
index bf206cf..23af4a8 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -1243,15 +1243,10 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector,
 X86CPU *cpu_x86_init(const char *cpu_model)
 {
     X86CPU *cpu;
-    CPUX86State *env;
     Error *error = NULL;
 
-    cpu = X86_CPU(object_new(TYPE_X86_CPU));
-    env = &cpu->env;
-    env->cpu_model_str = cpu_model;
-
-    if (cpu_x86_register(cpu, cpu_model) < 0) {
-        object_delete(OBJECT(cpu));
+    cpu = cpu_x86_create(cpu_model);
+    if (!cpu) {
         return NULL;
     }
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] target-i386: move CPU object creation to cpu.c
  2012-12-12 18:16 ` [Qemu-devel] [PATCH 1/2] target-i386: move CPU object creation to cpu.c Eduardo Habkost
@ 2012-12-14 10:26   ` Igor Mammedov
  2012-12-14 12:42     ` Eduardo Habkost
  0 siblings, 1 reply; 9+ messages in thread
From: Igor Mammedov @ 2012-12-14 10:26 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: qemu-devel, Andreas Färber

On Wed, 12 Dec 2012 16:16:22 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:

> As we will need to create the CPU object after splitting the CPU model
> string (because we're going to use different subclasses for each CPU
> model), move the CPU object creation to cpu_x86_register(), and at the
> same time rename cpu_x86_register() to cpu_x86_create().
> 
> This will also simplify the CPU creation code to a trivial
> cpu_x86_create()+cpu_x86_realize() sequence. This will be useful for
> code that have to set additional properties before cpu_x86_realize() is
> called (e.g. the PC CPU initialization code, that needs to set APIC IDs
> depending on the CPU cores/threads topology).
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  target-i386/cpu.c    | 16 +++++++++++++---
>  target-i386/cpu.h    |  2 +-
>  target-i386/helper.c |  9 ++-------
>  3 files changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 3b9bbfe..b242bf1 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -1539,13 +1539,22 @@ static void filter_features_for_kvm(X86CPU *cpu)
>  }
>  #endif
>  
> -int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
> +/* Create and initialize a X86CPU object, based on the full CPU model string
> + * (that may include "+feature,-feature,feature=xxx" feature strings)
feature format of cpu_model string misses just 'feature'

> + */
> +X86CPU *cpu_x86_create(const char *cpu_model)
>  {
> +    X86CPU *cpu;
> +    CPUX86State *env;
>      x86_def_t def1, *def = &def1;
>      Error *error = NULL;
>      char *name, *features;
>      gchar **model_pieces;
>  
> +    cpu = X86_CPU(object_new(TYPE_X86_CPU));
Could we put this after cpu_x86_parse_featurestr(), it's really not needed
before it now and eventually we would like to move it there anyway.

> +    env = &cpu->env;
> +    env->cpu_model_str = cpu_model;
> +
>      memset(def, 0, sizeof(*def));
>  
>      model_pieces = g_strsplit(cpu_model, ",", 2);
> @@ -1578,10 +1587,11 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
>      }
>  
>      g_strfreev(model_pieces);
> -    return 0;
> +    return cpu;
>  error:
> +    object_delete(OBJECT(cpu));
>      g_strfreev(model_pieces);
> -    return -1;
> +    return NULL;
>  }
>  
>  #if !defined(CONFIG_USER_ONLY)
> diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> index 386c4f6..3ebaae9 100644
> --- a/target-i386/cpu.h
> +++ b/target-i386/cpu.h
> @@ -980,7 +980,7 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo,
>  void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
>                     uint32_t *eax, uint32_t *ebx,
>                     uint32_t *ecx, uint32_t *edx);
> -int cpu_x86_register(X86CPU *cpu, const char *cpu_model);
> +X86CPU *cpu_x86_create(const char *cpu_model);
>  void cpu_clear_apic_feature(CPUX86State *env);
>  void host_cpuid(uint32_t function, uint32_t count,
>                  uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
> diff --git a/target-i386/helper.c b/target-i386/helper.c
> index bf206cf..23af4a8 100644
> --- a/target-i386/helper.c
> +++ b/target-i386/helper.c
> @@ -1243,15 +1243,10 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector,
>  X86CPU *cpu_x86_init(const char *cpu_model)
>  {
>      X86CPU *cpu;
> -    CPUX86State *env;
>      Error *error = NULL;
>  
> -    cpu = X86_CPU(object_new(TYPE_X86_CPU));
> -    env = &cpu->env;
> -    env->cpu_model_str = cpu_model;
> -
> -    if (cpu_x86_register(cpu, cpu_model) < 0) {
> -        object_delete(OBJECT(cpu));
> +    cpu = cpu_x86_create(cpu_model);
> +    if (!cpu) {
>          return NULL;
>      }
>  
> -- 
> 1.7.11.7
> 


-- 
Regards,
  Igor

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] target-i386: move CPU object creation to cpu.c
  2012-12-14 10:26   ` Igor Mammedov
@ 2012-12-14 12:42     ` Eduardo Habkost
  0 siblings, 0 replies; 9+ messages in thread
From: Eduardo Habkost @ 2012-12-14 12:42 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, Andreas Färber

On Fri, Dec 14, 2012 at 11:26:55AM +0100, Igor Mammedov wrote:
> On Wed, 12 Dec 2012 16:16:22 -0200
> Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
> > As we will need to create the CPU object after splitting the CPU model
> > string (because we're going to use different subclasses for each CPU
> > model), move the CPU object creation to cpu_x86_register(), and at the
> > same time rename cpu_x86_register() to cpu_x86_create().
> > 
> > This will also simplify the CPU creation code to a trivial
> > cpu_x86_create()+cpu_x86_realize() sequence. This will be useful for
> > code that have to set additional properties before cpu_x86_realize() is
> > called (e.g. the PC CPU initialization code, that needs to set APIC IDs
> > depending on the CPU cores/threads topology).
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> >  target-i386/cpu.c    | 16 +++++++++++++---
> >  target-i386/cpu.h    |  2 +-
> >  target-i386/helper.c |  9 ++-------
> >  3 files changed, 16 insertions(+), 11 deletions(-)
> > 
> > diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> > index 3b9bbfe..b242bf1 100644
> > --- a/target-i386/cpu.c
> > +++ b/target-i386/cpu.c
> > @@ -1539,13 +1539,22 @@ static void filter_features_for_kvm(X86CPU *cpu)
> >  }
> >  #endif
> >  
> > -int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
> > +/* Create and initialize a X86CPU object, based on the full CPU model string
> > + * (that may include "+feature,-feature,feature=xxx" feature strings)
> feature format of cpu_model string misses just 'feature'

Thanks. I'll change it.

> 
> > + */
> > +X86CPU *cpu_x86_create(const char *cpu_model)
> >  {
> > +    X86CPU *cpu;
> > +    CPUX86State *env;
> >      x86_def_t def1, *def = &def1;
> >      Error *error = NULL;
> >      char *name, *features;
> >      gchar **model_pieces;
> >  
> > +    cpu = X86_CPU(object_new(TYPE_X86_CPU));
> Could we put this after cpu_x86_parse_featurestr(), it's really not needed
> before it now and eventually we would like to move it there anyway.

I believe we want to call cpu_x86_parse_featurestr() _after_ the CPU
object is created, don't we? Because one day the feature string is going
be used to set properties in the CPU object.

But we can move object_new() after g_strsplit() (because evantually the
CPU object creation is going to use the first part of cpu_model to
lookup the class name).

> 
> > +    env = &cpu->env;
> > +    env->cpu_model_str = cpu_model;
> > +
> >      memset(def, 0, sizeof(*def));
> >  
> >      model_pieces = g_strsplit(cpu_model, ",", 2);
> > @@ -1578,10 +1587,11 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
> >      }
> >  
> >      g_strfreev(model_pieces);
> > -    return 0;
> > +    return cpu;
> >  error:
> > +    object_delete(OBJECT(cpu));
> >      g_strfreev(model_pieces);
> > -    return -1;
> > +    return NULL;
> >  }
> >  
> >  #if !defined(CONFIG_USER_ONLY)
> > diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> > index 386c4f6..3ebaae9 100644
> > --- a/target-i386/cpu.h
> > +++ b/target-i386/cpu.h
> > @@ -980,7 +980,7 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo,
> >  void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
> >                     uint32_t *eax, uint32_t *ebx,
> >                     uint32_t *ecx, uint32_t *edx);
> > -int cpu_x86_register(X86CPU *cpu, const char *cpu_model);
> > +X86CPU *cpu_x86_create(const char *cpu_model);
> >  void cpu_clear_apic_feature(CPUX86State *env);
> >  void host_cpuid(uint32_t function, uint32_t count,
> >                  uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
> > diff --git a/target-i386/helper.c b/target-i386/helper.c
> > index bf206cf..23af4a8 100644
> > --- a/target-i386/helper.c
> > +++ b/target-i386/helper.c
> > @@ -1243,15 +1243,10 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector,
> >  X86CPU *cpu_x86_init(const char *cpu_model)
> >  {
> >      X86CPU *cpu;
> > -    CPUX86State *env;
> >      Error *error = NULL;
> >  
> > -    cpu = X86_CPU(object_new(TYPE_X86_CPU));
> > -    env = &cpu->env;
> > -    env->cpu_model_str = cpu_model;
> > -
> > -    if (cpu_x86_register(cpu, cpu_model) < 0) {
> > -        object_delete(OBJECT(cpu));
> > +    cpu = cpu_x86_create(cpu_model);
> > +    if (!cpu) {
> >          return NULL;
> >      }
> >  
> > -- 
> > 1.7.11.7
> > 
> 
> 
> -- 
> Regards,
>   Igor

-- 
Eduardo

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-12-14 12:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-11  0:30 [Qemu-devel] [PATCH 0/2] target-i386: move CPU object creation to cpu.c Eduardo Habkost
2012-12-11  0:30 ` [Qemu-devel] [PATCH 1/2] " Eduardo Habkost
2012-12-11 13:21   ` Eduardo Habkost
2012-12-11 13:33   ` Igor Mammedov
2012-12-11 13:46     ` Eduardo Habkost
2012-12-11  0:30 ` [Qemu-devel] [PATCH 2/2] target-i386: make cpu_x86_create() get Error argument Eduardo Habkost
  -- strict thread matches above, loose matches on Subject: below --
2012-12-12 18:16 [Qemu-devel] [PATCH 0/2] target-i386: move CPU object creation to cpu.c (v2) Eduardo Habkost
2012-12-12 18:16 ` [Qemu-devel] [PATCH 1/2] target-i386: move CPU object creation to cpu.c Eduardo Habkost
2012-12-14 10:26   ` Igor Mammedov
2012-12-14 12:42     ` Eduardo Habkost

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