qom: simplify object_find_property / object_class_find_property
PATCH v2 1/1 qom: simplify object_find_property / object_class_find_property
When debugging QEMU it is often useful to put a breakpoint on the error_setg_internal method impl.
Unfortunately the object_property_add / object_class_property_add methods call object_property_find / object_class_property_find methods to check if a property exists already before adding the new property.
As a result there are a huge number of calls to error_setg_internal on startup of most QEMU commands, making it very painful to set a breakpoint on this method.
Most callers of object_find_property and object_class_find_property, however, pass in a NULL for the Error parameter. This simplifies the methods to remove the Error parameter entirely, and then adds some new wrapper methods that are able to raise an Error when needed.
---
v1: https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg03621.html
hw/arm/armv7m.c | 10 +++--- hw/arm/exynos4210.c | 2 +- hw/arm/highbank.c | 2 +- hw/arm/integratorcp.c | 2 +- hw/arm/realview.c | 2 +- hw/arm/sbsa-ref.c | 2 +- hw/arm/versatilepb.c | 2 +- hw/arm/vexpress.c | 4 +-- hw/arm/virt.c | 10 +++--- hw/arm/xilinx_zynq.c | 2 +- hw/core/qdev-properties-system.c | 2 +- hw/core/sysbus.c | 2 +- hw/cpu/a15mpcore.c | 4 +-- hw/cpu/a9mpcore.c | 2 +- hw/misc/iotkit-sysctl.c | 2 +- hw/pci/pci.c | 2 +- hw/scsi/scsi-bus.c | 4 +-- include/qom/object.h | 48 ++++++++++++++++++++++--- qom/object.c | 60 +++++++++++++++++++------------- target/arm/monitor.c | 2 +- target/i386/cpu.c | 2 +- target/ppc/translate_init.c.inc | 2 +- 22 files changed, 109 insertions(+), 61 deletions(-)
hw/arm/armv7m.c +5 -5
@@ -169,28 +169,28 @@ static void armv7m_realize(DeviceState *dev, Error **errp)object_property_set_link (OBJECT (s->cpu),"memory" ,OBJECT (&s->container), &error_abort); -if (object_property_find (OBJECT (s->cpu),"idau" ,NULL )) { +if (object_property_find (OBJECT (s->cpu),"idau" )) {object_property_set_link (OBJECT (s->cpu),"idau" , s->idau, &error_abort); } -if (object_property_find (OBJECT (s->cpu),"init-svtor" ,NULL )) { +if (object_property_find (OBJECT (s->cpu),"init-svtor" )) {if (!object_property_set_uint (OBJECT (s->cpu),"init-svtor" , s->init_svtor, errp)) {return ; } } -if (object_property_find (OBJECT (s->cpu),"start-powered-off" ,NULL )) { +if (object_property_find (OBJECT (s->cpu),"start-powered-off" )) {if (!object_property_set_bool (OBJECT (s->cpu),"start-powered-off" , s->start_powered_off, errp)) {return ; } } -if (object_property_find (OBJECT (s->cpu),"vfp" ,NULL )) { +if (object_property_find (OBJECT (s->cpu),"vfp" )) {if (!object_property_set_bool (OBJECT (s->cpu),"vfp" , s->vfp, errp)) {return ; } } -if (object_property_find (OBJECT (s->cpu),"dsp" ,NULL )) { +if (object_property_find (OBJECT (s->cpu),"dsp" )) {if (!object_property_set_bool (OBJECT (s->cpu),"dsp" , s->dsp, errp)) {return ; }
hw/arm/exynos4210.c +1 -1
@@ -214,7 +214,7 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)/* By default A9 CPUs have EL3 enabled. This board does not currently * support EL3 so the CPU EL3 property is disabled before realization. */ -if (object_property_find (cpuobj,"has_el3" ,NULL )) { +if (object_property_find (cpuobj,"has_el3" )) {object_property_set_bool (cpuobj,"has_el3" , false, &error_fatal); }
hw/arm/highbank.c +1 -1
@@ -278,7 +278,7 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id) &error_abort); } -if (object_property_find (cpuobj,"reset-cbar" ,NULL )) { +if (object_property_find (cpuobj,"reset-cbar" )) {object_property_set_int (cpuobj,"reset-cbar" ,MPCORE_PERIPHBASE , &error_abort); }
hw/arm/integratorcp.c +1 -1
@@ -609,7 +609,7 @@ static void integratorcp_init(MachineState *machine)* currently support EL3 so the CPU EL3 property is disabled before * realization. */ -if (object_property_find (cpuobj,"has_el3" ,NULL )) { +if (object_property_find (cpuobj,"has_el3" )) {object_property_set_bool (cpuobj,"has_el3" , false, &error_fatal); }
hw/arm/realview.c +1 -1
@@ -108,7 +108,7 @@ static void realview_init(MachineState *machine,* does not currently support EL3 so the CPU EL3 property is disabled * before realization. */ -if (object_property_find (cpuobj,"has_el3" ,NULL )) { +if (object_property_find (cpuobj,"has_el3" )) {object_property_set_bool (cpuobj,"has_el3" , false, &error_fatal); }
hw/arm/sbsa-ref.c +1 -1
@@ -705,7 +705,7 @@ static void sbsa_ref_init(MachineState *machine)numa_cpu_pre_plug (&possible_cpus->cpus[cs->cpu_index],DEVICE (cpuobj), &error_fatal); -if (object_property_find (cpuobj,"reset-cbar" ,NULL )) { +if (object_property_find (cpuobj,"reset-cbar" )) {object_property_set_int (cpuobj,"reset-cbar" , sbsa_ref_memmap[SBSA_CPUPERIPHS ].base, &error_abort);
hw/arm/versatilepb.c +1 -1
@@ -215,7 +215,7 @@ static void versatile_init(MachineState *machine, int board_id)* currently support EL3 so the CPU EL3 property is disabled before * realization. */ -if (object_property_find (cpuobj,"has_el3" ,NULL )) { +if (object_property_find (cpuobj,"has_el3" )) {object_property_set_bool (cpuobj,"has_el3" , false, &error_fatal); }
hw/arm/vexpress.c +2 -2
@@ -221,12 +221,12 @@ static void init_cpus(MachineState *ms, const char *cpu_type,object_property_set_bool (cpuobj,"has_el3" , false,NULL ); }if (!virt) { -if (object_property_find (cpuobj,"has_el2" ,NULL )) { +if (object_property_find (cpuobj,"has_el2" )) {object_property_set_bool (cpuobj,"has_el2" , false,NULL ); } } -if (object_property_find (cpuobj,"reset-cbar" ,NULL )) { +if (object_property_find (cpuobj,"reset-cbar" )) {object_property_set_int (cpuobj,"reset-cbar" , periphbase, &error_abort); }
hw/arm/virt.c +5 -5
@@ -1806,7 +1806,7 @@ static void machvirt_init(MachineState *machine)object_property_set_bool (cpuobj,"has_el3" , false,NULL ); } -if (!vms->virt &&object_property_find (cpuobj,"has_el2" ,NULL )) { +if (!vms->virt &&object_property_find (cpuobj,"has_el2" )) {object_property_set_bool (cpuobj,"has_el2" , false,NULL ); }
@@ -1822,15 +1822,15 @@ static void machvirt_init(MachineState *machine) }if (vmc->kvm_no_adjvtime && -object_property_find (cpuobj,"kvm-no-adjvtime" ,NULL )) { +object_property_find (cpuobj,"kvm-no-adjvtime" )) {object_property_set_bool (cpuobj,"kvm-no-adjvtime" , true,NULL ); } -if (vmc->no_pmu &&object_property_find (cpuobj,"pmu" ,NULL )) { +if (vmc->no_pmu &&object_property_find (cpuobj,"pmu" )) {object_property_set_bool (cpuobj,"pmu" , false,NULL ); } -if (object_property_find (cpuobj,"reset-cbar" ,NULL )) { +if (object_property_find (cpuobj,"reset-cbar" )) {object_property_set_int (cpuobj,"reset-cbar" , vms->memmap[VIRT_CPUPERIPHS ].base, &error_abort);
@@ -1850,7 +1850,7 @@ static void machvirt_init(MachineState *machine)* The property exists only if MemTag is supported. * If it is, we must allocate the ram to back that up. */ -if (!object_property_find (cpuobj,"tag-memory" ,NULL )) { +if (!object_property_find (cpuobj,"tag-memory" )) {error_report ("MTE requested, but not supported " "by the guest CPU" );exit (1 );
hw/arm/xilinx_zynq.c +1 -1
@@ -198,7 +198,7 @@ static void zynq_init(MachineState *machine)* currently support EL3 so the CPU EL3 property is disabled before * realization. */ -if (object_property_find (OBJECT (cpu),"has_el3" ,NULL )) { +if (object_property_find (OBJECT (cpu),"has_el3" )) {object_property_set_bool (OBJECT (cpu),"has_el3" , false, &error_fatal); }
hw/core/qdev-properties-system.c +1 -1
@@ -460,7 +460,7 @@ void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)qdev_prop_set_netdev (dev,"netdev" , nd->netdev); }if (nd->nvectors !=DEV_NVECTORS_UNSPECIFIED && -object_property_find (OBJECT (dev),"vectors" ,NULL )) { +object_property_find (OBJECT (dev),"vectors" )) {qdev_prop_set_uint32 (dev,"vectors" , nd->nvectors); } nd->instantiated =1 ;
hw/core/sysbus.c +1 -1
@@ -93,7 +93,7 @@ bool sysbus_has_irq(SysBusDevice *dev, int n)char *prop =g_strdup_printf ("%s[%d]" ,SYSBUS_DEVICE_GPIO_IRQ , n);ObjectProperty *r; - r =object_property_find (OBJECT (dev), prop,NULL ); + r =object_property_find (OBJECT (dev), prop);g_free (prop);return (r !=NULL );
hw/cpu/a15mpcore.c +2 -2
@@ -66,11 +66,11 @@ static void a15mp_priv_realize(DeviceState *dev, Error **errp)* either all the CPUs have TZ, or none do. */ cpuobj =OBJECT (qemu_get_cpu (0 )); - has_el3 =object_property_find (cpuobj,"has_el3" ,NULL ) && + has_el3 =object_property_find (cpuobj,"has_el3" ) &&object_property_get_bool (cpuobj,"has_el3" , &error_abort);qdev_prop_set_bit (gicdev,"has-security-extensions" , has_el3);/* Similarly for virtualization support */ - has_el2 =object_property_find (cpuobj,"has_el2" ,NULL ) && + has_el2 =object_property_find (cpuobj,"has_el2" ) &&object_property_get_bool (cpuobj,"has_el2" , &error_abort);qdev_prop_set_bit (gicdev,"has-virtualization-extensions" , has_el2); }
hw/cpu/a9mpcore.c +1 -1
@@ -81,7 +81,7 @@ static void a9mp_priv_realize(DeviceState *dev, Error **errp)/* Make the GIC's TZ support match the CPUs. We assume that * either all the CPUs have TZ, or none do. */ - has_el3 =object_property_find (cpuobj,"has_el3" ,NULL ) && + has_el3 =object_property_find (cpuobj,"has_el3" ) &&object_property_get_bool (cpuobj,"has_el3" , &error_abort);qdev_prop_set_bit (gicdev,"has-security-extensions" , has_el3);
hw/misc/iotkit-sysctl.c +1 -1
@@ -83,7 +83,7 @@ static void set_init_vtor(uint64_t cpuid, uint32_t vtor)Object *cpuobj =OBJECT (arm_get_cpu_by_id (cpuid));if (cpuobj) { -if (object_property_find (cpuobj,"init-svtor" ,NULL )) { +if (object_property_find (cpuobj,"init-svtor" )) {object_property_set_uint (cpuobj,"init-svtor" , vtor, &error_abort); } }
hw/pci/pci.c +1 -1
@@ -1900,7 +1900,7 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,* a temporary instance here to be able to check it. */ Object *obj =object_new_with_class (OBJECT_CLASS (dc)); -if (object_property_find (obj,"netdev" ,NULL )) { +if (object_property_find (obj,"netdev" )) {g_ptr_array_add (pci_nic_models, (gpointer )name); }object_unref (obj);
hw/scsi/scsi-bus.c +2 -2
@@ -270,10 +270,10 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockBackend *blk,object_property_set_int (OBJECT (dev),"bootindex" , bootindex, &error_abort); } -if (object_property_find (OBJECT (dev),"removable" ,NULL )) { +if (object_property_find (OBJECT (dev),"removable" )) {qdev_prop_set_bit (dev,"removable" , removable); } -if (serial &&object_property_find (OBJECT (dev),"serial" ,NULL )) { +if (serial &&object_property_find (OBJECT (dev),"serial" )) {qdev_prop_set_string (dev,"serial" , serial); }if (!qdev_prop_set_drive_err (dev,"drive" , blk, errp)) {
include/qom/object.h +43 -5
57 lines not on this page · raw message
qom/object.c +35 -25
157 lines not on this page · raw message
target/arm/monitor.c +1 -1
@@ -214,7 +214,7 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, i =0 ;while ((name = cpu_model_advertised_features[i++]) !=NULL ) { -ObjectProperty *prop =object_property_find (obj, name,NULL ); +ObjectProperty *prop =object_property_find (obj, name);if (prop) {QObject *value;
target/i386/cpu.c +1 -1
@@ -6932,7 +6932,7 @@ static void x86_cpu_register_bit_prop(X86CPU *cpu,ObjectProperty *op;uint64_t mask = (1ULL << bitnr); - op =object_property_find (OBJECT (cpu), prop_name,NULL ); + op =object_property_find (OBJECT (cpu), prop_name);if (op) { fp = op->opaque;assert (fp->w == w);
target/ppc/translate_init.c.inc +1 -1
@@ -10478,7 +10478,7 @@ static void ppc_cpu_parse_featurestr(const char *type, char *features, return; } - if (object_property_find(machine, "max-cpu-compat", NULL)) { + if (object_property_find(machine, "max-cpu-compat")) { int i; char **inpieces; char *s = features;
Signature · 1 line
2.26.2
Quoted 36 lines · Daniel P. Berrangé
When debugging QEMU it is often useful to put a breakpoint on the
error_setg_internalmethod impl.Unfortunately the
object_property_add/object_class_property_addmethods callobject_property_find/object_class_property_findmethods to check if a property exists already before adding the new property.As a result there are a huge number of calls to
error_setg_internalon startup of most QEMU commands, making it very painful to set a breakpoint on this method.Most callers of
object_find_propertyandobject_class_find_property, however, pass in a NULL for the Error parameter. This simplifies the methods to remove the Error parameter entirely, and then adds some new wrapper methods that are able to raise an Error when needed.Signed-off-by Daniel P. Berrangé <[email protected]>---
v1: https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg03621.html
hw/arm/armv7m.c | 10 +++--- hw/arm/exynos4210.c | 2 +- hw/arm/highbank.c | 2 +- hw/arm/integratorcp.c | 2 +- hw/arm/realview.c | 2 +- hw/arm/sbsa-ref.c | 2 +- hw/arm/versatilepb.c | 2 +- hw/arm/vexpress.c | 4 +-- hw/arm/virt.c | 10 +++--- hw/arm/xilinx_zynq.c | 2 +- hw/core/qdev-properties-system.c | 2 +- hw/core/sysbus.c | 2 +- hw/cpu/a15mpcore.c | 4 +-- hw/cpu/a9mpcore.c | 2 +- hw/misc/iotkit-sysctl.c | 2 +-
Quoted 8 lines
hw/pci/pci.c | 2 +- hw/scsi/scsi-bus.c | 4 +-- include/qom/object.h | 48 ++++++++++++++++++++++--- qom/object.c | 60 +++++++++++++++++++------------- target/arm/monitor.c | 2 +- target/i386/cpu.c | 2 +- target/ppc/translate_init.c.inc | 2 +- 22 files changed, 109 insertions(+), 61 deletions(-)
If possible, please use scripts/git.orderfile ;)
Quoted 10 lines · Daniel P. Berrangé
When debugging QEMU it is often useful to put a breakpoint on the
error_setg_internalmethod impl.Unfortunately the
object_property_add/object_class_property_addmethods callobject_property_find/object_class_property_findmethods to check if a property exists already before adding the new property.As a result there are a huge number of calls to
error_setg_internalon startup of most QEMU commands, making it very painful to set a breakpoint on this method.
Work-around: make the breakpoint conditional on errp != NULL.
Use of error_propagate() can defeat the work-around, but doesn't here, as far as I can tell.
Quoted 4 lines
Most callers of
object_find_propertyandobject_class_find_property, however, pass in a NULL for the Error parameter. This simplifies the methods to remove the Error parameter entirely, and then adds some new wrapper methods that are able to raise an Error when needed.
I don't mind. Up to the QOM maintainers.
Quoted 1 line
Signed-off-by Daniel P. Berrangé <[email protected]>
Eduardo Habkost
AppliedQuoted 11 lines · Daniel P. Berrangé
When debugging QEMU it is often useful to put a breakpoint on the
error_setg_internalmethod impl.Unfortunately the
object_property_add/object_class_property_addmethods callobject_property_find/object_class_property_findmethods to check if a property exists already before adding the new property.As a result there are a huge number of calls to
error_setg_internalon startup of most QEMU commands, making it very painful to set a breakpoint on this method.
Quoted 6 lines
Most callers of
object_find_propertyandobject_class_find_property, however, pass in a NULL for the Error parameter. This simplifies the methods to remove the Error parameter entirely, and then adds some new wrapper methods that are able to raise an Error when needed.Signed-off-by Daniel P. Berrangé <[email protected]>
Queued, thanks!
(Paolo, if you wish to get back to handling of QOM patches when you're back, please let me know)
Signature · 1 line
Eduardo