From: jeremy.linton@arm.com (Jeremy Linton)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v5 6/9] ACPI/PPTT: Add topology parsing code
Date: Fri, 1 Dec 2017 16:23:27 -0600 [thread overview]
Message-ID: <20171201222330.18863-7-jeremy.linton@arm.com> (raw)
In-Reply-To: <20171201222330.18863-1-jeremy.linton@arm.com>
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 <jeremy.linton@arm.com>
---
drivers/acpi/pptt.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 115 insertions(+)
diff --git a/drivers/acpi/pptt.c b/drivers/acpi/pptt.c
index a35e457cefb7..b9b7b8b8ad21 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);
+}
--
2.13.5
next prev parent reply other threads:[~2017-12-01 22:23 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-01 22:23 [PATCH v5 0/9] Support PPTT for ARM64 Jeremy Linton
2017-12-01 22:23 ` [PATCH v5 1/9] arm64/acpi: Create arch specific cpu to acpi id helper Jeremy Linton
2017-12-01 22:23 ` [PATCH v5 2/9] ACPI/PPTT: Add Processor Properties Topology Table parsing Jeremy Linton
2017-12-12 1:10 ` Rafael J. Wysocki
2017-12-01 22:23 ` [PATCH v5 3/9] ACPI: Enable PPTT support on ARM64 Jeremy Linton
2017-12-13 17:26 ` Lorenzo Pieralisi
2018-01-05 21:58 ` Jeremy Linton
2018-01-05 22:07 ` Rafael J. Wysocki
2017-12-01 22:23 ` [PATCH v5 4/9] drivers: base cacheinfo: Add support for ACPI based firmware tables Jeremy Linton
2017-12-12 1:11 ` Rafael J. Wysocki
2017-12-12 17:03 ` Jeremy Linton
2017-12-12 17:25 ` Rafael J. Wysocki
2017-12-12 22:55 ` Jeremy Linton
2017-12-12 23:02 ` Rafael J. Wysocki
2017-12-12 23:37 ` Jeremy Linton
2017-12-12 23:41 ` Rafael J. Wysocki
2018-01-03 14:21 ` Sudeep Holla
2018-01-04 11:46 ` Sudeep Holla
2017-12-01 22:23 ` [PATCH v5 5/9] arm64: " Jeremy Linton
2017-12-01 22:23 ` Jeremy Linton [this message]
2017-12-12 1:12 ` [PATCH v5 6/9] ACPI/PPTT: Add topology parsing code Rafael J. Wysocki
2017-12-12 16:13 ` Jeremy Linton
2017-12-13 17:38 ` Lorenzo Pieralisi
2017-12-13 22:28 ` Rafael J. Wysocki
2017-12-13 23:06 ` Jeremy Linton
2017-12-13 23:09 ` Rafael J. Wysocki
2018-01-03 8:49 ` vkilari at codeaurora.org
2018-01-03 16:57 ` Jeremy Linton
2018-01-04 6:48 ` vkilari at codeaurora.org
2018-01-04 17:50 ` Jeremy Linton
2017-12-01 22:23 ` [PATCH v5 7/9] arm64: Topology, rename cluster_id Jeremy Linton
2017-12-13 18:02 ` Lorenzo Pieralisi
2017-12-15 16:36 ` Jeremy Linton
2017-12-18 12:42 ` Morten Rasmussen
2017-12-18 15:47 ` Lorenzo Pieralisi
2017-12-19 9:38 ` Morten Rasmussen
2018-01-02 2:29 ` Xiongfeng Wang
2018-01-02 11:30 ` Morten Rasmussen
2018-01-03 14:29 ` Sudeep Holla
2018-01-03 17:32 ` Jeremy Linton
2018-01-03 17:43 ` Sudeep Holla
2018-01-04 3:59 ` Xiongfeng Wang
2018-01-04 18:00 ` Jeremy Linton
2018-01-04 4:14 ` Xiongfeng Wang
2017-12-01 22:23 ` [PATCH v5 8/9] arm64: topology: Enable ACPI/PPTT based CPU topology Jeremy Linton
2017-12-13 18:22 ` Lorenzo Pieralisi
2017-12-15 17:42 ` Jeremy Linton
2017-12-01 22:23 ` [PATCH v5 9/9] ACPI: Add PPTT to injectable table list Jeremy Linton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171201222330.18863-7-jeremy.linton@arm.com \
--to=jeremy.linton@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).