2009-02-11 00:49:29 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 MIPS Technologies, Inc.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Authors: Korey Sewell
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-05-26 18:23:13 +02:00
|
|
|
#include <algorithm>
|
2009-04-18 01:54:58 +02:00
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
#include "arch/utility.hh"
|
2011-06-09 07:34:06 +02:00
|
|
|
#include "base/bigint.hh"
|
2009-05-26 18:23:13 +02:00
|
|
|
#include "config/full_system.hh"
|
2009-09-23 17:34:21 +02:00
|
|
|
#include "config/the_isa.hh"
|
2011-04-15 19:44:06 +02:00
|
|
|
#include "cpu/inorder/resources/resource_list.hh"
|
2009-02-11 00:49:29 +01:00
|
|
|
#include "cpu/inorder/cpu.hh"
|
|
|
|
#include "cpu/inorder/first_stage.hh"
|
2009-09-23 17:34:21 +02:00
|
|
|
#include "cpu/inorder/inorder_dyn_inst.hh"
|
|
|
|
#include "cpu/inorder/pipeline_traits.hh"
|
2009-02-11 00:49:29 +01:00
|
|
|
#include "cpu/inorder/resource_pool.hh"
|
2009-09-23 17:34:21 +02:00
|
|
|
#include "cpu/inorder/thread_context.hh"
|
|
|
|
#include "cpu/inorder/thread_state.hh"
|
2011-04-15 19:44:06 +02:00
|
|
|
#include "cpu/activity.hh"
|
|
|
|
#include "cpu/base.hh"
|
|
|
|
#include "cpu/exetrace.hh"
|
2009-09-23 17:34:21 +02:00
|
|
|
#include "cpu/simple_thread.hh"
|
|
|
|
#include "cpu/thread_context.hh"
|
2011-04-15 19:44:32 +02:00
|
|
|
#include "debug/Activity.hh"
|
|
|
|
#include "debug/InOrderCPU.hh"
|
|
|
|
#include "debug/RefCount.hh"
|
|
|
|
#include "debug/SkedCache.hh"
|
2011-06-20 03:43:41 +02:00
|
|
|
#include "debug/Quiesce.hh"
|
2009-02-11 00:49:29 +01:00
|
|
|
#include "mem/translating_port.hh"
|
2009-09-23 17:34:21 +02:00
|
|
|
#include "params/InOrderCPU.hh"
|
2009-02-11 00:49:29 +01:00
|
|
|
#include "sim/process.hh"
|
|
|
|
#include "sim/stat_control.hh"
|
|
|
|
|
2009-09-15 07:44:48 +02:00
|
|
|
#if FULL_SYSTEM
|
|
|
|
#include "cpu/quiesce_event.hh"
|
|
|
|
#include "sim/system.hh"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if THE_ISA == ALPHA_ISA
|
|
|
|
#include "arch/alpha/osfpal.hh"
|
|
|
|
#endif
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
using namespace std;
|
|
|
|
using namespace TheISA;
|
|
|
|
using namespace ThePipeline;
|
|
|
|
|
|
|
|
InOrderCPU::TickEvent::TickEvent(InOrderCPU *c)
|
|
|
|
: Event(CPU_Tick_Pri), cpu(c)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
InOrderCPU::TickEvent::process()
|
|
|
|
{
|
|
|
|
cpu->tick();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
InOrderCPU::TickEvent::description()
|
|
|
|
{
|
|
|
|
return "InOrderCPU tick event";
|
|
|
|
}
|
|
|
|
|
|
|
|
InOrderCPU::CPUEvent::CPUEvent(InOrderCPU *_cpu, CPUEventType e_type,
|
2010-02-01 00:26:26 +01:00
|
|
|
Fault fault, ThreadID _tid, DynInstPtr inst,
|
2011-06-20 03:43:36 +02:00
|
|
|
CPUEventPri event_pri)
|
|
|
|
: Event(event_pri), cpu(_cpu)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2010-02-01 00:26:03 +01:00
|
|
|
setEvent(e_type, fault, _tid, inst);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
2009-05-12 21:01:16 +02:00
|
|
|
|
|
|
|
std::string InOrderCPU::eventNames[NumCPUEvents] =
|
|
|
|
{
|
|
|
|
"ActivateThread",
|
2010-02-01 00:26:32 +01:00
|
|
|
"ActivateNextReadyThread",
|
|
|
|
"DeactivateThread",
|
2010-02-01 00:28:05 +01:00
|
|
|
"HaltThread",
|
2009-05-12 21:01:16 +02:00
|
|
|
"SuspendThread",
|
|
|
|
"Trap",
|
2011-06-20 03:43:38 +02:00
|
|
|
"Syscall",
|
2010-02-01 00:26:40 +01:00
|
|
|
"SquashFromMemStall",
|
2009-05-12 21:01:16 +02:00
|
|
|
"UpdatePCs"
|
|
|
|
};
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
void
|
|
|
|
InOrderCPU::CPUEvent::process()
|
|
|
|
{
|
|
|
|
switch (cpuEventType)
|
|
|
|
{
|
|
|
|
case ActivateThread:
|
|
|
|
cpu->activateThread(tid);
|
2011-06-20 03:43:38 +02:00
|
|
|
cpu->resPool->activateThread(tid);
|
2009-02-11 00:49:29 +01:00
|
|
|
break;
|
|
|
|
|
2010-02-01 00:26:32 +01:00
|
|
|
case ActivateNextReadyThread:
|
|
|
|
cpu->activateNextReadyThread();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DeactivateThread:
|
|
|
|
cpu->deactivateThread(tid);
|
2011-06-20 03:43:38 +02:00
|
|
|
cpu->resPool->deactivateThread(tid);
|
2010-02-01 00:26:32 +01:00
|
|
|
break;
|
|
|
|
|
2010-02-01 00:28:05 +01:00
|
|
|
case HaltThread:
|
|
|
|
cpu->haltThread(tid);
|
2011-06-20 03:43:38 +02:00
|
|
|
cpu->resPool->deactivateThread(tid);
|
2009-02-11 00:49:29 +01:00
|
|
|
break;
|
|
|
|
|
2010-02-01 00:26:40 +01:00
|
|
|
case SuspendThread:
|
|
|
|
cpu->suspendThread(tid);
|
2011-06-20 03:43:38 +02:00
|
|
|
cpu->resPool->suspendThread(tid);
|
2009-02-11 00:49:29 +01:00
|
|
|
break;
|
|
|
|
|
2010-02-01 00:26:13 +01:00
|
|
|
case SquashFromMemStall:
|
|
|
|
cpu->squashDueToMemStall(inst->squashingStage, inst->seqNum, tid);
|
2011-06-20 03:43:38 +02:00
|
|
|
cpu->resPool->squashDueToMemStall(inst, inst->squashingStage,
|
|
|
|
inst->seqNum, tid);
|
2010-02-01 00:26:13 +01:00
|
|
|
break;
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
case Trap:
|
2011-06-20 03:43:34 +02:00
|
|
|
DPRINTF(InOrderCPU, "Trapping CPU\n");
|
2011-06-20 03:43:36 +02:00
|
|
|
cpu->trap(fault, tid, inst);
|
|
|
|
cpu->resPool->trap(fault, tid, inst);
|
2011-06-20 03:43:41 +02:00
|
|
|
cpu->trapPending[tid] = false;
|
2009-02-11 00:49:29 +01:00
|
|
|
break;
|
|
|
|
|
2011-06-20 03:43:39 +02:00
|
|
|
#if !FULL_SYSTEM
|
2011-06-20 03:43:38 +02:00
|
|
|
case Syscall:
|
|
|
|
cpu->syscall(inst->syscallNum, tid);
|
|
|
|
cpu->resPool->trap(fault, tid, inst);
|
|
|
|
break;
|
2011-06-20 03:43:39 +02:00
|
|
|
#endif
|
2009-02-11 00:49:29 +01:00
|
|
|
default:
|
2010-02-01 00:28:05 +01:00
|
|
|
fatal("Unrecognized Event Type %s", eventNames[cpuEventType]);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
2010-01-31 23:18:15 +01:00
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
cpu->cpuEventRemoveList.push(this);
|
|
|
|
}
|
|
|
|
|
2010-01-31 23:18:15 +01:00
|
|
|
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
const char *
|
|
|
|
InOrderCPU::CPUEvent::description()
|
|
|
|
{
|
|
|
|
return "InOrderCPU event";
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InOrderCPU::CPUEvent::scheduleEvent(int delay)
|
|
|
|
{
|
2011-01-08 06:50:29 +01:00
|
|
|
assert(!scheduled() || squashed());
|
2011-01-08 06:50:29 +01:00
|
|
|
cpu->reschedule(this, cpu->nextCycle(curTick() + cpu->ticks(delay)), true);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InOrderCPU::CPUEvent::unscheduleEvent()
|
|
|
|
{
|
|
|
|
if (scheduled())
|
|
|
|
squash();
|
|
|
|
}
|
|
|
|
|
|
|
|
InOrderCPU::InOrderCPU(Params *params)
|
|
|
|
: BaseCPU(params),
|
|
|
|
cpu_id(params->cpu_id),
|
2009-03-05 04:37:45 +01:00
|
|
|
coreType("default"),
|
|
|
|
_status(Idle),
|
2009-02-11 00:49:29 +01:00
|
|
|
tickEvent(this),
|
2011-02-04 06:08:18 +01:00
|
|
|
stageWidth(params->stageWidth),
|
2009-02-11 00:49:29 +01:00
|
|
|
timeBuffer(2 , 2),
|
|
|
|
removeInstsThisCycle(false),
|
|
|
|
activityRec(params->name, NumStages, 10, params->activity),
|
2009-09-15 07:44:48 +02:00
|
|
|
#if FULL_SYSTEM
|
|
|
|
system(params->system),
|
|
|
|
#endif // FULL_SYSTEM
|
2010-01-31 23:18:15 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
cpuEventNum(0),
|
|
|
|
resReqCount(0),
|
|
|
|
#endif // DEBUG
|
2011-06-20 03:43:39 +02:00
|
|
|
drainCount(0),
|
2009-02-11 00:49:29 +01:00
|
|
|
deferRegistration(false/*params->deferRegistration*/),
|
2010-02-01 00:28:59 +01:00
|
|
|
stageTracing(params->stageTracing),
|
2011-06-20 03:43:38 +02:00
|
|
|
lastRunningCycle(0),
|
2010-02-01 00:28:59 +01:00
|
|
|
instsPerSwitch(0)
|
2010-02-01 00:25:13 +01:00
|
|
|
{
|
2009-09-15 07:44:48 +02:00
|
|
|
ThreadID active_threads;
|
2009-02-11 00:49:29 +01:00
|
|
|
cpu_params = params;
|
|
|
|
|
|
|
|
resPool = new ResourcePool(this, params);
|
|
|
|
|
|
|
|
// Resize for Multithreading CPUs
|
|
|
|
thread.resize(numThreads);
|
|
|
|
|
2009-09-15 07:44:48 +02:00
|
|
|
#if FULL_SYSTEM
|
|
|
|
active_threads = 1;
|
|
|
|
#else
|
|
|
|
active_threads = params->workload.size();
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
if (active_threads > MaxThreads) {
|
|
|
|
panic("Workload Size too large. Increase the 'MaxThreads'"
|
|
|
|
"in your InOrder implementation or "
|
|
|
|
"edit your workload size.");
|
|
|
|
}
|
2010-02-01 00:25:13 +01:00
|
|
|
|
2010-02-01 00:29:59 +01:00
|
|
|
|
2010-02-01 00:25:13 +01:00
|
|
|
if (active_threads > 1) {
|
|
|
|
threadModel = (InOrderCPU::ThreadModel) params->threadModel;
|
2010-02-01 00:26:32 +01:00
|
|
|
|
|
|
|
if (threadModel == SMT) {
|
|
|
|
DPRINTF(InOrderCPU, "Setting Thread Model to SMT.\n");
|
|
|
|
} else if (threadModel == SwitchOnCacheMiss) {
|
|
|
|
DPRINTF(InOrderCPU, "Setting Thread Model to "
|
|
|
|
"Switch On Cache Miss\n");
|
|
|
|
}
|
|
|
|
|
2010-02-01 00:25:13 +01:00
|
|
|
} else {
|
|
|
|
threadModel = Single;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-15 07:44:48 +02:00
|
|
|
#endif
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
// Bind the fetch & data ports from the resource pool.
|
|
|
|
fetchPortIdx = resPool->getPortIdx(params->fetchMemPort);
|
|
|
|
if (fetchPortIdx == 0) {
|
2009-05-12 21:01:13 +02:00
|
|
|
fatal("Unable to find port to fetch instructions from.\n");
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dataPortIdx = resPool->getPortIdx(params->dataMemPort);
|
|
|
|
if (dataPortIdx == 0) {
|
2009-05-12 21:01:13 +02:00
|
|
|
fatal("Unable to find port for data.\n");
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
2009-05-26 18:23:13 +02:00
|
|
|
for (ThreadID tid = 0; tid < numThreads; ++tid) {
|
2011-06-20 03:43:38 +02:00
|
|
|
pc[tid].set(0);
|
|
|
|
lastCommittedPC[tid].set(0);
|
|
|
|
|
2009-09-15 07:44:48 +02:00
|
|
|
#if FULL_SYSTEM
|
|
|
|
// SMT is not supported in FS mode yet.
|
2009-10-01 15:35:06 +02:00
|
|
|
assert(numThreads == 1);
|
2011-10-30 08:32:54 +01:00
|
|
|
thread[tid] = new Thread(this, 0, NULL);
|
2009-09-15 07:44:48 +02:00
|
|
|
#else
|
2009-06-05 08:21:12 +02:00
|
|
|
if (tid < (ThreadID)params->workload.size()) {
|
2009-03-04 19:17:08 +01:00
|
|
|
DPRINTF(InOrderCPU, "Workload[%i] process is %#x\n",
|
2009-10-01 15:35:06 +02:00
|
|
|
tid, params->workload[tid]->prog_fname);
|
|
|
|
thread[tid] =
|
2009-07-09 08:02:22 +02:00
|
|
|
new Thread(this, tid, params->workload[tid]);
|
2009-02-11 00:49:29 +01:00
|
|
|
} else {
|
|
|
|
//Allocate Empty thread so M5 can use later
|
|
|
|
//when scheduling threads to CPU
|
2009-03-04 19:17:08 +01:00
|
|
|
Process* dummy_proc = params->workload[0];
|
2009-10-01 15:35:06 +02:00
|
|
|
thread[tid] = new Thread(this, tid, dummy_proc);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
2010-02-01 00:29:59 +01:00
|
|
|
|
|
|
|
// Eventually set this with parameters...
|
|
|
|
asid[tid] = tid;
|
2009-09-15 07:44:48 +02:00
|
|
|
#endif
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
// Setup the TC that will serve as the interface to the threads/CPU.
|
|
|
|
InOrderThreadContext *tc = new InOrderThreadContext;
|
|
|
|
tc->cpu = this;
|
2009-05-26 18:23:13 +02:00
|
|
|
tc->thread = thread[tid];
|
2009-02-11 00:49:29 +01:00
|
|
|
|
2011-06-20 03:43:39 +02:00
|
|
|
#if FULL_SYSTEM
|
|
|
|
// Setup quiesce event.
|
|
|
|
this->thread[tid]->quiesceEvent = new EndQuiesceEvent(tc);
|
|
|
|
#endif
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
// Give the thread the TC.
|
2009-05-26 18:23:13 +02:00
|
|
|
thread[tid]->tc = tc;
|
|
|
|
thread[tid]->setFuncExeInst(0);
|
|
|
|
globalSeqNum[tid] = 1;
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
// Add the TC to the CPU's list of TC's.
|
|
|
|
this->threadContexts.push_back(tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize TimeBuffer Stage Queues
|
|
|
|
for (int stNum=0; stNum < NumStages - 1; stNum++) {
|
|
|
|
stageQueue[stNum] = new StageQueue(NumStages, NumStages);
|
2009-03-04 19:16:49 +01:00
|
|
|
stageQueue[stNum]->id(stNum);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set Up Pipeline Stages
|
|
|
|
for (int stNum=0; stNum < NumStages; stNum++) {
|
|
|
|
if (stNum == 0)
|
|
|
|
pipelineStage[stNum] = new FirstStage(params, stNum);
|
|
|
|
else
|
|
|
|
pipelineStage[stNum] = new PipelineStage(params, stNum);
|
|
|
|
|
|
|
|
pipelineStage[stNum]->setCPU(this);
|
|
|
|
pipelineStage[stNum]->setActiveThreads(&activeThreads);
|
|
|
|
pipelineStage[stNum]->setTimeBuffer(&timeBuffer);
|
|
|
|
|
|
|
|
// Take Care of 1st/Nth stages
|
|
|
|
if (stNum > 0)
|
|
|
|
pipelineStage[stNum]->setPrevStageQueue(stageQueue[stNum - 1]);
|
2009-03-04 19:17:07 +01:00
|
|
|
if (stNum < NumStages - 1)
|
|
|
|
pipelineStage[stNum]->setNextStageQueue(stageQueue[stNum]);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize thread specific variables
|
2009-05-26 18:23:13 +02:00
|
|
|
for (ThreadID tid = 0; tid < numThreads; tid++) {
|
2009-02-11 00:49:29 +01:00
|
|
|
archRegDepMap[tid].setCPU(this);
|
|
|
|
|
|
|
|
nonSpecInstActive[tid] = false;
|
|
|
|
nonSpecSeqNum[tid] = 0;
|
|
|
|
|
|
|
|
squashSeqNum[tid] = MaxAddr;
|
|
|
|
lastSquashCycle[tid] = 0;
|
|
|
|
|
2009-07-09 08:02:20 +02:00
|
|
|
memset(intRegs[tid], 0, sizeof(intRegs[tid]));
|
2009-07-09 08:02:20 +02:00
|
|
|
memset(floatRegs.i[tid], 0, sizeof(floatRegs.i[tid]));
|
2009-07-09 08:02:20 +02:00
|
|
|
isa[tid].clear();
|
2009-02-11 00:49:29 +01:00
|
|
|
|
2010-02-01 00:29:59 +01:00
|
|
|
// Define dummy instructions and resource requests to be used.
|
|
|
|
dummyInst[tid] = new InOrderDynInst(this,
|
|
|
|
thread[tid],
|
|
|
|
0,
|
|
|
|
tid,
|
|
|
|
asid[tid]);
|
|
|
|
|
2011-02-18 20:28:30 +01:00
|
|
|
dummyReq[tid] = new ResourceRequest(resPool->getResource(0));
|
2011-06-20 03:43:40 +02:00
|
|
|
|
|
|
|
#if FULL_SYSTEM
|
|
|
|
// Use this dummy inst to force squashing behind every instruction
|
|
|
|
// in pipeline
|
|
|
|
dummyTrapInst[tid] = new InOrderDynInst(this, NULL, 0, 0, 0);
|
|
|
|
dummyTrapInst[tid]->seqNum = 0;
|
|
|
|
dummyTrapInst[tid]->squashSeqNum = 0;
|
|
|
|
dummyTrapInst[tid]->setTid(tid);
|
|
|
|
#endif
|
|
|
|
|
2011-06-20 03:43:41 +02:00
|
|
|
trapPending[tid] = false;
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
2010-02-01 00:30:48 +01:00
|
|
|
dummyReqInst = new InOrderDynInst(this, NULL, 0, 0, 0);
|
|
|
|
dummyReqInst->setSquashed();
|
2011-02-12 16:14:36 +01:00
|
|
|
dummyReqInst->resetInstCount();
|
2010-02-01 00:30:48 +01:00
|
|
|
|
|
|
|
dummyBufferInst = new InOrderDynInst(this, NULL, 0, 0, 0);
|
|
|
|
dummyBufferInst->setSquashed();
|
2011-02-12 16:14:36 +01:00
|
|
|
dummyBufferInst->resetInstCount();
|
|
|
|
|
|
|
|
endOfSkedIt = skedCache.end();
|
2011-02-12 16:14:40 +01:00
|
|
|
frontEndSked = createFrontEndSked();
|
2011-06-20 03:43:40 +02:00
|
|
|
faultSked = createFaultSked();
|
|
|
|
|
2011-01-08 06:50:29 +01:00
|
|
|
lastRunningCycle = curTick();
|
2009-02-11 00:49:29 +01:00
|
|
|
|
2011-06-20 03:43:39 +02:00
|
|
|
lockAddr = 0;
|
|
|
|
lockFlag = false;
|
2010-02-01 00:30:48 +01:00
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
// Schedule First Tick Event, CPU will reschedule itself from here on out.
|
|
|
|
scheduleTickEvent(0);
|
|
|
|
}
|
|
|
|
|
2010-02-01 00:30:08 +01:00
|
|
|
InOrderCPU::~InOrderCPU()
|
|
|
|
{
|
|
|
|
delete resPool;
|
2011-02-18 20:29:26 +01:00
|
|
|
|
2011-06-20 03:43:33 +02:00
|
|
|
SkedCacheIt sked_it = skedCache.begin();
|
|
|
|
SkedCacheIt sked_end = skedCache.end();
|
2011-02-18 20:29:26 +01:00
|
|
|
|
|
|
|
while (sked_it != sked_end) {
|
|
|
|
delete (*sked_it).second;
|
|
|
|
sked_it++;
|
|
|
|
}
|
|
|
|
skedCache.clear();
|
2010-02-01 00:30:08 +01:00
|
|
|
}
|
|
|
|
|
2011-06-20 03:43:33 +02:00
|
|
|
m5::hash_map<InOrderCPU::SkedID, ThePipeline::RSkedPtr> InOrderCPU::skedCache;
|
2009-02-11 00:49:29 +01:00
|
|
|
|
2011-02-12 16:14:40 +01:00
|
|
|
RSkedPtr
|
|
|
|
InOrderCPU::createFrontEndSked()
|
|
|
|
{
|
2011-02-12 16:14:45 +01:00
|
|
|
RSkedPtr res_sked = new ResourceSked();
|
2011-02-12 16:14:40 +01:00
|
|
|
int stage_num = 0;
|
|
|
|
StageScheduler F(res_sked, stage_num++);
|
|
|
|
StageScheduler D(res_sked, stage_num++);
|
|
|
|
|
|
|
|
// FETCH
|
|
|
|
F.needs(FetchSeq, FetchSeqUnit::AssignNextPC);
|
|
|
|
F.needs(ICache, FetchUnit::InitiateFetch);
|
|
|
|
|
|
|
|
// DECODE
|
|
|
|
D.needs(ICache, FetchUnit::CompleteFetch);
|
|
|
|
D.needs(Decode, DecodeUnit::DecodeInst);
|
|
|
|
D.needs(BPred, BranchPredictor::PredictBranch);
|
|
|
|
D.needs(FetchSeq, FetchSeqUnit::UpdateTargetPC);
|
|
|
|
|
2011-02-12 16:14:45 +01:00
|
|
|
|
2011-06-20 03:43:40 +02:00
|
|
|
DPRINTF(SkedCache, "Resource Sked created for instruction Front End\n");
|
|
|
|
|
|
|
|
return res_sked;
|
|
|
|
}
|
2011-02-12 16:14:45 +01:00
|
|
|
|
2011-06-20 03:43:40 +02:00
|
|
|
RSkedPtr
|
|
|
|
InOrderCPU::createFaultSked()
|
|
|
|
{
|
|
|
|
RSkedPtr res_sked = new ResourceSked();
|
|
|
|
StageScheduler W(res_sked, NumStages - 1);
|
|
|
|
W.needs(Grad, GraduationUnit::CheckFault);
|
|
|
|
DPRINTF(SkedCache, "Resource Sked created for instruction Faults\n");
|
2011-02-12 16:14:40 +01:00
|
|
|
return res_sked;
|
|
|
|
}
|
|
|
|
|
|
|
|
RSkedPtr
|
|
|
|
InOrderCPU::createBackEndSked(DynInstPtr inst)
|
|
|
|
{
|
|
|
|
RSkedPtr res_sked = lookupSked(inst);
|
|
|
|
if (res_sked != NULL) {
|
2011-02-12 16:14:45 +01:00
|
|
|
DPRINTF(SkedCache, "Found %s in sked cache.\n",
|
|
|
|
inst->instName());
|
2011-02-12 16:14:40 +01:00
|
|
|
return res_sked;
|
2011-02-12 16:14:45 +01:00
|
|
|
} else {
|
|
|
|
res_sked = new ResourceSked();
|
2011-02-12 16:14:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int stage_num = ThePipeline::BackEndStartStage;
|
|
|
|
StageScheduler X(res_sked, stage_num++);
|
|
|
|
StageScheduler M(res_sked, stage_num++);
|
|
|
|
StageScheduler W(res_sked, stage_num++);
|
|
|
|
|
|
|
|
if (!inst->staticInst) {
|
|
|
|
warn_once("Static Instruction Object Not Set. Can't Create"
|
|
|
|
" Back End Schedule");
|
2011-02-12 16:14:45 +01:00
|
|
|
return NULL;
|
2011-02-12 16:14:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// EXECUTE
|
2011-06-20 03:43:35 +02:00
|
|
|
X.needs(RegManager, UseDefUnit::MarkDestRegs);
|
2011-02-12 16:14:40 +01:00
|
|
|
for (int idx=0; idx < inst->numSrcRegs(); idx++) {
|
|
|
|
if (!idx || !inst->isStore()) {
|
|
|
|
X.needs(RegManager, UseDefUnit::ReadSrcReg, idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-20 03:43:34 +02:00
|
|
|
//@todo: schedule non-spec insts to operate on this cycle
|
|
|
|
// as long as all previous insts are done
|
2011-02-12 16:14:40 +01:00
|
|
|
if ( inst->isNonSpeculative() ) {
|
|
|
|
// skip execution of non speculative insts until later
|
|
|
|
} else if ( inst->isMemRef() ) {
|
|
|
|
if ( inst->isLoad() ) {
|
|
|
|
X.needs(AGEN, AGENUnit::GenerateAddr);
|
|
|
|
}
|
|
|
|
} else if (inst->opClass() == IntMultOp || inst->opClass() == IntDivOp) {
|
|
|
|
X.needs(MDU, MultDivUnit::StartMultDiv);
|
|
|
|
} else {
|
|
|
|
X.needs(ExecUnit, ExecutionUnit::ExecuteInst);
|
|
|
|
}
|
|
|
|
|
|
|
|
// MEMORY
|
2011-06-20 03:43:34 +02:00
|
|
|
if (!inst->isNonSpeculative()) {
|
|
|
|
if (inst->opClass() == IntMultOp || inst->opClass() == IntDivOp) {
|
|
|
|
M.needs(MDU, MultDivUnit::EndMultDiv);
|
2011-02-12 16:14:40 +01:00
|
|
|
}
|
|
|
|
|
2011-06-20 03:43:34 +02:00
|
|
|
if ( inst->isLoad() ) {
|
|
|
|
M.needs(DCache, CacheUnit::InitiateReadData);
|
2011-06-20 03:43:35 +02:00
|
|
|
if (inst->splitInst)
|
|
|
|
M.needs(DCache, CacheUnit::InitSecondSplitRead);
|
2011-06-20 03:43:34 +02:00
|
|
|
} else if ( inst->isStore() ) {
|
2011-06-20 03:43:36 +02:00
|
|
|
for (int i = 1; i < inst->numSrcRegs(); i++ ) {
|
|
|
|
M.needs(RegManager, UseDefUnit::ReadSrcReg, i);
|
2011-06-20 03:43:34 +02:00
|
|
|
}
|
|
|
|
M.needs(AGEN, AGENUnit::GenerateAddr);
|
|
|
|
M.needs(DCache, CacheUnit::InitiateWriteData);
|
2011-06-20 03:43:35 +02:00
|
|
|
if (inst->splitInst)
|
|
|
|
M.needs(DCache, CacheUnit::InitSecondSplitWrite);
|
2011-06-20 03:43:34 +02:00
|
|
|
}
|
2011-02-12 16:14:40 +01:00
|
|
|
}
|
|
|
|
|
2011-06-20 03:43:34 +02:00
|
|
|
// WRITEBACK
|
|
|
|
if (!inst->isNonSpeculative()) {
|
|
|
|
if ( inst->isLoad() ) {
|
|
|
|
W.needs(DCache, CacheUnit::CompleteReadData);
|
2011-06-20 03:43:35 +02:00
|
|
|
if (inst->splitInst)
|
|
|
|
W.needs(DCache, CacheUnit::CompleteSecondSplitRead);
|
2011-06-20 03:43:34 +02:00
|
|
|
} else if ( inst->isStore() ) {
|
|
|
|
W.needs(DCache, CacheUnit::CompleteWriteData);
|
2011-06-20 03:43:35 +02:00
|
|
|
if (inst->splitInst)
|
|
|
|
W.needs(DCache, CacheUnit::CompleteSecondSplitWrite);
|
2011-06-20 03:43:34 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Finally, Execute Speculative Data
|
|
|
|
if (inst->isMemRef()) {
|
|
|
|
if (inst->isLoad()) {
|
|
|
|
W.needs(AGEN, AGENUnit::GenerateAddr);
|
|
|
|
W.needs(DCache, CacheUnit::InitiateReadData);
|
2011-06-20 03:43:35 +02:00
|
|
|
if (inst->splitInst)
|
|
|
|
W.needs(DCache, CacheUnit::InitSecondSplitRead);
|
2011-06-20 03:43:34 +02:00
|
|
|
W.needs(DCache, CacheUnit::CompleteReadData);
|
2011-06-20 03:43:35 +02:00
|
|
|
if (inst->splitInst)
|
|
|
|
W.needs(DCache, CacheUnit::CompleteSecondSplitRead);
|
2011-06-20 03:43:34 +02:00
|
|
|
} else if (inst->isStore()) {
|
|
|
|
if ( inst->numSrcRegs() >= 2 ) {
|
|
|
|
W.needs(RegManager, UseDefUnit::ReadSrcReg, 1);
|
|
|
|
}
|
|
|
|
W.needs(AGEN, AGENUnit::GenerateAddr);
|
|
|
|
W.needs(DCache, CacheUnit::InitiateWriteData);
|
2011-06-20 03:43:35 +02:00
|
|
|
if (inst->splitInst)
|
|
|
|
W.needs(DCache, CacheUnit::InitSecondSplitWrite);
|
2011-06-20 03:43:34 +02:00
|
|
|
W.needs(DCache, CacheUnit::CompleteWriteData);
|
2011-06-20 03:43:35 +02:00
|
|
|
if (inst->splitInst)
|
|
|
|
W.needs(DCache, CacheUnit::CompleteSecondSplitWrite);
|
2011-06-20 03:43:34 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
W.needs(ExecUnit, ExecutionUnit::ExecuteInst);
|
|
|
|
}
|
2011-02-12 16:14:40 +01:00
|
|
|
}
|
|
|
|
|
2011-06-20 03:43:40 +02:00
|
|
|
W.needs(Grad, GraduationUnit::CheckFault);
|
2011-02-18 20:30:05 +01:00
|
|
|
|
2011-02-12 16:14:40 +01:00
|
|
|
for (int idx=0; idx < inst->numDestRegs(); idx++) {
|
|
|
|
W.needs(RegManager, UseDefUnit::WriteDestReg, idx);
|
|
|
|
}
|
|
|
|
|
2011-06-20 03:43:37 +02:00
|
|
|
if (inst->isControl())
|
|
|
|
W.needs(BPred, BranchPredictor::UpdatePredictor);
|
|
|
|
|
2011-06-20 03:43:40 +02:00
|
|
|
W.needs(Grad, GraduationUnit::GraduateInst);
|
|
|
|
|
2011-02-18 20:29:26 +01:00
|
|
|
// Insert Back Schedule into our cache of
|
2011-02-12 16:14:45 +01:00
|
|
|
// resource schedules
|
|
|
|
addToSkedCache(inst, res_sked);
|
|
|
|
|
|
|
|
DPRINTF(SkedCache, "Back End Sked Created for instruction: %s (%08p)\n",
|
|
|
|
inst->instName(), inst->getMachInst());
|
|
|
|
res_sked->print();
|
|
|
|
|
2011-02-12 16:14:40 +01:00
|
|
|
return res_sked;
|
|
|
|
}
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
void
|
|
|
|
InOrderCPU::regStats()
|
|
|
|
{
|
|
|
|
/* Register the Resource Pool's stats here.*/
|
|
|
|
resPool->regStats();
|
|
|
|
|
2010-02-01 00:28:51 +01:00
|
|
|
/* Register for each Pipeline Stage */
|
|
|
|
for (int stage_num=0; stage_num < ThePipeline::NumStages; stage_num++) {
|
|
|
|
pipelineStage[stage_num]->regStats();
|
|
|
|
}
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
/* Register any of the InOrderCPU's stats here.*/
|
2010-02-01 00:28:59 +01:00
|
|
|
instsPerCtxtSwitch
|
|
|
|
.name(name() + ".instsPerContextSwitch")
|
|
|
|
.desc("Instructions Committed Per Context Switch")
|
|
|
|
.prereq(instsPerCtxtSwitch);
|
|
|
|
|
|
|
|
numCtxtSwitches
|
|
|
|
.name(name() + ".contextSwitches")
|
|
|
|
.desc("Number of context switches");
|
2010-06-24 00:18:20 +02:00
|
|
|
|
|
|
|
comLoads
|
|
|
|
.name(name() + ".comLoads")
|
|
|
|
.desc("Number of Load instructions committed");
|
|
|
|
|
|
|
|
comStores
|
|
|
|
.name(name() + ".comStores")
|
|
|
|
.desc("Number of Store instructions committed");
|
|
|
|
|
|
|
|
comBranches
|
|
|
|
.name(name() + ".comBranches")
|
|
|
|
.desc("Number of Branches instructions committed");
|
|
|
|
|
|
|
|
comNops
|
|
|
|
.name(name() + ".comNops")
|
|
|
|
.desc("Number of Nop instructions committed");
|
|
|
|
|
|
|
|
comNonSpec
|
|
|
|
.name(name() + ".comNonSpec")
|
|
|
|
.desc("Number of Non-Speculative instructions committed");
|
|
|
|
|
|
|
|
comInts
|
|
|
|
.name(name() + ".comInts")
|
|
|
|
.desc("Number of Integer instructions committed");
|
|
|
|
|
|
|
|
comFloats
|
|
|
|
.name(name() + ".comFloats")
|
|
|
|
.desc("Number of Floating Point instructions committed");
|
2010-02-01 00:28:59 +01:00
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
timesIdled
|
|
|
|
.name(name() + ".timesIdled")
|
|
|
|
.desc("Number of times that the entire CPU went into an idle state and"
|
|
|
|
" unscheduled itself")
|
|
|
|
.prereq(timesIdled);
|
|
|
|
|
|
|
|
idleCycles
|
|
|
|
.name(name() + ".idleCycles")
|
2010-02-01 00:30:24 +01:00
|
|
|
.desc("Number of cycles cpu's stages were not processed");
|
|
|
|
|
|
|
|
runCycles
|
|
|
|
.name(name() + ".runCycles")
|
|
|
|
.desc("Number of cycles cpu stages are processed.");
|
|
|
|
|
|
|
|
activity
|
|
|
|
.name(name() + ".activity")
|
|
|
|
.desc("Percentage of cycles cpu is active")
|
|
|
|
.precision(6);
|
|
|
|
activity = (runCycles / numCycles) * 100;
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
threadCycles
|
|
|
|
.init(numThreads)
|
|
|
|
.name(name() + ".threadCycles")
|
|
|
|
.desc("Total Number of Cycles A Thread Was Active in CPU (Per-Thread)");
|
|
|
|
|
|
|
|
smtCycles
|
|
|
|
.name(name() + ".smtCycles")
|
2010-01-31 23:18:15 +01:00
|
|
|
.desc("Total number of cycles that the CPU was in SMT-mode");
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
committedInsts
|
|
|
|
.init(numThreads)
|
|
|
|
.name(name() + ".committedInsts")
|
|
|
|
.desc("Number of Instructions Simulated (Per-Thread)");
|
|
|
|
|
|
|
|
smtCommittedInsts
|
|
|
|
.init(numThreads)
|
|
|
|
.name(name() + ".smtCommittedInsts")
|
|
|
|
.desc("Number of SMT Instructions Simulated (Per-Thread)");
|
|
|
|
|
|
|
|
totalCommittedInsts
|
|
|
|
.name(name() + ".committedInsts_total")
|
|
|
|
.desc("Number of Instructions Simulated (Total)");
|
|
|
|
|
|
|
|
cpi
|
|
|
|
.name(name() + ".cpi")
|
|
|
|
.desc("CPI: Cycles Per Instruction (Per-Thread)")
|
|
|
|
.precision(6);
|
2010-06-24 00:18:20 +02:00
|
|
|
cpi = numCycles / committedInsts;
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
smtCpi
|
|
|
|
.name(name() + ".smt_cpi")
|
|
|
|
.desc("CPI: Total SMT-CPI")
|
|
|
|
.precision(6);
|
|
|
|
smtCpi = smtCycles / smtCommittedInsts;
|
|
|
|
|
|
|
|
totalCpi
|
|
|
|
.name(name() + ".cpi_total")
|
|
|
|
.desc("CPI: Total CPI of All Threads")
|
|
|
|
.precision(6);
|
2009-03-04 19:16:48 +01:00
|
|
|
totalCpi = numCycles / totalCommittedInsts;
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
ipc
|
|
|
|
.name(name() + ".ipc")
|
|
|
|
.desc("IPC: Instructions Per Cycle (Per-Thread)")
|
|
|
|
.precision(6);
|
2010-06-24 00:18:20 +02:00
|
|
|
ipc = committedInsts / numCycles;
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
smtIpc
|
|
|
|
.name(name() + ".smt_ipc")
|
|
|
|
.desc("IPC: Total SMT-IPC")
|
|
|
|
.precision(6);
|
|
|
|
smtIpc = smtCommittedInsts / smtCycles;
|
|
|
|
|
|
|
|
totalIpc
|
|
|
|
.name(name() + ".ipc_total")
|
|
|
|
.desc("IPC: Total IPC of All Threads")
|
|
|
|
.precision(6);
|
2009-03-04 19:16:48 +01:00
|
|
|
totalIpc = totalCommittedInsts / numCycles;
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
BaseCPU::regStats();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
InOrderCPU::tick()
|
|
|
|
{
|
|
|
|
DPRINTF(InOrderCPU, "\n\nInOrderCPU: Ticking main, InOrderCPU.\n");
|
|
|
|
|
|
|
|
++numCycles;
|
|
|
|
|
2011-06-20 03:43:42 +02:00
|
|
|
#if FULL_SYSTEM
|
2011-06-20 03:43:41 +02:00
|
|
|
checkForInterrupts();
|
2011-06-20 03:43:42 +02:00
|
|
|
#endif
|
|
|
|
|
2010-02-01 00:30:24 +01:00
|
|
|
bool pipes_idle = true;
|
2009-02-11 00:49:29 +01:00
|
|
|
//Tick each of the stages
|
|
|
|
for (int stNum=NumStages - 1; stNum >= 0 ; stNum--) {
|
|
|
|
pipelineStage[stNum]->tick();
|
2010-02-01 00:30:24 +01:00
|
|
|
|
|
|
|
pipes_idle = pipes_idle && pipelineStage[stNum]->idle;
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
2010-02-01 00:30:24 +01:00
|
|
|
if (pipes_idle)
|
|
|
|
idleCycles++;
|
|
|
|
else
|
|
|
|
runCycles++;
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
// Now advance the time buffers one tick
|
|
|
|
timeBuffer.advance();
|
|
|
|
for (int sqNum=0; sqNum < NumStages - 1; sqNum++) {
|
|
|
|
stageQueue[sqNum]->advance();
|
|
|
|
}
|
|
|
|
activityRec.advance();
|
2010-02-01 00:30:24 +01:00
|
|
|
|
2011-02-18 20:28:10 +01:00
|
|
|
// Any squashed events, or insts then remove them now
|
2009-02-11 00:49:29 +01:00
|
|
|
cleanUpRemovedEvents();
|
|
|
|
cleanUpRemovedInsts();
|
|
|
|
|
|
|
|
// Re-schedule CPU for this cycle
|
|
|
|
if (!tickEvent.scheduled()) {
|
|
|
|
if (_status == SwitchedOut) {
|
|
|
|
// increment stat
|
2011-01-08 06:50:29 +01:00
|
|
|
lastRunningCycle = curTick();
|
2009-02-11 00:49:29 +01:00
|
|
|
} else if (!activityRec.active()) {
|
|
|
|
DPRINTF(InOrderCPU, "sleeping CPU.\n");
|
2011-01-08 06:50:29 +01:00
|
|
|
lastRunningCycle = curTick();
|
2009-02-11 00:49:29 +01:00
|
|
|
timesIdled++;
|
|
|
|
} else {
|
2011-01-08 06:50:29 +01:00
|
|
|
//Tick next_tick = curTick() + cycles(1);
|
2009-02-11 00:49:29 +01:00
|
|
|
//tickEvent.schedule(next_tick);
|
2011-01-08 06:50:29 +01:00
|
|
|
schedule(&tickEvent, nextCycle(curTick() + 1));
|
2010-01-31 23:18:15 +01:00
|
|
|
DPRINTF(InOrderCPU, "Scheduled CPU for next tick @ %i.\n",
|
2011-01-08 06:50:29 +01:00
|
|
|
nextCycle(curTick() + 1));
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tickThreadStats();
|
|
|
|
updateThreadPriority();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
InOrderCPU::init()
|
|
|
|
{
|
|
|
|
if (!deferRegistration) {
|
|
|
|
registerThreadContexts();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set inSyscall so that the CPU doesn't squash when initially
|
|
|
|
// setting up registers.
|
2009-05-26 18:23:13 +02:00
|
|
|
for (ThreadID tid = 0; tid < numThreads; ++tid)
|
|
|
|
thread[tid]->inSyscall = true;
|
2009-02-11 00:49:29 +01:00
|
|
|
|
2009-04-18 01:54:58 +02:00
|
|
|
#if FULL_SYSTEM
|
2009-05-26 18:23:13 +02:00
|
|
|
for (ThreadID tid = 0; tid < numThreads; tid++) {
|
2009-04-18 01:54:58 +02:00
|
|
|
ThreadContext *src_tc = threadContexts[tid];
|
|
|
|
TheISA::initCPU(src_tc, src_tc->contextId());
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
2009-04-18 01:54:58 +02:00
|
|
|
#endif
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
// Clear inSyscall.
|
2009-05-26 18:23:13 +02:00
|
|
|
for (ThreadID tid = 0; tid < numThreads; ++tid)
|
|
|
|
thread[tid]->inSyscall = false;
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
// Call Initializiation Routine for Resource Pool
|
|
|
|
resPool->init();
|
|
|
|
}
|
|
|
|
|
|
|
|
Port*
|
|
|
|
InOrderCPU::getPort(const std::string &if_name, int idx)
|
|
|
|
{
|
|
|
|
return resPool->getPort(if_name, idx);
|
|
|
|
}
|
|
|
|
|
2009-09-15 07:44:48 +02:00
|
|
|
#if FULL_SYSTEM
|
|
|
|
Fault
|
|
|
|
InOrderCPU::hwrei(ThreadID tid)
|
|
|
|
{
|
2011-06-20 03:43:39 +02:00
|
|
|
#if THE_ISA == ALPHA_ISA
|
|
|
|
// Need to clear the lock flag upon returning from an interrupt.
|
|
|
|
setMiscRegNoEffect(AlphaISA::MISCREG_LOCKFLAG, false, tid);
|
|
|
|
|
|
|
|
thread[tid]->kernelStats->hwrei();
|
|
|
|
// FIXME: XXX check for interrupts? XXX
|
|
|
|
#endif
|
2009-09-15 07:44:48 +02:00
|
|
|
|
|
|
|
return NoFault;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
InOrderCPU::simPalCheck(int palFunc, ThreadID tid)
|
|
|
|
{
|
2011-06-20 03:43:39 +02:00
|
|
|
#if THE_ISA == ALPHA_ISA
|
|
|
|
if (this->thread[tid]->kernelStats)
|
|
|
|
this->thread[tid]->kernelStats->callpal(palFunc,
|
|
|
|
this->threadContexts[tid]);
|
|
|
|
|
|
|
|
switch (palFunc) {
|
|
|
|
case PAL::halt:
|
|
|
|
halt();
|
|
|
|
if (--System::numSystemsRunning == 0)
|
|
|
|
exitSimLoop("all cpus halted");
|
|
|
|
break;
|
2009-09-15 07:44:48 +02:00
|
|
|
|
2011-06-20 03:43:39 +02:00
|
|
|
case PAL::bpt:
|
|
|
|
case PAL::bugchk:
|
|
|
|
if (this->system->breakpoint())
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2009-09-15 07:44:48 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-20 03:43:40 +02:00
|
|
|
void
|
|
|
|
InOrderCPU::checkForInterrupts()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < threadContexts.size(); i++) {
|
|
|
|
ThreadContext *tc = threadContexts[i];
|
|
|
|
|
|
|
|
if (interrupts->checkInterrupts(tc)) {
|
|
|
|
Fault interrupt = interrupts->getInterrupt(tc);
|
|
|
|
|
|
|
|
if (interrupt != NoFault) {
|
|
|
|
DPRINTF(Interrupt, "Processing Intterupt for [tid:%i].\n",
|
|
|
|
tc->threadId());
|
|
|
|
|
|
|
|
ThreadID tid = tc->threadId();
|
|
|
|
interrupts->updateIntrInfo(tc);
|
|
|
|
|
|
|
|
// Squash from Last Stage in Pipeline
|
|
|
|
unsigned last_stage = NumStages - 1;
|
|
|
|
dummyTrapInst[tid]->squashingStage = last_stage;
|
|
|
|
pipelineStage[last_stage]->setupSquash(dummyTrapInst[tid],
|
|
|
|
tid);
|
|
|
|
|
|
|
|
// By default, setupSquash will always squash from stage + 1
|
|
|
|
pipelineStage[BackEndStartStage - 1]->setupSquash(dummyTrapInst[tid],
|
|
|
|
tid);
|
|
|
|
|
|
|
|
// Schedule Squash Through-out Resource Pool
|
|
|
|
resPool->scheduleEvent(
|
|
|
|
(InOrderCPU::CPUEventType)ResourcePool::SquashAll,
|
|
|
|
dummyTrapInst[tid], 0);
|
|
|
|
|
|
|
|
// Finally, Setup Trap to happen at end of cycle
|
|
|
|
trapContext(interrupt, tid, dummyTrapInst[tid]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-15 07:44:48 +02:00
|
|
|
|
|
|
|
Fault
|
|
|
|
InOrderCPU::getInterrupts()
|
|
|
|
{
|
|
|
|
// Check if there are any outstanding interrupts
|
2011-01-12 17:52:29 +01:00
|
|
|
return interrupts->getInterrupt(threadContexts[0]);
|
2009-09-15 07:44:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
InOrderCPU::processInterrupts(Fault interrupt)
|
|
|
|
{
|
|
|
|
// Check for interrupts here. For now can copy the code that
|
|
|
|
// exists within isa_fullsys_traits.hh. Also assume that thread 0
|
|
|
|
// is the one that handles the interrupts.
|
|
|
|
// @todo: Possibly consolidate the interrupt checking code.
|
|
|
|
// @todo: Allow other threads to handle interrupts.
|
|
|
|
|
|
|
|
assert(interrupt != NoFault);
|
2011-01-12 17:52:29 +01:00
|
|
|
interrupts->updateIntrInfo(threadContexts[0]);
|
2009-09-15 07:44:48 +02:00
|
|
|
|
|
|
|
DPRINTF(InOrderCPU, "Interrupt %s being handled\n", interrupt->name());
|
2011-01-12 17:52:29 +01:00
|
|
|
|
|
|
|
// Note: Context ID ok here? Impl. of FS mode needs to revisit this
|
|
|
|
trap(interrupt, threadContexts[0]->contextId(), dummyBufferInst);
|
2009-09-15 07:44:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
InOrderCPU::updateMemPorts()
|
|
|
|
{
|
|
|
|
// Update all ThreadContext's memory ports (Functional/Virtual
|
|
|
|
// Ports)
|
|
|
|
ThreadID size = thread.size();
|
|
|
|
for (ThreadID i = 0; i < size; ++i)
|
|
|
|
thread[i]->connectMemPorts(thread[i]->getTC());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
void
|
2011-06-20 03:43:36 +02:00
|
|
|
InOrderCPU::trapContext(Fault fault, ThreadID tid, DynInstPtr inst, int delay)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2010-09-14 04:26:03 +02:00
|
|
|
scheduleCpuEvent(Trap, fault, tid, inst, delay);
|
2011-06-20 03:43:41 +02:00
|
|
|
trapPending[tid] = true;
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-20 03:43:36 +02:00
|
|
|
InOrderCPU::trap(Fault fault, ThreadID tid, DynInstPtr inst)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2010-09-14 04:26:03 +02:00
|
|
|
fault->invoke(tcBase(tid), inst->staticInst);
|
2011-06-20 03:43:39 +02:00
|
|
|
removePipelineStalls(tid);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
2010-02-01 00:26:13 +01:00
|
|
|
void
|
|
|
|
InOrderCPU::squashFromMemStall(DynInstPtr inst, ThreadID tid, int delay)
|
|
|
|
{
|
|
|
|
scheduleCpuEvent(SquashFromMemStall, NoFault, tid, inst, delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-06-24 21:34:12 +02:00
|
|
|
InOrderCPU::squashDueToMemStall(int stage_num, InstSeqNum seq_num,
|
|
|
|
ThreadID tid)
|
2010-02-01 00:26:13 +01:00
|
|
|
{
|
|
|
|
DPRINTF(InOrderCPU, "Squashing Pipeline Stages Due to Memory Stall...\n");
|
|
|
|
|
|
|
|
// Squash all instructions in each stage including
|
|
|
|
// instruction that caused the squash (seq_num - 1)
|
|
|
|
// NOTE: The stage bandwidth needs to be cleared so thats why
|
|
|
|
// the stalling instruction is squashed as well. The stalled
|
|
|
|
// instruction is previously placed in another intermediate buffer
|
|
|
|
// while it's stall is being handled.
|
|
|
|
InstSeqNum squash_seq_num = seq_num - 1;
|
|
|
|
|
|
|
|
for (int stNum=stage_num; stNum >= 0 ; stNum--) {
|
|
|
|
pipelineStage[stNum]->squashDueToMemStall(squash_seq_num, tid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
void
|
|
|
|
InOrderCPU::scheduleCpuEvent(CPUEventType c_event, Fault fault,
|
2010-02-01 00:26:03 +01:00
|
|
|
ThreadID tid, DynInstPtr inst,
|
2011-06-20 03:43:36 +02:00
|
|
|
unsigned delay, CPUEventPri event_pri)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2010-02-01 00:26:26 +01:00
|
|
|
CPUEvent *cpu_event = new CPUEvent(this, c_event, fault, tid, inst,
|
2011-06-20 03:43:36 +02:00
|
|
|
event_pri);
|
2009-02-11 00:49:29 +01:00
|
|
|
|
2011-01-08 06:50:29 +01:00
|
|
|
Tick sked_tick = nextCycle(curTick() + ticks(delay));
|
2009-02-11 00:49:29 +01:00
|
|
|
if (delay >= 0) {
|
2010-02-01 00:26:26 +01:00
|
|
|
DPRINTF(InOrderCPU, "Scheduling CPU Event (%s) for cycle %i, [tid:%i].\n",
|
2011-01-08 06:50:29 +01:00
|
|
|
eventNames[c_event], curTick() + delay, tid);
|
2011-01-08 06:50:29 +01:00
|
|
|
schedule(cpu_event, sked_tick);
|
2009-02-11 00:49:29 +01:00
|
|
|
} else {
|
|
|
|
cpu_event->process();
|
|
|
|
cpuEventRemoveList.push(cpu_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Broadcast event to the Resource Pool
|
2010-02-01 00:26:32 +01:00
|
|
|
// Need to reset tid just in case this is a dummy instruction
|
|
|
|
inst->setTid(tid);
|
2010-02-01 00:26:03 +01:00
|
|
|
resPool->scheduleEvent(c_event, inst, 0, 0, tid);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
2010-02-01 00:26:47 +01:00
|
|
|
bool
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::isThreadActive(ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2009-05-26 18:23:13 +02:00
|
|
|
list<ThreadID>::iterator isActive =
|
|
|
|
std::find(activeThreads.begin(), activeThreads.end(), tid);
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
return (isActive != activeThreads.end());
|
|
|
|
}
|
|
|
|
|
2010-02-01 00:26:47 +01:00
|
|
|
bool
|
|
|
|
InOrderCPU::isThreadReady(ThreadID tid)
|
|
|
|
{
|
|
|
|
list<ThreadID>::iterator isReady =
|
|
|
|
std::find(readyThreads.begin(), readyThreads.end(), tid);
|
|
|
|
|
|
|
|
return (isReady != readyThreads.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
InOrderCPU::isThreadSuspended(ThreadID tid)
|
|
|
|
{
|
|
|
|
list<ThreadID>::iterator isSuspended =
|
|
|
|
std::find(suspendedThreads.begin(), suspendedThreads.end(), tid);
|
|
|
|
|
|
|
|
return (isSuspended != suspendedThreads.end());
|
|
|
|
}
|
2009-02-11 00:49:29 +01:00
|
|
|
|
2010-02-01 00:26:32 +01:00
|
|
|
void
|
|
|
|
InOrderCPU::activateNextReadyThread()
|
|
|
|
{
|
|
|
|
if (readyThreads.size() >= 1) {
|
|
|
|
ThreadID ready_tid = readyThreads.front();
|
|
|
|
|
|
|
|
// Activate in Pipeline
|
|
|
|
activateThread(ready_tid);
|
|
|
|
|
|
|
|
// Activate in Resource Pool
|
2011-06-20 03:43:38 +02:00
|
|
|
resPool->activateThread(ready_tid);
|
2010-02-01 00:26:32 +01:00
|
|
|
|
|
|
|
list<ThreadID>::iterator ready_it =
|
|
|
|
std::find(readyThreads.begin(), readyThreads.end(), ready_tid);
|
|
|
|
readyThreads.erase(ready_it);
|
|
|
|
} else {
|
|
|
|
DPRINTF(InOrderCPU,
|
2010-02-01 00:26:47 +01:00
|
|
|
"Attempting to activate new thread, but No Ready Threads to"
|
|
|
|
"activate.\n");
|
2010-02-01 00:27:38 +01:00
|
|
|
DPRINTF(InOrderCPU,
|
|
|
|
"Unable to switch to next active thread.\n");
|
2010-02-01 00:26:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
void
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::activateThread(ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2010-02-01 00:26:47 +01:00
|
|
|
if (isThreadSuspended(tid)) {
|
|
|
|
DPRINTF(InOrderCPU,
|
|
|
|
"Removing [tid:%i] from suspended threads list.\n", tid);
|
|
|
|
|
|
|
|
list<ThreadID>::iterator susp_it =
|
|
|
|
std::find(suspendedThreads.begin(), suspendedThreads.end(),
|
|
|
|
tid);
|
|
|
|
suspendedThreads.erase(susp_it);
|
|
|
|
}
|
|
|
|
|
2010-02-01 00:26:32 +01:00
|
|
|
if (threadModel == SwitchOnCacheMiss &&
|
|
|
|
numActiveThreads() == 1) {
|
|
|
|
DPRINTF(InOrderCPU,
|
2010-02-01 00:26:47 +01:00
|
|
|
"Ignoring activation of [tid:%i], since [tid:%i] is "
|
|
|
|
"already running.\n", tid, activeThreadId());
|
|
|
|
|
2010-02-01 00:27:38 +01:00
|
|
|
DPRINTF(InOrderCPU,"Placing [tid:%i] on ready threads list\n",
|
2010-02-01 00:26:47 +01:00
|
|
|
tid);
|
2010-02-01 00:26:32 +01:00
|
|
|
|
|
|
|
readyThreads.push_back(tid);
|
|
|
|
|
2010-02-01 00:26:47 +01:00
|
|
|
} else if (!isThreadActive(tid)) {
|
2009-05-26 18:23:13 +02:00
|
|
|
DPRINTF(InOrderCPU,
|
2010-02-01 00:26:47 +01:00
|
|
|
"Adding [tid:%i] to active threads list.\n", tid);
|
2009-02-11 00:49:29 +01:00
|
|
|
activeThreads.push_back(tid);
|
2010-02-01 00:26:47 +01:00
|
|
|
|
2010-02-01 00:27:38 +01:00
|
|
|
activateThreadInPipeline(tid);
|
2010-02-01 00:27:58 +01:00
|
|
|
|
2011-01-08 06:50:29 +01:00
|
|
|
thread[tid]->lastActivate = curTick();
|
2010-02-01 00:27:58 +01:00
|
|
|
|
2010-02-01 00:28:12 +01:00
|
|
|
tcBase(tid)->setStatus(ThreadContext::Active);
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
wakeCPU();
|
2010-02-01 00:28:59 +01:00
|
|
|
|
|
|
|
numCtxtSwitches++;
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-01 00:27:38 +01:00
|
|
|
void
|
|
|
|
InOrderCPU::activateThreadInPipeline(ThreadID tid)
|
|
|
|
{
|
|
|
|
for (int stNum=0; stNum < NumStages; stNum++) {
|
|
|
|
pipelineStage[stNum]->activateThread(tid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-01 00:26:40 +01:00
|
|
|
void
|
|
|
|
InOrderCPU::deactivateContext(ThreadID tid, int delay)
|
|
|
|
{
|
|
|
|
DPRINTF(InOrderCPU,"[tid:%i]: Deactivating ...\n", tid);
|
|
|
|
|
2010-02-01 00:29:59 +01:00
|
|
|
scheduleCpuEvent(DeactivateThread, NoFault, tid, dummyInst[tid], delay);
|
2010-02-01 00:26:40 +01:00
|
|
|
|
|
|
|
// Be sure to signal that there's some activity so the CPU doesn't
|
|
|
|
// deschedule itself.
|
|
|
|
activityRec.activity();
|
|
|
|
|
|
|
|
_status = Running;
|
|
|
|
}
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
void
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::deactivateThread(ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
|
|
|
DPRINTF(InOrderCPU, "[tid:%i]: Calling deactivate thread.\n", tid);
|
|
|
|
|
|
|
|
if (isThreadActive(tid)) {
|
|
|
|
DPRINTF(InOrderCPU,"[tid:%i]: Removing from active threads list\n",
|
|
|
|
tid);
|
2009-05-26 18:23:13 +02:00
|
|
|
list<ThreadID>::iterator thread_it =
|
|
|
|
std::find(activeThreads.begin(), activeThreads.end(), tid);
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
removePipelineStalls(*thread_it);
|
|
|
|
|
|
|
|
activeThreads.erase(thread_it);
|
2010-02-01 00:28:12 +01:00
|
|
|
|
|
|
|
// Ideally, this should be triggered from the
|
|
|
|
// suspendContext/Thread functions
|
|
|
|
tcBase(tid)->setStatus(ThreadContext::Suspended);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
2010-02-01 00:26:47 +01:00
|
|
|
|
|
|
|
assert(!isThreadActive(tid));
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-02-01 00:26:40 +01:00
|
|
|
InOrderCPU::removePipelineStalls(ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2010-02-01 00:26:40 +01:00
|
|
|
DPRINTF(InOrderCPU,"[tid:%i]: Removing all pipeline stalls\n",
|
|
|
|
tid);
|
2009-02-11 00:49:29 +01:00
|
|
|
|
2010-02-01 00:26:40 +01:00
|
|
|
for (int stNum = 0; stNum < NumStages ; stNum++) {
|
|
|
|
pipelineStage[stNum]->removeStalls(tid);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InOrderCPU::updateThreadPriority()
|
|
|
|
{
|
|
|
|
if (activeThreads.size() > 1)
|
|
|
|
{
|
|
|
|
//DEFAULT TO ROUND ROBIN SCHEME
|
|
|
|
//e.g. Move highest priority to end of thread list
|
2009-05-26 18:23:13 +02:00
|
|
|
list<ThreadID>::iterator list_begin = activeThreads.begin();
|
|
|
|
list<ThreadID>::iterator list_end = activeThreads.end();
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
unsigned high_thread = *list_begin;
|
|
|
|
|
|
|
|
activeThreads.erase(list_begin);
|
|
|
|
|
|
|
|
activeThreads.push_back(high_thread);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
InOrderCPU::tickThreadStats()
|
|
|
|
{
|
|
|
|
/** Keep track of cycles that each thread is active */
|
2009-05-26 18:23:13 +02:00
|
|
|
list<ThreadID>::iterator thread_it = activeThreads.begin();
|
2009-02-11 00:49:29 +01:00
|
|
|
while (thread_it != activeThreads.end()) {
|
|
|
|
threadCycles[*thread_it]++;
|
|
|
|
thread_it++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keep track of cycles where SMT is active
|
|
|
|
if (activeThreads.size() > 1) {
|
|
|
|
smtCycles++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::activateContext(ThreadID tid, int delay)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
|
|
|
DPRINTF(InOrderCPU,"[tid:%i]: Activating ...\n", tid);
|
|
|
|
|
2010-02-01 00:29:59 +01:00
|
|
|
|
|
|
|
scheduleCpuEvent(ActivateThread, NoFault, tid, dummyInst[tid], delay);
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
// Be sure to signal that there's some activity so the CPU doesn't
|
|
|
|
// deschedule itself.
|
|
|
|
activityRec.activity();
|
|
|
|
|
|
|
|
_status = Running;
|
|
|
|
}
|
|
|
|
|
2010-02-01 00:26:32 +01:00
|
|
|
void
|
|
|
|
InOrderCPU::activateNextReadyContext(int delay)
|
|
|
|
{
|
|
|
|
DPRINTF(InOrderCPU,"Activating next ready thread\n");
|
|
|
|
|
2010-02-01 00:29:59 +01:00
|
|
|
scheduleCpuEvent(ActivateNextReadyThread, NoFault, 0/*tid*/, dummyInst[0],
|
2011-06-20 03:43:36 +02:00
|
|
|
delay, ActivateNextReadyThread_Pri);
|
2010-02-01 00:26:32 +01:00
|
|
|
|
|
|
|
// Be sure to signal that there's some activity so the CPU doesn't
|
|
|
|
// deschedule itself.
|
|
|
|
activityRec.activity();
|
|
|
|
|
|
|
|
_status = Running;
|
|
|
|
}
|
2009-02-11 00:49:29 +01:00
|
|
|
|
2010-02-01 00:26:40 +01:00
|
|
|
void
|
|
|
|
InOrderCPU::haltContext(ThreadID tid, int delay)
|
|
|
|
{
|
2010-02-01 00:28:05 +01:00
|
|
|
DPRINTF(InOrderCPU, "[tid:%i]: Calling Halt Context...\n", tid);
|
|
|
|
|
2010-02-01 00:29:59 +01:00
|
|
|
scheduleCpuEvent(HaltThread, NoFault, tid, dummyInst[tid], delay);
|
2010-02-01 00:28:05 +01:00
|
|
|
|
|
|
|
activityRec.activity();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InOrderCPU::haltThread(ThreadID tid)
|
|
|
|
{
|
|
|
|
DPRINTF(InOrderCPU, "[tid:%i]: Placing on Halted Threads List...\n", tid);
|
|
|
|
deactivateThread(tid);
|
|
|
|
squashThreadInPipeline(tid);
|
|
|
|
haltedThreads.push_back(tid);
|
|
|
|
|
2010-02-01 00:28:12 +01:00
|
|
|
tcBase(tid)->setStatus(ThreadContext::Halted);
|
|
|
|
|
2010-02-01 00:28:05 +01:00
|
|
|
if (threadModel == SwitchOnCacheMiss) {
|
|
|
|
activateNextReadyContext();
|
|
|
|
}
|
2010-02-01 00:26:40 +01:00
|
|
|
}
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
void
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::suspendContext(ThreadID tid, int delay)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2010-02-01 00:29:59 +01:00
|
|
|
scheduleCpuEvent(SuspendThread, NoFault, tid, dummyInst[tid], delay);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::suspendThread(ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2010-06-24 21:34:12 +02:00
|
|
|
DPRINTF(InOrderCPU, "[tid:%i]: Placing on Suspended Threads List...\n",
|
|
|
|
tid);
|
2009-02-11 00:49:29 +01:00
|
|
|
deactivateThread(tid);
|
2010-02-01 00:26:32 +01:00
|
|
|
suspendedThreads.push_back(tid);
|
2011-01-08 06:50:29 +01:00
|
|
|
thread[tid]->lastSuspend = curTick();
|
2010-02-01 00:28:12 +01:00
|
|
|
|
|
|
|
tcBase(tid)->setStatus(ThreadContext::Suspended);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::squashThreadInPipeline(ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
|
|
|
//Squash all instructions in each stage
|
|
|
|
for (int stNum=NumStages - 1; stNum >= 0 ; stNum--) {
|
|
|
|
pipelineStage[stNum]->squash(0 /*seq_num*/, tid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-12 21:01:13 +02:00
|
|
|
PipelineStage*
|
|
|
|
InOrderCPU::getPipeStage(int stage_num)
|
|
|
|
{
|
|
|
|
return pipelineStage[stage_num];
|
|
|
|
}
|
|
|
|
|
2011-06-20 03:43:36 +02:00
|
|
|
|
2011-06-20 03:43:33 +02:00
|
|
|
RegIndex
|
2011-06-20 03:43:33 +02:00
|
|
|
InOrderCPU::flattenRegIdx(RegIndex reg_idx, RegType ®_type, ThreadID tid)
|
2011-06-20 03:43:33 +02:00
|
|
|
{
|
|
|
|
if (reg_idx < FP_Base_DepTag) {
|
2011-06-20 03:43:33 +02:00
|
|
|
reg_type = IntType;
|
2011-06-20 03:43:33 +02:00
|
|
|
return isa[tid].flattenIntIndex(reg_idx);
|
|
|
|
} else if (reg_idx < Ctrl_Base_DepTag) {
|
2011-06-20 03:43:33 +02:00
|
|
|
reg_type = FloatType;
|
2011-06-20 03:43:33 +02:00
|
|
|
reg_idx -= FP_Base_DepTag;
|
|
|
|
return isa[tid].flattenFloatIndex(reg_idx);
|
|
|
|
} else {
|
2011-06-20 03:43:33 +02:00
|
|
|
reg_type = MiscType;
|
|
|
|
return reg_idx - TheISA::Ctrl_Base_DepTag;
|
2011-06-20 03:43:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
uint64_t
|
2011-06-20 03:43:33 +02:00
|
|
|
InOrderCPU::readIntReg(RegIndex reg_idx, ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2011-06-20 03:43:33 +02:00
|
|
|
DPRINTF(IntRegs, "[tid:%i]: Reading Int. Reg %i as %x\n",
|
|
|
|
tid, reg_idx, intRegs[tid][reg_idx]);
|
|
|
|
|
2009-07-09 08:02:20 +02:00
|
|
|
return intRegs[tid][reg_idx];
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FloatReg
|
2011-06-20 03:43:33 +02:00
|
|
|
InOrderCPU::readFloatReg(RegIndex reg_idx, ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2011-06-20 03:43:38 +02:00
|
|
|
DPRINTF(FloatRegs, "[tid:%i]: Reading Float Reg %i as %x, %08f\n",
|
|
|
|
tid, reg_idx, floatRegs.i[tid][reg_idx], floatRegs.f[tid][reg_idx]);
|
|
|
|
|
2009-07-09 08:02:20 +02:00
|
|
|
return floatRegs.f[tid][reg_idx];
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FloatRegBits
|
2011-06-20 03:43:33 +02:00
|
|
|
InOrderCPU::readFloatRegBits(RegIndex reg_idx, ThreadID tid)
|
2011-06-20 03:43:38 +02:00
|
|
|
{
|
|
|
|
DPRINTF(FloatRegs, "[tid:%i]: Reading Float Reg %i as %x, %08f\n",
|
|
|
|
tid, reg_idx, floatRegs.i[tid][reg_idx], floatRegs.f[tid][reg_idx]);
|
|
|
|
|
2009-07-09 08:02:20 +02:00
|
|
|
return floatRegs.i[tid][reg_idx];
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-20 03:43:33 +02:00
|
|
|
InOrderCPU::setIntReg(RegIndex reg_idx, uint64_t val, ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2011-06-20 03:43:34 +02:00
|
|
|
if (reg_idx == TheISA::ZeroReg) {
|
|
|
|
DPRINTF(IntRegs, "[tid:%i]: Ignoring Setting of ISA-ZeroReg "
|
|
|
|
"(Int. Reg %i) to %x\n", tid, reg_idx, val);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
DPRINTF(IntRegs, "[tid:%i]: Setting Int. Reg %i to %x\n",
|
|
|
|
tid, reg_idx, val);
|
2011-06-20 03:43:33 +02:00
|
|
|
|
2011-06-20 03:43:34 +02:00
|
|
|
intRegs[tid][reg_idx] = val;
|
|
|
|
}
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-06-20 03:43:33 +02:00
|
|
|
InOrderCPU::setFloatReg(RegIndex reg_idx, FloatReg val, ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2009-07-09 08:02:20 +02:00
|
|
|
floatRegs.f[tid][reg_idx] = val;
|
2011-06-20 03:43:38 +02:00
|
|
|
DPRINTF(FloatRegs, "[tid:%i]: Setting Float. Reg %i bits to "
|
|
|
|
"%x, %08f\n",
|
|
|
|
tid, reg_idx,
|
|
|
|
floatRegs.i[tid][reg_idx],
|
|
|
|
floatRegs.f[tid][reg_idx]);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-06-20 03:43:33 +02:00
|
|
|
InOrderCPU::setFloatRegBits(RegIndex reg_idx, FloatRegBits val, ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2009-07-09 08:02:20 +02:00
|
|
|
floatRegs.i[tid][reg_idx] = val;
|
2011-06-20 03:43:38 +02:00
|
|
|
DPRINTF(FloatRegs, "[tid:%i]: Setting Float. Reg %i bits to "
|
|
|
|
"%x, %08f\n",
|
|
|
|
tid, reg_idx,
|
|
|
|
floatRegs.i[tid][reg_idx],
|
|
|
|
floatRegs.f[tid][reg_idx]);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::readRegOtherThread(unsigned reg_idx, ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
|
|
|
// If Default value is set, then retrieve target thread
|
2009-05-26 18:23:13 +02:00
|
|
|
if (tid == InvalidThreadID) {
|
2009-02-11 00:49:29 +01:00
|
|
|
tid = TheISA::getTargetThread(tcBase(tid));
|
|
|
|
}
|
|
|
|
|
2010-01-31 23:18:15 +01:00
|
|
|
if (reg_idx < FP_Base_DepTag) {
|
|
|
|
// Integer Register File
|
2009-02-11 00:49:29 +01:00
|
|
|
return readIntReg(reg_idx, tid);
|
2010-01-31 23:18:15 +01:00
|
|
|
} else if (reg_idx < Ctrl_Base_DepTag) {
|
|
|
|
// Float Register File
|
2009-02-11 00:49:29 +01:00
|
|
|
reg_idx -= FP_Base_DepTag;
|
|
|
|
return readFloatRegBits(reg_idx, tid);
|
|
|
|
} else {
|
|
|
|
reg_idx -= Ctrl_Base_DepTag;
|
|
|
|
return readMiscReg(reg_idx, tid); // Misc. Register File
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::setRegOtherThread(unsigned reg_idx, const MiscReg &val,
|
|
|
|
ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
|
|
|
// If Default value is set, then retrieve target thread
|
2009-05-26 18:23:13 +02:00
|
|
|
if (tid == InvalidThreadID) {
|
2009-02-11 00:49:29 +01:00
|
|
|
tid = TheISA::getTargetThread(tcBase(tid));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reg_idx < FP_Base_DepTag) { // Integer Register File
|
|
|
|
setIntReg(reg_idx, val, tid);
|
|
|
|
} else if (reg_idx < Ctrl_Base_DepTag) { // Float Register File
|
|
|
|
reg_idx -= FP_Base_DepTag;
|
|
|
|
setFloatRegBits(reg_idx, val, tid);
|
|
|
|
} else {
|
|
|
|
reg_idx -= Ctrl_Base_DepTag;
|
|
|
|
setMiscReg(reg_idx, val, tid); // Misc. Register File
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MiscReg
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::readMiscRegNoEffect(int misc_reg, ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2009-07-09 08:02:20 +02:00
|
|
|
return isa[tid].readMiscRegNoEffect(misc_reg);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MiscReg
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::readMiscReg(int misc_reg, ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2009-07-09 08:02:20 +02:00
|
|
|
return isa[tid].readMiscReg(misc_reg, tcBase(tid));
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::setMiscRegNoEffect(int misc_reg, const MiscReg &val, ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2009-07-09 08:02:20 +02:00
|
|
|
isa[tid].setMiscRegNoEffect(misc_reg, val);
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::setMiscReg(int misc_reg, const MiscReg &val, ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2009-07-09 08:02:20 +02:00
|
|
|
isa[tid].setMiscReg(misc_reg, val, tcBase(tid));
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InOrderCPU::ListIt
|
2011-06-20 03:43:34 +02:00
|
|
|
InOrderCPU::addInst(DynInstPtr inst)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2009-05-26 18:23:13 +02:00
|
|
|
ThreadID tid = inst->readTid();
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
instList[tid].push_back(inst);
|
|
|
|
|
|
|
|
return --(instList[tid].end());
|
|
|
|
}
|
|
|
|
|
2011-06-20 03:43:35 +02:00
|
|
|
InOrderCPU::ListIt
|
|
|
|
InOrderCPU::findInst(InstSeqNum seq_num, ThreadID tid)
|
|
|
|
{
|
|
|
|
ListIt it = instList[tid].begin();
|
|
|
|
ListIt end = instList[tid].end();
|
|
|
|
|
|
|
|
while (it != end) {
|
|
|
|
if ((*it)->seqNum == seq_num)
|
|
|
|
return it;
|
|
|
|
else if ((*it)->seqNum > seq_num)
|
|
|
|
break;
|
|
|
|
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return instList[tid].end();
|
|
|
|
}
|
|
|
|
|
2010-02-01 00:28:59 +01:00
|
|
|
void
|
|
|
|
InOrderCPU::updateContextSwitchStats()
|
|
|
|
{
|
|
|
|
// Set Average Stat Here, then reset to 0
|
|
|
|
instsPerCtxtSwitch = instsPerSwitch;
|
|
|
|
instsPerSwitch = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
void
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::instDone(DynInstPtr inst, ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2011-06-20 03:43:36 +02:00
|
|
|
// Set the nextPC to be fetched if this is the last instruction
|
|
|
|
// committed
|
|
|
|
// ========
|
|
|
|
// This contributes to the precise state of the CPU
|
2010-02-01 00:27:58 +01:00
|
|
|
// which can be used when restoring a thread to the CPU after after any
|
|
|
|
// type of context switching activity (fork, exception, etc.)
|
2011-06-20 03:43:36 +02:00
|
|
|
TheISA::PCState comm_pc = inst->pcState();
|
|
|
|
lastCommittedPC[tid] = comm_pc;
|
|
|
|
TheISA::advancePC(comm_pc, inst->staticInst);
|
|
|
|
pcState(comm_pc, tid);
|
2009-02-11 00:49:29 +01:00
|
|
|
|
2011-06-20 03:43:36 +02:00
|
|
|
//@todo: may be unnecessary with new-ISA-specific branch handling code
|
2010-02-01 00:27:58 +01:00
|
|
|
if (inst->isControl()) {
|
|
|
|
thread[tid]->lastGradIsBranch = true;
|
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[tid]->lastBranchPC = inst->pcState();
|
|
|
|
TheISA::advancePC(thread[tid]->lastBranchPC, inst->staticInst);
|
2010-02-01 00:27:58 +01:00
|
|
|
} else {
|
|
|
|
thread[tid]->lastGradIsBranch = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
// Finalize Trace Data For Instruction
|
|
|
|
if (inst->traceData) {
|
2011-01-08 06:50:29 +01:00
|
|
|
//inst->traceData->setCycle(curTick());
|
2009-02-11 00:49:29 +01:00
|
|
|
inst->traceData->setFetchSeq(inst->seqNum);
|
|
|
|
//inst->traceData->setCPSeq(cpu->tcBase(tid)->numInst);
|
|
|
|
inst->traceData->dump();
|
|
|
|
delete inst->traceData;
|
|
|
|
inst->traceData = NULL;
|
|
|
|
}
|
|
|
|
|
2010-02-01 00:28:59 +01:00
|
|
|
// Increment active thread's instruction count
|
|
|
|
instsPerSwitch++;
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
// Increment thread-state's instruction count
|
|
|
|
thread[tid]->numInst++;
|
|
|
|
|
|
|
|
// Increment thread-state's instruction stats
|
|
|
|
thread[tid]->numInsts++;
|
|
|
|
|
|
|
|
// Count committed insts per thread stats
|
|
|
|
committedInsts[tid]++;
|
|
|
|
|
|
|
|
// Count total insts committed stat
|
|
|
|
totalCommittedInsts++;
|
|
|
|
|
|
|
|
// Count SMT-committed insts per thread stat
|
|
|
|
if (numActiveThreads() > 1) {
|
|
|
|
smtCommittedInsts[tid]++;
|
|
|
|
}
|
|
|
|
|
2010-06-24 00:18:20 +02:00
|
|
|
// Instruction-Mix Stats
|
|
|
|
if (inst->isLoad()) {
|
|
|
|
comLoads++;
|
|
|
|
} else if (inst->isStore()) {
|
|
|
|
comStores++;
|
|
|
|
} else if (inst->isControl()) {
|
|
|
|
comBranches++;
|
|
|
|
} else if (inst->isNop()) {
|
|
|
|
comNops++;
|
|
|
|
} else if (inst->isNonSpeculative()) {
|
|
|
|
comNonSpec++;
|
|
|
|
} else if (inst->isInteger()) {
|
|
|
|
comInts++;
|
|
|
|
} else if (inst->isFloating()) {
|
|
|
|
comFloats++;
|
|
|
|
}
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
// Check for instruction-count-based events.
|
|
|
|
comInstEventQueue[tid]->serviceEvents(thread[tid]->numInst);
|
|
|
|
|
|
|
|
// Finally, remove instruction from CPU
|
|
|
|
removeInst(inst);
|
|
|
|
}
|
|
|
|
|
2010-02-01 00:30:48 +01:00
|
|
|
// currently unused function, but substitute repetitive code w/this function
|
|
|
|
// call
|
2009-02-11 00:49:29 +01:00
|
|
|
void
|
2011-06-20 03:43:34 +02:00
|
|
|
InOrderCPU::addToRemoveList(DynInstPtr inst)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
|
|
|
removeInstsThisCycle = true;
|
2010-02-01 00:30:59 +01:00
|
|
|
if (!inst->isRemoveList()) {
|
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(InOrderCPU, "Pushing instruction [tid:%i] PC %s "
|
2010-02-01 00:30:59 +01:00
|
|
|
"[sn:%lli] to remove list\n",
|
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
|
|
|
inst->threadNumber, inst->pcState(), inst->seqNum);
|
2010-02-01 00:30:59 +01:00
|
|
|
inst->setRemoveList();
|
|
|
|
removeList.push(inst->getInstListIt());
|
|
|
|
} 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
|
|
|
DPRINTF(InOrderCPU, "Ignoring instruction removal for [tid:%i] PC %s "
|
2010-02-01 00:30:59 +01:00
|
|
|
"[sn:%lli], already remove list\n",
|
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
|
|
|
inst->threadNumber, inst->pcState(), inst->seqNum);
|
2010-02-01 00:30:59 +01:00
|
|
|
}
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-20 03:43:34 +02:00
|
|
|
InOrderCPU::removeInst(DynInstPtr inst)
|
2009-02-11 00:49:29 +01: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
|
|
|
DPRINTF(InOrderCPU, "Removing graduated instruction [tid:%i] PC %s "
|
2009-02-11 00:49:29 +01:00
|
|
|
"[sn:%lli]\n",
|
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
|
|
|
inst->threadNumber, inst->pcState(), inst->seqNum);
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
removeInstsThisCycle = true;
|
|
|
|
|
|
|
|
// Remove the instruction.
|
2010-02-01 00:30:59 +01:00
|
|
|
if (!inst->isRemoveList()) {
|
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(InOrderCPU, "Pushing instruction [tid:%i] PC %s "
|
2010-02-01 00:30:59 +01:00
|
|
|
"[sn:%lli] to remove list\n",
|
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
|
|
|
inst->threadNumber, inst->pcState(), inst->seqNum);
|
2010-02-01 00:30:59 +01:00
|
|
|
inst->setRemoveList();
|
|
|
|
removeList.push(inst->getInstListIt());
|
|
|
|
} 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
|
|
|
DPRINTF(InOrderCPU, "Ignoring instruction removal for [tid:%i] PC %s "
|
2010-02-01 00:30:59 +01:00
|
|
|
"[sn:%lli], already on remove list\n",
|
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
|
|
|
inst->threadNumber, inst->pcState(), inst->seqNum);
|
2010-02-01 00:30:59 +01:00
|
|
|
}
|
2010-02-01 00:30:48 +01:00
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::removeInstsUntil(const InstSeqNum &seq_num, ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
|
|
|
//assert(!instList[tid].empty());
|
|
|
|
|
|
|
|
removeInstsThisCycle = true;
|
|
|
|
|
|
|
|
ListIt inst_iter = instList[tid].end();
|
|
|
|
|
|
|
|
inst_iter--;
|
|
|
|
|
2010-02-01 00:30:48 +01:00
|
|
|
DPRINTF(InOrderCPU, "Squashing instructions from CPU instruction "
|
2009-02-11 00:49:29 +01:00
|
|
|
"list that are from [tid:%i] and above [sn:%lli] (end=%lli).\n",
|
|
|
|
tid, seq_num, (*inst_iter)->seqNum);
|
|
|
|
|
|
|
|
while ((*inst_iter)->seqNum > seq_num) {
|
|
|
|
|
|
|
|
bool break_loop = (inst_iter == instList[tid].begin());
|
|
|
|
|
|
|
|
squashInstIt(inst_iter, tid);
|
|
|
|
|
|
|
|
inst_iter--;
|
|
|
|
|
|
|
|
if (break_loop)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void
|
2011-06-20 03:43:36 +02:00
|
|
|
InOrderCPU::squashInstIt(const ListIt inst_it, ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
2011-06-20 03:43:36 +02:00
|
|
|
DynInstPtr inst = (*inst_it);
|
|
|
|
if (inst->threadNumber == tid) {
|
2009-02-11 00:49:29 +01:00
|
|
|
DPRINTF(InOrderCPU, "Squashing instruction, "
|
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
|
|
|
"[tid:%i] [sn:%lli] PC %s\n",
|
2011-06-20 03:43:36 +02:00
|
|
|
inst->threadNumber,
|
|
|
|
inst->seqNum,
|
|
|
|
inst->pcState());
|
2009-02-11 00:49:29 +01:00
|
|
|
|
2011-06-20 03:43:36 +02:00
|
|
|
inst->setSquashed();
|
|
|
|
archRegDepMap[tid].remove(inst);
|
2009-02-11 00:49:29 +01:00
|
|
|
|
2011-06-20 03:43:36 +02:00
|
|
|
if (!inst->isRemoveList()) {
|
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(InOrderCPU, "Pushing instruction [tid:%i] PC %s "
|
2010-02-01 00:30:59 +01:00
|
|
|
"[sn:%lli] to remove list\n",
|
2011-06-20 03:43:36 +02:00
|
|
|
inst->threadNumber, inst->pcState(),
|
|
|
|
inst->seqNum);
|
|
|
|
inst->setRemoveList();
|
|
|
|
removeList.push(inst_it);
|
2010-02-01 00:30:59 +01:00
|
|
|
} else {
|
2010-06-24 21:34:12 +02:00
|
|
|
DPRINTF(InOrderCPU, "Ignoring instruction removal for [tid:%i]"
|
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
|
|
|
" PC %s [sn:%lli], already on remove list\n",
|
2011-06-20 03:43:36 +02:00
|
|
|
inst->threadNumber, inst->pcState(),
|
|
|
|
inst->seqNum);
|
2010-02-01 00:30:59 +01:00
|
|
|
}
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
2010-02-01 00:30:59 +01:00
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
InOrderCPU::cleanUpRemovedInsts()
|
|
|
|
{
|
|
|
|
while (!removeList.empty()) {
|
|
|
|
DPRINTF(InOrderCPU, "Removing instruction, "
|
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
|
|
|
"[tid:%i] [sn:%lli] PC %s\n",
|
2009-02-11 00:49:29 +01:00
|
|
|
(*removeList.front())->threadNumber,
|
|
|
|
(*removeList.front())->seqNum,
|
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
|
|
|
(*removeList.front())->pcState());
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
DynInstPtr inst = *removeList.front();
|
2009-05-26 18:23:13 +02:00
|
|
|
ThreadID tid = inst->threadNumber;
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
// Remove From Register Dependency Map, If Necessary
|
2011-06-20 03:43:36 +02:00
|
|
|
// archRegDepMap[tid].remove(inst);
|
2009-02-11 00:49:29 +01:00
|
|
|
|
|
|
|
// Clear if Non-Speculative
|
|
|
|
if (inst->staticInst &&
|
2011-02-12 16:14:48 +01:00
|
|
|
inst->seqNum == nonSpecSeqNum[tid] &&
|
|
|
|
nonSpecInstActive[tid] == true) {
|
2009-02-11 00:49:29 +01:00
|
|
|
nonSpecInstActive[tid] = false;
|
|
|
|
}
|
|
|
|
|
2011-06-20 03:43:34 +02:00
|
|
|
inst->onInstList = false;
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
instList[tid].erase(removeList.front());
|
|
|
|
|
|
|
|
removeList.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
removeInstsThisCycle = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InOrderCPU::cleanUpRemovedEvents()
|
|
|
|
{
|
|
|
|
while (!cpuEventRemoveList.empty()) {
|
|
|
|
Event *cpu_event = cpuEventRemoveList.front();
|
|
|
|
cpuEventRemoveList.pop();
|
|
|
|
delete cpu_event;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
InOrderCPU::dumpInsts()
|
|
|
|
{
|
|
|
|
int num = 0;
|
|
|
|
|
|
|
|
ListIt inst_list_it = instList[0].begin();
|
|
|
|
|
|
|
|
cprintf("Dumping Instruction List\n");
|
|
|
|
|
|
|
|
while (inst_list_it != instList[0].end()) {
|
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
|
|
|
cprintf("Instruction:%i\nPC:%s\n[tid:%i]\n[sn:%lli]\nIssued:%i\n"
|
2009-02-11 00:49:29 +01:00
|
|
|
"Squashed:%i\n\n",
|
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
|
|
|
num, (*inst_list_it)->pcState(),
|
|
|
|
(*inst_list_it)->threadNumber,
|
2009-02-11 00:49:29 +01:00
|
|
|
(*inst_list_it)->seqNum, (*inst_list_it)->isIssued(),
|
|
|
|
(*inst_list_it)->isSquashed());
|
|
|
|
inst_list_it++;
|
|
|
|
++num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InOrderCPU::wakeCPU()
|
|
|
|
{
|
|
|
|
if (/*activityRec.active() || */tickEvent.scheduled()) {
|
|
|
|
DPRINTF(Activity, "CPU already running.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(Activity, "Waking up CPU\n");
|
|
|
|
|
2011-01-08 06:50:29 +01:00
|
|
|
Tick extra_cycles = tickToCycles((curTick() - 1) - lastRunningCycle);
|
2010-02-01 00:28:51 +01:00
|
|
|
|
|
|
|
idleCycles += extra_cycles;
|
|
|
|
for (int stage_num = 0; stage_num < NumStages; stage_num++) {
|
|
|
|
pipelineStage[stage_num]->idleCycles += extra_cycles;
|
|
|
|
}
|
|
|
|
|
|
|
|
numCycles += extra_cycles;
|
2009-02-11 00:49:29 +01:00
|
|
|
|
2011-01-08 06:50:29 +01:00
|
|
|
schedule(&tickEvent, nextCycle(curTick()));
|
2009-02-11 00:49:29 +01:00
|
|
|
}
|
|
|
|
|
2009-09-15 07:44:48 +02:00
|
|
|
#if FULL_SYSTEM
|
2011-06-20 03:43:39 +02:00
|
|
|
// Lots of copied full system code...place into BaseCPU class?
|
2009-09-15 07:44:48 +02:00
|
|
|
void
|
|
|
|
InOrderCPU::wakeup()
|
|
|
|
{
|
2011-01-12 17:52:29 +01:00
|
|
|
if (thread[0]->status() != ThreadContext::Suspended)
|
2009-09-15 07:44:48 +02:00
|
|
|
return;
|
|
|
|
|
2011-01-12 17:52:29 +01:00
|
|
|
wakeCPU();
|
2009-09-15 07:44:48 +02:00
|
|
|
|
|
|
|
DPRINTF(Quiesce, "Suspended Processor woken\n");
|
2011-01-12 17:52:29 +01:00
|
|
|
threadContexts[0]->activate();
|
2009-09-15 07:44:48 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !FULL_SYSTEM
|
2011-06-20 03:43:38 +02:00
|
|
|
void
|
|
|
|
InOrderCPU::syscallContext(Fault fault, ThreadID tid, DynInstPtr inst, int delay)
|
|
|
|
{
|
2011-06-20 03:43:42 +02:00
|
|
|
// Syscall must be non-speculative, so squash from last stage
|
|
|
|
unsigned squash_stage = NumStages - 1;
|
|
|
|
inst->setSquashInfo(squash_stage);
|
|
|
|
|
|
|
|
// Squash In Pipeline Stage
|
|
|
|
pipelineStage[squash_stage]->setupSquash(inst, tid);
|
|
|
|
|
|
|
|
// Schedule Squash Through-out Resource Pool
|
|
|
|
resPool->scheduleEvent(
|
|
|
|
(InOrderCPU::CPUEventType)ResourcePool::SquashAll, inst, 0);
|
2011-06-20 03:43:38 +02:00
|
|
|
scheduleCpuEvent(Syscall, fault, tid, inst, delay, Syscall_Pri);
|
|
|
|
}
|
|
|
|
|
2009-02-11 00:49:29 +01:00
|
|
|
void
|
2009-05-26 18:23:13 +02:00
|
|
|
InOrderCPU::syscall(int64_t callnum, ThreadID tid)
|
2009-02-11 00:49:29 +01:00
|
|
|
{
|
|
|
|
DPRINTF(InOrderCPU, "[tid:%i] Executing syscall().\n\n", tid);
|
|
|
|
|
|
|
|
DPRINTF(Activity,"Activity: syscall() called.\n");
|
|
|
|
|
|
|
|
// Temporarily increase this by one to account for the syscall
|
|
|
|
// instruction.
|
|
|
|
++(this->thread[tid]->funcExeInst);
|
|
|
|
|
|
|
|
// Execute the actual syscall.
|
|
|
|
this->thread[tid]->syscall(callnum);
|
|
|
|
|
|
|
|
// Decrease funcExeInst by one as the normal commit will handle
|
|
|
|
// incrementing it.
|
|
|
|
--(this->thread[tid]->funcExeInst);
|
|
|
|
|
|
|
|
// Clear Non-Speculative Block Variable
|
|
|
|
nonSpecInstActive[tid] = false;
|
|
|
|
}
|
2009-09-15 07:44:48 +02:00
|
|
|
#endif
|
2009-02-11 00:49:29 +01:00
|
|
|
|
2009-05-12 21:01:14 +02:00
|
|
|
TheISA::TLB*
|
2009-05-12 21:01:13 +02:00
|
|
|
InOrderCPU::getITBPtr()
|
|
|
|
{
|
2009-05-12 21:01:16 +02:00
|
|
|
CacheUnit *itb_res =
|
|
|
|
dynamic_cast<CacheUnit*>(resPool->getResource(fetchPortIdx));
|
2009-05-12 21:01:14 +02:00
|
|
|
return itb_res->tlb();
|
2009-05-12 21:01:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-12 21:01:14 +02:00
|
|
|
TheISA::TLB*
|
2009-05-12 21:01:13 +02:00
|
|
|
InOrderCPU::getDTBPtr()
|
|
|
|
{
|
2009-05-12 21:01:16 +02:00
|
|
|
CacheUnit *dtb_res =
|
|
|
|
dynamic_cast<CacheUnit*>(resPool->getResource(dataPortIdx));
|
2009-05-12 21:01:14 +02:00
|
|
|
return dtb_res->tlb();
|
2009-05-12 21:01:13 +02:00
|
|
|
}
|
2009-05-12 21:01:16 +02:00
|
|
|
|
Decode: Pull instruction decoding out of the StaticInst class into its own.
This change pulls the instruction decoding machinery (including caches) out of
the StaticInst class and puts it into its own class. This has a few intrinsic
benefits. First, the StaticInst code, which has gotten to be quite large, gets
simpler. Second, the code that handles decode caching is now separated out
into its own component and can be looked at in isolation, making it easier to
understand. I took the opportunity to restructure the code a bit which will
hopefully also help.
Beyond that, this change also lays some ground work for each ISA to have its
own, potentially stateful decode object. We'd be able to include less
contextualizing information in the ExtMachInst objects since that context
would be applied at the decoder. Also, the decoder could "know" ahead of time
that all the instructions it's going to see are going to be, for instance, 64
bit mode, and it will have one less thing to check when it decodes them.
Because the decode caching mechanism has been separated out, it's now possible
to have multiple caches which correspond to different types of decoding
context. Having one cache for each element of the cross product of different
configurations may become prohibitive, so it may be desirable to clear out the
cache when relatively static state changes and not to have one for each
setting.
Because the decode function is no longer universally accessible as a static
member of the StaticInst class, a new function was added to the ThreadContexts
that returns the applicable decode object.
2011-09-09 11:30:01 +02:00
|
|
|
Decoder *
|
|
|
|
InOrderCPU::getDecoderPtr()
|
|
|
|
{
|
|
|
|
FetchUnit *fetch_res =
|
|
|
|
dynamic_cast<FetchUnit*>(resPool->getResource(fetchPortIdx));
|
|
|
|
return &fetch_res->decoder;
|
|
|
|
}
|
|
|
|
|
2009-05-12 21:01:16 +02:00
|
|
|
Fault
|
2010-08-13 15:16:02 +02:00
|
|
|
InOrderCPU::read(DynInstPtr inst, Addr addr,
|
|
|
|
uint8_t *data, unsigned size, unsigned flags)
|
2009-05-12 21:01:16 +02:00
|
|
|
{
|
|
|
|
//@TODO: Generalize name "CacheUnit" to "MemUnit" just in case
|
|
|
|
// you want to run w/out caches?
|
2010-01-31 23:18:15 +01:00
|
|
|
CacheUnit *cache_res =
|
|
|
|
dynamic_cast<CacheUnit*>(resPool->getResource(dataPortIdx));
|
2009-05-12 21:01:16 +02:00
|
|
|
|
2010-08-13 15:16:02 +02:00
|
|
|
return cache_res->read(inst, addr, data, size, flags);
|
2009-05-12 21:01:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Fault
|
2010-08-13 15:16:02 +02:00
|
|
|
InOrderCPU::write(DynInstPtr inst, uint8_t *data, unsigned size,
|
|
|
|
Addr addr, unsigned flags, uint64_t *write_res)
|
2009-05-12 21:01:16 +02:00
|
|
|
{
|
|
|
|
//@TODO: Generalize name "CacheUnit" to "MemUnit" just in case
|
|
|
|
// you want to run w/out caches?
|
|
|
|
CacheUnit *cache_res =
|
|
|
|
dynamic_cast<CacheUnit*>(resPool->getResource(dataPortIdx));
|
2010-08-13 15:16:02 +02:00
|
|
|
return cache_res->write(inst, data, size, addr, flags, write_res);
|
2009-05-12 21:01:16 +02:00
|
|
|
}
|