From patchwork Thu Jun 28 14:51: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: 10494205 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 46A086022E for ; Thu, 28 Jun 2018 15:04:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C7202A481 for ; Thu, 28 Jun 2018 15:04:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F0BC2A485; Thu, 28 Jun 2018 15:04:38 +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=unavailable 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 17D542A3B8 for ; Thu, 28 Jun 2018 15:04:36 +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=Wn2VWyXwKaYhXgVgA36qZINDwO4MmUb6YCmc86GutXU=; b=CVg kyG2WXJ3zF8TbO/ggoZ3mSUk8MKYKzykFC6bjIWC9QaDNg035a/du5uZMF1RYis/5M6CP579nMdcy dREZsQMwoi7D8sF5i8ugDABFDpMt5ReIMkIYfwDpE4oWlnT0BpfdOXMrZlLxF44BO4n0j8rdpJbVR iUVoVeThmAMriH8QQNvogU29WU8jhVQfYoKIi9ljEhVCz0hvKrPFD95hgP2VKWVPEDIx5ZukIi+EM KGHSZkiOm8f52GOXernlwre5TQ4b/gwJ4KEhtY/9MLW+Zs8E+NGYXJfLnPxWfUaU92iBoshKmjfmI xyFJELN4GeRVUOdYLlgKzBKQibTZ63w==; 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 1fYYTE-0006gY-EC; Thu, 28 Jun 2018 15:04:28 +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 1fYYTC-0006QA-Nh for linux-arm-kernel@bombadil.infradead.org; Thu, 28 Jun 2018 15:04:26 +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=kmrm7wALXjyoZ3Rx6lyefr2bhPqa73IyYcUYBxXqrRQ=; b=T5ALoH0yMzk6gRNIMaaTWvxwu q2IwXwdy9m/20em4FDCzvMD4b7QPtylg22r2+iFx7ZZN85xrOzCQPuAJgYnl3yCZo6FL/+mp/yYwp fkDvAw6I4/RxXjq1hJNph3nHKFMnmLyt7as60zd5fhxIjXs2Yk43dEHqo+ssCjLKhdVfqHKRDrija tiXdyojhMt1bdhIbh+aUvdbuTwocxb5snvuCRS81pjXlghjVFu5no1Um2tdkOunL78kKHBL7HoCze 1ukMgCFAyEUEa4msIC5YNwXv6NPh5OLjjr7IrzuG8uOyfYdLBdvaZYOtLOPebF4o2NDVC7ott++QO CYL+o6Kow==; 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 1fYYH6-0006ok-Js for linux-arm-kernel@lists.infradead.org; Thu, 28 Jun 2018 14:51:58 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 334204076063; Thu, 28 Jun 2018 14:51:31 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.43.2.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 982CB111CD33; Thu, 28 Jun 2018 14:51:29 +0000 (UTC) From: Andrew Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] arm64: acpi: reenumerate topology ids Date: Thu, 28 Jun 2018 16:51:28 +0200 Message-Id: <20180628145128.10057-1-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 28 Jun 2018 14:51:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 28 Jun 2018 14:51:31 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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-20180628_155156_822512_BB92A9D0 X-CRM114-Status: GOOD ( 21.45 ) 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: shunyong.yang@hxt-semitech.com, ard.biesheuvel@linaro.org, catalin.marinas@arm.com, will.deacon@arm.com, jeremy.linton@arm.com, sudeep.holla@arm.com, yu.zheng@hxt-semitech.com 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 Cc: Sudeep Holla Signed-off-by: Andrew Jones --- v1: Reworked this since the RFC in order to make the algorithm more obvious. It wasn't clear in the RFC that the ACPI nodes could be in any order, although they could have been. I've tested that this works with nodes in arbitrary order by hacking the QEMU PPTT table generator[*]. Note, while this produces equivalent topology IDs to what the DT cpu-map node produces for all sane configs, if PEs are threads (have MPIDR.MT set), but the cpu-map does not specify threads, then, while the DT parsing code will happily call the threads "cores", ACPI will see that the PPTT leaf nodes are for threads and produce different topology IDs. I see this difference as a bug with the DT parsing which can be addressed separately. [*] https://github.com/rhdrjones/qemu/commits/virt-cpu-topology arch/arm64/kernel/topology.c | 70 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 15 deletions(-) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index f845a8617812..7ef457401b24 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(x) (-((x) + 1)) +#define acpi_topology_istag(x) ((x) < 0) + /* * Propagate the topology information of the processor_topology_node tree to the * cpu_topology array. @@ -323,27 +327,31 @@ 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; + int cpu, ret; is_threaded = read_cpuid_mpidr() & MPIDR_MT_BITMASK; + /* + * Loop through all PEs twice. In the first loop store parent + * tags into the IDs. In the second loop we reset the IDs as + * 0..N-1 per parent tag. + */ + for_each_possible_cpu(cpu) { int i, cache_id; - topology_id = find_acpi_cpu_topology(cpu, 0); - if (topology_id < 0) - return topology_id; - - 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; + ret = find_acpi_cpu_topology(cpu, 0); + if (ret < 0) + return ret; + + if (is_threaded) + ret = find_acpi_cpu_topology(cpu, 1); + else + cpu_topology[cpu].thread_id = -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 +366,38 @@ static int __init parse_acpi_topology(void) } } + for_each_possible_cpu(cpu) { + int package_tag = cpu_topology[cpu].package_id; + int core_id = 0, cpu2; + + if (!acpi_topology_istag(package_tag)) + continue; + + for_each_possible_cpu(cpu2) { + if (cpu_topology[cpu2].package_id != package_tag) + continue; + + if (is_threaded) { + int core_tag = cpu_topology[cpu2].core_id; + int thread_id = 0, cpu3; + + for_each_possible_cpu(cpu3) { + if (cpu_topology[cpu3].core_id != core_tag) + continue; + + cpu_topology[cpu3].thread_id = thread_id++; + cpu_topology[cpu3].core_id = core_id; + cpu_topology[cpu3].package_id = package_id; + } + ++core_id; + } else { + cpu_topology[cpu2].core_id = core_id++; + cpu_topology[cpu2].package_id = package_id; + } + } + ++package_id; + } + return 0; }