qom-topo: Abstract CPU Topology Level to Topology Device
Subsystems (2)
v2 cover qom-topo: Abstract CPU Topology Level to Topology Device
Hi all,
After ten months, now I bring our 2nd attempt on CPU topology device back to mail list.
This series is still a practical implementation of Daniel’s idea
[0] from early last year on how to achieve hybrid topology based on QOM abstraction.
And this series is a preliminary step for introducing hybrid (aka, heterogeneous) CPU topology to QEMU. With the QOM topology support introduced in this series, for future hybrid CPU topology, QEMU will allow users to customize the topology tree via CLI using the -device command.
Compared to v1 [1], the goals of v2 stay the same:
1. Abstract a special class of device - "CPU topology device' - to handle CPU topology relationship.
2. Derive all CPU topology related devices, including existing CPU/core devices, as well as newly added module/die/socket devices, from "CPU topology device".
3. Build a CPU topology device tree based on the topology relationships represented by the CPU topology devices.
The main difference between v1 and v2 is that v2 introduces the special CPU bus to manage topology. The current QEMU Bus abstraction effectively manages the topology between devices, so applying it to CPU topology can avoid introducing an additional set of logic to handle topology relationships. Therefore, compared to v1, the code in v2 can be significantly reduced. (About why we made this change, pls refer the last two paragraphs in Section 3. "History of QOM (CPU) Topology".)
In addition, v2 removes the support about user custom topology creation from CLI. Since this part has more opens, the subsequent hybrid (CPU) topology v2 will discuss this.
This series make x86 support the topology tree as the example. I also hope that eventually all architectures and machines in QEMU will accept QOM topology.
Patches are based on my previous SMP cache topology series [2] (in fact, I rebase both them at the commit 2b81c046252f ("Merge tag 'block-pull- request' of https://gitlab.com/stefanha/qemu into staging")).
As ARM may has potential need for hybrid topology, I also add ARM folks in this thread.
This is a huge cover letter and a huge series, thank you for your patience and time! And welcome your feedback and comments!
1. Summary about What We Did?
=============================
Before introducing the background, please allow me to briefly outline the main work of this series. This will help relate it to the continuous efforts and discussions of the past decade.
* Implement CPU topology device/bus abstraction and topology tree.
This series implements a topology tree for (x86) machine like the following:
┌────────────────┐
│ │
│ MachineState │
│ │
└───────┬────────┘
│
┌─────┼─────┐
│ CPU Slot │
└─────┬─────┘
┌───┼───┐
│CPU Bus│
└───┬───┘
│
┌─────▼─────┐
│ CPU Socket│
└─────┬─────┘
┌───┼───┐
│CPU Bus│
└───┬───┘
│
┌─────▼─────┐
│ CPU Die │
└─────┬─────┘
┌───┼───┐
│CPU Bus│
└───┬───┘
│
┌─────▼─────┐
│ CPU Die │
└─────┬─────┘
┌───┼───┐
│CPU Bus│
└───┬───┘
┌──────┴──────┐
┌─────▼─────┐ ┌─────▼─────┐
│ CPU Module│ │ CPU Module│
└─────┬─────┘ └─────┬─────┘
┌───┼───┐ ┌───┼───┐
│CPU Bus│ │CPU Bus│
└───┬───┘ └───┬───┘
│ │
┌─────▼─────┐ ┌─────▼─────┐
│ CPU Core │ │ CPU Core │
└─────┬─────┘ └─────┬─────┘
┌───┼───┐ ┌───┼───┐
│CPU Bus│ │CPU Bus│
└──┬────┘ └────┬──┘
┌───┴───┐ ┌───┴───┐
┌──▼──┐ ┌──▼──┐ ┌──▼──┐ ┌──▼──┐
│ CPU │ │ CPU │ │ CPU │ │ CPU │
└─────┘ └─────┘ └─────┘ └─────┘ The Socket/Die/Module/Core/CPU are all the devices derived from CPU topology device ("CPUTopoState") and are connected through the "CPU bus", hierarchy by hierarchy.
The root of above topology tree is a CPU bus bridge named "CPU Slot", which is plugged in MachineState. The CPU Slot is designed to replace the current MachineState.smp to manage all CPU topologies. It will listen to the realize() and unrealize() of the CPU topology device and update the topology information to monitor topology tree updates and the plug/unplug event of topology devices.
* Based on topology tree, make qom-path match topology relationship.
This is implemented by re-parenting the topology device to its actual topological parent in the tree. This is an CPU example:
{
"props": {
"core-id": 0,
"die-id": 0,
"module-id": 0,
"socket-id": 0,
"thread-id": 0
},
"qom-path": "/machine/peripheral/cpu-slot/sock0/die0/core0/host-x86_64-cpu[0]",
"type": "host-x86_64-cpu",
"vcpus-count": 1
}* Introduce "bus-finder" to convert CPU's topology ID properties (thread-id/core-id, etc) to specific "CPU bus".
At present, topology ID properties are used to find free slot in possible_cpus[]. Once there's the CPU bus, it's necessary to use such properties to locate the proper parent CPU bus when adding the CPU from CLI. The "bus-finder" is an "INTERFACE" to help qdev search parent bus with device's properties.
2. What's the Problem?
======================
As computer architectures continue to innovate, the need for hybrid (aka, heterogeneous) topology of virtual machine in QEMU is growing.
Hybrid topology includes hybrid CPU topology and hybrid cache topology:
- Hybrid CPU topology:
Hybrid CPU topology refers to systems that use more than one kind of processor or cores [3] with the same ISA. The typical example is intel hybrid architecture with 2 core types [4], which will even have hybrid die topology [5]. And we can see that not only Intel, but also ARM and AMD's heterogeneous platforms will have the ability to support virtualization.
- Hybrid cache topology:
Not only Intel's hybrid platforms introduced complex hybrid cache topology, but more platforms have also seen the strong demand for hybrid cache topology definition (e.g. ARM [6]). Although cache topology is strictly speaking a separate topology from CPU topology, in terms of the actual processor build process and the current QEMU's way to define cache topology (e.g., i386 [7] & ARM [8]), cache topology is and should be dependent on CPU topology to be defined. Even for the SMP CPU case, the hyrbid cache topology is also useful to define different caches at same level (e.g., AMD x3D). The hybrid cache topology will depend on the implementation of the hybrid CPU topology, which is our future work.
The benefits of introducing hybrid topology for QEMU include:
* Allow QEMU to emulate complex heterogeneous CPU hardware.
* Hybrid topology information in Guest can help Guest improve performance and achieve better power efficiency based on Host's hardware difference.
* Enable hybrid features in Guest, for example, Intel's hybrid PMU.
Obviously, -smp is not enough. And though QEMU could define different properties for CPUs (like S390s [9]), it's not enough to handle or express complicated topology replationship.
Therefore, we're trying to figure out a proper way to define hybrid topology in QEMU.
This series, implementing QOM (CPU) topology, is the foundation of our hybrid topology support.
3. History of QOM (CPU) Topology
================================
The intent of QOM topology is not to stop at QOM CPUs, but to abstract more CPU topology levels.
In fact, it's not a new term.
Back in 2014, Fan proposed [10] a hierarchical tree based on QOM node, QOM sockets, QOM cores and QOM cpu. Andreas also propsed [11] socket/ core/thread QOM model to create hierarchical topology in place. From the discussion at that time, the hierarchy topology tree representation was what people (Igor said [12]) wanted. However, this work was not continued.
Then Bharata proposed to "CPU group" concept to handle CPU hotplug, but eventually matintainers accepted the cpu-core abstraction [13] to support core granularity hotplug for SPAPR. Until now, the only user of cpu-core is still PPC (PNV core and SPAPR core).
Cpu-cluster was introduced by Luc [14] to organize CPUs in different containers to support GDB for TCG case. Though this abstraction was descripted as: "mainly an internal QEMU representation and does not necessarily match with the notion of clusters on the real hardware", its name and function actually make it easy to correspond to the physical cluster/smp cluster (the difference, of course, is that TCG cluster collects CPUs directly, while the cluster as a CPU topology level collect cores, but this difference is not the impediment gap to convert "TCG " cluster to "general" cluster).
As CPU architectures evolve, QEMU has supported more topology levels (module, cluster, die, book and drawer), while the existing cpu-core and cpu-cluster abstractions become fragmented.
And now, the need for defining hybrid topology has prompted us to rethink the QOM topology.
Daniel suggested [0] to use -object interfaces to define CPU topology, and we absorbed his design idea. But in practice we found that -device looked like a better approach to take advantage of the current QOM CPU device, cpu-core device and cpu-cluster device. Therefore, this is this RFC to enhance CPU topology related devices.
The v1 RFC [1] has implemented the CPU topology device abstraction. However, the parent topology device and child topology device were not connected via a bus. Instead, a bus-like topology management mechanism was implemented separately for topology devices. Additionally, since the topology device in v1 was busless, adding devices via CLI does not support child<> connections. v1 faced significant difficulties to support child<> creation in the CLI.
Therefore, v2 learned from v1’s lessons and directly abstracted the "virtual" CPU bus (however, strictly speaking, there are prototypes in reality, such as the interconnect bus/ring bus) to utilize the existing bus mechanism for topology management. This also reduces the burden for subsequent hybrid topology series to create the topology tree via CLI.
4. Design Overview
==================
4.1. General CPU Topology Device
================================
We introduce a new topology device type as the basic abstraction, then all levels of the CPU topology are derived from this general CPU topology device type.
This topology device is the basic unit for building the topology tree. Children topology devices are inserted into the queue of the parent, and the child<> property is created between the children and their parent so that the qom-path could reflect topology relationship.
At the same time, to manage the topology relationship between parent device and child device, we introduce CPU bus to utilize existing device topology management ability of Qbus.
Additionally, as the root of the topology tree, we introduce a special "cpu-slot". It is created by the machine at machine's initialization and collects the topology devices created for the machine, and builds the CPU topology tree.
The cpu-slot is also responsible for statistics on global topology information, and whenever there is a new topology child, the cpu-slot as root is notified to update topology informantion. In addition, different architectures have different requirements for topology (e.g., support for different levels), and such limitations/properties are applied to cpu-slot, which is checked when adding the new child topology unit in topology tree.
4.2. Derived QOM Topology Devices
=================================
Based on the new general topology device type, (currently for x86) we convert CPU and cpu-core from general devices to topology devices.
And we also abstract cpu-module, cpu-die and cpu-socket as topology devices for x86's use.
4.3. "bus-finder" Interface to Convert Topology IDs to Topology Bus
===================================================================
Currently CPUs (across arches) use topology IDs to find the free slot in possible_cpus[].
For x86 CPU, the related properties include "thread-id"/"core-id"/ "module-id"/"die-id"/"socket-id", and "apicid". But actually, APIC ID is the combanition of topology IDs.
Those topology IDs implicitly maps the CPU to a (non-existent) topology tree. Now, we have the real topology tree. Then it's natural to use such topology IDs to search the proper topology parent in the tree.
In particular, when we transform the CPU into a CPU topology device with the bus_type, then this transformation is necessary to help find the correct parent bus (on parent topology device).
Therefore, we introduce the "bus-finder" interface, which provides the hook in qdev_device_add_from_qdict(), allowing arch CPU to use topology ID properties to find the parent bus.
4.4. Topology Tree building
===========================
At present, possible_cpus[] provides the CPU level (for PPC, core level) topology.
It's difficult to completely discard possible_cpus[] and build the topology tree entirely from scratch.
In v2, we take a compromise: after the -smp parsing is done, machine creates a topology tree, but only contains the hierarchies from the highest level up to the level higher than posssible_cpus[]. For x86, possible_cpus[] contains CPUs, so that the initial topology tree will have the hierarchies from socket level to core level.
Then when arch machine initialize CPUs, MachineClass.possible_cpu_arch_ids() will creates CPUs in possible_cpus[], and the CPU topology abstraction under the CPU device will insert the created CPUs into the topology tree based on the topology ID properties, so that a topology tree is completed.
5. Future TODOs
===============
The current QOM topology RFC is only the very first step to introduce the most basic QOM support, and it tries to be as compatible as possible with existing SMP facilities.
The ultimate goal is to completely replace the current smp-related topology structures with cpu-slot.
There are many TODOs:
* Add unit tests.
* Support QOM topology for all architectures.
* Get rid of MachineState.smp and MachineClass.smp_props with cpu-slot.
...
6. Patch Summary
================
Patch 01-02: Necessary change for qdev to support CPU topology via bus. Ptach 03-06: Introduce CPU topology device abstraction and CPU slot in
machine.
Patch 07-09: Abstract all topology levels to topology devices (for x86). Patch 10-11: Build topology tree for machine.
Patch 12-15: Enable topology tree for x86 machine.
7. Reference
============
[0]: Daniel's suggestion about QOM topology:
https://lore.kernel.org/qemu-devel/[email protected]/
[1]: [RFC 00/41] qom-topo: Abstract Everything about CPU Topology
https://lore.kernel.org/qemu-devel/[email protected]/ [2]: [PATCH v2 0/7] Introduce SMP Cache Topology https://lore.kernel.org/qemu-devel/[email protected]/ [3]: Heterogeneous computing: https://en.wikipedia.org/wiki/Heterogeneous_computing [4]: 12th gen’s Intel hybrid technology: https://www.intel.com/content/www/us/en/support/articles/000091896/processors.html [5]: Intel Meteor Lake (14th gen) architecture overview: https://www.intel.com/content/www/us/en/content-details/788851/meteor-lake-architecture-overview.html [6]: Need of ARM heterogeneous cache topology (by Yanan): https://mail.gnu.org/archive/html/qemu-devel/2023-02/msg05139.html [7]: Cache topology implementation for i386: https://lists.gnu.org/archive/html/qemu-devel/2023-10/msg08251.html [8]: Cluster for ARM to define shared L2 cache and L3 tag (by Yanan): https://lore.kernel.org/all/[email protected]/ [9]: S390x topology document (by Nina): https://lists.gnu.org/archive/html/qemu-devel/2023-10/msg04842.html [10]: [PATCH v1 0/4] prebuild cpu QOM tree /machine/node/socket/core ->link-cpu (by Fan): https://lore.kernel.org/all/[email protected]/
[11]: [PATCH RFC 0/4] target-i386: PC socket/core/thread modeling,
part 1 (by Andreas):
https://lore.kernel.org/all/[email protected]/
[12]: "Now we want to have similar QOM tree for introspection which
helps express topology as well" (by Igor):
https://lore.kernel.org/all/[email protected]/
[13]: [for-2.7 PATCH v3 06/15] cpu: Abstract CPU core type (by Bharata)
https://lore.kernel.org/all/[email protected]/ [14]: [PATCH v8 01/16] hw/cpu: introduce CPU clusters (by Luc): https://lore.kernel.org/all/[email protected]/
Thanks and Best Regards,
Zhao
---
Zhao Liu (15):
qdev: Add pointer to BusChild in DeviceState
qdev: Add the interface to reparent the device
hw/cpu: Introduce CPU topology device and CPU bus
hw/cpu: Introduce CPU slot to manage CPU topology
qdev: Add method in BusClass to customize device index hw/core: Create CPU slot in MachineState to manage CPU topology tree hw/core/cpu: Convert CPU from general device to topology device hw/cpu/core: Convert cpu-core from general device to topology device hw/cpu: Abstract module/die/socket levels as topology devices hw/machine: Build smp topology tree from -smp
hw/core: Support topology tree in none machine for compatibility hw/i386: Allow i386 to create new CPUs in topology tree system/qdev-monitor: Introduce bus-finder interface for compatibility
with bus-less plug behavior
i386/cpu: Support CPU plugged in topology tree via bus-finder
i386: Support topology device tree
MAINTAINERS | 12 ++ accel/kvm/kvm-all.c | 4 +- hw/core/cpu-common.c | 42 +++- hw/core/machine.c | 7 + hw/core/null-machine.c | 5 + hw/core/qdev.c | 89 +++++++-- hw/cpu/core.c | 9 +- hw/cpu/cpu-slot.c | 327 ++++++++++++++++++++++++++++++++ hw/cpu/cpu-topology.c | 216 +++++++++++++++++++++ hw/cpu/die.c | 34 ++++ hw/cpu/meson.build | 6 + hw/cpu/module.c | 34 ++++ hw/cpu/socket.c | 34 ++++ hw/i386/microvm.c | 13 +- hw/i386/x86-common.c | 226 +++++++++++++++------- hw/i386/x86.c | 2 + hw/pci-host/pnv_phb.c | 59 ++---- hw/ppc/pnv_core.c | 11 +- hw/ppc/spapr_cpu_core.c | 12 +- include/hw/boards.h | 11 ++ include/hw/core/cpu.h | 7 +- include/hw/cpu/core.h | 3 +- include/hw/cpu/cpu-slot.h | 79 ++++++++ include/hw/cpu/cpu-topology.h | 69 +++++++ include/hw/cpu/die.h | 29 +++ include/hw/cpu/module.h | 29 +++ include/hw/cpu/socket.h | 29 +++ include/hw/i386/x86.h | 2 + include/hw/ppc/pnv_core.h | 3 +- include/hw/ppc/spapr_cpu_core.h | 4 +- include/hw/qdev-core.h | 9 + include/monitor/bus-finder.h | 41 ++++ include/qemu/bitops.h | 5 + include/qemu/typedefs.h | 3 + stubs/hotplug-stubs.c | 5 + system/bus-finder.c | 46 +++++ system/meson.build | 1 + system/qdev-monitor.c | 41 +++- system/vl.c | 4 + target/i386/cpu.c | 13 ++ target/ppc/kvm.c | 2 +- 41 files changed, 1417 insertions(+), 160 deletions(-) create mode 100644 hw/cpu/cpu-slot.c create mode 100644 hw/cpu/cpu-topology.c create mode 100644 hw/cpu/die.c create mode 100644 hw/cpu/module.c create mode 100644 hw/cpu/socket.c create mode 100644 include/hw/cpu/cpu-slot.h create mode 100644 include/hw/cpu/cpu-topology.h create mode 100644 include/hw/cpu/die.h create mode 100644 include/hw/cpu/module.h create mode 100644 include/hw/cpu/socket.h create mode 100644 include/monitor/bus-finder.h create mode 100644 system/bus-finder.c
Signature · 1 line
2.34.1
RFC v2 1/15 qdev: Add pointer to BusChild in DeviceState
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.
--- hw/core/qdev.c | 29 ++++++++++++++--------------- include/hw/qdev-core.h | 4 ++++ include/qemu/typedefs.h | 1 + 3 files changed, 19 insertions(+), 15 deletions(-)
hw/core/qdev.c +14 -15
@@ -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);
include/hw/qdev-core.h +4 -0
@@ -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. */
include/qemu/typedefs.h +1 -0
@@ -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 ;
Signature · 1 line
2.34.1
RFC v2 2/15 qdev: Add the interface to reparent the device
In reply to Zhao LiuUser created devices may need to adjust their default object parent or parent bus.
User created devices are QOM parented to one of the peripheral containers ("/peripheral" or "/peripheral-anon") in qdev_set_id() by default. Sometimes, it is necessary to reparent a device to another object to express the more accurate child<> relationship, as in the cases of the PnvPHBRootPort device or subsequent topology devices.
The current pnv_phb_user_get_parent() implements such reparenting logic. To allow it to be used by topology devices as well, transform it into a generic qdev interface with custom device id ("default_id" parameter).
And add the code to handle the failure of object_property_add_child().
--- hw/core/qdev.c | 52 +++++++++++++++++++++++++++++++++++++ hw/pci-host/pnv_phb.c | 59 +++++++++--------------------------------- include/hw/qdev-core.h | 3 +++ 3 files changed, 67 insertions(+), 47 deletions(-)
hw/core/qdev.c +52 -0
@@ -143,6 +143,58 @@ bool qdev_set_parent_bus(DeviceState *dev, BusState *bus, Error **errp)return true; } +/* +* Set the QOM parent and parent bus of an object child. If the device +* state associated with the child has an id, use it as QOM id. +* Otherwise use default_id as QOM id. +* +* This helper does both operations at the same time because setting +* a new QOM child will erase the bus parent of the device. This happens +* because object_unparent() will call object_property_del_child(), +* which in turn calls the property release callback prop->release if +* it's defined. In our case this callback is set to +* object_finalize_child_property(), which was assigned during the +* first object_property_add_child() call. This callback will end up +* calling device_unparent(), and this function removes the device +* from its parent bus. +* +* The QOM and parent bus to be set aren't necessarily related, so +* let's receive both as arguments. +*/ +bool qdev_set_parent (DeviceState *dev,BusState *bus,Object *parent, +char *default_id,Error **errp) +{ +Object *child =OBJECT (dev); +ObjectProperty *prop; + +if (!dev->id && !default_id) { +error_setg (errp,"unknown device id" ); +return false; + } + +if (child->parent == parent) { +return true; + } + +object_ref (child); +object_unparent (child); + prop =object_property_add_child (parent, + dev->id ? dev->id : default_id, + child); +object_unref (child); + +if (!prop) { +error_setg (errp,"couldn't change parent" ); +return false; + } + +if (!qdev_set_parent_bus (dev, bus, errp)) { +return false; + } + +return true; +} +DeviceState *qdev_new (const char *name) {ObjectClass *oc =object_class_by_name (name);
hw/pci-host/pnv_phb.c +12 -47
89 lines not on this page · raw message
include/hw/qdev-core.h +3 -0
@@ -1011,6 +1011,9 @@ char *qdev_get_human_name(DeviceState *dev);/* FIXME: make this a link<> */ bool qdev_set_parent_bus (DeviceState *dev,BusState *bus,Error **errp); +bool qdev_set_parent (DeviceState *dev,BusState *bus,Object *parent, +char *default_id,Error **errp); +extern bool qdev_hot_removed;char *qdev_get_dev_path (DeviceState *dev);
Signature · 1 line
2.34.1
RFC v2 3/15 hw/cpu: Introduce CPU topology device and CPU bus
In reply to Zhao LiuHybrid (or heterogeneous) CPU topology needs to be expressed as a topology tree, which requires to abstract all the CPU topology level as the objects.
At present, QEMU already has the CPU device, core device and cluster device (for TCG), so that it's natual to introduce more topology related devices instead of abstractong native QEMU objects.
To make it easier to deal with topological relationships, introduce the general and abstract CPU topology device, and also introduce the CPU bus to connect such CPU topology devices.
With the underlying CPU topology device abstraction, all the CPU topology levels could be derived from it as subclasses. Then the specific devices, such as CPU, core, or future module/die/socket devices etc, don't have to care about topology relationship, and the underlying CPU topology abstraction and CPU bus will take care of everything and build the topology tree.
Note, for the user created topology devices, they are specified the default object parent (one of the peripheral containers: "/peripheral" or "/peripheral-anon"). It's necessary to fixup their parent object to correct topology parent, so that it can make their canonical path in qtree match the actual topological hierarchies relationship. This is done by cpu_topo_set_parent() when topology device realizes.
--- MAINTAINERS | 2 + hw/cpu/cpu-topology.c | 179 ++++++++++++++++++++++++++++++++++ hw/cpu/meson.build | 2 + include/hw/cpu/cpu-topology.h | 68 +++++++++++++ include/qemu/typedefs.h | 2 + stubs/hotplug-stubs.c | 5 + 6 files changed, 258 insertions(+) create mode 100644 hw/cpu/cpu-topology.c create mode 100644 include/hw/cpu/cpu-topology.h
MAINTAINERS +2 -0
@@ -1884,12 +1884,14 @@ F: hw/core/machine-smp.c F: hw/core/null-machine.c F: hw/core/numa.c F: hw/cpu/cluster.c +F: hw/cpu/cpu-topology.c F: qapi/machine.json F: qapi/machine-common.json F: qapi/machine-target.json F: include/hw/boards.h F: include/hw/core/cpu.h F: include/hw/cpu/cluster.h +F: include/hw/cpu/cpu-topology.h F: include/sysemu/numa.h F: tests/functional/test_cpu_queries.py F: tests/functional/test_empty_cpu_model.py
hw/cpu/cpu-topology.c new file +179 -0
179 lines not on this page · raw message
hw/cpu/meson.build +2 -0
@@ -1,3 +1,5 @@ +common_ss.add(files('cpu-topology.c')) + system_ss.add(files('core.c')) system_ss.add(when: 'CONFIG_CPU_CLUSTER', if_true: files('cluster.c'))
include/hw/cpu/cpu-topology.h new file +68 -0
68 lines not on this page · raw message
include/qemu/typedefs.h +2 -0
@@ -39,8 +39,10 @@ typedef struct Chardev Chardev;typedef struct Clock Clock ;typedef struct ConfidentialGuestSupport ConfidentialGuestSupport ;typedef struct CPUArchState CPUArchState ; +typedef struct CPUBusState CPUBusState ;typedef struct CPUPluginState CPUPluginState ;typedef struct CPUState CPUState ; +typedef struct CPUTopoState CPUTopoState ;typedef struct DeviceState DeviceState ;typedef struct DirtyBitmapSnapshot DirtyBitmapSnapshot ;typedef struct DisasContextBase DisasContextBase ;
stubs/hotplug-stubs.c +5 -0
@@ -19,6 +19,11 @@ HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev)return NULL ; } +HotplugHandler *qdev_get_bus_hotplug_handler (DeviceState *dev) +{ +return NULL ; +} +void hotplug_handler_pre_plug (HotplugHandler *plug_handler,DeviceState *plugged_dev,Error **errp)
Signature · 1 line
2.34.1
RFC v2 4/15 hw/cpu: Introduce CPU slot to manage CPU topology
In reply to Zhao LiuWhen there's a CPU topology tree, original MachineState.smp (CpuTopology structure) is not enough to dynamically monitor changes of the tree or update topology information in time.
To address this, introduce the CPU slot, as the root of CPU topology tree, which is used to update and maintain global topological statistics by listening any changes of topology device (realize() and unrealize()).
--- MAINTAINERS | 2 + hw/cpu/cpu-slot.c | 140 ++++++++++++++++++++++++++++++++++++++ hw/cpu/meson.build | 1 + include/hw/cpu/cpu-slot.h | 72 ++++++++++++++++++++ 4 files changed, 215 insertions(+) create mode 100644 hw/cpu/cpu-slot.c create mode 100644 include/hw/cpu/cpu-slot.h
MAINTAINERS +2 -0
@@ -1884,6 +1884,7 @@ F: hw/core/machine-smp.c F: hw/core/null-machine.c F: hw/core/numa.c F: hw/cpu/cluster.c +F: hw/cpu/cpu-slot.c F: hw/cpu/cpu-topology.c F: qapi/machine.json F: qapi/machine-common.json
@@ -1891,6 +1892,7 @@ F: qapi/machine-target.json F: include/hw/boards.h F: include/hw/core/cpu.h F: include/hw/cpu/cluster.h +F: include/hw/cpu/cpu-slot.h F: include/hw/cpu/cpu-topology.h F: include/sysemu/numa.h F: tests/functional/test_cpu_queries.py
hw/cpu/cpu-slot.c new file +140 -0
140 lines not on this page · raw message
hw/cpu/meson.build +1 -0
@@ -1,6 +1,7 @@ common_ss.add(files('cpu-topology.c')) system_ss.add(files('core.c')) +system_ss.add(files('cpu-slot.c')) system_ss.add(when: 'CONFIG_CPU_CLUSTER', if_true: files('cluster.c')) system_ss.add(when: 'CONFIG_ARM11MPCORE', if_true: files('arm11mpcore.c'))
include/hw/cpu/cpu-slot.h new file +72 -0
72 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC v2 5/15 qdev: Add method in BusClass to customize device index
In reply to Zhao LiuCurrently, when the bus assigns an index to a child device, it relies on a monotonically increasing max_index.
However, when a device is removed from the bus, its index is not reassigned to new devices, leading to "holes" in child indices.
For topology devices, such as CPUs/cores, arches define custom sub-topology IDs. Some of these IDs are global (e.g., core-id for core devices), while others are local (e.g., thread-id/core-id/module-id for x86 CPUs).
Local IDs are indexes under the same parent device and align with BusChild's index meaning. Therefore, local IDs in a topology context should use BusChild.index.
Considering that topology devices support hot-plug and local IDs often have range constraints, add a new method (BusClass.assign_free_index) to allow the bus to customize index assignment.
Based on this method, the CPU bus will search for free index "holes" created by unplugging and assign these free indices to newly inserted devices.
--- hw/core/qdev.c | 8 +++++++- hw/cpu/cpu-topology.c | 37 +++++++++++++++++++++++++++++++++++ include/hw/cpu/cpu-topology.h | 1 + include/hw/qdev-core.h | 2 ++ 4 files changed, 47 insertions(+), 1 deletion(-)
hw/core/qdev.c +7 -1
@@ -78,11 +78,17 @@ static void bus_remove_child(BusState *bus, DeviceState *child)static void bus_add_child (BusState *bus,DeviceState *child) { +BusClass *bc =BUS_GET_CLASS (bus);char name[32 ];BusChild *kid =g_malloc0 (sizeof (*kid)); +if (bc->assign_free_index) { + kid->index = bc->assign_free_index (bus); + }else { + kid->index = bus->max_index++; + } + bus->num_children++; - kid->index = bus->max_index++; kid->child = child; child->bus_node = kid;object_ref (OBJECT (kid->child));
hw/cpu/cpu-topology.c +37 -0
@@ -49,11 +49,40 @@ static bool cpu_bus_check_address(BusState *bus, DeviceState *dev,return cpu_parent_check_topology (bus->parent, dev, errp); } +static int cpu_bus_assign_free_index (BusState *bus) +{ +BusChild *kid; +int index; + +if (bus->num_children == bus->max_index) { +return bus->max_index++; + } + +assert (bus->num_children < bus->max_index); +/* TODO: Introduce the list sorted by index */ +for (index =0 ; index < bus->num_children; index++) { +bool existed = false; + + QTAILQ_FOREACH(kid, &bus->children, sibling) { +if (kid->index == index) { + existed = true; +break ; + } + } + +if (!existed) { +break ; + } + } +return index; +} +static void cpu_bus_class_init (ObjectClass *oc,void *data) {BusClass *bc =BUS_CLASS (oc); bc->check_address = cpu_bus_check_address; + bc->assign_free_index = cpu_bus_assign_free_index; }static const TypeInfo cpu_bus_type_info = {
@@ -177,3 +206,11 @@ int cpu_topo_get_instances_num(CPUTopoState *topo)return bus ? bus->num_children :1 ; } + +int cpu_topo_get_index (CPUTopoState *topo) +{ +BusChild *node =DEVICE (topo)->bus_node; + +assert (node); +return node->index; +}
include/hw/cpu/cpu-topology.h +1 -0
@@ -64,5 +64,6 @@ struct CPUTopoState {#define GET_CPU_TOPO_LEVEL (topo) (CPU_TOPO_GET_CLASS(topo)->level)int cpu_topo_get_instances_num (CPUTopoState *topo); +int cpu_topo_get_index (CPUTopoState *topo);#endif /* CPU_TOPO_H */
include/hw/qdev-core.h +2 -0
@@ -342,6 +342,8 @@ struct BusClass {*/ bool (*check_address)(BusState *bus,DeviceState *dev,Error **errp); +int (*assign_free_index)(BusState *bus); +BusRealize realize;BusUnrealize unrealize;
Signature · 1 line
2.34.1
RFC v2 6/15 hw/core: Create CPU slot in MachineState to manage CPU topology tree
In reply to Zhao LiuWith 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.
--- 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(+)
hw/core/machine.c +2 -0
@@ -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 }); }
hw/cpu/cpu-slot.c +34 -0
@@ -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)); + } +}
include/hw/boards.h +9 -0
@@ -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; };
include/hw/cpu/cpu-slot.h +2 -0
@@ -69,4 +69,6 @@ struct CPUSlot { DeviceListener listener; }; +void machine_plug_cpu_slot (MachineState *ms); +#endif /* CPU_SLOT_H */
system/vl.c +4 -0
@@ -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)
Signature · 1 line
2.34.1
RFC v2 7/15 hw/core/cpu: Convert CPU from general device to topology device
In reply to Zhao LiuConvert CPU to topology device then it can be added into topology tree.
Because CPU then inherits properties and settings of topology device, make the following changes to take into account the special case for CPU:
* Omit setting category since topology device has already set.
* Make realize() of topology device as the parent realize().
* Clean up some cases that assume parent obj is DeviceState and access parent_obj directly.
* Set CPU's topology level as thread.
* And one complex change: mask bus_type as NULL.
- This is because for the arches don't support topology tree, there's no CPU bus bridge so that CPUs of these arches can't be created. So, only the CPU with arch supporting topology tree should override the bus_type field.
* Further, support cpu_create() for the CPU with bus_type.
- This is a corner case, some arch CPUs may set bus_type, and cpu_create() would be called in system emulation case (e.g., none machine). To handle such case, try to find the machine's CPU bus in cpu_create().
--- accel/kvm/kvm-all.c | 4 ++-- hw/core/cpu-common.c | 42 +++++++++++++++++++++++++++++++++++++----- include/hw/core/cpu.h | 7 +++++-- target/ppc/kvm.c | 2 +- 4 files changed, 45 insertions(+), 10 deletions(-)
accel/kvm/kvm-all.c +2 -2
@@ -4173,7 +4173,7 @@ static void query_stats(StatsResultList **result, StatsTarget target,break ;case STATS_TARGET_VCPU :add_stats_entry (result,STATS_PROVIDER_KVM , - cpu->parent_obj.canonical_path, +DEVICE (cpu)->canonical_path, stats_list);break ;default :
@@ -4265,7 +4265,7 @@ static void query_stats_cb(StatsResultList **result, StatsTarget target, stats_args.names = names; stats_args.errp = errp;CPU_FOREACH (cpu) { -if (!apply_str_list_filter (cpu->parent_obj.canonical_path, targets)) { +if (!apply_str_list_filter (DEVICE (cpu)->canonical_path, targets)) {continue ; }query_stats_vcpu (cpu, &stats_args);
hw/core/cpu-common.c +37 -5
76 lines not on this page · raw message
include/hw/core/cpu.h +5 -2
@@ -20,6 +20,7 @@#ifndef QEMU_CPU_H #define QEMU_CPU_H +#include "hw/cpu/cpu-topology.h" #include "hw/qdev-core.h" #include "disas/dis-asm.h" #include "exec/breakpoint.h"
@@ -144,7 +145,7 @@ struct SysemuCPUOps;*/ struct CPUClass {/*< private >*/ -DeviceClass parent_class; +CPUTopoClass parent_class;/*< public >*/ ObjectClass *(*class_by_name)(const char *cpu_model);
@@ -189,6 +190,8 @@ struct CPUClass {int reset_dump_flags;int gdb_num_core_regs;bool gdb_stop_before_watchpoint; + +DeviceRealize parent_realize; };/*
@@ -456,7 +459,7 @@ struct qemu_work_item;*/ struct CPUState {/*< private >*/ -DeviceState parent_obj; +CPUTopoState parent_obj;/* cache to avoid expensive CPU_GET_CLASS */ CPUClass *cc;/*< public >*/
target/ppc/kvm.c +1 -1
@@ -2351,7 +2351,7 @@ static void alter_insns(uint64_t *word, uint64_t flags, bool on)static bool kvmppc_cpu_realize (CPUState *cs,Error **errp) {int ret; -const char *vcpu_str = (cs->parent_obj.hotplugged == true) ? +const char *vcpu_str = (DEVICE (cs)->hotplugged == true) ?"hotplug" :"create" ; cs->cpu_index =cpu_get_free_index ();
Signature · 1 line
2.34.1
RFC v2 8/15 hw/cpu/core: Convert cpu-core from general device to topology device
In reply to Zhao LiuConvert cpu-core to topology device then it can be added into topology tree.
At present, only PPC is using cpu-core device. For topology tree, it's necessary to add cpu-core in the tree as one of the topology hierarchies.
The generic cpu-core is sufficient to express the core layer in a topology tree without needing to consider any arch-specific feature, so to reduce the support complexity of the topology tree and allow arch to be able to use the abstract cpu-core directly, without further derivation of the arch-specific core, remove the "abstract" restriction from TypeInfo.
Because cpu-core then inherits properties and settings of topology device, also make the following changes to take into account the special case for cpu-core:
* Omit setting category since topology device has already set.
* Make realize() of topology device as the parent realize() for PPC cores.
* Set cpu-core's topology level as core.
* Mask bus_type for PPC cores as NULL to avoid PPC cores' creation failure since PPC currently doesn't support topology tree.
--- hw/cpu/core.c | 9 +++++---- hw/ppc/pnv_core.c | 11 ++++++++++- hw/ppc/spapr_cpu_core.c | 12 +++++++++++- include/hw/cpu/core.h | 3 ++- include/hw/ppc/pnv_core.h | 3 ++- include/hw/ppc/spapr_cpu_core.h | 4 +++- 6 files changed, 33 insertions(+), 9 deletions(-)
hw/cpu/core.c +5 -4
@@ -79,19 +79,20 @@ static void cpu_core_instance_init(Object *obj)static void cpu_core_class_init (ObjectClass *oc,void *data) { -DeviceClass *dc =DEVICE_CLASS (oc); +CPUTopoClass *tc =CPU_TOPO_CLASS (oc); -set_bit (DEVICE_CATEGORY_CPU , dc->categories); +/* TODO: Offload "core-id" and "nr-threads" to ppc-specific core. */ object_class_property_add (oc,"core-id" ,"int" , core_prop_get_core_id, core_prop_set_core_id,NULL ,NULL );object_class_property_add (oc,"nr-threads" ,"int" , core_prop_get_nr_threads, core_prop_set_nr_threads,NULL ,NULL ); + + tc->level =CPU_TOPOLOGY_LEVEL_CORE ; }static const TypeInfo cpu_core_type_info = { .name =TYPE_CPU_CORE , - .parent =TYPE_DEVICE , - .abstract = true, + .parent =TYPE_CPU_TOPO , .class_init = cpu_core_class_init, .instance_size =sizeof (CPUCore), .instance_init = cpu_core_instance_init,
hw/ppc/pnv_core.c +10 -1
@@ -356,6 +356,8 @@ static void pnv_core_realize(DeviceState *dev, Error **errp)assert (pc->chip); + pcc->parent_realize (dev, errp); + pc->threads = g_new(PowerPCCPU *, cc->nr_threads);for (i =0 ; i < cc->nr_threads; i++) {PowerPCCPU *cpu;
@@ -466,11 +468,18 @@ static void pnv_core_power10_class_init(ObjectClass *oc, void *data)static void pnv_core_class_init (ObjectClass *oc,void *data) {DeviceClass *dc =DEVICE_CLASS (oc); +PnvCoreClass *pcc =PNV_CORE_CLASS (oc); - dc->realize = pnv_core_realize; dc->unrealize = pnv_core_unrealize;device_class_set_props (dc, pnv_core_properties); dc->user_creatable = false; +device_class_set_parent_realize (dc, pnv_core_realize, + &pcc->parent_realize); +/* +* Avoid ppc that do not support topology device trees from +* encountering error when creating cores. +*/ + dc->bus_type =NULL ; }#define DEFINE_PNV_CORE_TYPE (family, cpu_model) \
hw/ppc/spapr_cpu_core.c +11 -1
@@ -338,6 +338,7 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp) (SpaprMachineState *)object_dynamic_cast (qdev_get_machine (),TYPE_SPAPR_MACHINE );SpaprCpuCore *sc =SPAPR_CPU_CORE (OBJECT (dev)); +SpaprCpuCoreClass *scc =SPAPR_CPU_CORE_GET_CLASS (sc);CPUCore *cc =CPU_CORE (OBJECT (dev));int i;
@@ -346,6 +347,8 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)return ; } + scc->parent_realize (dev, errp); +qemu_register_reset (spapr_cpu_core_reset_handler, sc); sc->threads = g_new0(PowerPCCPU *, cc->nr_threads);for (i =0 ; i < cc->nr_threads; i++) {
@@ -376,11 +379,18 @@ static void spapr_cpu_core_class_init(ObjectClass *oc, void *data)DeviceClass *dc =DEVICE_CLASS (oc);SpaprCpuCoreClass *scc =SPAPR_CPU_CORE_CLASS (oc); - dc->realize = spapr_cpu_core_realize; dc->unrealize = spapr_cpu_core_unrealize;device_class_set_legacy_reset (dc, spapr_cpu_core_reset);device_class_set_props (dc, spapr_cpu_core_properties); + dc->hotpluggable = true; scc->cpu_type = data; +device_class_set_parent_realize (dc, spapr_cpu_core_realize, + &scc->parent_realize); +/* +* Avoid ppc that do not support topology device trees from +* encountering error when creating cores. +*/ + dc->bus_type =NULL ; }#define DEFINE_SPAPR_CPU_CORE_TYPE (cpu_model) \
include/hw/cpu/core.h +2 -1
@@ -9,6 +9,7 @@#ifndef HW_CPU_CORE_H #define HW_CPU_CORE_H +#include "hw/cpu/cpu-topology.h" #include "hw/qdev-core.h" #include "qom/object.h"
@@ -18,7 +19,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(CPUCore, CPU_CORE)struct CPUCore {/*< private >*/ -DeviceState parent_obj; +CPUTopoState parent_obj;/*< public >*/ int core_id;
include/hw/ppc/pnv_core.h +2 -1
@@ -71,10 +71,11 @@ struct PnvCore { };struct PnvCoreClass { -DeviceClass parent_class; +CPUTopoClass parent_class;const MemoryRegionOps *xscom_ops;uint64_t xscom_size; +DeviceRealize parent_realize; };#define PNV_CORE_TYPE_SUFFIX "-" TYPE_PNV_CORE
include/hw/ppc/spapr_cpu_core.h +3 -1
@@ -32,8 +32,10 @@ struct SpaprCpuCore { };struct SpaprCpuCoreClass { -DeviceClass parent_class; +CPUTopoClass parent_class; +const char *cpu_type; +DeviceRealize parent_realize; };const char *spapr_get_cpu_core_type (const char *cpu_type);
Signature · 1 line
2.34.1
RFC v2 9/15 hw/cpu: Abstract module/die/socket levels as topology devices
In reply to Zhao LiuAbstract module/die/socket levels as the cpu-module/cpu-die/cpu-socket topology devices then they can be inserted into topology tree.
--- MAINTAINERS | 6 ++++++ hw/cpu/die.c | 34 ++++++++++++++++++++++++++++++++++ hw/cpu/meson.build | 3 +++ hw/cpu/module.c | 34 ++++++++++++++++++++++++++++++++++ hw/cpu/socket.c | 34 ++++++++++++++++++++++++++++++++++ include/hw/cpu/die.h | 29 +++++++++++++++++++++++++++++ include/hw/cpu/module.h | 29 +++++++++++++++++++++++++++++ include/hw/cpu/socket.h | 29 +++++++++++++++++++++++++++++ 8 files changed, 198 insertions(+) create mode 100644 hw/cpu/die.c create mode 100644 hw/cpu/module.c create mode 100644 hw/cpu/socket.c create mode 100644 include/hw/cpu/die.h create mode 100644 include/hw/cpu/module.h create mode 100644 include/hw/cpu/socket.h
MAINTAINERS +6 -0
@@ -1886,6 +1886,9 @@ F: hw/core/numa.c F: hw/cpu/cluster.c F: hw/cpu/cpu-slot.c F: hw/cpu/cpu-topology.c +F: hw/cpu/die.c +F: hw/cpu/module.c +F: hw/cpu/socket.c F: qapi/machine.json F: qapi/machine-common.json F: qapi/machine-target.json
@@ -1894,6 +1897,9 @@ F: include/hw/core/cpu.h F: include/hw/cpu/cluster.h F: include/hw/cpu/cpu-slot.h F: include/hw/cpu/cpu-topology.h +F: include/hw/cpu/die.h +F: include/hw/cpu/module.h +F: include/hw/cpu/socket.h F: include/sysemu/numa.h F: tests/functional/test_cpu_queries.py F: tests/functional/test_empty_cpu_model.py
hw/cpu/die.c new file +34 -0
@@ -0,0 +1,34 @@ +/* +* CPU die abstract device +* +* Copyright (C) 2024 Intel Corporation. +* +* Author: Zhao Liu <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* later. See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "hw/cpu/die.h" + +static void cpu_die_class_init (ObjectClass *oc,void *data) +{ +CPUTopoClass *tc =CPU_TOPO_CLASS (oc); + + tc->level =CPU_TOPOLOGY_LEVEL_DIE ; +} + +static const TypeInfo cpu_die_type_info = { + .name =TYPE_CPU_DIE , + .parent =TYPE_CPU_TOPO , + .class_init = cpu_die_class_init, + .instance_size =sizeof (CPUDie), +}; + +static void cpu_die_register_types (void ) +{ +type_register_static (&cpu_die_type_info); +} + +type_init (cpu_die_register_types)
hw/cpu/meson.build +3 -0
@@ -3,6 +3,9 @@ common_ss.add(files('cpu-topology.c')) system_ss.add(files('core.c')) system_ss.add(files('cpu-slot.c')) system_ss.add(when: 'CONFIG_CPU_CLUSTER', if_true: files('cluster.c')) +system_ss.add(files('die.c')) +system_ss.add(files('module.c')) +system_ss.add(files('socket.c')) system_ss.add(when: 'CONFIG_ARM11MPCORE', if_true: files('arm11mpcore.c')) system_ss.add(when: 'CONFIG_REALVIEW', if_true: files('realview_mpcore.c'))
hw/cpu/module.c new file +34 -0
@@ -0,0 +1,34 @@ +/* +* CPU module abstract device +* +* Copyright (C) 2024 Intel Corporation. +* +* Author: Zhao Liu <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* later. See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "hw/cpu/module.h" + +static void cpu_module_class_init (ObjectClass *oc,void *data) +{ +CPUTopoClass *tc =CPU_TOPO_CLASS (oc); + + tc->level =CPU_TOPOLOGY_LEVEL_MODULE ; +} + +static const TypeInfo cpu_module_type_info = { + .name =TYPE_CPU_MODULE , + .parent =TYPE_CPU_TOPO , + .class_init = cpu_module_class_init, + .instance_size =sizeof (CPUModule), +}; + +static void cpu_module_register_types (void ) +{ +type_register_static (&cpu_module_type_info); +} + +type_init (cpu_module_register_types)
hw/cpu/socket.c new file +34 -0
@@ -0,0 +1,34 @@ +/* +* CPU socket abstract device +* +* Copyright (C) 2024 Intel Corporation. +* +* Author: Zhao Liu <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* later. See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "hw/cpu/socket.h" + +static void cpu_socket_class_init (ObjectClass *oc,void *data) +{ +CPUTopoClass *tc =CPU_TOPO_CLASS (oc); + + tc->level =CPU_TOPOLOGY_LEVEL_SOCKET ; +} + +static const TypeInfo cpu_socket_type_info = { + .name =TYPE_CPU_SOCKET , + .parent =TYPE_CPU_TOPO , + .class_init = cpu_socket_class_init, + .instance_size =sizeof (CPUSocket), +}; + +static void cpu_socket_register_types (void ) +{ +type_register_static (&cpu_socket_type_info); +} + +type_init (cpu_socket_register_types)
include/hw/cpu/die.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* CPU die abstract device +* +* Copyright (C) 2024 Intel Corporation. +* +* Author: Zhao Liu <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* later. See the COPYING file in the top-level directory. +*/ + +#ifndef HW_CPU_DIE_H +#define HW_CPU_DIE_H + +#include "hw/cpu/cpu-topology.h" +#include "hw/qdev-core.h" + +#define TYPE_CPU_DIE "cpu-die" + +OBJECT_DECLARE_SIMPLE_TYPE(CPUDie, CPU_DIE) + +struct CPUDie { +/*< private >*/ +CPUTopoState obj; + +/*< public >*/ +}; + +#endif /* HW_CPU_DIE_H */
include/hw/cpu/module.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* CPU module abstract device +* +* Copyright (C) 2024 Intel Corporation. +* +* Author: Zhao Liu <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* later. See the COPYING file in the top-level directory. +*/ + +#ifndef HW_CPU_MODULE_H +#define HW_CPU_MODULE_H + +#include "hw/cpu/cpu-topology.h" +#include "hw/qdev-core.h" + +#define TYPE_CPU_MODULE "cpu-module" + +OBJECT_DECLARE_SIMPLE_TYPE(CPUModule, CPU_MODULE) + +struct CPUModule { +/*< private >*/ +CPUTopoState obj; + +/*< public >*/ +}; + +#endif /* HW_CPU_MODULE_H */
include/hw/cpu/socket.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* CPU socket abstract device +* +* Copyright (C) 2024 Intel Corporation. +* +* Author: Zhao Liu <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* later. See the COPYING file in the top-level directory. +*/ + +#ifndef HW_CPU_SOCKET_H +#define HW_CPU_SOCKET_H + +#include "hw/cpu/cpu-topology.h" +#include "hw/qdev-core.h" + +#define TYPE_CPU_SOCKET "cpu-socket" + +OBJECT_DECLARE_SIMPLE_TYPE(CPUSocket, CPU_SOCKET) + +struct CPUSocket { +/*< private >*/ +CPUTopoState parent_obj; + +/*< public >*/ +}; + +#endif /* HW_CPU_SOCKET_H */
Signature · 1 line
2.34.1
RFC v2 10/15 hw/machine: Build smp topology tree from -smp
In reply to Zhao LiuFor architectures supports QOM topology (indicated by the MachineClass. topo_tree_supported field), implement smp QOM topology tree from MachineState.smp.
The topology tree is created before MachineClass.init(), where arch will initialize CPUs or cores, corresponding to the MachineState.possible_cpus[].
To avoid conflicts with CPU/core generation in the arch machine, create_smp_topo_children() will only create topology levels which are higher than the granularity of possible_cpus[]. The remaining topology parts will be completed by the arch machine during machine init().
There's a new field, arch_id_topo_level, to indicate the granularity of possible_cpus[]. While this field is set, CPU slot can create the topology tree level by level. Without this field, any topology device will be collect at the CPU bus of the CPU slot and will not be organized into a tree structure.
--- hw/core/machine.c | 5 ++ hw/cpu/cpu-slot.c | 153 ++++++++++++++++++++++++++++++++++++++ include/hw/boards.h | 2 + include/hw/cpu/cpu-slot.h | 5 ++ include/qemu/bitops.h | 5 ++ 5 files changed, 170 insertions(+)
hw/core/machine.c +5 -0
@@ -1638,6 +1638,11 @@ void machine_run_board_init(MachineState *machine, const char *mem_path, Error * "on", false); } +if (machine_class->smp_props.topo_tree_supported && + !machine_create_topo_tree (machine, errp)) { +return ; + } +accel_init_interfaces (ACCEL_GET_CLASS (machine->accelerator)); machine_class->init (machine);phase_advance (PHASE_MACHINE_INITIALIZED );
hw/cpu/cpu-slot.c +153 -0
164 lines not on this page · raw message
include/hw/boards.h +2 -0
@@ -155,6 +155,7 @@ typedef struct {* supported by the machine * @topo_tree_supported - whether QOM topology tree is supported by the * machine +* @arch_id_topo_level - topology granularity for possible_cpus[] */ typedef struct { bool prefer_sockets;
@@ -166,6 +167,7 @@ typedef struct {bool modules_supported;bool cache_supported[CACHE_LEVEL_AND_TYPE__MAX ];bool topo_tree_supported; +CpuTopologyLevel arch_id_topo_level; } SMPCompatProps;/**
include/hw/cpu/cpu-slot.h +5 -0
@@ -69,6 +69,11 @@ struct CPUSlot { DeviceListener listener; }; +#define TOPO_FOREACH_END 1 +#define TOPO_FOREACH_CONTINUE 0 +#define TOPO_FOREACH_ERR -1 +void machine_plug_cpu_slot (MachineState *ms); +bool machine_create_topo_tree (MachineState *ms,Error **errp);#endif /* CPU_SLOT_H */
include/qemu/bitops.h +5 -0
@@ -631,4 +631,9 @@ static inline uint64_t half_unshuffle64(uint64_t x) return x; } +#define FOR_EACH_SET_BIT (bit, addr, size) \ + for ((bit) = find_first_bit((addr), (size)); \ + (bit) < (size); \ + (bit) = find_next_bit((addr), (size), (bit) + 1)) +#endif
Signature · 1 line
2.34.1
RFC v2 11/15 hw/core: Support topology tree in none machine for compatibility
In reply to Zhao LiuNone machine accepts any CPU types, even some CPUs may have the bus_type.
To address this, set topo_tree_supported as true for none machine, then none machine will have a CPU slot with CPU bus to collect any topology device with bus_type specified.
And since arch_id_topo_level is not set, the topology devices will be directly inserted under the CPU slot without being organized into a tree structure.
For the CPUs without bus_type, topo_tree_supported will not affect them.
--- hw/core/null-machine.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/core/null-machine.c +5 -0
@@ -54,6 +54,11 @@ static void machine_none_machine_init(MachineClass *mc) mc->no_floppy =1 ; mc->no_cdrom =1 ; mc->no_sdcard =1 ; +/* +* For compatibility with arches and CPUs that already +* support topology tree. +*/ + mc->smp_props.topo_tree_supported = true; }DEFINE_MACHINE ("none" , machine_none_machine_init)
Signature · 1 line
2.34.1
RFC v2 12/15 hw/i386: Allow i386 to create new CPUs in topology tree
In reply to Zhao LiuFor x86, CPU's apic ID represent its topology path and is the combination of topology sub IDs in each leavl.
When x86 machine creates CPUs, to insert the CPU into topology tree, use apic ID to get topology sub IDs.
Then search the topology tree for the corresponding parent topology device and insert the CPU into the CPU bus of the parent device.
--- hw/i386/x86-common.c | 101 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 4 deletions(-)
hw/i386/x86-common.c +97 -4
@@ -53,14 +53,107 @@/* Physical Address of PVH entry point read from kernel ELF NOTE */ static size_t pvh_start_addr; -static void x86_cpu_new (X86MachineState *x86ms,int64_t apic_id,Error **errp) +static int x86_cpu_get_topo_id (const X86CPUTopoIDs *topo_ids, +CpuTopologyLevel level) { -Object *cpu =object_new (MACHINE (x86ms)->cpu_type); +switch (level) { +case CPU_TOPOLOGY_LEVEL_THREAD : +return topo_ids->smt_id; +case CPU_TOPOLOGY_LEVEL_CORE : +return topo_ids->core_id; +case CPU_TOPOLOGY_LEVEL_MODULE : +return topo_ids->module_id; +case CPU_TOPOLOGY_LEVEL_DIE : +return topo_ids->die_id; +case CPU_TOPOLOGY_LEVEL_SOCKET : +return topo_ids->pkg_id; +default : +g_assert_not_reached (); + } + +return -1 ; +} + +typedef struct SearchCoreCb { +const X86CPUTopoIDs *topo_ids; +const CPUTopoState *parent; +}SearchCoreCb ; + +static int x86_search_topo_parent (DeviceState *dev,void *opaque) +{ +CPUTopoState *topo =CPU_TOPO (dev); +CpuTopologyLevel level =GET_CPU_TOPO_LEVEL (topo); +SearchCoreCb *cb = opaque; +int topo_id, index; + + topo_id =x86_cpu_get_topo_id (cb->topo_ids, level); + index =cpu_topo_get_index (topo); + +if (topo_id <0 ) { +error_report ("Invalid %s-id: %d" , +CpuTopologyLevel_str (level), topo_id); +error_printf ("Try to set the %s-id in [0-%d].\n" , +CpuTopologyLevel_str (level), +cpu_topo_get_instances_num (topo) -1 ); +return TOPO_FOREACH_ERR ; + } + +if (topo_id == index) { +if (level ==CPU_TOPOLOGY_LEVEL_CORE ) { + cb->parent = topo; +/* The error result could exit directly. */ +return TOPO_FOREACH_ERR ; + } +return TOPO_FOREACH_CONTINUE ; + } +return TOPO_FOREACH_END ; +} + +static BusState *x86_find_topo_bus (MachineState *ms,X86CPUTopoIDs *topo_ids) +{ +SearchCoreCb cb; + + cb.topo_ids = topo_ids; + cb.parent =NULL ; +qbus_walk_children (BUS (&ms->topo->bus), x86_search_topo_parent, +NULL ,NULL ,NULL , &cb); + +if (!cb.parent) { +return NULL ; + } + +return BUS (cb.parent->bus); +} + +static void x86_cpu_new (X86MachineState *x86ms,int index, +int64_t apic_id,Error **errp) +{ +MachineState *ms =MACHINE (x86ms); +MachineClass *mc =MACHINE_GET_CLASS (ms); +Object *cpu =object_new (ms->cpu_type); +DeviceState *dev =DEVICE (cpu); +BusState *bus =NULL ; + +/* +* Once x86 machine supports topo_tree_supported, x86 CPU would +* also have bus_type. +*/ +if (mc->smp_props.topo_tree_supported) { +X86CPUTopoIDs topo_ids; +X86CPUTopoInfo topo_info; + +init_topo_info (&topo_info, x86ms); +x86_topo_ids_from_apicid (apic_id, &topo_info, &topo_ids); + bus =x86_find_topo_bus (ms, &topo_ids); + +/* Only with dev->id, CPU can be inserted into topology tree. */ + dev->id =g_strdup_printf ("%s[%d]" , ms->cpu_type, index); + }if (!object_property_set_uint (cpu,"apic-id" , apic_id, errp)) { goto out; } -qdev_realize (DEVICE (cpu),NULL , errp); +qdev_realize (dev, bus, errp); out:object_unref (cpu);
@@ -111,7 +204,7 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version) possible_cpus = mc->possible_cpu_arch_ids (ms);for (i =0 ; i < ms->smp.cpus; i++) { -x86_cpu_new (x86ms, possible_cpus->cpus[i].arch_id, &error_fatal); +x86_cpu_new (x86ms, i, possible_cpus->cpus[i].arch_id, &error_fatal); } }
Signature · 1 line
2.34.1
RFC v2 13/15 system/qdev-monitor: Introduce bus-finder interface for compatibility with bus-less plug behavior
In reply to Zhao LiuCurrently, cpu and core is located by topology IDs when plugging.
On a topology tree, each topology device will has a CPU bus. Once cpu and core specify the bus_type, it's necessary to find accurate buses for them based on topology IDs (if bus=* is not set in -device).
Therefore, we need a way to use traditional topology IDs for locating specific bus in the topology tree. This is the bus-finder interface.
With bus-finder, qdev-monitor can locate the bus based on device properties when "bus=*" is not specified.
--- MAINTAINERS | 2 ++ include/monitor/bus-finder.h | 41 ++++++++++++++++++++++++++++++++ system/bus-finder.c | 46 ++++++++++++++++++++++++++++++++++++ system/meson.build | 1 + system/qdev-monitor.c | 41 ++++++++++++++++++++++++++++---- 5 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 include/monitor/bus-finder.h create mode 100644 system/bus-finder.c
MAINTAINERS +2 -0
@@ -3281,12 +3281,14 @@ F: hw/core/qdev* F: hw/core/bus.c F: hw/core/sysbus.c F: include/hw/qdev* +F: include/monitor/bus-finder.h F: include/monitor/qdev.h F: include/qom/ F: qapi/qom.json F: qapi/qdev.json F: scripts/coccinelle/qom-parent-type.cocci F: scripts/qom-cast-macro-clean-cocci-gen.py +F: system/bus-finder.c F: system/qdev-monitor.c F: stubs/qdev.c F: qom/
include/monitor/bus-finder.h new file +41 -0
41 lines not on this page · raw message
system/bus-finder.c new file +46 -0
46 lines not on this page · raw message
system/meson.build +1 -0
@@ -9,6 +9,7 @@ specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files( system_ss.add(files( 'balloon.c', 'bootdevice.c', + 'bus-finder.c', 'cpus.c', 'cpu-throttle.c', 'cpu-timers.c',
system/qdev-monitor.c +36 -5
71 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC v2 14/15 i386/cpu: Support CPU plugged in topology tree via bus-finder
In reply to Zhao LiuUse topology sub IDs or APIC ID to locate parent topology device and bus.
This process naturally verifies the correctness of topology-related IDs, making it possible to drop the existing topology ID sanity checks once x86 machine supports topology tree.
--- hw/i386/x86-common.c | 99 ++++++++++++++++++++++++++++++++++--------- include/hw/i386/x86.h | 2 + target/i386/cpu.c | 11 +++++ 3 files changed, 91 insertions(+), 21 deletions(-)
hw/i386/x86-common.c +78 -21
@@ -208,6 +208,65 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version) } } +static void x86_fixup_topo_ids (MachineState *ms,X86CPU *cpu) +{ +/* +* die-id was optional in QEMU 4.0 and older, so keep it optional +* if there's only one die per socket. +*/ +if (cpu->module_id <0 && ms->smp.modules ==1 ) { + cpu->module_id =0 ; + } + +/* +* module-id was optional in QEMU 9.0 and older, so keep it optional +* if there's only one module per die. +*/ +if (cpu->die_id <0 && ms->smp.dies ==1 ) { + cpu->die_id =0 ; + } +} + +BusState *x86_cpu_get_parent_bus (DeviceState *dev) +{ +MachineState *ms =MACHINE (qdev_get_machine ()); +X86MachineState *x86ms =X86_MACHINE (ms); +X86CPU *cpu =X86_CPU (dev); +X86CPUTopoIDs topo_ids; +X86CPUTopoInfo topo_info; +BusState *bus; + +x86_fixup_topo_ids (ms, cpu); +init_topo_info (&topo_info, x86ms); + +if (cpu->apic_id ==UNASSIGNED_APIC_ID ) { +/* TODO: Make the thread_id and bus index of CPU the same. */ + topo_ids.smt_id = cpu->thread_id; + topo_ids.core_id = cpu->core_id; + topo_ids.module_id = cpu->module_id; + topo_ids.die_id = cpu->die_id; + topo_ids.pkg_id = cpu->socket_id; + }else { +x86_topo_ids_from_apicid (cpu->apic_id, &topo_info, &topo_ids); + } + + bus =x86_find_topo_bus (ms, &topo_ids); + +/* +* If APIC ID is not set, +* set it based on socket/die/module/core/thread properties. +* +* The children walking result proves topo ids are valid. +* Though module and die are optional, topology tree will create +* at least 1 instance by default if the machine supports. +*/ +if (bus && cpu->apic_id ==UNASSIGNED_APIC_ID ) { + cpu->apic_id =x86_apicid_from_topo_ids (&topo_info, &topo_ids); + } + +return bus; +} +void x86_rtc_set_cpus_count (ISADevice *s,uint16_t cpus_count) {MC146818RtcState *rtc =MC146818_RTC (s);
@@ -340,6 +399,7 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev,X86CPU *cpu =X86_CPU (dev);CPUX86State *env = &cpu->env;MachineState *ms =MACHINE (hotplug_dev); +MachineClass *mc =MACHINE_GET_CLASS (ms);X86MachineState *x86ms =X86_MACHINE (hotplug_dev);unsigned int smp_cores = ms->smp.cores;unsigned int smp_threads = ms->smp.threads;
@@ -374,26 +434,9 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev,set_bit (CPU_TOPOLOGY_LEVEL_DIE , env->avail_cpu_topo); } -/* -* If APIC ID is not set, -* set it based on socket/die/module/core/thread properties. -*/ -if (cpu->apic_id ==UNASSIGNED_APIC_ID ) { -/* -* die-id was optional in QEMU 4.0 and older, so keep it optional -* if there's only one die per socket. -*/ -if (cpu->die_id <0 && ms->smp.dies ==1 ) { - cpu->die_id =0 ; - } - -/* -* module-id was optional in QEMU 9.0 and older, so keep it optional -* if there's only one module per die. -*/ -if (cpu->module_id <0 && ms->smp.modules ==1 ) { - cpu->module_id =0 ; - } +if (cpu->apic_id ==UNASSIGNED_APIC_ID && + !mc->smp_props.topo_tree_supported) { +x86_fixup_topo_ids (ms, cpu);if (cpu->socket_id <0 ) {error_setg (errp,"CPU socket-id is not set" );
@@ -409,7 +452,6 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, }else if (cpu->die_id > ms->smp.dies -1 ) {error_setg (errp,"Invalid CPU die-id: %u must be in range 0:%u" , cpu->die_id, ms->smp.dies -1 ); -return ; }if (cpu->module_id <0 ) {error_setg (errp,"CPU module-id is not set" );
@@ -442,6 +484,21 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, topo_ids.core_id = cpu->core_id; topo_ids.smt_id = cpu->thread_id; cpu->apic_id =x86_apicid_from_topo_ids (&topo_info, &topo_ids); + }else if (cpu->apic_id ==UNASSIGNED_APIC_ID && + mc->smp_props.topo_tree_supported) { +/* +* For this case, CPU is added by specifying the bus. Under the +* topology tree, specifying only the bus should be feasible, but +* the topology represented by the bus, topo ids, or apic id must +* be consistent. +* +* To simplify, the case with only the bus specified is not supported +* at this time. +*/ +if (x86_cpu_get_parent_bus (dev) != dev->parent_bus) { +error_setg (errp,"Invalid CPU topology ids" ); +return ; + } } cpu_slot =x86_find_cpu_slot (MACHINE (x86ms), cpu->apic_id, &idx);
include/hw/i386/x86.h +2 -0
@@ -138,6 +138,8 @@ void x86_load_linux(X86MachineState *x86ms,bool x86_machine_is_smm_enabled (const X86MachineState *x86ms);bool x86_machine_is_acpi_enabled (const X86MachineState *x86ms); +BusState *x86_cpu_get_parent_bus (DeviceState *dev); +/* Global System Interrupts */ #define ACPI_BUILD_PCI_IRQS ((1<<5) | (1<<9) | (1<<10) | (1<<11))
target/i386/cpu.c +11 -0
@@ -35,12 +35,14 @@#include "standard-headers/asm-x86/kvm_para.h" #include "hw/qdev-properties.h" #include "hw/i386/topology.h" +#include "monitor/bus-finder.h" #ifndef CONFIG_USER_ONLY #include "sysemu/reset.h" #include "qapi/qapi-commands-machine-target.h" #include "exec/address-spaces.h" #include "hw/boards.h" #include "hw/i386/sgx-epc.h" +#include "hw/i386/x86.h" #endif #include "disas/capstone.h"
@@ -8468,6 +8470,11 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) dc->user_creatable = true; +#ifndef CONFIG_USER_ONLY +BusFinderClass *bfc =BUS_FINDER_CLASS (oc); + bfc->find_bus = x86_cpu_get_parent_bus; +#endif +object_class_property_add (oc,"family" ,"int" , x86_cpuid_version_get_family, x86_cpuid_version_set_family,NULL ,NULL );
@@ -8520,6 +8527,10 @@ static const TypeInfo x86_cpu_type_info = { .abstract = true, .class_size = sizeof(X86CPUClass), .class_init = x86_cpu_common_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_BUS_FINDER }, + { } + } };/* "base" CPU model, used by query-cpu-model-expansion */
Signature · 1 line
2.34.1
RFC v2 15/15 i386: Support topology device tree
In reply to Zhao LiuSupport complete QOM CPu topology tree for x86 machine, and specify bus_type for x86 CPU so that all x86 CPUs will be added in the topology tree.
Since the CPU slot make the machine as the hotplug handler for all topology devices, hotplug related hooks may used to handle other topology devices besides the CPU. Thus, make microvm not assume that the device is only a CPU when implementing the relevant hooks.
Additionally, drop code paths that are not needed by the topology tree implementation.
--- hw/i386/microvm.c | 13 +++++--- hw/i386/x86-common.c | 78 +++++--------------------------------------- hw/i386/x86.c | 2 ++ target/i386/cpu.c | 2 ++ 4 files changed, 21 insertions(+), 74 deletions(-)
hw/i386/microvm.c +9 -4
@@ -417,16 +417,21 @@ static void microvm_fix_kernel_cmdline(MachineState *machine)static void microvm_device_pre_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) { -X86CPU *cpu =X86_CPU (dev); +if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +X86CPU *cpu; + cpu =X86_CPU (dev); - cpu->host_phys_bits = true;/* need reliable phys-bits */ -x86_cpu_pre_plug (hotplug_dev, dev, errp); + cpu->host_phys_bits = true;/* need reliable phys-bits */ +x86_cpu_pre_plug (hotplug_dev, dev, errp); + } }static void microvm_device_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) { -x86_cpu_plug (hotplug_dev, dev, errp); +if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +x86_cpu_plug (hotplug_dev, dev, errp); + } } static void microvm_device_unplug_request_cb(HotplugHandler *hotplug_dev,
hw/i386/x86-common.c +8 -70
102 lines not on this page · raw message
hw/i386/x86.c +2 -0
@@ -381,6 +381,8 @@ static void x86_machine_class_init(ObjectClass *oc, void *data) mc->cpu_index_to_instance_props = x86_cpu_index_to_props; mc->get_default_cpu_node_id = x86_get_default_cpu_node_id; mc->possible_cpu_arch_ids = x86_possible_cpu_arch_ids; + mc->smp_props.arch_id_topo_level =CPU_TOPOLOGY_LEVEL_THREAD ; + mc->smp_props.topo_tree_supported = true; mc->kvm_type = x86_kvm_type; x86mc->save_tsc_khz = true; x86mc->fwcfg_dma_enabled = true;
target/i386/cpu.c +2 -0
@@ -8473,6 +8473,8 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)#ifndef CONFIG_USER_ONLY BusFinderClass *bfc =BUS_FINDER_CLASS (oc); bfc->find_bus = x86_cpu_get_parent_bus; + + dc->bus_type =TYPE_CPU_BUS ;#endif object_class_property_add(oc, "family", "int",
Signature · 1 line
2.34.1