From patchwork Mon May 9 11:58:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 570995 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:66c4:0:0:0:0 with SMTP id x4csp3957338mal; Mon, 9 May 2022 05:45:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXx4y77eyBII9o/mZZi7oBVl/pMjn5xjZh1dzvW/QdU00pjWdzaXhOLUPDQQgZK9OKbj/Y X-Received: by 2002:a05:620a:2804:b0:67d:1e7b:b528 with SMTP id f4-20020a05620a280400b0067d1e7bb528mr11504089qkp.193.1652100314803; Mon, 09 May 2022 05:45:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652100314; cv=none; d=google.com; s=arc-20160816; b=NF5dTzM3bFiVsoRo7wxRR6cDzO/TQc7D0PAWdk1YuMbgDvEjFc0w0ZVWRMeEiuWukX M9WrRcVlYhSYsnbnz9UfgXv2OT52NmuCma0eYpCMwPKqB9mmUmRLewFuBtp8esTzC3YQ cziT/E4NWNEO6vAgqnO4FyrbDNZUIneWkud2coVlD6X3+rhLvud7pxvkb58Zoqwcq41n ALETn8mJ55LBY85a6Wc2wBmGXCiz3dDdhl7oZ658PXICaMuJDM7mJel3HXm/by4pPeZM ibV1A9NnV3+e31lfR4YAjHCUMI9eQSzRxFKjVDm+I7Zx8mc115hu4G1wGAG4US7AbU7p ZzZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=aYXIZAfUyumvHztGuBmfJ493wl1SWQhTJkN41sNVXpo=; b=Uj+MzkyLkgIcQTbye0aazTghJhiubqKwdPPKiVzynIu1lKAwVD2azD46jWGd12caKf Ro/r7p36WWHJ1SDRiZ5rKNQJY1GOiFugqv1wXMeM/uGB3Ow8luP0xDutB8YZnau3mJxt RuxklxH5NAUE8AAELvu6cvGyl150uPBxxv/arB3g3wDDANWclbYrGZuIgLcbLFCN3xYi cyzyOjuAiNwwTb7DSe9WIhneGe7dDU5tkbB+g7iBFNlXl6L6fUMBCc2fQvplqru5CbUh PMW6CYTmuwoyRgxBj7ayCs5hS/ScxwTcf63LhSORFDGvxnRCQ39Z44H1ed4DMmYABvK+ Ti5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=daBMO3S3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bq19-20020a05620a469300b0069fbb393062si8272731qkb.654.2022.05.09.05.45.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 May 2022 05:45:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=daBMO3S3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1no2lG-0001fn-Cr for patch@linaro.org; Mon, 09 May 2022 08:45:14 -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 ) 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 ) 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 ; Mon, 09 May 2022 04:59:17 -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-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) 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 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 04:59:16 -0700 (PDT) From: Peter Maydell 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 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Gavin Shan 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 Tested-by: Yanan Wang Reviewed-by: Yanan Wang Acked-by: Igor Mammedov Acked-by: Michael S. Tsirkin Message-id: 20220503140304.855514-7-gshan@redhat.com Signed-off-by: Peter Maydell --- 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 *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; - guint length, i; - int uid = 0; - int socket; + CPUArchIdList *cpus = ms->possible_cpus; + int64_t socket_id = -1, cluster_id = -1, core_id = -1; + uint32_t socket_offset = 0, cluster_offset = 0, core_offset = 0; + uint32_t pptt_start = table_data->len; + int n; AcpiTable table = { .sig = "PPTT", .rev = 2, .oem_id = oem_id, .oem_table_id = oem_table_id }; acpi_table_begin(&table, table_data); - for (socket = 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 = 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); - } + /* + * 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 = 0; n < cpus->len; n++) { + if (cpus->cpus[n].props.socket_id != socket_id) { + assert(cpus->cpus[n].props.socket_id > socket_id); + socket_id = cpus->cpus[n].props.socket_id; + cluster_id = -1; + core_id = -1; + socket_offset = table_data->len - pptt_start; + build_processor_hierarchy_node(table_data, + (1 << 0), /* Physical package */ + 0, socket_id, NULL, 0); } - } - 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 */ - 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 != cluster_id) { + assert(cpus->cpus[n].props.cluster_id > cluster_id); + cluster_id = cpus->cpus[n].props.cluster_id; + core_id = -1; + cluster_offset = 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 = socket_offset; } - } - length = g_queue_get_length(list); - for (i = 0; i < length; i++) { - int thread; + if (ms->smp.threads == 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 != core_id) { + assert(cpus->cpus[n].props.core_id > core_id); + core_id = cpus->cpus[n].props.core_id; + core_offset = table_data->len - pptt_start; + build_processor_hierarchy_node(table_data, + (0 << 0), /* Not a physical package */ + cluster_offset, core_id, NULL, 0); + } - parent_offset = GPOINTER_TO_UINT(g_queue_pop_head(list)); - for (thread = 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); } } - g_queue_free(list); acpi_table_end(linker, &table); }