From: Zi Shen Lim <zlim@broadcom.com>
To: Catalin Marinas <catalin.marinas@arm.com>,
Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
Mark Brown <broonie@linaro.org>,
Mark Rutland <mark.rutland@arm.com>,
Will Deacon <will.deacon@arm.com>
Cc: <linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, Zi Shen Lim <zlim@broadcom.com>
Subject: [PATCH 2/2] arm64: topology: add MPIDR-based detection
Date: Tue, 22 Apr 2014 18:40:14 -0700 [thread overview]
Message-ID: <1398217214-12204-3-git-send-email-zlim@broadcom.com> (raw)
In-Reply-To: <1398217214-12204-1-git-send-email-zlim@broadcom.com>
Create cpu topology based on MPIDR. When hardware sets MPIDR to sane
values, this method will always work. Therefore it should also work well
as the fallback method. [1]
[1] http://www.spinics.net/lists/arm-kernel/msg317445.html
Signed-off-by: Zi Shen Lim <zlim@broadcom.com>
---
arch/arm64/include/asm/cputype.h | 2 ++
arch/arm64/kernel/topology.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h
index c404fb0..7639e8b 100644
--- a/arch/arm64/include/asm/cputype.h
+++ b/arch/arm64/include/asm/cputype.h
@@ -18,6 +18,8 @@
#define INVALID_HWID ULONG_MAX
+#define MPIDR_UP_BITMASK (0x1 << 30)
+#define MPIDR_MT_BITMASK (0x1 << 24)
#define MPIDR_HWID_BITMASK 0xff00ffffff
#define MPIDR_LEVEL_BITS_SHIFT 3
diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
index 3e06b0b..ef3bb7e 100644
--- a/arch/arm64/kernel/topology.c
+++ b/arch/arm64/kernel/topology.c
@@ -19,6 +19,7 @@
#include <linux/nodemask.h>
#include <linux/sched.h>
+#include <asm/cputype.h>
#include <asm/topology.h>
/*
@@ -71,6 +72,36 @@ static void update_siblings_masks(unsigned int cpuid)
void store_cpu_topology(unsigned int cpuid)
{
+ struct cpu_topology *cpuid_topo = &cpu_topology[cpuid];
+ u64 mpidr;
+
+ mpidr = read_cpuid_mpidr();
+
+ /* Create cpu topology mapping based on MPIDR. */
+ if (mpidr & MPIDR_UP_BITMASK) {
+ /* Uniprocessor system */
+ cpuid_topo->thread_id = -1;
+ cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
+ cpuid_topo->cluster_id = -1;
+ } else {
+ /* Multiprocessor system */
+ if (mpidr & MPIDR_MT_BITMASK) {
+ /* Multi-threads per core */
+ cpuid_topo->thread_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
+ cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 1);
+ cpuid_topo->cluster_id = MPIDR_AFFINITY_LEVEL(mpidr, 2);
+ } else {
+ /* Single-thread per core */
+ cpuid_topo->thread_id = -1;
+ cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
+ cpuid_topo->cluster_id = MPIDR_AFFINITY_LEVEL(mpidr, 1);
+ }
+ }
+
+ pr_info("CPU%u: cluster %d core %d thread %d mpidr %llx\n",
+ cpuid, cpuid_topo->cluster_id, cpuid_topo->core_id,
+ cpuid_topo->thread_id, mpidr);
+
update_siblings_masks(cpuid);
}
--
1.8.4.3
next prev parent reply other threads:[~2014-04-23 1:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-23 1:40 [PATCH 0/2] arm64 topology updates Zi Shen Lim
2014-04-23 1:40 ` [PATCH 1/2] arm64, sched: Remove unused mc_capable() and smt_capable() Zi Shen Lim
2014-04-24 18:32 ` Mark Brown
2014-04-23 1:40 ` Zi Shen Lim [this message]
2014-04-23 10:36 ` [PATCH 2/2] arm64: topology: add MPIDR-based detection Mark Brown
2014-04-23 17:27 ` Zi Shen Lim
2014-04-23 18:26 ` Mark Brown
2014-04-23 19:22 ` Zi Shen Lim
2014-04-23 22:38 ` Mark Brown
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=1398217214-12204-3-git-send-email-zlim@broadcom.com \
--to=zlim@broadcom.com \
--cc=broonie@linaro.org \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=mark.rutland@arm.com \
--cc=will.deacon@arm.com \
/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
all inboxes | Powered by JetHome®