qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
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 06/15] hw/core: Create CPU slot in MachineState to manage CPU topology tree
Date: Thu, 19 Sep 2024 09:55:24 +0800	[thread overview]
Message-ID: <20240919015533.766754-7-zhao1.liu@intel.com> (raw)
In-Reply-To: <20240919015533.766754-1-zhao1.liu@intel.com>

With CPU slot support, the machine can manage the CPU topology tree. To
enable hot-plug support for topology devices, use the machine as the
hotplug handler for the CPU bus.

Additionally, since not all machines support the topology tree from the
start, add a "topo_tree_supported" flag to indicate whether a machine
supports the topology tree. And create the CPU slot as the topology root
only for machines that support it.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 hw/core/machine.c         |  2 ++
 hw/cpu/cpu-slot.c         | 34 ++++++++++++++++++++++++++++++++++
 include/hw/boards.h       |  9 +++++++++
 include/hw/cpu/cpu-slot.h |  2 ++
 system/vl.c               |  4 ++++
 5 files changed, 51 insertions(+)

diff --git a/hw/core/machine.c b/hw/core/machine.c
index 518beb9f883a..b6258d95b1e8 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -1239,6 +1239,8 @@ static void machine_initfn(Object *obj)
         ms->smp_cache.props[i].topology = CPU_TOPOLOGY_LEVEL_DEFAULT;
     }
 
+    ms->topo = NULL;
+
     machine_copy_boot_config(ms, &(BootConfiguration){ 0 });
 }
 
diff --git a/hw/cpu/cpu-slot.c b/hw/cpu/cpu-slot.c
index 66ef8d9faa97..4dbd5b7b7e00 100644
--- a/hw/cpu/cpu-slot.c
+++ b/hw/cpu/cpu-slot.c
@@ -138,3 +138,37 @@ static void cpu_slot_register_types(void)
 }
 
 type_init(cpu_slot_register_types)
+
+void machine_plug_cpu_slot(MachineState *ms)
+{
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
+    CPUSlot *slot;
+
+    slot = CPU_SLOT(qdev_new(TYPE_CPU_SLOT));
+    set_bit(CPU_TOPOLOGY_LEVEL_THREAD, slot->supported_levels);
+    set_bit(CPU_TOPOLOGY_LEVEL_CORE, slot->supported_levels);
+    set_bit(CPU_TOPOLOGY_LEVEL_SOCKET, slot->supported_levels);
+
+    /*
+     * Now just consider the levels that x86 supports.
+     * TODO: Supports other levels.
+     */
+    if (mc->smp_props.modules_supported) {
+        set_bit(CPU_TOPOLOGY_LEVEL_MODULE, slot->supported_levels);
+    }
+
+    if (mc->smp_props.dies_supported) {
+        set_bit(CPU_TOPOLOGY_LEVEL_DIE, slot->supported_levels);
+    }
+
+    ms->topo = slot;
+    object_property_add_child(container_get(OBJECT(ms), "/peripheral"),
+                              "cpu-slot", OBJECT(ms->topo));
+    DEVICE(ms->topo)->id = g_strdup_printf("%s", "cpu-slot");
+
+    sysbus_realize(SYS_BUS_DEVICE(slot), &error_abort);
+
+    if (mc->get_hotplug_handler) {
+        qbus_set_hotplug_handler(BUS(&slot->bus), OBJECT(ms));
+    }
+}
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 2dd8decf640a..eeb4e7e2ce9f 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -10,6 +10,7 @@
 #include "qemu/module.h"
 #include "qom/object.h"
 #include "hw/core/cpu.h"
+#include "hw/cpu/cpu-slot.h"
 
 #define TYPE_MACHINE_SUFFIX "-machine"
 
@@ -152,6 +153,8 @@ typedef struct {
  * @modules_supported - whether modules are supported by the machine
  * @cache_supported - whether cache topologies (l1d, l1i, l2 and l3) are
  *                    supported by the machine
+ * @topo_tree_supported - whether QOM topology tree is supported by the
+ *                        machine
  */
 typedef struct {
     bool prefer_sockets;
@@ -162,6 +165,7 @@ typedef struct {
     bool drawers_supported;
     bool modules_supported;
     bool cache_supported[CACHE_LEVEL_AND_TYPE__MAX];
+    bool topo_tree_supported;
 } SMPCompatProps;
 
 /**
@@ -431,6 +435,11 @@ struct MachineState {
     CPUArchIdList *possible_cpus;
     CpuTopology smp;
     SmpCache smp_cache;
+    /*
+     * TODO: get rid of "smp" and merge it into "topo" when all arches
+     * support QOM topology.
+     */
+    CPUSlot *topo;
     struct NVDIMMState *nvdimms_state;
     struct NumaState *numa_state;
 };
diff --git a/include/hw/cpu/cpu-slot.h b/include/hw/cpu/cpu-slot.h
index 9d02d5de578e..24e122013bf7 100644
--- a/include/hw/cpu/cpu-slot.h
+++ b/include/hw/cpu/cpu-slot.h
@@ -69,4 +69,6 @@ struct CPUSlot {
     DeviceListener listener;
 };
 
+void machine_plug_cpu_slot(MachineState *ms);
+
 #endif /* CPU_SLOT_H */
diff --git a/system/vl.c b/system/vl.c
index fe547ca47c27..193e7049ccbe 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -2151,6 +2151,10 @@ static void qemu_create_machine(QDict *qdict)
                                           false, &error_abort);
         qobject_unref(default_opts);
     }
+
+    if (machine_class->smp_props.topo_tree_supported) {
+        machine_plug_cpu_slot(current_machine);
+    }
 }
 
 static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
-- 
2.34.1



  parent reply	other threads:[~2024-09-19  1:42 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 ` [RFC v2 01/15] qdev: Add pointer to BusChild in DeviceState Zhao Liu
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 ` Zhao Liu [this message]
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-7-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).