Skip to contentSkip to conversation

make apic hot-plugable

Qemu-devel In review Liu Ping Fan 4 participants 22 messages Jul 10, 2012 – Jul 11, 2012

lore
Share & tools
lore
#1 lore raw

PATCH 1/5 qdev: introduce qdev_create_kid(Object *parent, const char *type)

DeviceState can be created as kid of DeviceState/CPUState, not neccesary attached to bus. This will be helpful to simulate the real hardware submodule which sits inside package.

---
 hw/qdev.c |   28 ++++++++++++++++++++++++++++
 hw/qdev.h |    1 +
 2 files changed, 29 insertions(+), 0 deletions(-)
hw/qdev.c +28 -0
index af54467..d2100a1 100644
@@ -26,6 +26,7 @@
    this API directly.  */
 
 #include "net.h"
+#include "qemu/cpu.h"
 #include "qdev.h"
 #include "sysemu.h"
 #include "error.h"
@@ -145,6 +146,33 @@ DeviceState *qdev_try_create(BusState *bus, const char *type)
     return dev;
 }
 
+DeviceState *qdev_create_kid(Object *parent, const char *type)
+{
+    DeviceState *dev;
+    assert(parent);
+
+    if (object_class_by_name(type) == NULL) {
+        return NULL;
+    }
+
+    if (object_is_type_str(parent, TYPE_BUS)) {
+        return qdev_create(BUS(parent), type);
+    }
+
+    if (!object_is_type_str(parent, TYPE_DEVICE)
+        || !object_is_type_str(parent, TYPE_CPU)) {
+        return NULL;
+    }
+
+    dev = DEVICE(object_new(type));
+    if (!dev) {
+        return NULL;
+    }
+    object_property_add_child(OBJECT(parent), type, OBJECT(dev), NULL);
+
+    return dev;
+}
+
 /* Initialize a device.  Device properties should be set before calling
    this function.  IRQs and MMIO regions should be connected/mapped after
    calling this function.
hw/qdev.h +1 -0
index f4683dc..aecc69e 100644
@@ -154,6 +154,7 @@ typedef struct GlobalProperty {
 
 DeviceState *qdev_create(BusState *bus, const char *name);
 DeviceState *qdev_try_create(BusState *bus, const char *name);
+DeviceState *qdev_create_kid(Object *parent, const char *type);
 bool qdev_exists(const char *name);
 int qdev_device_help(QemuOpts *opts);
 DeviceState *qdev_device_add(QemuOpts *opts);
Signature · 1 line
1.7.4.4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/5] qdev: introduce qdev_create_kid(Object *parent, const char *type)

Am 10.07.2012 08:16, schrieb Liu Ping Fan:

Quoted 26 lines

DeviceState can be created as kid of DeviceState/CPUState, not neccesary attached to bus. This will be helpful to simulate the real hardware submodule which sits inside package.

---
 hw/qdev.c |   28 ++++++++++++++++++++++++++++
 hw/qdev.h |    1 +
 2 files changed, 29 insertions(+), 0 deletions(-)
hw/qdev.c +1 -0
index af54467..d2100a1 100644
@@ -26,6 +26,7 @@
    this API directly.  */
 
 #include "net.h"
+#include "qemu/cpu.h"
 #include "qdev.h"
 #include "sysemu.h"
 #include "error.h"
@@ -145,6 +146,33 @@ DeviceState *qdev_try_create(BusState *bus, const char *type)
     return dev;
 }
 

hw/qdev.c DeviceState *qdev_try_create(BusState *bus, const char *type) · line 158

Quoted 10 lines
hw/qdev.c +10 -0
+DeviceState *qdev_create_kid(Object *parent, const char *type)
+{
+    DeviceState *dev;
+    assert(parent);
+
+    if (object_class_by_name(type) == NULL) {
+        return NULL;
+    }
+
+    if (object_is_type_str(parent, TYPE_BUS)) {

This is only introduced in patch 2, no?

Andreas

Quoted 33 lines
hw/qdev.c +17 -0
+        return qdev_create(BUS(parent), type);
+    }
+
+    if (!object_is_type_str(parent, TYPE_DEVICE)
+        || !object_is_type_str(parent, TYPE_CPU)) {
+        return NULL;
+    }
+
+    dev = DEVICE(object_new(type));
+    if (!dev) {
+        return NULL;
+    }
+    object_property_add_child(OBJECT(parent), type, OBJECT(dev), NULL);
+
+    return dev;
+}
+
 /* Initialize a device.  Device properties should be set before calling
    this function.  IRQs and MMIO regions should be connected/mapped after
    calling this function.
hw/qdev.h +1 -0
index f4683dc..aecc69e 100644
@@ -154,6 +154,7 @@ typedef struct GlobalProperty {
 
 DeviceState *qdev_create(BusState *bus, const char *name);
 DeviceState *qdev_try_create(BusState *bus, const char *name);
+DeviceState *qdev_create_kid(Object *parent, const char *type);
 bool qdev_exists(const char *name);
 int qdev_device_help(QemuOpts *opts);
 DeviceState *qdev_device_add(QemuOpts *opts);
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
#3 lore raw

Re: [Qemu-devel] [PATCH 1/5] qdev: introduce qdev_create_kid(Object *parent, const char *type)

In reply to Liu Ping Fan

Il 10/07/2012 08:16, Liu Ping Fan ha scritto:

Quoted 39 lines

DeviceState can be created as kid of DeviceState/CPUState, not neccesary attached to bus. This will be helpful to simulate the real hardware submodule which sits inside package.

---
 hw/qdev.c |   28 ++++++++++++++++++++++++++++
 hw/qdev.h |    1 +
 2 files changed, 29 insertions(+), 0 deletions(-)
hw/qdev.c +14 -0
index af54467..d2100a1 100644
@@ -26,6 +26,7 @@
    this API directly.  */
 
 #include "net.h"
