2006-05-16 23:36:50 +02:00
|
|
|
/*
|
2015-09-30 18:14:19 +02:00
|
|
|
* Copyright (c) 2010-2012,2015 ARM Limited
|
2013-10-15 20:22:44 +02:00
|
|
|
* Copyright (c) 2013 Advanced Micro Devices, Inc.
|
2010-06-02 19:58:12 +02:00
|
|
|
* All rights reserved
|
|
|
|
*
|
|
|
|
* The license below extends only to copyright in the software and shall
|
|
|
|
* not be construed as granting a license to any other intellectual
|
|
|
|
* property including but not limited to intellectual property relating
|
|
|
|
* to a hardware implementation of the functionality of the software
|
|
|
|
* licensed hereunder. You may use the software subject to the license
|
|
|
|
* terms below provided that you ensure that this notice is replicated
|
|
|
|
* unmodified and in its entirety in all distributions of the software,
|
|
|
|
* modified or unmodified, in source code or in binary form.
|
|
|
|
*
|
2006-05-16 23:36:50 +02:00
|
|
|
* Copyright (c) 2002-2005 The Regents of The University of Michigan
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2006-06-01 01:26:56 +02:00
|
|
|
*
|
|
|
|
* Authors: Steve Reinhardt
|
2006-05-16 23:36:50 +02:00
|
|
|
*/
|
|
|
|
|
2011-11-01 12:01:13 +01:00
|
|
|
#include "arch/kernel_stats.hh"
|
|
|
|
#include "arch/stacktrace.hh"
|
|
|
|
#include "arch/tlb.hh"
|
2009-05-17 23:34:52 +02:00
|
|
|
#include "arch/utility.hh"
|
2011-11-01 12:01:13 +01:00
|
|
|
#include "arch/vtophys.hh"
|
2011-04-15 19:44:06 +02:00
|
|
|
#include "base/loader/symtab.hh"
|
2009-02-27 01:29:17 +01:00
|
|
|
#include "base/cp_annotate.hh"
|
2009-05-17 23:34:52 +02:00
|
|
|
#include "base/cprintf.hh"
|
2006-05-16 23:36:50 +02:00
|
|
|
#include "base/inifile.hh"
|
|
|
|
#include "base/misc.hh"
|
|
|
|
#include "base/pollevent.hh"
|
|
|
|
#include "base/trace.hh"
|
2009-05-17 23:34:52 +02:00
|
|
|
#include "base/types.hh"
|
2009-09-23 17:34:21 +02:00
|
|
|
#include "config/the_isa.hh"
|
2011-04-15 19:44:06 +02:00
|
|
|
#include "cpu/simple/base.hh"
|
2006-05-16 23:36:50 +02:00
|
|
|
#include "cpu/base.hh"
|
2012-03-09 15:59:27 +01:00
|
|
|
#include "cpu/checker/cpu.hh"
|
|
|
|
#include "cpu/checker/thread_context.hh"
|
2006-05-16 23:36:50 +02:00
|
|
|
#include "cpu/exetrace.hh"
|
2014-02-09 20:49:28 +01:00
|
|
|
#include "cpu/pred/bpred_unit.hh"
|
2006-05-16 23:36:50 +02:00
|
|
|
#include "cpu/profile.hh"
|
2015-09-30 18:14:19 +02:00
|
|
|
#include "cpu/simple/exec_context.hh"
|
2006-06-07 21:29:53 +02:00
|
|
|
#include "cpu/simple_thread.hh"
|
2006-05-16 23:36:50 +02:00
|
|
|
#include "cpu/smt.hh"
|
|
|
|
#include "cpu/static_inst.hh"
|
2006-06-07 21:29:53 +02:00
|
|
|
#include "cpu/thread_context.hh"
|
2011-04-15 19:44:32 +02:00
|
|
|
#include "debug/Decode.hh"
|
|
|
|
#include "debug/Fetch.hh"
|
|
|
|
#include "debug/Quiesce.hh"
|
2011-11-01 12:01:13 +01:00
|
|
|
#include "mem/mem_object.hh"
|
2006-10-20 08:38:45 +02:00
|
|
|
#include "mem/packet.hh"
|
2009-04-21 03:54:02 +02:00
|
|
|
#include "mem/request.hh"
|
2009-05-17 23:34:52 +02:00
|
|
|
#include "params/BaseSimpleCPU.hh"
|
2006-06-07 21:29:53 +02:00
|
|
|
#include "sim/byteswap.hh"
|
2006-05-16 23:36:50 +02:00
|
|
|
#include "sim/debug.hh"
|
2012-02-07 13:43:21 +01:00
|
|
|
#include "sim/faults.hh"
|
2011-11-18 10:33:28 +01:00
|
|
|
#include "sim/full_system.hh"
|
2006-05-16 23:36:50 +02:00
|
|
|
#include "sim/sim_events.hh"
|
|
|
|
#include "sim/sim_object.hh"
|
|
|
|
#include "sim/stats.hh"
|
2006-07-13 02:22:07 +02:00
|
|
|
#include "sim/system.hh"
|
2006-05-16 23:36:50 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace TheISA;
|
|
|
|
|
2008-08-11 21:22:16 +02:00
|
|
|
BaseSimpleCPU::BaseSimpleCPU(BaseSimpleCPUParams *p)
|
2014-02-09 20:49:28 +01:00
|
|
|
: BaseCPU(p),
|
2015-09-30 18:14:19 +02:00
|
|
|
curThread(0),
|
2014-02-09 20:49:28 +01:00
|
|
|
branchPred(p->branchPred),
|
2015-09-30 18:14:19 +02:00
|
|
|
traceData(NULL),
|
|
|
|
inst(),
|
|
|
|
_status(Idle)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
2015-09-30 18:14:19 +02:00
|
|
|
SimpleThread *thread;
|
2006-06-05 04:13:42 +02:00
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
for (unsigned i = 0; i < numThreads; i++) {
|
|
|
|
if (FullSystem) {
|
|
|
|
thread = new SimpleThread(this, i, p->system,
|
|
|
|
p->itb, p->dtb, p->isa[i]);
|
|
|
|
} else {
|
|
|
|
thread = new SimpleThread(this, i, p->system, p->workload[i],
|
|
|
|
p->itb, p->dtb, p->isa[i]);
|
|
|
|
}
|
|
|
|
threadInfo.push_back(new SimpleExecContext(this, thread));
|
|
|
|
ThreadContext *tc = thread->getTC();
|
|
|
|
threadContexts.push_back(tc);
|
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
|
2012-01-31 16:46:03 +01:00
|
|
|
if (p->checker) {
|
2015-09-30 18:14:19 +02:00
|
|
|
if (numThreads != 1)
|
|
|
|
fatal("Checker currently does not support SMT");
|
|
|
|
|
2012-01-31 16:46:03 +01:00
|
|
|
BaseCPU *temp_checker = p->checker;
|
|
|
|
checker = dynamic_cast<CheckerCPU *>(temp_checker);
|
|
|
|
checker->setSystem(p->system);
|
|
|
|
// Manipulate thread context
|
2015-09-30 18:14:19 +02:00
|
|
|
ThreadContext *cpu_tc = threadContexts[0];
|
|
|
|
threadContexts[0] = new CheckerThreadContext<ThreadContext>(cpu_tc, this->checker);
|
2012-01-31 16:46:03 +01:00
|
|
|
} else {
|
|
|
|
checker = NULL;
|
|
|
|
}
|
2015-09-30 18:14:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BaseSimpleCPU::init()
|
|
|
|
{
|
|
|
|
BaseCPU::init();
|
|
|
|
|
|
|
|
for (auto tc : threadContexts) {
|
|
|
|
// Initialise the ThreadContext's memory proxies
|
|
|
|
tc->initMemProxies(tc);
|
|
|
|
|
|
|
|
if (FullSystem && !params()->switched_out) {
|
|
|
|
// initialize CPU, including PC
|
|
|
|
TheISA::initCPU(tc, tc->contextId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BaseSimpleCPU::checkPcEventQueue()
|
|
|
|
{
|
|
|
|
Addr oldpc, pc = threadInfo[curThread]->thread->instAddr();
|
|
|
|
do {
|
|
|
|
oldpc = pc;
|
|
|
|
system->pcEventQueue.service(threadContexts[curThread]);
|
|
|
|
pc = threadInfo[curThread]->thread->instAddr();
|
|
|
|
} while (oldpc != pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BaseSimpleCPU::swapActiveThread()
|
|
|
|
{
|
|
|
|
if (numThreads > 1) {
|
|
|
|
if ((!curStaticInst || !curStaticInst->isDelayedCommit()) &&
|
|
|
|
!threadInfo[curThread]->stayAtPC) {
|
|
|
|
// Swap active threads
|
|
|
|
if (!activeThreads.empty()) {
|
|
|
|
curThread = activeThreads.front();
|
|
|
|
activeThreads.pop_front();
|
|
|
|
activeThreads.push_back(curThread);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BaseSimpleCPU::countInst()
|
|
|
|
{
|
|
|
|
SimpleExecContext& t_info = *threadInfo[curThread];
|
|
|
|
|
|
|
|
if (!curStaticInst->isMicroop() || curStaticInst->isLastMicroop()) {
|
|
|
|
t_info.numInst++;
|
|
|
|
t_info.numInsts++;
|
|
|
|
}
|
|
|
|
t_info.numOp++;
|
|
|
|
t_info.numOps++;
|
2012-01-31 16:46:03 +01:00
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
system->totalNumInsts++;
|
|
|
|
t_info.thread->funcExeInst++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Counter
|
|
|
|
BaseSimpleCPU::totalInsts() const
|
|
|
|
{
|
|
|
|
Counter total_inst = 0;
|
|
|
|
for (auto& t_info : threadInfo) {
|
|
|
|
total_inst += t_info->numInst;
|
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
return total_inst;
|
|
|
|
}
|
2007-05-18 19:42:50 +02:00
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
Counter
|
|
|
|
BaseSimpleCPU::totalOps() const
|
|
|
|
{
|
|
|
|
Counter total_op = 0;
|
|
|
|
for (auto& t_info : threadInfo) {
|
|
|
|
total_op += t_info->numOp;
|
|
|
|
}
|
2007-10-18 19:15:08 +02:00
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
return total_op;
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BaseSimpleCPU::~BaseSimpleCPU()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-01-31 18:05:52 +01:00
|
|
|
BaseSimpleCPU::haltContext(ThreadID thread_num)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
|
|
|
// for now, these are equivalent
|
|
|
|
suspendContext(thread_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
BaseSimpleCPU::regStats()
|
|
|
|
{
|
|
|
|
using namespace Stats;
|
|
|
|
|
|
|
|
BaseCPU::regStats();
|
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
for (ThreadID tid = 0; tid < numThreads; tid++) {
|
|
|
|
SimpleExecContext& t_info = *threadInfo[tid];
|
|
|
|
|
|
|
|
std::string thread_str = name();
|
|
|
|
if (numThreads > 1)
|
|
|
|
thread_str += ".thread" + std::to_string(tid);
|
|
|
|
|
|
|
|
t_info.numInsts
|
|
|
|
.name(thread_str + ".committedInsts")
|
|
|
|
.desc("Number of instructions committed")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numOps
|
|
|
|
.name(thread_str + ".committedOps")
|
|
|
|
.desc("Number of ops (including micro ops) committed")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numIntAluAccesses
|
|
|
|
.name(thread_str + ".num_int_alu_accesses")
|
|
|
|
.desc("Number of integer alu accesses")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numFpAluAccesses
|
|
|
|
.name(thread_str + ".num_fp_alu_accesses")
|
|
|
|
.desc("Number of float alu accesses")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numCallsReturns
|
|
|
|
.name(thread_str + ".num_func_calls")
|
|
|
|
.desc("number of times a function call or return occured")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numCondCtrlInsts
|
|
|
|
.name(thread_str + ".num_conditional_control_insts")
|
|
|
|
.desc("number of instructions that are conditional controls")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numIntInsts
|
|
|
|
.name(thread_str + ".num_int_insts")
|
|
|
|
.desc("number of integer instructions")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numFpInsts
|
|
|
|
.name(thread_str + ".num_fp_insts")
|
|
|
|
.desc("number of float instructions")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numIntRegReads
|
|
|
|
.name(thread_str + ".num_int_register_reads")
|
|
|
|
.desc("number of times the integer registers were read")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numIntRegWrites
|
|
|
|
.name(thread_str + ".num_int_register_writes")
|
|
|
|
.desc("number of times the integer registers were written")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numFpRegReads
|
|
|
|
.name(thread_str + ".num_fp_register_reads")
|
|
|
|
.desc("number of times the floating registers were read")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numFpRegWrites
|
|
|
|
.name(thread_str + ".num_fp_register_writes")
|
|
|
|
.desc("number of times the floating registers were written")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numCCRegReads
|
|
|
|
.name(thread_str + ".num_cc_register_reads")
|
|
|
|
.desc("number of times the CC registers were read")
|
|
|
|
.flags(nozero)
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numCCRegWrites
|
|
|
|
.name(thread_str + ".num_cc_register_writes")
|
|
|
|
.desc("number of times the CC registers were written")
|
|
|
|
.flags(nozero)
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numMemRefs
|
|
|
|
.name(thread_str + ".num_mem_refs")
|
|
|
|
.desc("number of memory refs")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numStoreInsts
|
|
|
|
.name(thread_str + ".num_store_insts")
|
|
|
|
.desc("Number of store instructions")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numLoadInsts
|
|
|
|
.name(thread_str + ".num_load_insts")
|
|
|
|
.desc("Number of load instructions")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.notIdleFraction
|
|
|
|
.name(thread_str + ".not_idle_fraction")
|
|
|
|
.desc("Percentage of non-idle cycles")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.idleFraction
|
|
|
|
.name(thread_str + ".idle_fraction")
|
|
|
|
.desc("Percentage of idle cycles")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numBusyCycles
|
|
|
|
.name(thread_str + ".num_busy_cycles")
|
|
|
|
.desc("Number of busy cycles")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.numIdleCycles
|
|
|
|
.name(thread_str + ".num_idle_cycles")
|
|
|
|
.desc("Number of idle cycles")
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.icacheStallCycles
|
|
|
|
.name(thread_str + ".icache_stall_cycles")
|
|
|
|
.desc("ICache total stall cycles")
|
|
|
|
.prereq(t_info.icacheStallCycles)
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.dcacheStallCycles
|
|
|
|
.name(thread_str + ".dcache_stall_cycles")
|
|
|
|
.desc("DCache total stall cycles")
|
|
|
|
.prereq(t_info.dcacheStallCycles)
|
|
|
|
;
|
|
|
|
|
|
|
|
t_info.statExecutedInstType
|
|
|
|
.init(Enums::Num_OpClass)
|
|
|
|
.name(thread_str + ".op_class")
|
|
|
|
.desc("Class of executed instruction")
|
|
|
|
.flags(total | pdf | dist)
|
|
|
|
;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < Num_OpClasses; ++i) {
|
|
|
|
t_info.statExecutedInstType.subname(i, Enums::OpClassStrings[i]);
|
|
|
|
}
|
2014-05-10 00:58:47 +02:00
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.idleFraction = constant(1.0) - t_info.notIdleFraction;
|
|
|
|
t_info.numIdleCycles = t_info.idleFraction * numCycles;
|
|
|
|
t_info.numBusyCycles = t_info.notIdleFraction * numCycles;
|
2014-02-09 20:49:28 +01:00
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.numBranches
|
|
|
|
.name(thread_str + ".Branches")
|
|
|
|
.desc("Number of branches fetched")
|
|
|
|
.prereq(t_info.numBranches);
|
2014-02-09 20:49:28 +01:00
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.numPredictedBranches
|
|
|
|
.name(thread_str + ".predictedBranches")
|
|
|
|
.desc("Number of branches predicted as taken")
|
|
|
|
.prereq(t_info.numPredictedBranches);
|
2014-02-09 20:49:28 +01:00
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.numBranchMispred
|
|
|
|
.name(thread_str + ".BranchMispred")
|
|
|
|
.desc("Number of branch mispredictions")
|
|
|
|
.prereq(t_info.numBranchMispred);
|
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BaseSimpleCPU::resetStats()
|
|
|
|
{
|
2015-09-30 18:14:19 +02:00
|
|
|
for (auto &thread_info : threadInfo) {
|
|
|
|
thread_info->notIdleFraction = (_status != Idle);
|
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-07-07 10:51:03 +02:00
|
|
|
BaseSimpleCPU::serializeThread(CheckpointOut &cp, ThreadID tid) const
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
2013-01-07 19:05:52 +01:00
|
|
|
assert(_status == Idle || _status == Running);
|
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
threadInfo[tid]->thread->serialize(cp);
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-07-07 10:51:03 +02:00
|
|
|
BaseSimpleCPU::unserializeThread(CheckpointIn &cp, ThreadID tid)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
2015-09-30 18:14:19 +02:00
|
|
|
threadInfo[tid]->thread->unserialize(cp);
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-26 18:23:13 +02:00
|
|
|
change_thread_state(ThreadID tid, int activate, int priority)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Addr
|
|
|
|
BaseSimpleCPU::dbg_vtophys(Addr addr)
|
|
|
|
{
|
2015-09-30 18:14:19 +02:00
|
|
|
return vtophys(threadContexts[curThread], addr);
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-24 16:27:21 +01:00
|
|
|
BaseSimpleCPU::wakeup()
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
2015-09-30 18:14:19 +02:00
|
|
|
for (ThreadID tid = 0; tid < numThreads; tid++) {
|
2015-09-30 18:14:19 +02:00
|
|
|
getCpuAddrMonitor(tid)->gotWakeup = true;
|
2015-09-30 18:14:19 +02:00
|
|
|
if (threadInfo[tid]->thread->status() == ThreadContext::Suspended) {
|
|
|
|
DPRINTF(Quiesce,"Suspended Processor awoke\n");
|
|
|
|
threadInfo[tid]->thread->activate();
|
|
|
|
}
|
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BaseSimpleCPU::checkForInterrupts()
|
|
|
|
{
|
2015-09-30 18:14:19 +02:00
|
|
|
SimpleExecContext&t_info = *threadInfo[curThread];
|
|
|
|
SimpleThread* thread = t_info.thread;
|
|
|
|
ThreadContext* tc = thread->getTC();
|
|
|
|
|
2008-10-21 16:12:53 +02:00
|
|
|
if (checkInterrupts(tc)) {
|
2008-10-12 18:09:56 +02:00
|
|
|
Fault interrupt = interrupts->getInterrupt(tc);
|
2006-05-16 23:36:50 +02:00
|
|
|
|
2006-11-03 08:25:39 +01:00
|
|
|
if (interrupt != NoFault) {
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.fetchOffset = 0;
|
2008-10-12 18:09:56 +02:00
|
|
|
interrupts->updateIntrInfo(tc);
|
2006-11-03 08:25:39 +01:00
|
|
|
interrupt->invoke(tc);
|
2012-05-26 22:44:46 +02:00
|
|
|
thread->decoder.reset();
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-25 19:16:15 +01:00
|
|
|
void
|
2006-05-31 04:30:42 +02:00
|
|
|
BaseSimpleCPU::setupFetchRequest(Request *req)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
2015-09-30 18:14:19 +02:00
|
|
|
SimpleExecContext &t_info = *threadInfo[curThread];
|
|
|
|
SimpleThread* thread = t_info.thread;
|
|
|
|
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
Addr instAddr = thread->instAddr();
|
2007-05-31 22:01:41 +02:00
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
// set up memory request for instruction fetch
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
DPRINTF(Fetch, "Fetch: PC:%08p\n", instAddr);
|
2006-05-16 23:36:50 +02:00
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
Addr fetchPC = (instAddr & PCMask) + t_info.fetchOffset;
|
2012-02-12 23:07:38 +01:00
|
|
|
req->setVirt(0, fetchPC, sizeof(MachInst), Request::INST_FETCH, instMasterId(),
|
|
|
|
instAddr);
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
BaseSimpleCPU::preExecute()
|
|
|
|
{
|
2015-09-30 18:14:19 +02:00
|
|
|
SimpleExecContext &t_info = *threadInfo[curThread];
|
|
|
|
SimpleThread* thread = t_info.thread;
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
// maintain $r0 semantics
|
2006-06-07 21:29:53 +02:00
|
|
|
thread->setIntReg(ZeroReg, 0);
|
2006-05-16 23:36:50 +02:00
|
|
|
#if THE_ISA == ALPHA_ISA
|
2006-06-07 21:29:53 +02:00
|
|
|
thread->setFloatReg(ZeroReg, 0.0);
|
2006-05-16 23:36:50 +02:00
|
|
|
#endif // ALPHA_ISA
|
|
|
|
|
|
|
|
// check for instruction-count-based events
|
2015-09-30 18:14:19 +02:00
|
|
|
comInstEventQueue[curThread]->serviceEvents(t_info.numInst);
|
2011-02-07 07:14:17 +01:00
|
|
|
system->instEventQueue.serviceEvents(system->totalNumInsts);
|
2006-05-16 23:36:50 +02:00
|
|
|
|
|
|
|
// decode the instruction
|
|
|
|
inst = gtoh(inst);
|
2007-05-18 19:42:50 +02:00
|
|
|
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
TheISA::PCState pcState = thread->pcState();
|
2007-05-18 19:42:50 +02:00
|
|
|
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
if (isRomMicroPC(pcState.microPC())) {
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.stayAtPC = false;
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
curStaticInst = microcodeRom.fetchMicroop(pcState.microPC(),
|
|
|
|
curMacroStaticInst);
|
2008-10-13 01:59:55 +02:00
|
|
|
} else if (!curMacroStaticInst) {
|
|
|
|
//We're not in the middle of a macro instruction
|
2007-03-13 17:13:21 +01:00
|
|
|
StaticInstPtr instPtr = NULL;
|
|
|
|
|
2012-05-26 22:44:46 +02:00
|
|
|
TheISA::Decoder *decoder = &(thread->decoder);
|
|
|
|
|
2007-03-13 17:13:21 +01:00
|
|
|
//Predecode, ie bundle up an ExtMachInst
|
2007-03-15 03:47:42 +01:00
|
|
|
//If more fetch data is needed, pass it in.
|
2015-09-30 18:14:19 +02:00
|
|
|
Addr fetchPC = (pcState.instAddr() & PCMask) + t_info.fetchOffset;
|
2012-05-26 22:44:46 +02:00
|
|
|
//if(decoder->needMoreBytes())
|
|
|
|
decoder->moreBytes(pcState, fetchPC, inst);
|
2007-06-19 20:17:34 +02:00
|
|
|
//else
|
2012-05-26 22:44:46 +02:00
|
|
|
// decoder->process();
|
2007-05-18 19:42:50 +02:00
|
|
|
|
2012-05-26 22:44:46 +02:00
|
|
|
//Decode an instruction if one is ready. Otherwise, we'll have to
|
2007-05-18 19:42:50 +02:00
|
|
|
//fetch beyond the MachInst at the current pc.
|
2012-05-26 22:44:46 +02:00
|
|
|
instPtr = decoder->decode(pcState);
|
|
|
|
if (instPtr) {
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.stayAtPC = false;
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
thread->pcState(pcState);
|
2007-05-18 19:42:50 +02:00
|
|
|
} else {
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.stayAtPC = true;
|
|
|
|
t_info.fetchOffset += sizeof(MachInst);
|
2007-05-18 19:42:50 +02:00
|
|
|
}
|
2007-03-13 17:13:21 +01:00
|
|
|
|
|
|
|
//If we decoded an instruction and it's microcoded, start pulling
|
|
|
|
//out micro ops
|
2007-06-12 18:21:47 +02:00
|
|
|
if (instPtr && instPtr->isMacroop()) {
|
2006-10-16 03:04:14 +02:00
|
|
|
curMacroStaticInst = instPtr;
|
2015-09-30 18:14:19 +02:00
|
|
|
curStaticInst =
|
|
|
|
curMacroStaticInst->fetchMicroop(pcState.microPC());
|
2006-10-16 21:56:46 +02:00
|
|
|
} else {
|
|
|
|
curStaticInst = instPtr;
|
2006-10-16 03:04:14 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//Read the next micro op from the macro op
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
curStaticInst = curMacroStaticInst->fetchMicroop(pcState.microPC());
|
2006-10-16 03:04:14 +02:00
|
|
|
}
|
|
|
|
|
2007-03-13 17:13:21 +01:00
|
|
|
//If we decoded an instruction this "tick", record information about it.
|
2012-04-15 21:35:49 +02:00
|
|
|
if (curStaticInst) {
|
2007-06-04 21:53:04 +02:00
|
|
|
#if TRACING_ON
|
2015-09-30 18:14:19 +02:00
|
|
|
traceData = tracer->getInstRecord(curTick(), thread->getTC(),
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
curStaticInst, thread->pcState(), curMacroStaticInst);
|
2006-05-16 23:36:50 +02:00
|
|
|
|
2012-04-15 21:35:49 +02:00
|
|
|
DPRINTF(Decode,"Decode: Decoded %s instruction: %#x\n",
|
2007-03-13 17:13:21 +01:00
|
|
|
curStaticInst->getName(), curStaticInst->machInst);
|
2007-06-04 21:53:04 +02:00
|
|
|
#endif // TRACING_ON
|
2007-03-13 17:13:21 +01:00
|
|
|
}
|
2014-02-09 20:49:28 +01:00
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
if (branchPred && curStaticInst &&
|
|
|
|
curStaticInst->isControl()) {
|
2014-02-09 20:49:28 +01:00
|
|
|
// Use a fake sequence number since we only have one
|
|
|
|
// instruction in flight at the same time.
|
|
|
|
const InstSeqNum cur_sn(0);
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.predPC = thread->pcState();
|
2014-02-09 20:49:28 +01:00
|
|
|
const bool predict_taken(
|
2015-09-30 18:14:19 +02:00
|
|
|
branchPred->predict(curStaticInst, cur_sn, t_info.predPC,
|
|
|
|
curThread));
|
2014-02-09 20:49:28 +01:00
|
|
|
|
|
|
|
if (predict_taken)
|
2015-09-30 18:14:19 +02:00
|
|
|
++t_info.numPredictedBranches;
|
2014-02-09 20:49:28 +01:00
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BaseSimpleCPU::postExecute()
|
|
|
|
{
|
2015-09-30 18:14:19 +02:00
|
|
|
SimpleExecContext &t_info = *threadInfo[curThread];
|
|
|
|
SimpleThread* thread = t_info.thread;
|
|
|
|
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
assert(curStaticInst);
|
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
TheISA::PCState pc = threadContexts[curThread]->pcState();
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
Addr instAddr = pc.instAddr();
|
2011-11-01 12:01:14 +01:00
|
|
|
if (FullSystem && thread->profile) {
|
2015-09-30 18:14:19 +02:00
|
|
|
bool usermode = TheISA::inUserMode(threadContexts[curThread]);
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
thread->profilePC = usermode ? 1 : instAddr;
|
2015-09-30 18:14:19 +02:00
|
|
|
ProfileNode *node = thread->profile->consume(threadContexts[curThread],
|
|
|
|
curStaticInst);
|
2006-05-16 23:36:50 +02:00
|
|
|
if (node)
|
2006-06-07 21:29:53 +02:00
|
|
|
thread->profileNode = node;
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (curStaticInst->isMemRef()) {
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.numMemRefs++;
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (curStaticInst->isLoad()) {
|
2015-09-30 18:14:19 +02:00
|
|
|
++t_info.numLoad;
|
|
|
|
comLoadEventQueue[curThread]->serviceEvents(t_info.numLoad);
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
2009-02-27 01:29:17 +01:00
|
|
|
if (CPA::available()) {
|
2015-09-30 18:14:19 +02:00
|
|
|
CPA::cpa()->swAutoBegin(threadContexts[curThread], pc.nextInstAddr());
|
2009-02-27 01:29:17 +01:00
|
|
|
}
|
|
|
|
|
2014-02-09 20:49:28 +01:00
|
|
|
if (curStaticInst->isControl()) {
|
2015-09-30 18:14:19 +02:00
|
|
|
++t_info.numBranches;
|
2014-02-09 20:49:28 +01:00
|
|
|
}
|
|
|
|
|
2011-02-07 07:14:17 +01:00
|
|
|
/* Power model statistics */
|
|
|
|
//integer alu accesses
|
|
|
|
if (curStaticInst->isInteger()){
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.numIntAluAccesses++;
|
|
|
|
t_info.numIntInsts++;
|
2011-02-07 07:14:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//float alu accesses
|
|
|
|
if (curStaticInst->isFloating()){
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.numFpAluAccesses++;
|
|
|
|
t_info.numFpInsts++;
|
2011-02-07 07:14:17 +01:00
|
|
|
}
|
2015-09-30 18:14:19 +02:00
|
|
|
|
2011-02-07 07:14:17 +01:00
|
|
|
//number of function calls/returns to get window accesses
|
|
|
|
if (curStaticInst->isCall() || curStaticInst->isReturn()){
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.numCallsReturns++;
|
2011-02-07 07:14:17 +01:00
|
|
|
}
|
2015-09-30 18:14:19 +02:00
|
|
|
|
2011-02-07 07:14:17 +01:00
|
|
|
//the number of branch predictions that will be made
|
|
|
|
if (curStaticInst->isCondCtrl()){
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.numCondCtrlInsts++;
|
2011-02-07 07:14:17 +01:00
|
|
|
}
|
2015-09-30 18:14:19 +02:00
|
|
|
|
2011-02-07 07:14:17 +01:00
|
|
|
//result bus acceses
|
|
|
|
if (curStaticInst->isLoad()){
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.numLoadInsts++;
|
2011-02-07 07:14:17 +01:00
|
|
|
}
|
2015-09-30 18:14:19 +02:00
|
|
|
|
2011-02-07 07:14:17 +01:00
|
|
|
if (curStaticInst->isStore()){
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.numStoreInsts++;
|
2011-02-07 07:14:17 +01:00
|
|
|
}
|
|
|
|
/* End power model statistics */
|
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.statExecutedInstType[curStaticInst->opClass()]++;
|
2014-05-10 00:58:47 +02:00
|
|
|
|
2011-11-01 12:01:14 +01:00
|
|
|
if (FullSystem)
|
|
|
|
traceFunctions(instAddr);
|
2006-05-26 20:33:43 +02:00
|
|
|
|
|
|
|
if (traceData) {
|
2007-02-11 00:14:50 +01:00
|
|
|
traceData->dump();
|
|
|
|
delete traceData;
|
|
|
|
traceData = NULL;
|
2006-05-26 20:33:43 +02:00
|
|
|
}
|
2014-10-16 11:49:41 +02:00
|
|
|
|
|
|
|
// Call CPU instruction commit probes
|
|
|
|
probeInstCommit(curStaticInst);
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-19 16:35:18 +02:00
|
|
|
BaseSimpleCPU::advancePC(const Fault &fault)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
2015-09-30 18:14:19 +02:00
|
|
|
SimpleExecContext &t_info = *threadInfo[curThread];
|
|
|
|
SimpleThread* thread = t_info.thread;
|
|
|
|
|
2014-02-09 20:49:28 +01:00
|
|
|
const bool branching(thread->pcState().branching());
|
|
|
|
|
2007-05-18 19:42:50 +02:00
|
|
|
//Since we're moving to a new pc, zero out the offset
|
2015-09-30 18:14:19 +02:00
|
|
|
t_info.fetchOffset = 0;
|
2006-05-16 23:36:50 +02:00
|
|
|
if (fault != NoFault) {
|
2007-01-17 01:12:33 +01:00
|
|
|
curMacroStaticInst = StaticInst::nullStaticInstPtr;
|
2015-09-30 18:14:19 +02:00
|
|
|
fault->invoke(threadContexts[curThread], curStaticInst);
|
2012-05-26 22:44:46 +02:00
|
|
|
thread->decoder.reset();
|
2007-05-18 19:42:50 +02:00
|
|
|
} else {
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
if (curStaticInst) {
|
|
|
|
if (curStaticInst->isLastMicroop())
|
|
|
|
curMacroStaticInst = StaticInst::nullStaticInstPtr;
|
|
|
|
TheISA::PCState pcState = thread->pcState();
|
|
|
|
TheISA::advancePC(pcState, curStaticInst);
|
|
|
|
thread->pcState(pcState);
|
2006-10-16 03:04:14 +02:00
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
2014-02-09 20:49:28 +01:00
|
|
|
|
|
|
|
if (branchPred && curStaticInst && curStaticInst->isControl()) {
|
|
|
|
// Use a fake sequence number since we only have one
|
|
|
|
// instruction in flight at the same time.
|
|
|
|
const InstSeqNum cur_sn(0);
|
|
|
|
|
2015-09-30 18:14:19 +02:00
|
|
|
if (t_info.predPC == thread->pcState()) {
|
2014-02-09 20:49:28 +01:00
|
|
|
// Correctly predicted branch
|
2015-09-30 18:14:19 +02:00
|
|
|
branchPred->update(cur_sn, curThread);
|
2014-02-09 20:49:28 +01:00
|
|
|
} else {
|
|
|
|
// Mis-predicted branch
|
2015-09-30 18:14:19 +02:00
|
|
|
branchPred->squash(cur_sn, thread->pcState(), branching, curThread);
|
|
|
|
++t_info.numBranchMispred;
|
2014-02-09 20:49:28 +01:00
|
|
|
}
|
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
2013-01-13 05:09:48 +01:00
|
|
|
void
|
|
|
|
BaseSimpleCPU::startup()
|
|
|
|
{
|
|
|
|
BaseCPU::startup();
|
2015-09-30 18:14:19 +02:00
|
|
|
for (auto& t_info : threadInfo)
|
|
|
|
t_info->thread->startup();
|
2013-01-13 05:09:48 +01:00
|
|
|
}
|