arch-arm: Rewrite getMPIDR
authorAdrian Herrera <adrian.herrera@arm.com>
Tue, 10 Dec 2019 17:21:18 +0000 (17:21 +0000)
committerGiacomo Travaglini <giacomo.travaglini@arm.com>
Thu, 12 Mar 2020 14:28:22 +0000 (14:28 +0000)
This patch is rewriting getMPIDR to have a more canonical form:

* Using threadId() instead of contextId()

It is also splitting the helper so that a client can get an affinity
number given a specific thread context.

Change-Id: I727e4b96ada345fd548cd3ff9423bf27347812c4
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/26304
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Ciro Santilli <ciro.santilli@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Maintainer: Giacomo Travaglini <giacomo.travaglini@arm.com>

src/arch/arm/utility.cc
src/arch/arm/utility.hh

index 373508cee394e3594b76f24e18fc9742c3342af8..8f81a3486a646643681c98c745e2f4fcc323caeb 100644 (file)
@@ -263,18 +263,42 @@ getMPIDR(ArmSystem *arm_sys, ThreadContext *tc)
     // for simulation of larger systems
     assert((0 <= tc->cpuId()) && (tc->cpuId() < 256));
     assert(tc->socketId() < 65536);
-    if (arm_sys->multiThread) {
-       return 0x80000000 | // multiprocessor extensions available
-              0x01000000 | // multi-threaded cores
-              tc->contextId();
-    } else if (arm_sys->multiProc) {
-       return 0x80000000 | // multiprocessor extensions available
-              tc->cpuId() | tc->socketId() << 8;
-    } else {
-       return 0x80000000 |  // multiprocessor extensions available
-              0x40000000 |  // in up system
-              tc->cpuId() | tc->socketId() << 8;
-    }
+
+    RegVal mpidr = 0x80000000;
+
+    if (!arm_sys->multiProc)
+        replaceBits(mpidr, 30, 1);
+
+    if (arm_sys->multiThread)
+        replaceBits(mpidr, 24, 1);
+
+    // Get Affinity numbers
+    mpidr |= getAffinity(arm_sys, tc);
+    return mpidr;
+}
+
+static RegVal
+getAff2(ArmSystem *arm_sys, ThreadContext *tc)
+{
+    return arm_sys->multiThread ? tc->socketId() << 16 : 0;
+}
+
+static RegVal
+getAff1(ArmSystem *arm_sys, ThreadContext *tc)
+{
+    return arm_sys->multiThread ? tc->cpuId() << 8 : tc->socketId() << 8;
+}
+
+static RegVal
+getAff0(ArmSystem *arm_sys, ThreadContext *tc)
+{
+    return arm_sys->multiThread ? tc->threadId() : tc->cpuId();
+}
+
+RegVal
+getAffinity(ArmSystem *arm_sys, ThreadContext *tc)
+{
+    return getAff2(arm_sys, tc) | getAff1(arm_sys, tc) | getAff0(arm_sys, tc);
 }
 
 bool
index 409ceed90d883aab402ee736a922b5705adc0e25..3d64bdd133aa9cb9966a71438efb4b56bc0a19f8 100644 (file)
@@ -256,9 +256,12 @@ bool longDescFormatInUse(ThreadContext *tc);
  * to VMPIDR_EL2 (as it happens in virtualized systems) */
 RegVal readMPIDR(ArmSystem *arm_sys, ThreadContext *tc);
 
-/** This helper function is returing the value of MPIDR_EL1 */
+/** This helper function is returning the value of MPIDR_EL1 */
 RegVal getMPIDR(ArmSystem *arm_sys, ThreadContext *tc);
 
+/** Retrieves MPIDR_EL1.{Aff2,Aff1,Aff0} affinity numbers */
+RegVal getAffinity(ArmSystem *arm_sys, ThreadContext *tc);
+
 static inline uint32_t
 mcrMrcIssBuild(bool isRead, uint32_t crm, IntRegIndex rt, uint32_t crn,
                uint32_t opc1, uint32_t opc2)