+#include "qemu/cpu.h"
 #include "qdev.h"
 #include "sysemu.h"
 #include "error.h"
@@ -145,6 +146,33 @@ DeviceState *qdev_try_create(BusState *bus, const char *type)
     return dev;
 }
 
+DeviceState *qdev_create_kid(Object *parent, const char *type)
+{
+    DeviceState *dev;
+    assert(parent);
+
+    if (object_class_by_name(type) == NULL) {
+        return NULL;
+    }
+
+    if (object_is_type_str(parent, TYPE_BUS)) {
+        return qdev_create(BUS(parent), type);
+    }
+

hw/qdev.c DeviceState *qdev_try_create(BusState *bus, const char *type) · line 171

Quoted 10 lines
hw/qdev.c +10 -0
+    if (!object_is_type_str(parent, TYPE_DEVICE)
+        || !object_is_type_str(parent, TYPE_CPU)) {
+        return NULL;
+    }
+
+    dev = DEVICE(object_new(type));
+    if (!dev) {
+        return NULL;
+    }
+    object_property_add_child(OBJECT(parent), type, OBJECT(dev), NULL);

I don't like this. The only additional functionality is "magic" dispatching between qdev_create for buses and object_property_add_child for devices. This should be done with a method that is implemented in both objects (e.g. an interface), not with type checks like this.

However, you're not even using the functionality, and designing APIs without an effective need usually makes for bad APIs.

Instead, you can just move APIC creation in the CPU, and use object_property_add_child there.

Paolo

Quoted 19 lines
hw/qdev.c +3 -0
+    return dev;
+}
+
 /* Initialize a device.  Device properties should be set before calling
    this function.  IRQs and MMIO regions should be connected/mapped after
    calling this function.
hw/qdev.h +1 -0
index f4683dc..aecc69e 100644
@@ -154,6 +154,7 @@ typedef struct GlobalProperty {
 
 DeviceState *qdev_create(BusState *bus, const char *name);
 DeviceState *qdev_try_create(BusState *bus, const char *name);
+DeviceState *qdev_create_kid(Object *parent, const char *type);
 bool qdev_exists(const char *name);
 int qdev_device_help(QemuOpts *opts);
 DeviceState *qdev_device_add(QemuOpts *opts);
#4 lore raw

Re: [Qemu-devel] [PATCH 1/5] qdev: introduce qdev_create_kid(Object *parent, const char *type)

Quoted 56 lines · Paolo Bonzini

Il 10/07/2012 08:16, Liu Ping Fan ha scritto:

Quoted 39 lines

DeviceState can be created as kid of DeviceState/CPUState, not neccesary attached to bus. This will be helpful to simulate the real hardware submodule which sits inside package.

---
 hw/qdev.c |   28 ++++++++++++++++++++++++++++
 hw/qdev.h |    1 +
 2 files changed, 29 insertions(+), 0 deletions(-)
hw/qdev.c +14 -0
index af54467..d2100a1 100644
@@ -26,6 +26,7 @@
    this API directly.  */
 
 #include "net.h"
+#include "qemu/cpu.h"
 #include "qdev.h"
 #include "sysemu.h"
 #include "error.h"
@@ -145,6 +146,33 @@ DeviceState *qdev_try_create(BusState *bus, const char *type)
     return dev;
 }
 
