From patchwork Fri Jun 22 14:22:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 10482261 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B084A60230 for ; Fri, 22 Jun 2018 14:31:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F95728F5A for ; Fri, 22 Jun 2018 14:31:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83F3F28F65; Fri, 22 Jun 2018 14:31:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1A0C828F5A for ; Fri, 22 Jun 2018 14:31:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=6aqJrsHg+cCW/e9++4hinspRXaKFI+vFDjRnE+Zj79k=; b=doa G3Gat8WCynhGDYaGbzGrhwA/D5lq0/5+fmZXXU2gaHfdDo2M76JHkcg1kwliL0q6MOyejuNoFEiXN 46dDGl6HNQPaXeG0Jp1w4bDFAjzTJFpMWc6jZXNSz/maH48s2z3Knyo4TD7TgBj8JOfFeRp08A3T0 eUivKNfO+fv+zZAW2OevE5/8Tvd9WcF9F+7m7ISIij5Z6nn1HW3qu2hgCoIusUvWc2Z2fwqq7TqiA 1y3hBwHHzI0zEbuWtB48mDP/7WcMkLBssTwxfOzHs24GUfL5Ao20WW51Klveo2eGz8Q2Z8nEQX2Rh nspmCrhTAvXQqfrwG6eePZYhqtzyc8g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fWN5e-0007wt-EK; Fri, 22 Jun 2018 14:31:06 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fWN5c-0007pz-7i for linux-arm-kernel@bombadil.infradead.org; Fri, 22 Jun 2018 14:31:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=4uMQrO2sE6DSRJYFTBiAmHzGGHvoDvb1gzgD9Ji//WE=; b=kfzV5ZsoxhqOYt94MCd8DW1M1 rwqEz8fbVNjdwZt+IZvmzZNYQoBb4BgzOWwzm9RRgoGbeKJjEKUsI54kokMLKqVwPV2GDcqflahNH H+R0xP6lfWup3mUkgewtdKcQn95WUrDaZAHP9oiOP90xdocuHFW4qy6pQTXFYIpnpDKwMork68TNd cOCai6pcvYgUt+fT0kGZgJvygbyiEyFrt79iIPSnod4XwcJFk9K+PbN0ZHcX1YkiAehLVp4IqzjKu IpMdVyJxrj14z4wpoKj9l5tkLg9T0sVfqTgTpOW4FgRKnMl90mCUVtUQRNt1LDQ5QtYM1V/FdZz2K ZO63DclCQ==; Received: from mx3-rdu2.redhat.com ([66.187.233.73] helo=mx1.redhat.com) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fWMxj-0004L5-Fd for linux-arm-kernel@lists.infradead.org; Fri, 22 Jun 2018 14:22:57 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4BAB74023132; Fri, 22 Jun 2018 14:22:30 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.43.2.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B2161C722; Fri, 22 Jun 2018 14:22:29 +0000 (UTC) From: Andrew Jones To: linux-arm-kernel@lists.infradead.org Subject: [PATCH RFC] arm64: acpi: reenumerate topology ids Date: Fri, 22 Jun 2018 16:22:28 +0200 Message-Id: <20180622142228.19645-1-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 22 Jun 2018 14:22:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 22 Jun 2018 14:22:30 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'drjones@redhat.com' RCPT:'' X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180622_152255_692577_D238BF99 X-CRM114-Status: GOOD ( 17.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sudeep.holla@arm.com, jeremy.linton@arm.com, ard.biesheuvel@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When booting with devicetree, and the devicetree has the cpu-map node, the topology IDs that are visible from sysfs are generated with counters. ACPI, on the other hand, uses ACPI table pointer offsets, which, while guaranteed to be unique, look a bit weird. Instead, we can generate DT identical topology IDs for ACPI by just using counters for the leaf nodes and by remapping the non-leaf table pointer offsets to counters. Cc: Jeremy Linton Signed-off-by: Andrew Jones --- arch/arm64/kernel/topology.c | 68 ++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index f845a8617812..4c6aa9eec3d3 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -316,6 +316,10 @@ static void __init reset_cpu_topology(void) } #ifdef CONFIG_ACPI + +#define acpi_topology_mktag(id) (-((id) + 1)) +#define acpi_topology_istag(id) ((id) < 0) + /* * Propagate the topology information of the processor_topology_node tree to the * cpu_topology array. @@ -323,27 +327,24 @@ static void __init reset_cpu_topology(void) static int __init parse_acpi_topology(void) { bool is_threaded; - int cpu, topology_id; + int package_id = 0, core_id, thread_id; + int cpu, ret; is_threaded = read_cpuid_mpidr() & MPIDR_MT_BITMASK; for_each_possible_cpu(cpu) { int i, cache_id; - topology_id = find_acpi_cpu_topology(cpu, 0); - if (topology_id < 0) - return topology_id; + ret = find_acpi_cpu_topology(cpu, 0); + if (ret < 0) + return ret; - if (is_threaded) { - cpu_topology[cpu].thread_id = topology_id; - topology_id = find_acpi_cpu_topology(cpu, 1); - cpu_topology[cpu].core_id = topology_id; - } else { - cpu_topology[cpu].thread_id = -1; - cpu_topology[cpu].core_id = topology_id; - } - topology_id = find_acpi_cpu_topology_package(cpu); - cpu_topology[cpu].package_id = topology_id; + if (is_threaded) + ret = find_acpi_cpu_topology(cpu, 1); + cpu_topology[cpu].core_id = acpi_topology_mktag(ret); + + ret = find_acpi_cpu_topology_package(cpu); + cpu_topology[cpu].package_id = acpi_topology_mktag(ret); i = acpi_find_last_cache_level(cpu); @@ -358,6 +359,45 @@ static int __init parse_acpi_topology(void) } } + for_each_possible_cpu(cpu) { + int tag, cpu2; + + if (is_threaded) { + if (acpi_topology_istag(cpu_topology[cpu].core_id)) + thread_id = 0; + cpu_topology[cpu].thread_id = thread_id; + ++thread_id; + } else { + cpu_topology[cpu].thread_id = -1; + } + + if (acpi_topology_istag(cpu_topology[cpu].core_id)) { + if (acpi_topology_istag(cpu_topology[cpu].package_id)) + core_id = 0; + tag = cpu_topology[cpu].core_id; + cpu_topology[cpu].core_id = core_id; + + if (is_threaded) { + for_each_possible_cpu(cpu2) { + if (cpu_topology[cpu2].core_id == tag) + cpu_topology[cpu2].core_id = core_id; + } + } + ++core_id; + } + + if (acpi_topology_istag(cpu_topology[cpu].package_id)) { + tag = cpu_topology[cpu].package_id; + cpu_topology[cpu].package_id = package_id; + + for_each_possible_cpu(cpu2) { + if (cpu_topology[cpu2].package_id == tag) + cpu_topology[cpu2].package_id = package_id; + } + ++package_id; + } + } + return 0; }