From 8cfa988335cec1e1f166fe9b37d489d0d743ced3 Mon Sep 17 00:00:00 2001 From: Adrian Herrera Date: Tue, 10 Dec 2019 17:21:18 +0000 Subject: [PATCH] arch-arm: Rewrite getMPIDR 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 Reviewed-by: Ciro Santilli Tested-by: kokoro Maintainer: Giacomo Travaglini --- src/arch/arm/utility.cc | 48 ++++++++++++++++++++++++++++++----------- src/arch/arm/utility.hh | 5 ++++- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/arch/arm/utility.cc b/src/arch/arm/utility.cc index 373508cee..8f81a3486 100644 --- a/src/arch/arm/utility.cc +++ b/src/arch/arm/utility.cc @@ -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 diff --git a/src/arch/arm/utility.hh b/src/arch/arm/utility.hh index 409ceed90..3d64bdd13 100644 --- a/src/arch/arm/utility.hh +++ b/src/arch/arm/utility.hh @@ -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) -- 2.30.2