+DeviceState *qdev_create_kid(Object *parent, const char *type)
+{
+    DeviceState *dev;
+    assert(parent);
+
+    if (object_class_by_name(type) == NULL) {
+        return NULL;
+    }
+
+    if (object_is_type_str(parent, TYPE_BUS)) {
+        return qdev_create(BUS(parent), type);
+    }
+

hw/qdev.c DeviceState *qdev_try_create(BusState *bus, const char *type) · line 171

Quoted 10 lines
hw/qdev.c +10 -0
+    if (!object_is_type_str(parent, TYPE_DEVICE)
+        || !object_is_type_str(parent, TYPE_CPU)) {
+        return NULL;
+    }
+
+    dev = DEVICE(object_new(type));
+    if (!dev) {
+        return NULL;
+    }
+    object_property_add_child(OBJECT(parent), type, OBJECT(dev), NULL);

I don't like this. The only additional functionality is "magic" dispatching between qdev_create for buses and object_property_add_child for devices. This should be done with a method that is implemented in both objects (e.g. an interface), not with type checks like this.

Quoted 6 lines

However, you're not even using the functionality, and designing APIs without an effective need usually makes for bad APIs.

Instead, you can just move APIC creation in the CPU, and use object_property_add_child there.

OK, I will move the creation in the CPU. But I think as part of qom, DeviceState can have a DeviceState child, so there is need for wrapper for the function. Maybe just make the qdev_create_kid(Object*) -> qdev_create_kid(DeviceState*) ?

regards,
pingfan

Quoted 23 lines

Paolo

Quoted 19 lines
hw/qdev.c +3 -0
+    return dev;
+}
+
 /* Initialize a device.  Device properties should be set before calling
    this function.  IRQs and MMIO regions should be connected/mapped after
    calling this function.
hw/qdev.h +1 -0
index f4683dc..aecc69e 100644
@@ -154,6 +154,7 @@ typedef struct GlobalProperty {
 
 DeviceState *qdev_create(BusState *bus, const char *name);
 DeviceState *qdev_try_create(BusState *bus, const char *name);
+DeviceState *qdev_create_kid(Object *parent, const char *type);
 bool qdev_exists(const char *name);
 int qdev_device_help(QemuOpts *opts);
 DeviceState *qdev_device_add(QemuOpts *opts);
#5 lore raw

Re: [Qemu-devel] [PATCH 1/5] qdev: introduce qdev_create_kid(Object *parent, const char *type)

Il 11/07/2012 03:17, liu ping fan ha scritto:

Quoted 4 lines

OK, I will move the creation in the CPU. But I think as part of qom, DeviceState can have a DeviceState child, so there is need for wrapper for the function. Maybe just make the qdev_create_kid(Object*) -> qdev_create_kid(DeviceState*) ?

You can just use object_property_add_child whenever you would use qdev_create_kid.

Paolo

#6 lore raw

PATCH 2/5 qom: introduce object_is_type_str(), so we can judge its type.

In reply to Liu Ping Fan
---
 include/qemu/object.h |    2 ++
 qom/object.c          |    6 ++++++
 2 files changed, 8 insertions(+), 0 deletions(-)
include/qemu/object.h +2 -0
index 8b17776..a66e996 100644
@@ -479,6 +479,8 @@ void object_initialize(void *obj, const char *typename);
  */
 void object_finalize(void *obj);
 
+bool object_is_type_str(Object *obj, const char *typename);
+
 /**
  * object_dynamic_cast:
  * @obj: The object to cast.
qom/object.c +6 -0
index 00bb3b0..6c27d90 100644
@@ -425,6 +425,12 @@ static bool type_is_ancestor(TypeImpl *type, TypeImpl *target_type)
     return false;
 }
 
+bool object_is_type_str(Object *obj, const char *typename)
+{
+    TypeImpl *target_type = type_get_by_name(typename);
+    return !target_type || type_is_ancestor(obj->class->type, target_type);
+}
+
 static bool object_is_type(Object *obj, TypeImpl *target_type)
 {
     return !target_type || type_is_ancestor(obj->class->type, target_type);
Signature · 1 line
1.7.4.4
#7 lore raw

Re: [Qemu-devel] [PATCH 2/5] qom: introduce object_is_type_str(), so we can judge its type.

Il 10/07/2012 08:16, Liu Ping Fan ha scritto:

Quoted 11 lines
---
 include/qemu/object.h |    2 ++
 qom/object.c          |    6 ++++++
 2 files changed, 8 insertions(+), 0 deletions(-)
include/qemu/object.h +0 -0
index 8b17776..a66e996 100644

include/qemu/object.h void object_initialize(void *obj, const char *typename); · line 482

Quoted 4 lines
include/qemu/object.h +1 -0
@@ -479,6 +479,8 @@ void object_initialize(void *obj, const char *typename);
  */
 void object_finalize(void *obj);
 
+bool object_is_type_str(Object *obj, const char *typename);

Please call this object_is_instance_of, and just call object_dynamic_cast internally so that interfaces are handled properly.

Paolo

