qdev: split up header so it can be used in cpu.h
PATCH 1/2 qdev: split up header so it can be used in cpu.h
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
--- hw/irq.h | 2 + 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 | 125 +++++++++++++++++ hw/qdev.c | 1 + hw/qdev.h | 367 +------------------------------------------------- 9 files changed, 391 insertions(+), 363 deletions(-) create mode 100644 hw/qdev-core.h create mode 100644 hw/qdev-monitor.h create mode 100644 hw/qdev-properties.h
hw/irq.h +2 -0
@@ -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/mc146818rtc.c +1 -0
@@ -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
@@ -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
@@ -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
@@ -2,6 +2,7 @@#include "qdev.h" #include "qerror.h" #include "blockdev.h" +#include "qapi/qapi-visit-core.h" void *qdev_get_prop_ptr (DeviceState *dev,Property *prop) {
hw/qdev-properties.h new file +125 -0
125 lines not on this page · raw message
hw/qdev.c +1 -0
@@ -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 -363
372 lines not on this page · raw message
Signature · 1 line
1.7.5.4
PATCH 2/2 cpu: for cpu-user and cpu-softmmu and make cpu-softmmu a child of DeviceState
The line between linux-user and softmmu is not very well defined right now. linux-user really don't want to include devices and making CpuState a child of DeviceState would require pulling lots of stuff into linux-user.
To solve this, we simply fork cpu-user and cpu-softmmu letting them evolve independently.
We also need to push a qdev_init_nofail() into all callers of cpu_init(). This is needed eventually anyway so might as well do this now.
---
Makefile.objs | 6 ---
hw/armv7m.c | 1 +
hw/axis_dev88.c | 1 +
hw/exynos4210.c | 1 +
hw/highbank.c | 1 +
hw/integratorcp.c | 1 +
hw/leon3.c | 1 +
hw/lm32_boards.c | 2 +
hw/milkymist.c | 1 +
hw/mips_fulong2e.c | 1 +
hw/mips_jazz.c | 1 +
hw/mips_malta.c | 1 +
hw/mips_mipssim.c | 1 +
hw/mips_r4k.c | 1 +
hw/musicpal.c | 1 +
hw/omap1.c | 1 +
hw/omap2.c | 1 +
hw/pc.c | 1 +
hw/petalogix_ml605_mmu.c | 1 +
hw/petalogix_s3adsp1800_mmu.c | 1 +
hw/ppc440_bamboo.c | 1 +
hw/ppc4xx_devs.c | 1 +
hw/ppc_newworld.c | 1 +
hw/ppc_oldworld.c | 1 +
hw/ppc_prep.c | 1 +
hw/ppce500_mpc8544ds.c | 1 +
hw/pxa2xx.c | 1 +
hw/r2d.c | 1 +
hw/realview.c | 1 +
hw/s390-virtio.c | 1 +
hw/spapr.c | 1 +
hw/strongarm.c | 1 +
hw/sun4m.c | 1 +
hw/sun4u.c | 1 +
hw/versatilepb.c | 1 +
hw/vexpress.c | 2 +
hw/virtex_ml507.c | 1 +
hw/xen_machine_pv.c | 1 +
hw/xilinx_zynq.c | 1 +
hw/xtensa_lx60.c | 1 +
hw/xtensa_sim.c | 1 +
include/qemu/cpu-softmmu.h | 75 +++++++++++++++++++++++++++++++++++++++
include/qemu/cpu-user.h | 75 +++++++++++++++++++++++++++++++++++++++
include/qemu/cpu.h | 78 ++--------------------------------------
qemu-common.h | 3 +-
qom/Makefile.objs | 5 +--
qom/cpu-softmmu.c | 66 ++++++++++++++++++++++++++++++++++
qom/{cpu.c => cpu-user.c} | 0
48 files changed, 266 insertions(+), 84 deletions(-)
create mode 100644 include/qemu/cpu-softmmu.h
create mode 100644 include/qemu/cpu-user.h
create mode 100644 qom/cpu-softmmu.c
rename qom/{cpu.c => cpu-user.c} (100%)Makefile.objs +0 -6
@@ -11,12 +11,6 @@ qobject-obj-y += qerror.o error.o qemu-error.o universal-obj-y += $(qobject-obj-y) ####################################################################### -# QOM -qom-obj-y = qom/ - -universal-obj-y += $(qom-obj-y) - -####################################################################### # oslib-obj-y is code depending on the OS (win32 vs posix) oslib-obj-y = osdep.o oslib-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o
hw/armv7m.c +1 -0
@@ -188,6 +188,7 @@ qemu_irq *armv7m_init(MemoryRegion *address_space_mem,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;#if 0
hw/axis_dev88.c +1 -0
@@ -265,6 +265,7 @@ void axisdev88_init (ram_addr_t ram_size, cpu_model ="crisv32" ; } cpu =cpu_cris_init (cpu_model); +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;/* allocate RAM */
hw/exynos4210.c +1 -0
@@ -112,6 +112,7 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem,fprintf (stderr,"Unable to find CPU %d definition\n" , n);exit (1 ); } +qdev_init_nofail (DEVICE (s->cpu[n]));/* Create PIC controller for each processor instance */ irqp =arm_pic_init_cpu (s->cpu[n]);
hw/highbank.c +1 -0
@@ -214,6 +214,7 @@ static void highbank_init(ram_addr_t ram_size,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu));/* This will become a QOM property eventually */ cpu->reset_cbar =GIC_BASE_ADDR ;
hw/integratorcp.c +1 -0
@@ -460,6 +460,7 @@ static void integratorcp_init(ram_addr_t ram_size,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu));memory_region_init_ram (ram,"integrator.ram" , ram_size);vmstate_register_ram_global (ram);
hw/leon3.c +1 -0
@@ -123,6 +123,7 @@ static void leon3_generic_hw_init(ram_addr_t ram_size,fprintf (stderr,"qemu: Unable to find Sparc CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;cpu_sparc_set_id (env,0 );
hw/lm32_boards.c +2 -0
@@ -103,6 +103,7 @@ static void lm32_evr_init(ram_addr_t ram_size_not_used, cpu_model ="lm32-full" ; } cpu =cpu_lm32_init (cpu_model); +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env; reset_info->cpu = cpu;
@@ -200,6 +201,7 @@ static void lm32_uclinux_init(ram_addr_t ram_size_not_used, cpu_model ="lm32-full" ; } cpu =cpu_lm32_init (cpu_model); +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env; reset_info->cpu = cpu;
hw/milkymist.c +1 -0
@@ -107,6 +107,7 @@ milkymist_init(ram_addr_t ram_size_not_used, cpu_model ="lm32-full" ; } cpu =cpu_lm32_init (cpu_model); +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env; reset_info->cpu = cpu;
hw/mips_fulong2e.c +1 -0
@@ -285,6 +285,7 @@ static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;qemu_register_reset (main_cpu_reset, cpu);
hw/mips_jazz.c +1 -0
@@ -147,6 +147,7 @@ static void mips_jazz_init(MemoryRegion *address_space,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;qemu_register_reset (main_cpu_reset, cpu);
hw/mips_malta.c +1 -0
@@ -833,6 +833,7 @@ void mips_malta_init (ram_addr_t ram_size,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;/* Init internal devices */
hw/mips_mipssim.c +1 -0
@@ -158,6 +158,7 @@ mips_mipssim_init (ram_addr_t ram_size,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env; reset_info =g_malloc0 (sizeof (ResetData));
hw/mips_r4k.c +1 -0
@@ -185,6 +185,7 @@ void mips_r4k_init (ram_addr_t ram_size,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env; reset_info =g_malloc0 (sizeof (ResetData));
hw/musicpal.c +1 -0
@@ -1538,6 +1538,7 @@ static void musicpal_init(ram_addr_t ram_size,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); cpu_pic =arm_pic_init_cpu (cpu);/* For now we use a fixed - the original - RAM size */
hw/omap1.c +1 -0
@@ -3836,6 +3836,7 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (s->cpu)); s->sdram_size = sdram_size; s->sram_size =OMAP15XX_SRAM_SIZE ;
hw/omap2.c +1 -0
@@ -2258,6 +2258,7 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (s->cpu)); s->sdram_size = sdram_size; s->sram_size =OMAP242X_SRAM_SIZE ;
hw/pc.c +1 -0
@@ -943,6 +943,7 @@ static X86CPU *pc_new_cpu(const char *cpu_model)fprintf (stderr,"Unable to find x86 CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;if ((env->cpuid_features &CPUID_APIC ) || smp_cpus >1 ) { env->apic_state =apic_init (env, env->cpuid_apic_id);
hw/petalogix_ml605_mmu.c +1 -0
@@ -91,6 +91,7 @@ petalogix_ml605_init(ram_addr_t ram_size, cpu_model ="microblaze" ; } cpu =cpu_mb_init (cpu_model); +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;/* Attach emulated BRAM through the LMB. */
hw/petalogix_s3adsp1800_mmu.c +1 -0
@@ -79,6 +79,7 @@ petalogix_s3adsp1800_init(ram_addr_t ram_size, cpu_model ="microblaze" ; } cpu =cpu_mb_init (cpu_model); +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;/* Attach emulated BRAM through the LMB. */
hw/ppc440_bamboo.c +1 -0
@@ -192,6 +192,7 @@ static void bamboo_init(ram_addr_t ram_size,fprintf (stderr,"Unable to initialize CPU!\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;qemu_register_reset (main_cpu_reset, cpu);
hw/ppc4xx_devs.c +1 -0
@@ -61,6 +61,7 @@ CPUPPCState *ppc4xx_init (const char *cpu_model, cpu_model);exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env; cpu_clk->cb =NULL ;/* We don't care about CPU clock frequency changes */
hw/ppc_newworld.c +1 -0
@@ -172,6 +172,7 @@ static void ppc_core99_init (ram_addr_t ram_size,fprintf (stderr,"Unable to find PowerPC CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;/* Set time-base frequency to 100 Mhz */
hw/ppc_oldworld.c +1 -0
@@ -110,6 +110,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,fprintf (stderr,"Unable to find PowerPC CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;/* Set time-base frequency to 16.6 Mhz */
hw/ppc_prep.c +1 -0
@@ -493,6 +493,7 @@ static void ppc_prep_init (ram_addr_t ram_size,fprintf (stderr,"Unable to find PowerPC CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;if (env->flags &POWERPC_FLAG_RTC_CLK ) {
hw/ppce500_mpc8544ds.c +1 -0
@@ -264,6 +264,7 @@ static void mpc8544ds_init(ram_addr_t ram_size,fprintf (stderr,"Unable to initialize CPU!\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;if (!firstenv) {
hw/pxa2xx.c +1 -0
@@ -2070,6 +2070,7 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (s->cpu)); s->reset =qemu_allocate_irqs (pxa2xx_reset, s,1 )[0 ];/* SDRAM & Internal Memory Storage */
hw/r2d.c +1 -0
@@ -245,6 +245,7 @@ static void r2d_init(ram_addr_t ram_size,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env; reset_info =g_malloc0 (sizeof (ResetData));
hw/realview.c +1 -0
@@ -94,6 +94,7 @@ static void realview_init(ram_addr_t ram_size,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); irqp =arm_pic_init_cpu (cpu); cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ ]; }
hw/s390-virtio.c +1 -0
@@ -213,6 +213,7 @@ static void s390_init(ram_addr_t my_ram_size,CPUS390XState *tmp_env; cpu =cpu_s390x_init (cpu_model); +qdev_init_nofail (DEVICE (cpu)); tmp_env = &cpu->env;if (!env) { env = tmp_env;
hw/spapr.c +1 -0
@@ -566,6 +566,7 @@ static void ppc_spapr_init(ram_addr_t ram_size,fprintf (stderr,"Unable to find PowerPC CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;/* Set time-base frequency to 512 MHz */
hw/strongarm.c +1 -0
@@ -1569,6 +1569,7 @@ StrongARMState *sa1110_init(MemoryRegion *sysmem,error_report ("Unable to find CPU definition" );exit (1 ); } +qdev_init_nofail (DEVICE (s->cpu));memory_region_init_ram (&s->sdram,"strongarm.sdram" , sdram_size);vmstate_register_ram_global (&s->sdram);
hw/sun4m.c +1 -0
@@ -819,6 +819,7 @@ static void cpu_devinit(const char *cpu_model, unsigned int id,fprintf (stderr,"qemu: Unable to find Sparc CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;cpu_sparc_set_id (env, id);
hw/sun4u.c +1 -0
@@ -770,6 +770,7 @@ static SPARCCPU *cpu_devinit(const char *cpu_model, const struct hwdef *hwdef)fprintf (stderr,"Unable to find Sparc CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env; env->tick = cpu_timer_create("tick", env, tick_irq,
hw/versatilepb.c +1 -0
@@ -197,6 +197,7 @@ static void versatile_init(ram_addr_t ram_size,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu));memory_region_init_ram (ram,"versatile.ram" , ram_size);vmstate_register_ram_global (ram);/* ??? RAM should repeat to fill physical memory space. */
hw/vexpress.c +2 -0
@@ -181,6 +181,7 @@ static void a9_daughterboard_init(const VEDBoardInfo *daughterboard,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); irqp =arm_pic_init_cpu (cpu); cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ ]; }
@@ -280,6 +281,7 @@ static void a15_daughterboard_init(const VEDBoardInfo *daughterboard,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); irqp =arm_pic_init_cpu (cpu); cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ ]; }
hw/virtex_ml507.c +1 -0
@@ -92,6 +92,7 @@ static PowerPCCPU *ppc440_init_xilinx(ram_addr_t *ram_size,fprintf (stderr,"Unable to initialize CPU!\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env;ppc_booke_timers_init (env, sysclk,0 /* no flags */ );
hw/xen_machine_pv.c +1 -0
@@ -50,6 +50,7 @@ static void xen_init_pv(ram_addr_t ram_size,#endif } cpu =cpu_x86_init (cpu_model); +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env; env->halted =1 ;
hw/xilinx_zynq.c +1 -0
@@ -71,6 +71,7 @@ static void zynq_init(ram_addr_t ram_size, const char *boot_device,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); irqp =arm_pic_init_cpu (cpu); cpu_irq = irqp[ARM_PIC_CPU_IRQ ];
hw/xtensa_lx60.c +1 -0
@@ -182,6 +182,7 @@ static void lx_init(const LxBoardDesc *board,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env; env->sregs[PRID ] = n;
hw/xtensa_sim.c +1 -0
@@ -60,6 +60,7 @@ static void sim_init(ram_addr_t ram_size,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } +qdev_init_nofail (DEVICE (cpu)); env = &cpu->env; env->sregs[PRID ] = n;
include/qemu/cpu-softmmu.h new file +75 -0
75 lines not on this page · raw message
include/qemu/cpu-user.h new file +75 -0
75 lines not on this page · raw message
include/qemu/cpu.h +4 -74
79 lines not on this page · raw message
qemu-common.h +2 -1
@@ -254,7 +254,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 ;
@@ -265,6 +264,8 @@ typedef struct VirtIODevice VirtIODevice;typedef struct QEMUSGList QEMUSGList ;typedef struct SHPCDevice SHPCDevice ; +#include "hw/irq.h" +typedef uint64_t pcibus_t ; typedef enum LostTickPolicy {
qom/Makefile.objs +2 -3
@@ -1,4 +1,3 @@ qom-obj-y = object.o container.o qom-qobject.o -qom-obj-twice-y = cpu.o -common-obj-y = $(qom-obj-twice-y) -user-obj-y = $(qom-obj-twice-y) +common-obj-y += $(qom-obj-y) cpu-softmmu.o +user-obj-y += $(qom-obj-y) cpu-user.o
qom/cpu-softmmu.c new file +66 -0
66 lines not on this page · raw message
qom/cpu-user.c renamed from qom/cpu.c +0 -0
Signature · 1 line
1.7.5.4
Re: [Qemu-devel] [PATCH 2/2] cpu: for cpu-user and cpu-softmmu and make cpu-softmmu a child of DeviceState
Am 22.06.2012 21:36, schrieb Anthony Liguori:
Quoted 6 lines
The line between linux-user and softmmu is not very well defined right now. linux-user really don't want to include devices and making CpuState a child of DeviceState would require pulling lots of stuff into linux-user.
To solve this, we simply fork cpu-user and cpu-softmmu letting them evolve independently.
[snip]
I still don't understand why.
Quoted 1 line
From your announcement on IRC I thought that you would leave
TYPE_CPUas
is and introdruce TYPE_SOFTMMU_CPU / TYPE_USER_CPU as derived intermediate types. But here you are just replacing my suggested #ifdefs with code duplication...
The QOM CPUState part 4 series on the list I reminded you of starts moving more stuff into struct CPUState, which is supposed to be used by common code, i.e., both softmmu and *-user.
With this patch of yours I'd need to move the fields from central CPU_COMMON into *two* structs kept in sync, which doesn't feel like an advantage to me. Apart from fields for include/qemu/cpu.h I was also planning on placing helper functions into qom/cpu.c, which now would need to be duplicated, like cpu_common_reset() for the fields added. So if there's some error it is likely to get fixed in one version but forgotten in the other one. That would be really bad. If functions do mostly the same thing they should be compiled from the same source - basics of Product Line Engineering. If there's functions that only apply to one of them then I'm fine placing them in a cpu-softmmu or cpu-user file respectively. But this patch 2/2 just seems to make more work without real gains to avoid #ifdefs - we'll get some anyway due to w32 and unrolling those into even more file copies sounds even worse.
Apart from tcg/, which you keep iterating, linux-user also reuses most of target-*/ (except for supervisor- and hypervisor-level instructions) as well as core CPU execution infrastructure, which I'm trying to streamline through CPUState compiled only twice rather than per each *-softmmu and *-*-user.
So IMO the key point is that we don't want them to evolve independently. We want to code efficiently and to build QEMU efficiently.
Regards,
Andreas
For reference my previous suggestion for CPUState-as-a-DeviceState was:
include/qemu/cpu.h +7 -0
@@ -21,6 +21,9 @@#define QEMU_CPU_H #include "qemu/object.h" +#ifndef CONFIG_USER_ONLY +#include "hw/qdev.h" +#endif /** * SECTION:cpu
@@ -45,7 +48,11 @@ typedef struct CPUState CPUState;*/ typedef struct CPUClass { /*< private >*/ +#ifdef CONFIG_USER_ONLY ObjectClass parent_class; +#else + DeviceClass parent_class; +#endif /*< public >*/ void (*reset)(CPUState *cpu);
qom/cpu.c +12 -0
@@ -36,14 +36,26 @@ static void cpu_common_reset(CPUState *cpu)static void cpu_class_init (ObjectClass *klass,void *data) { +#ifndef CONFIG_USER_ONLY +DeviceClass *dc =DEVICE_CLASS (klass); +#endif CPUClass *k =CPU_CLASS (klass); +#ifndef CONFIG_USER_ONLY +/* Overwrite this in subclasses for which hotplug is supported. */ + dc->no_user =1 ; +#endif + k->reset = cpu_common_reset; }static TypeInfo cpu_type_info = { .name =TYPE_CPU , +#ifdef CONFIG_USER_ONLY .parent =TYPE_OBJECT , +#else + .parent =TYPE_DEVICE , +#endif .instance_size =sizeof (CPUState), .abstract = true, .class_size =sizeof (CPUClass),
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
Re: [Qemu-devel] [PATCH 2/2] cpu: for cpu-user and cpu-softmmu and make cpu-softmmu a child of DeviceState
Quoted 34 lines · Andreas Färber
Am 22.06.2012 21:36, schrieb Anthony Liguori:
Quoted 6 lines
The line between linux-user and softmmu is not very well defined right now. linux-user really don't want to include devices and making CpuState a child of DeviceState would require pulling lots of stuff into linux-user.
To solve this, we simply fork cpu-user and cpu-softmmu letting them evolve independently.
[snip]
I still don't understand why.
From your announcement on IRC I thought that you would leave
TYPE_CPUas is and introdruceTYPE_SOFTMMU_CPU/TYPE_USER_CPUas derived intermediate types. But here you are just replacing my suggested #ifdefs with code duplication...The QOM CPUState part 4 series on the list I reminded you of starts moving more stuff into struct CPUState, which is supposed to be used by common code, i.e., both softmmu and *-user.
With this patch of yours I'd need to move the fields from central
CPU_COMMONinto *two* structs kept in sync, which doesn't feel like an advantage to me. Apart from fields forinclude/qemu/cpu.hI was also planning on placing helper functions intoqom/cpu.c, which now would need to be duplicated, likecpu_common_reset()for the fields added. So if there's some error it is likely to get fixed in one version but forgotten in the other one. That would be really bad. If functions do mostly the same thing they should be compiled from the same source - basics of Product Line Engineering. If there's functions that only apply to one of them then I'm fine placing them in a cpu-softmmu or cpu-user file respectively. But this patch 2/2 just seems to make more work without real gains to avoid #ifdefs - we'll get some anyway due to w32 and unrolling those into even more file copies sounds even worse.
Quoted 8 lines
Apart from tcg/, which you keep iterating, linux-user also reuses most of target-*/ (except for supervisor- and hypervisor-level instructions) as well as core CPU execution infrastructure, which I'm trying to streamline through CPUState compiled only twice rather than per each *-softmmu and *-*-user.
So IMO the key point is that we don't want them to evolve independently. We want to code efficiently and to build QEMU efficiently.
I also don't see much benefit from the separation. Perhaps the problem that needs to be fixed is that DeviceState requires pulling in a lot of stuff?
The user emulators see a CPU device and a board but with most, but not all, HW devices stripped. There are CPU devices (for example tick counters on Sparc64) which are also visible to user emulator and whose interrupt lines could be modeled conveniently using Pins. Now we can't use qemu_irq for the CPU but that limitation should be lifted.
Quoted 67 lines
Regards,
AndreasFor reference my previous suggestion for CPUState-as-a-DeviceState was:
include/qemu/cpu.h +7
-0@@ -21,6 +21,9 @@ #define QEMU_CPU_H #include "qemu/object.h" +#ifndef CONFIG_USER_ONLY +#include "hw/qdev.h" +#endif /*** SECTION:cpu @@ -45,7 +48,11 @@ typedef struct CPUState CPUState;*/ typedef struct CPUClass { /*< private >*/ +#ifdef CONFIG_USER_ONLY ObjectClass parent_class; +#else + DeviceClass parent_class; +#endif /*< public >*/ void (*reset)(CPUState *cpu);qom/cpu.c +12
-1@@ -36,14 +36,26 @@ static void cpu_common_reset(CPUState *cpu) static void cpu_class_init(ObjectClass *klass, void *data) { +#ifndef CONFIG_USER_ONLY + DeviceClass *dc = DEVICE_CLASS(klass); +#endif CPUClass *k = CPU_CLASS(klass); +#ifndef CONFIG_USER_ONLY + /* Overwrite this in subclasses for which hotplug is supported. */ + dc->no_user = 1; +#endif + k->reset = cpu_common_reset; } static TypeInfo cpu_type_info = { .name = TYPE_CPU, +#ifdef CONFIG_USER_ONLY .parent = TYPE_OBJECT, +#else + .parent = TYPE_DEVICE, +#endif .instance_size = sizeof(CPUState), .abstract = true, .class_size = sizeof(CPUClass), --SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg