Skip to contentSkip to conversation

target-i386: X86CPU subclasses

PATCH In review Andreas Färber 2 participants 7 messages Feb 25, 2014 – Mar 9, 2014

lore
Share & tools
lore
#0 lore raw

v10 cover target-i386: X86CPU subclasses

Hello,

Here's my cleaned up version of slim x86 CPU subclasses. Second patch didn't get a lot of testing yet.

Loading cpudef is still in main initfn since otherwise the host type would need to be relocated. Can be cleaned up as follow-ups.

I wonder whether we are intentionally registering the host type even for !CONFIG_KVM? Instantiating it will then always lead to assertion failure.

Available for testing here:
git://github.com/afaerber/qemu-cpu.git qom-cpu-x86-subclasses.v10
https://github.com/afaerber/qemu-cpu/commits/qom-cpu-x86-subclasses.v10

Regards,
Andreas

v9 -> v10:
* Cleaned up documentation comments.
* Prepended patch to implement CPUClass::class_by_name(), rebased on it.
* Cleaned up naming (..._class_init, ..._initfn, type vs. class).
* Dropped duplicate white line.
* Dropped unnecessary .abstract, .instance_size, .class_size fields.
* Aligned model type registration with other targets by having the registration function operate on one model only.
* Relocated cpudef-based types to after x86_cpu_load_cpudef().
* Moved assignment of cpu_def into cpudef-specific class_init.

(went through various hands, last ehabkost's)

v2 -> v3:
* Instead of re-coding all CPU definitions as class_init functions, leave the built-in definition array in place and place x86_def_t in the class.
* Use kvm_arch_init() hook to assure class_init succeeds for -cpu host. Suggested by Eduardo.

v1-> v2:
* Instead of turning x86_def_t into X86CPUInfo to initialize classes, drop it completely and register types manually with customizable TypeInfos
* Use new list facilities for printing -cpu ? models
* Adopt new name scheme suggested by Eduardo and ideas from my alpha series
* Keep short names in -cpu ? output for alignment reasons
* Merge cpu_x86_init() into cpu.c:cpu_x86_register()
* Append patch showing Haswell as subclass of SandyBridge

Cc Eduardo Habkost <[email protected]>
Cc Igor Mammedov <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Anthony Liguori <[email protected]>

Andreas Färber (1):
target-i386: Prepare CPUClass::class_by_name for X86CPU

Eduardo Habkost (1):
target-i386: X86CPU model subclasses

 target-i386/cpu-qom.h |  15 ++++
 target-i386/cpu.c     | 197 +++++++++++++++++++++++++++++++-------------------
 2 files changed, 138 insertions(+), 74 deletions(-)
Signature · 1 line
1.8.4.5
#1 lore raw

PATCH v10 1/2 target-i386: Prepare CPUClass::class_by_name for X86CPU

---
 target-i386/cpu.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
target-i386/cpu.c +21 -3
index a8b8e88..1c009bb 100644
@@ -484,6 +484,15 @@ static void add_flagname_to_bitmaps(const char *flagname,
     }
 }
 
