ARM virt: Support CPU cluster topology
v7 cover ARM virt: Support CPU cluster topology
This v7 series enables the support for CPU cluster topology on ARM virt machines. The generic infrastructure for CPU cluster parameter has been in upstream.
Background and descriptions:
The new Cluster-Aware Scheduling support has landed in Linux 5.16, which has been proved to benefit the scheduling performance (e.g. load balance and wake_affine strategy) for both x86_64 and AArch64. We can see the PR [1] or the actual patch series [2] for reference.
So since Linux 5.16 we have four-level arch-neutral CPU topology definition like below and a new scheduler level for clusters.
struct cpu_topology {
int thread_id;
int core_id;
int cluster_id;
int package_id;
int llc_id;
cpumask_t thread_sibling;
cpumask_t core_sibling;
cpumask_t cluster_sibling;
cpumask_t llc_sibling;
}A cluster generally means a group of CPU cores which share L2 cache or other mid-level resources, and it is the shared resources that is used to improve scheduler's behavior. From the point of view of the size range, it's between CPU die and CPU core. For example, on some ARM64 Kunpeng servers, we have 6 clusters in each NUMA node, and 4 CPU cores in each cluster. The 4 CPU cores share a separate L2 cache and a L3 cache tag, which brings cache affinity advantage.
[1] https://lore.kernel.org/lkml/163572864855.3357115.17938524897008353101.tglx@xen13/
[2] https://lkml.org/lkml/2021/9/24/178
In virtualization, on the Hosts which have physical clusters, if we can design a vCPU topology with cluster level for guest kernel and have a dedicated vCPU pinning. A Cluster-Aware Guest kernel can also make use of the cache affinity of CPU clusters to gain similar scheduling performance. This series only enables clusters support in the vCPU topology on ARM virt machines. We can also enable it for other machine types in the future if needed.
The patches in this series do:
- Enable CPU cluster support on ARM virt machines, so that users can specify a 4-level CPU hierarchy sockets/clusters/cores/threads. And the 4-level topology will be described to guest kernel through ACPI PPTT and DT cpu-map.
Changelog:v6->v7:
- dropped the introduced ARM specific build_pptt() and extend the generic one
- added A-bs/R-bs from Andrew and Ani, thanks.
- v6: https://patchew.org/QEMU/[email protected]/
v5->v6:
- dropped the generic part which is in upstream now
- rebased on latest master
- v5: https://patchew.org/QEMU/[email protected]/
Yanan Wang (6):
hw/arm/virt: Support CPU cluster on ARM virt machine hw/arm/virt: Support cluster level in DT cpu-map hw/acpi/aml-build: Improve scalability of PPTT generation tests/acpi/bios-tables-test: Allow changes to virt/PPTT file hw/acpi/aml-build: Support cluster level in PPTT generation tests/acpi/bios-table-test: Update expected virt/PPTT file
hw/acpi/aml-build.c | 68 ++++++++++++++++++++++++++++---------- hw/arm/virt.c | 16 +++++---- qemu-options.hx | 10 ++++++ tests/data/acpi/virt/PPTT | Bin 76 -> 96 bytes 4 files changed, 69 insertions(+), 25 deletions(-)
Signature · 1 line
2.27.0
PATCH v7 1/6 hw/arm/virt: Support CPU cluster on ARM virt machine
ARM64 machines like Kunpeng Family Server Chips have a level of hardware topology in which a group of CPU cores share L3 cache tag or L2 cache. For example, Kunpeng 920 typically has 6 or 8 clusters in each NUMA node (also represent range of CPU die), and each cluster has 4 CPU cores. All clusters share L3 cache data, but CPU cores in each cluster share a local L3 tag.
Running a guest kernel with Cluster-Aware Scheduling on the Hosts which have physical clusters, if we can design a vCPU topology with cluster level for guest kernel and then have a dedicated vCPU pinning, the guest will gain scheduling performance improvement from cache affinity of CPU cluster.
So let's enable the support for this new parameter on ARM virt machines. After this patch, we can define a 4-level CPU hierarchy like: cpus=*,maxcpus=*,sockets=*,clusters=*, cores=*,threads=*.
--- hw/arm/virt.c | 1 + qemu-options.hx | 10 ++++++++++ 2 files changed, 11 insertions(+)
hw/arm/virt.c +1 -0
@@ -2700,6 +2700,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) hc->unplug_request = virt_machine_device_unplug_request_cb; hc->unplug = virt_machine_device_unplug_cb; mc->nvdimm_supported = true; + mc->smp_props.clusters_supported = true; mc->auto_enable_numa_with_memhp = true; mc->auto_enable_numa_with_memdev = true; mc->default_ram_id ="mach-virt.ram" ;
qemu-options.hx +10 -0
@@ -277,6 +277,16 @@ SRST -smp 16,sockets=2,dies=2,cores=2,threads=2,maxcpus=16 + The following sub-option defines a CPU topology hierarchy (2 sockets + totally on the machine, 2 clusters per socket, 2 cores per cluster, + 2 threads per core) for ARM virt machines which support sockets/clusters + /cores/threads. Some members of the option can be omitted but their values + will be automatically computed: + + :: + + -smp 16,sockets=2,clusters=2,cores=2,threads=2,maxcpus=16 + Historically preference was given to the coarsest topology parameters when computing missing values (ie sockets preferred over cores, which were preferred over threads), however, this behaviour is considered
Signature · 1 line
2.27.0
PATCH v7 3/6 hw/acpi/aml-build: Improve scalability of PPTT generation
In reply to Yanan Wang viaUse g_queue APIs to reduce the nested loops and code indentation with the processor hierarchy levels increasing. Consenquently, it's more scalable to add new topology level to build_pptt.
No functional change intended.
--- hw/acpi/aml-build.c | 50 +++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 18 deletions(-)
hw/acpi/aml-build.c +32 -18
@@ -2001,7 +2001,10 @@ static void build_processor_hierarchy_node(GArray *tbl, uint32_t flags,void build_pptt (GArray *table_data,BIOSLinker *linker,MachineState *ms,const char *oem_id,const char *oem_table_id) { -int pptt_start = table_data->len; +GQueue *list =g_queue_new (); +guint pptt_start = table_data->len; +guint parent_offset; +guint length, i;int uid =0 ;int socket;AcpiTable table = { .sig ="PPTT" , .rev =2 ,
@@ -2010,9 +2013,8 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,acpi_table_begin (&table, table_data);for (socket =0 ; socket < ms->smp.sockets; socket++) { -uint32_t socket_offset = table_data->len - pptt_start; -int core; - +g_queue_push_tail (list, +GUINT_TO_POINTER (table_data->len - pptt_start)); build_processor_hierarchy_node( table_data,/*
@@ -2021,35 +2023,47 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,*/ (1 <<0 ), 0, socket, NULL, 0); + } -for (core =0 ; core < ms->smp.cores; core++) { -uint32_t core_offset = table_data->len - pptt_start; -int thread; + length =g_queue_get_length (list); +for (i =0 ; i < length; i++) { +int core; + parent_offset =GPOINTER_TO_UINT (g_queue_pop_head (list)); +for (core =0 ; core < ms->smp.cores; core++) {if (ms->smp.threads >1 ) { +g_queue_push_tail (list, +GUINT_TO_POINTER (table_data->len - pptt_start));build_processor_hierarchy_node ( table_data, (0 <<0 ),/* not a physical package */ - socket_offset, core,NULL ,0 ); - -for (thread =0 ; thread < ms->smp.threads; thread++) { -build_processor_hierarchy_node ( - table_data, - (1 <<1 ) |/* ACPI Processor ID valid */ - (1 <<2 ) |/* Processor is a Thread */ - (1 <<3 ),/* Node is a Leaf */ - core_offset, uid++,NULL ,0 ); - } + parent_offset, core,NULL ,0 ); }else {build_processor_hierarchy_node ( table_data, (1 <<1 ) |/* ACPI Processor ID valid */ (1 <<3 ),/* Node is a Leaf */ - socket_offset, uid++,NULL ,0 ); + parent_offset, uid++,NULL ,0 ); } } } + length =g_queue_get_length (list); +for (i =0 ; i < length; i++) { +int thread; + + parent_offset =GPOINTER_TO_UINT (g_queue_pop_head (list)); +for (thread =0 ; thread < ms->smp.threads; thread++) { +build_processor_hierarchy_node ( + table_data, + (1 <<1 ) |/* ACPI Processor ID valid */ + (1 <<2 ) |/* Processor is a Thread */ + (1 <<3 ),/* Node is a Leaf */ + parent_offset, uid++,NULL ,0 ); + } + } + +g_queue_free (list);acpi_table_end (linker, &table); }
Signature · 1 line
2.27.0
PATCH v7 2/6 hw/arm/virt: Support cluster level in DT cpu-map
In reply to Yanan Wang viaSupport one cluster level between core and physical package in the cpu-map of Arm/virt devicetree. This is also consistent with Linux Doc "Documentation/devicetree/bindings/cpu/cpu-topology.txt".
--- hw/arm/virt.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
hw/arm/virt.c +8 -7
@@ -430,9 +430,8 @@ static void fdt_add_cpu_nodes(const VirtMachineState *vms)* can contain several layers of clustering within a single physical * package and cluster nodes can be contained in parent cluster nodes. * -* Given that cluster is not yet supported in the vCPU topology, -* we currently generate one cluster node within each socket node -* by default. +* Note: currently we only support one layer of clustering within +* each physical package. */ qemu_fdt_add_subnode (ms->fdt,"/cpus/cpu-map" );
@@ -442,14 +441,16 @@ static void fdt_add_cpu_nodes(const VirtMachineState *vms)if (ms->smp.threads >1 ) { map_path =g_strdup_printf ( -"/cpus/cpu-map/socket%d/cluster0/core%d/thread%d" , - cpu / (ms->smp.cores * ms->smp.threads), +"/cpus/cpu-map/socket%d/cluster%d/core%d/thread%d" , + cpu / (ms->smp.clusters * ms->smp.cores * ms->smp.threads), + (cpu / (ms->smp.cores * ms->smp.threads)) % ms->smp.clusters, (cpu / ms->smp.threads) % ms->smp.cores, cpu % ms->smp.threads); }else { map_path =g_strdup_printf ( -"/cpus/cpu-map/socket%d/cluster0/core%d" , - cpu / ms->smp.cores, +"/cpus/cpu-map/socket%d/cluster%d/core%d" , + cpu / (ms->smp.clusters * ms->smp.cores), + (cpu / ms->smp.cores) % ms->smp.clusters, cpu % ms->smp.cores); }qemu_fdt_add_path (ms->fdt, map_path);
Signature · 1 line
2.27.0
PATCH v7 5/6 hw/acpi/aml-build: Support cluster level in PPTT generation
In reply to Yanan Wang viaSupport CPU cluster topology level in generation of ACPI Processor Properties Topology Table (PPTT).
--- hw/acpi/aml-build.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
hw/acpi/aml-build.c +18 -0
@@ -2001,6 +2001,7 @@ static void build_processor_hierarchy_node(GArray *tbl, uint32_t flags,void build_pptt (GArray *table_data,BIOSLinker *linker,MachineState *ms,const char *oem_id,const char *oem_table_id) { +MachineClass *mc =MACHINE_GET_CLASS (ms);GQueue *list =g_queue_new ();guint pptt_start = table_data->len;guint parent_offset;
@@ -2025,6 +2026,23 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms, 0, socket, NULL, 0); } +if (mc->smp_props.clusters_supported) { + length =g_queue_get_length (list); +for (i =0 ; i < length; i++) { +int cluster; + + parent_offset =GPOINTER_TO_UINT (g_queue_pop_head (list)); +for (cluster =0 ; cluster < ms->smp.clusters; cluster++) { +g_queue_push_tail (list, +GUINT_TO_POINTER (table_data->len - pptt_start)); +build_processor_hierarchy_node ( + table_data, + (0 <<0 ),/* not a physical package */ + parent_offset, cluster,NULL ,0 ); + } + } + } + length =g_queue_get_length (list);for (i =0 ; i < length; i++) {int core;
Signature · 1 line
2.27.0
PATCH v7 4/6 tests/acpi/bios-tables-test: Allow changes to virt/PPTT file
In reply to Yanan Wang viaList test/data/acpi/virt/PPTT as the expected files allowed to be changed in tests/qtest/bios-tables-test-allowed-diff.h
--- tests/qtest/bios-tables-test-allowed-diff.h | 1 + 1 file changed, 1 insertion(+)
tests/qtest/bios-tables-test-allowed-diff.h +1 -0
@@ -1 +1,2 @@/* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/virt/PPTT",
Signature · 1 line
2.27.0
PATCH v7 6/6 tests/acpi/bios-table-test: Update expected virt/PPTT file
In reply to Yanan Wang viaRun ./tests/data/acpi/rebuild-expected-aml.sh from build directory to update PPTT binary. Also empty bios-tables-test-allowed-diff.h.
The disassembled differences between actual and expected PPTT:
/*
* Intel ACPI Component Architecture
* AML/ASL+ Disassembler version 20200528 (64-bit version)
* Copyright (c) 2000 - 2020 Intel Corporation
*
- * Disassembly of tests/data/acpi/virt/PPTT, Tue Jan 4 12:51:11 2022
+ * Disassembly of /tmp/aml-2ZGOF1, Tue Jan 4 12:51:11 2022 *
* ACPI Data Table [PPTT]
*
* Format: [HexOffset DecimalOffset ByteLength] FieldName : FieldValue */
[000h 0000 4] Signature : "PPTT" [Processor Properties Topology Table] -[004h 0004 4] Table Length : 0000004C +[004h 0004 4] Table Length : 00000060 [008h 0008 1] Revision : 02 -[009h 0009 1] Checksum : A8 +[009h 0009 1] Checksum : 48 [00Ah 0010 6] Oem ID : "BOCHS " [010h 0016 8] Oem Table ID : "BXPC " [018h 0024 4] Oem Revision : 00000001 [01Ch 0028 4] Asl Compiler ID : "BXPC" [020h 0032 4] Asl Compiler Revision : 00000001
[024h 0036 1] Subtable Type : 00 [Processor Hierarchy Node]
[025h 0037 1] Length : 14
[026h 0038 2] Reserved : 0000
[028h 0040 4] Flags (decoded below) : 00000001
Physical package : 1
ACPI Processor ID valid : 0
Processor is a thread : 0
Node is a leaf : 0
Identical Implementation : 0
[02Ch 0044 4] Parent : 00000000
[030h 0048 4] ACPI Processor ID : 00000000
[034h 0052 4] Private Resource Number : 00000000[038h 0056 1] Subtable Type : 00 [Processor Hierarchy Node] [039h 0057 1] Length : 14 [03Ah 0058 2] Reserved : 0000 -[03Ch 0060 4] Flags (decoded below) : 0000000A +[03Ch 0060 4] Flags (decoded below) : 00000000
Physical package : 0
- ACPI Processor ID valid : 1
+ ACPI Processor ID valid : 0
Processor is a thread : 0
- Node is a leaf : 1
+ Node is a leaf : 0
Identical Implementation : 0
[040h 0064 4] Parent : 00000024 [044h 0068 4] ACPI Processor ID : 00000000 [048h 0072 4] Private Resource Number : 00000000
-Raw Table Data: Length 76 (0x4C)
+[04Ch 0076 1] Subtable Type : 00 [Processor Hierarchy Node] +[04Dh 0077 1] Length : 14 +[04Eh 0078 2] Reserved : 0000 +[050h 0080 4] Flags (decoded below) : 0000000A
+ Physical package : 0
+ ACPI Processor ID valid : 1
+ Processor is a thread : 0
+ Node is a leaf : 1
+ Identical Implementation : 0
+[054h 0084 4] Parent : 00000038 +[058h 0088 4] ACPI Processor ID : 00000000 +[05Ch 0092 4] Private Resource Number : 00000000
+
+Raw Table Data: Length 96 (0x60)
- 0000: 50 50 54 54 4C 00 00 00 02 A8 42 4F 43 48 53 20 // PPTTL.....BOCHS
+ 0000: 50 50 54 54 60 00 00 00 02 48 42 4F 43 48 53 20 // PPTT`....HBOCHS
0010: 42 58 50 43 20 20 20 20 01 00 00 00 42 58 50 43 // BXPC ....BXPC
0020: 01 00 00 00 00 14 00 00 01 00 00 00 00 00 00 00 // ................
- 0030: 00 00 00 00 00 00 00 00 00 14 00 00 0A 00 00 00 // ................
- 0040: 24 00 00 00 00 00 00 00 00 00 00 00 // $...........
+ 0030: 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00 // ................
+ 0040: 24 00 00 00 00 00 00 00 00 00 00 00 00 14 00 00 // $...............
+ 0050: 0A 00 00 00 38 00 00 00 00 00 00 00 00 00 00 00 // ....8...........--- tests/data/acpi/virt/PPTT | Bin 76 -> 96 bytes tests/qtest/bios-tables-test-allowed-diff.h | 1 - 2 files changed, 1 deletion(-)
tests/data/acpi/virt/PPTT binary +0 -0
tests/qtest/bios-tables-test-allowed-diff.h +0 -1
@@ -1,2 +1 @@/* List of comma-separated changed AML files to ignore */ -"tests/data/acpi/virt/PPTT",
Signature · 1 line
2.27.0
Peter Maydell
AppliedQuoted 11 lines · Yanan Wang
This v7 series enables the support for CPU cluster topology on ARM virt machines. The generic infrastructure for CPU cluster parameter has been in upstream.
The patches in this series do:
- Enable CPU cluster support on ARM virt machines, so that users can specify a 4-level CPU hierarchy sockets/clusters/cores/threads. And the 4-level topology will be described to guest kernel through ACPI PPTT and DT cpu-map.
Quoted 5 lines
Changelog:
v6->v7:
- dropped the introduced ARM specificbuild_pptt()and extend the generic one
- added A-bs/R-bs from Andrew and Ani, thanks.
- v6: https://patchew.org/QEMU/[email protected]/
Applied to target-arm.next, thanks.
(People who've been reviewing this series -- let me know if you wanted more time for it.)
-- PMM