Quoted 22 lines
include/qemu/object.h +1 -0
+
 /**
  * object_dynamic_cast:
  * @obj: The object to cast.
qom/object.c +6 -0
index 00bb3b0..6c27d90 100644
@@ -425,6 +425,12 @@ static bool type_is_ancestor(TypeImpl *type, TypeImpl *target_type)
     return false;
 }
 
+bool object_is_type_str(Object *obj, const char *typename)
+{
+    TypeImpl *target_type = type_get_by_name(typename);
+    return !target_type || type_is_ancestor(obj->class->type, target_type);
+}
+
 static bool object_is_type(Object *obj, TypeImpl *target_type)
 {
     return !target_type || type_is_ancestor(obj->class->type, target_type);
#8 lore raw

Re: [Qemu-devel] [PATCH 2/5] qom: introduce object_is_type_str(), so we can judge its type.

Quoted 15 lines · Paolo Bonzini

Il 10/07/2012 08:16, Liu Ping Fan ha scritto:

Quoted 14 lines
---
 include/qemu/object.h |    2 ++
 qom/object.c          |    6 ++++++
 2 files changed, 8 insertions(+), 0 deletions(-)
include/qemu/object.h +0 -0
index 8b17776..a66e996 100644
@@ -479,6 +479,8 @@ void object_initialize(void *obj, const char *typename);
  */
 void object_finalize(void *obj);
 
Quoted 5 lines

include/qemu/object.h void object_initialize(void *obj, const char *typename); · line 482

Quoted 1 line
include/qemu/object.h +1 -0
+bool object_is_type_str(Object *obj, const char *typename);

Please call this object_is_instance_of, and just call object_dynamic_cast internally so that interfaces are handled properly.

OK, will update it in next version

regards,
pingfan

Quoted 26 lines

Paolo

Quoted 22 lines
include/qemu/object.h +1 -0
+
 /**
  * object_dynamic_cast:
  * @obj: The object to cast.
qom/object.c +6 -0
index 00bb3b0..6c27d90 100644
@@ -425,6 +425,12 @@ static bool type_is_ancestor(TypeImpl *type, TypeImpl *target_type)
     return false;
 }
 
+bool object_is_type_str(Object *obj, const char *typename)
+{
+    TypeImpl *target_type = type_get_by_name(typename);
+    return !target_type || type_is_ancestor(obj->class->type, target_type);
+}
+
 static bool object_is_type(Object *obj, TypeImpl *target_type)
 {
     return !target_type || type_is_ancestor(obj->class->type, target_type);
#9 lore raw

PATCH 3/5 qdev: export the bus reset interface

In reply to Liu Ping Fan
---
 hw/qdev.c |   17 ++++++++++++-----
 hw/qdev.h |    2 ++
 2 files changed, 14 insertions(+), 5 deletions(-)
hw/qdev.c +12 -5
index d2100a1..f7983e4 100644
@@ -249,11 +249,9 @@ static int qdev_reset_one(DeviceState *dev, void *opaque)
 
 static int qbus_reset_one(BusState *bus, void *opaque)
 {
-    BusClass *bc = BUS_GET_CLASS(bus);
-    if (bc->reset) {
-        return bc->reset(bus);
-    }
-    return 0;
+    int ret;
+    ret = bus_reset(bus);
+    return ret;
 }
 
 void qdev_reset_all(DeviceState *dev)
@@ -766,6 +764,15 @@ void device_reset(DeviceState *dev)
     }
 }
 
+int bus_reset(BusState *bus)
+{
+    BusClass *bc = BUS_GET_CLASS(bus);
+    if (bc->reset) {
+        return bc->reset(bus);
+    }
+    return 0;
+}
+
 Object *qdev_get_machine(void)
 {
     static Object *dev;
hw/qdev.h +2 -0
index aecc69e..5f88b4b 100644
@@ -356,6 +356,8 @@ void qdev_machine_init(void);
  */
 void device_reset(DeviceState *dev);
 
+int bus_reset(BusState *bus);
+
 const VMStateDescription *qdev_get_vmsd(DeviceState *dev);
 
 const char *qdev_fw_name(DeviceState *dev);
Signature · 1 line
1.7.4.4
#10 lore raw

Re: [Qemu-devel] [PATCH 3/5] qdev: export the bus reset interface

Il 10/07/2012 08:16, Liu Ping Fan ha scritto:

Quoted 27 lines
---
 hw/qdev.c |   17 ++++++++++++-----
 hw/qdev.h |    2 ++
 2 files changed, 14 insertions(+), 5 deletions(-)
hw/qdev.c +3 -5
index d2100a1..f7983e4 100644
@@ -249,11 +249,9 @@ static int qdev_reset_one(DeviceState *dev, void *opaque)
 
 static int qbus_reset_one(BusState *bus, void *opaque)
 {
-    BusClass *bc = BUS_GET_CLASS(bus);
-    if (bc->reset) {
-        return bc->reset(bus);
-    }
-    return 0;
+    int ret;
+    ret = bus_reset(bus);
+    return ret;
 }
 
 void qdev_reset_all(DeviceState *dev)
@@ -766,6 +764,15 @@ void device_reset(DeviceState *dev)
     }

hw/qdev.c void device_reset(DeviceState *dev) · line 774

Quoted 10 lines
hw/qdev.c +8 -0
 }
 
+int bus_reset(BusState *bus)
+{
+    BusClass *bc = BUS_GET_CLASS(bus);
+    if (bc->reset) {
+        return bc->reset(bus);
+    }
+    return 0;
+}

Two comments:

