mem: restructure Packet cmd initialization a bit more

Refactor the way that specific MemCmd values are generated for packets.
The new approach is a little more elegant in that we assign the right
value up front, and it's also more amenable to non-heap-allocated
Packet objects.

Also replaced the code in the Minor model that was still doing it the
ad-hoc way.

This is basically a refinement of http://repo.gem5.org/gem5/rev/711eb0e64249.
This commit is contained in:
Steve Reinhardt 2015-02-11 10:48:50 -08:00
parent ccef61d1cc
commit ee0b52404c
5 changed files with 41 additions and 43 deletions

View file

@ -811,10 +811,17 @@ CacheUnit::finishCacheUnitReq(DynInstPtr inst, CacheRequest *cache_req)
void void
CacheUnit::buildDataPacket(CacheRequest *cache_req) CacheUnit::buildDataPacket(CacheRequest *cache_req)
{ {
cache_req->dataPkt = new CacheReqPacket(cache_req, MemCmd cmd;
cache_req->pktCmd,
if (cache_req->pktCmd == MemCmd::ReadReq) {
cmd = Packet::makeReadCmd(cache_req->memReq);
} else {
assert(cache_req->pktCmd == MemCmd::WriteReq);
cmd = Packet::makeWriteCmd(cache_req->memReq);
}
cache_req->dataPkt = new CacheReqPacket(cache_req, cmd,
cache_req->instIdx); cache_req->instIdx);
cache_req->dataPkt->refineCommand(); // handle LL/SC, etc.
DPRINTF(InOrderCachePort, "[slot:%i]: Slot marked for %x\n", DPRINTF(InOrderCachePort, "[slot:%i]: Slot marked for %x\n",
cache_req->getSlot(), cache_req->getSlot(),

View file

@ -230,7 +230,7 @@ class CacheRequest : public ResourceRequest
bool isMemAccPending() { return memAccPending; } bool isMemAccPending() { return memAccPending; }
//Make this data private/protected! //Make this data private/protected!
MemCmd::Command pktCmd; MemCmd pktCmd;
RequestPtr memReq; RequestPtr memReq;
PacketDataPtr reqData; PacketDataPtr reqData;
CacheReqPacket *dataPkt; CacheReqPacket *dataPkt;
@ -252,7 +252,7 @@ class CacheReqPacket : public Packet
{ {
public: public:
CacheReqPacket(CacheRequest *_req, CacheReqPacket(CacheRequest *_req,
Command _cmd, int _idx = 0) MemCmd _cmd, int _idx = 0)
: Packet(&(*_req->memReq), _cmd), cacheReq(_req), : Packet(&(*_req->memReq), _cmd), cacheReq(_req),
instIdx(_idx), hasSlot(false), reqData(NULL), memReq(NULL) instIdx(_idx), hasSlot(false), reqData(NULL), memReq(NULL)
{ {

View file

@ -1545,18 +1545,8 @@ PacketPtr
makePacketForRequest(Request &request, bool isLoad, makePacketForRequest(Request &request, bool isLoad,
Packet::SenderState *sender_state, PacketDataPtr data) Packet::SenderState *sender_state, PacketDataPtr data)
{ {
MemCmd command; PacketPtr ret = isLoad ? Packet::createRead(&request)
: Packet::createWrite(&request);
/* Make a ret with the right command type to match the request */
if (request.isLLSC()) {
command = (isLoad ? MemCmd::LoadLockedReq : MemCmd::StoreCondReq);
} else if (request.isSwap()) {
command = MemCmd::SwapReq;
} else {
command = (isLoad ? MemCmd::ReadReq : MemCmd::WriteReq);
}
PacketPtr ret = new Packet(&request, command);
if (sender_state) if (sender_state)
ret->pushSenderState(sender_state); ret->pushSenderState(sender_state);

View file

@ -341,8 +341,7 @@ AtomicSimpleCPU::readMem(Addr addr, uint8_t * data,
// Now do the access. // Now do the access.
if (fault == NoFault && !req->getFlags().isSet(Request::NO_ACCESS)) { if (fault == NoFault && !req->getFlags().isSet(Request::NO_ACCESS)) {
Packet pkt(req, MemCmd::ReadReq); Packet pkt(req, Packet::makeReadCmd(req));
pkt.refineCommand();
pkt.dataStatic(data); pkt.dataStatic(data);
if (req->isMmappedIpr()) if (req->isMmappedIpr())

View file

@ -643,45 +643,47 @@ class Packet : public Printable
} }
/** /**
* Change the packet type based on request type. * Generate the appropriate read MemCmd based on the Request flags.
*/ */
void static MemCmd
refineCommand() makeReadCmd(const RequestPtr req)
{ {
if (cmd == MemCmd::ReadReq) { if (req->isLLSC())
if (req->isLLSC()) { return MemCmd::LoadLockedReq;
cmd = MemCmd::LoadLockedReq; else if (req->isPrefetch())
} else if (req->isPrefetch()) { return MemCmd::SoftPFReq;
cmd = MemCmd::SoftPFReq; else
} return MemCmd::ReadReq;
} else if (cmd == MemCmd::WriteReq) { }
if (req->isLLSC()) {
cmd = MemCmd::StoreCondReq; /**
} else if (req->isSwap()) { * Generate the appropriate write MemCmd based on the Request flags.
cmd = MemCmd::SwapReq; */
} static MemCmd
} makeWriteCmd(const RequestPtr req)
{
if (req->isLLSC())
return MemCmd::StoreCondReq;
else if (req->isSwap())
return MemCmd::SwapReq;
else
return MemCmd::WriteReq;
} }
/** /**
* Constructor-like methods that return Packets based on Request objects. * Constructor-like methods that return Packets based on Request objects.
* Will call refineCommand() to fine-tune the Packet type if it's not a * Fine-tune the MemCmd type if it's not a vanilla read or write.
* vanilla read or write.
*/ */
static PacketPtr static PacketPtr
createRead(const RequestPtr req) createRead(const RequestPtr req)
{ {
PacketPtr pkt = new Packet(req, MemCmd::ReadReq); return new Packet(req, makeReadCmd(req));
pkt->refineCommand();
return pkt;
} }
static PacketPtr static PacketPtr
createWrite(const RequestPtr req) createWrite(const RequestPtr req)
{ {
PacketPtr pkt = new Packet(req, MemCmd::WriteReq); return new Packet(req, makeWriteCmd(req));
pkt->refineCommand();
return pkt;
} }
/** /**