changeset f98df9231cdd in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=f98df9231cdd
description:
mem: Create a separate class for the cache write buffer
This patch breaks out the cache write buffer into a separate class,
without affecting any stats. The goal of the patch is to avoid
encumbering the much-simpler write queue with the complex MSHR
handling. In a follow on patch this simplification allows us to
implement write combining.
The WriteQueue gets its own class, but shares a common ancestor, the
generic Queue, with the MSHRQueue.
diffstat:
src/mem/cache/SConscript | 2 +
src/mem/cache/base.cc | 5 +-
src/mem/cache/base.hh | 90 ++++---
src/mem/cache/cache.cc | 399 ++++++++++++++++++++----------------
src/mem/cache/cache.hh | 76 ++++--
src/mem/cache/mshr.cc | 27 +-
src/mem/cache/mshr.hh | 63 +----
src/mem/cache/mshr_queue.cc | 146 +------------
src/mem/cache/mshr_queue.hh | 115 +----------
src/mem/cache/queue.hh | 251 +++++++++++++++++++++++
src/mem/cache/queue_entry.hh | 109 ++++++++++
src/mem/cache/write_queue.cc | 91 ++++++++
src/mem/cache/write_queue.hh | 97 ++++++++
src/mem/cache/write_queue_entry.cc | 185 +++++++++++++++++
src/mem/cache/write_queue_entry.hh | 194 +++++++++++++++++
15 files changed, 1293 insertions(+), 557 deletions(-)
diffs (truncated from 2452 to 300 lines):
diff -r c1525cc9ec7f -r f98df9231cdd src/mem/cache/SConscript
--- a/src/mem/cache/SConscript Wed Mar 16 13:03:49 2016 -0700
+++ b/src/mem/cache/SConscript Thu Mar 17 09:51:18 2016 -0400
@@ -37,6 +37,8 @@
Source('blk.cc')
Source('mshr.cc')
Source('mshr_queue.cc')
+Source('write_queue.cc')
+Source('write_queue_entry.cc')
DebugFlag('Cache')
DebugFlag('CachePort')
diff -r c1525cc9ec7f -r f98df9231cdd src/mem/cache/base.cc
--- a/src/mem/cache/base.cc Wed Mar 16 13:03:49 2016 -0700
+++ b/src/mem/cache/base.cc Thu Mar 17 09:51:18 2016 -0400
@@ -68,9 +68,8 @@
BaseCache::BaseCache(const BaseCacheParams *p, unsigned blk_size)
: MemObject(p),
cpuSidePort(nullptr), memSidePort(nullptr),
- mshrQueue("MSHRs", p->mshrs, 4, p->demand_mshr_reserve, MSHRQueue_MSHRs),
- writeBuffer("write buffer", p->write_buffers, p->mshrs+1000, 0,
- MSHRQueue_WriteBuffer),
+ mshrQueue("MSHRs", p->mshrs, 4, p->demand_mshr_reserve),
+ writeBuffer("write buffer", p->write_buffers, p->mshrs+1000),
blkSize(blk_size),
lookupLatency(p->hit_latency),
forwardLatency(p->hit_latency),
diff -r c1525cc9ec7f -r f98df9231cdd src/mem/cache/base.hh
--- a/src/mem/cache/base.hh Wed Mar 16 13:03:49 2016 -0700
+++ b/src/mem/cache/base.hh Thu Mar 17 09:51:18 2016 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012-2013, 2015 ARM Limited
+ * Copyright (c) 2012-2013, 2015-2016 ARM Limited
* All rights reserved.
*
* The license below extends only to copyright in the software and shall
@@ -62,6 +62,7 @@
#include "debug/Cache.hh"
#include "debug/CachePort.hh"
#include "mem/cache/mshr_queue.hh"
+#include "mem/cache/write_queue.hh"
#include "mem/mem_object.hh"
#include "mem/packet.hh"
#include "mem/qport.hh"
@@ -72,12 +73,12 @@
#include "sim/sim_exit.hh"
#include "sim/system.hh"
-class MSHR;
/**
* A basic cache interface. Implements some common functions for speed.
*/
class BaseCache : public MemObject
{
+ protected:
/**
* Indexes to enumerate the MSHR queues.
*/
@@ -190,47 +191,29 @@
MSHRQueue mshrQueue;
/** Write/writeback buffer */
- MSHRQueue writeBuffer;
+ WriteQueue writeBuffer;
/**
- * Allocate a buffer, passing the time indicating when schedule an
- * event to the queued port to go and ask the MSHR and write queue
- * if they have packets to send.
- *
- * allocateBufferInternal() function is called in:
- * - MSHR allocateWriteBuffer (unchached write forwarded to WriteBuffer);
- * - MSHR allocateMissBuffer (miss in MSHR queue);
+ * Mark a request as in service (sent downstream in the memory
+ * system), effectively making this MSHR the ordering point.
*/
- MSHR *allocateBufferInternal(MSHRQueue *mq, Addr addr, int size,
- PacketPtr pkt, Tick time,
- bool sched_send)
+ void markInService(MSHR *mshr, bool pending_modified_resp)
{
- // check that the address is block aligned since we rely on
- // this in a number of places when checking for matches and
- // overlap
- assert(addr == blockAlign(addr));
+ bool wasFull = mshrQueue.isFull();
+ mshrQueue.markInService(mshr, pending_modified_resp);
- MSHR *mshr = mq->allocate(addr, size, pkt, time, order++,
- allocOnFill(pkt->cmd));
-
- if (mq->isFull()) {
- setBlocked((BlockedCause)mq->index);
+ if (wasFull && !mshrQueue.isFull()) {
+ clearBlocked(Blocked_NoMSHRs);
}
-
- if (sched_send)
- // schedule the send
- schedMemSideSendEvent(time);
-
- return mshr;
}
- void markInServiceInternal(MSHR *mshr, bool pending_modified_resp)
+ void markInService(WriteQueueEntry *entry)
{
- MSHRQueue *mq = mshr->queue;
- bool wasFull = mq->isFull();
- mq->markInService(mshr, pending_modified_resp);
- if (wasFull && !mq->isFull()) {
- clearBlocked((BlockedCause)mq->index);
+ bool wasFull = writeBuffer.isFull();
+ writeBuffer.markInService(entry);
+
+ if (wasFull && !writeBuffer.isFull()) {
+ clearBlocked(Blocked_NoWBBuffers);
}
}
@@ -511,19 +494,44 @@
MSHR *allocateMissBuffer(PacketPtr pkt, Tick time, bool sched_send = true)
{
- return allocateBufferInternal(&mshrQueue,
- blockAlign(pkt->getAddr()), blkSize,
- pkt, time, sched_send);
+ MSHR *mshr = mshrQueue.allocate(blockAlign(pkt->getAddr()), blkSize,
+ pkt, time, order++,
+ allocOnFill(pkt->cmd));
+
+ if (mshrQueue.isFull()) {
+ setBlocked((BlockedCause)MSHRQueue_MSHRs);
+ }
+
+ if (sched_send) {
+ // schedule the send
+ schedMemSideSendEvent(time);
+ }
+
+ return mshr;
}
- MSHR *allocateWriteBuffer(PacketPtr pkt, Tick time)
+ void allocateWriteBuffer(PacketPtr pkt, Tick time)
{
// should only see writes or clean evicts here
assert(pkt->isWrite() || pkt->cmd == MemCmd::CleanEvict);
- return allocateBufferInternal(&writeBuffer,
- blockAlign(pkt->getAddr()), blkSize,
- pkt, time, true);
+ Addr blk_addr = blockAlign(pkt->getAddr());
+
+ WriteQueueEntry *wq_entry =
+ writeBuffer.findMatch(blk_addr, pkt->isSecure());
+ if (wq_entry && !wq_entry->inService) {
+ DPRINTF(Cache, "Potential to merge writeback %s to %#llx",
+ pkt->cmdString(), pkt->getAddr());
+ }
+
+ writeBuffer.allocate(blk_addr, blkSize, pkt, time, order++);
+
+ if (writeBuffer.isFull()) {
+ setBlocked((BlockedCause)MSHRQueue_WriteBuffer);
+ }
+
+ // schedule the send
+ schedMemSideSendEvent(time);
}
/**
diff -r c1525cc9ec7f -r f98df9231cdd src/mem/cache/cache.cc
--- a/src/mem/cache/cache.cc Wed Mar 16 13:03:49 2016 -0700
+++ b/src/mem/cache/cache.cc Thu Mar 17 09:51:18 2016 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015 ARM Limited
+ * Copyright (c) 2010-2016 ARM Limited
* All rights reserved.
*
* The license below extends only to copyright in the software and shall
@@ -286,20 +286,6 @@
}
}
-
-/////////////////////////////////////////////////////
-//
-// MSHR helper functions
-//
-/////////////////////////////////////////////////////
-
-
-void
-Cache::markInService(MSHR *mshr, bool pending_modified_resp)
-{
- markInServiceInternal(mshr, pending_modified_resp);
-}
-
/////////////////////////////////////////////////////
//
// Access path: requests coming in from the CPU side
@@ -363,11 +349,9 @@
// generating CleanEvict and Writeback or simply CleanEvict and
// CleanEvict almost simultaneously will be caught by snoops sent out
// by crossbar.
- std::vector<MSHR *> outgoing;
- if (writeBuffer.findMatches(pkt->getAddr(), pkt->isSecure(),
- outgoing)) {
- assert(outgoing.size() == 1);
- MSHR *wb_entry = outgoing[0];
+ WriteQueueEntry *wb_entry = writeBuffer.findMatch(pkt->getAddr(),
+ pkt->isSecure());
+ if (wb_entry) {
assert(wb_entry->getNumTargets() == 1);
PacketPtr wbPkt = wb_entry->getTarget()->pkt;
assert(wbPkt->isWriteback());
@@ -388,7 +372,7 @@
// Dirty writeback from above trumps our clean
// writeback... discard here
// Note: markInService will remove entry from writeback buffer.
- markInService(wb_entry, false);
+ markInService(wb_entry);
delete wbPkt;
}
}
@@ -1239,6 +1223,50 @@
void
+Cache::handleUncacheableWriteResp(PacketPtr pkt)
+{
+ WriteQueueEntry *wq_entry =
+ dynamic_cast<WriteQueueEntry*>(pkt->senderState);
+ assert(wq_entry);
+
+ WriteQueueEntry::Target *target = wq_entry->getTarget();
+ Packet *tgt_pkt = target->pkt;
+
+ // we send out invalidation reqs and get invalidation
+ // responses for write-line requests
+ assert(tgt_pkt->cmd != MemCmd::WriteLineReq);
+
+ int stats_cmd_idx = tgt_pkt->cmdToIndex();
+ Tick miss_latency = curTick() - target->recvTime;
+ assert(pkt->req->masterId() < system->maxMasters());
+ mshr_uncacheable_lat[stats_cmd_idx][pkt->req->masterId()] +=
+ miss_latency;
+
+ tgt_pkt->makeTimingResponse();
+ // if this packet is an error copy that to the new packet
+ if (pkt->isError())
+ tgt_pkt->copyError(pkt);
+ // Reset the bus additional time as it is now accounted for
+ tgt_pkt->headerDelay = tgt_pkt->payloadDelay = 0;
+ Tick completion_time = clockEdge(responseLatency) +
+ pkt->headerDelay + pkt->payloadDelay;
+
+ cpuSidePort->schedTimingResp(tgt_pkt, completion_time, true);
+
+ wq_entry->popTarget();
+ assert(!wq_entry->hasTargets());
+
+ bool wasFull = writeBuffer.isFull();
+ writeBuffer.deallocate(wq_entry);
+
+ if (wasFull && !writeBuffer.isFull()) {
+ clearBlocked(Blocked_NoWBBuffers);
+ }
+
+ delete pkt;
+}
+
+void
Cache::recvTimingResp(PacketPtr pkt)
{
assert(pkt->isResponse());
@@ -1248,11 +1276,8 @@
panic_if(pkt->headerDelay != 0 && pkt->cmd != MemCmd::HardPFResp,
"%s saw a non-zero packet delay\n", name());
- MSHR *mshr = dynamic_cast<MSHR*>(pkt->senderState);
bool is_error = pkt->isError();
- assert(mshr);
-
if (is_error) {
DPRINTF(Cache, "Cache received packet with error for addr %#llx (%s), "
"cmd: %s\n", pkt->getAddr(), pkt->isSecure() ? "s" : "ns",
@@ -1263,8 +1288,18 @@
pkt->cmdString(), pkt->getAddr(), pkt->getSize(),
pkt->isSecure() ? "s" : "ns");
- MSHRQueue *mq = mshr->queue;
- bool wasFull = mq->isFull();
+ // if this is a write, we should be looking at an uncacheable
+ // write
+ if (pkt->isWrite()) {
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev