2006-05-16 23:36:50 +02:00
|
|
|
/*
|
2010-11-08 20:58:22 +01:00
|
|
|
* Copyright (c) 2010 ARM Limited
|
|
|
|
* All rights reserved
|
|
|
|
*
|
|
|
|
* The license below extends only to copyright in the software and shall
|
|
|
|
* not be construed as granting a license to any other intellectual
|
|
|
|
* property including but not limited to intellectual property relating
|
|
|
|
* to a hardware implementation of the functionality of the software
|
|
|
|
* licensed hereunder. You may use the software subject to the license
|
|
|
|
* terms below provided that you ensure that this notice is replicated
|
|
|
|
* unmodified and in its entirety in all distributions of the software,
|
|
|
|
* modified or unmodified, in source code or in binary form.
|
|
|
|
*
|
2006-05-16 23:36:50 +02:00
|
|
|
* Copyright (c) 2002-2005 The Regents of The University of Michigan
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2006-06-01 01:26:56 +02:00
|
|
|
*
|
|
|
|
* Authors: Steve Reinhardt
|
2006-05-16 23:36:50 +02:00
|
|
|
*/
|
|
|
|
|
2006-10-08 19:53:24 +02:00
|
|
|
#include "arch/locked_mem.hh"
|
2011-03-02 08:18:47 +01:00
|
|
|
#include "arch/mmapped_ipr.hh"
|
2006-05-16 23:36:50 +02:00
|
|
|
#include "arch/utility.hh"
|
2007-02-12 19:06:30 +01:00
|
|
|
#include "base/bigint.hh"
|
2009-09-23 17:34:21 +02:00
|
|
|
#include "config/the_isa.hh"
|
2006-05-16 23:36:50 +02:00
|
|
|
#include "cpu/exetrace.hh"
|
|
|
|
#include "cpu/simple/timing.hh"
|
2006-10-20 08:38:45 +02:00
|
|
|
#include "mem/packet.hh"
|
|
|
|
#include "mem/packet_access.hh"
|
2007-07-24 06:51:38 +02:00
|
|
|
#include "params/TimingSimpleCPU.hh"
|
2010-09-14 04:26:03 +02:00
|
|
|
#include "sim/faults.hh"
|
2006-07-13 02:22:07 +02:00
|
|
|
#include "sim/system.hh"
|
2006-05-16 23:36:50 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace TheISA;
|
|
|
|
|
2006-07-07 21:15:11 +02:00
|
|
|
Port *
|
|
|
|
TimingSimpleCPU::getPort(const std::string &if_name, int idx)
|
|
|
|
{
|
|
|
|
if (if_name == "dcache_port")
|
|
|
|
return &dcachePort;
|
|
|
|
else if (if_name == "icache_port")
|
|
|
|
return &icachePort;
|
|
|
|
else
|
|
|
|
panic("No Such Port\n");
|
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
TimingSimpleCPU::init()
|
|
|
|
{
|
|
|
|
BaseCPU::init();
|
|
|
|
#if FULL_SYSTEM
|
2006-06-06 23:32:21 +02:00
|
|
|
for (int i = 0; i < threadContexts.size(); ++i) {
|
|
|
|
ThreadContext *tc = threadContexts[i];
|
2006-05-16 23:36:50 +02:00
|
|
|
|
|
|
|
// initialize CPU, including PC
|
2008-11-03 03:56:57 +01:00
|
|
|
TheISA::initCPU(tc, _cpuId);
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
Tick
|
2006-10-20 09:10:12 +02:00
|
|
|
TimingSimpleCPU::CpuPort::recvAtomic(PacketPtr pkt)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
|
|
|
panic("TimingSimpleCPU doesn't expect recvAtomic callback!");
|
2011-01-08 06:50:29 +01:00
|
|
|
return curTick();
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-10-20 09:10:12 +02:00
|
|
|
TimingSimpleCPU::CpuPort::recvFunctional(PacketPtr pkt)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
2006-10-09 02:30:42 +02:00
|
|
|
//No internal storage to update, jusst return
|
|
|
|
return;
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimingSimpleCPU::CpuPort::recvStatusChange(Status status)
|
|
|
|
{
|
2006-11-14 00:51:16 +01:00
|
|
|
if (status == RangeChange) {
|
|
|
|
if (!snoopRangeSent) {
|
|
|
|
snoopRangeSent = true;
|
|
|
|
sendStatusChange(Port::RangeChange);
|
|
|
|
}
|
2006-05-19 04:54:19 +02:00
|
|
|
return;
|
2006-11-14 00:51:16 +01:00
|
|
|
}
|
2006-05-19 04:54:19 +02:00
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
panic("TimingSimpleCPU doesn't expect recvStatusChange callback!");
|
|
|
|
}
|
|
|
|
|
2006-07-21 01:00:40 +02:00
|
|
|
|
|
|
|
void
|
2006-10-20 09:10:12 +02:00
|
|
|
TimingSimpleCPU::CpuPort::TickEvent::schedule(PacketPtr _pkt, Tick t)
|
2006-07-21 01:00:40 +02:00
|
|
|
{
|
|
|
|
pkt = _pkt;
|
2008-10-09 13:58:24 +02:00
|
|
|
cpu->schedule(this, t);
|
2006-07-21 01:00:40 +02:00
|
|
|
}
|
|
|
|
|
2008-08-11 21:22:16 +02:00
|
|
|
TimingSimpleCPU::TimingSimpleCPU(TimingSimpleCPUParams *p)
|
2009-02-25 19:16:15 +01:00
|
|
|
: BaseSimpleCPU(p), fetchTranslation(this), icachePort(this, p->clock),
|
|
|
|
dcachePort(this, p->clock), fetchEvent(this)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
|
|
|
_status = Idle;
|
2006-11-14 00:51:16 +01:00
|
|
|
|
|
|
|
icachePort.snoopRangeSent = false;
|
|
|
|
dcachePort.snoopRangeSent = false;
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
ifetch_pkt = dcache_pkt = NULL;
|
2006-07-05 23:59:33 +02:00
|
|
|
drainEvent = NULL;
|
2006-10-08 06:55:05 +02:00
|
|
|
previousTick = 0;
|
2006-07-13 02:22:07 +02:00
|
|
|
changeState(SimObject::Running);
|
2011-02-07 07:14:17 +01:00
|
|
|
system->totalNumInsts = 0;
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TimingSimpleCPU::~TimingSimpleCPU()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimingSimpleCPU::serialize(ostream &os)
|
|
|
|
{
|
2006-07-12 23:11:57 +02:00
|
|
|
SimObject::State so_state = SimObject::getState();
|
|
|
|
SERIALIZE_ENUM(so_state);
|
2006-06-30 01:45:24 +02:00
|
|
|
BaseSimpleCPU::serialize(os);
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimingSimpleCPU::unserialize(Checkpoint *cp, const string §ion)
|
|
|
|
{
|
2006-07-12 23:11:57 +02:00
|
|
|
SimObject::State so_state;
|
|
|
|
UNSERIALIZE_ENUM(so_state);
|
2006-06-30 01:45:24 +02:00
|
|
|
BaseSimpleCPU::unserialize(cp, section);
|
|
|
|
}
|
|
|
|
|
2006-07-13 02:22:07 +02:00
|
|
|
unsigned int
|
2006-07-05 23:59:33 +02:00
|
|
|
TimingSimpleCPU::drain(Event *drain_event)
|
2006-06-30 01:45:24 +02:00
|
|
|
{
|
2006-07-05 23:59:33 +02:00
|
|
|
// TimingSimpleCPU is ready to drain if it's not waiting for
|
2006-06-30 01:45:24 +02:00
|
|
|
// an access to complete.
|
2008-07-01 16:24:09 +02:00
|
|
|
if (_status == Idle || _status == Running || _status == SwitchedOut) {
|
2006-07-13 02:22:07 +02:00
|
|
|
changeState(SimObject::Drained);
|
|
|
|
return 0;
|
2006-06-30 01:45:24 +02:00
|
|
|
} else {
|
2006-07-05 23:59:33 +02:00
|
|
|
changeState(SimObject::Draining);
|
|
|
|
drainEvent = drain_event;
|
2006-07-13 02:22:07 +02:00
|
|
|
return 1;
|
2006-06-30 01:45:24 +02:00
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-06-30 01:45:24 +02:00
|
|
|
TimingSimpleCPU::resume()
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
2007-11-08 16:46:41 +01:00
|
|
|
DPRINTF(SimpleCPU, "Resume\n");
|
2006-06-30 01:45:24 +02:00
|
|
|
if (_status != SwitchedOut && _status != Idle) {
|
2007-07-24 06:51:38 +02:00
|
|
|
assert(system->getMemoryMode() == Enums::timing);
|
2006-10-12 00:44:48 +02:00
|
|
|
|
2008-10-27 23:18:04 +01:00
|
|
|
if (fetchEvent.scheduled())
|
|
|
|
deschedule(fetchEvent);
|
2006-07-12 23:11:57 +02:00
|
|
|
|
2008-10-27 23:18:04 +01:00
|
|
|
schedule(fetchEvent, nextCycle());
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
2006-06-30 01:45:24 +02:00
|
|
|
|
2006-07-13 02:22:07 +02:00
|
|
|
changeState(SimObject::Running);
|
2006-06-30 01:45:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimingSimpleCPU::switchOut()
|
|
|
|
{
|
2008-07-01 16:24:09 +02:00
|
|
|
assert(_status == Running || _status == Idle);
|
2006-06-30 01:45:24 +02:00
|
|
|
_status = SwitchedOut;
|
2011-01-08 06:50:29 +01:00
|
|
|
numCycles += tickToCycles(curTick() - previousTick);
|
2006-07-07 21:38:15 +02:00
|
|
|
|
|
|
|
// If we've been scheduled to resume but are then told to switch out,
|
|
|
|
// we'll need to cancel it.
|
2008-10-27 23:18:04 +01:00
|
|
|
if (fetchEvent.scheduled())
|
2008-10-09 13:58:24 +02:00
|
|
|
deschedule(fetchEvent);
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TimingSimpleCPU::takeOverFrom(BaseCPU *oldCPU)
|
|
|
|
{
|
2007-03-09 16:06:09 +01:00
|
|
|
BaseCPU::takeOverFrom(oldCPU, &icachePort, &dcachePort);
|
2006-05-16 23:36:50 +02:00
|
|
|
|
2006-06-06 23:32:21 +02:00
|
|
|
// if any of this CPU's ThreadContexts are active, mark the CPU as
|
2006-05-16 23:36:50 +02:00
|
|
|
// running and schedule its tick event.
|
2006-06-06 23:32:21 +02:00
|
|
|
for (int i = 0; i < threadContexts.size(); ++i) {
|
|
|
|
ThreadContext *tc = threadContexts[i];
|
|
|
|
if (tc->status() == ThreadContext::Active && _status != Running) {
|
2006-05-16 23:36:50 +02:00
|
|
|
_status = Running;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-10-08 06:55:05 +02:00
|
|
|
|
2006-10-10 01:13:06 +02:00
|
|
|
if (_status != Running) {
|
|
|
|
_status = Idle;
|
|
|
|
}
|
2007-10-18 19:15:08 +02:00
|
|
|
assert(threadContexts.size() == 1);
|
2011-01-08 06:50:29 +01:00
|
|
|
previousTick = curTick();
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TimingSimpleCPU::activateContext(int thread_num, int delay)
|
|
|
|
{
|
2007-11-08 16:46:41 +01:00
|
|
|
DPRINTF(SimpleCPU, "ActivateContext %d (%d cycles)\n", thread_num, delay);
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
assert(thread_num == 0);
|
2006-06-07 21:29:53 +02:00
|
|
|
assert(thread);
|
2006-05-16 23:36:50 +02:00
|
|
|
|
|
|
|
assert(_status == Idle);
|
|
|
|
|
|
|
|
notIdleFraction++;
|
|
|
|
_status = Running;
|
2006-11-29 22:07:55 +01:00
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
// kick things off by initiating the fetch of the next instruction
|
2011-01-08 06:50:29 +01:00
|
|
|
schedule(fetchEvent, nextCycle(curTick() + ticks(delay)));
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TimingSimpleCPU::suspendContext(int thread_num)
|
|
|
|
{
|
2007-11-08 16:46:41 +01:00
|
|
|
DPRINTF(SimpleCPU, "SuspendContext %d\n", thread_num);
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
assert(thread_num == 0);
|
2006-06-07 21:29:53 +02:00
|
|
|
assert(thread);
|
2006-05-16 23:36:50 +02:00
|
|
|
|
2009-04-19 11:23:29 +02:00
|
|
|
if (_status == Idle)
|
|
|
|
return;
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
assert(_status == Running);
|
|
|
|
|
2006-05-26 20:33:43 +02:00
|
|
|
// just change status to Idle... if status != Running,
|
|
|
|
// completeInst() will not initiate fetch of next instruction.
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
notIdleFraction--;
|
|
|
|
_status = Idle;
|
|
|
|
}
|
|
|
|
|
2008-11-10 06:56:28 +01:00
|
|
|
bool
|
|
|
|
TimingSimpleCPU::handleReadPacket(PacketPtr pkt)
|
|
|
|
{
|
|
|
|
RequestPtr req = pkt->req;
|
2011-03-02 08:18:47 +01:00
|
|
|
if (req->isMmappedIpr()) {
|
2008-11-10 06:56:28 +01:00
|
|
|
Tick delay;
|
|
|
|
delay = TheISA::handleIprRead(thread->getTC(), pkt);
|
2011-01-08 06:50:29 +01:00
|
|
|
new IprEvent(pkt, this, nextCycle(curTick() + delay));
|
2008-11-10 06:56:28 +01:00
|
|
|
_status = DcacheWaitResponse;
|
|
|
|
dcache_pkt = NULL;
|
|
|
|
} else if (!dcachePort.sendTiming(pkt)) {
|
|
|
|
_status = DcacheRetry;
|
|
|
|
dcache_pkt = pkt;
|
|
|
|
} else {
|
|
|
|
_status = DcacheWaitResponse;
|
|
|
|
// memory system takes ownership of packet
|
|
|
|
dcache_pkt = NULL;
|
|
|
|
}
|
|
|
|
return dcache_pkt == NULL;
|
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
|
2009-02-25 19:16:15 +01:00
|
|
|
void
|
2010-02-12 20:53:19 +01:00
|
|
|
TimingSimpleCPU::sendData(RequestPtr req, uint8_t *data, uint64_t *res,
|
|
|
|
bool read)
|
2008-11-14 08:30:37 +01:00
|
|
|
{
|
2009-02-25 19:16:15 +01:00
|
|
|
PacketPtr pkt;
|
|
|
|
buildPacket(pkt, req, read);
|
2010-09-30 16:35:19 +02:00
|
|
|
pkt->dataDynamicArray<uint8_t>(data);
|
2009-02-25 19:16:15 +01:00
|
|
|
if (req->getFlags().isSet(Request::NO_ACCESS)) {
|
|
|
|
assert(!dcache_pkt);
|
|
|
|
pkt->makeResponse();
|
|
|
|
completeDataAccess(pkt);
|
|
|
|
} else if (read) {
|
|
|
|
handleReadPacket(pkt);
|
|
|
|
} else {
|
|
|
|
bool do_access = true; // flag to suppress cache access
|
2008-11-14 08:30:37 +01:00
|
|
|
|
2009-04-20 06:44:15 +02:00
|
|
|
if (req->isLLSC()) {
|
2009-02-25 19:16:15 +01:00
|
|
|
do_access = TheISA::handleLockedWrite(thread, req);
|
|
|
|
} else if (req->isCondSwap()) {
|
|
|
|
assert(res);
|
|
|
|
req->setExtraData(*res);
|
|
|
|
}
|
2008-11-14 08:30:37 +01:00
|
|
|
|
2009-02-25 19:16:15 +01:00
|
|
|
if (do_access) {
|
|
|
|
dcache_pkt = pkt;
|
|
|
|
handleWritePacket();
|
|
|
|
} else {
|
|
|
|
_status = DcacheWaitResponse;
|
|
|
|
completeDataAccess(pkt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-02-12 20:53:19 +01:00
|
|
|
TimingSimpleCPU::sendSplitData(RequestPtr req1, RequestPtr req2,
|
|
|
|
RequestPtr req, uint8_t *data, bool read)
|
2009-02-25 19:16:15 +01:00
|
|
|
{
|
|
|
|
PacketPtr pkt1, pkt2;
|
|
|
|
buildSplitPacket(pkt1, pkt2, req1, req2, req, data, read);
|
|
|
|
if (req->getFlags().isSet(Request::NO_ACCESS)) {
|
|
|
|
assert(!dcache_pkt);
|
|
|
|
pkt1->makeResponse();
|
|
|
|
completeDataAccess(pkt1);
|
|
|
|
} else if (read) {
|
2011-02-07 07:14:18 +01:00
|
|
|
SplitFragmentSenderState * send_state =
|
|
|
|
dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState);
|
2009-02-25 19:16:15 +01:00
|
|
|
if (handleReadPacket(pkt1)) {
|
|
|
|
send_state->clearFromParent();
|
2011-02-07 07:14:18 +01:00
|
|
|
send_state = dynamic_cast<SplitFragmentSenderState *>(
|
|
|
|
pkt2->senderState);
|
2009-02-25 19:16:15 +01:00
|
|
|
if (handleReadPacket(pkt2)) {
|
|
|
|
send_state->clearFromParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dcache_pkt = pkt1;
|
2011-02-07 07:14:18 +01:00
|
|
|
SplitFragmentSenderState * send_state =
|
|
|
|
dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState);
|
2009-02-25 19:16:15 +01:00
|
|
|
if (handleWritePacket()) {
|
|
|
|
send_state->clearFromParent();
|
|
|
|
dcache_pkt = pkt2;
|
2011-02-07 07:14:18 +01:00
|
|
|
send_state = dynamic_cast<SplitFragmentSenderState *>(
|
|
|
|
pkt2->senderState);
|
2009-02-25 19:16:15 +01:00
|
|
|
if (handleWritePacket()) {
|
|
|
|
send_state->clearFromParent();
|
|
|
|
}
|
|
|
|
}
|
2009-02-25 19:15:34 +01:00
|
|
|
}
|
2009-02-25 19:16:15 +01:00
|
|
|
}
|
2008-11-14 08:30:37 +01:00
|
|
|
|
2009-02-25 19:16:15 +01:00
|
|
|
void
|
|
|
|
TimingSimpleCPU::translationFault(Fault fault)
|
|
|
|
{
|
2009-11-11 06:10:18 +01:00
|
|
|
// fault may be NoFault in cases where a fault is suppressed,
|
|
|
|
// for instance prefetches.
|
2011-01-08 06:50:29 +01:00
|
|
|
numCycles += tickToCycles(curTick() - previousTick);
|
|
|
|
previousTick = curTick();
|
2008-11-14 08:30:37 +01:00
|
|
|
|
2009-02-25 19:16:15 +01:00
|
|
|
if (traceData) {
|
|
|
|
// Since there was a fault, we shouldn't trace this instruction.
|
|
|
|
delete traceData;
|
|
|
|
traceData = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
postExecute();
|
|
|
|
|
|
|
|
if (getState() == SimObject::Draining) {
|
|
|
|
advancePC(fault);
|
|
|
|
completeDrain();
|
|
|
|
} else {
|
|
|
|
advanceInst(fault);
|
|
|
|
}
|
2008-11-14 08:30:37 +01:00
|
|
|
}
|
|
|
|
|
2009-02-25 19:16:15 +01:00
|
|
|
void
|
|
|
|
TimingSimpleCPU::buildPacket(PacketPtr &pkt, RequestPtr req, bool read)
|
2008-11-14 08:30:37 +01:00
|
|
|
{
|
|
|
|
MemCmd cmd;
|
2009-02-25 19:16:15 +01:00
|
|
|
if (read) {
|
2008-11-14 08:30:37 +01:00
|
|
|
cmd = MemCmd::ReadReq;
|
2009-04-20 06:44:15 +02:00
|
|
|
if (req->isLLSC())
|
2008-11-14 08:30:37 +01:00
|
|
|
cmd = MemCmd::LoadLockedReq;
|
|
|
|
} else {
|
|
|
|
cmd = MemCmd::WriteReq;
|
2009-04-20 06:44:15 +02:00
|
|
|
if (req->isLLSC()) {
|
2008-11-14 08:30:37 +01:00
|
|
|
cmd = MemCmd::StoreCondReq;
|
|
|
|
} else if (req->isSwap()) {
|
|
|
|
cmd = MemCmd::SwapReq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pkt = new Packet(req, cmd, Packet::Broadcast);
|
2009-02-25 19:16:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimingSimpleCPU::buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2,
|
|
|
|
RequestPtr req1, RequestPtr req2, RequestPtr req,
|
|
|
|
uint8_t *data, bool read)
|
|
|
|
{
|
|
|
|
pkt1 = pkt2 = NULL;
|
|
|
|
|
2011-03-02 08:18:47 +01:00
|
|
|
assert(!req1->isMmappedIpr() && !req2->isMmappedIpr());
|
2009-02-25 19:16:15 +01:00
|
|
|
|
|
|
|
if (req->getFlags().isSet(Request::NO_ACCESS)) {
|
|
|
|
buildPacket(pkt1, req, read);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
buildPacket(pkt1, req1, read);
|
|
|
|
buildPacket(pkt2, req2, read);
|
|
|
|
|
|
|
|
req->setPhys(req1->getPaddr(), req->getSize(), req1->getFlags());
|
|
|
|
PacketPtr pkt = new Packet(req, pkt1->cmd.responseCommand(),
|
|
|
|
Packet::Broadcast);
|
|
|
|
|
2010-09-30 16:35:19 +02:00
|
|
|
pkt->dataDynamicArray<uint8_t>(data);
|
2009-02-25 19:16:15 +01:00
|
|
|
pkt1->dataStatic<uint8_t>(data);
|
|
|
|
pkt2->dataStatic<uint8_t>(data + req1->getSize());
|
|
|
|
|
|
|
|
SplitMainSenderState * main_send_state = new SplitMainSenderState;
|
|
|
|
pkt->senderState = main_send_state;
|
|
|
|
main_send_state->fragments[0] = pkt1;
|
|
|
|
main_send_state->fragments[1] = pkt2;
|
|
|
|
main_send_state->outstanding = 2;
|
|
|
|
pkt1->senderState = new SplitFragmentSenderState(pkt, 0);
|
|
|
|
pkt2->senderState = new SplitFragmentSenderState(pkt, 1);
|
2008-11-14 08:30:37 +01:00
|
|
|
}
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
Fault
|
2010-08-13 15:16:02 +02:00
|
|
|
TimingSimpleCPU::readBytes(Addr addr, uint8_t *data,
|
|
|
|
unsigned size, unsigned flags)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
2008-11-10 06:56:28 +01:00
|
|
|
Fault fault;
|
|
|
|
const int asid = 0;
|
2009-05-26 18:23:13 +02:00
|
|
|
const ThreadID tid = 0;
|
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
|
|
|
const Addr pc = thread->instAddr();
|
2009-06-05 08:21:12 +02:00
|
|
|
unsigned block_size = dcachePort.peerBlockSize();
|
2010-02-12 20:53:19 +01:00
|
|
|
BaseTLB::Mode mode = BaseTLB::Read;
|
2008-11-10 06:56:28 +01:00
|
|
|
|
2010-03-23 16:50:57 +01:00
|
|
|
if (traceData) {
|
|
|
|
traceData->setAddr(addr);
|
|
|
|
}
|
|
|
|
|
2010-08-13 15:16:02 +02:00
|
|
|
RequestPtr req = new Request(asid, addr, size,
|
2009-05-26 18:23:13 +02:00
|
|
|
flags, pc, _cpuId, tid);
|
2008-11-14 08:30:37 +01:00
|
|
|
|
2010-08-13 15:16:02 +02:00
|
|
|
Addr split_addr = roundDown(addr + size - 1, block_size);
|
2008-11-14 08:30:37 +01:00
|
|
|
assert(split_addr <= addr || split_addr - addr < block_size);
|
|
|
|
|
2009-02-25 19:16:15 +01:00
|
|
|
_status = DTBWaitResponse;
|
2008-11-14 08:30:37 +01:00
|
|
|
if (split_addr > addr) {
|
2009-02-25 19:16:15 +01:00
|
|
|
RequestPtr req1, req2;
|
2009-04-20 06:44:15 +02:00
|
|
|
assert(!req->isLLSC() && !req->isSwap());
|
2009-02-25 19:16:15 +01:00
|
|
|
req->splitOnVaddr(split_addr, req1, req2);
|
|
|
|
|
2010-02-12 20:53:19 +01:00
|
|
|
WholeTranslationState *state =
|
2010-08-13 15:16:02 +02:00
|
|
|
new WholeTranslationState(req, req1, req2, new uint8_t[size],
|
2010-02-12 20:53:19 +01:00
|
|
|
NULL, mode);
|
|
|
|
DataTranslation<TimingSimpleCPU> *trans1 =
|
|
|
|
new DataTranslation<TimingSimpleCPU>(this, state, 0);
|
|
|
|
DataTranslation<TimingSimpleCPU> *trans2 =
|
|
|
|
new DataTranslation<TimingSimpleCPU>(this, state, 1);
|
|
|
|
|
|
|
|
thread->dtb->translateTiming(req1, tc, trans1, mode);
|
|
|
|
thread->dtb->translateTiming(req2, tc, trans2, mode);
|
2008-11-10 06:56:28 +01:00
|
|
|
} else {
|
2010-02-12 20:53:19 +01:00
|
|
|
WholeTranslationState *state =
|
2010-08-13 15:16:02 +02:00
|
|
|
new WholeTranslationState(req, new uint8_t[size], NULL, mode);
|
2010-02-12 20:53:19 +01:00
|
|
|
DataTranslation<TimingSimpleCPU> *translation
|
|
|
|
= new DataTranslation<TimingSimpleCPU>(this, state);
|
|
|
|
thread->dtb->translateTiming(req, tc, translation, mode);
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
2008-11-10 06:56:28 +01:00
|
|
|
return NoFault;
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
2010-08-13 15:16:02 +02:00
|
|
|
template <class T>
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::read(Addr addr, T &data, unsigned flags)
|
|
|
|
{
|
|
|
|
return readBytes(addr, (uint8_t *)&data, sizeof(T), flags);
|
|
|
|
}
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
|
|
|
|
2007-02-12 19:06:30 +01:00
|
|
|
template
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::read(Addr addr, Twin64_t &data, unsigned flags);
|
|
|
|
|
2007-03-03 04:34:51 +01:00
|
|
|
template
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::read(Addr addr, Twin32_t &data, unsigned flags);
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
template
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::read(Addr addr, uint64_t &data, unsigned flags);
|
|
|
|
|
|
|
|
template
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::read(Addr addr, uint32_t &data, unsigned flags);
|
|
|
|
|
|
|
|
template
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::read(Addr addr, uint16_t &data, unsigned flags);
|
|
|
|
|
|
|
|
template
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::read(Addr addr, uint8_t &data, unsigned flags);
|
|
|
|
|
|
|
|
#endif //DOXYGEN_SHOULD_SKIP_THIS
|
|
|
|
|
|
|
|
template<>
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::read(Addr addr, double &data, unsigned flags)
|
|
|
|
{
|
|
|
|
return read(addr, *(uint64_t*)&data, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::read(Addr addr, float &data, unsigned flags)
|
|
|
|
{
|
|
|
|
return read(addr, *(uint32_t*)&data, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::read(Addr addr, int32_t &data, unsigned flags)
|
|
|
|
{
|
|
|
|
return read(addr, (uint32_t&)data, flags);
|
|
|
|
}
|
|
|
|
|
2008-11-10 06:56:28 +01:00
|
|
|
bool
|
|
|
|
TimingSimpleCPU::handleWritePacket()
|
|
|
|
{
|
|
|
|
RequestPtr req = dcache_pkt->req;
|
2011-03-02 08:18:47 +01:00
|
|
|
if (req->isMmappedIpr()) {
|
2008-11-10 06:56:28 +01:00
|
|
|
Tick delay;
|
|
|
|
delay = TheISA::handleIprWrite(thread->getTC(), dcache_pkt);
|
2011-01-08 06:50:29 +01:00
|
|
|
new IprEvent(dcache_pkt, this, nextCycle(curTick() + delay));
|
2008-11-10 06:56:28 +01:00
|
|
|
_status = DcacheWaitResponse;
|
|
|
|
dcache_pkt = NULL;
|
|
|
|
} else if (!dcachePort.sendTiming(dcache_pkt)) {
|
|
|
|
_status = DcacheRetry;
|
|
|
|
} else {
|
|
|
|
_status = DcacheWaitResponse;
|
|
|
|
// memory system takes ownership of packet
|
|
|
|
dcache_pkt = NULL;
|
|
|
|
}
|
|
|
|
return dcache_pkt == NULL;
|
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
|
|
|
|
Fault
|
2010-08-13 15:16:02 +02:00
|
|
|
TimingSimpleCPU::writeTheseBytes(uint8_t *data, unsigned size,
|
|
|
|
Addr addr, unsigned flags, uint64_t *res)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
2008-11-10 06:56:28 +01:00
|
|
|
const int asid = 0;
|
2009-05-26 18:23:13 +02:00
|
|
|
const ThreadID tid = 0;
|
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
|
|
|
const Addr pc = thread->instAddr();
|
2009-06-05 08:21:12 +02:00
|
|
|
unsigned block_size = dcachePort.peerBlockSize();
|
2010-02-12 20:53:19 +01:00
|
|
|
BaseTLB::Mode mode = BaseTLB::Write;
|
2008-11-10 06:56:28 +01:00
|
|
|
|
2010-03-23 16:50:57 +01:00
|
|
|
if (traceData) {
|
|
|
|
traceData->setAddr(addr);
|
|
|
|
}
|
|
|
|
|
2010-08-13 15:16:02 +02:00
|
|
|
RequestPtr req = new Request(asid, addr, size,
|
2009-05-26 18:23:13 +02:00
|
|
|
flags, pc, _cpuId, tid);
|
2008-11-10 06:56:28 +01:00
|
|
|
|
2010-08-13 15:16:02 +02:00
|
|
|
Addr split_addr = roundDown(addr + size - 1, block_size);
|
2008-11-14 08:30:37 +01:00
|
|
|
assert(split_addr <= addr || split_addr - addr < block_size);
|
2008-11-10 06:56:28 +01:00
|
|
|
|
2009-02-25 19:16:15 +01:00
|
|
|
_status = DTBWaitResponse;
|
2008-11-14 08:30:37 +01:00
|
|
|
if (split_addr > addr) {
|
2009-02-25 19:16:15 +01:00
|
|
|
RequestPtr req1, req2;
|
2009-04-20 06:44:15 +02:00
|
|
|
assert(!req->isLLSC() && !req->isSwap());
|
2009-02-25 19:16:15 +01:00
|
|
|
req->splitOnVaddr(split_addr, req1, req2);
|
|
|
|
|
2010-02-12 20:53:19 +01:00
|
|
|
WholeTranslationState *state =
|
2010-08-13 15:16:02 +02:00
|
|
|
new WholeTranslationState(req, req1, req2, data, res, mode);
|
2010-02-12 20:53:19 +01:00
|
|
|
DataTranslation<TimingSimpleCPU> *trans1 =
|
|
|
|
new DataTranslation<TimingSimpleCPU>(this, state, 0);
|
|
|
|
DataTranslation<TimingSimpleCPU> *trans2 =
|
|
|
|
new DataTranslation<TimingSimpleCPU>(this, state, 1);
|
|
|
|
|
|
|
|
thread->dtb->translateTiming(req1, tc, trans1, mode);
|
|
|
|
thread->dtb->translateTiming(req2, tc, trans2, mode);
|
2008-11-10 06:56:28 +01:00
|
|
|
} else {
|
2010-02-12 20:53:19 +01:00
|
|
|
WholeTranslationState *state =
|
2010-08-13 15:16:02 +02:00
|
|
|
new WholeTranslationState(req, data, res, mode);
|
2010-02-12 20:53:19 +01:00
|
|
|
DataTranslation<TimingSimpleCPU> *translation =
|
|
|
|
new DataTranslation<TimingSimpleCPU>(this, state);
|
|
|
|
thread->dtb->translateTiming(req, tc, translation, mode);
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 16:50:57 +01:00
|
|
|
// Translation faults will be returned via finishTranslation()
|
2008-11-10 06:56:28 +01:00
|
|
|
return NoFault;
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
2010-08-13 15:16:02 +02:00
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::writeBytes(uint8_t *data, unsigned size,
|
|
|
|
Addr addr, unsigned flags, uint64_t *res)
|
|
|
|
{
|
|
|
|
uint8_t *newData = new uint8_t[size];
|
|
|
|
memcpy(newData, data, size);
|
|
|
|
return writeTheseBytes(newData, size, addr, flags, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::write(T data, Addr addr, unsigned flags, uint64_t *res)
|
|
|
|
{
|
|
|
|
if (traceData) {
|
|
|
|
traceData->setData(data);
|
|
|
|
}
|
2010-09-30 16:35:19 +02:00
|
|
|
T *dataP = (T*) new uint8_t[sizeof(T)];
|
2010-08-13 15:16:02 +02:00
|
|
|
*dataP = TheISA::htog(data);
|
|
|
|
|
|
|
|
return writeTheseBytes((uint8_t *)dataP, sizeof(T), addr, flags, res);
|
|
|
|
}
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
|
|
|
|
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
2007-03-11 23:12:33 +01:00
|
|
|
template
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::write(Twin32_t data, Addr addr,
|
|
|
|
unsigned flags, uint64_t *res);
|
|
|
|
|
|
|
|
template
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::write(Twin64_t data, Addr addr,
|
|
|
|
unsigned flags, uint64_t *res);
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
template
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::write(uint64_t data, Addr addr,
|
|
|
|
unsigned flags, uint64_t *res);
|
|
|
|
|
|
|
|
template
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::write(uint32_t data, Addr addr,
|
|
|
|
unsigned flags, uint64_t *res);
|
|
|
|
|
|
|
|
template
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::write(uint16_t data, Addr addr,
|
|
|
|
unsigned flags, uint64_t *res);
|
|
|
|
|
|
|
|
template
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::write(uint8_t data, Addr addr,
|
|
|
|
unsigned flags, uint64_t *res);
|
|
|
|
|
|
|
|
#endif //DOXYGEN_SHOULD_SKIP_THIS
|
|
|
|
|
|
|
|
template<>
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::write(double data, Addr addr, unsigned flags, uint64_t *res)
|
|
|
|
{
|
|
|
|
return write(*(uint64_t*)&data, addr, flags, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::write(float data, Addr addr, unsigned flags, uint64_t *res)
|
|
|
|
{
|
|
|
|
return write(*(uint32_t*)&data, addr, flags, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
Fault
|
|
|
|
TimingSimpleCPU::write(int32_t data, Addr addr, unsigned flags, uint64_t *res)
|
|
|
|
{
|
|
|
|
return write((uint32_t)data, addr, flags, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-12 20:53:19 +01:00
|
|
|
void
|
|
|
|
TimingSimpleCPU::finishTranslation(WholeTranslationState *state)
|
|
|
|
{
|
|
|
|
_status = Running;
|
|
|
|
|
|
|
|
if (state->getFault() != NoFault) {
|
|
|
|
if (state->isPrefetch()) {
|
|
|
|
state->setNoFault();
|
|
|
|
}
|
2010-09-30 16:35:19 +02:00
|
|
|
delete [] state->data;
|
2010-02-12 20:53:19 +01:00
|
|
|
state->deleteReqs();
|
|
|
|
translationFault(state->getFault());
|
|
|
|
} else {
|
|
|
|
if (!state->isSplit) {
|
|
|
|
sendData(state->mainReq, state->data, state->res,
|
|
|
|
state->mode == BaseTLB::Read);
|
|
|
|
} else {
|
|
|
|
sendSplitData(state->sreqLow, state->sreqHigh, state->mainReq,
|
|
|
|
state->data, state->mode == BaseTLB::Read);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete state;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
void
|
|
|
|
TimingSimpleCPU::fetch()
|
|
|
|
{
|
2007-11-08 16:46:41 +01:00
|
|
|
DPRINTF(SimpleCPU, "Fetch\n");
|
|
|
|
|
2006-10-23 08:39:02 +02:00
|
|
|
if (!curStaticInst || !curStaticInst->isDelayedCommit())
|
|
|
|
checkForInterrupts();
|
2006-05-19 04:54:19 +02:00
|
|
|
|
2008-02-14 22:14:35 +01:00
|
|
|
checkPcEventQueue();
|
|
|
|
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
TheISA::PCState pcState = thread->pcState();
|
|
|
|
bool needToFetch = !isRomMicroPC(pcState.microPC()) && !curMacroStaticInst;
|
2006-05-16 23:36:50 +02:00
|
|
|
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
if (needToFetch) {
|
2008-10-13 04:32:06 +02:00
|
|
|
Request *ifetch_req = new Request();
|
2008-11-03 03:56:57 +01:00
|
|
|
ifetch_req->setThreadContext(_cpuId, /* thread ID */ 0);
|
2009-02-25 19:16:15 +01:00
|
|
|
setupFetchRequest(ifetch_req);
|
2009-04-09 07:21:27 +02:00
|
|
|
thread->itb->translateTiming(ifetch_req, tc, &fetchTranslation,
|
|
|
|
BaseTLB::Execute);
|
2009-02-25 19:16:15 +01:00
|
|
|
} else {
|
|
|
|
_status = IcacheWaitResponse;
|
|
|
|
completeIfetch(NULL);
|
|
|
|
|
2011-01-08 06:50:29 +01:00
|
|
|
numCycles += tickToCycles(curTick() - previousTick);
|
|
|
|
previousTick = curTick();
|
2009-02-25 19:16:15 +01:00
|
|
|
}
|
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
|
2009-02-25 19:16:15 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
TimingSimpleCPU::sendFetch(Fault fault, RequestPtr req, ThreadContext *tc)
|
|
|
|
{
|
|
|
|
if (fault == NoFault) {
|
|
|
|
ifetch_pkt = new Packet(req, MemCmd::ReadReq, Packet::Broadcast);
|
2008-10-13 04:32:06 +02:00
|
|
|
ifetch_pkt->dataStatic(&inst);
|
|
|
|
|
2009-02-25 19:16:15 +01:00
|
|
|
if (!icachePort.sendTiming(ifetch_pkt)) {
|
|
|
|
// Need to wait for retry
|
|
|
|
_status = IcacheRetry;
|
2006-05-16 23:36:50 +02:00
|
|
|
} else {
|
2009-02-25 19:16:15 +01:00
|
|
|
// Need to wait for cache to respond
|
|
|
|
_status = IcacheWaitResponse;
|
|
|
|
// ownership of packet transferred to memory system
|
|
|
|
ifetch_pkt = NULL;
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
} else {
|
2009-02-25 19:16:15 +01:00
|
|
|
delete req;
|
|
|
|
// fetch fault: advance directly to next instruction (fault handler)
|
2011-02-12 01:29:35 +01:00
|
|
|
_status = Running;
|
2009-02-25 19:16:15 +01:00
|
|
|
advanceInst(fault);
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
2006-10-08 06:55:05 +02:00
|
|
|
|
2011-01-08 06:50:29 +01:00
|
|
|
numCycles += tickToCycles(curTick() - previousTick);
|
|
|
|
previousTick = curTick();
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2006-05-26 20:33:43 +02:00
|
|
|
TimingSimpleCPU::advanceInst(Fault fault)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
2008-11-10 06:55:01 +01:00
|
|
|
if (fault != NoFault || !stayAtPC)
|
|
|
|
advancePC(fault);
|
2006-05-16 23:36:50 +02:00
|
|
|
|
2006-05-19 04:54:19 +02:00
|
|
|
if (_status == Running) {
|
|
|
|
// kick off fetch of next instruction... callback from icache
|
|
|
|
// response will cause that instruction to be executed,
|
|
|
|
// keeping the CPU running.
|
|
|
|
fetch();
|
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2006-10-20 09:10:12 +02:00
|
|
|
TimingSimpleCPU::completeIfetch(PacketPtr pkt)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
2007-11-08 16:46:41 +01:00
|
|
|
DPRINTF(SimpleCPU, "Complete ICache Fetch\n");
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
// received a response from the icache: execute the received
|
|
|
|
// instruction
|
2008-10-13 04:32:06 +02:00
|
|
|
|
|
|
|
assert(!pkt || !pkt->isError());
|
2006-05-16 23:36:50 +02:00
|
|
|
assert(_status == IcacheWaitResponse);
|
2006-06-30 01:45:24 +02:00
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
_status = Running;
|
2006-05-26 20:33:43 +02:00
|
|
|
|
2011-01-08 06:50:29 +01:00
|
|
|
numCycles += tickToCycles(curTick() - previousTick);
|
|
|
|
previousTick = curTick();
|
2006-10-08 06:55:05 +02:00
|
|
|
|
2006-07-05 23:59:33 +02:00
|
|
|
if (getState() == SimObject::Draining) {
|
2008-10-13 04:32:06 +02:00
|
|
|
if (pkt) {
|
|
|
|
delete pkt->req;
|
|
|
|
delete pkt;
|
|
|
|
}
|
2006-11-14 23:22:32 +01:00
|
|
|
|
2006-07-05 23:59:33 +02:00
|
|
|
completeDrain();
|
2006-06-30 01:45:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
preExecute();
|
2010-11-08 20:58:22 +01:00
|
|
|
if (curStaticInst && curStaticInst->isMemRef()) {
|
2006-05-16 23:36:50 +02:00
|
|
|
// load or store: just send to dcache
|
|
|
|
Fault fault = curStaticInst->initiateAcc(this, traceData);
|
2011-02-12 01:29:35 +01:00
|
|
|
|
|
|
|
// If we're not running now the instruction will complete in a dcache
|
|
|
|
// response callback or the instruction faulted and has started an
|
|
|
|
// ifetch
|
|
|
|
if (_status == Running) {
|
2009-02-25 19:16:15 +01:00
|
|
|
if (fault != NoFault && traceData) {
|
2007-08-27 05:29:09 +02:00
|
|
|
// If there was a fault, we shouldn't trace this instruction.
|
|
|
|
delete traceData;
|
|
|
|
traceData = NULL;
|
2006-10-08 19:53:24 +02:00
|
|
|
}
|
2007-08-27 05:25:42 +02:00
|
|
|
|
2006-05-26 20:33:43 +02:00
|
|
|
postExecute();
|
2007-10-01 08:55:27 +02:00
|
|
|
// @todo remove me after debugging with legion done
|
|
|
|
if (curStaticInst && (!curStaticInst->isMicroop() ||
|
|
|
|
curStaticInst->isFirstMicroop()))
|
|
|
|
instCnt++;
|
2006-05-26 20:33:43 +02:00
|
|
|
advanceInst(fault);
|
|
|
|
}
|
2008-11-10 06:55:01 +01:00
|
|
|
} else if (curStaticInst) {
|
2006-05-16 23:36:50 +02:00
|
|
|
// non-memory instruction: execute completely now
|
|
|
|
Fault fault = curStaticInst->execute(this, traceData);
|
2007-08-27 05:25:42 +02:00
|
|
|
|
|
|
|
// keep an instruction count
|
|
|
|
if (fault == NoFault)
|
|
|
|
countInst();
|
2010-08-26 02:10:43 +02:00
|
|
|
else if (traceData && !DTRACE(ExecFaulting)) {
|
2007-08-27 05:29:09 +02:00
|
|
|
delete traceData;
|
|
|
|
traceData = NULL;
|
|
|
|
}
|
2007-08-27 05:25:42 +02:00
|
|
|
|
2006-05-26 20:33:43 +02:00
|
|
|
postExecute();
|
2007-10-01 08:55:27 +02:00
|
|
|
// @todo remove me after debugging with legion done
|
|
|
|
if (curStaticInst && (!curStaticInst->isMicroop() ||
|
|
|
|
curStaticInst->isFirstMicroop()))
|
|
|
|
instCnt++;
|
2006-05-26 20:33:43 +02:00
|
|
|
advanceInst(fault);
|
2008-11-10 06:55:01 +01:00
|
|
|
} else {
|
|
|
|
advanceInst(NoFault);
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
2006-11-14 23:22:32 +01:00
|
|
|
|
2008-10-13 04:32:06 +02:00
|
|
|
if (pkt) {
|
|
|
|
delete pkt->req;
|
|
|
|
delete pkt;
|
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
2006-07-21 01:00:40 +02:00
|
|
|
void
|
|
|
|
TimingSimpleCPU::IcachePort::ITickEvent::process()
|
|
|
|
{
|
|
|
|
cpu->completeIfetch(pkt);
|
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
|
|
|
|
bool
|
2006-10-20 09:10:12 +02:00
|
|
|
TimingSimpleCPU::IcachePort::recvTiming(PacketPtr pkt)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
2007-08-27 06:45:40 +02:00
|
|
|
if (pkt->isResponse() && !pkt->wasNacked()) {
|
2006-10-18 00:50:19 +02:00
|
|
|
// delay processing of returned data until next CPU clock edge
|
2011-01-08 06:50:29 +01:00
|
|
|
Tick next_tick = cpu->nextCycle(curTick());
|
2006-10-18 00:50:19 +02:00
|
|
|
|
2011-01-08 06:50:29 +01:00
|
|
|
if (next_tick == curTick())
|
2006-10-18 00:50:19 +02:00
|
|
|
cpu->completeIfetch(pkt);
|
|
|
|
else
|
2006-11-06 19:27:45 +01:00
|
|
|
tickEvent.schedule(pkt, next_tick);
|
2006-10-18 00:50:19 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2007-06-30 19:16:18 +02:00
|
|
|
else if (pkt->wasNacked()) {
|
2007-05-08 00:58:38 +02:00
|
|
|
assert(cpu->_status == IcacheWaitResponse);
|
|
|
|
pkt->reinitNacked();
|
|
|
|
if (!sendTiming(pkt)) {
|
|
|
|
cpu->_status = IcacheRetry;
|
|
|
|
cpu->ifetch_pkt = pkt;
|
|
|
|
}
|
2006-10-18 00:50:19 +02:00
|
|
|
}
|
2007-05-08 00:58:38 +02:00
|
|
|
//Snooping a Coherence Request, do nothing
|
|
|
|
return true;
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
2006-05-31 00:57:42 +02:00
|
|
|
void
|
2006-05-16 23:36:50 +02:00
|
|
|
TimingSimpleCPU::IcachePort::recvRetry()
|
|
|
|
{
|
|
|
|
// we shouldn't get a retry unless we have a packet that we're
|
|
|
|
// waiting to transmit
|
|
|
|
assert(cpu->ifetch_pkt != NULL);
|
|
|
|
assert(cpu->_status == IcacheRetry);
|
2006-10-20 09:10:12 +02:00
|
|
|
PacketPtr tmp = cpu->ifetch_pkt;
|
2006-05-31 00:57:42 +02:00
|
|
|
if (sendTiming(tmp)) {
|
|
|
|
cpu->_status = IcacheWaitResponse;
|
|
|
|
cpu->ifetch_pkt = NULL;
|
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-10-20 09:10:12 +02:00
|
|
|
TimingSimpleCPU::completeDataAccess(PacketPtr pkt)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
|
|
|
// received a response from the dcache: complete the load or store
|
|
|
|
// instruction
|
2007-06-30 19:16:18 +02:00
|
|
|
assert(!pkt->isError());
|
2010-08-13 02:16:02 +02:00
|
|
|
assert(_status == DcacheWaitResponse || _status == DTBWaitResponse ||
|
|
|
|
pkt->req->getFlags().isSet(Request::NO_ACCESS));
|
2006-05-16 23:36:50 +02:00
|
|
|
|
2011-01-08 06:50:29 +01:00
|
|
|
numCycles += tickToCycles(curTick() - previousTick);
|
|
|
|
previousTick = curTick();
|
2006-10-08 06:55:05 +02:00
|
|
|
|
2008-11-10 06:56:28 +01:00
|
|
|
if (pkt->senderState) {
|
|
|
|
SplitFragmentSenderState * send_state =
|
|
|
|
dynamic_cast<SplitFragmentSenderState *>(pkt->senderState);
|
|
|
|
assert(send_state);
|
|
|
|
delete pkt->req;
|
|
|
|
delete pkt;
|
|
|
|
PacketPtr big_pkt = send_state->bigPkt;
|
|
|
|
delete send_state;
|
|
|
|
|
|
|
|
SplitMainSenderState * main_send_state =
|
|
|
|
dynamic_cast<SplitMainSenderState *>(big_pkt->senderState);
|
|
|
|
assert(main_send_state);
|
|
|
|
// Record the fact that this packet is no longer outstanding.
|
|
|
|
assert(main_send_state->outstanding != 0);
|
|
|
|
main_send_state->outstanding--;
|
|
|
|
|
|
|
|
if (main_send_state->outstanding) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
delete main_send_state;
|
|
|
|
big_pkt->senderState = NULL;
|
|
|
|
pkt = big_pkt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_status = Running;
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
Fault fault = curStaticInst->completeAcc(pkt, this, traceData);
|
|
|
|
|
2007-08-27 05:25:42 +02:00
|
|
|
// keep an instruction count
|
|
|
|
if (fault == NoFault)
|
|
|
|
countInst();
|
2007-08-27 05:29:09 +02:00
|
|
|
else if (traceData) {
|
|
|
|
// If there was a fault, we shouldn't trace this instruction.
|
|
|
|
delete traceData;
|
|
|
|
traceData = NULL;
|
|
|
|
}
|
2007-08-27 05:25:42 +02:00
|
|
|
|
2008-07-15 20:38:51 +02:00
|
|
|
// the locked flag may be cleared on the response packet, so check
|
|
|
|
// pkt->req and not pkt to see if it was a load-locked
|
2009-04-20 06:44:15 +02:00
|
|
|
if (pkt->isRead() && pkt->req->isLLSC()) {
|
2006-10-08 19:53:24 +02:00
|
|
|
TheISA::handleLockedRead(thread, pkt->req);
|
|
|
|
}
|
|
|
|
|
2006-05-26 20:33:43 +02:00
|
|
|
delete pkt->req;
|
|
|
|
delete pkt;
|
|
|
|
|
|
|
|
postExecute();
|
2006-10-10 01:13:06 +02:00
|
|
|
|
|
|
|
if (getState() == SimObject::Draining) {
|
|
|
|
advancePC(fault);
|
|
|
|
completeDrain();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-26 20:33:43 +02:00
|
|
|
advanceInst(fault);
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-30 01:45:24 +02:00
|
|
|
void
|
2006-07-05 23:59:33 +02:00
|
|
|
TimingSimpleCPU::completeDrain()
|
2006-06-30 01:45:24 +02:00
|
|
|
{
|
2006-07-05 23:59:33 +02:00
|
|
|
DPRINTF(Config, "Done draining\n");
|
2006-07-13 02:22:07 +02:00
|
|
|
changeState(SimObject::Drained);
|
2006-07-05 23:59:33 +02:00
|
|
|
drainEvent->process();
|
2006-06-30 01:45:24 +02:00
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
|
2007-03-09 16:06:09 +01:00
|
|
|
void
|
|
|
|
TimingSimpleCPU::DcachePort::setPeer(Port *port)
|
|
|
|
{
|
|
|
|
Port::setPeer(port);
|
|
|
|
|
|
|
|
#if FULL_SYSTEM
|
|
|
|
// Update the ThreadContext's memory ports (Functional/Virtual
|
|
|
|
// Ports)
|
2008-07-01 16:24:16 +02:00
|
|
|
cpu->tcBase()->connectMemPorts(cpu->tcBase());
|
2007-03-09 16:06:09 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
bool
|
2006-10-20 09:10:12 +02:00
|
|
|
TimingSimpleCPU::DcachePort::recvTiming(PacketPtr pkt)
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
2007-08-27 06:45:40 +02:00
|
|
|
if (pkt->isResponse() && !pkt->wasNacked()) {
|
2006-10-18 00:50:19 +02:00
|
|
|
// delay processing of returned data until next CPU clock edge
|
2011-01-08 06:50:29 +01:00
|
|
|
Tick next_tick = cpu->nextCycle(curTick());
|
2006-07-21 01:00:40 +02:00
|
|
|
|
2011-01-08 06:50:29 +01:00
|
|
|
if (next_tick == curTick()) {
|
2006-10-18 00:50:19 +02:00
|
|
|
cpu->completeDataAccess(pkt);
|
2008-11-10 06:56:28 +01:00
|
|
|
} else {
|
2010-11-15 21:04:03 +01:00
|
|
|
if (!tickEvent.scheduled()) {
|
|
|
|
tickEvent.schedule(pkt, next_tick);
|
|
|
|
} else {
|
|
|
|
// In the case of a split transaction and a cache that is
|
|
|
|
// faster than a CPU we could get two responses before
|
|
|
|
// next_tick expires
|
|
|
|
if (!retryEvent.scheduled())
|
|
|
|
schedule(retryEvent, next_tick);
|
|
|
|
return false;
|
|
|
|
}
|
2008-11-10 06:56:28 +01:00
|
|
|
}
|
2006-07-21 01:00:40 +02:00
|
|
|
|
2006-10-18 00:50:19 +02:00
|
|
|
return true;
|
|
|
|
}
|
2007-06-30 19:16:18 +02:00
|
|
|
else if (pkt->wasNacked()) {
|
2007-05-08 00:58:38 +02:00
|
|
|
assert(cpu->_status == DcacheWaitResponse);
|
|
|
|
pkt->reinitNacked();
|
|
|
|
if (!sendTiming(pkt)) {
|
|
|
|
cpu->_status = DcacheRetry;
|
|
|
|
cpu->dcache_pkt = pkt;
|
|
|
|
}
|
2006-10-18 00:50:19 +02:00
|
|
|
}
|
2007-05-08 00:58:38 +02:00
|
|
|
//Snooping a Coherence Request, do nothing
|
|
|
|
return true;
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
2006-07-21 01:00:40 +02:00
|
|
|
void
|
|
|
|
TimingSimpleCPU::DcachePort::DTickEvent::process()
|
|
|
|
{
|
|
|
|
cpu->completeDataAccess(pkt);
|
|
|
|
}
|
|
|
|
|
2006-05-31 00:57:42 +02:00
|
|
|
void
|
2006-05-16 23:36:50 +02:00
|
|
|
TimingSimpleCPU::DcachePort::recvRetry()
|
|
|
|
{
|
|
|
|
// we shouldn't get a retry unless we have a packet that we're
|
|
|
|
// waiting to transmit
|
|
|
|
assert(cpu->dcache_pkt != NULL);
|
|
|
|
assert(cpu->_status == DcacheRetry);
|
2006-10-20 09:10:12 +02:00
|
|
|
PacketPtr tmp = cpu->dcache_pkt;
|
2008-11-10 06:56:28 +01:00
|
|
|
if (tmp->senderState) {
|
|
|
|
// This is a packet from a split access.
|
|
|
|
SplitFragmentSenderState * send_state =
|
|
|
|
dynamic_cast<SplitFragmentSenderState *>(tmp->senderState);
|
|
|
|
assert(send_state);
|
|
|
|
PacketPtr big_pkt = send_state->bigPkt;
|
|
|
|
|
|
|
|
SplitMainSenderState * main_send_state =
|
|
|
|
dynamic_cast<SplitMainSenderState *>(big_pkt->senderState);
|
|
|
|
assert(main_send_state);
|
|
|
|
|
|
|
|
if (sendTiming(tmp)) {
|
|
|
|
// If we were able to send without retrying, record that fact
|
|
|
|
// and try sending the other fragment.
|
|
|
|
send_state->clearFromParent();
|
|
|
|
int other_index = main_send_state->getPendingFragment();
|
|
|
|
if (other_index > 0) {
|
|
|
|
tmp = main_send_state->fragments[other_index];
|
|
|
|
cpu->dcache_pkt = tmp;
|
|
|
|
if ((big_pkt->isRead() && cpu->handleReadPacket(tmp)) ||
|
|
|
|
(big_pkt->isWrite() && cpu->handleWritePacket())) {
|
|
|
|
main_send_state->fragments[other_index] = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cpu->_status = DcacheWaitResponse;
|
|
|
|
// memory system takes ownership of packet
|
|
|
|
cpu->dcache_pkt = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (sendTiming(tmp)) {
|
2006-05-31 00:57:42 +02:00
|
|
|
cpu->_status = DcacheWaitResponse;
|
2006-10-08 19:53:24 +02:00
|
|
|
// memory system takes ownership of packet
|
2006-05-31 00:57:42 +02:00
|
|
|
cpu->dcache_pkt = NULL;
|
|
|
|
}
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|
|
|
|
|
2008-10-09 13:58:24 +02:00
|
|
|
TimingSimpleCPU::IprEvent::IprEvent(Packet *_pkt, TimingSimpleCPU *_cpu,
|
|
|
|
Tick t)
|
|
|
|
: pkt(_pkt), cpu(_cpu)
|
2007-10-01 08:55:27 +02:00
|
|
|
{
|
2008-10-09 13:58:24 +02:00
|
|
|
cpu->schedule(this, t);
|
2007-10-01 08:55:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimingSimpleCPU::IprEvent::process()
|
|
|
|
{
|
|
|
|
cpu->completeDataAccess(pkt);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2008-02-06 22:32:40 +01:00
|
|
|
TimingSimpleCPU::IprEvent::description() const
|
2007-10-01 08:55:27 +02:00
|
|
|
{
|
|
|
|
return "Timing Simple CPU Delay IPR event";
|
|
|
|
}
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
|
2008-01-02 22:46:22 +01:00
|
|
|
void
|
|
|
|
TimingSimpleCPU::printAddr(Addr a)
|
|
|
|
{
|
|
|
|
dcachePort.printAddr(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-16 23:36:50 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// TimingSimpleCPU Simulation Object
|
|
|
|
//
|
2007-07-24 06:51:38 +02:00
|
|
|
TimingSimpleCPU *
|
|
|
|
TimingSimpleCPUParams::create()
|
2006-05-16 23:36:50 +02:00
|
|
|
{
|
2008-08-11 21:22:16 +02:00
|
|
|
numThreads = 1;
|
|
|
|
#if !FULL_SYSTEM
|
2007-07-24 06:51:38 +02:00
|
|
|
if (workload.size() != 1)
|
|
|
|
panic("only one workload allowed");
|
2006-05-16 23:36:50 +02:00
|
|
|
#endif
|
2008-08-11 21:22:16 +02:00
|
|
|
return new TimingSimpleCPU(this);
|
2006-05-16 23:36:50 +02:00
|
|
|
}
|