From patchwork Sat Jan 13 00:59:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Linton X-Patchwork-Id: 124397 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp71882qgn; Fri, 12 Jan 2018 17:01:00 -0800 (PST) X-Google-Smtp-Source: ACJfBos6WlVRaPQGZkI0QSpYHp/S8HczshZUlwDcnAlva7OcDzXDHvKxKzSR1T3qOPHePPrVXgAN X-Received: by 10.84.240.12 with SMTP id y12mr27459144plk.382.1515805260839; Fri, 12 Jan 2018 17:01:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515805260; cv=none; d=google.com; s=arc-20160816; b=qLsb3j1W57zMYRb17h7kQO+BFI7dairZCZPD9PhS5ZYQsHRS9pbK/S9Kk+2xr9Wpto UeL983rOPVe4xpOhpjwW5SI/3kw+p5lvc/PF9yGl+z+aJE5Yt0vgUqy9GjRTQL4BcnUA OKKdpgBbPErrutJ5Szy/ckqqvXsnNscqGgT+8VZ/y8IP0Nb1N6qJUe1x7BGP+tFdbwm5 aWc8OBrebYwZ9CnQOu05lvw1Zhd1+1w+kcmhmmANe5TFZnfIbCp07vMs3doONOM0iKb2 joJv27syHLPLoRGWZpFnCM/lCOfN/187uMxbpG6yJWN5ktStbanuamjzhRQScpwtP7jQ Kpdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=7RJuWeiCjhqkFbnVAVXnxUpFG0CWw8INrIjIGZoSp/c=; b=u12CmJ4yov5xIv60fb6oaZJD9KAY56oxdT1cwSFaIYHiVkj5cgCQ4DNIEazOmMZQl8 og1kCYZ2Yczz+LvFkh9CnfvOa7rQlVlEmiROF3vE11/mXqUAfmzWptVW3duR5IazSyqA 4bS1YKsWTjAqRHLLU1KEZ8HoYMhRUS2Ol7NNZqis03kQ/iML9COaOD1eg2I/05F1yDl5 RN1lrR1XQL/8wZa8fXbXCtNcd7nSMj49uZTPuKq7uE0cnoKsV/M/hnvoqd3z5SB/zME+ 96ZmqMFFX6h39ZWKw1bZfmtxH871m8PqKHh7CcNz9uDo7MG8hLIh3SDVxGQgOoi4Nw4b c4xQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v85si3309345pgb.353.2018.01.12.17.01.00; Fri, 12 Jan 2018 17:01:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965554AbeAMBA4 (ORCPT + 28 others); Fri, 12 Jan 2018 20:00:56 -0500 Received: from foss.arm.com ([217.140.101.70]:53922 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965523AbeAMBAy (ORCPT ); Fri, 12 Jan 2018 20:00:54 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8498D1610; Fri, 12 Jan 2018 17:00:53 -0800 (PST) Received: from beelzebub.austin.arm.com (beelzebub.austin.arm.com [10.118.12.119]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8DAC93F487; Fri, 12 Jan 2018 17:00:52 -0800 (PST) From: Jeremy Linton To: linux-acpi@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, sudeep.holla@arm.com, hanjun.guo@linaro.org, lorenzo.pieralisi@arm.com, rjw@rjwysocki.net, will.deacon@arm.com, catalin.marinas@arm.com, gregkh@linuxfoundation.org, viresh.kumar@linaro.org, mark.rutland@arm.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, jhugo@codeaurora.org, wangxiongfeng2@huawei.com, Jonathan.Zhang@cavium.com, ahs3@redhat.com, Jayachandran.Nair@cavium.com, austinwc@codeaurora.org, lenb@kernel.org, vkilari@codeaurora.org, morten.rasmussen@arm.com, Jeremy Linton Subject: [PATCH v6 09/12] ACPI/PPTT: Add topology parsing code Date: Fri, 12 Jan 2018 18:59:17 -0600 Message-Id: <20180113005920.28658-10-jeremy.linton@arm.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20180113005920.28658-1-jeremy.linton@arm.com> References: <20180113005920.28658-1-jeremy.linton@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The PPTT can be used to determine the groupings of CPU's at given levels in the system. Lets add a few routines to the PPTT parsing code to return a unique id for each unique level in the processor hierarchy. This can then be matched to build thread/core/cluster/die/package/etc mappings for each processing element in the system. Signed-off-by: Jeremy Linton --- drivers/acpi/pptt.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 3 ++ 2 files changed, 118 insertions(+) -- 2.13.5 diff --git a/drivers/acpi/pptt.c b/drivers/acpi/pptt.c index 4f5ab19c3a08..83d89d683f16 100644 --- a/drivers/acpi/pptt.c +++ b/drivers/acpi/pptt.c @@ -412,6 +412,79 @@ static void cache_setup_acpi_cpu(struct acpi_table_header *table, } } +/* Passing level values greater than this will result in search termination */ +#define PPTT_ABORT_PACKAGE 0xFF + +/* + * Given an acpi_pptt_processor node, walk up until we identify the + * package that the node is associated with, or we run out of levels + * to request or the search is terminated with a flag match + * The level parameter also serves to limit possible loops within the tree. + */ +static struct acpi_pptt_processor *acpi_find_processor_package_id( + struct acpi_table_header *table_hdr, + struct acpi_pptt_processor *cpu, + int level, int flag) +{ + struct acpi_pptt_processor *prev_node; + + while (cpu && level) { + if (cpu->flags & flag) + break; + pr_debug("level %d\n", level); + prev_node = fetch_pptt_node(table_hdr, cpu->parent); + if (prev_node == NULL) + break; + cpu = prev_node; + level--; + } + return cpu; +} + +/* + * Get a unique value given a cpu, and a topology level, that can be + * matched to determine which cpus share common topological features + * at that level. + */ +static int topology_get_acpi_cpu_tag(struct acpi_table_header *table, + unsigned int cpu, int level, int flag) +{ + struct acpi_pptt_processor *cpu_node; + u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu); + + cpu_node = acpi_find_processor_node(table, acpi_cpu_id); + if (cpu_node) { + cpu_node = acpi_find_processor_package_id(table, cpu_node, + level, flag); + /* Only the first level has a guaranteed id */ + if (level == 0) + return cpu_node->acpi_processor_id; + return (int)((u8 *)cpu_node - (u8 *)table); + } + pr_err_once("PPTT table found, but unable to locate core for %d\n", + cpu); + return -ENOENT; +} + +static int find_acpi_cpu_topology_tag(unsigned int cpu, int level, int flag) +{ + struct acpi_table_header *table; + acpi_status status; + int retval; + + status = acpi_get_table(ACPI_SIG_PPTT, 0, &table); + if (ACPI_FAILURE(status)) { + pr_err_once("No PPTT table found, cpu topology may be inaccurate\n"); + return -ENOENT; + } + retval = topology_get_acpi_cpu_tag(table, cpu, level, flag); + pr_debug("Topology Setup ACPI cpu %d, level %d ret = %d\n", + cpu, level, retval); + acpi_put_table(table); + + return retval; +} + /** * acpi_find_last_cache_level() - Determines the number of cache levels for a PE * @cpu: Kernel logical cpu number @@ -475,3 +548,45 @@ int cache_setup_acpi(unsigned int cpu) return status; } + +/** + * find_acpi_cpu_topology() - Determine a unique topology value for a given cpu + * @cpu: Kernel logical cpu number + * @level: The topological level for which we would like a unique ID + * + * Determine a topology unique ID for each thread/core/cluster/mc_grouping + * /socket/etc. This ID can then be used to group peers, which will have + * matching ids. + * + * The search terminates when either the requested level is found or + * we reach a root node. Levels beyond the termination point will return the + * same unique ID. The unique id for level 0 is the acpi processor id. All + * other levels beyond this use a generated value to uniquely identify + * a topological feature. + * + * Return: -ENOENT if the PPTT doesn't exist, or the cpu cannot be found. + * Otherwise returns a value which represents a unique topological feature. + */ +int find_acpi_cpu_topology(unsigned int cpu, int level) +{ + return find_acpi_cpu_topology_tag(cpu, level, 0); +} + +/** + * find_acpi_cpu_topology_package() - Determine a unique cpu package value + * @cpu: Kernel logical cpu number + * + * Determine a topology unique package ID for the given cpu. + * This ID can then be used to group peers, which will have matching ids. + * + * The search terminates when either a level is found with the PHYSICAL_PACKAGE + * flag set or we reach a root node. + * + * Return: -ENOENT if the PPTT doesn't exist, or the cpu cannot be found. + * Otherwise returns a value which represents the package for this cpu. + */ +int find_acpi_cpu_topology_package(unsigned int cpu) +{ + return find_acpi_cpu_topology_tag(cpu, PPTT_ABORT_PACKAGE, + ACPI_PPTT_PHYSICAL_PACKAGE); +} diff --git a/include/linux/acpi.h b/include/linux/acpi.h index dc1ebfeeb5ec..117d13934487 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1266,4 +1266,7 @@ static inline int lpit_read_residency_count_address(u64 *address) } #endif +int find_acpi_cpu_topology(unsigned int cpu, int level); +int find_acpi_cpu_topology_package(unsigned int cpu); + #endif /*_LINUX_ACPI_H*/