From patchwork Thu Jun 28 09:18:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shunyong Yang X-Patchwork-Id: 10493379 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 8C98060325 for ; Thu, 28 Jun 2018 09:23:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7957A29E29 for ; Thu, 28 Jun 2018 09:23:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C02829E37; Thu, 28 Jun 2018 09:23:42 +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 1311429E29 for ; Thu, 28 Jun 2018 09:23:42 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=UTkNr6DiI41gY8nrQsZtZMLpgcKMJXGerHt7egHxpfY=; b=m1KXeEiUAWbeJw hp4k6F/Y4UpnvG0Xi30Pq2GgbHHXz1yXo+vcsF3fpoeuuHYavRNJ+eG2Jb0hKPXz7wcyYgAde4fzB s9k7Btjkd7Nh8WZbi4huze4kDZoykHI8sW/l4iGcu4i3DSQnqWUUcHOat6o7NmpKOfhj8Rnwh/D7M mUEg2tZpUm/008cESzNFAAcIxsA2pmX/ZA5qJSvVwz+hfUAePsb2J/90NLe+C2A/dqca3UGV+jLSb jdQe5Fr9rKeKuBU7nv1X5eZMM0ZY6tea/0zMyJXoWxkU7BkzI036UzXblavMFRUCxqvOz/OGbIyXl TN4Uky3SN96Q/DsfRPWA==; 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 1fYT9J-0004jS-RF; Thu, 28 Jun 2018 09:23:33 +0000 Received: from [223.203.96.7] (helo=barracuda.hxt-semitech.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fYT9B-0004Xe-Sw for linux-arm-kernel@lists.infradead.org; Thu, 28 Jun 2018 09:23:31 +0000 X-ASG-Debug-ID: 1530177766-093b7e43b2a5720001-tbGyMd Received: from HXTBJIDCEMVIW01.hxtcorp.net (localhost [10.128.0.14]) by barracuda.hxt-semitech.com with ESMTP id 0xeOAI1TKUxfpkVd (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 28 Jun 2018 17:22:46 +0800 (CST) X-Barracuda-Envelope-From: shunyong.yang@hxt-semitech.com Received: from y.localdomain (10.5.21.109) by HXTBJIDCEMVIW01.hxtcorp.net (10.128.0.14) with Microsoft SMTP Server (TLS) id 15.0.847.32; Thu, 28 Jun 2018 17:22:48 +0800 From: Shunyong Yang To: Subject: [RFC PATCH] arm64: topology: Map PPTT node offset to logic physical package id Date: Thu, 28 Jun 2018 17:18:28 +0800 X-ASG-Orig-Subj: [RFC PATCH] arm64: topology: Map PPTT node offset to logic physical package id Message-ID: <1530177508-15298-1-git-send-email-shunyong.yang@hxt-semitech.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.5.21.109] X-ClientProxiedBy: HXTBJIDCEMVIW01.hxtcorp.net (10.128.0.14) To HXTBJIDCEMVIW01.hxtcorp.net (10.128.0.14) X-Barracuda-Connect: localhost[10.128.0.14] X-Barracuda-Start-Time: 1530177766 X-Barracuda-Encrypted: ECDHE-RSA-AES256-SHA X-Barracuda-URL: https://192.168.50.101:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at hxt-semitech.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Bayes: INNOCENT GLOBAL 0.4965 1.0000 0.0000 X-Barracuda-Spam-Score: 1.20 X-Barracuda-Spam-Status: No, SCORE=1.20 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests=SORTED_RECIPS X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.52503 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 1.20 SORTED_RECIPS Recipient list is sorted by address X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180628_022326_352478_9AC10010 X-CRM114-Status: GOOD ( 10.86 ) 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 , will.deacon@arm.com, linux-kernel@vger.kernel.org, jeremy.linton@arm.com, Joey Zheng , linux-arm-kernel@lists.infradead.org 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 As PPTT spec doesn't define the physical package id, find_acpi_cpu_topology_package() will return offset of the node with Physical package field set when querying physical package id. So, it returns 162(0xA2) in following example. [0A2h 0162 1] Subtable Type : 00 [Processor Hierarchy Node] [0A3h 0163 1] Length : 1C [0A4h 0164 2] Reserved : 0000 [0A6h 0166 4] Flags (decoded below) : 00000003 Physical package : 1 ACPI Processor ID valid : 1 [0AAh 0170 4] Parent : 00000000 [0AEh 0174 4] ACPI Processor ID : 00001000 [0B2h 0178 4] Private Resource Number : 00000002 [0B6h 0182 4] Private Resource : 0000006C [0BAh 0186 4] Private Resource : 00000084 So, when "cat physical_package" in /sys/devices/system/cpu/cpu0/topology/, it will output 162(0xA2). And if some items are added before the node above, the output will change to other value. This patch maps the node offset to a logic package id. It maps the first node offset to 0, the second to 1, and so on. Then, it will not output a big value, such as 162 above. And it will not change when some nodes(Physical package not set) are added. And as long as the nodes with Physical package field set in PPTT keeps the real hardware order, the logic id can map to hardware package id to some extent. Hope to get feedback from you. Cc: Joey Zheng Signed-off-by: Shunyong Yang --- arch/arm64/kernel/topology.c | 53 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index f845a8617812..c219224b36e8 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -320,11 +320,59 @@ static void __init reset_cpu_topology(void) * Propagate the topology information of the processor_topology_node tree to the * cpu_topology array. */ + +struct package_id_map { + int topology_id; + int package_id; + struct list_head list; +}; + +static int map_package_id(int topology_id, int *max_package_id, + struct list_head *head) +{ + struct list_head *pos; + struct package_id_map *entry; + + list_for_each(pos, head) { + entry = container_of(pos, struct package_id_map, list); + if (entry->topology_id == topology_id) + goto done; + } + + /* topology_id not found in the list */ + entry = kzalloc(sizeof(*entry), GFP_KERNEL); + if (!entry) + return topology_id; + + entry->topology_id = topology_id; + entry->package_id = *max_package_id; + list_add(&entry->list, head); + *max_package_id = *max_package_id + 1; + +done: + return entry->package_id; +} + +static void destroy_map(struct list_head *head) +{ + struct package_id_map *entry; + struct list_head *pos, *q; + + list_for_each_safe(pos, q, head) { + entry = container_of(pos, struct package_id_map, list); + list_del(pos); + kfree(entry); + } +} + static int __init parse_acpi_topology(void) { bool is_threaded; int cpu, topology_id; + struct list_head package_id_list; + int max_package_id = 0; + INIT_LIST_HEAD(&package_id_list); is_threaded = read_cpuid_mpidr() & MPIDR_MT_BITMASK; for_each_possible_cpu(cpu) { @@ -343,7 +391,9 @@ static int __init parse_acpi_topology(void) cpu_topology[cpu].core_id = topology_id; } topology_id = find_acpi_cpu_topology_package(cpu); - cpu_topology[cpu].package_id = topology_id; + cpu_topology[cpu].package_id = map_package_id(topology_id, + &max_package_id, + &package_id_list); i = acpi_find_last_cache_level(cpu); @@ -358,6 +408,7 @@ static int __init parse_acpi_topology(void) } } + destroy_map(&package_id_list); return 0; }