From nobody Thu May 8 16:40:32 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1652100385; cv=none; d=zohomail.com; s=zohoarc; b=jR0CU16BmDrptc8gePVxM5rnLMhbV3Leyzw9p3tvHq5Sw928urEhzat387B2Lx4QO8G89tGn437OLvJL2HLr9AO9BAxh+Qduid5XaAOeoyRBj4Nn8GJy0bTWUDIHnVAFFoW6kMz48Rfh6LcB3TufhQq58jrLMdNWiEzhL5TS2q0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652100385; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aYXIZAfUyumvHztGuBmfJ493wl1SWQhTJkN41sNVXpo=; b=Yid5WmfvTrS2egt8+KEhqkWRR6cwQ8kCPXa940IeIfAYv3b79vnFc2D39TUQppf/0gfGfV3Bt58QGA4okZyj8F1PP5E83AFBPQDI6+sR/qkAWqrEILweoff9TsWixmXrJ2UffFfdstXt6P0JwObvc9huDAN6vyuS/74ujwp1hGg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from=<peter.maydell@linaro.org> (p=none dis=none) Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org> Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1652100385643108.74811699104396; Mon, 9 May 2022 05:46:25 -0700 (PDT) Received: from localhost ([::1]:54592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>) id 1no2mO-0004XX-9P for importer@patchew.org; Mon, 09 May 2022 08:46:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <peter.maydell@linaro.org>) id 1no22p-00088B-GK for qemu-devel@nongnu.org; Mon, 09 May 2022 07:59:19 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:42926) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <peter.maydell@linaro.org>) id 1no22n-0001Gn-Jv for qemu-devel@nongnu.org; Mon, 09 May 2022 07:59:19 -0400 Received: by mail-wr1-x436.google.com with SMTP id e24so19108668wrc.9 for <qemu-devel@nongnu.org>; Mon, 09 May 2022 04:59:17 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id bs6-20020a056000070600b0020c5253d8bdsm12199928wrb.9.2022.05.09.04.59.16 for <qemu-devel@nongnu.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 04:59:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=aYXIZAfUyumvHztGuBmfJ493wl1SWQhTJkN41sNVXpo=; b=daBMO3S3dZ0hlNjXy6GD80QDKPKSa9jz99hOUzLdyJdahyZqnsoiAi1OE+TCP5++HM L3a6jGkhKL8duPBZj1l+42jLbtgADJol6Kh/EqfPjeMKyjdcwnqtFIssCHLDClnCEJnT gUwLmbiUdQ/GIS46z+aBaCWqL/UsEwyGxeF3+XDIWvDH7cn3RsPqg53Eso5RNAY6tcI2 PjWIGwUHueFRoGIjHxFxlT4oaHsYgeojg3XcEzf1hhFDa6fF9ESJ63/4Y3xPdYw2BNZh uPnk62ojcTs5S5FFlZTV48wWrqPo1NNQf0HN8/LcU78vCvw5wdaH9IoyS7E5Y56/z7DG snhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aYXIZAfUyumvHztGuBmfJ493wl1SWQhTJkN41sNVXpo=; b=jSXbEjhuo5aq6DbJjNnVH//ZXyOBRjufnrJuUWUGvKkkgSOaBm8I2i5n+DoOsA+piF FS5ae9nW+XioXZ+JKhT11Xa6viI8zUnYvPUz4PFa12Si8i18/X/L+q+9xjWRqX/Od+A4 NYDvDrLcSdihrgHH7X/79QBJ3obeqTShoA9VgvrjCzsFvDAsvpy45G/XOwMyj96MibM1 ngps5SAVz3zhVfaq8TJQk6ZmHseKQboqI/0UE8N7RO0REIDYox8yHKaZqt21KhodR2TJ 57H1LEoj4unRwAghUDPTLClwtp4kwNQRyjd03WvIB7T2b/OU5TQjjkS7M0oxhDr5bbZN t5dg== X-Gm-Message-State: AOAM530bcWtK4z8CxO8e7bVuAUXLTKiULRW4cLVRpCgag1NABZM0XgTb 5vGqfkRUo7gMOr+zA15HAaAQYe3pVVWRUQ== X-Google-Smtp-Source: ABdhPJwrLTUgygQva0W2aRB8BuTkKUKr67iWE/n8EhjMipCMEWcjuxUyoBZJ7zVe1QmGlM5dOXDQZA== X-Received: by 2002:a5d:4052:0:b0:20a:d8b9:9d4b with SMTP id w18-20020a5d4052000000b0020ad8b99d4bmr13201130wrp.612.1652097556877; Mon, 09 May 2022 04:59:16 -0700 (PDT) From: Peter Maydell <peter.maydell@linaro.org> To: qemu-devel@nongnu.org Subject: [PULL 32/32] hw/acpi/aml-build: Use existing CPU topology to build PPTT table Date: Mon, 9 May 2022 12:58:48 +0100 Message-Id: <20220509115848.3521805-33-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220509115848.3521805-1-peter.maydell@linaro.org> References: <20220509115848.3521805-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: <qemu-devel.nongnu.org> List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe> List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel> List-Post: <mailto:qemu-devel@nongnu.org> List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help> List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=subscribe> Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org> X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1652100387099100001 Content-Type: text/plain; charset="utf-8" From: Gavin Shan <gshan@redhat.com> When the PPTT table is built, the CPU topology is re-calculated, but it's unecessary because the CPU topology has been populated in virt_possible_cpu_arch_ids() on arm/virt machine. This reworks build_pptt() to avoid by reusing the existing IDs in ms->possible_cpus. Currently, the only user of build_pptt() is arm/virt machine. Signed-off-by: Gavin Shan <gshan@redhat.com> Tested-by: Yanan Wang <wangyanan55@huawei.com> Reviewed-by: Yanan Wang <wangyanan55@huawei.com> Acked-by: Igor Mammedov <imammedo@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Message-id: 20220503140304.855514-7-gshan@redhat.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org> --- hw/acpi/aml-build.c | 111 +++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 63 deletions(-) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 4086879ebff..e6bfac95c7a 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -2002,86 +2002,71 @@ void build_pptt(GArray *table_data, BIOSLinker *lin= ker, MachineState *ms, const char *oem_id, const char *oem_table_id) { MachineClass *mc =3D MACHINE_GET_CLASS(ms); - GQueue *list =3D g_queue_new(); - guint pptt_start =3D table_data->len; - guint parent_offset; - guint length, i; - int uid =3D 0; - int socket; + CPUArchIdList *cpus =3D ms->possible_cpus; + int64_t socket_id =3D -1, cluster_id =3D -1, core_id =3D -1; + uint32_t socket_offset =3D 0, cluster_offset =3D 0, core_offset =3D 0; + uint32_t pptt_start =3D table_data->len; + int n; AcpiTable table =3D { .sig =3D "PPTT", .rev =3D 2, .oem_id =3D oem_id, .oem_table_id =3D oem_table_id= }; =20 acpi_table_begin(&table, table_data); =20 - for (socket =3D 0; socket < ms->smp.sockets; socket++) { - g_queue_push_tail(list, - GUINT_TO_POINTER(table_data->len - pptt_start)); - build_processor_hierarchy_node( - table_data, - /* - * Physical package - represents the boundary - * of a physical package - */ - (1 << 0), - 0, socket, NULL, 0); - } - - if (mc->smp_props.clusters_supported) { - length =3D g_queue_get_length(list); - for (i =3D 0; i < length; i++) { - int cluster; - - parent_offset =3D GPOINTER_TO_UINT(g_queue_pop_head(list)); - for (cluster =3D 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); - } + /* + * This works with the assumption that cpus[n].props.*_id has been + * sorted from top to down levels in mc->possible_cpu_arch_ids(). + * Otherwise, the unexpected and duplicated containers will be + * created. + */ + for (n =3D 0; n < cpus->len; n++) { + if (cpus->cpus[n].props.socket_id !=3D socket_id) { + assert(cpus->cpus[n].props.socket_id > socket_id); + socket_id =3D cpus->cpus[n].props.socket_id; + cluster_id =3D -1; + core_id =3D -1; + socket_offset =3D table_data->len - pptt_start; + build_processor_hierarchy_node(table_data, + (1 << 0), /* Physical package */ + 0, socket_id, NULL, 0); } - } =20 - length =3D g_queue_get_length(list); - for (i =3D 0; i < length; i++) { - int core; - - parent_offset =3D GPOINTER_TO_UINT(g_queue_pop_head(list)); - for (core =3D 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 */ - parent_offset, core, NULL, 0); - } else { - build_processor_hierarchy_node( - table_data, - (1 << 1) | /* ACPI Processor ID valid */ - (1 << 3), /* Node is a Leaf */ - parent_offset, uid++, NULL, 0); + if (mc->smp_props.clusters_supported) { + if (cpus->cpus[n].props.cluster_id !=3D cluster_id) { + assert(cpus->cpus[n].props.cluster_id > cluster_id); + cluster_id =3D cpus->cpus[n].props.cluster_id; + core_id =3D -1; + cluster_offset =3D table_data->len - pptt_start; + build_processor_hierarchy_node(table_data, + (0 << 0), /* Not a physical package */ + socket_offset, cluster_id, NULL, 0); } + } else { + cluster_offset =3D socket_offset; } - } =20 - length =3D g_queue_get_length(list); - for (i =3D 0; i < length; i++) { - int thread; + if (ms->smp.threads =3D=3D 1) { + build_processor_hierarchy_node(table_data, + (1 << 1) | /* ACPI Processor ID valid */ + (1 << 3), /* Node is a Leaf */ + cluster_offset, n, NULL, 0); + } else { + if (cpus->cpus[n].props.core_id !=3D core_id) { + assert(cpus->cpus[n].props.core_id > core_id); + core_id =3D cpus->cpus[n].props.core_id; + core_offset =3D table_data->len - pptt_start; + build_processor_hierarchy_node(table_data, + (0 << 0), /* Not a physical package */ + cluster_offset, core_id, NULL, 0); + } =20 - parent_offset =3D GPOINTER_TO_UINT(g_queue_pop_head(list)); - for (thread =3D 0; thread < ms->smp.threads; thread++) { - build_processor_hierarchy_node( - table_data, + 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); + core_offset, n, NULL, 0); } } =20 - g_queue_free(list); acpi_table_end(linker, &table); } =20 --=20 2.25.1