hw: Few more QOM/QDev cleanups
cover hw: Few more QOM/QDev cleanups
- Remove a pointless check,
- Use QOM cast macros,
- Declare QDev links statically using DEFINE_PROP_LINK()
Philippe Mathieu-Daudé (7):
hw/virtio/virtio-pmem: Replace impossible check by assertion hw/block/vhost-user-blk: Use DEVICE() / VIRTIO_DEVICE() macros hw/display/virtio-gpu: Use VIRTIO_DEVICE() macro hw/scsi/virtio-scsi: Use VIRTIO_SCSI_COMMON() macro hw/dma: Declare link using static DEFINE_PROP_LINK() macro hw/net: Declare link using static DEFINE_PROP_LINK() macro hw/usb: Declare link using static DEFINE_PROP_LINK() macro
hw/block/vhost-user-blk.c | 4 ++-- hw/display/virtio-gpu.c | 2 +- hw/dma/xilinx_axidma.c | 6 ++---- hw/dma/xlnx-zdma.c | 7 ++----- hw/dma/xlnx_csu_dma.c | 13 ++++--------- hw/net/cadence_gem.c | 7 ++----- hw/scsi/virtio-scsi.c | 2 +- hw/usb/hcd-xhci-sysbus.c | 4 ---- hw/usb/hcd-xhci.c | 2 ++ hw/virtio/virtio-pmem.c | 5 +---- 10 files changed, 17 insertions(+), 35 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/7 hw/virtio/virtio-pmem: Replace impossible check by assertion
The get_memory_region() handler is used when (un)plugging the device, which can only occur *after* it is realized.
virtio_pmem_realize() ensure the instance can not be realized without 'memdev'. Remove the superfluous check, replacing it by an assertion.
--- hw/virtio/virtio-pmem.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
hw/virtio/virtio-pmem.c +1 -4
@@ -147,10 +147,7 @@ static void virtio_pmem_fill_device_info(const VirtIOPMEM *pmem,static MemoryRegion *virtio_pmem_get_memory_region (VirtIOPMEM *pmem,Error **errp) { -if (!pmem->memdev) { -error_setg (errp,"'%s' property must be set" ,VIRTIO_PMEM_MEMDEV_PROP ); -return NULL ; - } +assert (pmem->memdev);return &pmem->memdev->mr; }
Signature · 1 line
2.41.0
Re: [PATCH 1/7] hw/virtio/virtio-pmem: Replace impossible check by assertion
Quoted 31 lines · Philippe Mathieu-Daudé
The
get_memory_region()handler is used when (un)plugging the device, which can only occur *after* it is realized.
virtio_pmem_realize()ensure the instance can not be realized without 'memdev'. Remove the superfluous check, replacing it by an assertion.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/virtio/virtio-pmem.c| 5 +----1 file changed, 1 insertion(+), 4 deletions(-)hw/virtio/virtio-pmem.c +1
-4@@ -147,10 +147,7 @@ static void virtio_pmem_fill_device_info(const VirtIOPMEM *pmem,static MemoryRegion *virtio_pmem_get_memory_region (VirtIOPMEM *pmem,Error **errp) { -if (!pmem->memdev) { -error_setg (errp,"'%s' property must be set" ,VIRTIO_PMEM_MEMDEV_PROP ); -return NULL ; - } +assert (pmem->memdev);return &pmem->memdev->mr; }Signature · 1 line
2.41.0
PATCH 2/7 hw/block/vhost-user-blk: Use DEVICE() / VIRTIO_DEVICE() macros
In reply to Philippe Mathieu-DaudéAccess QOM parent with the proper QOM [VIRTIO_]DEVICE() macros.
--- hw/block/vhost-user-blk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/block/vhost-user-blk.c +2 -2
@@ -405,7 +405,7 @@ static void vhost_user_blk_event(void *opaque, QEMUChrEvent event)static int vhost_user_blk_realize_connect (VHostUserBlk *s,Error **errp) { -DeviceState *dev = &s->parent_obj.parent_obj; +DeviceState *dev =DEVICE (s);int ret; s->connected = false;
@@ -423,7 +423,7 @@ static int vhost_user_blk_realize_connect(VHostUserBlk *s, Error **errp)assert (s->connected); ret =vhost_dev_get_config (&s->dev, (uint8_t *)&s->blkcfg, - s->parent_obj.config_len, errp); +VIRTIO_DEVICE (s)->config_len, errp);if (ret <0 ) {qemu_chr_fe_disconnect (&s->chardev);vhost_dev_cleanup (&s->dev);
Signature · 1 line
2.41.0
Re: [PATCH 2/7] hw/block/vhost-user-blk: Use DEVICE() / VIRTIO_DEVICE() macros
Quoted 33 lines · Philippe Mathieu-Daudé
Access QOM parent with the proper QOM [VIRTIO_]DEVICE() macros.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/block/vhost-user-blk.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)hw/block/vhost-user-blk.c +2
-2@@ -405,7 +405,7 @@ static void vhost_user_blk_event(void *opaque, QEMUChrEvent event)static int vhost_user_blk_realize_connect (VHostUserBlk *s,Error **errp) { -DeviceState *dev = &s->parent_obj.parent_obj; +DeviceState *dev =DEVICE (s);int ret; s->connected = false;@@ -423,7 +423,7 @@ static int vhost_user_blk_realize_connect(VHostUserBlk *s, Error **errp)assert (s->connected); ret =vhost_dev_get_config (&s->dev, (uint8_t *)&s->blkcfg, - s->parent_obj.config_len, errp); +VIRTIO_DEVICE (s)->config_len, errp);if (ret <0 ) {qemu_chr_fe_disconnect (&s->chardev);vhost_dev_cleanup (&s->dev);Signature · 1 line
2.41.0
Re: [PATCH 2/7] hw/block/vhost-user-blk: Use DEVICE() / VIRTIO_DEVICE() macros
In reply to Philippe Mathieu-DaudéQuoted 21 lines · Philippe Mathieu-Daudé
Access QOM parent with the proper QOM [VIRTIO_]DEVICE() macros.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/block/vhost-user-blk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/block/vhost-user-blk.c +1
-1@@ -405,7 +405,7 @@ static void vhost_user_blk_event(void *opaque, QEMUChrEvent event)static int vhost_user_blk_realize_connect (VHostUserBlk *s,Error **errp) { -DeviceState *dev = &s->parent_obj.parent_obj; +DeviceState *dev =DEVICE (s);int ret; s->connected = false;
hw/block/vhost-user-blk.c static int vhost_user_blk_realize_connect(VHostUserBlk *s, Error **errp) · line 429
Quoted 8 lines
hw/block/vhost-user-blk.c +1
-1@@ -423,7 +423,7 @@ static int vhost_user_blk_realize_connect(VHostUserBlk *s, Error **errp)assert (s->connected); ret =vhost_dev_get_config (&s->dev, (uint8_t *)&s->blkcfg, - s->parent_obj.config_len, errp); +VIRTIO_DEVICE (s)->config_len, errp);if (ret <0 ) {qemu_chr_fe_disconnect (&s->chardev);vhost_dev_cleanup (&s->dev);
ATB,
Mark.
PATCH 3/7 hw/display/virtio-gpu: Use VIRTIO_DEVICE() macro
In reply to Philippe Mathieu-DaudéAccess QOM parent with the proper QOM VIRTIO_DEVICE() macro.
--- hw/display/virtio-gpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/virtio-gpu.c +1 -1
@@ -1132,7 +1132,7 @@ static void virtio_gpu_ctrl_bh(void *opaque)VirtIOGPU *g = opaque;VirtIOGPUClass *vgc =VIRTIO_GPU_GET_CLASS (g); - vgc->handle_ctrl (&g->parent_obj.parent_obj, g->ctrl_vq); + vgc->handle_ctrl (VIRTIO_DEVICE (g), g->ctrl_vq); }static void virtio_gpu_handle_cursor (VirtIODevice *vdev,VirtQueue *vq)
Signature · 1 line
2.41.0
Re: [PATCH 3/7] hw/display/virtio-gpu: Use VIRTIO_DEVICE() macro
Quoted 24 lines · Philippe Mathieu-Daudé
Access QOM parent with the proper QOM
VIRTIO_DEVICE()macro.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/display/virtio-gpu.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)hw/display/virtio-gpu.c +1
-1@@ -1132,7 +1132,7 @@ static void virtio_gpu_ctrl_bh(void *opaque)VirtIOGPU *g = opaque;VirtIOGPUClass *vgc =VIRTIO_GPU_GET_CLASS (g); - vgc->handle_ctrl (&g->parent_obj.parent_obj, g->ctrl_vq); + vgc->handle_ctrl (VIRTIO_DEVICE (g), g->ctrl_vq); }static void virtio_gpu_handle_cursor (VirtIODevice *vdev,VirtQueue *vq)Signature · 1 line
2.41.0
Re: [PATCH 3/7] hw/display/virtio-gpu: Use VIRTIO_DEVICE() macro
In reply to Philippe Mathieu-DaudéQuoted 12 lines · Philippe Mathieu-Daudé
Access QOM parent with the proper QOM
VIRTIO_DEVICE()macro.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/display/virtio-gpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/display/virtio-gpu.c +0
-0
hw/display/virtio-gpu.c static void virtio_gpu_ctrl_bh(void *opaque) · line 1138
Quoted 8 lines
hw/display/virtio-gpu.c +1
-1@@ -1132,7 +1132,7 @@ static void virtio_gpu_ctrl_bh(void *opaque)VirtIOGPU *g = opaque;VirtIOGPUClass *vgc =VIRTIO_GPU_GET_CLASS (g); - vgc->handle_ctrl (&g->parent_obj.parent_obj, g->ctrl_vq); + vgc->handle_ctrl (VIRTIO_DEVICE (g), g->ctrl_vq); }static void virtio_gpu_handle_cursor (VirtIODevice *vdev,VirtQueue *vq)
ATB,
Mark.
PATCH 4/7 hw/scsi/virtio-scsi: Use VIRTIO_SCSI_COMMON() macro
In reply to Philippe Mathieu-DaudéAccess QOM parent with the proper QOM VIRTIO_SCSI_COMMON() macro.
--- hw/scsi/virtio-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/virtio-scsi.c +1 -1
@@ -761,7 +761,7 @@ static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req)static int virtio_scsi_handle_cmd_req_prepare (VirtIOSCSI *s,VirtIOSCSIReq *req) { -VirtIOSCSICommon *vs = &s->parent_obj; +VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (s);SCSIDevice *d;int rc;
Signature · 1 line
2.41.0
Re: [PATCH 4/7] hw/scsi/virtio-scsi: Use VIRTIO_SCSI_COMMON() macro
Quoted 24 lines · Philippe Mathieu-Daudé
Access QOM parent with the proper QOM
VIRTIO_SCSI_COMMON()macro.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/scsi/virtio-scsi.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)hw/scsi/virtio-scsi.c +1
-1@@ -761,7 +761,7 @@ static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req)static int virtio_scsi_handle_cmd_req_prepare (VirtIOSCSI *s,VirtIOSCSIReq *req) { -VirtIOSCSICommon *vs = &s->parent_obj; +VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (s);SCSIDevice *d;int rc;Signature · 1 line
2.41.0
Re: [PATCH 4/7] hw/scsi/virtio-scsi: Use VIRTIO_SCSI_COMMON() macro
In reply to Philippe Mathieu-DaudéQuoted 12 lines · Philippe Mathieu-Daudé
Access QOM parent with the proper QOM
VIRTIO_SCSI_COMMON()macro.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/scsi/virtio-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/scsi/virtio-scsi.c +0
-0
hw/scsi/virtio-scsi.c static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req) · line 766
Quoted 7 lines
hw/scsi/virtio-scsi.c +1
-1@@ -761,7 +761,7 @@ static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req)static int virtio_scsi_handle_cmd_req_prepare (VirtIOSCSI *s,VirtIOSCSIReq *req) { -VirtIOSCSICommon *vs = &s->parent_obj; +VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (s);SCSIDevice *d;int rc;
ATB,
Mark.
Re: [PATCH 4/7] hw/scsi/virtio-scsi: Use VIRTIO_SCSI_COMMON() macro
In reply to Philippe Mathieu-DaudéAm 17.10.2023 um 16:01 hat Philippe Mathieu-Daudé geschrieben:
Quoted 12 lines
Access QOM parent with the proper QOM
VIRTIO_SCSI_COMMON()macro.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/scsi/virtio-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/scsi/virtio-scsi.c +0
-0
hw/scsi/virtio-scsi.c static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req) · line 766
Quoted 7 lines
hw/scsi/virtio-scsi.c +1
-1@@ -761,7 +761,7 @@ static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req)static int virtio_scsi_handle_cmd_req_prepare (VirtIOSCSI *s,VirtIOSCSIReq *req) { -VirtIOSCSICommon *vs = &s->parent_obj; +VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (s);SCSIDevice *d;int rc;
Why is a dynamic cast more "proper" than a static type-safe access, even more so in a hot I/O path?
Rich Jones posted a flamegraph the other day that surprised me because object_class_dynamic_class_assert() and object_dynamic_cast_assert() were shown to be a big part of scsi_req_new(). In the overall performance, it's probably dwarved by other issues, but unnecessary little things can add up, too.
Kevin
Re: [PATCH 4/7] hw/scsi/virtio-scsi: Use VIRTIO_SCSI_COMMON() macro
Quoted 15 lines · Kevin Wolf
Am 17.10.2023 um 16:01 hat Philippe Mathieu-Daudé geschrieben:
Quoted 13 lines
Access QOM parent with the proper QOM
VIRTIO_SCSI_COMMON()macro.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/scsi/virtio-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/scsi/virtio-scsi.c +0
-0@@ -761,7 +761,7 @@ static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req)
Quoted 9 lines
hw/scsi/virtio-scsi.c static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req) · line 766
Quoted 6 lines
hw/scsi/virtio-scsi.c +1
-1static int virtio_scsi_handle_cmd_req_prepare (VirtIOSCSI *s,VirtIOSCSIReq *req) { -VirtIOSCSICommon *vs = &s->parent_obj; +VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (s);SCSIDevice *d;int rc;Why is a dynamic cast more "proper" than a static type-safe access, even more so in a hot I/O path?
I dunno, but it is absolutely the standard QOM style to use the cast macro to do the downcast, rather than fishing about in the struct for the parent_obj field. If QOM casts are getting too expensive we should ideally fix them rather than adding more and more code that takes some side route around them...
thanks
-- PMM
Re: [PATCH 4/7] hw/scsi/virtio-scsi: Use VIRTIO_SCSI_COMMON() macro
In reply to Kevin WolfQuoted 24 lines · Kevin Wolf
Am 17.10.2023 um 16:01 hat Philippe Mathieu-Daudé geschrieben:
Quoted 12 lines
Access QOM parent with the proper QOM
VIRTIO_SCSI_COMMON()macro.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/scsi/virtio-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/scsi/virtio-scsi.c +0
-0hw/scsi/virtio-scsi.c static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req) · line 766
Quoted 7 lines
hw/scsi/virtio-scsi.c +1
-1@@ -761,7 +761,7 @@ static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req)static int virtio_scsi_handle_cmd_req_prepare (VirtIOSCSI *s,VirtIOSCSIReq *req) { -VirtIOSCSICommon *vs = &s->parent_obj; +VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (s);SCSIDevice *d;int rc;Why is a dynamic cast more "proper" than a static type-safe access, even more so in a hot I/O path?
Quoted 5 lines
Rich Jones posted a flamegraph the other day that surprised me because
object_class_dynamic_class_assert()andobject_dynamic_cast_assert()were shown to be a big part ofscsi_req_new(). In the overall performance, it's probably dwarved by other issues, but unnecessary little things can add up, too.
I think Kevin is referring to one of these flamegraphs:
http://oirase.annexia.org/tmp/2023-kvm-build-on-device.svg
http://oirase.annexia.org/tmp/2023-kvm-build.svg
Here's a zoom showing scsi_req_new (hopefully this URL is stable ...):
http://oirase.annexia.org/tmp/2023-kvm-build-on-device.svg?s=scsi_req_new&x=512.9&y=501
Note that qemu has been compiled with QOM cast debug. This is the default for Fedora (not RHEL) because we'd like to get early detection of bugs from Fedora users.
There was another patch recently where a simple change saved about 5% of total runtime in RISC-V TCG guests (admittedly a much more hot path than this one).
https://lists.nongnu.org/archive/html/qemu-devel/2023-10/msg02388.html
Rich.
Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Re: [PATCH 4/7] hw/scsi/virtio-scsi: Use VIRTIO_SCSI_COMMON() macro
Am 31.10.2023 um 14:48 hat Richard W.M. Jones geschrieben:
Quoted 36 lines · Kevin Wolf
Quoted 24 lines
Am 17.10.2023 um 16:01 hat Philippe Mathieu-Daudé geschrieben:
Quoted 12 lines
Access QOM parent with the proper QOM
VIRTIO_SCSI_COMMON()macro.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/scsi/virtio-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/scsi/virtio-scsi.c +0
-0hw/scsi/virtio-scsi.c static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req) · line 766
Quoted 7 lines
hw/scsi/virtio-scsi.c +1
-1@@ -761,7 +761,7 @@ static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req)static int virtio_scsi_handle_cmd_req_prepare (VirtIOSCSI *s,VirtIOSCSIReq *req) { -VirtIOSCSICommon *vs = &s->parent_obj; +VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (s);SCSIDevice *d;int rc;Why is a dynamic cast more "proper" than a static type-safe access, even more so in a hot I/O path?
Quoted 5 lines
Rich Jones posted a flamegraph the other day that surprised me because
object_class_dynamic_class_assert()andobject_dynamic_cast_assert()were shown to be a big part ofscsi_req_new(). In the overall performance, it's probably dwarved by other issues, but unnecessary little things can add up, too.I think Kevin is referring to one of these flamegraphs:
http://oirase.annexia.org/tmp/2023-kvm-build-on-device.svg
http://oirase.annexia.org/tmp/2023-kvm-build.svg
Quoted 7 lines
Here's a zoom showing
scsi_req_new(hopefully this URL is stable ...):http://oirase.annexia.org/tmp/2023-kvm-build-on-device.svg?s=scsi_req_new&x=512.9&y=501
Note that qemu has been compiled with QOM cast debug. This is the default for Fedora (not RHEL) because we'd like to get early detection of bugs from Fedora users.
Indeed, object_dynamic_cast_assert() probably wouldn't show up any more if you disabled QOM cast debugging. But we enable it by default, so that's an explicit setting users have to make, and as you say, at least Fedora doesn't.
The other one, object_class_dynamic_cast_assert() isn't even affected by the debug setting because it does more than just asserting a plain cast. Working around it isn't as trivial either, but I did think about caching it in the object to avoid a string based class lookup for every single request.
Looking at it again, strangely CONFIG_QOM_CAST_DEBUG enables a cache in object_class_dynamic_cast_assert() that isn't used otherwise. Why don't we want this optimisation without the debug flag?
Kevin
Re: [PATCH 4/7] hw/scsi/virtio-scsi: Use VIRTIO_SCSI_COMMON() macro
In reply to Richard W.M. JonesAm 31.10.2023 um 14:48 hat Richard W.M. Jones geschrieben:
Quoted 31 lines · Kevin Wolf
Quoted 24 lines
Am 17.10.2023 um 16:01 hat Philippe Mathieu-Daudé geschrieben:
Quoted 12 lines
Access QOM parent with the proper QOM
VIRTIO_SCSI_COMMON()macro.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/scsi/virtio-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/scsi/virtio-scsi.c +0
-0hw/scsi/virtio-scsi.c static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req) · line 766
Quoted 7 lines
hw/scsi/virtio-scsi.c +1
-1@@ -761,7 +761,7 @@ static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req)static int virtio_scsi_handle_cmd_req_prepare (VirtIOSCSI *s,VirtIOSCSIReq *req) { -VirtIOSCSICommon *vs = &s->parent_obj; +VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (s);SCSIDevice *d;int rc;Why is a dynamic cast more "proper" than a static type-safe access, even more so in a hot I/O path?
Quoted 5 lines
Rich Jones posted a flamegraph the other day that surprised me because
object_class_dynamic_class_assert()andobject_dynamic_cast_assert()were shown to be a big part ofscsi_req_new(). In the overall performance, it's probably dwarved by other issues, but unnecessary little things can add up, too.
Quoted 8 lines
I think Kevin is referring to one of these flamegraphs:
http://oirase.annexia.org/tmp/2023-kvm-build-on-device.svg
http://oirase.annexia.org/tmp/2023-kvm-build.svgHere's a zoom showing
scsi_req_new(hopefully this URL is stable ...):http://oirase.annexia.org/tmp/2023-kvm-build-on-device.svg?s=scsi_req_new&x=512.9&y=501
Oh, this one (kvm-build-on-device) doesn't even show the object cast. I was looking at kvm-build, it seems, where both the class and the object cast are visible:
http://oirase.annexia.org/tmp/2023-kvm-build.svg?s=scsi_req_new&x=455.4&y=533
Kevin
Re: [PATCH 4/7] hw/scsi/virtio-scsi: Use VIRTIO_SCSI_COMMON() macro
Quoted 39 lines · Kevin Wolf
Am 31.10.2023 um 14:48 hat Richard W.M. Jones geschrieben:
Quoted 38 lines · Kevin Wolf
Quoted 24 lines
Am 17.10.2023 um 16:01 hat Philippe Mathieu-Daudé geschrieben:
Quoted 12 lines
Access QOM parent with the proper QOM
VIRTIO_SCSI_COMMON()macro.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/scsi/virtio-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/scsi/virtio-scsi.c +0
-0hw/scsi/virtio-scsi.c static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req) · line 766
Quoted 7 lines
hw/scsi/virtio-scsi.c +1
-1@@ -761,7 +761,7 @@ static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req)static int virtio_scsi_handle_cmd_req_prepare (VirtIOSCSI *s,VirtIOSCSIReq *req) { -VirtIOSCSICommon *vs = &s->parent_obj; +VirtIOSCSICommon *vs =VIRTIO_SCSI_COMMON (s);SCSIDevice *d;int rc;Why is a dynamic cast more "proper" than a static type-safe access, even more so in a hot I/O path?
Quoted 5 lines
Rich Jones posted a flamegraph the other day that surprised me because
object_class_dynamic_class_assert()andobject_dynamic_cast_assert()were shown to be a big part ofscsi_req_new(). In the overall performance, it's probably dwarved by other issues, but unnecessary little things can add up, too.I think Kevin is referring to one of these flamegraphs:
http://oirase.annexia.org/tmp/2023-kvm-build-on-device.svg
http://oirase.annexia.org/tmp/2023-kvm-build.svgHere's a zoom showing
scsi_req_new(hopefully this URL is stable ...):
Quoted 7 lines
Quoted 1 line
http://oirase.annexia.org/tmp/2023-kvm-build-on-device.svg?s=scsi_req_new&x=512.9&y=501
Oh, this one (kvm-build-on-device) doesn't even show the object cast. I was looking at kvm-build, it seems, where both the class and the object cast are visible:
http://oirase.annexia.org/tmp/2023-kvm-build.svg?s=scsi_req_new&x=455.4&y=533
Not sure if this is the reason why, but the difference between these two runs is that kvm-build is backed by a qcow2 file and kvm-build-on-device is backed by a host block device. I believe they both were otherwise identically configured qemu.
More background in this Fedora thread:
Rich.
Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
PATCH 5/7 hw/dma: Declare link using static DEFINE_PROP_LINK() macro
In reply to Philippe Mathieu-DaudéDeclare link statically using DEFINE_PROP_LINK().
--- hw/dma/xilinx_axidma.c | 6 ++---- hw/dma/xlnx-zdma.c | 7 ++----- hw/dma/xlnx_csu_dma.c | 13 ++++--------- 3 files changed, 8 insertions(+), 18 deletions(-)
hw/dma/xilinx_axidma.c +2 -4
@@ -577,10 +577,6 @@ static void xilinx_axidma_init(Object *obj)object_initialize_child (OBJECT (s),"axistream-control-connected-target" , &s->rx_control_dev,TYPE_XILINX_AXI_DMA_CONTROL_STREAM ); -object_property_add_link (obj,"dma" ,TYPE_MEMORY_REGION , - (Object **)&s->dma_mr, - qdev_prop_allow_set_link_before_realize, -OBJ_PROP_LINK_STRONG );sysbus_init_irq (sbd, &s->streams[0 ].irq);sysbus_init_irq (sbd, &s->streams[1 ].irq);
@@ -596,6 +592,8 @@ static Property axidma_properties[] = { tx_data_dev, TYPE_STREAM_SINK, StreamSink *),DEFINE_PROP_LINK ("axistream-control-connected" , XilinxAXIDMA, tx_control_dev, TYPE_STREAM_SINK, StreamSink *), +DEFINE_PROP_LINK ("dma" , XilinxAXIDMA, dma_mr, + TYPE_MEMORY_REGION, MemoryRegion *), DEFINE_PROP_END_OF_LIST(), };
hw/dma/xlnx-zdma.c +2 -5
@@ -795,11 +795,6 @@ static void zdma_init(Object *obj) TYPE_XLNX_ZDMA, ZDMA_R_MAX * 4);sysbus_init_mmio (sbd, &s->iomem);sysbus_init_irq (sbd, &s->irq_zdma_ch_imr); - -object_property_add_link (obj,"dma" ,TYPE_MEMORY_REGION , - (Object **)&s->dma_mr, - qdev_prop_allow_set_link_before_realize, -OBJ_PROP_LINK_STRONG ); }static const VMStateDescription vmstate_zdma = {
@@ -817,6 +812,8 @@ static const VMStateDescription vmstate_zdma = {static Property zdma_props[] = {DEFINE_PROP_UINT32 ("bus-width" , XlnxZDMA, cfg.bus_width,64 ), +DEFINE_PROP_LINK ("dma" , XlnxZDMA, dma_mr, + TYPE_MEMORY_REGION, MemoryRegion *),DEFINE_PROP_END_OF_LIST (), };
hw/dma/xlnx_csu_dma.c +4 -9
@@ -702,6 +702,10 @@ static Property xlnx_csu_dma_properties[] = {* which channel the device is connected to. */ DEFINE_PROP_BOOL ("is-dst" , XlnxCSUDMA, is_dst, true), +DEFINE_PROP_LINK ("stream-connected-dma" , XlnxCSUDMA, tx_dev, + TYPE_STREAM_SINK, StreamSink *), +DEFINE_PROP_LINK ("dma" , XlnxCSUDMA, dma_mr, + TYPE_MEMORY_REGION, MemoryRegion *), DEFINE_PROP_END_OF_LIST(), };
@@ -728,15 +732,6 @@ static void xlnx_csu_dma_init(Object *obj)memory_region_init (&s->iomem, obj,TYPE_XLNX_CSU_DMA ,XLNX_CSU_DMA_R_MAX *4 ); - -object_property_add_link (obj,"stream-connected-dma" ,TYPE_STREAM_SINK , - (Object **)&s->tx_dev, - qdev_prop_allow_set_link_before_realize, -OBJ_PROP_LINK_STRONG ); -object_property_add_link (obj,"dma" ,TYPE_MEMORY_REGION , - (Object **)&s->dma_mr, - qdev_prop_allow_set_link_before_realize, -OBJ_PROP_LINK_STRONG ); }static const TypeInfo xlnx_csu_dma_info = {
Signature · 1 line
2.41.0
Re: [PATCH 5/7] hw/dma: Declare link using static DEFINE_PROP_LINK() macro
Quoted 79 lines · Philippe Mathieu-Daudé
Declare link statically using
DEFINE_PROP_LINK().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/dma/xilinx_axidma.c | 6 ++---- hw/dma/xlnx-zdma.c | 7 ++----- hw/dma/xlnx_csu_dma.c | 13 ++++--------- 3 files changed, 8 insertions(+), 18 deletions(-)hw/dma/xilinx_axidma.c +2
-4@@ -577,10 +577,6 @@ static void xilinx_axidma_init(Object *obj)object_initialize_child (OBJECT (s),"axistream-control-connected-target" , &s->rx_control_dev,TYPE_XILINX_AXI_DMA_CONTROL_STREAM ); -object_property_add_link (obj,"dma" ,TYPE_MEMORY_REGION , - (Object **)&s->dma_mr, - qdev_prop_allow_set_link_before_realize, -OBJ_PROP_LINK_STRONG );sysbus_init_irq (sbd, &s->streams[0 ].irq);sysbus_init_irq (sbd, &s->streams[1 ].irq);@@ -596,6 +592,8 @@ static Property axidma_properties[] = { tx_data_dev, TYPE_STREAM_SINK, StreamSink *),DEFINE_PROP_LINK ("axistream-control-connected" , XilinxAXIDMA, tx_control_dev, TYPE_STREAM_SINK, StreamSink *), +DEFINE_PROP_LINK ("dma" , XilinxAXIDMA, dma_mr, + TYPE_MEMORY_REGION, MemoryRegion *), DEFINE_PROP_END_OF_LIST(), };hw/dma/xlnx-zdma.c +2
-5@@ -795,11 +795,6 @@ static void zdma_init(Object *obj) TYPE_XLNX_ZDMA, ZDMA_R_MAX * 4);sysbus_init_mmio (sbd, &s->iomem);sysbus_init_irq (sbd, &s->irq_zdma_ch_imr); - -object_property_add_link (obj,"dma" ,TYPE_MEMORY_REGION , - (Object **)&s->dma_mr, - qdev_prop_allow_set_link_before_realize, -OBJ_PROP_LINK_STRONG ); }static const VMStateDescription vmstate_zdma = {@@ -817,6 +812,8 @@ static const VMStateDescription vmstate_zdma = {static Property zdma_props[] = {DEFINE_PROP_UINT32 ("bus-width" , XlnxZDMA, cfg.bus_width,64 ), +DEFINE_PROP_LINK ("dma" , XlnxZDMA, dma_mr, + TYPE_MEMORY_REGION, MemoryRegion *),DEFINE_PROP_END_OF_LIST (), };hw/dma/xlnx_csu_dma.c +4
-2@@ -702,6 +702,10 @@ static Property xlnx_csu_dma_properties[] = {* which channel the device is connected to. */ DEFINE_PROP_BOOL ("is-dst" , XlnxCSUDMA, is_dst, true), +DEFINE_PROP_LINK ("stream-connected-dma" , XlnxCSUDMA, tx_dev, + TYPE_STREAM_SINK, StreamSink *), +DEFINE_PROP_LINK ("dma" , XlnxCSUDMA, dma_mr, + TYPE_MEMORY_REGION, MemoryRegion *), DEFINE_PROP_END_OF_LIST(), };@@ -728,15 +732,6 @@ static void xlnx_csu_dma_init(Object *obj)memory_region_init (&s->iomem, obj,TYPE_XLNX_CSU_DMA ,XLNX_CSU_DMA_R_MAX *4 ); - - object_property_add_link(obj, "stream-connected-dma", TYPE_STREAM_SINK,
hw/dma/xlnx_csu_dma.c static void xlnx_csu_dma_init(Object *obj) · line 737
Quoted 10 lines
hw/dma/xlnx_csu_dma.c +0
-7- (Object **)&s->tx_dev, - qdev_prop_allow_set_link_before_realize, - OBJ_PROP_LINK_STRONG); -object_property_add_link (obj,"dma" ,TYPE_MEMORY_REGION , - (Object **)&s->dma_mr, - qdev_prop_allow_set_link_before_realize, -OBJ_PROP_LINK_STRONG ); }static const TypeInfo xlnx_csu_dma_info = {
ATB,
Mark.
PATCH 6/7 hw/net: Declare link using static DEFINE_PROP_LINK() macro
In reply to Philippe Mathieu-DaudéDeclare link statically using DEFINE_PROP_LINK().
--- hw/net/cadence_gem.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
hw/net/cadence_gem.c +2 -5
@@ -1654,11 +1654,6 @@ static void gem_init(Object *obj) "enet", sizeof(s->regs));sysbus_init_mmio (SYS_BUS_DEVICE (dev), &s->iomem); - -object_property_add_link (obj,"dma" ,TYPE_MEMORY_REGION , - (Object **)&s->dma_mr, - qdev_prop_allow_set_link_before_realize, -OBJ_PROP_LINK_STRONG ); }static const VMStateDescription vmstate_cadence_gem = {
@@ -1691,6 +1686,8 @@ static Property gem_properties[] = { num_type2_screeners, 4),DEFINE_PROP_UINT16 ("jumbo-max-len" , CadenceGEMState, jumbo_max_len,10240 ), +DEFINE_PROP_LINK ("dma" , CadenceGEMState, dma_mr, + TYPE_MEMORY_REGION, MemoryRegion *), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
2.41.0
Re: [PATCH 6/7] hw/net: Declare link using static DEFINE_PROP_LINK() macro
Quoted 24 lines · Philippe Mathieu-Daudé
Declare link statically using
DEFINE_PROP_LINK().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/net/cadence_gem.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)hw/net/cadence_gem.c +0
-5@@ -1654,11 +1654,6 @@ static void gem_init(Object *obj) "enet", sizeof(s->regs));sysbus_init_mmio (SYS_BUS_DEVICE (dev), &s->iomem); - -object_property_add_link (obj,"dma" ,TYPE_MEMORY_REGION , - (Object **)&s->dma_mr, - qdev_prop_allow_set_link_before_realize, -OBJ_PROP_LINK_STRONG ); }static const VMStateDescription vmstate_cadence_gem = {
hw/net/cadence_gem.c static Property gem_properties[] = { · line 1692
Quoted 7 lines
hw/net/cadence_gem.c +2
-0@@ -1691,6 +1686,8 @@ static Property gem_properties[] = { num_type2_screeners, 4),DEFINE_PROP_UINT16 ("jumbo-max-len" , CadenceGEMState, jumbo_max_len,10240 ), +DEFINE_PROP_LINK ("dma" , CadenceGEMState, dma_mr, + TYPE_MEMORY_REGION, MemoryRegion *), DEFINE_PROP_END_OF_LIST(), };
ATB,
Mark.
PATCH 7/7 hw/usb: Declare link using static DEFINE_PROP_LINK() macro
In reply to Philippe Mathieu-DaudéPull the 'dma' property to the core XHCI type, declare its link statically using DEFINE_PROP_LINK().
--- hw/usb/hcd-xhci-sysbus.c | 4 ---- hw/usb/hcd-xhci.c | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-)
hw/usb/hcd-xhci-sysbus.c +0 -4
@@ -60,10 +60,6 @@ static void xhci_sysbus_instance_init(Object *obj)object_initialize_child (obj,"xhci-core" , &s->xhci,TYPE_XHCI );qdev_alias_all_properties (DEVICE (&s->xhci), obj); -object_property_add_link (obj,"dma" ,TYPE_MEMORY_REGION , - (Object **)&s->xhci.dma_mr, - qdev_prop_allow_set_link_before_realize, -OBJ_PROP_LINK_STRONG ); s->xhci.intr_update =NULL ; s->xhci.intr_raise = xhci_sysbus_intr_raise; }
hw/usb/hcd-xhci.c +2 -0
@@ -3638,6 +3638,8 @@ static Property xhci_properties[] = {DEFINE_PROP_UINT32 ("p3" , XHCIState, numports_3,4 ),DEFINE_PROP_LINK ("host" , XHCIState, hostOpaque,TYPE_DEVICE , DeviceState *), +DEFINE_PROP_LINK ("dma" , XHCIState, dma_mr, + TYPE_MEMORY_REGION, MemoryRegion *), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
2.41.0
Re: [PATCH 7/7] hw/usb: Declare link using static DEFINE_PROP_LINK() macro
Quoted 29 lines · Philippe Mathieu-Daudé
Pull the 'dma' property to the core XHCI type, declare its link statically using
DEFINE_PROP_LINK().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/usb/hcd-xhci-sysbus.c | 4 ---- hw/usb/hcd-xhci.c | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-)hw/usb/hcd-xhci-sysbus.c +0
-4@@ -60,10 +60,6 @@ static void xhci_sysbus_instance_init(Object *obj)object_initialize_child (obj,"xhci-core" , &s->xhci,TYPE_XHCI );qdev_alias_all_properties (DEVICE (&s->xhci), obj); -object_property_add_link (obj,"dma" ,TYPE_MEMORY_REGION , - (Object **)&s->xhci.dma_mr, - qdev_prop_allow_set_link_before_realize, -OBJ_PROP_LINK_STRONG ); s->xhci.intr_update =NULL ; s->xhci.intr_raise = xhci_sysbus_intr_raise; }hw/usb/hcd-xhci.c +0
-0
hw/usb/hcd-xhci.c static Property xhci_properties[] = { · line 3644
Quoted 7 lines
hw/usb/hcd-xhci.c +2
-0@@ -3638,6 +3638,8 @@ static Property xhci_properties[] = {DEFINE_PROP_UINT32 ("p3" , XHCIState, numports_3,4 ),DEFINE_PROP_LINK ("host" , XHCIState, hostOpaque,TYPE_DEVICE , DeviceState *), +DEFINE_PROP_LINK ("dma" , XHCIState, dma_mr, + TYPE_MEMORY_REGION, MemoryRegion *), DEFINE_PROP_END_OF_LIST(), };
I'm slightly unsure about this one: does pulling the "dma" property into the core type cause any issues if the property is left unset for any non-sysbus xhci users?
ATB,
Mark.
Quoted 3 lines · Philippe Mathieu-Daudé
- Remove a pointless check,
- Use QOM cast macros,
- Declare QDev links statically usingDEFINE_PROP_LINK()
virtio things
Quoted 23 lines
Philippe Mathieu-Daudé (7):
hw/virtio/virtio-pmem: Replace impossible check by assertion hw/block/vhost-user-blk: UseDEVICE()/VIRTIO_DEVICE()macros hw/display/virtio-gpu: UseVIRTIO_DEVICE()macro hw/scsi/virtio-scsi: UseVIRTIO_SCSI_COMMON()macro hw/dma: Declare link using staticDEFINE_PROP_LINK()macro hw/net: Declare link using staticDEFINE_PROP_LINK()macro hw/usb: Declare link using staticDEFINE_PROP_LINK()macrohw/block/vhost-user-blk.c | 4 ++-- hw/display/virtio-gpu.c | 2 +- hw/dma/xilinx_axidma.c | 6 ++---- hw/dma/xlnx-zdma.c | 7 ++----- hw/dma/xlnx_csu_dma.c | 13 ++++--------- hw/net/cadence_gem.c | 7 ++----- hw/scsi/virtio-scsi.c | 2 +- hw/usb/hcd-xhci-sysbus.c | 4 ---- hw/usb/hcd-xhci.c | 2 ++ hw/virtio/virtio-pmem.c | 5 +---- 10 files changed, 17 insertions(+), 35 deletions(-)Signature · 1 line
2.41.0
Quoted 7 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (7):
hw/virtio/virtio-pmem: Replace impossible check by assertion hw/block/vhost-user-blk: UseDEVICE()/VIRTIO_DEVICE()macros hw/display/virtio-gpu: UseVIRTIO_DEVICE()macro hw/scsi/virtio-scsi: UseVIRTIO_SCSI_COMMON()macro hw/dma: Declare link using staticDEFINE_PROP_LINK()macro hw/net: Declare link using staticDEFINE_PROP_LINK()macro
Patches 1-6 queued to hw-misc.