1) Is this correct? Resetting a bus should reset all the children before resetting the bus itself.

2) Does it make sense to export it, since we're going towards removing unnecessary buses?

Paolo

Quoted 18 lines
hw/qdev.c +1 -0
+
 Object *qdev_get_machine(void)
 {
     static Object *dev;
hw/qdev.h +2 -0
index aecc69e..5f88b4b 100644
@@ -356,6 +356,8 @@ void qdev_machine_init(void);
  */
 void device_reset(DeviceState *dev);
 
+int bus_reset(BusState *bus);
+
 const VMStateDescription *qdev_get_vmsd(DeviceState *dev);
 
 const char *qdev_fw_name(DeviceState *dev);
#11 lore raw

PATCH 4/5 qom-cpu: during cpu reset, it will reset its child

In reply to Liu Ping Fan

This will give the embeded logic module, such as apic has the opportunity to reset.

---
 qom/cpu.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
qom/cpu.c +16 -0
index 5b36046..6aea8e6 100644
@@ -20,10 +20,26 @@
 
 #include "qemu/cpu.h"
 #include "qemu-common.h"
+#include "hw/qdev.h"
+
+static int cpu_reset_kid(Object *child, void *opaque)
+{
+    if (object_is_type_str(child, TYPE_DEVICE)) {
+        device_reset(DEVICE(child));
+    } else if (object_is_type_str(child, TYPE_BUS)) {
+        bus_reset(BUS(child));
+    } else {
+        printf("cpu's child must be DEVICE or BUS");
+        abort();
+    }
+    return 0;
+}
 
 void cpu_reset(CPUState *cpu)
 {
     CPUClass *klass = CPU_GET_CLASS(cpu);
+    Object *obj = OBJECT(cpu);
+    object_child_foreach(obj, cpu_reset_kid, NULL);
 
     if (klass->reset != NULL) {
         (*klass->reset)(cpu);
Signature · 1 line
1.7.4.4
#12 lore raw

Re: [Qemu-devel] [PATCH 4/5] qom-cpu: during cpu reset, it will reset its child

Il 10/07/2012 08:16, Liu Ping Fan ha scritto:

Quoted 26 lines

This will give the embeded logic module, such as apic has the opportunity to reset.

---
 qom/cpu.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
qom/cpu.c +10 -0
index 5b36046..6aea8e6 100644
@@ -20,10 +20,26 @@
 
 #include "qemu/cpu.h"
 #include "qemu-common.h"
+#include "hw/qdev.h"
+
+static int cpu_reset_kid(Object *child, void *opaque)
+{
+    if (object_is_type_str(child, TYPE_DEVICE)) {
+        device_reset(DEVICE(child));
+    } else if (object_is_type_str(child, TYPE_BUS)) {
+        bus_reset(BUS(child));
+    } else {
+        printf("cpu's child must be DEVICE or BUS");

qom/cpu.c line 42

Quoted 10 lines
qom/cpu.c +6 -0
+        abort();
+    }
+    return 0;
+}
 
 void cpu_reset(CPUState *cpu)
 {
     CPUClass *klass = CPU_GET_CLASS(cpu);
+    Object *obj = OBJECT(cpu);
+    object_child_foreach(obj, cpu_reset_kid, NULL);

Ok, now I see what you want to do. Next time, please add meaningful commit messages to all patches in the series, even those that only add infrastructure.

It really looks like time is ripe to make CPUs children of Device, so you can just use qdev_reset_all to reset the CPU.

Paolo

Quoted 3 lines
qom/cpu.c +0 -0
     if (klass->reset != NULL) {
         (*klass->reset)(cpu);
 
#13 lore raw

Re: [Qemu-devel] [PATCH 4/5] qom-cpu: during cpu reset, it will reset its child

Am 10.07.2012 10:41, schrieb Paolo Bonzini:

Quoted 42 lines

Il 10/07/2012 08:16, Liu Ping Fan ha scritto:

Quoted 26 lines

This will give the embeded logic module, such as apic has the opportunity to reset.

---
 qom/cpu.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
qom/cpu.c +10 -0
index 5b36046..6aea8e6 100644
@@ -20,10 +20,26 @@
 
 #include "qemu/cpu.h"
 #include "qemu-common.h"
+#include "hw/qdev.h"
+
+static int cpu_reset_kid(Object *child, void *opaque)
+{
+    if (object_is_type_str(child, TYPE_DEVICE)) {
+        device_reset(DEVICE(child));
+    } else if (object_is_type_str(child, TYPE_BUS)) {
+        bus_reset(BUS(child));
+    } else {
+        printf("cpu's child must be DEVICE or BUS");

qom/cpu.c line 42

Quoted 10 lines
qom/cpu.c +6 -0
+        abort();
+    }
+    return 0;
+}
 
 void cpu_reset(CPUState *cpu)
 {
     CPUClass *klass = CPU_GET_CLASS(cpu);
+    Object *obj = OBJECT(cpu);
+    object_child_foreach(obj, cpu_reset_kid, NULL);

Ok, now I see what you want to do. Next time, please add meaningful commit messages to all patches in the series, even those that only add infrastructure.

Quoted 2 lines

It really looks like time is ripe to make CPUs children of Device, so you can just use qdev_reset_all to reset the CPU.

While we agree on that goal, the way there has proven controversial, please review and comment on the two approaches around.

One thing we definitely need to do is to split up qdev.h.

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
#14 lore raw

Re: [Qemu-devel] [PATCH 4/5] qom-cpu: during cpu reset, it will reset its child

Quoted 43 lines · Andreas Färber

Am 10.07.2012 10:41, schrieb Paolo Bonzini:

Quoted 42 lines

Il 10/07/2012 08:16, Liu Ping Fan ha scritto:

Quoted 26 lines

This will give the embeded logic module, such as apic has the opportunity to reset.

---
 qom/cpu.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
qom/cpu.c +10 -0
index 5b36046..6aea8e6 100644
@@ -20,10 +20,26 @@
 
 #include "qemu/cpu.h"
 #include "qemu-common.h"
+#include "hw/qdev.h"
+
+static int cpu_reset_kid(Object *child, void *opaque)
+{
+    if (object_is_type_str(child, TYPE_DEVICE)) {
+        device_reset(DEVICE(child));
+    } else if (object_is_type_str(child, TYPE_BUS)) {
+        bus_reset(BUS(child));
+    } else {
+        printf("cpu's child must be DEVICE or BUS");

qom/cpu.c line 42

Quoted 10 lines
qom/cpu.c +6 -0
+        abort();
+    }
+    return 0;
+}
 
 void cpu_reset(CPUState *cpu)
 {
     CPUClass *klass = CPU_GET_CLASS(cpu);
+    Object *obj = OBJECT(cpu);
+    object_child_foreach(obj, cpu_reset_kid, NULL);

Ok, now I see what you want to do. Next time, please add meaningful commit messages to all patches in the series, even those that only add infrastructure.

Quoted 8 lines
Quoted 2 lines

It really looks like time is ripe to make CPUs children of Device, so you can just use qdev_reset_all to reset the CPU.

While we agree on that goal, the way there has proven controversial, please review and comment on the two approaches around.

One thing we definitely need to do is to split up qdev.h.

Could you remember the main topic about these? I miss these discussion.

Thanks,
pingfan

Quoted 7 lines

Andreas

--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

#15 lore raw

Re: [Qemu-devel] [PATCH 4/5] qom-cpu: during cpu reset, it will reset its child

Quoted 47 lines · liu ping fan
Quoted 46 lines · Andreas Färber

Am 10.07.2012 10:41, schrieb Paolo Bonzini:

Quoted 44 lines

Il 10/07/2012 08:16, Liu Ping Fan ha scritto:

Quoted 26 lines

This will give the embeded logic module, such as apic has the opportunity to reset.

---
  qom/cpu.c |   16 ++++++++++++++++
  1 files changed, 16 insertions(+), 0 deletions(-)
qom/cpu.c +10 -0
index 5b36046..6aea8e6 100644
@@ -20,10 +20,26 @@
 
  #include "qemu/cpu.h"
  #include "qemu-common.h"
+#include "hw/qdev.h"
+
+static int cpu_reset_kid(Object *child, void *opaque)
+{
+    if (object_is_type_str(child, TYPE_DEVICE)) {
+        device_reset(DEVICE(child));
+    } else if (object_is_type_str(child, TYPE_BUS)) {
+        bus_reset(BUS(child));
+    } else {
+        printf("cpu's child must be DEVICE or BUS");

qom/cpu.c line 42

Quoted 10 lines
qom/cpu.c +6 -0
+        abort();
+    }
+    return 0;
+}
 
  void cpu_reset(CPUState *cpu)
  {
      CPUClass *klass = CPU_GET_CLASS(cpu);
+    Object *obj = OBJECT(cpu);
+    object_child_foreach(obj, cpu_reset_kid, NULL);

Ok, now I see what you want to do. Next time, please add meaningful commit messages to all patches in the series, even those that only add infrastructure.

It really looks like time is ripe to make CPUs children of Device, so you can just use qdev_reset_all to reset the CPU.

Quoted 6 lines
Quoted 5 lines

While we agree on that goal, the way there has proven controversial, please review and comment on the two approaches around.

One thing we definitely need to do is to split up qdev.h.

Could you remember the main topic about these? I miss these discussion.

http://lists.gnu.org/archive/html/qemu-devel/2012-06/msg03912.html
the rest was on irc

Quoted 11 lines

Thanks,
pingfan

Quoted 7 lines

Andreas

--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

Signature · 2 lines
-----
 Igor
#16 lore raw

Re: [Qemu-devel] [PATCH 4/5] qom-cpu: during cpu reset, it will reset its child

In reply to Paolo Bonzini
Quoted 32 lines · Paolo Bonzini

Il 10/07/2012 08:16, Liu Ping Fan ha scritto:

Quoted 31 lines

This will give the embeded logic module, such as apic has the opportunity to reset.

---
 qom/cpu.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
qom/cpu.c +14 -0
index 5b36046..6aea8e6 100644
@@ -20,10 +20,26 @@
 
 #include "qemu/cpu.h"
 #include "qemu-common.h"
+#include "hw/qdev.h"
+
+static int cpu_reset_kid(Object *child, void *opaque)
+{
+    if (object_is_type_str(child, TYPE_DEVICE)) {
+        device_reset(DEVICE(child));
+    } else if (object_is_type_str(child, TYPE_BUS)) {
+        bus_reset(BUS(child));
+    } else {
+        printf("cpu's child must be DEVICE or BUS");
+        abort();
+    }
+    return 0;
+}
 
Quoted 10 lines

qom/cpu.c line 42

Quoted 5 lines
qom/cpu.c +2 -0
 void cpu_reset(CPUState *cpu)
 {
     CPUClass *klass = CPU_GET_CLASS(cpu);
+    Object *obj = OBJECT(cpu);
+    object_child_foreach(obj, cpu_reset_kid, NULL);

Ok, now I see what you want to do. Next time, please add meaningful commit messages to all patches in the series, even those that only add infrastructure.

OK, I will.

Quoted 3 lines

It really looks like time is ripe to make CPUs children of Device, so you can just use qdev_reset_all to reset the CPU.

Change CPUState as child of Device? It is cool, but I think it will a huge work with argue.

Quoted 7 lines

Paolo

Quoted 3 lines
qom/cpu.c +0 -0
     if (klass->reset != NULL) {
         (*klass->reset)(cpu);
 
#17 lore raw

Re: [Qemu-devel] [PATCH 4/5] qom-cpu: during cpu reset, it will reset its child

Il 11/07/2012 03:17, liu ping fan ha scritto:

Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

It really looks like time is ripe to make CPUs children of Device, so you can just use qdev_reset_all to reset the CPU.

Change CPUState as child of Device? It is cool, but I think it will a huge work with argue.

Luckily other people (Igor, Andreas, Anthony) are already working on that.

Paolo

#18 lore raw

PATCH 5/5 apic: create apic as a child of cpu, not system_bus any longer

In reply to Liu Ping Fan
---
 hw/pc.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
hw/pc.c +5 -5
index c7e9ab3..8df58c9 100644
@@ -886,17 +886,17 @@ DeviceState *cpu_get_current_apic(void)
     }
 }
 
-static DeviceState *apic_init(void *env, uint8_t apic_id)
+static DeviceState *apic_init(void *cpu, void *env, uint8_t apic_id)
 {
     DeviceState *dev;
     static int apic_mapped;
 
     if (kvm_irqchip_in_kernel()) {
-        dev = qdev_create(NULL, "kvm-apic");
+        dev = qdev_create_kid(OBJECT(cpu), "kvm-apic");
     } else if (xen_enabled()) {
-        dev = qdev_create(NULL, "xen-apic");
+        dev = qdev_create_kid(OBJECT(cpu), "xen-apic");
     } else {
-        dev = qdev_create(NULL, "apic");
+        dev = qdev_create_kid(OBJECT(cpu), "apic");
     }
 
     qdev_prop_set_uint8(dev, "id", apic_id);
@@ -945,7 +945,7 @@ static X86CPU *pc_new_cpu(const char *cpu_model)
     }
     env = &cpu->env;
     if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) {
-        env->apic_state = apic_init(env, env->cpuid_apic_id);
+        env->apic_state = apic_init(cpu, env, env->cpuid_apic_id);
     }
     qemu_register_reset(pc_cpu_reset, cpu);
     pc_cpu_reset(cpu);
Signature · 1 line
1.7.4.4
#19 lore raw

Re: [Qemu-devel] [PATCH 5/5] apic: create apic as a child of cpu, not system_bus any longer

Il 10/07/2012 08:16, Liu Ping Fan ha scritto:

Quoted 19 lines
---
 hw/pc.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
hw/pc.c +1 -1
index c7e9ab3..8df58c9 100644
@@ -886,17 +886,17 @@ DeviceState *cpu_get_current_apic(void)
     }
 }
 
-static DeviceState *apic_init(void *env, uint8_t apic_id)
+static DeviceState *apic_init(void *cpu, void *env, uint8_t apic_id)
 {
     DeviceState *dev;
     static int apic_mapped;
 

hw/pc.c DeviceState *cpu_get_current_apic(void) · line 900

Quoted 10 lines
hw/pc.c +3 -3
     if (kvm_irqchip_in_kernel()) {
-        dev = qdev_create(NULL, "kvm-apic");
+        dev = qdev_create_kid(OBJECT(cpu), "kvm-apic");
     } else if (xen_enabled()) {
-        dev = qdev_create(NULL, "xen-apic");
+        dev = qdev_create_kid(OBJECT(cpu), "xen-apic");
     } else {
-        dev = qdev_create(NULL, "apic");
+        dev = qdev_create_kid(OBJECT(cpu), "apic");
     }

Does it make sense instead to do this in the realize method of the CPU?

Paolo

Quoted 12 lines
hw/pc.c +1 -1
     qdev_prop_set_uint8(dev, "id", apic_id);
@@ -945,7 +945,7 @@ static X86CPU *pc_new_cpu(const char *cpu_model)
     }
     env = &cpu->env;
     if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) {
-        env->apic_state = apic_init(env, env->cpuid_apic_id);
+        env->apic_state = apic_init(cpu, env, env->cpuid_apic_id);
     }
     qemu_register_reset(pc_cpu_reset, cpu);
     pc_cpu_reset(cpu);
#20 lore raw

Re: [Qemu-devel] [PATCH 5/5] apic: create apic as a child of cpu, not system_bus any longer

Am 10.07.2012 10:45, schrieb Paolo Bonzini:

Quoted 20 lines

Il 10/07/2012 08:16, Liu Ping Fan ha scritto:

Quoted 19 lines
---
 hw/pc.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
hw/pc.c +1 -1
index c7e9ab3..8df58c9 100644
@@ -886,17 +886,17 @@ DeviceState *cpu_get_current_apic(void)
     }
 }
 
-static DeviceState *apic_init(void *env, uint8_t apic_id)
+static DeviceState *apic_init(void *cpu, void *env, uint8_t apic_id)
 {
     DeviceState *dev;
     static int apic_mapped;
 
Quoted 12 lines

hw/pc.c DeviceState *cpu_get_current_apic(void) · line 900

Quoted 10 lines
hw/pc.c +3 -3
     if (kvm_irqchip_in_kernel()) {
-        dev = qdev_create(NULL, "kvm-apic");
+        dev = qdev_create_kid(OBJECT(cpu), "kvm-apic");
     } else if (xen_enabled()) {
-        dev = qdev_create(NULL, "xen-apic");
+        dev = qdev_create_kid(OBJECT(cpu), "xen-apic");
     } else {
-        dev = qdev_create(NULL, "apic");
+        dev = qdev_create_kid(OBJECT(cpu), "apic");
     }

Does it make sense instead to do this in the realize method of the CPU?

Igor was working on patches to do that. We ran into other design issues on that road, yesterday I made a proposal how we might proceed with his approach:

http://lists.nongnu.org/archive/html/qemu-devel/2012-07/msg00992.html

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
#21 lore raw

Re: [Qemu-devel] [PATCH 5/5] apic: create apic as a child of cpu, not system_bus any longer

Quoted 34 lines · Andreas Färber

Am 10.07.2012 10:45, schrieb Paolo Bonzini:

Quoted 20 lines

Il 10/07/2012 08:16, Liu Ping Fan ha scritto:

Quoted 19 lines
---
  hw/pc.c |   10 +++++-----
  1 files changed, 5 insertions(+), 5 deletions(-)
hw/pc.c +1 -1
index c7e9ab3..8df58c9 100644
@@ -886,17 +886,17 @@ DeviceState *cpu_get_current_apic(void)
      }
  }
 
-static DeviceState *apic_init(void *env, uint8_t apic_id)
+static DeviceState *apic_init(void *cpu, void *env, uint8_t apic_id)
  {
      DeviceState *dev;
      static int apic_mapped;
 
Quoted 12 lines

hw/pc.c DeviceState *cpu_get_current_apic(void) · line 900

Quoted 10 lines
hw/pc.c +3 -3
      if (kvm_irqchip_in_kernel()) {
-        dev = qdev_create(NULL, "kvm-apic");
+        dev = qdev_create_kid(OBJECT(cpu), "kvm-apic");
      } else if (xen_enabled()) {
-        dev = qdev_create(NULL, "xen-apic");
+        dev = qdev_create_kid(OBJECT(cpu), "xen-apic");
      } else {
-        dev = qdev_create(NULL, "apic");
+        dev = qdev_create_kid(OBJECT(cpu), "apic");
      }

Does it make sense instead to do this in the realize method of the CPU?

Quoted 7 lines

Igor was working on patches to do that. We ran into other design issues on that road, yesterday I made a proposal how we might proceed with his approach:

http://lists.nongnu.org/archive/html/qemu-devel/2012-07/msg00992.html

Andreas

I was trying to put APIC by-value inside of X86_CPU and do in-place initialization in x86_cpu_initfn(), but that has it's own drawbacks:
1. currently all apic flavors have common instance sizeof(APICCommonState) that could be used as a way to reserve space in CPUX86State. But they could diverge and create problems later when nobody remembers that sizeof(whatever apic) must be equal to sizeof(APICCommonState)
2. it won't solve OOM anyway because of a initfn could fail due to OOM in any object_property_add() call

So if not-inplace apic creation in realize() is acceptable alternative then I'd like to respin apic patches with this change.

Signature · 2 lines
-----
 Igor