thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 7 months ago
Clone

Blame SOURCES/kvm-hw-acpi-aml-build-Use-existing-CPU-topology-to-build.patch

29b115
From 8a12049e97149056f61f7748d9869606d282d16e Mon Sep 17 00:00:00 2001
29b115
From: Gavin Shan <gshan@redhat.com>
29b115
Date: Wed, 11 May 2022 18:01:35 +0800
29b115
Subject: [PATCH 06/16] hw/acpi/aml-build: Use existing CPU topology to build
29b115
 PPTT table
29b115
29b115
RH-Author: Gavin Shan <gshan@redhat.com>
29b115
RH-MergeRequest: 86: hw/arm/virt: Fix the default CPU topology
29b115
RH-Commit: [6/6] 53fa376531c204cf706cc1a7a0499019756106cb (gwshan/qemu-rhel-9)
29b115
RH-Bugzilla: 2041823
29b115
RH-Acked-by: Eric Auger <eric.auger@redhat.com>
29b115
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
29b115
RH-Acked-by: Andrew Jones <drjones@redhat.com>
29b115
29b115
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2041823
29b115
29b115
When the PPTT table is built, the CPU topology is re-calculated, but
29b115
it's unecessary because the CPU topology has been populated in
29b115
virt_possible_cpu_arch_ids() on arm/virt machine.
29b115
29b115
This reworks build_pptt() to avoid by reusing the existing IDs in
29b115
ms->possible_cpus. Currently, the only user of build_pptt() is
29b115
arm/virt machine.
29b115
29b115
Signed-off-by: Gavin Shan <gshan@redhat.com>
29b115
Tested-by: Yanan Wang <wangyanan55@huawei.com>
29b115
Reviewed-by: Yanan Wang <wangyanan55@huawei.com>
29b115
Acked-by: Igor Mammedov <imammedo@redhat.com>
29b115
Acked-by: Michael S. Tsirkin <mst@redhat.com>
29b115
Message-id: 20220503140304.855514-7-gshan@redhat.com
29b115
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
29b115
(cherry picked from commit ae9141d4a3265553503bf07d3574b40f84615a34)
29b115
Signed-off-by: Gavin Shan <gshan@redhat.com>
29b115
---
29b115
 hw/acpi/aml-build.c | 111 +++++++++++++++++++-------------------------
29b115
 1 file changed, 48 insertions(+), 63 deletions(-)
29b115
29b115
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
29b115
index 4086879ebf..e6bfac95c7 100644
29b115
--- a/hw/acpi/aml-build.c
29b115
+++ b/hw/acpi/aml-build.c
29b115
@@ -2002,86 +2002,71 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,
29b115
                 const char *oem_id, const char *oem_table_id)
