2006-06-28 17:02:14 +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.
|
|
|
|
*
|
|
|
|
* Authors: Erik Hallnor
|
|
|
|
* Steve Reinhardt
|
|
|
|
* Ron Dreslinski
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Definitions of CoherenceProtocol.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "base/misc.hh"
|
|
|
|
#include "mem/cache/miss/mshr.hh"
|
|
|
|
#include "mem/cache/cache.hh"
|
|
|
|
#include "mem/cache/coherence/coherence_protocol.hh"
|
2007-07-24 06:51:38 +02:00
|
|
|
#include "params/CoherenceProtocol.hh"
|
2006-06-28 17:02:14 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
CoherenceProtocol::StateTransition::StateTransition()
|
2007-02-07 19:53:37 +01:00
|
|
|
: busCmd(MemCmd::InvalidCmd), newState(-1), snoopFunc(invalidTransition)
|
2006-06-28 17:02:14 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CoherenceProtocol::regStats()
|
|
|
|
{
|
|
|
|
// Even though we count all the possible transitions in the
|
|
|
|
// requestCount and snoopCount arrays, most of these are invalid,
|
|
|
|
// so we just select the interesting ones to print here.
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
requestCount[Invalid][MemCmd::ReadReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".read_invalid")
|
|
|
|
.desc("read misses to invalid blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
requestCount[Invalid][MemCmd::WriteReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() +".write_invalid")
|
|
|
|
.desc("write misses to invalid blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
requestCount[Invalid][MemCmd::SoftPFReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() +".swpf_invalid")
|
|
|
|
.desc("soft prefetch misses to invalid blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
requestCount[Invalid][MemCmd::HardPFReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() +".hwpf_invalid")
|
|
|
|
.desc("hard prefetch misses to invalid blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
requestCount[Shared][MemCmd::WriteReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".write_shared")
|
|
|
|
.desc("write misses to shared blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
requestCount[Owned][MemCmd::WriteReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".write_owned")
|
|
|
|
.desc("write misses to owned blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Shared][MemCmd::ReadReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_read_shared")
|
|
|
|
.desc("read snoops on shared blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Shared][MemCmd::ReadExReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_readex_shared")
|
|
|
|
.desc("readEx snoops on shared blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Shared][MemCmd::UpgradeReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_upgrade_shared")
|
|
|
|
.desc("upgradee snoops on shared blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Modified][MemCmd::ReadReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_read_modified")
|
|
|
|
.desc("read snoops on modified blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Modified][MemCmd::ReadExReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_readex_modified")
|
|
|
|
.desc("readEx snoops on modified blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Owned][MemCmd::ReadReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_read_owned")
|
|
|
|
.desc("read snoops on owned blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Owned][MemCmd::ReadExReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_readex_owned")
|
|
|
|
.desc("readEx snoops on owned blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Owned][MemCmd::UpgradeReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_upgrade_owned")
|
|
|
|
.desc("upgrade snoops on owned blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Exclusive][MemCmd::ReadReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_read_exclusive")
|
|
|
|
.desc("read snoops on exclusive blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Exclusive][MemCmd::ReadExReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_readex_exclusive")
|
|
|
|
.desc("readEx snoops on exclusive blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Shared][MemCmd::InvalidateReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_inv_shared")
|
|
|
|
.desc("Invalidate snoops on shared blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Owned][MemCmd::InvalidateReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_inv_owned")
|
|
|
|
.desc("Invalidate snoops on owned blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Exclusive][MemCmd::InvalidateReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_inv_exclusive")
|
|
|
|
.desc("Invalidate snoops on exclusive blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Modified][MemCmd::InvalidateReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_inv_modified")
|
|
|
|
.desc("Invalidate snoops on modified blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Invalid][MemCmd::InvalidateReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_inv_invalid")
|
|
|
|
.desc("Invalidate snoops on invalid blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Shared][MemCmd::WriteInvalidateReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_writeinv_shared")
|
|
|
|
.desc("WriteInvalidate snoops on shared blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Owned][MemCmd::WriteInvalidateReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_writeinv_owned")
|
|
|
|
.desc("WriteInvalidate snoops on owned blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Exclusive][MemCmd::WriteInvalidateReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_writeinv_exclusive")
|
|
|
|
.desc("WriteInvalidate snoops on exclusive blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Modified][MemCmd::WriteInvalidateReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_writeinv_modified")
|
|
|
|
.desc("WriteInvalidate snoops on modified blocks")
|
|
|
|
;
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
snoopCount[Invalid][MemCmd::WriteInvalidateReq]
|
2006-06-28 17:02:14 +02:00
|
|
|
.name(name() + ".snoop_writeinv_invalid")
|
|
|
|
.desc("WriteInvalidate snoops on invalid blocks")
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2006-10-20 09:10:12 +02:00
|
|
|
CoherenceProtocol::invalidateTrans(BaseCache *cache, PacketPtr &pkt,
|
2006-06-28 17:02:14 +02:00
|
|
|
CacheBlk *blk, MSHR *mshr,
|
|
|
|
CacheBlk::State & new_state)
|
|
|
|
{
|
|
|
|
// invalidate the block
|
|
|
|
new_state = (blk->status & ~stateMask) | Invalid;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2006-10-20 09:10:12 +02:00
|
|
|
CoherenceProtocol::supplyTrans(BaseCache *cache, PacketPtr &pkt,
|
2006-06-28 17:02:14 +02:00
|
|
|
CacheBlk *blk,
|
|
|
|
MSHR *mshr,
|
2006-10-21 22:43:14 +02:00
|
|
|
CacheBlk::State & new_state)
|
2006-06-28 17:02:14 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2006-10-20 09:10:12 +02:00
|
|
|
CoherenceProtocol::supplyAndGotoSharedTrans(BaseCache *cache, PacketPtr &pkt,
|
2006-06-28 17:02:14 +02:00
|
|
|
CacheBlk *blk,
|
|
|
|
MSHR *mshr,
|
|
|
|
CacheBlk::State & new_state)
|
|
|
|
{
|
|
|
|
new_state = (blk->status & ~stateMask) | Shared;
|
|
|
|
pkt->flags |= SHARED_LINE;
|
|
|
|
return supplyTrans(cache, pkt, blk, mshr, new_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2006-10-20 09:10:12 +02:00
|
|
|
CoherenceProtocol::supplyAndGotoOwnedTrans(BaseCache *cache, PacketPtr &pkt,
|
2006-06-28 17:02:14 +02:00
|
|
|
CacheBlk *blk,
|
|
|
|
MSHR *mshr,
|
|
|
|
CacheBlk::State & new_state)
|
|
|
|
{
|
|
|
|
new_state = (blk->status & ~stateMask) | Owned;
|
|
|
|
pkt->flags |= SHARED_LINE;
|
|
|
|
return supplyTrans(cache, pkt, blk, mshr, new_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2006-10-20 09:10:12 +02:00
|
|
|
CoherenceProtocol::supplyAndInvalidateTrans(BaseCache *cache, PacketPtr &pkt,
|
2006-06-28 17:02:14 +02:00
|
|
|
CacheBlk *blk,
|
|
|
|
MSHR *mshr,
|
|
|
|
CacheBlk::State & new_state)
|
|
|
|
{
|
|
|
|
new_state = (blk->status & ~stateMask) | Invalid;
|
|
|
|
return supplyTrans(cache, pkt, blk, mshr, new_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2006-10-20 09:10:12 +02:00
|
|
|
CoherenceProtocol::assertShared(BaseCache *cache, PacketPtr &pkt,
|
2006-06-28 17:02:14 +02:00
|
|
|
CacheBlk *blk,
|
|
|
|
MSHR *mshr,
|
|
|
|
CacheBlk::State & new_state)
|
|
|
|
{
|
|
|
|
new_state = (blk->status & ~stateMask) | Shared;
|
|
|
|
pkt->flags |= SHARED_LINE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoherenceProtocol::CoherenceProtocol(const string &name,
|
2007-07-24 06:51:38 +02:00
|
|
|
Enums::Coherence protocol,
|
2006-06-28 17:02:14 +02:00
|
|
|
const bool doUpgrades)
|
|
|
|
: SimObject(name)
|
|
|
|
{
|
2007-07-24 06:51:38 +02:00
|
|
|
bool hasOwned = (protocol == Enums::mosi || protocol == Enums::moesi);
|
|
|
|
bool hasExclusive = (protocol == Enums::mesi || protocol == Enums::moesi);
|
2006-10-21 22:43:14 +02:00
|
|
|
|
|
|
|
if (hasOwned && !doUpgrades) {
|
|
|
|
fatal("CoherenceProtocol: ownership protocols require upgrade "
|
|
|
|
"transactions\n(write miss on owned block generates ReadExcl, "
|
|
|
|
"which will clobber dirty block)\n");
|
2006-06-28 17:02:14 +02:00
|
|
|
}
|
|
|
|
|
2006-10-21 22:43:14 +02:00
|
|
|
// set up a few shortcuts to save typing & visual clutter
|
2007-02-07 19:53:37 +01:00
|
|
|
typedef MemCmd MC;
|
|
|
|
StateTransition (&tt)[stateMax+1][MC::NUM_MEM_CMDS] = transitionTable;
|
2006-10-21 22:43:14 +02:00
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
MC::Command writeToSharedCmd =
|
|
|
|
doUpgrades ? MC::UpgradeReq : MC::ReadExReq;
|
|
|
|
MC::Command writeToSharedResp =
|
|
|
|
doUpgrades ? MC::UpgradeReq : MC::ReadExResp;
|
2006-10-21 22:43:14 +02:00
|
|
|
|
|
|
|
// Note that all transitions by default cause a panic.
|
|
|
|
// Override the valid transitions with the appropriate actions here.
|
|
|
|
|
|
|
|
//
|
|
|
|
// ----- incoming requests: specify outgoing bus request -----
|
|
|
|
//
|
2007-02-07 19:53:37 +01:00
|
|
|
tt[Invalid][MC::ReadReq].onRequest(MC::ReadReq);
|
2006-10-21 22:43:14 +02:00
|
|
|
// we only support write allocate right now
|
2007-02-07 19:53:37 +01:00
|
|
|
tt[Invalid][MC::WriteReq].onRequest(MC::ReadExReq);
|
2007-03-28 00:05:25 +02:00
|
|
|
tt[Invalid][MC::SwapReq].onRequest(MC::ReadExReq);
|
2007-02-07 19:53:37 +01:00
|
|
|
tt[Shared][MC::WriteReq].onRequest(writeToSharedCmd);
|
2007-03-28 00:05:25 +02:00
|
|
|
tt[Shared][MC::SwapReq].onRequest(writeToSharedCmd);
|
2006-10-21 22:43:14 +02:00
|
|
|
if (hasOwned) {
|
2007-02-07 19:53:37 +01:00
|
|
|
tt[Owned][MC::WriteReq].onRequest(writeToSharedCmd);
|
2007-03-28 00:05:25 +02:00
|
|
|
tt[Owned][MC::SwapReq].onRequest(writeToSharedCmd);
|
2006-06-28 17:02:14 +02:00
|
|
|
}
|
|
|
|
|
2006-10-21 22:43:14 +02:00
|
|
|
// Prefetching causes a read
|
2007-02-07 19:53:37 +01:00
|
|
|
tt[Invalid][MC::SoftPFReq].onRequest(MC::ReadReq);
|
|
|
|
tt[Invalid][MC::HardPFReq].onRequest(MC::ReadReq);
|
2006-10-21 22:43:14 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// ----- on response to given request: specify new state -----
|
|
|
|
//
|
2007-02-07 19:53:37 +01:00
|
|
|
tt[Invalid][MC::ReadExResp].onResponse(Modified);
|
2006-10-21 22:43:14 +02:00
|
|
|
tt[Shared][writeToSharedResp].onResponse(Modified);
|
|
|
|
// Go to Exclusive state on read response if we have one (will
|
|
|
|
// move into shared if the shared line is asserted in the
|
|
|
|
// getNewState function)
|
|
|
|
//
|
|
|
|
// originally had this as:
|
2007-02-07 19:53:37 +01:00
|
|
|
// tt[Invalid][MC::ReadResp].onResponse(hasExclusive ? Exclusive: Shared);
|
2006-10-21 22:43:14 +02:00
|
|
|
// ...but for some reason that caused a link error...
|
|
|
|
if (hasExclusive) {
|
2007-02-07 19:53:37 +01:00
|
|
|
tt[Invalid][MC::ReadResp].onResponse(Exclusive);
|
2006-10-21 22:43:14 +02:00
|
|
|
} else {
|
2007-02-07 19:53:37 +01:00
|
|
|
tt[Invalid][MC::ReadResp].onResponse(Shared);
|
2006-10-21 22:43:14 +02:00
|
|
|
}
|
|
|
|
if (hasOwned) {
|
|
|
|
tt[Owned][writeToSharedResp].onResponse(Modified);
|
2006-06-28 17:02:14 +02:00
|
|
|
}
|
|
|
|
|
2006-10-21 22:43:14 +02:00
|
|
|
//
|
|
|
|
// ----- bus snoop transition functions -----
|
|
|
|
//
|
2007-02-07 19:53:37 +01:00
|
|
|
tt[Invalid][MC::ReadReq].onSnoop(nullTransition);
|
|
|
|
tt[Invalid][MC::ReadExReq].onSnoop(nullTransition);
|
|
|
|
tt[Invalid][MC::InvalidateReq].onSnoop(invalidateTrans);
|
|
|
|
tt[Invalid][MC::WriteInvalidateReq].onSnoop(invalidateTrans);
|
|
|
|
tt[Shared][MC::ReadReq].onSnoop(hasExclusive
|
2006-10-21 22:43:14 +02:00
|
|
|
? assertShared : nullTransition);
|
2007-02-07 19:53:37 +01:00
|
|
|
tt[Shared][MC::ReadExReq].onSnoop(invalidateTrans);
|
|
|
|
tt[Shared][MC::InvalidateReq].onSnoop(invalidateTrans);
|
|
|
|
tt[Shared][MC::WriteInvalidateReq].onSnoop(invalidateTrans);
|
2006-10-21 22:43:14 +02:00
|
|
|
if (doUpgrades) {
|
2007-02-07 19:53:37 +01:00
|
|
|
tt[Invalid][MC::UpgradeReq].onSnoop(nullTransition);
|
|
|
|
tt[Shared][MC::UpgradeReq].onSnoop(invalidateTrans);
|
2006-10-21 22:43:14 +02:00
|
|
|
}
|
2007-02-07 19:53:37 +01:00
|
|
|
tt[Modified][MC::ReadExReq].onSnoop(supplyAndInvalidateTrans);
|
|
|
|
tt[Modified][MC::ReadReq].onSnoop(hasOwned
|
2006-10-21 22:43:14 +02:00
|
|
|
? supplyAndGotoOwnedTrans
|
|
|
|
: supplyAndGotoSharedTrans);
|
2007-02-07 19:53:37 +01:00
|
|
|
tt[Modified][MC::InvalidateReq].onSnoop(invalidateTrans);
|
|
|
|
tt[Modified][MC::WriteInvalidateReq].onSnoop(invalidateTrans);
|
2006-10-21 22:43:14 +02:00
|
|
|
|
|
|
|
if (hasExclusive) {
|
2007-02-07 19:53:37 +01:00
|
|
|
tt[Exclusive][MC::ReadReq].onSnoop(assertShared);
|
|
|
|
tt[Exclusive][MC::ReadExReq].onSnoop(invalidateTrans);
|
|
|
|
tt[Exclusive][MC::InvalidateReq].onSnoop(invalidateTrans);
|
|
|
|
tt[Exclusive][MC::WriteInvalidateReq].onSnoop(invalidateTrans);
|
2006-06-28 17:02:14 +02:00
|
|
|
}
|
|
|
|
|
2006-10-21 22:43:14 +02:00
|
|
|
if (hasOwned) {
|
2007-02-07 19:53:37 +01:00
|
|
|
tt[Owned][MC::ReadReq].onSnoop(supplyAndGotoOwnedTrans);
|
|
|
|
tt[Owned][MC::ReadExReq].onSnoop(supplyAndInvalidateTrans);
|
|
|
|
tt[Owned][MC::UpgradeReq].onSnoop(invalidateTrans);
|
|
|
|
tt[Owned][MC::InvalidateReq].onSnoop(invalidateTrans);
|
|
|
|
tt[Owned][MC::WriteInvalidateReq].onSnoop(invalidateTrans);
|
2006-06-28 17:02:14 +02:00
|
|
|
}
|
2006-10-21 22:43:14 +02:00
|
|
|
|
|
|
|
// @todo add in hardware prefetch to this list
|
2006-06-28 17:02:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
MemCmd
|
|
|
|
CoherenceProtocol::getBusCmd(MemCmd cmdIn, CacheBlk::State state,
|
2006-06-28 17:02:14 +02:00
|
|
|
MSHR *mshr)
|
|
|
|
{
|
|
|
|
state &= stateMask;
|
2007-02-07 19:53:37 +01:00
|
|
|
int cmd_idx = cmdIn.toInt();
|
2006-06-28 17:02:14 +02:00
|
|
|
|
|
|
|
assert(0 <= state && state <= stateMax);
|
2007-02-07 19:53:37 +01:00
|
|
|
assert(0 <= cmd_idx && cmd_idx < MemCmd::NUM_MEM_CMDS);
|
2006-06-28 17:02:14 +02:00
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
MemCmd::Command cmdOut = transitionTable[state][cmd_idx].busCmd;
|
2006-06-28 17:02:14 +02:00
|
|
|
|
2007-02-07 19:53:37 +01:00
|
|
|
assert(cmdOut != MemCmd::InvalidCmd);
|
2006-06-28 17:02:14 +02:00
|
|
|
|
|
|
|
++requestCount[state][cmd_idx];
|
|
|
|
|
|
|
|
return cmdOut;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CacheBlk::State
|
2006-10-20 09:10:12 +02:00
|
|
|
CoherenceProtocol::getNewState(PacketPtr &pkt, CacheBlk::State oldState)
|
2006-06-28 17:02:14 +02:00
|
|
|
{
|
|
|
|
CacheBlk::State state = oldState & stateMask;
|
2006-06-28 20:35:00 +02:00
|
|
|
int cmd_idx = pkt->cmdToIndex();
|
2006-06-28 17:02:14 +02:00
|
|
|
|
|
|
|
assert(0 <= state && state <= stateMax);
|
2007-02-07 19:53:37 +01:00
|
|
|
assert(0 <= cmd_idx && cmd_idx < MemCmd::NUM_MEM_CMDS);
|
2006-06-28 17:02:14 +02:00
|
|
|
|
|
|
|
CacheBlk::State newState = transitionTable[state][cmd_idx].newState;
|
|
|
|
|
|
|
|
//Check if it's exclusive and the shared line was asserted,
|
|
|
|
//then goto shared instead
|
|
|
|
if (newState == Exclusive && (pkt->flags & SHARED_LINE)) {
|
|
|
|
newState = Shared;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(newState != -1);
|
|
|
|
|
|
|
|
//Make sure not to loose any other state information
|
|
|
|
newState = (oldState & ~stateMask) | newState;
|
|
|
|
return newState;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2006-10-20 09:10:12 +02:00
|
|
|
CoherenceProtocol::handleBusRequest(BaseCache *cache, PacketPtr &pkt,
|
2006-06-28 17:02:14 +02:00
|
|
|
CacheBlk *blk,
|
|
|
|
MSHR *mshr,
|
|
|
|
CacheBlk::State & new_state)
|
|
|
|
{
|
|
|
|
if (blk == NULL) {
|
|
|
|
// nothing to do if we don't have a block
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CacheBlk::State state = blk->status & stateMask;
|
2006-06-28 20:35:00 +02:00
|
|
|
int cmd_idx = pkt->cmdToIndex();
|
2006-06-28 17:02:14 +02:00
|
|
|
|
|
|
|
assert(0 <= state && state <= stateMax);
|
2007-02-07 19:53:37 +01:00
|
|
|
assert(0 <= cmd_idx && cmd_idx < MemCmd::NUM_MEM_CMDS);
|
2006-06-28 17:02:14 +02:00
|
|
|
|
|
|
|
// assert(mshr == NULL); // can't currently handle outstanding requests
|
|
|
|
//Check first if MSHR, and also insure, if there is one, that it is not in service
|
|
|
|
assert(!mshr || mshr->inService == 0);
|
|
|
|
++snoopCount[state][cmd_idx];
|
|
|
|
|
|
|
|
bool ret = transitionTable[state][cmd_idx].snoopFunc(cache, pkt, blk, mshr,
|
|
|
|
new_state);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2006-10-20 09:10:12 +02:00
|
|
|
CoherenceProtocol::nullTransition(BaseCache *cache, PacketPtr &pkt,
|
2006-06-28 17:02:14 +02:00
|
|
|
CacheBlk *blk, MSHR *mshr,
|
|
|
|
CacheBlk::State & new_state)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
if (blk)
|
|
|
|
new_state = blk->status;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2006-10-20 09:10:12 +02:00
|
|
|
CoherenceProtocol::invalidTransition(BaseCache *cache, PacketPtr &pkt,
|
2006-06-28 17:02:14 +02:00
|
|
|
CacheBlk *blk, MSHR *mshr,
|
|
|
|
CacheBlk::State & new_state)
|
|
|
|
{
|
|
|
|
panic("Invalid transition");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-07-24 06:51:38 +02:00
|
|
|
CoherenceProtocol *
|
|
|
|
CoherenceProtocolParams::create()
|
2006-06-28 17:02:14 +02:00
|
|
|
{
|
2007-07-24 06:51:38 +02:00
|
|
|
return new CoherenceProtocol(name, protocol, do_upgrades);
|
2006-06-28 17:02:14 +02:00
|
|
|
}
|