Skip to contentSkip to conversation

cpu: make a child of DeviceState

PATCH In review Igor Mammedov 7 participants 19 messages Aug 19, 2012 – Aug 21, 2012

lore
Share & tools
lore
#0 lore raw

v2 cover cpu: make a child of DeviceState

this is th 3rd approach to make CPU a child of DeviceState for both kinds of targets *-user and *-softmmu. It seems with current state of qemu it doesn't take too much effort to make it compile. Please check if it doesn't break something on other targets/archs/hosts than i386.

what's tested:
- compile tested building all targets on FC17x64 host.
- briefly tested i386 user and softmmu targets

Anthony Liguori (1):
qdev: split up header so it can be used in cpu.h

Igor Mammedov (4):
move qemu_irq typedef out of cpu-common.h qapi-types.h doesn't really need to include qemu-common.h cleanup error.h, included qapi-types.h aready has stdbool.h make CPU a child of DeviceState

 error.h               |    1 -
 hw/arm-misc.h         |    1 +
 hw/bt.h               |    2 +
 hw/devices.h          |    2 +
 hw/irq.h              |    2 +
 hw/mc146818rtc.c      |    1 +
 hw/omap.h             |    1 +
 hw/qdev-addr.c        |    1 +
 hw/qdev-core.h        |  240 ++++++++++++++++++++++++++++++++
 hw/qdev-monitor.h     |   16 ++
 hw/qdev-properties.c  |    1 +
 hw/qdev-properties.h  |  128 +++++++++++++++++
 hw/qdev.c             |    1 +
 hw/qdev.h             |  371 +------------------------------------------------
 hw/soc_dma.h          |    1 +
 hw/xen.h              |    1 +
 include/qemu/cpu.h    |    6 +-
 qemu-common.h         |    1 -
 scripts/qapi-types.py |    2 +-
 sysemu.h              |    1 +
 20 files changed, 407 insertions(+), 373 deletions(-)
 create mode 100644 hw/qdev-core.h
 create mode 100644 hw/qdev-monitor.h
 create mode 100644 hw/qdev-properties.h
#1 lore raw

PATCH v2 1/5 move qemu_irq typedef out of cpu-common.h

it's necessary for making CPU child of DEVICE without causing circular header deps.

---
 hw/arm-misc.h |    1 +
 hw/bt.h       |    2 ++
 hw/devices.h  |    2 ++
 hw/irq.h      |    2 ++
 hw/omap.h     |    1 +
 hw/soc_dma.h  |    1 +
 hw/xen.h      |    1 +
 qemu-common.h |    1 -
 sysemu.h      |    1 +
 9 files changed, 11 insertions(+), 1 deletions(-)
hw/arm-misc.h +1 -0
index bdd8fec..b13aa59 100644
@@ -12,6 +12,7 @@
 #define ARM_MISC_H 1
 
 #include "memory.h"
+#include "hw/irq.h"
 
 /* The CPU is also modeled as an interrupt controller.  */
 #define ARM_PIC_CPU_IRQ 0
