Fix some more mem leaks, still some left

Update retry mechanism

src/mem/cache/base_cache.cc:
    Rework the retry mechanism
src/mem/cache/base_cache.hh:
    Rework the retry mechanism
    Try to fix memory bug
src/mem/cache/cache_impl.hh:
    Rework upgrades to not be blocked by slave
src/mem/cache/miss/mshr_queue.cc:
    Fix mem leak on writebacks

--HG--
extra : convert_revision : 3cec234ee441edf398ec8d0f51a0c5d7ada1e2be
This commit is contained in:
Ron Dreslinski 2006-10-10 17:10:56 -04:00
parent 9e008d73d5
commit 995146ead7
4 changed files with 68 additions and 54 deletions

View file

@ -45,6 +45,7 @@ BaseCache::CachePort::CachePort(const std::string &_name, BaseCache *_cache,
{ {
blocked = false; blocked = false;
cshrRetry = NULL; cshrRetry = NULL;
waitingOnRetry = false;
//Start ports at null if more than one is created we should panic //Start ports at null if more than one is created we should panic
//cpuSidePort = NULL; //cpuSidePort = NULL;
//memSidePort = NULL; //memSidePort = NULL;
@ -113,25 +114,30 @@ void
BaseCache::CachePort::recvRetry() BaseCache::CachePort::recvRetry()
{ {
Packet *pkt; Packet *pkt;
assert(waitingOnRetry);
if (!drainList.empty()) { if (!drainList.empty()) {
//We have some responses to drain first //We have some responses to drain first
bool result = true; if (sendTiming(drainList.front())) {
while (result && !drainList.empty()) { drainList.pop_front();
result = sendTiming(drainList.front()); if (!drainList.empty() ||
if (result) !isCpuSide && cache->doMasterRequest() ||
drainList.pop_front(); isCpuSide && cache->doSlaveRequest()) {
BaseCache::CacheEvent * reqCpu = new BaseCache::CacheEvent(this);
reqCpu->schedule(curTick + 1);
}
waitingOnRetry = false;
} }
if (!result) return;
} }
else if (!isCpuSide) else if (!isCpuSide)
{ {
if (!cache->doMasterRequest()) return; assert(cache->doMasterRequest());
pkt = cache->getPacket(); pkt = cache->getPacket();
MSHR* mshr = (MSHR*)pkt->senderState; MSHR* mshr = (MSHR*)pkt->senderState;
bool success = sendTiming(pkt); bool success = sendTiming(pkt);
DPRINTF(Cache, "Address %x was %s in sending the timing request\n", DPRINTF(Cache, "Address %x was %s in sending the timing request\n",
pkt->getAddr(), success ? "succesful" : "unsuccesful"); pkt->getAddr(), success ? "succesful" : "unsuccesful");
cache->sendResult(pkt, mshr, success); cache->sendResult(pkt, mshr, success);
waitingOnRetry = !success;
if (success && cache->doMasterRequest()) if (success && cache->doMasterRequest())
{ {
//Still more to issue, rerequest in 1 cycle //Still more to issue, rerequest in 1 cycle
@ -140,12 +146,14 @@ BaseCache::CachePort::recvRetry()
reqCpu->schedule(curTick + 1); reqCpu->schedule(curTick + 1);
} }
} }
else if (cshrRetry) else
{ {
assert(cshrRetry);
//pkt = cache->getCoherencePacket(); //pkt = cache->getCoherencePacket();
//We save the packet, no reordering on CSHRS //We save the packet, no reordering on CSHRS
pkt = cshrRetry; pkt = cshrRetry;
bool success = sendTiming(pkt); bool success = sendTiming(pkt);
waitingOnRetry = !success;
if (success && cache->doSlaveRequest()) if (success && cache->doSlaveRequest())
{ {
//Still more to issue, rerequest in 1 cycle //Still more to issue, rerequest in 1 cycle
@ -154,7 +162,6 @@ BaseCache::CachePort::recvRetry()
reqCpu->schedule(curTick + 1); reqCpu->schedule(curTick + 1);
cshrRetry = NULL; cshrRetry = NULL;
} }
} }
return; return;
} }
@ -198,23 +205,22 @@ BaseCache::CacheEvent::CacheEvent(CachePort *_cachePort, Packet *_pkt)
void void
BaseCache::CacheEvent::process() BaseCache::CacheEvent::process()
{ {
if (!cachePort->drainList.empty()) {
//We have some responses to drain first
bool result = true;
while (result && !cachePort->drainList.empty()) {
result = cachePort->sendTiming(cachePort->drainList.front());
if (result)
cachePort->drainList.pop_front();
}
if (!result) return;
}
if (!pkt) if (!pkt)
{ {
if (!cachePort->isCpuSide) if (cachePort->waitingOnRetry) return;
//We have some responses to drain first
if (!cachePort->drainList.empty()) {
if (cachePort->sendTiming(cachePort->drainList.front())) {
cachePort->drainList.pop_front();
if (!cachePort->drainList.empty() ||
!cachePort->isCpuSide && cachePort->cache->doMasterRequest() ||
cachePort->isCpuSide && cachePort->cache->doSlaveRequest())
this->schedule(curTick + 1);
}
else cachePort->waitingOnRetry = true;
}
else if (!cachePort->isCpuSide)
{ {
//For now, doMasterRequest somehow is still getting set
if (!cachePort->cache->doMasterRequest()) return;
//MSHR //MSHR
pkt = cachePort->cache->getPacket(); pkt = cachePort->cache->getPacket();
MSHR* mshr = (MSHR*) pkt->senderState; MSHR* mshr = (MSHR*) pkt->senderState;
@ -222,6 +228,7 @@ BaseCache::CacheEvent::process()
DPRINTF(Cache, "Address %x was %s in sending the timing request\n", DPRINTF(Cache, "Address %x was %s in sending the timing request\n",
pkt->getAddr(), success ? "succesful" : "unsuccesful"); pkt->getAddr(), success ? "succesful" : "unsuccesful");
cachePort->cache->sendResult(pkt, mshr, success); cachePort->cache->sendResult(pkt, mshr, success);
cachePort->waitingOnRetry = !success;
if (success && cachePort->cache->doMasterRequest()) if (success && cachePort->cache->doMasterRequest())
{ {
//Still more to issue, rerequest in 1 cycle //Still more to issue, rerequest in 1 cycle
@ -237,6 +244,7 @@ BaseCache::CacheEvent::process()
if (!success) { if (!success) {
//Need to send on a retry //Need to send on a retry
cachePort->cshrRetry = pkt; cachePort->cshrRetry = pkt;
cachePort->waitingOnRetry = true;
} }
else if (cachePort->cache->doSlaveRequest()) else if (cachePort->cache->doSlaveRequest())
{ {
@ -255,12 +263,13 @@ BaseCache::CacheEvent::process()
pkt->result = Packet::Success; pkt->result = Packet::Success;
pkt->makeTimingResponse(); pkt->makeTimingResponse();
if (!cachePort->drainList.empty()) { if (!cachePort->drainList.empty()) {
//Already blocked waiting for bus, just append //Already have a list, just append
cachePort->drainList.push_back(pkt); cachePort->drainList.push_back(pkt);
} }
else if (!cachePort->sendTiming(pkt)) { else if (!cachePort->sendTiming(pkt)) {
//It failed, save it to list of drain events //It failed, save it to list of drain events
cachePort->drainList.push_back(pkt); cachePort->drainList.push_back(pkt);
cachePort->waitingOnRetry = true;
} }
} }

View file

@ -112,6 +112,8 @@ class BaseCache : public MemObject
bool isCpuSide; bool isCpuSide;
bool waitingOnRetry;
std::list<Packet *> drainList; std::list<Packet *> drainList;
Packet *cshrRetry; Packet *cshrRetry;
@ -465,7 +467,7 @@ class BaseCache : public MemObject
*/ */
void setMasterRequest(RequestCause cause, Tick time) void setMasterRequest(RequestCause cause, Tick time)
{ {
if (!doMasterRequest()) if (!doMasterRequest() && memSidePort->drainList.empty())
{ {
BaseCache::CacheEvent * reqCpu = new BaseCache::CacheEvent(memSidePort); BaseCache::CacheEvent * reqCpu = new BaseCache::CacheEvent(memSidePort);
reqCpu->schedule(time); reqCpu->schedule(time);
@ -527,6 +529,10 @@ class BaseCache : public MemObject
CacheEvent *reqCpu = new CacheEvent(cpuSidePort, pkt); CacheEvent *reqCpu = new CacheEvent(cpuSidePort, pkt);
reqCpu->schedule(time); reqCpu->schedule(time);
} }
else {
if (pkt->cmd == Packet::Writeback) delete pkt->req;
delete pkt;
}
} }
/** /**
@ -543,6 +549,10 @@ class BaseCache : public MemObject
CacheEvent *reqCpu = new CacheEvent(cpuSidePort, pkt); CacheEvent *reqCpu = new CacheEvent(cpuSidePort, pkt);
reqCpu->schedule(time); reqCpu->schedule(time);
} }
else {
if (pkt->cmd == Packet::Writeback) delete pkt->req;
delete pkt;
}
} }
/** /**

View file

@ -193,19 +193,6 @@ Cache<TagStore,Buffering,Coherence>::access(PacketPtr &pkt)
prefetcher->handleMiss(pkt, curTick); prefetcher->handleMiss(pkt, curTick);
} }
if (!pkt->req->isUncacheable()) { if (!pkt->req->isUncacheable()) {
if (pkt->isInvalidate() && !pkt->isRead()
&& !pkt->isWrite()) {
//Upgrade or Invalidate
//Look into what happens if two slave caches on bus
DPRINTF(Cache, "%s %x ? blk_addr: %x\n", pkt->cmdString(),
pkt->getAddr() & (((ULL(1))<<48)-1),
pkt->getAddr() & ~((Addr)blkSize - 1));
pkt->flags |= SATISFIED;
//Invalidates/Upgrades need no response if they get the bus
// return MA_HIT; //@todo, return values
return true;
}
blk = tags->handleAccess(pkt, lat, writebacks); blk = tags->handleAccess(pkt, lat, writebacks);
} else { } else {
size = pkt->getSize(); size = pkt->getSize();
@ -241,7 +228,10 @@ Cache<TagStore,Buffering,Coherence>::access(PacketPtr &pkt)
// clear dirty bit if write through // clear dirty bit if write through
if (pkt->needsResponse()) if (pkt->needsResponse())
respond(pkt, curTick+lat); respond(pkt, curTick+lat);
// return MA_HIT; if (pkt->cmd == Packet::Writeback) {
//Signal that you can kill the pkt/req
pkt->flags |= SATISFIED;
}
return true; return true;
} }
@ -287,22 +277,22 @@ void
Cache<TagStore,Buffering,Coherence>::sendResult(PacketPtr &pkt, MSHR* mshr, bool success) Cache<TagStore,Buffering,Coherence>::sendResult(PacketPtr &pkt, MSHR* mshr, bool success)
{ {
if (success && !(pkt->flags & NACKED_LINE)) { if (success && !(pkt->flags & NACKED_LINE)) {
missQueue->markInService(pkt, mshr); missQueue->markInService(pkt, mshr);
//Temp Hack for UPGRADES //Temp Hack for UPGRADES
if (pkt->cmd == Packet::UpgradeReq) { if (pkt->cmd == Packet::UpgradeReq) {
pkt->flags &= ~CACHE_LINE_FILL; pkt->flags &= ~CACHE_LINE_FILL;
BlkType *blk = tags->findBlock(pkt); BlkType *blk = tags->findBlock(pkt);
CacheBlk::State old_state = (blk) ? blk->status : 0; CacheBlk::State old_state = (blk) ? blk->status : 0;
CacheBlk::State new_state = coherence->getNewState(pkt,old_state); CacheBlk::State new_state = coherence->getNewState(pkt,old_state);
DPRINTF(Cache, "Block for blk addr %x moving from state %i to %i\n", DPRINTF(Cache, "Block for blk addr %x moving from state %i to %i\n",
pkt->getAddr() & (((ULL(1))<<48)-1), old_state, new_state); pkt->getAddr() & (((ULL(1))<<48)-1), old_state, new_state);
//Set the state on the upgrade //Set the state on the upgrade
memcpy(pkt->getPtr<uint8_t>(), blk->data, blkSize); memcpy(pkt->getPtr<uint8_t>(), blk->data, blkSize);
PacketList writebacks; PacketList writebacks;
tags->handleFill(blk, mshr, new_state, writebacks, pkt); tags->handleFill(blk, mshr, new_state, writebacks, pkt);
assert(writebacks.empty()); assert(writebacks.empty());
missQueue->handleResponse(pkt, curTick + hitLatency); missQueue->handleResponse(pkt, curTick + hitLatency);
} }
} else if (pkt && !pkt->req->isUncacheable()) { } else if (pkt && !pkt->req->isUncacheable()) {
pkt->flags &= ~NACKED_LINE; pkt->flags &= ~NACKED_LINE;
pkt->flags &= ~SATISFIED; pkt->flags &= ~SATISFIED;

View file

@ -215,6 +215,11 @@ MSHRQueue::markInService(MSHR* mshr)
//assert(mshr == pendingList.front()); //assert(mshr == pendingList.front());
if (!(mshr->pkt->needsResponse() || mshr->pkt->cmd == Packet::UpgradeReq)) { if (!(mshr->pkt->needsResponse() || mshr->pkt->cmd == Packet::UpgradeReq)) {
assert(mshr->getNumTargets() == 0); assert(mshr->getNumTargets() == 0);
if ((mshr->pkt->flags & SATISFIED) && (mshr->pkt->cmd == Packet::Writeback)) {
//Writeback hit, so delete it
//otherwise the consumer will delete it
delete mshr->pkt->req;
}
deallocate(mshr); deallocate(mshr);
return; return;
} }