29b115
 {
29b115
     MachineClass *mc = MACHINE_GET_CLASS(ms);
29b115
-    GQueue *list = g_queue_new();
29b115
-    guint pptt_start = table_data->len;
29b115
-    guint parent_offset;
29b115
-    guint length, i;
29b115
-    int uid = 0;
29b115
-    int socket;
29b115
+    CPUArchIdList *cpus = ms->possible_cpus;
29b115
+    int64_t socket_id = -1, cluster_id = -1, core_id = -1;
29b115
+    uint32_t socket_offset = 0, cluster_offset = 0, core_offset = 0;
29b115
+    uint32_t pptt_start = table_data->len;
29b115
+    int n;
29b115
     AcpiTable table = { .sig = "PPTT", .rev = 2,
29b115
                         .oem_id = oem_id, .oem_table_id = oem_table_id };
29b115
 
29b115
     acpi_table_begin(&table, table_data);
29b115
 
29b115
-    for (socket = 0; socket < ms->smp.sockets; socket++) {
29b115
-        g_queue_push_tail(list,
29b115
-            GUINT_TO_POINTER(table_data->len - pptt_start));
29b115
-        build_processor_hierarchy_node(
29b115
-            table_data,
29b115
-            /*
29b115
-             * Physical package - represents the boundary
29b115
-             * of a physical package
29b115
-             */
29b115
-            (1 << 0),
29b115
-            0, socket, NULL, 0);
29b115
-    }
29b115
-
29b115
-    if (mc->smp_props.clusters_supported) {
29b115
-        length = g_queue_get_length(list);
29b115
-        for (i = 0; i < length; i++) {
29b115
-            int cluster;
29b115
-
29b115
-            parent_offset = GPOINTER_TO_UINT(g_queue_pop_head(list));
29b115
-            for (cluster = 0; cluster < ms->smp.clusters; cluster++) {
29b115
-                g_queue_push_tail(list,
29b115
-                    GUINT_TO_POINTER(table_data->len - pptt_start));
29b115
-                build_processor_hierarchy_node(
29b115
-                    table_data,
29b115
-                    (0 << 0), /* not a physical package */
29b115
-                    parent_offset, cluster, NULL, 0);
29b115
-            }
29b115
+    /*
29b115
+     * This works with the assumption that cpus[n].props.*_id has been
29b115
+     * sorted from top to down levels in mc->possible_cpu_arch_ids().
29b115
+     * Otherwise, the unexpected and duplicated containers will be
29b115
+     * created.
29b115
+     */
29b115
+    for (n = 0; n < cpus->len; n++) {
29b115
+        if (cpus->cpus[n].props.socket_id != socket_id) {
29b115
+            assert(cpus->cpus[n].props.socket_id > socket_id);
29b115
+            socket_id = cpus->cpus[n].props.socket_id;
29b115
+            cluster_id = -1;
29b115
+            core_id = -1;
29b115
+            socket_offset = table_data->len - pptt_start;
29b115
+            build_processor_hierarchy_node(table_data,
29b115
+                (1 << 0), /* Physical package */
29b115
+                0, socket_id, NULL, 0);
29b115
         }
29b115
-    }
29b115
 
29b115
-    length = g_queue_get_length(list);
29b115
-    for (i = 0; i < length; i++) {
29b115
-        int core;
29b115
-
29b115
-        parent_offset = GPOINTER_TO_UINT(g_queue_pop_head(list));
29b115
-        for (core = 0; core < ms->smp.cores; core++) {
29b115
-            if (ms->smp.threads > 1) {
29b115
-                g_queue_push_tail(list,
29b115
-                    GUINT_TO_POINTER(table_data->len - pptt_start));
29b115
-                build_processor_hierarchy_node(
29b115
-                    table_data,
29b115
-                    (0 << 0), /* not a physical package */
29b115
-                    parent_offset, core, NULL, 0);
29b115
-            } else {
29b115
-                build_processor_hierarchy_node(
29b115
-                    table_data,
29b115
-                    (1 << 1) | /* ACPI Processor ID valid */
29b115
-                    (1 << 3),  /* Node is a Leaf */
29b115
-                    parent_offset, uid++, NULL, 0);
29b115
+        if (mc->smp_props.clusters_supported) {
29b115
+            if (cpus->cpus[n].props.cluster_id != cluster_id) {
29b115
+                assert(cpus->cpus[n].props.cluster_id > cluster_id);
29b115
+                cluster_id = cpus->cpus[n].props.cluster_id;
29b115
+                core_id = -1;
29b115
+                cluster_offset = table_data->len - pptt_start;
29b115
+                build_processor_hierarchy_node(table_data,
29b115
+                    (0 << 0), /* Not a physical package */
29b115
+                    socket_offset, cluster_id, NULL, 0);
29b115
             }
29b115
+        } else {
29b115
+            cluster_offset = socket_offset;
29b115
         }
29b115
-    }
29b115
 
29b115
-    length = g_queue_get_length(list);
29b115
-    for (i = 0; i < length; i++) {
29b115
-        int thread;
29b115
+        if (ms->smp.threads == 1) {
29b115
+            build_processor_hierarchy_node(table_data,
29b115
+                (1 << 1) | /* ACPI Processor ID valid */
29b115
+                (1 << 3),  /* Node is a Leaf */
29b115
+                cluster_offset, n, NULL, 0);
29b115
+        } else {
29b115
+            if (cpus->cpus[n].props.core_id != core_id) {
29b115
+                assert(cpus->cpus[n].props.core_id > core_id);
29b115
+                core_id = cpus->cpus[n].props.core_id;
29b115
+                core_offset = table_data->len - pptt_start;
29b115
+                build_processor_hierarchy_node(table_data,
29b115
+                    (0 << 0), /* Not a physical package */
29b115
+                    cluster_offset, core_id, NULL, 0);
29b115
+            }
29b115
 
29b115
-        parent_offset = GPOINTER_TO_UINT(g_queue_pop_head(list));
29b115
-        for (thread = 0; thread < ms->smp.threads; thread++) {
29b115
-            build_processor_hierarchy_node(
29b115
-                table_data,
29b115
+            build_processor_hierarchy_node(table_data,
29b115
                 (1 << 1) | /* ACPI Processor ID valid */
29b115
                 (1 << 2) | /* Processor is a Thread */
29b115
                 (1 << 3),  /* Node is a Leaf */
29b115
-                parent_offset, uid++, NULL, 0);
29b115
+                core_offset, n, NULL, 0);
29b115
         }
29b115
     }
29b115
 
29b115
-    g_queue_free(list);
29b115
     acpi_table_end(linker, &table);
29b115
 }
29b115
 
29b115
-- 
29b115
2.31.1
29b115