hw/bt.h +2 -0
index a48b8d4..ebf6a37 100644
@@ -23,6 +23,8 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "hw/irq.h"
+
 /* BD Address */
 typedef struct {
     uint8_t b[6];
hw/devices.h +2 -0
index 1a55c1e..c60bcab 100644
@@ -1,6 +1,8 @@
 #ifndef QEMU_DEVICES_H
 #define QEMU_DEVICES_H
 
+#include "hw/irq.h"
+
 /* ??? Not all users of this file can include cpu-common.h.  */
 struct MemoryRegion;
 
hw/irq.h +2 -0
index 56c55f0..1339a3a 100644
@@ -3,6 +3,8 @@
 
 /* Generic IRQ/GPIO pin infrastructure.  */
 
+typedef struct IRQState *qemu_irq;
+
 typedef void (*qemu_irq_handler)(void *opaque, int n, int level);
 
 void qemu_set_irq(qemu_irq irq, int level);
hw/omap.h +1 -0
index 413851b..8b08462 100644
@@ -19,6 +19,7 @@
 #ifndef hw_omap_h
 #include "memory.h"
 # define hw_omap_h		"omap.h"
+#include "hw/irq.h"
 
 # define OMAP_EMIFS_BASE	0x00000000
 # define OMAP2_Q0_BASE		0x00000000
hw/soc_dma.h +1 -0
index 904b26c..e386ace 100644
@@ -19,6 +19,7 @@
  */
 
 #include "memory.h"
+#include "hw/irq.h"
 
 struct soc_dma_s;
 struct soc_dma_ch_s;
hw/xen.h +1 -0
index e5926b7..ff11dfd 100644
@@ -8,6 +8,7 @@
  */
 #include <inttypes.h>
 
+#include "hw/irq.h"
 #include "qemu-common.h"
 
 /* xen-machine.c */
qemu-common.h +0 -1
index e5c2bcd..6677a30 100644
@@ -273,7 +273,6 @@ typedef struct PCIEPort PCIEPort;
 typedef struct PCIESlot PCIESlot;
 typedef struct MSIMessage MSIMessage;
 typedef struct SerialState SerialState;
-typedef struct IRQState *qemu_irq;
 typedef struct PCMCIACardState PCMCIACardState;
 typedef struct MouseTransformInfo MouseTransformInfo;
 typedef struct uWireSlave uWireSlave;
sysemu.h +1 -0
index 65552ac..f765821 100644
@@ -9,6 +9,7 @@
 #include "qapi-types.h"
 #include "notify.h"
 #include "main-loop.h"
+#include "hw/irq.h"
 
 /* vl.c */
 
Signature · 1 line
1.7.1
#6 lore raw

PATCH v2 2/5 qdev: split up header so it can be used in cpu.h

In reply to Igor Mammedov

From: Anthony Liguori <[email protected]>

Header file dependency is a frickin' nightmare right now. cpu.h tends to get included in our 'include everything' header files but qdev also needs to include those headers mainly for qdev-properties since it knows about CharDriverState and friends.

We can solve this for now by splitting out qdev.h along the same lines that we previously split the C file. Then cpu.h just needs to include qdev-core.h

v1->v2:
move qemu_irq typedef out of this patch into a separate one with an additional cleanup of headers to fix build breakage

---
 hw/mc146818rtc.c     |    1 +
 hw/qdev-addr.c       |    1 +
 hw/qdev-core.h       |  240 ++++++++++++++++++++++++++++++++
 hw/qdev-monitor.h    |   16 ++
 hw/qdev-properties.c |    1 +
 hw/qdev-properties.h |  128 +++++++++++++++++
 hw/qdev.c            |    1 +
 hw/qdev.h            |  371 +-------------------------------------------------
 8 files changed, 392 insertions(+), 367 deletions(-)
 create mode 100644 hw/qdev-core.h
 create mode 100644 hw/qdev-monitor.h
 create mode 100644 hw/qdev-properties.h
hw/mc146818rtc.c +1 -0
index 3777f85..3780617 100644
@@ -25,6 +25,7 @@
 #include "qemu-timer.h"
 #include "sysemu.h"
 #include "mc146818rtc.h"
+#include "qapi/qapi-visit-core.h"
 
 #ifdef TARGET_I386
 #include "apic.h"
hw/qdev-addr.c +1 -0
index b711b6b..5b5d38f 100644
@@ -1,6 +1,7 @@
 #include "qdev.h"
 #include "qdev-addr.h"
 #include "targphys.h"
+#include "qapi/qapi-visit-core.h"
 
 /* --- target physical address --- */
 
hw/qdev-core.h new file +240 -0

240 lines not on this page · raw message

hw/qdev-monitor.h new file +16 -0
new file mode 100644
index 0000000..220ceba
@@ -0,0 +1,16 @@
+#ifndef QEMU_QDEV_MONITOR_H
+#define QEMU_QDEV_MONITOR_H
+
+#include "qdev-core.h"
+#include "monitor.h"
+
+/*** monitor commands ***/
+
+void do_info_qtree(Monitor *mon);
+void do_info_qdm(Monitor *mon);
+int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
+int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
+int qdev_device_help(QemuOpts *opts);
+DeviceState *qdev_device_add(QemuOpts *opts);
+
+#endif
hw/qdev-properties.c +1 -0
index 8aca0d4..81d901c 100644
@@ -4,6 +4,7 @@
 #include "blockdev.h"
 #include "hw/block-common.h"
 #include "net/hub.h"
+#include "qapi/qapi-visit-core.h"
 
 void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
 {
hw/qdev-properties.h new file +128 -0

128 lines not on this page · raw message

hw/qdev.c +1 -0
index b5b74b9..36c3e4b 100644
@@ -29,6 +29,7 @@
 #include "qdev.h"
 #include "sysemu.h"
 #include "error.h"
+#include "qapi/qapi-visit-core.h"
 
 int qdev_hotplug = 0;
 static bool qdev_hot_added = false;
hw/qdev.h +4 -367

376 lines not on this page · raw message

Signature · 1 line
1.7.1
#7 lore raw

PATCH v2 3/5 qapi-types.h doesn't really need to include qemu-common.h

In reply to Igor Mammedov

needed to prevent build breakage when CPU becomes a child of DeviceState

---
 scripts/qapi-types.py |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
scripts/qapi-types.py +1 -1
index cf601ae..f34addb 100644
@@ -263,7 +263,7 @@ fdecl.write(mcgen('''
 #ifndef %(guard)s
 #define %(guard)s
 
-#include "qemu-common.h"
+#include <stdbool.h>
 
 ''',
                   guard=guardname(h_file)))
Signature · 1 line
1.7.1
#10 lore raw

PATCH v2 4/5 cleanup error.h, included qapi-types.h aready has stdbool.h

In reply to Igor Mammedov
---
 error.h |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
error.h +0 -1
index 96fc203..643a372 100644
@@ -14,7 +14,6 @@
 
 #include "compiler.h"
 #include "qapi-types.h"
-#include <stdbool.h>
 
 /**
  * A class representing internal errors within QEMU.  An error has a ErrorClass
Signature · 1 line
1.7.1
#13 lore raw

PATCH v2 5/5 make CPU a child of DeviceState

In reply to Igor Mammedov
---
 include/qemu/cpu.h |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
include/qemu/cpu.h +3 -3
index ad706a6..ac44057 100644
@@ -20,7 +20,7 @@
 #ifndef QEMU_CPU_H
 #define QEMU_CPU_H
 
-#include "qemu/object.h"
+#include "hw/qdev-core.h"
 #include "qemu-thread.h"
 
 /**
@@ -46,7 +46,7 @@ typedef struct CPUState CPUState;
  */
 typedef struct CPUClass {
     /*< private >*/
-    ObjectClass parent_class;
+    DeviceClass parent_class;
     /*< public >*/
 
     void (*reset)(CPUState *cpu);
@@ -59,7 +59,7 @@ typedef struct CPUClass {
  */
 struct CPUState {
     /*< private >*/
-    Object parent_obj;
+    DeviceState parent_obj;
     /*< public >*/
 
     struct QemuThread *thread;
Signature · 1 line
1.7.1
#2 lore raw

Re: [Qemu-devel] [PATCH 1/5] move qemu_irq typedef out of cpu-common.h

In reply to Igor Mammedov

Am 20.08.2012 01:39, schrieb Igor Mammedov:

Quoted 108 lines

it's necessary for making CPU child of DEVICE without causing circular header deps.

---
  hw/arm-misc.h |    1 +
  hw/bt.h       |    2 ++
  hw/devices.h  |    2 ++
  hw/irq.h      |    2 ++
  hw/omap.h     |    1 +
  hw/soc_dma.h  |    1 +
  hw/xen.h      |    1 +
  qemu-common.h |    1 -
  sysemu.h      |    1 +
  9 files changed, 11 insertions(+), 1 deletions(-)
hw/arm-misc.h +1 -0
index bdd8fec..b13aa59 100644
@@ -12,6 +12,7 @@
  #define ARM_MISC_H 1
 
  #include "memory.h"
+#include "hw/irq.h"
 
  /* The CPU is also modeled as an interrupt controller.  */
  #define ARM_PIC_CPU_IRQ 0
hw/bt.h +2 -0
index a48b8d4..ebf6a37 100644
@@ -23,6 +23,8 @@
   * along with this program; if not, see <http://www.gnu.org/licenses/>.
   */
 
+#include "hw/irq.h"
+
  /* BD Address */
  typedef struct {
      uint8_t b[6];
hw/devices.h +2 -0
index 1a55c1e..c60bcab 100644
@@ -1,6 +1,8 @@
  #ifndef QEMU_DEVICES_H
  #define QEMU_DEVICES_H
 
+#include "hw/irq.h"
+
  /* ??? Not all users of this file can include cpu-common.h.  */
  struct MemoryRegion;
 
hw/irq.h +2 -0
index 56c55f0..1339a3a 100644
@@ -3,6 +3,8 @@
 
  /* Generic IRQ/GPIO pin infrastructure.  */
 
+typedef struct IRQState *qemu_irq;
+
  typedef void (*qemu_irq_handler)(void *opaque, int n, int level);
 
  void qemu_set_irq(qemu_irq irq, int level);
hw/omap.h +1 -0
index 413851b..8b08462 100644
@@ -19,6 +19,7 @@
  #ifndef hw_omap_h
  #include "memory.h"
  # define hw_omap_h		"omap.h"
+#include "hw/irq.h"
 
  # define OMAP_EMIFS_BASE	0x00000000
  # define OMAP2_Q0_BASE		0x00000000
hw/soc_dma.h +1 -0
index 904b26c..e386ace 100644
@@ -19,6 +19,7 @@
   */
 
  #include "memory.h"
+#include "hw/irq.h"
 
  struct soc_dma_s;
  struct soc_dma_ch_s;
hw/xen.h +1 -0
index e5926b7..ff11dfd 100644
@@ -8,6 +8,7 @@
   */
  #include <inttypes.h>
 
+#include "hw/irq.h"
  #include "qemu-common.h"
 
  /* xen-machine.c */
qemu-common.h +0 -0
index e5c2bcd..6677a30 100644

qemu-common.h typedef struct PCIEPort PCIEPort; · line 278

Quoted 7 lines
qemu-common.h +0 -1
@@ -273,7 +273,6 @@ typedef struct PCIEPort PCIEPort;
  typedef struct PCIESlot PCIESlot;
  typedef struct MSIMessage MSIMessage;
  typedef struct SerialState SerialState;
-typedef struct IRQState *qemu_irq;
  typedef struct PCMCIACardState PCMCIACardState;
  typedef struct MouseTransformInfo MouseTransformInfo;
  typedef struct uWireSlave uWireSlave;

Just move the declaration of qemu_irq to the beginning of qemu-common.h and leave the rest of files untouched. That also fixes the circular dependency.

I already have a patch that does this, so you can integrate it in your series instead of this one.

Quoted 12 lines
sysemu.h +1 -0
index 65552ac..f765821 100644
@@ -9,6 +9,7 @@
  #include "qapi-types.h"
  #include "notify.h"
  #include "main-loop.h"
+#include "hw/irq.h"
 
  /* vl.c */
 
#15 lore raw
In reply to Igor Mammedov

Am 20.08.2012 01:39, schrieb Igor Mammedov:

Quoted 40 lines

this is th 3rd approach to make CPU a child of DeviceState for both kinds of targets *-user and *-softmmu. It seems with current state of qemu it doesn't take too much effort to make it compile. Please check if it doesn't break something on other targets/archs/hosts than i386.

what's tested:
- compile tested building all targets on FC17x64 host.
- briefly tested i386 user and softmmu targets

Anthony Liguori (1):
qdev: split up header so it can be used in cpu.h

Igor Mammedov (4):
move qemu_irq typedef out of cpu-common.h qapi-types.h doesn't really need to include qemu-common.h cleanup error.h, included qapi-types.h aready has stdbool.h make CPU a child of DeviceState

  error.h               |    1 -
  hw/arm-misc.h         |    1 +
  hw/bt.h               |    2 +
  hw/devices.h          |    2 +
  hw/irq.h              |    2 +
  hw/mc146818rtc.c      |    1 +
  hw/omap.h             |    1 +
  hw/qdev-addr.c        |    1 +
  hw/qdev-core.h        |  240 ++++++++++++++++++++++++++++++++
  hw/qdev-monitor.h     |   16 ++
  hw/qdev-properties.c  |    1 +
  hw/qdev-properties.h  |  128 +++++++++++++++++
  hw/qdev.c             |    1 +
  hw/qdev.h             |  371 +------------------------------------------------
  hw/soc_dma.h          |    1 +
  hw/xen.h              |    1 +
  include/qemu/cpu.h    |    6 +-
  qemu-common.h         |    1 -
  scripts/qapi-types.py |    2 +-
  sysemu.h              |    1 +
  20 files changed, 407 insertions(+), 373 deletions(-)
Quoted 4 lines

create mode 100644 hw/qdev-core.h
create mode 100644 hw/qdev-monitor.h
create mode 100644 hw/qdev-properties.h

I'd prefer if you could keep the following simple pattern:

* Start includes in *.c files with config.h (optionally) and qemu-common.h.

* Don't include standard include files which are already included in qemu-common.h

* Don't include qemu-common.h in *.h files.

Regards,

Stefan Weil

#3 lore raw

Re: [Qemu-devel] [PATCH 1/5] move qemu_irq typedef out of cpu-common.h

In reply to Stefan Weil
Quoted 121 lines · On Mon, 20 Aug 2012 06:41:04 +0200 Stefan Weil <[email protected]> wrote:

Am 20.08.2012 01:39, schrieb Igor Mammedov:

Quoted 108 lines

it's necessary for making CPU child of DEVICE without causing circular header deps.

---
  hw/arm-misc.h |    1 +
  hw/bt.h       |    2 ++
  hw/devices.h  |    2 ++
  hw/irq.h      |    2 ++
  hw/omap.h     |    1 +
  hw/soc_dma.h  |    1 +
  hw/xen.h      |    1 +
  qemu-common.h |    1 -
  sysemu.h      |    1 +
  9 files changed, 11 insertions(+), 1 deletions(-)
hw/arm-misc.h +1 -0
index bdd8fec..b13aa59 100644
@@ -12,6 +12,7 @@
  #define ARM_MISC_H 1
 
  #include "memory.h"
+#include "hw/irq.h"
 
  /* The CPU is also modeled as an interrupt controller.  */
  #define ARM_PIC_CPU_IRQ 0
hw/bt.h +2 -0
index a48b8d4..ebf6a37 100644
@@ -23,6 +23,8 @@
   * along with this program; if not, see <http://www.gnu.org/licenses/>.
   */
 
+#include "hw/irq.h"
+
  /* BD Address */
  typedef struct {
      uint8_t b[6];
hw/devices.h +2 -0
index 1a55c1e..c60bcab 100644
@@ -1,6 +1,8 @@
  #ifndef QEMU_DEVICES_H
  #define QEMU_DEVICES_H
 
+#include "hw/irq.h"
+
  /* ??? Not all users of this file can include cpu-common.h.  */
  struct MemoryRegion;
 
hw/irq.h +2 -0
index 56c55f0..1339a3a 100644
@@ -3,6 +3,8 @@
 
  /* Generic IRQ/GPIO pin infrastructure.  */
 
+typedef struct IRQState *qemu_irq;
+
  typedef void (*qemu_irq_handler)(void *opaque, int n, int level);
 
  void qemu_set_irq(qemu_irq irq, int level);
hw/omap.h +1 -0
index 413851b..8b08462 100644
@@ -19,6 +19,7 @@
  #ifndef hw_omap_h
  #include "memory.h"
  # define hw_omap_h		"omap.h"
+#include "hw/irq.h"
 
  # define OMAP_EMIFS_BASE	0x00000000
  # define OMAP2_Q0_BASE		0x00000000
hw/soc_dma.h +1 -0
index 904b26c..e386ace 100644
@@ -19,6 +19,7 @@
   */
 
  #include "memory.h"
+#include "hw/irq.h"
 
  struct soc_dma_s;
  struct soc_dma_ch_s;
hw/xen.h +1 -0
index e5926b7..ff11dfd 100644
@@ -8,6 +8,7 @@
   */
  #include <inttypes.h>
 
+#include "hw/irq.h"
  #include "qemu-common.h"
 
  /* xen-machine.c */
qemu-common.h +0 -0
index e5c2bcd..6677a30 100644

qemu-common.h typedef struct PCIEPort PCIEPort; · line 278

Quoted 7 lines
qemu-common.h +0 -1
@@ -273,7 +273,6 @@ typedef struct PCIEPort PCIEPort;
  typedef struct PCIESlot PCIESlot;
  typedef struct MSIMessage MSIMessage;
  typedef struct SerialState SerialState;
-typedef struct IRQState *qemu_irq;
  typedef struct PCMCIACardState PCMCIACardState;
  typedef struct MouseTransformInfo MouseTransformInfo;
  typedef struct uWireSlave uWireSlave;

Just move the declaration of qemu_irq to the beginning of qemu-common.h and leave the rest of files untouched. That also fixes the circular dependency.

Quoted 3 lines

I already have a patch that does this, so you can integrate it in your series
instead of this one.

No doubt it's more simpler way, but IMHO It's more of a hack than fixing problem.
It works for now but doesn't alleviate problem with header nightmare in qemu, where everything is included in qemu-common.h and everything includes it as well.

Any way if majority prefer simple move, I'll drop this patch in favor of yours.

Quoted 15 lines
Quoted 14 lines
sysemu.h +1 -0
index 65552ac..f765821 100644
@@ -9,6 +9,7 @@
  #include "qapi-types.h"
  #include "notify.h"
  #include "main-loop.h"
+#include "hw/irq.h"
 
  /* vl.c */
 
Signature · 2 lines
Regards,
  Igor
#16 lore raw
In reply to Stefan Weil
Quoted 46 lines · On Mon, 20 Aug 2012 06:52:51 +0200 Stefan Weil <[email protected]> wrote:

Am 20.08.2012 01:39, schrieb Igor Mammedov:

Quoted 40 lines

this is th 3rd approach to make CPU a child of DeviceState for both kinds of targets *-user and *-softmmu. It seems with current state of qemu it doesn't take too much effort to make it compile. Please check if it doesn't break something on other targets/archs/hosts than i386.

what's tested:
- compile tested building all targets on FC17x64 host.
- briefly tested i386 user and softmmu targets

Anthony Liguori (1):
qdev: split up header so it can be used in cpu.h

Igor Mammedov (4):
move qemu_irq typedef out of cpu-common.h qapi-types.h doesn't really need to include qemu-common.h cleanup error.h, included qapi-types.h aready has stdbool.h make CPU a child of DeviceState

  error.h               |    1 -
  hw/arm-misc.h         |    1 +
  hw/bt.h               |    2 +
  hw/devices.h          |    2 +
  hw/irq.h              |    2 +
  hw/mc146818rtc.c      |    1 +
  hw/omap.h             |    1 +
  hw/qdev-addr.c        |    1 +
  hw/qdev-core.h        |  240 ++++++++++++++++++++++++++++++++
  hw/qdev-monitor.h     |   16 ++
  hw/qdev-properties.c  |    1 +
  hw/qdev-properties.h  |  128 +++++++++++++++++
  hw/qdev.c             |    1 +
  hw/qdev.h             |  371 +------------------------------------------------
  hw/soc_dma.h          |    1 +
  hw/xen.h              |    1 +
  include/qemu/cpu.h    |    6 +-
  qemu-common.h         |    1 -
  scripts/qapi-types.py |    2 +-
  sysemu.h              |    1 +
  20 files changed, 407 insertions(+), 373 deletions(-)
Quoted 4 lines

create mode 100644 hw/qdev-core.h
create mode 100644 hw/qdev-monitor.h
create mode 100644 hw/qdev-properties.h

Quoted 4 lines

I'd prefer if you could keep the following simple pattern:

* Start includes in *.c files with config.h (optionally) and qemu-common.h.

Can't agree with you on this. I'd say that every header should be be self sufficient, include other headers if it uses types from them and NOT depend on the position where it's included, it should provide all its own deps.

Quoted 3 lines

* Don't include standard include files which are already included in qemu-common.h

Probably initially qemu-common.h was intended to simplify inclusion of standard headers and glue stuff in multi-os build environment. but it seems to be become misused. It includes now a lot of stuff that is not common to every file it's included in.
Perhaps we should split out of it std includes and glue layer into something like std/host-common.h and case on case basis move out other type definitions that are not common into there appropriate places. Like with qemu_irq.

Quoted 2 lines

* Don't include qemu-common.h in *.h files.

I'm all for it. But it's difficult right now because it tends to be included in a lot of headers that don't really need it and then other headers happens to depend on previous inclusion of it. It's difficult to untangle this in one take, but could be possible in small steps.

[1/1] is a direction that could be used to put type custom types in their proper places. It would be better way long term and help to avoid problems with including one header in another.

Quoted 5 lines

Regards,

Stefan Weil

Signature · 2 lines
Regards,
  Igor
#8 lore raw

Re: [Qemu-devel] [PATCH 3/5] qapi-types.h doesn't really need to include qemu-common.h

In reply to Igor Mammedov
Quoted 12 lines · On Mon, 20 Aug 2012 01:39:37 +0200 Igor Mammedov <[email protected]> wrote:

needed to prevent build breakage when CPU becomes a child of DeviceState

---
 scripts/qapi-types.py |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
scripts/qapi-types.py +0 -0
index cf601ae..f34addb 100644

scripts/qapi-types.py fdecl.write(mcgen(''' · line 266

Quoted 5 lines
scripts/qapi-types.py +1 -1
@@ -263,7 +263,7 @@ fdecl.write(mcgen('''
 #ifndef %(guard)s
 #define %(guard)s
 
-#include "qemu-common.h"
+#include <stdbool.h>

Please, also include <stdint.h>, as int64_t is used in qapi-types.h.

The build doesn't break probably because files including qapi-types.h are including <stdint.h> first.

Quoted 3 lines
scripts/qapi-types.py +0 -0
 ''',
                   guard=guardname(h_file)))
#11 lore raw

Re: [Qemu-devel] [PATCH 4/5] cleanup error.h, included qapi-types.h aready has stdbool.h

In reply to Igor Mammedov
Quoted 10 lines · On Mon, 20 Aug 2012 01:39:38 +0200 Igor Mammedov <[email protected]> wrote:
---
 error.h |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
error.h +0 -0
index 96fc203..643a372 100644

error.h line 17

Quoted 4 lines
error.h +0 -1
@@ -14,7 +14,6 @@
 
 #include "compiler.h"
 #include "qapi-types.h"
-#include <stdbool.h>

Hmm, not good. qapi-types.h includes <stdbool.h> for internal matters, files including qapi-types.h shouldn't rely on this (as they can break if qapi-types.h is changed not to include <stdbool.h>).

You can keep this code as it is.

Quoted 3 lines
error.h +0 -0
 /**
  * A class representing internal errors within QEMU.  An error has a ErrorClass
#4 lore raw

Re: [Qemu-devel] [PATCH 1/5] move qemu_irq typedef out of cpu-common.h

In reply to Igor Mammedov
Quoted 127 lines · Igor Mammedov
Quoted 121 lines · On Mon, 20 Aug 2012 06:41:04 +0200 Stefan Weil <[email protected]> wrote:

Am 20.08.2012 01:39, schrieb Igor Mammedov:

Quoted 108 lines

it's necessary for making CPU child of DEVICE without causing circular header deps.

---
  hw/arm-misc.h |    1 +
  hw/bt.h       |    2 ++
  hw/devices.h  |    2 ++
  hw/irq.h      |    2 ++
  hw/omap.h     |    1 +
  hw/soc_dma.h  |    1 +
  hw/xen.h      |    1 +
  qemu-common.h |    1 -
  sysemu.h      |    1 +
  9 files changed, 11 insertions(+), 1 deletions(-)
hw/arm-misc.h +1 -0
index bdd8fec..b13aa59 100644
@@ -12,6 +12,7 @@
  #define ARM_MISC_H 1
 
  #include "memory.h"
+#include "hw/irq.h"
 
  /* The CPU is also modeled as an interrupt controller.  */
  #define ARM_PIC_CPU_IRQ 0
hw/bt.h +2 -0
index a48b8d4..ebf6a37 100644
@@ -23,6 +23,8 @@
   * along with this program; if not, see <http://www.gnu.org/licenses/>.
   */
 
+#include "hw/irq.h"
+
  /* BD Address */
  typedef struct {
      uint8_t b[6];
hw/devices.h +2 -0
index 1a55c1e..c60bcab 100644
@@ -1,6 +1,8 @@
  #ifndef QEMU_DEVICES_H
  #define QEMU_DEVICES_H
 
+#include "hw/irq.h"
+
  /* ??? Not all users of this file can include cpu-common.h.  */
  struct MemoryRegion;
 
hw/irq.h +2 -0
index 56c55f0..1339a3a 100644
@@ -3,6 +3,8 @@
 
  /* Generic IRQ/GPIO pin infrastructure.  */
 
+typedef struct IRQState *qemu_irq;
+
  typedef void (*qemu_irq_handler)(void *opaque, int n, int level);
 
  void qemu_set_irq(qemu_irq irq, int level);
hw/omap.h +1 -0
index 413851b..8b08462 100644
@@ -19,6 +19,7 @@
  #ifndef hw_omap_h
  #include "memory.h"
  # define hw_omap_h                "omap.h"
+#include "hw/irq.h"
 
  # define OMAP_EMIFS_BASE  0x00000000
  # define OMAP2_Q0_BASE            0x00000000
hw/soc_dma.h +1 -0
index 904b26c..e386ace 100644
@@ -19,6 +19,7 @@
   */
 
  #include "memory.h"
+#include "hw/irq.h"
 
  struct soc_dma_s;
  struct soc_dma_ch_s;
hw/xen.h +1 -0
index e5926b7..ff11dfd 100644
@@ -8,6 +8,7 @@
   */
  #include <inttypes.h>
 
+#include "hw/irq.h"
  #include "qemu-common.h"
 
  /* xen-machine.c */
qemu-common.h +0 -0
index e5c2bcd..6677a30 100644

qemu-common.h typedef struct PCIEPort PCIEPort; · line 278

Quoted 7 lines
qemu-common.h +0 -1
@@ -273,7 +273,6 @@ typedef struct PCIEPort PCIEPort;
  typedef struct PCIESlot PCIESlot;
  typedef struct MSIMessage MSIMessage;
  typedef struct SerialState SerialState;
-typedef struct IRQState *qemu_irq;
  typedef struct PCMCIACardState PCMCIACardState;
  typedef struct MouseTransformInfo MouseTransformInfo;
  typedef struct uWireSlave uWireSlave;

Just move the declaration of qemu_irq to the beginning of qemu-common.h and leave the rest of files untouched. That also fixes the circular dependency.

Quoted 3 lines

I already have a patch that does this, so you can integrate it in your series
instead of this one.

Quoted 7 lines

No doubt it's more simpler way, but IMHO It's more of a hack than fixing problem.
It works for now but doesn't alleviate problem with header nightmare in qemu, where everything is included in qemu-common.h and everything includes it as well.

Any way if majority prefer simple move, I'll drop this patch in favor of yours.

I like Igor's approach more.

Quoted 21 lines
Quoted 13 lines
Quoted 13 lines
sysemu.h +1 -0
index 65552ac..f765821 100644
@@ -9,6 +9,7 @@
  #include "qapi-types.h"
  #include "notify.h"
  #include "main-loop.h"
+#include "hw/irq.h"
 
Quoted 3 lines

sysemu.h line 15

Quoted 2 lines
sysemu.h +0 -0
  /* vl.c */
 

--
Regards,
Igor

#9 lore raw

Re: [Qemu-devel] [PATCH 3/5] qapi-types.h doesn't really need to include qemu-common.h

In reply to Luiz Capitulino
Quoted 18 lines · On Mon, 20 Aug 2012 12:22:10 -0300 Luiz Capitulino <[email protected]>…
Quoted 15 lines · On Mon, 20 Aug 2012 01:39:37 +0200 Igor Mammedov <[email protected]> wrote:

needed to prevent build breakage when CPU becomes a child of DeviceState

---
 scripts/qapi-types.py |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
scripts/qapi-types.py +0 -0
index cf601ae..f34addb 100644
@@ -263,7 +263,7 @@ fdecl.write(mcgen('''
 #ifndef %(guard)s
 #define %(guard)s
 
Quoted 7 lines

scripts/qapi-types.py fdecl.write(mcgen(''' · line 266

Quoted 2 lines
scripts/qapi-types.py +1 -1
-#include "qemu-common.h"
+#include <stdbool.h>

Please, also include <stdint.h>, as int64_t is used in qapi-types.h.

The build doesn't break probably because files including qapi-types.h are including <stdint.h> first.

Thanks for suggestion. I'll fix it for next respin.

Quoted 5 lines
Quoted 4 lines
scripts/qapi-types.py +0 -0
 ''',
                   guard=guardname(h_file)))
Signature · 2 lines
Regards,
  Igor
#12 lore raw

Re: [Qemu-devel] [Xen-devel] [PATCH 4/5] cleanup error.h, included qapi-types.h aready has stdbool.h

In reply to Luiz Capitulino
Quoted 22 lines · On Mon, 20 Aug 2012 12:28:05 -0300 Luiz Capitulino <[email protected]>…
Quoted 10 lines · On Mon, 20 Aug 2012 01:39:38 +0200 Igor Mammedov <[email protected]> wrote:
---
 error.h |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
error.h +0 -0
index 96fc203..643a372 100644

error.h line 17

Quoted 4 lines
error.h +0 -1
@@ -14,7 +14,6 @@
 
 #include "compiler.h"
 #include "qapi-types.h"
-#include <stdbool.h>

Hmm, not good. qapi-types.h includes <stdbool.h> for internal matters, files including qapi-types.h shouldn't rely on this (as they can break if qapi-types.h is changed not to include <stdbool.h>).

Quoted 1 line

You can keep this code as it is.

Agreed, I'll drop this patch.

Quoted 10 lines

error.h line 19

Quoted 4 lines
error.h +0 -0
 /**
  * A class representing internal errors within QEMU.  An error has a ErrorClass

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Signature · 2 lines
Regards,
  Igor
#17 lore raw

[Qemu-devel] [RFC] How should QEMU code handle include statements (was: Re: [PATCH 0/5 v2] cpu: make a child of DeviceState)

In reply to Igor Mammedov

Am 20.08.2012 13:47, schrieb Igor Mammedov:

Quoted 11 lines
Quoted 4 lines · On Mon, 20 Aug 2012 06:52:51 +0200 Stefan Weil<[email protected]> wrote:

I'd prefer if you could keep the following simple pattern:

* Start includes in *.c files with config.h (optionally) and qemu-common.h.

Can't agree with you on this. I'd say that every header should be be self sufficient, include other headers if it uses types from them and NOT depend on the position where it's included, it should provide all its own deps.

Quoted 2 lines

* Don't include standard include files which are already included in qemu-common.h

Quoted 8 lines

Probably initially qemu-common.h was intended to simplify inclusion of standard headers and glue stuff in multi-os build environment. but it seems to be become misused. It includes now a lot of stuff that is not common to every file it's included in.
Perhaps we should split out of it std includes and glue layer into something like std/host-common.h and case on case basis move out other type definitions that are not common into there appropriate places. Like with qemu_irq.

There are several possible strategies regarding include statements:

1. Each header file which represents some public interface must include any header file which it depends on, so applications which include xxx.h can rely on the fact that they won't need anything else to compile xxx.h.

To minimize dependencies, this rule can be extended: each header file must not include unneeded header files.

Usually header files in /usr/include are built according to these rules.

2. There is one header file (or a small set of header files) which includes a basic set of features which normal code needs. Any C code file starts by including this header file.

Other header files can rely on the fact that the basic set of features are already available.

3. In a modification of (2), each header file can include the basic header file(s).

4. The status quo of QEMU is a wild mixture of those strategies.

IMHO, there should be a consensus about the strategy which is used for QEMU code.

While I personally prefer (1) and used it for my first contributions, QEMU introduced qemu-common.h. I had the impression that from then on QEMU preferred strategy (2). Obviously not everybody shares that impression.

Which strategy / rule do we want to use for QEMU code?

Regards,

Stefan Weil

#5 lore raw

Re: [Qemu-devel] [PATCH 1/5] move qemu_irq typedef out of cpu-common.h

In reply to Blue Swirl
Quoted 134 lines · Blue Swirl
Quoted 133 lines · Igor Mammedov
Quoted 121 lines · On Mon, 20 Aug 2012 06:41:04 +0200 Stefan Weil <[email protected]> wrote:

Am 20.08.2012 01:39, schrieb Igor Mammedov:

Quoted 108 lines

it's necessary for making CPU child of DEVICE without causing circular header deps.

---
  hw/arm-misc.h |    1 +
  hw/bt.h       |    2 ++
  hw/devices.h  |    2 ++
  hw/irq.h      |    2 ++
  hw/omap.h     |    1 +
  hw/soc_dma.h  |    1 +
  hw/xen.h      |    1 +
  qemu-common.h |    1 -
  sysemu.h      |    1 +
  9 files changed, 11 insertions(+), 1 deletions(-)
hw/arm-misc.h +1 -0
index bdd8fec..b13aa59 100644
@@ -12,6 +12,7 @@
  #define ARM_MISC_H 1
 
  #include "memory.h"
+#include "hw/irq.h"
 
  /* The CPU is also modeled as an interrupt controller.  */
  #define ARM_PIC_CPU_IRQ 0
hw/bt.h +2 -0
index a48b8d4..ebf6a37 100644
@@ -23,6 +23,8 @@
   * along with this program; if not, see <http://www.gnu.org/licenses/>.
   */
 
+#include "hw/irq.h"
+
  /* BD Address */
  typedef struct {
      uint8_t b[6];
hw/devices.h +2 -0
index 1a55c1e..c60bcab 100644
@@ -1,6 +1,8 @@
  #ifndef QEMU_DEVICES_H
  #define QEMU_DEVICES_H
 
+#include "hw/irq.h"
+
  /* ??? Not all users of this file can include cpu-common.h.  */
  struct MemoryRegion;
 
hw/irq.h +2 -0
index 56c55f0..1339a3a 100644
@@ -3,6 +3,8 @@
 
  /* Generic IRQ/GPIO pin infrastructure.  */
 
+typedef struct IRQState *qemu_irq;
+
  typedef void (*qemu_irq_handler)(void *opaque, int n, int level);
 
  void qemu_set_irq(qemu_irq irq, int level);
hw/omap.h +1 -0
index 413851b..8b08462 100644
@@ -19,6 +19,7 @@
  #ifndef hw_omap_h
  #include "memory.h"
  # define hw_omap_h                "omap.h"
+#include "hw/irq.h"
 
  # define OMAP_EMIFS_BASE  0x00000000
  # define OMAP2_Q0_BASE            0x00000000
hw/soc_dma.h +1 -0
index 904b26c..e386ace 100644
@@ -19,6 +19,7 @@
   */
 
  #include "memory.h"
+#include "hw/irq.h"
 
  struct soc_dma_s;
  struct soc_dma_ch_s;
hw/xen.h +1 -0
index e5926b7..ff11dfd 100644
@@ -8,6 +8,7 @@
   */
  #include <inttypes.h>
 
+#include "hw/irq.h"
  #include "qemu-common.h"
 
  /* xen-machine.c */
qemu-common.h +0 -0
index e5c2bcd..6677a30 100644

qemu-common.h typedef struct PCIEPort PCIEPort; · line 278

Quoted 7 lines
qemu-common.h +0 -1
@@ -273,7 +273,6 @@ typedef struct PCIEPort PCIEPort;
  typedef struct PCIESlot PCIESlot;
  typedef struct MSIMessage MSIMessage;
  typedef struct SerialState SerialState;
-typedef struct IRQState *qemu_irq;
  typedef struct PCMCIACardState PCMCIACardState;
  typedef struct MouseTransformInfo MouseTransformInfo;
  typedef struct uWireSlave uWireSlave;

Just move the declaration of qemu_irq to the beginning of qemu-common.h and leave the rest of files untouched. That also fixes the circular dependency.

Quoted 3 lines

I already have a patch that does this, so you can integrate it in your series
instead of this one.

No doubt it's more simpler way, but IMHO It's more of a hack than fixing problem.
It works for now but doesn't alleviate problem with header nightmare in qemu, where everything is included in qemu-common.h and everything includes it as well.

Quoted 3 lines
Quoted 1 line

Any way if majority prefer simple move, I'll drop this patch in favor of yours.

I like Igor's approach more.

Ack.

We should move away from dumping ground includes like qemu-common in favor of meaningful headers that are explicitly included where needed.

Regards,

Anthony Liguori

Quoted 22 lines
Quoted 22 lines
Quoted 14 lines
Quoted 14 lines
sysemu.h +1 -0
index 65552ac..f765821 100644
@@ -9,6 +9,7 @@
  #include "qapi-types.h"
  #include "notify.h"
  #include "main-loop.h"
+#include "hw/irq.h"
 
Quoted 3 lines

sysemu.h line 15

Quoted 2 lines
sysemu.h +0 -0
  /* vl.c */
 

--
Regards,
Igor

#18 lore raw

Re: [Qemu-devel] [RFC] How should QEMU code handle include statements

In reply to Stefan Weil
Quoted 6 lines · Stefan Weil

While I personally prefer (1) and used it for my first contributions, QEMU introduced qemu-common.h. I had the impression that from then on QEMU preferred strategy (2). Obviously not everybody shares that impression.

Which strategy / rule do we want to use for QEMU code?

(1).

Signature · 1 line
error compiling committee.c: too many arguments to function
#14 lore raw

Re: [Qemu-devel] [PATCH 5/5] make CPU a child of DeviceState

In reply to Igor Mammedov
Quoted 28 lines · Igor Mammedov
---
 include/qemu/cpu.h |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
include/qemu/cpu.h +2 -2
index ad706a6..ac44057 100644
@@ -20,7 +20,7 @@
 #ifndef QEMU_CPU_H
 #define QEMU_CPU_H
 
-#include "qemu/object.h"
+#include "hw/qdev-core.h"
 #include "qemu-thread.h"
 
 /**
@@ -46,7 +46,7 @@ typedef struct CPUState CPUState;
  */
 typedef struct CPUClass {
     /*< private >*/
-    ObjectClass parent_class;
+    DeviceClass parent_class;
     /*< public >*/
 
     void (*reset)(CPUState *cpu);

include/qemu/cpu.h typedef struct CPUClass { · line 65

Quoted 8 lines
include/qemu/cpu.h +1 -1
@@ -59,7 +59,7 @@ typedef struct CPUClass {
  */
 struct CPUState {
     /*< private >*/
-    Object parent_obj;
+    DeviceState parent_obj;
     /*< public >*/
 
     struct QemuThread *thread;

Don't you need to update cpu_type_info on qom/cpu.c as well? It still has .parent = TYPE_OBJECT.

Signature · 1 line
Eduardo