+static ObjectClass *x86_cpu_class_by_name(const char *cpu_model)
+{
+    if (cpu_model == NULL) {
+        return NULL;
+    }
+
+    return object_class_by_name(TYPE_X86_CPU);
+}
+
 typedef struct X86CPUDefinition {
     const char *name;
     uint32_t level;
@@ -1881,6 +1890,7 @@ X86CPU *cpu_x86_create(const char *cpu_model, DeviceState *icc_bridge,
                        Error **errp)
 {
     X86CPU *cpu = NULL;
+    ObjectClass *oc;
     gchar **model_pieces;
     char *name, *features;
     char *typename;
@@ -1894,7 +1904,12 @@ X86CPU *cpu_x86_create(const char *cpu_model, DeviceState *icc_bridge,
     name = model_pieces[0];
     features = model_pieces[1];
 
-    cpu = X86_CPU(object_new(TYPE_X86_CPU));
+    oc = x86_cpu_class_by_name(name);
+    if (oc == NULL) {
+        error_setg(&error, "Unable to find CPU definition: %s", name);
+        goto out;
+    }
+    cpu = X86_CPU(object_new(object_class_get_name(oc)));
     x86_cpu_load_def(cpu, name, &error);
     if (error) {
         goto out;
@@ -1925,8 +1940,10 @@ X86CPU *cpu_x86_create(const char *cpu_model, DeviceState *icc_bridge,
 out:
     if (error != NULL) {
         error_propagate(errp, error);
-        object_unref(OBJECT(cpu));
-        cpu = NULL;
+        if (cpu) {
+            object_unref(OBJECT(cpu));
+            cpu = NULL;
+        }
     }
     g_strfreev(model_pieces);
     return cpu;
@@ -2739,6 +2756,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     cc->reset = x86_cpu_reset;
     cc->reset_dump_flags = CPU_DUMP_FPU | CPU_DUMP_CCOP;
 
+    cc->class_by_name = x86_cpu_class_by_name;
     cc->has_work = x86_cpu_has_work;
     cc->do_interrupt = x86_cpu_do_interrupt;
     cc->dump_state = x86_cpu_dump_state;
Signature · 1 line
1.8.4.5
#3 lore raw

PATCH v10 2/2 target-i386: X86CPU model subclasses

In reply to Andreas Färber

From: Eduardo Habkost <[email protected]>

Register separate QOM types for each x86 CPU model.

This will allow management code to more easily probe what each CPU model provides, by simply creating objects using the appropriate class name, without having to restart QEMU.

This also allows us to eliminate the qdev_prop_set_globals_for_type() hack to set CPU-model-specific global properties.

Instead of creating separate class_init functions for each class, I just used class_data to store a pointer to the X86CPUDefinition struct for each CPU model. This should make the patch shorter and easier to review. Later we can gradually convert each X86CPUDefinition field to lists of per-class property defaults.

The "host" CPU model is special, as the feature flags depend on KVM being initialized. So it has its own class_init and instance_init function, and feature flags are set on instance_init instead of class_init.

---
 target-i386/cpu-qom.h |  15 +++++
 target-i386/cpu.c     | 177 +++++++++++++++++++++++++++++---------------------
 2 files changed, 119 insertions(+), 73 deletions(-)
target-i386/cpu-qom.h +15 -0
index 722f11a..e9b3d57 100644
@@ -38,7 +38,17 @@
     OBJECT_GET_CLASS(X86CPUClass, (obj), TYPE_X86_CPU)
 
 /**
+ * X86CPUDefinition:
+ *
+ * CPU model definition data that was not converted to QOM per-subclass
+ * property defaults yet.
+ */
+typedef struct X86CPUDefinition X86CPUDefinition;
+
+/**
  * X86CPUClass:
+ * @cpu_def: CPU model definition
+ * @kvm_required: Whether CPU model requires KVM to be enabled.
  * @parent_realize: The parent class' realize handler.
  * @parent_reset: The parent class' reset handler.
  *
@@ -49,6 +59,11 @@ typedef struct X86CPUClass {
     CPUClass parent_class;
     /*< public >*/
 
+    /* Should be eventually replaced by subclass-specific property defaults. */
+    X86CPUDefinition *cpu_def;
+
+    bool kvm_required;
+
     DeviceRealize parent_realize;
     void (*parent_reset)(CPUState *cpu);
 } X86CPUClass;
target-i386/cpu.c +104 -73

301 lines not on this page · raw message

Signature · 1 line
1.8.4.5
Reviewed-by Tested-by on v10 2/2
#4 lore raw

Re: [Qemu-devel] [PATCH qom-cpu v10 2/2] target-i386: X86CPU model subclasses

Quoted 22 lines · Andreas Färber

From: Eduardo Habkost <[email protected]>

Register separate QOM types for each x86 CPU model.

This will allow management code to more easily probe what each CPU model provides, by simply creating objects using the appropriate class name, without having to restart QEMU.

This also allows us to eliminate the qdev_prop_set_globals_for_type() hack to set CPU-model-specific global properties.

Instead of creating separate class_init functions for each class, I just used class_data to store a pointer to the X86CPUDefinition struct for each CPU model. This should make the patch shorter and easier to review. Later we can gradually convert each X86CPUDefinition field to lists of per-class property defaults.

The "host" CPU model is special, as the feature flags depend on KVM being initialized. So it has its own class_init and instance_init function, and feature flags are set on instance_init instead of class_init.

Quoted 4 lines

For the changes you introduced:

After hacking the code to allow device_add on CPUs, I could use the classes to instantiate CPUs from different models using device_add (which would be useful to allow probing of CPU model information in a single QEMU instance).

Signature · 1 line
Eduardo
#5 lore raw

Re: [Qemu-devel] [PATCH qom-cpu v10 2/2] target-i386: X86CPU model subclasses

Am 04.03.2014 20:53, schrieb Eduardo Habkost:

Quoted 30 lines · Andreas Färber
Quoted 22 lines

From: Eduardo Habkost <[email protected]>

Register separate QOM types for each x86 CPU model.

This will allow management code to more easily probe what each CPU model provides, by simply creating objects using the appropriate class name, without having to restart QEMU.

This also allows us to eliminate the qdev_prop_set_globals_for_type() hack to set CPU-model-specific global properties.

Instead of creating separate class_init functions for each class, I just used class_data to store a pointer to the X86CPUDefinition struct for each CPU model. This should make the patch shorter and easier to review. Later we can gradually convert each X86CPUDefinition field to lists of per-class property defaults.

The "host" CPU model is special, as the feature flags depend on KVM being initialized. So it has its own class_init and instance_init function, and feature flags are set on instance_init instead of class_init.

Quoted 4 lines

For the changes you introduced:

Quoted 7 lines

After hacking the code to allow device_add on CPUs, I could use the classes to instantiate CPUs from different models using device_add (which would be useful to allow probing of CPU model information in a single QEMU instance).

Thanks a lot, I'm proceeding to staging this on qom-cpu-next:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu-next

Features parsing needs minor merges. Goal is still 2.0.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#6 lore raw
In reply to Andreas Färber

Am 25.02.2014 08:36, schrieb Andreas Färber:

Quoted 10 lines

Hello,

Here's my cleaned up version of slim x86 CPU subclasses. Second patch didn't get a lot of testing yet.

Loading cpudef is still in main initfn since otherwise the host type would need to be relocated. Can be cleaned up as follow-ups.

I wonder whether we are intentionally registering the host type even for !CONFIG_KVM? Instantiating it will then always lead to assertion failure.

Ping! Did anyone review or test? Still applies after new x2apic patches.

Andreas

Quoted 49 lines

Available for testing here:
git://github.com/afaerber/qemu-cpu.git qom-cpu-x86-subclasses.v10
https://github.com/afaerber/qemu-cpu/commits/qom-cpu-x86-subclasses.v10

Regards,
Andreas

v9 -> v10:
* Cleaned up documentation comments.
* Prepended patch to implement CPUClass::class_by_name(), rebased on it.
* Cleaned up naming (..._class_init, ..._initfn, type vs. class).
* Dropped duplicate white line.
* Dropped unnecessary .abstract, .instance_size, .class_size fields.
* Aligned model type registration with other targets by having the registration function operate on one model only.
* Relocated cpudef-based types to after x86_cpu_load_cpudef().
* Moved assignment of cpu_def into cpudef-specific class_init.

(went through various hands, last ehabkost's)

v2 -> v3:
* Instead of re-coding all CPU definitions as class_init functions, leave the built-in definition array in place and place x86_def_t in the class.
* Use kvm_arch_init() hook to assure class_init succeeds for -cpu host. Suggested by Eduardo.

v1-> v2:
* Instead of turning x86_def_t into X86CPUInfo to initialize classes, drop it completely and register types manually with customizable TypeInfos
* Use new list facilities for printing -cpu ? models
* Adopt new name scheme suggested by Eduardo and ideas from my alpha series
* Keep short names in -cpu ? output for alignment reasons
* Merge cpu_x86_init() into cpu.c:cpu_x86_register()
* Append patch showing Haswell as subclass of SandyBridge

Cc Eduardo Habkost <[email protected]>
Cc Igor Mammedov <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Anthony Liguori <[email protected]>

Andreas Färber (1):
target-i386: Prepare CPUClass::class_by_name for X86CPU

Eduardo Habkost (1):
target-i386: X86CPU model subclasses

 target-i386/cpu-qom.h |  15 ++++
 target-i386/cpu.c     | 197 +++++++++++++++++++++++++++++++-------------------
 2 files changed, 138 insertions(+), 74 deletions(-)
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg