From: Zhao Liu <zhao1.liu@intel.com>
To: "Daniel P . Berrangé" <berrange@redhat.com>,
"Igor Mammedov" <imammedo@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Yanan Wang" <wangyanan55@huawei.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Cédric Le Goater" <clg@kaod.org>,
"Nicholas Piggin" <npiggin@gmail.com>,
"Frédéric Barrat" <fbarrat@linux.ibm.com>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Marcelo Tosatti" <mtosatti@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Peter Maydell" <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org,
qemu-arm@nongnu.org, Zhenyu Wang <zhenyu.z.wang@intel.com>,
Dapeng Mi <dapeng1.mi@linux.intel.com>,
Yongwei Ma <yongwei.ma@intel.com>, Zhao Liu <zhao1.liu@intel.com>
Subject: [RFC v2 01/15] qdev: Add pointer to BusChild in DeviceState
Date: Thu, 19 Sep 2024 09:55:19 +0800 [thread overview]
Message-ID: <20240919015533.766754-2-zhao1.liu@intel.com> (raw)
In-Reply-To: <20240919015533.766754-1-zhao1.liu@intel.com>
The device topology structures based on buses are unidirectional: the
parent device can access the child device through the BusChild within
the bus, but not vice versa.
For the CPU topology tree constructed on the device-bus, it is necessary
for the child device to be able to access the parent device via the
parent bus. To address this, introduce a pointer to the BusChild, named
bus_node.
This pointer also simplifies the logic of bus_remove_child(). Instead of
the parent bus needing to traverse the children list to locate the
corresponding BusChild, it can now directly find it using the bus_node
pointer.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
hw/core/qdev.c | 29 ++++++++++++++---------------
include/hw/qdev-core.h | 4 ++++
include/qemu/typedefs.h | 1 +
3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index db36f54d914a..4429856eaddd 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -57,25 +57,23 @@ static void bus_free_bus_child(BusChild *kid)
static void bus_remove_child(BusState *bus, DeviceState *child)
{
- BusChild *kid;
-
- QTAILQ_FOREACH(kid, &bus->children, sibling) {
- if (kid->child == child) {
- char name[32];
+ BusChild *kid = child->bus_node;
+ char name[32];
- snprintf(name, sizeof(name), "child[%d]", kid->index);
- QTAILQ_REMOVE_RCU(&bus->children, kid, sibling);
+ if (!kid) {
+ return;
+ }
- bus->num_children--;
+ snprintf(name, sizeof(name), "child[%d]", kid->index);
+ QTAILQ_REMOVE_RCU(&bus->children, kid, sibling);
+ child->bus_node = NULL;
+ bus->num_children--;
- /* This gives back ownership of kid->child back to us. */
- object_property_del(OBJECT(bus), name);
+ /* This gives back ownership of kid->child back to us. */
+ object_property_del(OBJECT(bus), name);
- /* free the bus kid, when it is safe to do so*/
- call_rcu(kid, bus_free_bus_child, rcu);
- break;
- }
- }
+ /* free the bus kid, when it is safe to do so*/
+ call_rcu(kid, bus_free_bus_child, rcu);
}
static void bus_add_child(BusState *bus, DeviceState *child)
@@ -86,6 +84,7 @@ static void bus_add_child(BusState *bus, DeviceState *child)
bus->num_children++;
kid->index = bus->max_index++;
kid->child = child;
+ child->bus_node = kid;
object_ref(OBJECT(kid->child));
QTAILQ_INSERT_HEAD_RCU(&bus->children, kid, sibling);
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index aa97c34a4be7..85c7d462dfba 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -253,6 +253,10 @@ struct DeviceState {
* @parent_bus: bus this device belongs to
*/
BusState *parent_bus;
+ /**
+ * @bus_node: bus node inserted in parent bus
+ */
+ BusChild *bus_node;
/**
* @gpios: QLIST of named GPIOs the device provides.
*/
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index 9d222dc37628..aef41c4e67ce 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -32,6 +32,7 @@ typedef struct BdrvDirtyBitmapIter BdrvDirtyBitmapIter;
typedef struct BlockBackend BlockBackend;
typedef struct BlockBackendRootState BlockBackendRootState;
typedef struct BlockDriverState BlockDriverState;
+typedef struct BusChild BusChild;
typedef struct BusClass BusClass;
typedef struct BusState BusState;
typedef struct Chardev Chardev;
--
2.34.1
next prev parent reply other threads:[~2024-09-19 1:40 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-19 1:55 [RFC v2 00/15] qom-topo: Abstract CPU Topology Level to Topology Device Zhao Liu
2024-09-19 1:55 ` Zhao Liu [this message]
2024-09-19 1:55 ` [RFC v2 02/15] qdev: Add the interface to reparent the device Zhao Liu
2024-09-19 1:55 ` [RFC v2 03/15] hw/cpu: Introduce CPU topology device and CPU bus Zhao Liu
2024-09-19 1:55 ` [RFC v2 04/15] hw/cpu: Introduce CPU slot to manage CPU topology Zhao Liu
2024-09-19 1:55 ` [RFC v2 05/15] qdev: Add method in BusClass to customize device index Zhao Liu
2024-09-19 1:55 ` [RFC v2 06/15] hw/core: Create CPU slot in MachineState to manage CPU topology tree Zhao Liu
2024-09-19 1:55 ` [RFC v2 07/15] hw/core/cpu: Convert CPU from general device to topology device Zhao Liu
2024-09-19 1:55 ` [RFC v2 08/15] hw/cpu/core: Convert cpu-core " Zhao Liu
2024-09-19 1:55 ` [RFC v2 09/15] hw/cpu: Abstract module/die/socket levels as topology devices Zhao Liu
2024-09-19 1:55 ` [RFC v2 10/15] hw/machine: Build smp topology tree from -smp Zhao Liu
2024-09-19 1:55 ` [RFC v2 11/15] hw/core: Support topology tree in none machine for compatibility Zhao Liu
2024-09-19 1:55 ` [RFC v2 12/15] hw/i386: Allow i386 to create new CPUs in topology tree Zhao Liu
2024-09-19 1:55 ` [RFC v2 13/15] system/qdev-monitor: Introduce bus-finder interface for compatibility with bus-less plug behavior Zhao Liu
2024-09-19 1:55 ` [RFC v2 14/15] i386/cpu: Support CPU plugged in topology tree via bus-finder Zhao Liu
2024-09-19 1:55 ` [RFC v2 15/15] i386: Support topology device tree Zhao Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240919015533.766754-2-zhao1.liu@intel.com \
--to=zhao1.liu@intel.com \
--cc=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=clg@kaod.org \
--cc=danielhb413@gmail.com \
--cc=dapeng1.mi@linux.intel.com \
--cc=david@gibson.dropbear.id.au \
--cc=eduardo@habkost.net \
--cc=fbarrat@linux.ibm.com \
--cc=harshpb@linux.ibm.com \
--cc=imammedo@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=npiggin@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=wangyanan55@huawei.com \
--cc=yongwei.ma@intel.com \
--cc=zhenyu.z.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).