base.cc revision 12820
12810SN/A/* 212724Snikos.nikoleris@arm.com * Copyright (c) 2012-2013, 2018 ARM Limited 38856Sandreas.hansson@arm.com * All rights reserved. 48856Sandreas.hansson@arm.com * 58856Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 68856Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 78856Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 88856Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 98856Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 108856Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 118856Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 128856Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 138856Sandreas.hansson@arm.com * 142810SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan 152810SN/A * All rights reserved. 162810SN/A * 172810SN/A * Redistribution and use in source and binary forms, with or without 182810SN/A * modification, are permitted provided that the following conditions are 192810SN/A * met: redistributions of source code must retain the above copyright 202810SN/A * notice, this list of conditions and the following disclaimer; 212810SN/A * redistributions in binary form must reproduce the above copyright 222810SN/A * notice, this list of conditions and the following disclaimer in the 232810SN/A * documentation and/or other materials provided with the distribution; 242810SN/A * neither the name of the copyright holders nor the names of its 252810SN/A * contributors may be used to endorse or promote products derived from 262810SN/A * this software without specific prior written permission. 272810SN/A * 282810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392810SN/A * 402810SN/A * Authors: Erik Hallnor 4112724Snikos.nikoleris@arm.com * Nikos Nikoleris 422810SN/A */ 432810SN/A 442810SN/A/** 452810SN/A * @file 462810SN/A * Definition of BaseCache functions. 472810SN/A */ 482810SN/A 4911486Snikos.nikoleris@arm.com#include "mem/cache/base.hh" 5011486Snikos.nikoleris@arm.com 5112724Snikos.nikoleris@arm.com#include "base/compiler.hh" 5212724Snikos.nikoleris@arm.com#include "base/logging.hh" 538232Snate@binkert.org#include "debug/Cache.hh" 5412724Snikos.nikoleris@arm.com#include "debug/CachePort.hh" 5512724Snikos.nikoleris@arm.com#include "debug/CacheVerbose.hh" 5611486Snikos.nikoleris@arm.com#include "mem/cache/mshr.hh" 5712724Snikos.nikoleris@arm.com#include "mem/cache/prefetch/base.hh" 5812724Snikos.nikoleris@arm.com#include "mem/cache/queue_entry.hh" 5912724Snikos.nikoleris@arm.com#include "params/BaseCache.hh" 6012724Snikos.nikoleris@arm.com#include "sim/core.hh" 6112724Snikos.nikoleris@arm.com 6212724Snikos.nikoleris@arm.comclass BaseMasterPort; 6312724Snikos.nikoleris@arm.comclass BaseSlavePort; 642810SN/A 652810SN/Ausing namespace std; 662810SN/A 678856Sandreas.hansson@arm.comBaseCache::CacheSlavePort::CacheSlavePort(const std::string &_name, 688856Sandreas.hansson@arm.com BaseCache *_cache, 698856Sandreas.hansson@arm.com const std::string &_label) 708922Swilliam.wang@arm.com : QueuedSlavePort(_name, _cache, queue), queue(*_cache, *this, _label), 7112084Sspwilson2@wisc.edu blocked(false), mustSendRetry(false), 7212084Sspwilson2@wisc.edu sendRetryEvent([this]{ processSendRetry(); }, _name) 738856Sandreas.hansson@arm.com{ 748856Sandreas.hansson@arm.com} 754475SN/A 7611053Sandreas.hansson@arm.comBaseCache::BaseCache(const BaseCacheParams *p, unsigned blk_size) 775034SN/A : MemObject(p), 7812724Snikos.nikoleris@arm.com cpuSidePort (p->name + ".cpu_side", this, "CpuSidePort"), 7912724Snikos.nikoleris@arm.com memSidePort(p->name + ".mem_side", this, "MemSidePort"), 8011377Sandreas.hansson@arm.com mshrQueue("MSHRs", p->mshrs, 0, p->demand_mshr_reserve), // see below 8111377Sandreas.hansson@arm.com writeBuffer("write buffer", p->write_buffers, p->mshrs), // see below 8212724Snikos.nikoleris@arm.com tags(p->tags), 8312724Snikos.nikoleris@arm.com prefetcher(p->prefetcher), 8412724Snikos.nikoleris@arm.com prefetchOnAccess(p->prefetch_on_access), 8512724Snikos.nikoleris@arm.com writebackClean(p->writeback_clean), 8612724Snikos.nikoleris@arm.com tempBlockWriteback(nullptr), 8712724Snikos.nikoleris@arm.com writebackTempBlockAtomicEvent([this]{ writebackTempBlockAtomic(); }, 8812724Snikos.nikoleris@arm.com name(), false, 8912724Snikos.nikoleris@arm.com EventBase::Delayed_Writeback_Pri), 9011053Sandreas.hansson@arm.com blkSize(blk_size), 9111722Ssophiane.senni@gmail.com lookupLatency(p->tag_latency), 9211722Ssophiane.senni@gmail.com dataLatency(p->data_latency), 9311722Ssophiane.senni@gmail.com forwardLatency(p->tag_latency), 9411722Ssophiane.senni@gmail.com fillLatency(p->data_latency), 959263Smrinmoy.ghosh@arm.com responseLatency(p->response_latency), 965034SN/A numTarget(p->tgts_per_mshr), 9711331Sandreas.hansson@arm.com forwardSnoops(true), 9812724Snikos.nikoleris@arm.com clusivity(p->clusivity), 9910884Sandreas.hansson@arm.com isReadOnly(p->is_read_only), 1004626SN/A blocked(0), 10110360Sandreas.hansson@arm.com order(0), 10211484Snikos.nikoleris@arm.com noTargetMSHR(nullptr), 1035034SN/A missCount(p->max_miss_count), 1048883SAli.Saidi@ARM.com addrRanges(p->addr_ranges.begin(), p->addr_ranges.end()), 1058833Sdam.sunwoo@arm.com system(p->system) 1064458SN/A{ 10711377Sandreas.hansson@arm.com // the MSHR queue has no reserve entries as we check the MSHR 10811377Sandreas.hansson@arm.com // queue on every single allocation, whereas the write queue has 10911377Sandreas.hansson@arm.com // as many reserve entries as we have MSHRs, since every MSHR may 11011377Sandreas.hansson@arm.com // eventually require a writeback, and we do not check the write 11111377Sandreas.hansson@arm.com // buffer before committing to an MSHR 11211377Sandreas.hansson@arm.com 11311331Sandreas.hansson@arm.com // forward snoops is overridden in init() once we can query 11411331Sandreas.hansson@arm.com // whether the connected master is actually snooping or not 11512724Snikos.nikoleris@arm.com 11612730Sodanrc@yahoo.com.br tempBlock = new TempCacheBlk(); 11712724Snikos.nikoleris@arm.com tempBlock->data = new uint8_t[blkSize]; 11812724Snikos.nikoleris@arm.com 11912724Snikos.nikoleris@arm.com tags->setCache(this); 12012724Snikos.nikoleris@arm.com if (prefetcher) 12112724Snikos.nikoleris@arm.com prefetcher->setCache(this); 12212724Snikos.nikoleris@arm.com} 12312724Snikos.nikoleris@arm.com 12412724Snikos.nikoleris@arm.comBaseCache::~BaseCache() 12512724Snikos.nikoleris@arm.com{ 12612724Snikos.nikoleris@arm.com delete [] tempBlock->data; 12712724Snikos.nikoleris@arm.com delete tempBlock; 1282810SN/A} 1292810SN/A 1303013SN/Avoid 1318856Sandreas.hansson@arm.comBaseCache::CacheSlavePort::setBlocked() 1322810SN/A{ 1333013SN/A assert(!blocked); 13410714Sandreas.hansson@arm.com DPRINTF(CachePort, "Port is blocking new requests\n"); 1352810SN/A blocked = true; 1369614Srene.dejong@arm.com // if we already scheduled a retry in this cycle, but it has not yet 1379614Srene.dejong@arm.com // happened, cancel it 1389614Srene.dejong@arm.com if (sendRetryEvent.scheduled()) { 13910345SCurtis.Dunham@arm.com owner.deschedule(sendRetryEvent); 14010714Sandreas.hansson@arm.com DPRINTF(CachePort, "Port descheduled retry\n"); 14110345SCurtis.Dunham@arm.com mustSendRetry = true; 1429614Srene.dejong@arm.com } 1432810SN/A} 1442810SN/A 1452810SN/Avoid 1468856Sandreas.hansson@arm.comBaseCache::CacheSlavePort::clearBlocked() 1472810SN/A{ 1483013SN/A assert(blocked); 14910714Sandreas.hansson@arm.com DPRINTF(CachePort, "Port is accepting new requests\n"); 1503013SN/A blocked = false; 1518856Sandreas.hansson@arm.com if (mustSendRetry) { 15210714Sandreas.hansson@arm.com // @TODO: need to find a better time (next cycle?) 1538922Swilliam.wang@arm.com owner.schedule(sendRetryEvent, curTick() + 1); 1542897SN/A } 1552810SN/A} 1562810SN/A 15710344Sandreas.hansson@arm.comvoid 15810344Sandreas.hansson@arm.comBaseCache::CacheSlavePort::processSendRetry() 15910344Sandreas.hansson@arm.com{ 16010714Sandreas.hansson@arm.com DPRINTF(CachePort, "Port is sending retry\n"); 16110344Sandreas.hansson@arm.com 16210344Sandreas.hansson@arm.com // reset the flag and call retry 16310344Sandreas.hansson@arm.com mustSendRetry = false; 16410713Sandreas.hansson@arm.com sendRetryReq(); 16510344Sandreas.hansson@arm.com} 1662844SN/A 16712730Sodanrc@yahoo.com.brAddr 16812730Sodanrc@yahoo.com.brBaseCache::regenerateBlkAddr(CacheBlk* blk) 16912730Sodanrc@yahoo.com.br{ 17012730Sodanrc@yahoo.com.br if (blk != tempBlock) { 17112730Sodanrc@yahoo.com.br return tags->regenerateBlkAddr(blk); 17212730Sodanrc@yahoo.com.br } else { 17312730Sodanrc@yahoo.com.br return tempBlock->getAddr(); 17412730Sodanrc@yahoo.com.br } 17512730Sodanrc@yahoo.com.br} 17612730Sodanrc@yahoo.com.br 1772810SN/Avoid 1782858SN/ABaseCache::init() 1792858SN/A{ 18012724Snikos.nikoleris@arm.com if (!cpuSidePort.isConnected() || !memSidePort.isConnected()) 1818922Swilliam.wang@arm.com fatal("Cache ports on %s are not connected\n", name()); 18212724Snikos.nikoleris@arm.com cpuSidePort.sendRangeChange(); 18312724Snikos.nikoleris@arm.com forwardSnoops = cpuSidePort.isSnooping(); 1842858SN/A} 1852858SN/A 1869294Sandreas.hansson@arm.comBaseMasterPort & 1879294Sandreas.hansson@arm.comBaseCache::getMasterPort(const std::string &if_name, PortID idx) 1888922Swilliam.wang@arm.com{ 1898922Swilliam.wang@arm.com if (if_name == "mem_side") { 19012724Snikos.nikoleris@arm.com return memSidePort; 1918922Swilliam.wang@arm.com } else { 1928922Swilliam.wang@arm.com return MemObject::getMasterPort(if_name, idx); 1938922Swilliam.wang@arm.com } 1948922Swilliam.wang@arm.com} 1958922Swilliam.wang@arm.com 1969294Sandreas.hansson@arm.comBaseSlavePort & 1979294Sandreas.hansson@arm.comBaseCache::getSlavePort(const std::string &if_name, PortID idx) 1988922Swilliam.wang@arm.com{ 1998922Swilliam.wang@arm.com if (if_name == "cpu_side") { 20012724Snikos.nikoleris@arm.com return cpuSidePort; 2018922Swilliam.wang@arm.com } else { 2028922Swilliam.wang@arm.com return MemObject::getSlavePort(if_name, idx); 2038922Swilliam.wang@arm.com } 2048922Swilliam.wang@arm.com} 2054628SN/A 20610821Sandreas.hansson@arm.combool 20710821Sandreas.hansson@arm.comBaseCache::inRange(Addr addr) const 20810821Sandreas.hansson@arm.com{ 20910821Sandreas.hansson@arm.com for (const auto& r : addrRanges) { 21010821Sandreas.hansson@arm.com if (r.contains(addr)) { 21110821Sandreas.hansson@arm.com return true; 21210821Sandreas.hansson@arm.com } 21310821Sandreas.hansson@arm.com } 21410821Sandreas.hansson@arm.com return false; 21510821Sandreas.hansson@arm.com} 21610821Sandreas.hansson@arm.com 2172858SN/Avoid 21812724Snikos.nikoleris@arm.comBaseCache::handleTimingReqHit(PacketPtr pkt, CacheBlk *blk, Tick request_time) 21912724Snikos.nikoleris@arm.com{ 22012724Snikos.nikoleris@arm.com if (pkt->needsResponse()) { 22112724Snikos.nikoleris@arm.com pkt->makeTimingResponse(); 22212724Snikos.nikoleris@arm.com // @todo: Make someone pay for this 22312724Snikos.nikoleris@arm.com pkt->headerDelay = pkt->payloadDelay = 0; 22412724Snikos.nikoleris@arm.com 22512724Snikos.nikoleris@arm.com // In this case we are considering request_time that takes 22612724Snikos.nikoleris@arm.com // into account the delay of the xbar, if any, and just 22712724Snikos.nikoleris@arm.com // lat, neglecting responseLatency, modelling hit latency 22812724Snikos.nikoleris@arm.com // just as lookupLatency or or the value of lat overriden 22912724Snikos.nikoleris@arm.com // by access(), that calls accessBlock() function. 23012724Snikos.nikoleris@arm.com cpuSidePort.schedTimingResp(pkt, request_time, true); 23112724Snikos.nikoleris@arm.com } else { 23212724Snikos.nikoleris@arm.com DPRINTF(Cache, "%s satisfied %s, no response needed\n", __func__, 23312724Snikos.nikoleris@arm.com pkt->print()); 23412724Snikos.nikoleris@arm.com 23512724Snikos.nikoleris@arm.com // queue the packet for deletion, as the sending cache is 23612724Snikos.nikoleris@arm.com // still relying on it; if the block is found in access(), 23712724Snikos.nikoleris@arm.com // CleanEvict and Writeback messages will be deleted 23812724Snikos.nikoleris@arm.com // here as well 23912724Snikos.nikoleris@arm.com pendingDelete.reset(pkt); 24012724Snikos.nikoleris@arm.com } 24112724Snikos.nikoleris@arm.com} 24212724Snikos.nikoleris@arm.com 24312724Snikos.nikoleris@arm.comvoid 24412724Snikos.nikoleris@arm.comBaseCache::handleTimingReqMiss(PacketPtr pkt, MSHR *mshr, CacheBlk *blk, 24512724Snikos.nikoleris@arm.com Tick forward_time, Tick request_time) 24612724Snikos.nikoleris@arm.com{ 24712724Snikos.nikoleris@arm.com if (mshr) { 24812724Snikos.nikoleris@arm.com /// MSHR hit 24912724Snikos.nikoleris@arm.com /// @note writebacks will be checked in getNextMSHR() 25012724Snikos.nikoleris@arm.com /// for any conflicting requests to the same block 25112724Snikos.nikoleris@arm.com 25212724Snikos.nikoleris@arm.com //@todo remove hw_pf here 25312724Snikos.nikoleris@arm.com 25412724Snikos.nikoleris@arm.com // Coalesce unless it was a software prefetch (see above). 25512724Snikos.nikoleris@arm.com if (pkt) { 25612724Snikos.nikoleris@arm.com assert(!pkt->isWriteback()); 25712724Snikos.nikoleris@arm.com // CleanEvicts corresponding to blocks which have 25812724Snikos.nikoleris@arm.com // outstanding requests in MSHRs are simply sunk here 25912724Snikos.nikoleris@arm.com if (pkt->cmd == MemCmd::CleanEvict) { 26012724Snikos.nikoleris@arm.com pendingDelete.reset(pkt); 26112724Snikos.nikoleris@arm.com } else if (pkt->cmd == MemCmd::WriteClean) { 26212724Snikos.nikoleris@arm.com // A WriteClean should never coalesce with any 26312724Snikos.nikoleris@arm.com // outstanding cache maintenance requests. 26412724Snikos.nikoleris@arm.com 26512724Snikos.nikoleris@arm.com // We use forward_time here because there is an 26612724Snikos.nikoleris@arm.com // uncached memory write, forwarded to WriteBuffer. 26712724Snikos.nikoleris@arm.com allocateWriteBuffer(pkt, forward_time); 26812724Snikos.nikoleris@arm.com } else { 26912724Snikos.nikoleris@arm.com DPRINTF(Cache, "%s coalescing MSHR for %s\n", __func__, 27012724Snikos.nikoleris@arm.com pkt->print()); 27112724Snikos.nikoleris@arm.com 27212724Snikos.nikoleris@arm.com assert(pkt->req->masterId() < system->maxMasters()); 27312724Snikos.nikoleris@arm.com mshr_hits[pkt->cmdToIndex()][pkt->req->masterId()]++; 27412724Snikos.nikoleris@arm.com 27512724Snikos.nikoleris@arm.com // We use forward_time here because it is the same 27612724Snikos.nikoleris@arm.com // considering new targets. We have multiple 27712724Snikos.nikoleris@arm.com // requests for the same address here. It 27812724Snikos.nikoleris@arm.com // specifies the latency to allocate an internal 27912724Snikos.nikoleris@arm.com // buffer and to schedule an event to the queued 28012724Snikos.nikoleris@arm.com // port and also takes into account the additional 28112724Snikos.nikoleris@arm.com // delay of the xbar. 28212724Snikos.nikoleris@arm.com mshr->allocateTarget(pkt, forward_time, order++, 28312724Snikos.nikoleris@arm.com allocOnFill(pkt->cmd)); 28412724Snikos.nikoleris@arm.com if (mshr->getNumTargets() == numTarget) { 28512724Snikos.nikoleris@arm.com noTargetMSHR = mshr; 28612724Snikos.nikoleris@arm.com setBlocked(Blocked_NoTargets); 28712724Snikos.nikoleris@arm.com // need to be careful with this... if this mshr isn't 28812724Snikos.nikoleris@arm.com // ready yet (i.e. time > curTick()), we don't want to 28912724Snikos.nikoleris@arm.com // move it ahead of mshrs that are ready 29012724Snikos.nikoleris@arm.com // mshrQueue.moveToFront(mshr); 29112724Snikos.nikoleris@arm.com } 29212724Snikos.nikoleris@arm.com } 29312724Snikos.nikoleris@arm.com } 29412724Snikos.nikoleris@arm.com } else { 29512724Snikos.nikoleris@arm.com // no MSHR 29612724Snikos.nikoleris@arm.com assert(pkt->req->masterId() < system->maxMasters()); 29712724Snikos.nikoleris@arm.com mshr_misses[pkt->cmdToIndex()][pkt->req->masterId()]++; 29812724Snikos.nikoleris@arm.com 29912724Snikos.nikoleris@arm.com if (pkt->isEviction() || pkt->cmd == MemCmd::WriteClean) { 30012724Snikos.nikoleris@arm.com // We use forward_time here because there is an 30112724Snikos.nikoleris@arm.com // writeback or writeclean, forwarded to WriteBuffer. 30212724Snikos.nikoleris@arm.com allocateWriteBuffer(pkt, forward_time); 30312724Snikos.nikoleris@arm.com } else { 30412724Snikos.nikoleris@arm.com if (blk && blk->isValid()) { 30512724Snikos.nikoleris@arm.com // If we have a write miss to a valid block, we 30612724Snikos.nikoleris@arm.com // need to mark the block non-readable. Otherwise 30712724Snikos.nikoleris@arm.com // if we allow reads while there's an outstanding 30812724Snikos.nikoleris@arm.com // write miss, the read could return stale data 30912724Snikos.nikoleris@arm.com // out of the cache block... a more aggressive 31012724Snikos.nikoleris@arm.com // system could detect the overlap (if any) and 31112724Snikos.nikoleris@arm.com // forward data out of the MSHRs, but we don't do 31212724Snikos.nikoleris@arm.com // that yet. Note that we do need to leave the 31312724Snikos.nikoleris@arm.com // block valid so that it stays in the cache, in 31412724Snikos.nikoleris@arm.com // case we get an upgrade response (and hence no 31512724Snikos.nikoleris@arm.com // new data) when the write miss completes. 31612724Snikos.nikoleris@arm.com // As long as CPUs do proper store/load forwarding 31712724Snikos.nikoleris@arm.com // internally, and have a sufficiently weak memory 31812724Snikos.nikoleris@arm.com // model, this is probably unnecessary, but at some 31912724Snikos.nikoleris@arm.com // point it must have seemed like we needed it... 32012724Snikos.nikoleris@arm.com assert((pkt->needsWritable() && !blk->isWritable()) || 32112724Snikos.nikoleris@arm.com pkt->req->isCacheMaintenance()); 32212724Snikos.nikoleris@arm.com blk->status &= ~BlkReadable; 32312724Snikos.nikoleris@arm.com } 32412724Snikos.nikoleris@arm.com // Here we are using forward_time, modelling the latency of 32512724Snikos.nikoleris@arm.com // a miss (outbound) just as forwardLatency, neglecting the 32612724Snikos.nikoleris@arm.com // lookupLatency component. 32712724Snikos.nikoleris@arm.com allocateMissBuffer(pkt, forward_time); 32812724Snikos.nikoleris@arm.com } 32912724Snikos.nikoleris@arm.com } 33012724Snikos.nikoleris@arm.com} 33112724Snikos.nikoleris@arm.com 33212724Snikos.nikoleris@arm.comvoid 33312724Snikos.nikoleris@arm.comBaseCache::recvTimingReq(PacketPtr pkt) 33412724Snikos.nikoleris@arm.com{ 33512724Snikos.nikoleris@arm.com // anything that is merely forwarded pays for the forward latency and 33612724Snikos.nikoleris@arm.com // the delay provided by the crossbar 33712724Snikos.nikoleris@arm.com Tick forward_time = clockEdge(forwardLatency) + pkt->headerDelay; 33812724Snikos.nikoleris@arm.com 33912724Snikos.nikoleris@arm.com // We use lookupLatency here because it is used to specify the latency 34012724Snikos.nikoleris@arm.com // to access. 34112724Snikos.nikoleris@arm.com Cycles lat = lookupLatency; 34212724Snikos.nikoleris@arm.com CacheBlk *blk = nullptr; 34312724Snikos.nikoleris@arm.com bool satisfied = false; 34412724Snikos.nikoleris@arm.com { 34512724Snikos.nikoleris@arm.com PacketList writebacks; 34612724Snikos.nikoleris@arm.com // Note that lat is passed by reference here. The function 34712724Snikos.nikoleris@arm.com // access() calls accessBlock() which can modify lat value. 34812724Snikos.nikoleris@arm.com satisfied = access(pkt, blk, lat, writebacks); 34912724Snikos.nikoleris@arm.com 35012724Snikos.nikoleris@arm.com // copy writebacks to write buffer here to ensure they logically 35112820Srmk35@cl.cam.ac.uk // precede anything happening below 35212724Snikos.nikoleris@arm.com doWritebacks(writebacks, forward_time); 35312724Snikos.nikoleris@arm.com } 35412724Snikos.nikoleris@arm.com 35512724Snikos.nikoleris@arm.com // Here we charge the headerDelay that takes into account the latencies 35612724Snikos.nikoleris@arm.com // of the bus, if the packet comes from it. 35712724Snikos.nikoleris@arm.com // The latency charged it is just lat that is the value of lookupLatency 35812724Snikos.nikoleris@arm.com // modified by access() function, or if not just lookupLatency. 35912724Snikos.nikoleris@arm.com // In case of a hit we are neglecting response latency. 36012724Snikos.nikoleris@arm.com // In case of a miss we are neglecting forward latency. 36112724Snikos.nikoleris@arm.com Tick request_time = clockEdge(lat) + pkt->headerDelay; 36212724Snikos.nikoleris@arm.com // Here we reset the timing of the packet. 36312724Snikos.nikoleris@arm.com pkt->headerDelay = pkt->payloadDelay = 0; 36412724Snikos.nikoleris@arm.com // track time of availability of next prefetch, if any 36512724Snikos.nikoleris@arm.com Tick next_pf_time = MaxTick; 36612724Snikos.nikoleris@arm.com 36712724Snikos.nikoleris@arm.com if (satisfied) { 36812724Snikos.nikoleris@arm.com // if need to notify the prefetcher we have to do it before 36912724Snikos.nikoleris@arm.com // anything else as later handleTimingReqHit might turn the 37012724Snikos.nikoleris@arm.com // packet in a response 37112724Snikos.nikoleris@arm.com if (prefetcher && 37212724Snikos.nikoleris@arm.com (prefetchOnAccess || (blk && blk->wasPrefetched()))) { 37312724Snikos.nikoleris@arm.com if (blk) 37412724Snikos.nikoleris@arm.com blk->status &= ~BlkHWPrefetched; 37512724Snikos.nikoleris@arm.com 37612724Snikos.nikoleris@arm.com // Don't notify on SWPrefetch 37712724Snikos.nikoleris@arm.com if (!pkt->cmd.isSWPrefetch()) { 37812724Snikos.nikoleris@arm.com assert(!pkt->req->isCacheMaintenance()); 37912724Snikos.nikoleris@arm.com next_pf_time = prefetcher->notify(pkt); 38012724Snikos.nikoleris@arm.com } 38112724Snikos.nikoleris@arm.com } 38212724Snikos.nikoleris@arm.com 38312724Snikos.nikoleris@arm.com handleTimingReqHit(pkt, blk, request_time); 38412724Snikos.nikoleris@arm.com } else { 38512724Snikos.nikoleris@arm.com handleTimingReqMiss(pkt, blk, forward_time, request_time); 38612724Snikos.nikoleris@arm.com 38712724Snikos.nikoleris@arm.com // We should call the prefetcher reguardless if the request is 38812724Snikos.nikoleris@arm.com // satisfied or not, reguardless if the request is in the MSHR 38912724Snikos.nikoleris@arm.com // or not. The request could be a ReadReq hit, but still not 39012724Snikos.nikoleris@arm.com // satisfied (potentially because of a prior write to the same 39112724Snikos.nikoleris@arm.com // cache line. So, even when not satisfied, there is an MSHR 39212724Snikos.nikoleris@arm.com // already allocated for this, we need to let the prefetcher 39312724Snikos.nikoleris@arm.com // know about the request 39412724Snikos.nikoleris@arm.com 39512724Snikos.nikoleris@arm.com // Don't notify prefetcher on SWPrefetch or cache maintenance 39612724Snikos.nikoleris@arm.com // operations 39712724Snikos.nikoleris@arm.com if (prefetcher && pkt && 39812724Snikos.nikoleris@arm.com !pkt->cmd.isSWPrefetch() && 39912724Snikos.nikoleris@arm.com !pkt->req->isCacheMaintenance()) { 40012724Snikos.nikoleris@arm.com next_pf_time = prefetcher->notify(pkt); 40112724Snikos.nikoleris@arm.com } 40212724Snikos.nikoleris@arm.com } 40312724Snikos.nikoleris@arm.com 40412724Snikos.nikoleris@arm.com if (next_pf_time != MaxTick) { 40512724Snikos.nikoleris@arm.com schedMemSideSendEvent(next_pf_time); 40612724Snikos.nikoleris@arm.com } 40712724Snikos.nikoleris@arm.com} 40812724Snikos.nikoleris@arm.com 40912724Snikos.nikoleris@arm.comvoid 41012724Snikos.nikoleris@arm.comBaseCache::handleUncacheableWriteResp(PacketPtr pkt) 41112724Snikos.nikoleris@arm.com{ 41212724Snikos.nikoleris@arm.com Tick completion_time = clockEdge(responseLatency) + 41312724Snikos.nikoleris@arm.com pkt->headerDelay + pkt->payloadDelay; 41412724Snikos.nikoleris@arm.com 41512724Snikos.nikoleris@arm.com // Reset the bus additional time as it is now accounted for 41612724Snikos.nikoleris@arm.com pkt->headerDelay = pkt->payloadDelay = 0; 41712724Snikos.nikoleris@arm.com 41812724Snikos.nikoleris@arm.com cpuSidePort.schedTimingResp(pkt, completion_time, true); 41912724Snikos.nikoleris@arm.com} 42012724Snikos.nikoleris@arm.com 42112724Snikos.nikoleris@arm.comvoid 42212724Snikos.nikoleris@arm.comBaseCache::recvTimingResp(PacketPtr pkt) 42312724Snikos.nikoleris@arm.com{ 42412724Snikos.nikoleris@arm.com assert(pkt->isResponse()); 42512724Snikos.nikoleris@arm.com 42612724Snikos.nikoleris@arm.com // all header delay should be paid for by the crossbar, unless 42712724Snikos.nikoleris@arm.com // this is a prefetch response from above 42812724Snikos.nikoleris@arm.com panic_if(pkt->headerDelay != 0 && pkt->cmd != MemCmd::HardPFResp, 42912724Snikos.nikoleris@arm.com "%s saw a non-zero packet delay\n", name()); 43012724Snikos.nikoleris@arm.com 43112724Snikos.nikoleris@arm.com const bool is_error = pkt->isError(); 43212724Snikos.nikoleris@arm.com 43312724Snikos.nikoleris@arm.com if (is_error) { 43412724Snikos.nikoleris@arm.com DPRINTF(Cache, "%s: Cache received %s with error\n", __func__, 43512724Snikos.nikoleris@arm.com pkt->print()); 43612724Snikos.nikoleris@arm.com } 43712724Snikos.nikoleris@arm.com 43812724Snikos.nikoleris@arm.com DPRINTF(Cache, "%s: Handling response %s\n", __func__, 43912724Snikos.nikoleris@arm.com pkt->print()); 44012724Snikos.nikoleris@arm.com 44112724Snikos.nikoleris@arm.com // if this is a write, we should be looking at an uncacheable 44212724Snikos.nikoleris@arm.com // write 44312724Snikos.nikoleris@arm.com if (pkt->isWrite()) { 44412724Snikos.nikoleris@arm.com assert(pkt->req->isUncacheable()); 44512724Snikos.nikoleris@arm.com handleUncacheableWriteResp(pkt); 44612724Snikos.nikoleris@arm.com return; 44712724Snikos.nikoleris@arm.com } 44812724Snikos.nikoleris@arm.com 44912724Snikos.nikoleris@arm.com // we have dealt with any (uncacheable) writes above, from here on 45012724Snikos.nikoleris@arm.com // we know we are dealing with an MSHR due to a miss or a prefetch 45112724Snikos.nikoleris@arm.com MSHR *mshr = dynamic_cast<MSHR*>(pkt->popSenderState()); 45212724Snikos.nikoleris@arm.com assert(mshr); 45312724Snikos.nikoleris@arm.com 45412724Snikos.nikoleris@arm.com if (mshr == noTargetMSHR) { 45512724Snikos.nikoleris@arm.com // we always clear at least one target 45612724Snikos.nikoleris@arm.com clearBlocked(Blocked_NoTargets); 45712724Snikos.nikoleris@arm.com noTargetMSHR = nullptr; 45812724Snikos.nikoleris@arm.com } 45912724Snikos.nikoleris@arm.com 46012724Snikos.nikoleris@arm.com // Initial target is used just for stats 46112724Snikos.nikoleris@arm.com MSHR::Target *initial_tgt = mshr->getTarget(); 46212724Snikos.nikoleris@arm.com int stats_cmd_idx = initial_tgt->pkt->cmdToIndex(); 46312724Snikos.nikoleris@arm.com Tick miss_latency = curTick() - initial_tgt->recvTime; 46412724Snikos.nikoleris@arm.com 46512724Snikos.nikoleris@arm.com if (pkt->req->isUncacheable()) { 46612724Snikos.nikoleris@arm.com assert(pkt->req->masterId() < system->maxMasters()); 46712724Snikos.nikoleris@arm.com mshr_uncacheable_lat[stats_cmd_idx][pkt->req->masterId()] += 46812724Snikos.nikoleris@arm.com miss_latency; 46912724Snikos.nikoleris@arm.com } else { 47012724Snikos.nikoleris@arm.com assert(pkt->req->masterId() < system->maxMasters()); 47112724Snikos.nikoleris@arm.com mshr_miss_latency[stats_cmd_idx][pkt->req->masterId()] += 47212724Snikos.nikoleris@arm.com miss_latency; 47312724Snikos.nikoleris@arm.com } 47412724Snikos.nikoleris@arm.com 47512724Snikos.nikoleris@arm.com PacketList writebacks; 47612724Snikos.nikoleris@arm.com 47712724Snikos.nikoleris@arm.com bool is_fill = !mshr->isForward && 47812724Snikos.nikoleris@arm.com (pkt->isRead() || pkt->cmd == MemCmd::UpgradeResp); 47912724Snikos.nikoleris@arm.com 48012724Snikos.nikoleris@arm.com CacheBlk *blk = tags->findBlock(pkt->getAddr(), pkt->isSecure()); 48112724Snikos.nikoleris@arm.com 48212724Snikos.nikoleris@arm.com if (is_fill && !is_error) { 48312724Snikos.nikoleris@arm.com DPRINTF(Cache, "Block for addr %#llx being updated in Cache\n", 48412724Snikos.nikoleris@arm.com pkt->getAddr()); 48512724Snikos.nikoleris@arm.com 48612724Snikos.nikoleris@arm.com blk = handleFill(pkt, blk, writebacks, mshr->allocOnFill()); 48712724Snikos.nikoleris@arm.com assert(blk != nullptr); 48812724Snikos.nikoleris@arm.com } 48912724Snikos.nikoleris@arm.com 49012724Snikos.nikoleris@arm.com if (blk && blk->isValid() && pkt->isClean() && !pkt->isInvalidate()) { 49112724Snikos.nikoleris@arm.com // The block was marked not readable while there was a pending 49212724Snikos.nikoleris@arm.com // cache maintenance operation, restore its flag. 49312724Snikos.nikoleris@arm.com blk->status |= BlkReadable; 49412794Snikos.nikoleris@arm.com 49512794Snikos.nikoleris@arm.com // This was a cache clean operation (without invalidate) 49612794Snikos.nikoleris@arm.com // and we have a copy of the block already. Since there 49712794Snikos.nikoleris@arm.com // is no invalidation, we can promote targets that don't 49812794Snikos.nikoleris@arm.com // require a writable copy 49912794Snikos.nikoleris@arm.com mshr->promoteReadable(); 50012724Snikos.nikoleris@arm.com } 50112724Snikos.nikoleris@arm.com 50212724Snikos.nikoleris@arm.com if (blk && blk->isWritable() && !pkt->req->isCacheInvalidate()) { 50312724Snikos.nikoleris@arm.com // If at this point the referenced block is writable and the 50412724Snikos.nikoleris@arm.com // response is not a cache invalidate, we promote targets that 50512724Snikos.nikoleris@arm.com // were deferred as we couldn't guarrantee a writable copy 50612724Snikos.nikoleris@arm.com mshr->promoteWritable(); 50712724Snikos.nikoleris@arm.com } 50812724Snikos.nikoleris@arm.com 50912724Snikos.nikoleris@arm.com serviceMSHRTargets(mshr, pkt, blk, writebacks); 51012724Snikos.nikoleris@arm.com 51112724Snikos.nikoleris@arm.com if (mshr->promoteDeferredTargets()) { 51212724Snikos.nikoleris@arm.com // avoid later read getting stale data while write miss is 51312724Snikos.nikoleris@arm.com // outstanding.. see comment in timingAccess() 51412724Snikos.nikoleris@arm.com if (blk) { 51512724Snikos.nikoleris@arm.com blk->status &= ~BlkReadable; 51612724Snikos.nikoleris@arm.com } 51712724Snikos.nikoleris@arm.com mshrQueue.markPending(mshr); 51812724Snikos.nikoleris@arm.com schedMemSideSendEvent(clockEdge() + pkt->payloadDelay); 51912724Snikos.nikoleris@arm.com } else { 52012724Snikos.nikoleris@arm.com // while we deallocate an mshr from the queue we still have to 52112724Snikos.nikoleris@arm.com // check the isFull condition before and after as we might 52212724Snikos.nikoleris@arm.com // have been using the reserved entries already 52312724Snikos.nikoleris@arm.com const bool was_full = mshrQueue.isFull(); 52412724Snikos.nikoleris@arm.com mshrQueue.deallocate(mshr); 52512724Snikos.nikoleris@arm.com if (was_full && !mshrQueue.isFull()) { 52612724Snikos.nikoleris@arm.com clearBlocked(Blocked_NoMSHRs); 52712724Snikos.nikoleris@arm.com } 52812724Snikos.nikoleris@arm.com 52912724Snikos.nikoleris@arm.com // Request the bus for a prefetch if this deallocation freed enough 53012724Snikos.nikoleris@arm.com // MSHRs for a prefetch to take place 53112724Snikos.nikoleris@arm.com if (prefetcher && mshrQueue.canPrefetch()) { 53212724Snikos.nikoleris@arm.com Tick next_pf_time = std::max(prefetcher->nextPrefetchReadyTime(), 53312724Snikos.nikoleris@arm.com clockEdge()); 53412724Snikos.nikoleris@arm.com if (next_pf_time != MaxTick) 53512724Snikos.nikoleris@arm.com schedMemSideSendEvent(next_pf_time); 53612724Snikos.nikoleris@arm.com } 53712724Snikos.nikoleris@arm.com } 53812724Snikos.nikoleris@arm.com 53912724Snikos.nikoleris@arm.com // if we used temp block, check to see if its valid and then clear it out 54012724Snikos.nikoleris@arm.com if (blk == tempBlock && tempBlock->isValid()) { 54112724Snikos.nikoleris@arm.com evictBlock(blk, writebacks); 54212724Snikos.nikoleris@arm.com } 54312724Snikos.nikoleris@arm.com 54412724Snikos.nikoleris@arm.com const Tick forward_time = clockEdge(forwardLatency) + pkt->headerDelay; 54512724Snikos.nikoleris@arm.com // copy writebacks to write buffer 54612724Snikos.nikoleris@arm.com doWritebacks(writebacks, forward_time); 54712724Snikos.nikoleris@arm.com 54812724Snikos.nikoleris@arm.com DPRINTF(CacheVerbose, "%s: Leaving with %s\n", __func__, pkt->print()); 54912724Snikos.nikoleris@arm.com delete pkt; 55012724Snikos.nikoleris@arm.com} 55112724Snikos.nikoleris@arm.com 55212724Snikos.nikoleris@arm.com 55312724Snikos.nikoleris@arm.comTick 55412724Snikos.nikoleris@arm.comBaseCache::recvAtomic(PacketPtr pkt) 55512724Snikos.nikoleris@arm.com{ 55612724Snikos.nikoleris@arm.com // We are in atomic mode so we pay just for lookupLatency here. 55712724Snikos.nikoleris@arm.com Cycles lat = lookupLatency; 55812724Snikos.nikoleris@arm.com 55912724Snikos.nikoleris@arm.com // follow the same flow as in recvTimingReq, and check if a cache 56012724Snikos.nikoleris@arm.com // above us is responding 56112724Snikos.nikoleris@arm.com if (pkt->cacheResponding() && !pkt->isClean()) { 56212724Snikos.nikoleris@arm.com assert(!pkt->req->isCacheInvalidate()); 56312724Snikos.nikoleris@arm.com DPRINTF(Cache, "Cache above responding to %s: not responding\n", 56412724Snikos.nikoleris@arm.com pkt->print()); 56512724Snikos.nikoleris@arm.com 56612724Snikos.nikoleris@arm.com // if a cache is responding, and it had the line in Owned 56712724Snikos.nikoleris@arm.com // rather than Modified state, we need to invalidate any 56812724Snikos.nikoleris@arm.com // copies that are not on the same path to memory 56912724Snikos.nikoleris@arm.com assert(pkt->needsWritable() && !pkt->responderHadWritable()); 57012724Snikos.nikoleris@arm.com lat += ticksToCycles(memSidePort.sendAtomic(pkt)); 57112724Snikos.nikoleris@arm.com 57212724Snikos.nikoleris@arm.com return lat * clockPeriod(); 57312724Snikos.nikoleris@arm.com } 57412724Snikos.nikoleris@arm.com 57512724Snikos.nikoleris@arm.com // should assert here that there are no outstanding MSHRs or 57612724Snikos.nikoleris@arm.com // writebacks... that would mean that someone used an atomic 57712724Snikos.nikoleris@arm.com // access in timing mode 57812724Snikos.nikoleris@arm.com 57912724Snikos.nikoleris@arm.com CacheBlk *blk = nullptr; 58012724Snikos.nikoleris@arm.com PacketList writebacks; 58112724Snikos.nikoleris@arm.com bool satisfied = access(pkt, blk, lat, writebacks); 58212724Snikos.nikoleris@arm.com 58312724Snikos.nikoleris@arm.com if (pkt->isClean() && blk && blk->isDirty()) { 58412724Snikos.nikoleris@arm.com // A cache clean opearation is looking for a dirty 58512724Snikos.nikoleris@arm.com // block. If a dirty block is encountered a WriteClean 58612724Snikos.nikoleris@arm.com // will update any copies to the path to the memory 58712724Snikos.nikoleris@arm.com // until the point of reference. 58812724Snikos.nikoleris@arm.com DPRINTF(CacheVerbose, "%s: packet %s found block: %s\n", 58912724Snikos.nikoleris@arm.com __func__, pkt->print(), blk->print()); 59012724Snikos.nikoleris@arm.com PacketPtr wb_pkt = writecleanBlk(blk, pkt->req->getDest(), pkt->id); 59112724Snikos.nikoleris@arm.com writebacks.push_back(wb_pkt); 59212724Snikos.nikoleris@arm.com pkt->setSatisfied(); 59312724Snikos.nikoleris@arm.com } 59412724Snikos.nikoleris@arm.com 59512724Snikos.nikoleris@arm.com // handle writebacks resulting from the access here to ensure they 59612820Srmk35@cl.cam.ac.uk // logically precede anything happening below 59712724Snikos.nikoleris@arm.com doWritebacksAtomic(writebacks); 59812724Snikos.nikoleris@arm.com assert(writebacks.empty()); 59912724Snikos.nikoleris@arm.com 60012724Snikos.nikoleris@arm.com if (!satisfied) { 60112724Snikos.nikoleris@arm.com lat += handleAtomicReqMiss(pkt, blk, writebacks); 60212724Snikos.nikoleris@arm.com } 60312724Snikos.nikoleris@arm.com 60412724Snikos.nikoleris@arm.com // Note that we don't invoke the prefetcher at all in atomic mode. 60512724Snikos.nikoleris@arm.com // It's not clear how to do it properly, particularly for 60612724Snikos.nikoleris@arm.com // prefetchers that aggressively generate prefetch candidates and 60712724Snikos.nikoleris@arm.com // rely on bandwidth contention to throttle them; these will tend 60812724Snikos.nikoleris@arm.com // to pollute the cache in atomic mode since there is no bandwidth 60912724Snikos.nikoleris@arm.com // contention. If we ever do want to enable prefetching in atomic 61012724Snikos.nikoleris@arm.com // mode, though, this is the place to do it... see timingAccess() 61112724Snikos.nikoleris@arm.com // for an example (though we'd want to issue the prefetch(es) 61212724Snikos.nikoleris@arm.com // immediately rather than calling requestMemSideBus() as we do 61312724Snikos.nikoleris@arm.com // there). 61412724Snikos.nikoleris@arm.com 61512724Snikos.nikoleris@arm.com // do any writebacks resulting from the response handling 61612724Snikos.nikoleris@arm.com doWritebacksAtomic(writebacks); 61712724Snikos.nikoleris@arm.com 61812724Snikos.nikoleris@arm.com // if we used temp block, check to see if its valid and if so 61912724Snikos.nikoleris@arm.com // clear it out, but only do so after the call to recvAtomic is 62012724Snikos.nikoleris@arm.com // finished so that any downstream observers (such as a snoop 62112724Snikos.nikoleris@arm.com // filter), first see the fill, and only then see the eviction 62212724Snikos.nikoleris@arm.com if (blk == tempBlock && tempBlock->isValid()) { 62312724Snikos.nikoleris@arm.com // the atomic CPU calls recvAtomic for fetch and load/store 62412724Snikos.nikoleris@arm.com // sequentuially, and we may already have a tempBlock 62512724Snikos.nikoleris@arm.com // writeback from the fetch that we have not yet sent 62612724Snikos.nikoleris@arm.com if (tempBlockWriteback) { 62712724Snikos.nikoleris@arm.com // if that is the case, write the prevoius one back, and 62812724Snikos.nikoleris@arm.com // do not schedule any new event 62912724Snikos.nikoleris@arm.com writebackTempBlockAtomic(); 63012724Snikos.nikoleris@arm.com } else { 63112724Snikos.nikoleris@arm.com // the writeback/clean eviction happens after the call to 63212724Snikos.nikoleris@arm.com // recvAtomic has finished (but before any successive 63312724Snikos.nikoleris@arm.com // calls), so that the response handling from the fill is 63412724Snikos.nikoleris@arm.com // allowed to happen first 63512724Snikos.nikoleris@arm.com schedule(writebackTempBlockAtomicEvent, curTick()); 63612724Snikos.nikoleris@arm.com } 63712724Snikos.nikoleris@arm.com 63812724Snikos.nikoleris@arm.com tempBlockWriteback = evictBlock(blk); 63912724Snikos.nikoleris@arm.com } 64012724Snikos.nikoleris@arm.com 64112724Snikos.nikoleris@arm.com if (pkt->needsResponse()) { 64212724Snikos.nikoleris@arm.com pkt->makeAtomicResponse(); 64312724Snikos.nikoleris@arm.com } 64412724Snikos.nikoleris@arm.com 64512724Snikos.nikoleris@arm.com return lat * clockPeriod(); 64612724Snikos.nikoleris@arm.com} 64712724Snikos.nikoleris@arm.com 64812724Snikos.nikoleris@arm.comvoid 64912724Snikos.nikoleris@arm.comBaseCache::functionalAccess(PacketPtr pkt, bool from_cpu_side) 65012724Snikos.nikoleris@arm.com{ 65112724Snikos.nikoleris@arm.com Addr blk_addr = pkt->getBlockAddr(blkSize); 65212724Snikos.nikoleris@arm.com bool is_secure = pkt->isSecure(); 65312724Snikos.nikoleris@arm.com CacheBlk *blk = tags->findBlock(pkt->getAddr(), is_secure); 65412724Snikos.nikoleris@arm.com MSHR *mshr = mshrQueue.findMatch(blk_addr, is_secure); 65512724Snikos.nikoleris@arm.com 65612724Snikos.nikoleris@arm.com pkt->pushLabel(name()); 65712724Snikos.nikoleris@arm.com 65812724Snikos.nikoleris@arm.com CacheBlkPrintWrapper cbpw(blk); 65912724Snikos.nikoleris@arm.com 66012724Snikos.nikoleris@arm.com // Note that just because an L2/L3 has valid data doesn't mean an 66112724Snikos.nikoleris@arm.com // L1 doesn't have a more up-to-date modified copy that still 66212724Snikos.nikoleris@arm.com // needs to be found. As a result we always update the request if 66312724Snikos.nikoleris@arm.com // we have it, but only declare it satisfied if we are the owner. 66412724Snikos.nikoleris@arm.com 66512724Snikos.nikoleris@arm.com // see if we have data at all (owned or otherwise) 66612724Snikos.nikoleris@arm.com bool have_data = blk && blk->isValid() 66712724Snikos.nikoleris@arm.com && pkt->checkFunctional(&cbpw, blk_addr, is_secure, blkSize, 66812724Snikos.nikoleris@arm.com blk->data); 66912724Snikos.nikoleris@arm.com 67012724Snikos.nikoleris@arm.com // data we have is dirty if marked as such or if we have an 67112724Snikos.nikoleris@arm.com // in-service MSHR that is pending a modified line 67212724Snikos.nikoleris@arm.com bool have_dirty = 67312724Snikos.nikoleris@arm.com have_data && (blk->isDirty() || 67412724Snikos.nikoleris@arm.com (mshr && mshr->inService && mshr->isPendingModified())); 67512724Snikos.nikoleris@arm.com 67612724Snikos.nikoleris@arm.com bool done = have_dirty || 67712724Snikos.nikoleris@arm.com cpuSidePort.checkFunctional(pkt) || 67812724Snikos.nikoleris@arm.com mshrQueue.checkFunctional(pkt, blk_addr) || 67912724Snikos.nikoleris@arm.com writeBuffer.checkFunctional(pkt, blk_addr) || 68012724Snikos.nikoleris@arm.com memSidePort.checkFunctional(pkt); 68112724Snikos.nikoleris@arm.com 68212724Snikos.nikoleris@arm.com DPRINTF(CacheVerbose, "%s: %s %s%s%s\n", __func__, pkt->print(), 68312724Snikos.nikoleris@arm.com (blk && blk->isValid()) ? "valid " : "", 68412724Snikos.nikoleris@arm.com have_data ? "data " : "", done ? "done " : ""); 68512724Snikos.nikoleris@arm.com 68612724Snikos.nikoleris@arm.com // We're leaving the cache, so pop cache->name() label 68712724Snikos.nikoleris@arm.com pkt->popLabel(); 68812724Snikos.nikoleris@arm.com 68912724Snikos.nikoleris@arm.com if (done) { 69012724Snikos.nikoleris@arm.com pkt->makeResponse(); 69112724Snikos.nikoleris@arm.com } else { 69212724Snikos.nikoleris@arm.com // if it came as a request from the CPU side then make sure it 69312724Snikos.nikoleris@arm.com // continues towards the memory side 69412724Snikos.nikoleris@arm.com if (from_cpu_side) { 69512724Snikos.nikoleris@arm.com memSidePort.sendFunctional(pkt); 69612724Snikos.nikoleris@arm.com } else if (cpuSidePort.isSnooping()) { 69712724Snikos.nikoleris@arm.com // if it came from the memory side, it must be a snoop request 69812724Snikos.nikoleris@arm.com // and we should only forward it if we are forwarding snoops 69912724Snikos.nikoleris@arm.com cpuSidePort.sendFunctionalSnoop(pkt); 70012724Snikos.nikoleris@arm.com } 70112724Snikos.nikoleris@arm.com } 70212724Snikos.nikoleris@arm.com} 70312724Snikos.nikoleris@arm.com 70412724Snikos.nikoleris@arm.com 70512724Snikos.nikoleris@arm.comvoid 70612724Snikos.nikoleris@arm.comBaseCache::cmpAndSwap(CacheBlk *blk, PacketPtr pkt) 70712724Snikos.nikoleris@arm.com{ 70812724Snikos.nikoleris@arm.com assert(pkt->isRequest()); 70912724Snikos.nikoleris@arm.com 71012724Snikos.nikoleris@arm.com uint64_t overwrite_val; 71112724Snikos.nikoleris@arm.com bool overwrite_mem; 71212724Snikos.nikoleris@arm.com uint64_t condition_val64; 71312724Snikos.nikoleris@arm.com uint32_t condition_val32; 71412724Snikos.nikoleris@arm.com 71512724Snikos.nikoleris@arm.com int offset = pkt->getOffset(blkSize); 71612724Snikos.nikoleris@arm.com uint8_t *blk_data = blk->data + offset; 71712724Snikos.nikoleris@arm.com 71812724Snikos.nikoleris@arm.com assert(sizeof(uint64_t) >= pkt->getSize()); 71912724Snikos.nikoleris@arm.com 72012724Snikos.nikoleris@arm.com overwrite_mem = true; 72112724Snikos.nikoleris@arm.com // keep a copy of our possible write value, and copy what is at the 72212724Snikos.nikoleris@arm.com // memory address into the packet 72312724Snikos.nikoleris@arm.com pkt->writeData((uint8_t *)&overwrite_val); 72412724Snikos.nikoleris@arm.com pkt->setData(blk_data); 72512724Snikos.nikoleris@arm.com 72612724Snikos.nikoleris@arm.com if (pkt->req->isCondSwap()) { 72712724Snikos.nikoleris@arm.com if (pkt->getSize() == sizeof(uint64_t)) { 72812724Snikos.nikoleris@arm.com condition_val64 = pkt->req->getExtraData(); 72912724Snikos.nikoleris@arm.com overwrite_mem = !std::memcmp(&condition_val64, blk_data, 73012724Snikos.nikoleris@arm.com sizeof(uint64_t)); 73112724Snikos.nikoleris@arm.com } else if (pkt->getSize() == sizeof(uint32_t)) { 73212724Snikos.nikoleris@arm.com condition_val32 = (uint32_t)pkt->req->getExtraData(); 73312724Snikos.nikoleris@arm.com overwrite_mem = !std::memcmp(&condition_val32, blk_data, 73412724Snikos.nikoleris@arm.com sizeof(uint32_t)); 73512724Snikos.nikoleris@arm.com } else 73612724Snikos.nikoleris@arm.com panic("Invalid size for conditional read/write\n"); 73712724Snikos.nikoleris@arm.com } 73812724Snikos.nikoleris@arm.com 73912724Snikos.nikoleris@arm.com if (overwrite_mem) { 74012724Snikos.nikoleris@arm.com std::memcpy(blk_data, &overwrite_val, pkt->getSize()); 74112724Snikos.nikoleris@arm.com blk->status |= BlkDirty; 74212724Snikos.nikoleris@arm.com } 74312724Snikos.nikoleris@arm.com} 74412724Snikos.nikoleris@arm.com 74512724Snikos.nikoleris@arm.comQueueEntry* 74612724Snikos.nikoleris@arm.comBaseCache::getNextQueueEntry() 74712724Snikos.nikoleris@arm.com{ 74812724Snikos.nikoleris@arm.com // Check both MSHR queue and write buffer for potential requests, 74912724Snikos.nikoleris@arm.com // note that null does not mean there is no request, it could 75012724Snikos.nikoleris@arm.com // simply be that it is not ready 75112724Snikos.nikoleris@arm.com MSHR *miss_mshr = mshrQueue.getNext(); 75212724Snikos.nikoleris@arm.com WriteQueueEntry *wq_entry = writeBuffer.getNext(); 75312724Snikos.nikoleris@arm.com 75412724Snikos.nikoleris@arm.com // If we got a write buffer request ready, first priority is a 75512724Snikos.nikoleris@arm.com // full write buffer, otherwise we favour the miss requests 75612724Snikos.nikoleris@arm.com if (wq_entry && (writeBuffer.isFull() || !miss_mshr)) { 75712724Snikos.nikoleris@arm.com // need to search MSHR queue for conflicting earlier miss. 75812724Snikos.nikoleris@arm.com MSHR *conflict_mshr = 75912724Snikos.nikoleris@arm.com mshrQueue.findPending(wq_entry->blkAddr, 76012724Snikos.nikoleris@arm.com wq_entry->isSecure); 76112724Snikos.nikoleris@arm.com 76212724Snikos.nikoleris@arm.com if (conflict_mshr && conflict_mshr->order < wq_entry->order) { 76312724Snikos.nikoleris@arm.com // Service misses in order until conflict is cleared. 76412724Snikos.nikoleris@arm.com return conflict_mshr; 76512724Snikos.nikoleris@arm.com 76612724Snikos.nikoleris@arm.com // @todo Note that we ignore the ready time of the conflict here 76712724Snikos.nikoleris@arm.com } 76812724Snikos.nikoleris@arm.com 76912724Snikos.nikoleris@arm.com // No conflicts; issue write 77012724Snikos.nikoleris@arm.com return wq_entry; 77112724Snikos.nikoleris@arm.com } else if (miss_mshr) { 77212724Snikos.nikoleris@arm.com // need to check for conflicting earlier writeback 77312724Snikos.nikoleris@arm.com WriteQueueEntry *conflict_mshr = 77412724Snikos.nikoleris@arm.com writeBuffer.findPending(miss_mshr->blkAddr, 77512724Snikos.nikoleris@arm.com miss_mshr->isSecure); 77612724Snikos.nikoleris@arm.com if (conflict_mshr) { 77712724Snikos.nikoleris@arm.com // not sure why we don't check order here... it was in the 77812724Snikos.nikoleris@arm.com // original code but commented out. 77912724Snikos.nikoleris@arm.com 78012724Snikos.nikoleris@arm.com // The only way this happens is if we are 78112724Snikos.nikoleris@arm.com // doing a write and we didn't have permissions 78212724Snikos.nikoleris@arm.com // then subsequently saw a writeback (owned got evicted) 78312724Snikos.nikoleris@arm.com // We need to make sure to perform the writeback first 78412724Snikos.nikoleris@arm.com // To preserve the dirty data, then we can issue the write 78512724Snikos.nikoleris@arm.com 78612724Snikos.nikoleris@arm.com // should we return wq_entry here instead? I.e. do we 78712724Snikos.nikoleris@arm.com // have to flush writes in order? I don't think so... not 78812724Snikos.nikoleris@arm.com // for Alpha anyway. Maybe for x86? 78912724Snikos.nikoleris@arm.com return conflict_mshr; 79012724Snikos.nikoleris@arm.com 79112724Snikos.nikoleris@arm.com // @todo Note that we ignore the ready time of the conflict here 79212724Snikos.nikoleris@arm.com } 79312724Snikos.nikoleris@arm.com 79412724Snikos.nikoleris@arm.com // No conflicts; issue read 79512724Snikos.nikoleris@arm.com return miss_mshr; 79612724Snikos.nikoleris@arm.com } 79712724Snikos.nikoleris@arm.com 79812724Snikos.nikoleris@arm.com // fall through... no pending requests. Try a prefetch. 79912724Snikos.nikoleris@arm.com assert(!miss_mshr && !wq_entry); 80012724Snikos.nikoleris@arm.com if (prefetcher && mshrQueue.canPrefetch()) { 80112724Snikos.nikoleris@arm.com // If we have a miss queue slot, we can try a prefetch 80212724Snikos.nikoleris@arm.com PacketPtr pkt = prefetcher->getPacket(); 80312724Snikos.nikoleris@arm.com if (pkt) { 80412724Snikos.nikoleris@arm.com Addr pf_addr = pkt->getBlockAddr(blkSize); 80512724Snikos.nikoleris@arm.com if (!tags->findBlock(pf_addr, pkt->isSecure()) && 80612724Snikos.nikoleris@arm.com !mshrQueue.findMatch(pf_addr, pkt->isSecure()) && 80712724Snikos.nikoleris@arm.com !writeBuffer.findMatch(pf_addr, pkt->isSecure())) { 80812724Snikos.nikoleris@arm.com // Update statistic on number of prefetches issued 80912724Snikos.nikoleris@arm.com // (hwpf_mshr_misses) 81012724Snikos.nikoleris@arm.com assert(pkt->req->masterId() < system->maxMasters()); 81112724Snikos.nikoleris@arm.com mshr_misses[pkt->cmdToIndex()][pkt->req->masterId()]++; 81212724Snikos.nikoleris@arm.com 81312724Snikos.nikoleris@arm.com // allocate an MSHR and return it, note 81412724Snikos.nikoleris@arm.com // that we send the packet straight away, so do not 81512724Snikos.nikoleris@arm.com // schedule the send 81612724Snikos.nikoleris@arm.com return allocateMissBuffer(pkt, curTick(), false); 81712724Snikos.nikoleris@arm.com } else { 81812724Snikos.nikoleris@arm.com // free the request and packet 81912724Snikos.nikoleris@arm.com delete pkt; 82012724Snikos.nikoleris@arm.com } 82112724Snikos.nikoleris@arm.com } 82212724Snikos.nikoleris@arm.com } 82312724Snikos.nikoleris@arm.com 82412724Snikos.nikoleris@arm.com return nullptr; 82512724Snikos.nikoleris@arm.com} 82612724Snikos.nikoleris@arm.com 82712724Snikos.nikoleris@arm.comvoid 82812724Snikos.nikoleris@arm.comBaseCache::satisfyRequest(PacketPtr pkt, CacheBlk *blk, bool, bool) 82912724Snikos.nikoleris@arm.com{ 83012724Snikos.nikoleris@arm.com assert(pkt->isRequest()); 83112724Snikos.nikoleris@arm.com 83212724Snikos.nikoleris@arm.com assert(blk && blk->isValid()); 83312724Snikos.nikoleris@arm.com // Occasionally this is not true... if we are a lower-level cache 83412724Snikos.nikoleris@arm.com // satisfying a string of Read and ReadEx requests from 83512724Snikos.nikoleris@arm.com // upper-level caches, a Read will mark the block as shared but we 83612724Snikos.nikoleris@arm.com // can satisfy a following ReadEx anyway since we can rely on the 83712724Snikos.nikoleris@arm.com // Read requester(s) to have buffered the ReadEx snoop and to 83812724Snikos.nikoleris@arm.com // invalidate their blocks after receiving them. 83912724Snikos.nikoleris@arm.com // assert(!pkt->needsWritable() || blk->isWritable()); 84012724Snikos.nikoleris@arm.com assert(pkt->getOffset(blkSize) + pkt->getSize() <= blkSize); 84112724Snikos.nikoleris@arm.com 84212724Snikos.nikoleris@arm.com // Check RMW operations first since both isRead() and 84312724Snikos.nikoleris@arm.com // isWrite() will be true for them 84412724Snikos.nikoleris@arm.com if (pkt->cmd == MemCmd::SwapReq) { 84512766Sqtt2@cornell.edu if (pkt->isAtomicOp()) { 84612766Sqtt2@cornell.edu // extract data from cache and save it into the data field in 84712766Sqtt2@cornell.edu // the packet as a return value from this atomic op 84812766Sqtt2@cornell.edu 84912766Sqtt2@cornell.edu int offset = tags->extractBlkOffset(pkt->getAddr()); 85012766Sqtt2@cornell.edu uint8_t *blk_data = blk->data + offset; 85112766Sqtt2@cornell.edu std::memcpy(pkt->getPtr<uint8_t>(), blk_data, pkt->getSize()); 85212766Sqtt2@cornell.edu 85312766Sqtt2@cornell.edu // execute AMO operation 85412766Sqtt2@cornell.edu (*(pkt->getAtomicOp()))(blk_data); 85512766Sqtt2@cornell.edu 85612766Sqtt2@cornell.edu // set block status to dirty 85712766Sqtt2@cornell.edu blk->status |= BlkDirty; 85812766Sqtt2@cornell.edu } else { 85912766Sqtt2@cornell.edu cmpAndSwap(blk, pkt); 86012766Sqtt2@cornell.edu } 86112724Snikos.nikoleris@arm.com } else if (pkt->isWrite()) { 86212724Snikos.nikoleris@arm.com // we have the block in a writable state and can go ahead, 86312724Snikos.nikoleris@arm.com // note that the line may be also be considered writable in 86412724Snikos.nikoleris@arm.com // downstream caches along the path to memory, but always 86512724Snikos.nikoleris@arm.com // Exclusive, and never Modified 86612724Snikos.nikoleris@arm.com assert(blk->isWritable()); 86712724Snikos.nikoleris@arm.com // Write or WriteLine at the first cache with block in writable state 86812724Snikos.nikoleris@arm.com if (blk->checkWrite(pkt)) { 86912724Snikos.nikoleris@arm.com pkt->writeDataToBlock(blk->data, blkSize); 87012724Snikos.nikoleris@arm.com } 87112724Snikos.nikoleris@arm.com // Always mark the line as dirty (and thus transition to the 87212724Snikos.nikoleris@arm.com // Modified state) even if we are a failed StoreCond so we 87312724Snikos.nikoleris@arm.com // supply data to any snoops that have appended themselves to 87412724Snikos.nikoleris@arm.com // this cache before knowing the store will fail. 87512724Snikos.nikoleris@arm.com blk->status |= BlkDirty; 87612724Snikos.nikoleris@arm.com DPRINTF(CacheVerbose, "%s for %s (write)\n", __func__, pkt->print()); 87712724Snikos.nikoleris@arm.com } else if (pkt->isRead()) { 87812724Snikos.nikoleris@arm.com if (pkt->isLLSC()) { 87912724Snikos.nikoleris@arm.com blk->trackLoadLocked(pkt); 88012724Snikos.nikoleris@arm.com } 88112724Snikos.nikoleris@arm.com 88212724Snikos.nikoleris@arm.com // all read responses have a data payload 88312724Snikos.nikoleris@arm.com assert(pkt->hasRespData()); 88412724Snikos.nikoleris@arm.com pkt->setDataFromBlock(blk->data, blkSize); 88512724Snikos.nikoleris@arm.com } else if (pkt->isUpgrade()) { 88612724Snikos.nikoleris@arm.com // sanity check 88712724Snikos.nikoleris@arm.com assert(!pkt->hasSharers()); 88812724Snikos.nikoleris@arm.com 88912724Snikos.nikoleris@arm.com if (blk->isDirty()) { 89012724Snikos.nikoleris@arm.com // we were in the Owned state, and a cache above us that 89112724Snikos.nikoleris@arm.com // has the line in Shared state needs to be made aware 89212724Snikos.nikoleris@arm.com // that the data it already has is in fact dirty 89312724Snikos.nikoleris@arm.com pkt->setCacheResponding(); 89412724Snikos.nikoleris@arm.com blk->status &= ~BlkDirty; 89512724Snikos.nikoleris@arm.com } 89612794Snikos.nikoleris@arm.com } else if (pkt->isClean()) { 89712794Snikos.nikoleris@arm.com blk->status &= ~BlkDirty; 89812724Snikos.nikoleris@arm.com } else { 89912724Snikos.nikoleris@arm.com assert(pkt->isInvalidate()); 90012724Snikos.nikoleris@arm.com invalidateBlock(blk); 90112724Snikos.nikoleris@arm.com DPRINTF(CacheVerbose, "%s for %s (invalidation)\n", __func__, 90212724Snikos.nikoleris@arm.com pkt->print()); 90312724Snikos.nikoleris@arm.com } 90412724Snikos.nikoleris@arm.com} 90512724Snikos.nikoleris@arm.com 90612724Snikos.nikoleris@arm.com///////////////////////////////////////////////////// 90712724Snikos.nikoleris@arm.com// 90812724Snikos.nikoleris@arm.com// Access path: requests coming in from the CPU side 90912724Snikos.nikoleris@arm.com// 91012724Snikos.nikoleris@arm.com///////////////////////////////////////////////////// 91112724Snikos.nikoleris@arm.com 91212724Snikos.nikoleris@arm.combool 91312724Snikos.nikoleris@arm.comBaseCache::access(PacketPtr pkt, CacheBlk *&blk, Cycles &lat, 91412724Snikos.nikoleris@arm.com PacketList &writebacks) 91512724Snikos.nikoleris@arm.com{ 91612724Snikos.nikoleris@arm.com // sanity check 91712724Snikos.nikoleris@arm.com assert(pkt->isRequest()); 91812724Snikos.nikoleris@arm.com 91912724Snikos.nikoleris@arm.com chatty_assert(!(isReadOnly && pkt->isWrite()), 92012724Snikos.nikoleris@arm.com "Should never see a write in a read-only cache %s\n", 92112724Snikos.nikoleris@arm.com name()); 92212724Snikos.nikoleris@arm.com 92312724Snikos.nikoleris@arm.com // Here lat is the value passed as parameter to accessBlock() function 92412724Snikos.nikoleris@arm.com // that can modify its value. 92512724Snikos.nikoleris@arm.com blk = tags->accessBlock(pkt->getAddr(), pkt->isSecure(), lat); 92612724Snikos.nikoleris@arm.com 92712724Snikos.nikoleris@arm.com DPRINTF(Cache, "%s for %s %s\n", __func__, pkt->print(), 92812724Snikos.nikoleris@arm.com blk ? "hit " + blk->print() : "miss"); 92912724Snikos.nikoleris@arm.com 93012724Snikos.nikoleris@arm.com if (pkt->req->isCacheMaintenance()) { 93112724Snikos.nikoleris@arm.com // A cache maintenance operation is always forwarded to the 93212724Snikos.nikoleris@arm.com // memory below even if the block is found in dirty state. 93312724Snikos.nikoleris@arm.com 93412724Snikos.nikoleris@arm.com // We defer any changes to the state of the block until we 93512724Snikos.nikoleris@arm.com // create and mark as in service the mshr for the downstream 93612724Snikos.nikoleris@arm.com // packet. 93712724Snikos.nikoleris@arm.com return false; 93812724Snikos.nikoleris@arm.com } 93912724Snikos.nikoleris@arm.com 94012724Snikos.nikoleris@arm.com if (pkt->isEviction()) { 94112724Snikos.nikoleris@arm.com // We check for presence of block in above caches before issuing 94212724Snikos.nikoleris@arm.com // Writeback or CleanEvict to write buffer. Therefore the only 94312724Snikos.nikoleris@arm.com // possible cases can be of a CleanEvict packet coming from above 94412724Snikos.nikoleris@arm.com // encountering a Writeback generated in this cache peer cache and 94512724Snikos.nikoleris@arm.com // waiting in the write buffer. Cases of upper level peer caches 94612724Snikos.nikoleris@arm.com // generating CleanEvict and Writeback or simply CleanEvict and 94712724Snikos.nikoleris@arm.com // CleanEvict almost simultaneously will be caught by snoops sent out 94812724Snikos.nikoleris@arm.com // by crossbar. 94912724Snikos.nikoleris@arm.com WriteQueueEntry *wb_entry = writeBuffer.findMatch(pkt->getAddr(), 95012724Snikos.nikoleris@arm.com pkt->isSecure()); 95112724Snikos.nikoleris@arm.com if (wb_entry) { 95212724Snikos.nikoleris@arm.com assert(wb_entry->getNumTargets() == 1); 95312724Snikos.nikoleris@arm.com PacketPtr wbPkt = wb_entry->getTarget()->pkt; 95412724Snikos.nikoleris@arm.com assert(wbPkt->isWriteback()); 95512724Snikos.nikoleris@arm.com 95612724Snikos.nikoleris@arm.com if (pkt->isCleanEviction()) { 95712724Snikos.nikoleris@arm.com // The CleanEvict and WritebackClean snoops into other 95812724Snikos.nikoleris@arm.com // peer caches of the same level while traversing the 95912724Snikos.nikoleris@arm.com // crossbar. If a copy of the block is found, the 96012724Snikos.nikoleris@arm.com // packet is deleted in the crossbar. Hence, none of 96112724Snikos.nikoleris@arm.com // the other upper level caches connected to this 96212724Snikos.nikoleris@arm.com // cache have the block, so we can clear the 96312724Snikos.nikoleris@arm.com // BLOCK_CACHED flag in the Writeback if set and 96412724Snikos.nikoleris@arm.com // discard the CleanEvict by returning true. 96512724Snikos.nikoleris@arm.com wbPkt->clearBlockCached(); 96612724Snikos.nikoleris@arm.com return true; 96712724Snikos.nikoleris@arm.com } else { 96812724Snikos.nikoleris@arm.com assert(pkt->cmd == MemCmd::WritebackDirty); 96912724Snikos.nikoleris@arm.com // Dirty writeback from above trumps our clean 97012724Snikos.nikoleris@arm.com // writeback... discard here 97112724Snikos.nikoleris@arm.com // Note: markInService will remove entry from writeback buffer. 97212724Snikos.nikoleris@arm.com markInService(wb_entry); 97312724Snikos.nikoleris@arm.com delete wbPkt; 97412724Snikos.nikoleris@arm.com } 97512724Snikos.nikoleris@arm.com } 97612724Snikos.nikoleris@arm.com } 97712724Snikos.nikoleris@arm.com 97812724Snikos.nikoleris@arm.com // Writeback handling is special case. We can write the block into 97912724Snikos.nikoleris@arm.com // the cache without having a writeable copy (or any copy at all). 98012724Snikos.nikoleris@arm.com if (pkt->isWriteback()) { 98112724Snikos.nikoleris@arm.com assert(blkSize == pkt->getSize()); 98212724Snikos.nikoleris@arm.com 98312724Snikos.nikoleris@arm.com // we could get a clean writeback while we are having 98412724Snikos.nikoleris@arm.com // outstanding accesses to a block, do the simple thing for 98512724Snikos.nikoleris@arm.com // now and drop the clean writeback so that we do not upset 98612724Snikos.nikoleris@arm.com // any ordering/decisions about ownership already taken 98712724Snikos.nikoleris@arm.com if (pkt->cmd == MemCmd::WritebackClean && 98812724Snikos.nikoleris@arm.com mshrQueue.findMatch(pkt->getAddr(), pkt->isSecure())) { 98912724Snikos.nikoleris@arm.com DPRINTF(Cache, "Clean writeback %#llx to block with MSHR, " 99012724Snikos.nikoleris@arm.com "dropping\n", pkt->getAddr()); 99112724Snikos.nikoleris@arm.com return true; 99212724Snikos.nikoleris@arm.com } 99312724Snikos.nikoleris@arm.com 99412724Snikos.nikoleris@arm.com if (!blk) { 99512724Snikos.nikoleris@arm.com // need to do a replacement 99612754Sodanrc@yahoo.com.br blk = allocateBlock(pkt, writebacks); 99712724Snikos.nikoleris@arm.com if (!blk) { 99812724Snikos.nikoleris@arm.com // no replaceable block available: give up, fwd to next level. 99912724Snikos.nikoleris@arm.com incMissCount(pkt); 100012724Snikos.nikoleris@arm.com return false; 100112724Snikos.nikoleris@arm.com } 100212724Snikos.nikoleris@arm.com 100312724Snikos.nikoleris@arm.com blk->status |= (BlkValid | BlkReadable); 100412724Snikos.nikoleris@arm.com } 100512724Snikos.nikoleris@arm.com // only mark the block dirty if we got a writeback command, 100612724Snikos.nikoleris@arm.com // and leave it as is for a clean writeback 100712724Snikos.nikoleris@arm.com if (pkt->cmd == MemCmd::WritebackDirty) { 100812724Snikos.nikoleris@arm.com // TODO: the coherent cache can assert(!blk->isDirty()); 100912724Snikos.nikoleris@arm.com blk->status |= BlkDirty; 101012724Snikos.nikoleris@arm.com } 101112724Snikos.nikoleris@arm.com // if the packet does not have sharers, it is passing 101212724Snikos.nikoleris@arm.com // writable, and we got the writeback in Modified or Exclusive 101312724Snikos.nikoleris@arm.com // state, if not we are in the Owned or Shared state 101412724Snikos.nikoleris@arm.com if (!pkt->hasSharers()) { 101512724Snikos.nikoleris@arm.com blk->status |= BlkWritable; 101612724Snikos.nikoleris@arm.com } 101712724Snikos.nikoleris@arm.com // nothing else to do; writeback doesn't expect response 101812724Snikos.nikoleris@arm.com assert(!pkt->needsResponse()); 101912724Snikos.nikoleris@arm.com pkt->writeDataToBlock(blk->data, blkSize); 102012724Snikos.nikoleris@arm.com DPRINTF(Cache, "%s new state is %s\n", __func__, blk->print()); 102112724Snikos.nikoleris@arm.com incHitCount(pkt); 102212724Snikos.nikoleris@arm.com // populate the time when the block will be ready to access. 102312724Snikos.nikoleris@arm.com blk->whenReady = clockEdge(fillLatency) + pkt->headerDelay + 102412724Snikos.nikoleris@arm.com pkt->payloadDelay; 102512724Snikos.nikoleris@arm.com return true; 102612724Snikos.nikoleris@arm.com } else if (pkt->cmd == MemCmd::CleanEvict) { 102712724Snikos.nikoleris@arm.com if (blk) { 102812724Snikos.nikoleris@arm.com // Found the block in the tags, need to stop CleanEvict from 102912724Snikos.nikoleris@arm.com // propagating further down the hierarchy. Returning true will 103012724Snikos.nikoleris@arm.com // treat the CleanEvict like a satisfied write request and delete 103112724Snikos.nikoleris@arm.com // it. 103212724Snikos.nikoleris@arm.com return true; 103312724Snikos.nikoleris@arm.com } 103412724Snikos.nikoleris@arm.com // We didn't find the block here, propagate the CleanEvict further 103512724Snikos.nikoleris@arm.com // down the memory hierarchy. Returning false will treat the CleanEvict 103612724Snikos.nikoleris@arm.com // like a Writeback which could not find a replaceable block so has to 103712724Snikos.nikoleris@arm.com // go to next level. 103812724Snikos.nikoleris@arm.com return false; 103912724Snikos.nikoleris@arm.com } else if (pkt->cmd == MemCmd::WriteClean) { 104012724Snikos.nikoleris@arm.com // WriteClean handling is a special case. We can allocate a 104112724Snikos.nikoleris@arm.com // block directly if it doesn't exist and we can update the 104212724Snikos.nikoleris@arm.com // block immediately. The WriteClean transfers the ownership 104312724Snikos.nikoleris@arm.com // of the block as well. 104412724Snikos.nikoleris@arm.com assert(blkSize == pkt->getSize()); 104512724Snikos.nikoleris@arm.com 104612724Snikos.nikoleris@arm.com if (!blk) { 104712724Snikos.nikoleris@arm.com if (pkt->writeThrough()) { 104812724Snikos.nikoleris@arm.com // if this is a write through packet, we don't try to 104912724Snikos.nikoleris@arm.com // allocate if the block is not present 105012724Snikos.nikoleris@arm.com return false; 105112724Snikos.nikoleris@arm.com } else { 105212724Snikos.nikoleris@arm.com // a writeback that misses needs to allocate a new block 105312754Sodanrc@yahoo.com.br blk = allocateBlock(pkt, writebacks); 105412724Snikos.nikoleris@arm.com if (!blk) { 105512724Snikos.nikoleris@arm.com // no replaceable block available: give up, fwd to 105612724Snikos.nikoleris@arm.com // next level. 105712724Snikos.nikoleris@arm.com incMissCount(pkt); 105812724Snikos.nikoleris@arm.com return false; 105912724Snikos.nikoleris@arm.com } 106012724Snikos.nikoleris@arm.com 106112724Snikos.nikoleris@arm.com blk->status |= (BlkValid | BlkReadable); 106212724Snikos.nikoleris@arm.com } 106312724Snikos.nikoleris@arm.com } 106412724Snikos.nikoleris@arm.com 106512724Snikos.nikoleris@arm.com // at this point either this is a writeback or a write-through 106612724Snikos.nikoleris@arm.com // write clean operation and the block is already in this 106712724Snikos.nikoleris@arm.com // cache, we need to update the data and the block flags 106812724Snikos.nikoleris@arm.com assert(blk); 106912724Snikos.nikoleris@arm.com // TODO: the coherent cache can assert(!blk->isDirty()); 107012724Snikos.nikoleris@arm.com if (!pkt->writeThrough()) { 107112724Snikos.nikoleris@arm.com blk->status |= BlkDirty; 107212724Snikos.nikoleris@arm.com } 107312724Snikos.nikoleris@arm.com // nothing else to do; writeback doesn't expect response 107412724Snikos.nikoleris@arm.com assert(!pkt->needsResponse()); 107512724Snikos.nikoleris@arm.com pkt->writeDataToBlock(blk->data, blkSize); 107612724Snikos.nikoleris@arm.com DPRINTF(Cache, "%s new state is %s\n", __func__, blk->print()); 107712724Snikos.nikoleris@arm.com 107812724Snikos.nikoleris@arm.com incHitCount(pkt); 107912724Snikos.nikoleris@arm.com // populate the time when the block will be ready to access. 108012724Snikos.nikoleris@arm.com blk->whenReady = clockEdge(fillLatency) + pkt->headerDelay + 108112724Snikos.nikoleris@arm.com pkt->payloadDelay; 108212724Snikos.nikoleris@arm.com // if this a write-through packet it will be sent to cache 108312724Snikos.nikoleris@arm.com // below 108412724Snikos.nikoleris@arm.com return !pkt->writeThrough(); 108512724Snikos.nikoleris@arm.com } else if (blk && (pkt->needsWritable() ? blk->isWritable() : 108612724Snikos.nikoleris@arm.com blk->isReadable())) { 108712724Snikos.nikoleris@arm.com // OK to satisfy access 108812724Snikos.nikoleris@arm.com incHitCount(pkt); 108912724Snikos.nikoleris@arm.com satisfyRequest(pkt, blk); 109012724Snikos.nikoleris@arm.com maintainClusivity(pkt->fromCache(), blk); 109112724Snikos.nikoleris@arm.com 109212724Snikos.nikoleris@arm.com return true; 109312724Snikos.nikoleris@arm.com } 109412724Snikos.nikoleris@arm.com 109512724Snikos.nikoleris@arm.com // Can't satisfy access normally... either no block (blk == nullptr) 109612724Snikos.nikoleris@arm.com // or have block but need writable 109712724Snikos.nikoleris@arm.com 109812724Snikos.nikoleris@arm.com incMissCount(pkt); 109912724Snikos.nikoleris@arm.com 110012724Snikos.nikoleris@arm.com if (!blk && pkt->isLLSC() && pkt->isWrite()) { 110112724Snikos.nikoleris@arm.com // complete miss on store conditional... just give up now 110212724Snikos.nikoleris@arm.com pkt->req->setExtraData(0); 110312724Snikos.nikoleris@arm.com return true; 110412724Snikos.nikoleris@arm.com } 110512724Snikos.nikoleris@arm.com 110612724Snikos.nikoleris@arm.com return false; 110712724Snikos.nikoleris@arm.com} 110812724Snikos.nikoleris@arm.com 110912724Snikos.nikoleris@arm.comvoid 111012724Snikos.nikoleris@arm.comBaseCache::maintainClusivity(bool from_cache, CacheBlk *blk) 111112724Snikos.nikoleris@arm.com{ 111212724Snikos.nikoleris@arm.com if (from_cache && blk && blk->isValid() && !blk->isDirty() && 111312724Snikos.nikoleris@arm.com clusivity == Enums::mostly_excl) { 111412724Snikos.nikoleris@arm.com // if we have responded to a cache, and our block is still 111512724Snikos.nikoleris@arm.com // valid, but not dirty, and this cache is mostly exclusive 111612724Snikos.nikoleris@arm.com // with respect to the cache above, drop the block 111712724Snikos.nikoleris@arm.com invalidateBlock(blk); 111812724Snikos.nikoleris@arm.com } 111912724Snikos.nikoleris@arm.com} 112012724Snikos.nikoleris@arm.com 112112724Snikos.nikoleris@arm.comCacheBlk* 112212724Snikos.nikoleris@arm.comBaseCache::handleFill(PacketPtr pkt, CacheBlk *blk, PacketList &writebacks, 112312724Snikos.nikoleris@arm.com bool allocate) 112412724Snikos.nikoleris@arm.com{ 112512724Snikos.nikoleris@arm.com assert(pkt->isResponse() || pkt->cmd == MemCmd::WriteLineReq); 112612724Snikos.nikoleris@arm.com Addr addr = pkt->getAddr(); 112712724Snikos.nikoleris@arm.com bool is_secure = pkt->isSecure(); 112812724Snikos.nikoleris@arm.com#if TRACING_ON 112912724Snikos.nikoleris@arm.com CacheBlk::State old_state = blk ? blk->status : 0; 113012724Snikos.nikoleris@arm.com#endif 113112724Snikos.nikoleris@arm.com 113212724Snikos.nikoleris@arm.com // When handling a fill, we should have no writes to this line. 113312724Snikos.nikoleris@arm.com assert(addr == pkt->getBlockAddr(blkSize)); 113412724Snikos.nikoleris@arm.com assert(!writeBuffer.findMatch(addr, is_secure)); 113512724Snikos.nikoleris@arm.com 113612724Snikos.nikoleris@arm.com if (!blk) { 113712724Snikos.nikoleris@arm.com // better have read new data... 113812724Snikos.nikoleris@arm.com assert(pkt->hasData()); 113912724Snikos.nikoleris@arm.com 114012724Snikos.nikoleris@arm.com // only read responses and write-line requests have data; 114112724Snikos.nikoleris@arm.com // note that we don't write the data here for write-line - that 114212724Snikos.nikoleris@arm.com // happens in the subsequent call to satisfyRequest 114312724Snikos.nikoleris@arm.com assert(pkt->isRead() || pkt->cmd == MemCmd::WriteLineReq); 114412724Snikos.nikoleris@arm.com 114512724Snikos.nikoleris@arm.com // need to do a replacement if allocating, otherwise we stick 114612724Snikos.nikoleris@arm.com // with the temporary storage 114712754Sodanrc@yahoo.com.br blk = allocate ? allocateBlock(pkt, writebacks) : nullptr; 114812724Snikos.nikoleris@arm.com 114912724Snikos.nikoleris@arm.com if (!blk) { 115012724Snikos.nikoleris@arm.com // No replaceable block or a mostly exclusive 115112724Snikos.nikoleris@arm.com // cache... just use temporary storage to complete the 115212724Snikos.nikoleris@arm.com // current request and then get rid of it 115312724Snikos.nikoleris@arm.com assert(!tempBlock->isValid()); 115412724Snikos.nikoleris@arm.com blk = tempBlock; 115512730Sodanrc@yahoo.com.br tempBlock->insert(addr, is_secure); 115612724Snikos.nikoleris@arm.com DPRINTF(Cache, "using temp block for %#llx (%s)\n", addr, 115712724Snikos.nikoleris@arm.com is_secure ? "s" : "ns"); 115812724Snikos.nikoleris@arm.com } 115912724Snikos.nikoleris@arm.com 116012724Snikos.nikoleris@arm.com // we should never be overwriting a valid block 116112724Snikos.nikoleris@arm.com assert(!blk->isValid()); 116212724Snikos.nikoleris@arm.com } else { 116312724Snikos.nikoleris@arm.com // existing block... probably an upgrade 116412747Sodanrc@yahoo.com.br assert(regenerateBlkAddr(blk) == addr); 116512729Sodanrc@yahoo.com.br assert(blk->isSecure() == is_secure); 116612724Snikos.nikoleris@arm.com // either we're getting new data or the block should already be valid 116712724Snikos.nikoleris@arm.com assert(pkt->hasData() || blk->isValid()); 116812724Snikos.nikoleris@arm.com // don't clear block status... if block is already dirty we 116912724Snikos.nikoleris@arm.com // don't want to lose that 117012724Snikos.nikoleris@arm.com } 117112724Snikos.nikoleris@arm.com 117212724Snikos.nikoleris@arm.com blk->status |= BlkValid | BlkReadable; 117312724Snikos.nikoleris@arm.com 117412724Snikos.nikoleris@arm.com // sanity check for whole-line writes, which should always be 117512724Snikos.nikoleris@arm.com // marked as writable as part of the fill, and then later marked 117612724Snikos.nikoleris@arm.com // dirty as part of satisfyRequest 117712724Snikos.nikoleris@arm.com if (pkt->cmd == MemCmd::WriteLineReq) { 117812724Snikos.nikoleris@arm.com assert(!pkt->hasSharers()); 117912724Snikos.nikoleris@arm.com } 118012724Snikos.nikoleris@arm.com 118112724Snikos.nikoleris@arm.com // here we deal with setting the appropriate state of the line, 118212724Snikos.nikoleris@arm.com // and we start by looking at the hasSharers flag, and ignore the 118312724Snikos.nikoleris@arm.com // cacheResponding flag (normally signalling dirty data) if the 118412724Snikos.nikoleris@arm.com // packet has sharers, thus the line is never allocated as Owned 118512724Snikos.nikoleris@arm.com // (dirty but not writable), and always ends up being either 118612724Snikos.nikoleris@arm.com // Shared, Exclusive or Modified, see Packet::setCacheResponding 118712724Snikos.nikoleris@arm.com // for more details 118812724Snikos.nikoleris@arm.com if (!pkt->hasSharers()) { 118912724Snikos.nikoleris@arm.com // we could get a writable line from memory (rather than a 119012724Snikos.nikoleris@arm.com // cache) even in a read-only cache, note that we set this bit 119112724Snikos.nikoleris@arm.com // even for a read-only cache, possibly revisit this decision 119212724Snikos.nikoleris@arm.com blk->status |= BlkWritable; 119312724Snikos.nikoleris@arm.com 119412724Snikos.nikoleris@arm.com // check if we got this via cache-to-cache transfer (i.e., from a 119512724Snikos.nikoleris@arm.com // cache that had the block in Modified or Owned state) 119612724Snikos.nikoleris@arm.com if (pkt->cacheResponding()) { 119712724Snikos.nikoleris@arm.com // we got the block in Modified state, and invalidated the 119812724Snikos.nikoleris@arm.com // owners copy 119912724Snikos.nikoleris@arm.com blk->status |= BlkDirty; 120012724Snikos.nikoleris@arm.com 120112724Snikos.nikoleris@arm.com chatty_assert(!isReadOnly, "Should never see dirty snoop response " 120212724Snikos.nikoleris@arm.com "in read-only cache %s\n", name()); 120312724Snikos.nikoleris@arm.com } 120412724Snikos.nikoleris@arm.com } 120512724Snikos.nikoleris@arm.com 120612724Snikos.nikoleris@arm.com DPRINTF(Cache, "Block addr %#llx (%s) moving from state %x to %s\n", 120712724Snikos.nikoleris@arm.com addr, is_secure ? "s" : "ns", old_state, blk->print()); 120812724Snikos.nikoleris@arm.com 120912724Snikos.nikoleris@arm.com // if we got new data, copy it in (checking for a read response 121012724Snikos.nikoleris@arm.com // and a response that has data is the same in the end) 121112724Snikos.nikoleris@arm.com if (pkt->isRead()) { 121212724Snikos.nikoleris@arm.com // sanity checks 121312724Snikos.nikoleris@arm.com assert(pkt->hasData()); 121412724Snikos.nikoleris@arm.com assert(pkt->getSize() == blkSize); 121512724Snikos.nikoleris@arm.com 121612724Snikos.nikoleris@arm.com pkt->writeDataToBlock(blk->data, blkSize); 121712724Snikos.nikoleris@arm.com } 121812724Snikos.nikoleris@arm.com // We pay for fillLatency here. 121912724Snikos.nikoleris@arm.com blk->whenReady = clockEdge() + fillLatency * clockPeriod() + 122012724Snikos.nikoleris@arm.com pkt->payloadDelay; 122112724Snikos.nikoleris@arm.com 122212724Snikos.nikoleris@arm.com return blk; 122312724Snikos.nikoleris@arm.com} 122412724Snikos.nikoleris@arm.com 122512724Snikos.nikoleris@arm.comCacheBlk* 122612754Sodanrc@yahoo.com.brBaseCache::allocateBlock(const PacketPtr pkt, PacketList &writebacks) 122712724Snikos.nikoleris@arm.com{ 122812754Sodanrc@yahoo.com.br // Get address 122912754Sodanrc@yahoo.com.br const Addr addr = pkt->getAddr(); 123012754Sodanrc@yahoo.com.br 123112754Sodanrc@yahoo.com.br // Get secure bit 123212754Sodanrc@yahoo.com.br const bool is_secure = pkt->isSecure(); 123312754Sodanrc@yahoo.com.br 123412724Snikos.nikoleris@arm.com // Find replacement victim 123512744Sodanrc@yahoo.com.br std::vector<CacheBlk*> evict_blks; 123612746Sodanrc@yahoo.com.br CacheBlk *victim = tags->findVictim(addr, is_secure, evict_blks); 123712724Snikos.nikoleris@arm.com 123812724Snikos.nikoleris@arm.com // It is valid to return nullptr if there is no victim 123912744Sodanrc@yahoo.com.br if (!victim) 124012724Snikos.nikoleris@arm.com return nullptr; 124112724Snikos.nikoleris@arm.com 124212744Sodanrc@yahoo.com.br // Check for transient state allocations. If any of the entries listed 124312744Sodanrc@yahoo.com.br // for eviction has a transient state, the allocation fails 124412744Sodanrc@yahoo.com.br for (const auto& blk : evict_blks) { 124512744Sodanrc@yahoo.com.br if (blk->isValid()) { 124612744Sodanrc@yahoo.com.br Addr repl_addr = regenerateBlkAddr(blk); 124712744Sodanrc@yahoo.com.br MSHR *repl_mshr = mshrQueue.findMatch(repl_addr, blk->isSecure()); 124812744Sodanrc@yahoo.com.br if (repl_mshr) { 124912744Sodanrc@yahoo.com.br // must be an outstanding upgrade or clean request 125012744Sodanrc@yahoo.com.br // on a block we're about to replace... 125112744Sodanrc@yahoo.com.br assert((!blk->isWritable() && repl_mshr->needsWritable()) || 125212744Sodanrc@yahoo.com.br repl_mshr->isCleaning()); 125312724Snikos.nikoleris@arm.com 125412744Sodanrc@yahoo.com.br // too hard to replace block with transient state 125512744Sodanrc@yahoo.com.br // allocation failed, block not inserted 125612744Sodanrc@yahoo.com.br return nullptr; 125712744Sodanrc@yahoo.com.br } 125812744Sodanrc@yahoo.com.br } 125912744Sodanrc@yahoo.com.br } 126012744Sodanrc@yahoo.com.br 126112744Sodanrc@yahoo.com.br // The victim will be replaced by a new entry, so increase the replacement 126212744Sodanrc@yahoo.com.br // counter if a valid block is being replaced 126312744Sodanrc@yahoo.com.br if (victim->isValid()) { 126412744Sodanrc@yahoo.com.br DPRINTF(Cache, "replacement: replacing %#llx (%s) with %#llx " 126512744Sodanrc@yahoo.com.br "(%s): %s\n", regenerateBlkAddr(victim), 126612744Sodanrc@yahoo.com.br victim->isSecure() ? "s" : "ns", 126712744Sodanrc@yahoo.com.br addr, is_secure ? "s" : "ns", 126812744Sodanrc@yahoo.com.br victim->isDirty() ? "writeback" : "clean"); 126912744Sodanrc@yahoo.com.br 127012744Sodanrc@yahoo.com.br replacements++; 127112744Sodanrc@yahoo.com.br } 127212744Sodanrc@yahoo.com.br 127312744Sodanrc@yahoo.com.br // Evict valid blocks associated to this victim block 127412744Sodanrc@yahoo.com.br for (const auto& blk : evict_blks) { 127512744Sodanrc@yahoo.com.br if (blk->isValid()) { 127612724Snikos.nikoleris@arm.com if (blk->wasPrefetched()) { 127712724Snikos.nikoleris@arm.com unusedPrefetches++; 127812724Snikos.nikoleris@arm.com } 127912744Sodanrc@yahoo.com.br 128012724Snikos.nikoleris@arm.com evictBlock(blk, writebacks); 128112724Snikos.nikoleris@arm.com } 128212724Snikos.nikoleris@arm.com } 128312724Snikos.nikoleris@arm.com 128412754Sodanrc@yahoo.com.br // Insert new block at victimized entry 128512754Sodanrc@yahoo.com.br tags->insertBlock(pkt, victim); 128612754Sodanrc@yahoo.com.br 128712744Sodanrc@yahoo.com.br return victim; 128812724Snikos.nikoleris@arm.com} 128912724Snikos.nikoleris@arm.com 129012724Snikos.nikoleris@arm.comvoid 129112724Snikos.nikoleris@arm.comBaseCache::invalidateBlock(CacheBlk *blk) 129212724Snikos.nikoleris@arm.com{ 129312724Snikos.nikoleris@arm.com if (blk != tempBlock) 129412724Snikos.nikoleris@arm.com tags->invalidate(blk); 129512724Snikos.nikoleris@arm.com blk->invalidate(); 129612724Snikos.nikoleris@arm.com} 129712724Snikos.nikoleris@arm.com 129812724Snikos.nikoleris@arm.comPacketPtr 129912724Snikos.nikoleris@arm.comBaseCache::writebackBlk(CacheBlk *blk) 130012724Snikos.nikoleris@arm.com{ 130112724Snikos.nikoleris@arm.com chatty_assert(!isReadOnly || writebackClean, 130212724Snikos.nikoleris@arm.com "Writeback from read-only cache"); 130312724Snikos.nikoleris@arm.com assert(blk && blk->isValid() && (blk->isDirty() || writebackClean)); 130412724Snikos.nikoleris@arm.com 130512724Snikos.nikoleris@arm.com writebacks[Request::wbMasterId]++; 130612724Snikos.nikoleris@arm.com 130712749Sgiacomo.travaglini@arm.com RequestPtr req = std::make_shared<Request>( 130812749Sgiacomo.travaglini@arm.com regenerateBlkAddr(blk), blkSize, 0, Request::wbMasterId); 130912749Sgiacomo.travaglini@arm.com 131012724Snikos.nikoleris@arm.com if (blk->isSecure()) 131112724Snikos.nikoleris@arm.com req->setFlags(Request::SECURE); 131212724Snikos.nikoleris@arm.com 131312724Snikos.nikoleris@arm.com req->taskId(blk->task_id); 131412724Snikos.nikoleris@arm.com 131512724Snikos.nikoleris@arm.com PacketPtr pkt = 131612724Snikos.nikoleris@arm.com new Packet(req, blk->isDirty() ? 131712724Snikos.nikoleris@arm.com MemCmd::WritebackDirty : MemCmd::WritebackClean); 131812724Snikos.nikoleris@arm.com 131912724Snikos.nikoleris@arm.com DPRINTF(Cache, "Create Writeback %s writable: %d, dirty: %d\n", 132012724Snikos.nikoleris@arm.com pkt->print(), blk->isWritable(), blk->isDirty()); 132112724Snikos.nikoleris@arm.com 132212724Snikos.nikoleris@arm.com if (blk->isWritable()) { 132312724Snikos.nikoleris@arm.com // not asserting shared means we pass the block in modified 132412724Snikos.nikoleris@arm.com // state, mark our own block non-writeable 132512724Snikos.nikoleris@arm.com blk->status &= ~BlkWritable; 132612724Snikos.nikoleris@arm.com } else { 132712724Snikos.nikoleris@arm.com // we are in the Owned state, tell the receiver 132812724Snikos.nikoleris@arm.com pkt->setHasSharers(); 132912724Snikos.nikoleris@arm.com } 133012724Snikos.nikoleris@arm.com 133112724Snikos.nikoleris@arm.com // make sure the block is not marked dirty 133212724Snikos.nikoleris@arm.com blk->status &= ~BlkDirty; 133312724Snikos.nikoleris@arm.com 133412724Snikos.nikoleris@arm.com pkt->allocate(); 133512724Snikos.nikoleris@arm.com pkt->setDataFromBlock(blk->data, blkSize); 133612724Snikos.nikoleris@arm.com 133712724Snikos.nikoleris@arm.com return pkt; 133812724Snikos.nikoleris@arm.com} 133912724Snikos.nikoleris@arm.com 134012724Snikos.nikoleris@arm.comPacketPtr 134112724Snikos.nikoleris@arm.comBaseCache::writecleanBlk(CacheBlk *blk, Request::Flags dest, PacketId id) 134212724Snikos.nikoleris@arm.com{ 134312749Sgiacomo.travaglini@arm.com RequestPtr req = std::make_shared<Request>( 134412749Sgiacomo.travaglini@arm.com regenerateBlkAddr(blk), blkSize, 0, Request::wbMasterId); 134512749Sgiacomo.travaglini@arm.com 134612724Snikos.nikoleris@arm.com if (blk->isSecure()) { 134712724Snikos.nikoleris@arm.com req->setFlags(Request::SECURE); 134812724Snikos.nikoleris@arm.com } 134912724Snikos.nikoleris@arm.com req->taskId(blk->task_id); 135012724Snikos.nikoleris@arm.com 135112724Snikos.nikoleris@arm.com PacketPtr pkt = new Packet(req, MemCmd::WriteClean, blkSize, id); 135212724Snikos.nikoleris@arm.com 135312724Snikos.nikoleris@arm.com if (dest) { 135412724Snikos.nikoleris@arm.com req->setFlags(dest); 135512724Snikos.nikoleris@arm.com pkt->setWriteThrough(); 135612724Snikos.nikoleris@arm.com } 135712724Snikos.nikoleris@arm.com 135812724Snikos.nikoleris@arm.com DPRINTF(Cache, "Create %s writable: %d, dirty: %d\n", pkt->print(), 135912724Snikos.nikoleris@arm.com blk->isWritable(), blk->isDirty()); 136012724Snikos.nikoleris@arm.com 136112724Snikos.nikoleris@arm.com if (blk->isWritable()) { 136212724Snikos.nikoleris@arm.com // not asserting shared means we pass the block in modified 136312724Snikos.nikoleris@arm.com // state, mark our own block non-writeable 136412724Snikos.nikoleris@arm.com blk->status &= ~BlkWritable; 136512724Snikos.nikoleris@arm.com } else { 136612724Snikos.nikoleris@arm.com // we are in the Owned state, tell the receiver 136712724Snikos.nikoleris@arm.com pkt->setHasSharers(); 136812724Snikos.nikoleris@arm.com } 136912724Snikos.nikoleris@arm.com 137012724Snikos.nikoleris@arm.com // make sure the block is not marked dirty 137112724Snikos.nikoleris@arm.com blk->status &= ~BlkDirty; 137212724Snikos.nikoleris@arm.com 137312724Snikos.nikoleris@arm.com pkt->allocate(); 137412724Snikos.nikoleris@arm.com pkt->setDataFromBlock(blk->data, blkSize); 137512724Snikos.nikoleris@arm.com 137612724Snikos.nikoleris@arm.com return pkt; 137712724Snikos.nikoleris@arm.com} 137812724Snikos.nikoleris@arm.com 137912724Snikos.nikoleris@arm.com 138012724Snikos.nikoleris@arm.comvoid 138112724Snikos.nikoleris@arm.comBaseCache::memWriteback() 138212724Snikos.nikoleris@arm.com{ 138312728Snikos.nikoleris@arm.com tags->forEachBlk([this](CacheBlk &blk) { writebackVisitor(blk); }); 138412724Snikos.nikoleris@arm.com} 138512724Snikos.nikoleris@arm.com 138612724Snikos.nikoleris@arm.comvoid 138712724Snikos.nikoleris@arm.comBaseCache::memInvalidate() 138812724Snikos.nikoleris@arm.com{ 138912728Snikos.nikoleris@arm.com tags->forEachBlk([this](CacheBlk &blk) { invalidateVisitor(blk); }); 139012724Snikos.nikoleris@arm.com} 139112724Snikos.nikoleris@arm.com 139212724Snikos.nikoleris@arm.combool 139312724Snikos.nikoleris@arm.comBaseCache::isDirty() const 139412724Snikos.nikoleris@arm.com{ 139512728Snikos.nikoleris@arm.com return tags->anyBlk([](CacheBlk &blk) { return blk.isDirty(); }); 139612724Snikos.nikoleris@arm.com} 139712724Snikos.nikoleris@arm.com 139812728Snikos.nikoleris@arm.comvoid 139912724Snikos.nikoleris@arm.comBaseCache::writebackVisitor(CacheBlk &blk) 140012724Snikos.nikoleris@arm.com{ 140112724Snikos.nikoleris@arm.com if (blk.isDirty()) { 140212724Snikos.nikoleris@arm.com assert(blk.isValid()); 140312724Snikos.nikoleris@arm.com 140412749Sgiacomo.travaglini@arm.com RequestPtr request = std::make_shared<Request>( 140512749Sgiacomo.travaglini@arm.com regenerateBlkAddr(&blk), blkSize, 0, Request::funcMasterId); 140612749Sgiacomo.travaglini@arm.com 140712749Sgiacomo.travaglini@arm.com request->taskId(blk.task_id); 140812724Snikos.nikoleris@arm.com if (blk.isSecure()) { 140912749Sgiacomo.travaglini@arm.com request->setFlags(Request::SECURE); 141012724Snikos.nikoleris@arm.com } 141112724Snikos.nikoleris@arm.com 141212749Sgiacomo.travaglini@arm.com Packet packet(request, MemCmd::WriteReq); 141312724Snikos.nikoleris@arm.com packet.dataStatic(blk.data); 141412724Snikos.nikoleris@arm.com 141512724Snikos.nikoleris@arm.com memSidePort.sendFunctional(&packet); 141612724Snikos.nikoleris@arm.com 141712724Snikos.nikoleris@arm.com blk.status &= ~BlkDirty; 141812724Snikos.nikoleris@arm.com } 141912724Snikos.nikoleris@arm.com} 142012724Snikos.nikoleris@arm.com 142112728Snikos.nikoleris@arm.comvoid 142212724Snikos.nikoleris@arm.comBaseCache::invalidateVisitor(CacheBlk &blk) 142312724Snikos.nikoleris@arm.com{ 142412724Snikos.nikoleris@arm.com if (blk.isDirty()) 142512724Snikos.nikoleris@arm.com warn_once("Invalidating dirty cache lines. " \ 142612724Snikos.nikoleris@arm.com "Expect things to break.\n"); 142712724Snikos.nikoleris@arm.com 142812724Snikos.nikoleris@arm.com if (blk.isValid()) { 142912724Snikos.nikoleris@arm.com assert(!blk.isDirty()); 143012724Snikos.nikoleris@arm.com invalidateBlock(&blk); 143112724Snikos.nikoleris@arm.com } 143212724Snikos.nikoleris@arm.com} 143312724Snikos.nikoleris@arm.com 143412724Snikos.nikoleris@arm.comTick 143512724Snikos.nikoleris@arm.comBaseCache::nextQueueReadyTime() const 143612724Snikos.nikoleris@arm.com{ 143712724Snikos.nikoleris@arm.com Tick nextReady = std::min(mshrQueue.nextReadyTime(), 143812724Snikos.nikoleris@arm.com writeBuffer.nextReadyTime()); 143912724Snikos.nikoleris@arm.com 144012724Snikos.nikoleris@arm.com // Don't signal prefetch ready time if no MSHRs available 144112724Snikos.nikoleris@arm.com // Will signal once enoguh MSHRs are deallocated 144212724Snikos.nikoleris@arm.com if (prefetcher && mshrQueue.canPrefetch()) { 144312724Snikos.nikoleris@arm.com nextReady = std::min(nextReady, 144412724Snikos.nikoleris@arm.com prefetcher->nextPrefetchReadyTime()); 144512724Snikos.nikoleris@arm.com } 144612724Snikos.nikoleris@arm.com 144712724Snikos.nikoleris@arm.com return nextReady; 144812724Snikos.nikoleris@arm.com} 144912724Snikos.nikoleris@arm.com 145012724Snikos.nikoleris@arm.com 145112724Snikos.nikoleris@arm.combool 145212724Snikos.nikoleris@arm.comBaseCache::sendMSHRQueuePacket(MSHR* mshr) 145312724Snikos.nikoleris@arm.com{ 145412724Snikos.nikoleris@arm.com assert(mshr); 145512724Snikos.nikoleris@arm.com 145612724Snikos.nikoleris@arm.com // use request from 1st target 145712724Snikos.nikoleris@arm.com PacketPtr tgt_pkt = mshr->getTarget()->pkt; 145812724Snikos.nikoleris@arm.com 145912724Snikos.nikoleris@arm.com DPRINTF(Cache, "%s: MSHR %s\n", __func__, tgt_pkt->print()); 146012724Snikos.nikoleris@arm.com 146112724Snikos.nikoleris@arm.com CacheBlk *blk = tags->findBlock(mshr->blkAddr, mshr->isSecure); 146212724Snikos.nikoleris@arm.com 146312724Snikos.nikoleris@arm.com // either a prefetch that is not present upstream, or a normal 146412724Snikos.nikoleris@arm.com // MSHR request, proceed to get the packet to send downstream 146512724Snikos.nikoleris@arm.com PacketPtr pkt = createMissPacket(tgt_pkt, blk, mshr->needsWritable()); 146612724Snikos.nikoleris@arm.com 146712724Snikos.nikoleris@arm.com mshr->isForward = (pkt == nullptr); 146812724Snikos.nikoleris@arm.com 146912724Snikos.nikoleris@arm.com if (mshr->isForward) { 147012724Snikos.nikoleris@arm.com // not a cache block request, but a response is expected 147112724Snikos.nikoleris@arm.com // make copy of current packet to forward, keep current 147212724Snikos.nikoleris@arm.com // copy for response handling 147312724Snikos.nikoleris@arm.com pkt = new Packet(tgt_pkt, false, true); 147412724Snikos.nikoleris@arm.com assert(!pkt->isWrite()); 147512724Snikos.nikoleris@arm.com } 147612724Snikos.nikoleris@arm.com 147712724Snikos.nikoleris@arm.com // play it safe and append (rather than set) the sender state, 147812724Snikos.nikoleris@arm.com // as forwarded packets may already have existing state 147912724Snikos.nikoleris@arm.com pkt->pushSenderState(mshr); 148012724Snikos.nikoleris@arm.com 148112724Snikos.nikoleris@arm.com if (pkt->isClean() && blk && blk->isDirty()) { 148212724Snikos.nikoleris@arm.com // A cache clean opearation is looking for a dirty block. Mark 148312724Snikos.nikoleris@arm.com // the packet so that the destination xbar can determine that 148412724Snikos.nikoleris@arm.com // there will be a follow-up write packet as well. 148512724Snikos.nikoleris@arm.com pkt->setSatisfied(); 148612724Snikos.nikoleris@arm.com } 148712724Snikos.nikoleris@arm.com 148812724Snikos.nikoleris@arm.com if (!memSidePort.sendTimingReq(pkt)) { 148912724Snikos.nikoleris@arm.com // we are awaiting a retry, but we 149012724Snikos.nikoleris@arm.com // delete the packet and will be creating a new packet 149112724Snikos.nikoleris@arm.com // when we get the opportunity 149212724Snikos.nikoleris@arm.com delete pkt; 149312724Snikos.nikoleris@arm.com 149412724Snikos.nikoleris@arm.com // note that we have now masked any requestBus and 149512724Snikos.nikoleris@arm.com // schedSendEvent (we will wait for a retry before 149612724Snikos.nikoleris@arm.com // doing anything), and this is so even if we do not 149712724Snikos.nikoleris@arm.com // care about this packet and might override it before 149812724Snikos.nikoleris@arm.com // it gets retried 149912724Snikos.nikoleris@arm.com return true; 150012724Snikos.nikoleris@arm.com } else { 150112724Snikos.nikoleris@arm.com // As part of the call to sendTimingReq the packet is 150212724Snikos.nikoleris@arm.com // forwarded to all neighbouring caches (and any caches 150312724Snikos.nikoleris@arm.com // above them) as a snoop. Thus at this point we know if 150412724Snikos.nikoleris@arm.com // any of the neighbouring caches are responding, and if 150512724Snikos.nikoleris@arm.com // so, we know it is dirty, and we can determine if it is 150612724Snikos.nikoleris@arm.com // being passed as Modified, making our MSHR the ordering 150712724Snikos.nikoleris@arm.com // point 150812724Snikos.nikoleris@arm.com bool pending_modified_resp = !pkt->hasSharers() && 150912724Snikos.nikoleris@arm.com pkt->cacheResponding(); 151012724Snikos.nikoleris@arm.com markInService(mshr, pending_modified_resp); 151112724Snikos.nikoleris@arm.com 151212724Snikos.nikoleris@arm.com if (pkt->isClean() && blk && blk->isDirty()) { 151312724Snikos.nikoleris@arm.com // A cache clean opearation is looking for a dirty 151412724Snikos.nikoleris@arm.com // block. If a dirty block is encountered a WriteClean 151512724Snikos.nikoleris@arm.com // will update any copies to the path to the memory 151612724Snikos.nikoleris@arm.com // until the point of reference. 151712724Snikos.nikoleris@arm.com DPRINTF(CacheVerbose, "%s: packet %s found block: %s\n", 151812724Snikos.nikoleris@arm.com __func__, pkt->print(), blk->print()); 151912724Snikos.nikoleris@arm.com PacketPtr wb_pkt = writecleanBlk(blk, pkt->req->getDest(), 152012724Snikos.nikoleris@arm.com pkt->id); 152112724Snikos.nikoleris@arm.com PacketList writebacks; 152212724Snikos.nikoleris@arm.com writebacks.push_back(wb_pkt); 152312724Snikos.nikoleris@arm.com doWritebacks(writebacks, 0); 152412724Snikos.nikoleris@arm.com } 152512724Snikos.nikoleris@arm.com 152612724Snikos.nikoleris@arm.com return false; 152712724Snikos.nikoleris@arm.com } 152812724Snikos.nikoleris@arm.com} 152912724Snikos.nikoleris@arm.com 153012724Snikos.nikoleris@arm.combool 153112724Snikos.nikoleris@arm.comBaseCache::sendWriteQueuePacket(WriteQueueEntry* wq_entry) 153212724Snikos.nikoleris@arm.com{ 153312724Snikos.nikoleris@arm.com assert(wq_entry); 153412724Snikos.nikoleris@arm.com 153512724Snikos.nikoleris@arm.com // always a single target for write queue entries 153612724Snikos.nikoleris@arm.com PacketPtr tgt_pkt = wq_entry->getTarget()->pkt; 153712724Snikos.nikoleris@arm.com 153812724Snikos.nikoleris@arm.com DPRINTF(Cache, "%s: write %s\n", __func__, tgt_pkt->print()); 153912724Snikos.nikoleris@arm.com 154012724Snikos.nikoleris@arm.com // forward as is, both for evictions and uncacheable writes 154112724Snikos.nikoleris@arm.com if (!memSidePort.sendTimingReq(tgt_pkt)) { 154212724Snikos.nikoleris@arm.com // note that we have now masked any requestBus and 154312724Snikos.nikoleris@arm.com // schedSendEvent (we will wait for a retry before 154412724Snikos.nikoleris@arm.com // doing anything), and this is so even if we do not 154512724Snikos.nikoleris@arm.com // care about this packet and might override it before 154612724Snikos.nikoleris@arm.com // it gets retried 154712724Snikos.nikoleris@arm.com return true; 154812724Snikos.nikoleris@arm.com } else { 154912724Snikos.nikoleris@arm.com markInService(wq_entry); 155012724Snikos.nikoleris@arm.com return false; 155112724Snikos.nikoleris@arm.com } 155212724Snikos.nikoleris@arm.com} 155312724Snikos.nikoleris@arm.com 155412724Snikos.nikoleris@arm.comvoid 155512724Snikos.nikoleris@arm.comBaseCache::serialize(CheckpointOut &cp) const 155612724Snikos.nikoleris@arm.com{ 155712724Snikos.nikoleris@arm.com bool dirty(isDirty()); 155812724Snikos.nikoleris@arm.com 155912724Snikos.nikoleris@arm.com if (dirty) { 156012724Snikos.nikoleris@arm.com warn("*** The cache still contains dirty data. ***\n"); 156112724Snikos.nikoleris@arm.com warn(" Make sure to drain the system using the correct flags.\n"); 156212724Snikos.nikoleris@arm.com warn(" This checkpoint will not restore correctly " \ 156312724Snikos.nikoleris@arm.com "and dirty data in the cache will be lost!\n"); 156412724Snikos.nikoleris@arm.com } 156512724Snikos.nikoleris@arm.com 156612724Snikos.nikoleris@arm.com // Since we don't checkpoint the data in the cache, any dirty data 156712724Snikos.nikoleris@arm.com // will be lost when restoring from a checkpoint of a system that 156812724Snikos.nikoleris@arm.com // wasn't drained properly. Flag the checkpoint as invalid if the 156912724Snikos.nikoleris@arm.com // cache contains dirty data. 157012724Snikos.nikoleris@arm.com bool bad_checkpoint(dirty); 157112724Snikos.nikoleris@arm.com SERIALIZE_SCALAR(bad_checkpoint); 157212724Snikos.nikoleris@arm.com} 157312724Snikos.nikoleris@arm.com 157412724Snikos.nikoleris@arm.comvoid 157512724Snikos.nikoleris@arm.comBaseCache::unserialize(CheckpointIn &cp) 157612724Snikos.nikoleris@arm.com{ 157712724Snikos.nikoleris@arm.com bool bad_checkpoint; 157812724Snikos.nikoleris@arm.com UNSERIALIZE_SCALAR(bad_checkpoint); 157912724Snikos.nikoleris@arm.com if (bad_checkpoint) { 158012724Snikos.nikoleris@arm.com fatal("Restoring from checkpoints with dirty caches is not " 158112724Snikos.nikoleris@arm.com "supported in the classic memory system. Please remove any " 158212724Snikos.nikoleris@arm.com "caches or drain them properly before taking checkpoints.\n"); 158312724Snikos.nikoleris@arm.com } 158412724Snikos.nikoleris@arm.com} 158512724Snikos.nikoleris@arm.com 158612724Snikos.nikoleris@arm.comvoid 15872810SN/ABaseCache::regStats() 15882810SN/A{ 158911522Sstephan.diestelhorst@arm.com MemObject::regStats(); 159011522Sstephan.diestelhorst@arm.com 15912810SN/A using namespace Stats; 15922810SN/A 15932810SN/A // Hit statistics 15944022SN/A for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) { 15954022SN/A MemCmd cmd(access_idx); 15964022SN/A const string &cstr = cmd.toString(); 15972810SN/A 15982810SN/A hits[access_idx] 15998833Sdam.sunwoo@arm.com .init(system->maxMasters()) 16002810SN/A .name(name() + "." + cstr + "_hits") 16012810SN/A .desc("number of " + cstr + " hits") 16022810SN/A .flags(total | nozero | nonan) 16032810SN/A ; 16048833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 16058833Sdam.sunwoo@arm.com hits[access_idx].subname(i, system->getMasterName(i)); 16068833Sdam.sunwoo@arm.com } 16072810SN/A } 16082810SN/A 16094871SN/A// These macros make it easier to sum the right subset of commands and 16104871SN/A// to change the subset of commands that are considered "demand" vs 16114871SN/A// "non-demand" 16124871SN/A#define SUM_DEMAND(s) \ 161311455Sandreas.hansson@arm.com (s[MemCmd::ReadReq] + s[MemCmd::WriteReq] + s[MemCmd::WriteLineReq] + \ 161410885Sandreas.hansson@arm.com s[MemCmd::ReadExReq] + s[MemCmd::ReadCleanReq] + s[MemCmd::ReadSharedReq]) 16154871SN/A 16164871SN/A// should writebacks be included here? prior code was inconsistent... 16174871SN/A#define SUM_NON_DEMAND(s) \ 16184871SN/A (s[MemCmd::SoftPFReq] + s[MemCmd::HardPFReq]) 16194871SN/A 16202810SN/A demandHits 16212810SN/A .name(name() + ".demand_hits") 16222810SN/A .desc("number of demand (read+write) hits") 16238833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 16242810SN/A ; 16254871SN/A demandHits = SUM_DEMAND(hits); 16268833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 16278833Sdam.sunwoo@arm.com demandHits.subname(i, system->getMasterName(i)); 16288833Sdam.sunwoo@arm.com } 16292810SN/A 16302810SN/A overallHits 16312810SN/A .name(name() + ".overall_hits") 16322810SN/A .desc("number of overall hits") 16338833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 16342810SN/A ; 16354871SN/A overallHits = demandHits + SUM_NON_DEMAND(hits); 16368833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 16378833Sdam.sunwoo@arm.com overallHits.subname(i, system->getMasterName(i)); 16388833Sdam.sunwoo@arm.com } 16392810SN/A 16402810SN/A // Miss statistics 16414022SN/A for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) { 16424022SN/A MemCmd cmd(access_idx); 16434022SN/A const string &cstr = cmd.toString(); 16442810SN/A 16452810SN/A misses[access_idx] 16468833Sdam.sunwoo@arm.com .init(system->maxMasters()) 16472810SN/A .name(name() + "." + cstr + "_misses") 16482810SN/A .desc("number of " + cstr + " misses") 16492810SN/A .flags(total | nozero | nonan) 16502810SN/A ; 16518833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 16528833Sdam.sunwoo@arm.com misses[access_idx].subname(i, system->getMasterName(i)); 16538833Sdam.sunwoo@arm.com } 16542810SN/A } 16552810SN/A 16562810SN/A demandMisses 16572810SN/A .name(name() + ".demand_misses") 16582810SN/A .desc("number of demand (read+write) misses") 16598833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 16602810SN/A ; 16614871SN/A demandMisses = SUM_DEMAND(misses); 16628833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 16638833Sdam.sunwoo@arm.com demandMisses.subname(i, system->getMasterName(i)); 16648833Sdam.sunwoo@arm.com } 16652810SN/A 16662810SN/A overallMisses 16672810SN/A .name(name() + ".overall_misses") 16682810SN/A .desc("number of overall misses") 16698833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 16702810SN/A ; 16714871SN/A overallMisses = demandMisses + SUM_NON_DEMAND(misses); 16728833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 16738833Sdam.sunwoo@arm.com overallMisses.subname(i, system->getMasterName(i)); 16748833Sdam.sunwoo@arm.com } 16752810SN/A 16762810SN/A // Miss latency statistics 16774022SN/A for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) { 16784022SN/A MemCmd cmd(access_idx); 16794022SN/A const string &cstr = cmd.toString(); 16802810SN/A 16812810SN/A missLatency[access_idx] 16828833Sdam.sunwoo@arm.com .init(system->maxMasters()) 16832810SN/A .name(name() + "." + cstr + "_miss_latency") 16842810SN/A .desc("number of " + cstr + " miss cycles") 16852810SN/A .flags(total | nozero | nonan) 16862810SN/A ; 16878833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 16888833Sdam.sunwoo@arm.com missLatency[access_idx].subname(i, system->getMasterName(i)); 16898833Sdam.sunwoo@arm.com } 16902810SN/A } 16912810SN/A 16922810SN/A demandMissLatency 16932810SN/A .name(name() + ".demand_miss_latency") 16942810SN/A .desc("number of demand (read+write) miss cycles") 16958833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 16962810SN/A ; 16974871SN/A demandMissLatency = SUM_DEMAND(missLatency); 16988833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 16998833Sdam.sunwoo@arm.com demandMissLatency.subname(i, system->getMasterName(i)); 17008833Sdam.sunwoo@arm.com } 17012810SN/A 17022810SN/A overallMissLatency 17032810SN/A .name(name() + ".overall_miss_latency") 17042810SN/A .desc("number of overall miss cycles") 17058833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 17062810SN/A ; 17074871SN/A overallMissLatency = demandMissLatency + SUM_NON_DEMAND(missLatency); 17088833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 17098833Sdam.sunwoo@arm.com overallMissLatency.subname(i, system->getMasterName(i)); 17108833Sdam.sunwoo@arm.com } 17112810SN/A 17122810SN/A // access formulas 17134022SN/A for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) { 17144022SN/A MemCmd cmd(access_idx); 17154022SN/A const string &cstr = cmd.toString(); 17162810SN/A 17172810SN/A accesses[access_idx] 17182810SN/A .name(name() + "." + cstr + "_accesses") 17192810SN/A .desc("number of " + cstr + " accesses(hits+misses)") 17202810SN/A .flags(total | nozero | nonan) 17212810SN/A ; 17228833Sdam.sunwoo@arm.com accesses[access_idx] = hits[access_idx] + misses[access_idx]; 17232810SN/A 17248833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 17258833Sdam.sunwoo@arm.com accesses[access_idx].subname(i, system->getMasterName(i)); 17268833Sdam.sunwoo@arm.com } 17272810SN/A } 17282810SN/A 17292810SN/A demandAccesses 17302810SN/A .name(name() + ".demand_accesses") 17312810SN/A .desc("number of demand (read+write) accesses") 17328833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 17332810SN/A ; 17342810SN/A demandAccesses = demandHits + demandMisses; 17358833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 17368833Sdam.sunwoo@arm.com demandAccesses.subname(i, system->getMasterName(i)); 17378833Sdam.sunwoo@arm.com } 17382810SN/A 17392810SN/A overallAccesses 17402810SN/A .name(name() + ".overall_accesses") 17412810SN/A .desc("number of overall (read+write) accesses") 17428833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 17432810SN/A ; 17442810SN/A overallAccesses = overallHits + overallMisses; 17458833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 17468833Sdam.sunwoo@arm.com overallAccesses.subname(i, system->getMasterName(i)); 17478833Sdam.sunwoo@arm.com } 17482810SN/A 17492810SN/A // miss rate formulas 17504022SN/A for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) { 17514022SN/A MemCmd cmd(access_idx); 17524022SN/A const string &cstr = cmd.toString(); 17532810SN/A 17542810SN/A missRate[access_idx] 17552810SN/A .name(name() + "." + cstr + "_miss_rate") 17562810SN/A .desc("miss rate for " + cstr + " accesses") 17572810SN/A .flags(total | nozero | nonan) 17582810SN/A ; 17598833Sdam.sunwoo@arm.com missRate[access_idx] = misses[access_idx] / accesses[access_idx]; 17602810SN/A 17618833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 17628833Sdam.sunwoo@arm.com missRate[access_idx].subname(i, system->getMasterName(i)); 17638833Sdam.sunwoo@arm.com } 17642810SN/A } 17652810SN/A 17662810SN/A demandMissRate 17672810SN/A .name(name() + ".demand_miss_rate") 17682810SN/A .desc("miss rate for demand accesses") 17698833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 17702810SN/A ; 17712810SN/A demandMissRate = demandMisses / demandAccesses; 17728833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 17738833Sdam.sunwoo@arm.com demandMissRate.subname(i, system->getMasterName(i)); 17748833Sdam.sunwoo@arm.com } 17752810SN/A 17762810SN/A overallMissRate 17772810SN/A .name(name() + ".overall_miss_rate") 17782810SN/A .desc("miss rate for overall accesses") 17798833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 17802810SN/A ; 17812810SN/A overallMissRate = overallMisses / overallAccesses; 17828833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 17838833Sdam.sunwoo@arm.com overallMissRate.subname(i, system->getMasterName(i)); 17848833Sdam.sunwoo@arm.com } 17852810SN/A 17862810SN/A // miss latency formulas 17874022SN/A for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) { 17884022SN/A MemCmd cmd(access_idx); 17894022SN/A const string &cstr = cmd.toString(); 17902810SN/A 17912810SN/A avgMissLatency[access_idx] 17922810SN/A .name(name() + "." + cstr + "_avg_miss_latency") 17932810SN/A .desc("average " + cstr + " miss latency") 17942810SN/A .flags(total | nozero | nonan) 17952810SN/A ; 17962810SN/A avgMissLatency[access_idx] = 17972810SN/A missLatency[access_idx] / misses[access_idx]; 17988833Sdam.sunwoo@arm.com 17998833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 18008833Sdam.sunwoo@arm.com avgMissLatency[access_idx].subname(i, system->getMasterName(i)); 18018833Sdam.sunwoo@arm.com } 18022810SN/A } 18032810SN/A 18042810SN/A demandAvgMissLatency 18052810SN/A .name(name() + ".demand_avg_miss_latency") 18062810SN/A .desc("average overall miss latency") 18078833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 18082810SN/A ; 18092810SN/A demandAvgMissLatency = demandMissLatency / demandMisses; 18108833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 18118833Sdam.sunwoo@arm.com demandAvgMissLatency.subname(i, system->getMasterName(i)); 18128833Sdam.sunwoo@arm.com } 18132810SN/A 18142810SN/A overallAvgMissLatency 18152810SN/A .name(name() + ".overall_avg_miss_latency") 18162810SN/A .desc("average overall miss latency") 18178833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 18182810SN/A ; 18192810SN/A overallAvgMissLatency = overallMissLatency / overallMisses; 18208833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 18218833Sdam.sunwoo@arm.com overallAvgMissLatency.subname(i, system->getMasterName(i)); 18228833Sdam.sunwoo@arm.com } 18232810SN/A 18242810SN/A blocked_cycles.init(NUM_BLOCKED_CAUSES); 18252810SN/A blocked_cycles 18262810SN/A .name(name() + ".blocked_cycles") 18272810SN/A .desc("number of cycles access was blocked") 18282810SN/A .subname(Blocked_NoMSHRs, "no_mshrs") 18292810SN/A .subname(Blocked_NoTargets, "no_targets") 18302810SN/A ; 18312810SN/A 18322810SN/A 18332810SN/A blocked_causes.init(NUM_BLOCKED_CAUSES); 18342810SN/A blocked_causes 18352810SN/A .name(name() + ".blocked") 18362810SN/A .desc("number of cycles access was blocked") 18372810SN/A .subname(Blocked_NoMSHRs, "no_mshrs") 18382810SN/A .subname(Blocked_NoTargets, "no_targets") 18392810SN/A ; 18402810SN/A 18412810SN/A avg_blocked 18422810SN/A .name(name() + ".avg_blocked_cycles") 18432810SN/A .desc("average number of cycles each access was blocked") 18442810SN/A .subname(Blocked_NoMSHRs, "no_mshrs") 18452810SN/A .subname(Blocked_NoTargets, "no_targets") 18462810SN/A ; 18472810SN/A 18482810SN/A avg_blocked = blocked_cycles / blocked_causes; 18492810SN/A 185011436SRekai.GonzalezAlberquilla@arm.com unusedPrefetches 185111436SRekai.GonzalezAlberquilla@arm.com .name(name() + ".unused_prefetches") 185211436SRekai.GonzalezAlberquilla@arm.com .desc("number of HardPF blocks evicted w/o reference") 185311436SRekai.GonzalezAlberquilla@arm.com .flags(nozero) 185411436SRekai.GonzalezAlberquilla@arm.com ; 185511436SRekai.GonzalezAlberquilla@arm.com 18564626SN/A writebacks 18578833Sdam.sunwoo@arm.com .init(system->maxMasters()) 18584626SN/A .name(name() + ".writebacks") 18594626SN/A .desc("number of writebacks") 18608833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 18614626SN/A ; 18628833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 18638833Sdam.sunwoo@arm.com writebacks.subname(i, system->getMasterName(i)); 18648833Sdam.sunwoo@arm.com } 18654626SN/A 18664626SN/A // MSHR statistics 18674626SN/A // MSHR hit statistics 18684626SN/A for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) { 18694626SN/A MemCmd cmd(access_idx); 18704626SN/A const string &cstr = cmd.toString(); 18714626SN/A 18724626SN/A mshr_hits[access_idx] 18738833Sdam.sunwoo@arm.com .init(system->maxMasters()) 18744626SN/A .name(name() + "." + cstr + "_mshr_hits") 18754626SN/A .desc("number of " + cstr + " MSHR hits") 18764626SN/A .flags(total | nozero | nonan) 18774626SN/A ; 18788833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 18798833Sdam.sunwoo@arm.com mshr_hits[access_idx].subname(i, system->getMasterName(i)); 18808833Sdam.sunwoo@arm.com } 18814626SN/A } 18824626SN/A 18834626SN/A demandMshrHits 18844626SN/A .name(name() + ".demand_mshr_hits") 18854626SN/A .desc("number of demand (read+write) MSHR hits") 18868833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 18874626SN/A ; 18884871SN/A demandMshrHits = SUM_DEMAND(mshr_hits); 18898833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 18908833Sdam.sunwoo@arm.com demandMshrHits.subname(i, system->getMasterName(i)); 18918833Sdam.sunwoo@arm.com } 18924626SN/A 18934626SN/A overallMshrHits 18944626SN/A .name(name() + ".overall_mshr_hits") 18954626SN/A .desc("number of overall MSHR hits") 18968833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 18974626SN/A ; 18984871SN/A overallMshrHits = demandMshrHits + SUM_NON_DEMAND(mshr_hits); 18998833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 19008833Sdam.sunwoo@arm.com overallMshrHits.subname(i, system->getMasterName(i)); 19018833Sdam.sunwoo@arm.com } 19024626SN/A 19034626SN/A // MSHR miss statistics 19044626SN/A for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) { 19054626SN/A MemCmd cmd(access_idx); 19064626SN/A const string &cstr = cmd.toString(); 19074626SN/A 19084626SN/A mshr_misses[access_idx] 19098833Sdam.sunwoo@arm.com .init(system->maxMasters()) 19104626SN/A .name(name() + "." + cstr + "_mshr_misses") 19114626SN/A .desc("number of " + cstr + " MSHR misses") 19124626SN/A .flags(total | nozero | nonan) 19134626SN/A ; 19148833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 19158833Sdam.sunwoo@arm.com mshr_misses[access_idx].subname(i, system->getMasterName(i)); 19168833Sdam.sunwoo@arm.com } 19174626SN/A } 19184626SN/A 19194626SN/A demandMshrMisses 19204626SN/A .name(name() + ".demand_mshr_misses") 19214626SN/A .desc("number of demand (read+write) MSHR misses") 19228833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 19234626SN/A ; 19244871SN/A demandMshrMisses = SUM_DEMAND(mshr_misses); 19258833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 19268833Sdam.sunwoo@arm.com demandMshrMisses.subname(i, system->getMasterName(i)); 19278833Sdam.sunwoo@arm.com } 19284626SN/A 19294626SN/A overallMshrMisses 19304626SN/A .name(name() + ".overall_mshr_misses") 19314626SN/A .desc("number of overall MSHR misses") 19328833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 19334626SN/A ; 19344871SN/A overallMshrMisses = demandMshrMisses + SUM_NON_DEMAND(mshr_misses); 19358833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 19368833Sdam.sunwoo@arm.com overallMshrMisses.subname(i, system->getMasterName(i)); 19378833Sdam.sunwoo@arm.com } 19384626SN/A 19394626SN/A // MSHR miss latency statistics 19404626SN/A for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) { 19414626SN/A MemCmd cmd(access_idx); 19424626SN/A const string &cstr = cmd.toString(); 19434626SN/A 19444626SN/A mshr_miss_latency[access_idx] 19458833Sdam.sunwoo@arm.com .init(system->maxMasters()) 19464626SN/A .name(name() + "." + cstr + "_mshr_miss_latency") 19474626SN/A .desc("number of " + cstr + " MSHR miss cycles") 19484626SN/A .flags(total | nozero | nonan) 19494626SN/A ; 19508833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 19518833Sdam.sunwoo@arm.com mshr_miss_latency[access_idx].subname(i, system->getMasterName(i)); 19528833Sdam.sunwoo@arm.com } 19534626SN/A } 19544626SN/A 19554626SN/A demandMshrMissLatency 19564626SN/A .name(name() + ".demand_mshr_miss_latency") 19574626SN/A .desc("number of demand (read+write) MSHR miss cycles") 19588833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 19594626SN/A ; 19604871SN/A demandMshrMissLatency = SUM_DEMAND(mshr_miss_latency); 19618833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 19628833Sdam.sunwoo@arm.com demandMshrMissLatency.subname(i, system->getMasterName(i)); 19638833Sdam.sunwoo@arm.com } 19644626SN/A 19654626SN/A overallMshrMissLatency 19664626SN/A .name(name() + ".overall_mshr_miss_latency") 19674626SN/A .desc("number of overall MSHR miss cycles") 19688833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 19694626SN/A ; 19704871SN/A overallMshrMissLatency = 19714871SN/A demandMshrMissLatency + SUM_NON_DEMAND(mshr_miss_latency); 19728833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 19738833Sdam.sunwoo@arm.com overallMshrMissLatency.subname(i, system->getMasterName(i)); 19748833Sdam.sunwoo@arm.com } 19754626SN/A 19764626SN/A // MSHR uncacheable statistics 19774626SN/A for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) { 19784626SN/A MemCmd cmd(access_idx); 19794626SN/A const string &cstr = cmd.toString(); 19804626SN/A 19814626SN/A mshr_uncacheable[access_idx] 19828833Sdam.sunwoo@arm.com .init(system->maxMasters()) 19834626SN/A .name(name() + "." + cstr + "_mshr_uncacheable") 19844626SN/A .desc("number of " + cstr + " MSHR uncacheable") 19854626SN/A .flags(total | nozero | nonan) 19864626SN/A ; 19878833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 19888833Sdam.sunwoo@arm.com mshr_uncacheable[access_idx].subname(i, system->getMasterName(i)); 19898833Sdam.sunwoo@arm.com } 19904626SN/A } 19914626SN/A 19924626SN/A overallMshrUncacheable 19934626SN/A .name(name() + ".overall_mshr_uncacheable_misses") 19944626SN/A .desc("number of overall MSHR uncacheable misses") 19958833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 19964626SN/A ; 19974871SN/A overallMshrUncacheable = 19984871SN/A SUM_DEMAND(mshr_uncacheable) + SUM_NON_DEMAND(mshr_uncacheable); 19998833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 20008833Sdam.sunwoo@arm.com overallMshrUncacheable.subname(i, system->getMasterName(i)); 20018833Sdam.sunwoo@arm.com } 20024626SN/A 20034626SN/A // MSHR miss latency statistics 20044626SN/A for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) { 20054626SN/A MemCmd cmd(access_idx); 20064626SN/A const string &cstr = cmd.toString(); 20074626SN/A 20084626SN/A mshr_uncacheable_lat[access_idx] 20098833Sdam.sunwoo@arm.com .init(system->maxMasters()) 20104626SN/A .name(name() + "." + cstr + "_mshr_uncacheable_latency") 20114626SN/A .desc("number of " + cstr + " MSHR uncacheable cycles") 20124626SN/A .flags(total | nozero | nonan) 20134626SN/A ; 20148833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 201511483Snikos.nikoleris@arm.com mshr_uncacheable_lat[access_idx].subname( 201611483Snikos.nikoleris@arm.com i, system->getMasterName(i)); 20178833Sdam.sunwoo@arm.com } 20184626SN/A } 20194626SN/A 20204626SN/A overallMshrUncacheableLatency 20214626SN/A .name(name() + ".overall_mshr_uncacheable_latency") 20224626SN/A .desc("number of overall MSHR uncacheable cycles") 20238833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 20244626SN/A ; 20254871SN/A overallMshrUncacheableLatency = 20264871SN/A SUM_DEMAND(mshr_uncacheable_lat) + 20274871SN/A SUM_NON_DEMAND(mshr_uncacheable_lat); 20288833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 20298833Sdam.sunwoo@arm.com overallMshrUncacheableLatency.subname(i, system->getMasterName(i)); 20308833Sdam.sunwoo@arm.com } 20314626SN/A 20324626SN/A#if 0 20334626SN/A // MSHR access formulas 20344626SN/A for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) { 20354626SN/A MemCmd cmd(access_idx); 20364626SN/A const string &cstr = cmd.toString(); 20374626SN/A 20384626SN/A mshrAccesses[access_idx] 20394626SN/A .name(name() + "." + cstr + "_mshr_accesses") 20404626SN/A .desc("number of " + cstr + " mshr accesses(hits+misses)") 20414626SN/A .flags(total | nozero | nonan) 20424626SN/A ; 20434626SN/A mshrAccesses[access_idx] = 20444626SN/A mshr_hits[access_idx] + mshr_misses[access_idx] 20454626SN/A + mshr_uncacheable[access_idx]; 20464626SN/A } 20474626SN/A 20484626SN/A demandMshrAccesses 20494626SN/A .name(name() + ".demand_mshr_accesses") 20504626SN/A .desc("number of demand (read+write) mshr accesses") 20514626SN/A .flags(total | nozero | nonan) 20524626SN/A ; 20534626SN/A demandMshrAccesses = demandMshrHits + demandMshrMisses; 20544626SN/A 20554626SN/A overallMshrAccesses 20564626SN/A .name(name() + ".overall_mshr_accesses") 20574626SN/A .desc("number of overall (read+write) mshr accesses") 20584626SN/A .flags(total | nozero | nonan) 20594626SN/A ; 20604626SN/A overallMshrAccesses = overallMshrHits + overallMshrMisses 20614626SN/A + overallMshrUncacheable; 20624626SN/A#endif 20634626SN/A 20644626SN/A // MSHR miss rate formulas 20654626SN/A for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) { 20664626SN/A MemCmd cmd(access_idx); 20674626SN/A const string &cstr = cmd.toString(); 20684626SN/A 20694626SN/A mshrMissRate[access_idx] 20704626SN/A .name(name() + "." + cstr + "_mshr_miss_rate") 20714626SN/A .desc("mshr miss rate for " + cstr + " accesses") 20724626SN/A .flags(total | nozero | nonan) 20734626SN/A ; 20744626SN/A mshrMissRate[access_idx] = 20754626SN/A mshr_misses[access_idx] / accesses[access_idx]; 20768833Sdam.sunwoo@arm.com 20778833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 20788833Sdam.sunwoo@arm.com mshrMissRate[access_idx].subname(i, system->getMasterName(i)); 20798833Sdam.sunwoo@arm.com } 20804626SN/A } 20814626SN/A 20824626SN/A demandMshrMissRate 20834626SN/A .name(name() + ".demand_mshr_miss_rate") 20844626SN/A .desc("mshr miss rate for demand accesses") 20858833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 20864626SN/A ; 20874626SN/A demandMshrMissRate = demandMshrMisses / demandAccesses; 20888833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 20898833Sdam.sunwoo@arm.com demandMshrMissRate.subname(i, system->getMasterName(i)); 20908833Sdam.sunwoo@arm.com } 20914626SN/A 20924626SN/A overallMshrMissRate 20934626SN/A .name(name() + ".overall_mshr_miss_rate") 20944626SN/A .desc("mshr miss rate for overall accesses") 20958833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 20964626SN/A ; 20974626SN/A overallMshrMissRate = overallMshrMisses / overallAccesses; 20988833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 20998833Sdam.sunwoo@arm.com overallMshrMissRate.subname(i, system->getMasterName(i)); 21008833Sdam.sunwoo@arm.com } 21014626SN/A 21024626SN/A // mshrMiss latency formulas 21034626SN/A for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) { 21044626SN/A MemCmd cmd(access_idx); 21054626SN/A const string &cstr = cmd.toString(); 21064626SN/A 21074626SN/A avgMshrMissLatency[access_idx] 21084626SN/A .name(name() + "." + cstr + "_avg_mshr_miss_latency") 21094626SN/A .desc("average " + cstr + " mshr miss latency") 21104626SN/A .flags(total | nozero | nonan) 21114626SN/A ; 21124626SN/A avgMshrMissLatency[access_idx] = 21134626SN/A mshr_miss_latency[access_idx] / mshr_misses[access_idx]; 21148833Sdam.sunwoo@arm.com 21158833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 211611483Snikos.nikoleris@arm.com avgMshrMissLatency[access_idx].subname( 211711483Snikos.nikoleris@arm.com i, system->getMasterName(i)); 21188833Sdam.sunwoo@arm.com } 21194626SN/A } 21204626SN/A 21214626SN/A demandAvgMshrMissLatency 21224626SN/A .name(name() + ".demand_avg_mshr_miss_latency") 21234626SN/A .desc("average overall mshr miss latency") 21248833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 21254626SN/A ; 21264626SN/A demandAvgMshrMissLatency = demandMshrMissLatency / demandMshrMisses; 21278833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 21288833Sdam.sunwoo@arm.com demandAvgMshrMissLatency.subname(i, system->getMasterName(i)); 21298833Sdam.sunwoo@arm.com } 21304626SN/A 21314626SN/A overallAvgMshrMissLatency 21324626SN/A .name(name() + ".overall_avg_mshr_miss_latency") 21334626SN/A .desc("average overall mshr miss latency") 21348833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 21354626SN/A ; 21364626SN/A overallAvgMshrMissLatency = overallMshrMissLatency / overallMshrMisses; 21378833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 21388833Sdam.sunwoo@arm.com overallAvgMshrMissLatency.subname(i, system->getMasterName(i)); 21398833Sdam.sunwoo@arm.com } 21404626SN/A 21414626SN/A // mshrUncacheable latency formulas 21424626SN/A for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) { 21434626SN/A MemCmd cmd(access_idx); 21444626SN/A const string &cstr = cmd.toString(); 21454626SN/A 21464626SN/A avgMshrUncacheableLatency[access_idx] 21474626SN/A .name(name() + "." + cstr + "_avg_mshr_uncacheable_latency") 21484626SN/A .desc("average " + cstr + " mshr uncacheable latency") 21494626SN/A .flags(total | nozero | nonan) 21504626SN/A ; 21514626SN/A avgMshrUncacheableLatency[access_idx] = 21524626SN/A mshr_uncacheable_lat[access_idx] / mshr_uncacheable[access_idx]; 21538833Sdam.sunwoo@arm.com 21548833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 215511483Snikos.nikoleris@arm.com avgMshrUncacheableLatency[access_idx].subname( 215611483Snikos.nikoleris@arm.com i, system->getMasterName(i)); 21578833Sdam.sunwoo@arm.com } 21584626SN/A } 21594626SN/A 21604626SN/A overallAvgMshrUncacheableLatency 21614626SN/A .name(name() + ".overall_avg_mshr_uncacheable_latency") 21624626SN/A .desc("average overall mshr uncacheable latency") 21638833Sdam.sunwoo@arm.com .flags(total | nozero | nonan) 21644626SN/A ; 216511483Snikos.nikoleris@arm.com overallAvgMshrUncacheableLatency = 216611483Snikos.nikoleris@arm.com overallMshrUncacheableLatency / overallMshrUncacheable; 21678833Sdam.sunwoo@arm.com for (int i = 0; i < system->maxMasters(); i++) { 21688833Sdam.sunwoo@arm.com overallAvgMshrUncacheableLatency.subname(i, system->getMasterName(i)); 21698833Sdam.sunwoo@arm.com } 21704626SN/A 217112702Snikos.nikoleris@arm.com replacements 217212702Snikos.nikoleris@arm.com .name(name() + ".replacements") 217312702Snikos.nikoleris@arm.com .desc("number of replacements") 217412702Snikos.nikoleris@arm.com ; 21752810SN/A} 217612724Snikos.nikoleris@arm.com 217712724Snikos.nikoleris@arm.com/////////////// 217812724Snikos.nikoleris@arm.com// 217912724Snikos.nikoleris@arm.com// CpuSidePort 218012724Snikos.nikoleris@arm.com// 218112724Snikos.nikoleris@arm.com/////////////// 218212724Snikos.nikoleris@arm.combool 218312724Snikos.nikoleris@arm.comBaseCache::CpuSidePort::recvTimingSnoopResp(PacketPtr pkt) 218412724Snikos.nikoleris@arm.com{ 218512725Snikos.nikoleris@arm.com // Snoops shouldn't happen when bypassing caches 218612725Snikos.nikoleris@arm.com assert(!cache->system->bypassCaches()); 218712725Snikos.nikoleris@arm.com 218812725Snikos.nikoleris@arm.com assert(pkt->isResponse()); 218912725Snikos.nikoleris@arm.com 219012724Snikos.nikoleris@arm.com // Express snoop responses from master to slave, e.g., from L1 to L2 219112724Snikos.nikoleris@arm.com cache->recvTimingSnoopResp(pkt); 219212724Snikos.nikoleris@arm.com return true; 219312724Snikos.nikoleris@arm.com} 219412724Snikos.nikoleris@arm.com 219512724Snikos.nikoleris@arm.com 219612724Snikos.nikoleris@arm.combool 219712724Snikos.nikoleris@arm.comBaseCache::CpuSidePort::tryTiming(PacketPtr pkt) 219812724Snikos.nikoleris@arm.com{ 219912725Snikos.nikoleris@arm.com if (cache->system->bypassCaches() || pkt->isExpressSnoop()) { 220012724Snikos.nikoleris@arm.com // always let express snoop packets through even if blocked 220112724Snikos.nikoleris@arm.com return true; 220212724Snikos.nikoleris@arm.com } else if (blocked || mustSendRetry) { 220312724Snikos.nikoleris@arm.com // either already committed to send a retry, or blocked 220412724Snikos.nikoleris@arm.com mustSendRetry = true; 220512724Snikos.nikoleris@arm.com return false; 220612724Snikos.nikoleris@arm.com } 220712724Snikos.nikoleris@arm.com mustSendRetry = false; 220812724Snikos.nikoleris@arm.com return true; 220912724Snikos.nikoleris@arm.com} 221012724Snikos.nikoleris@arm.com 221112724Snikos.nikoleris@arm.combool 221212724Snikos.nikoleris@arm.comBaseCache::CpuSidePort::recvTimingReq(PacketPtr pkt) 221312724Snikos.nikoleris@arm.com{ 221412725Snikos.nikoleris@arm.com assert(pkt->isRequest()); 221512725Snikos.nikoleris@arm.com 221612725Snikos.nikoleris@arm.com if (cache->system->bypassCaches()) { 221712725Snikos.nikoleris@arm.com // Just forward the packet if caches are disabled. 221812725Snikos.nikoleris@arm.com // @todo This should really enqueue the packet rather 221912725Snikos.nikoleris@arm.com bool M5_VAR_USED success = cache->memSidePort.sendTimingReq(pkt); 222012725Snikos.nikoleris@arm.com assert(success); 222112725Snikos.nikoleris@arm.com return true; 222212725Snikos.nikoleris@arm.com } else if (tryTiming(pkt)) { 222312724Snikos.nikoleris@arm.com cache->recvTimingReq(pkt); 222412724Snikos.nikoleris@arm.com return true; 222512724Snikos.nikoleris@arm.com } 222612724Snikos.nikoleris@arm.com return false; 222712724Snikos.nikoleris@arm.com} 222812724Snikos.nikoleris@arm.com 222912724Snikos.nikoleris@arm.comTick 223012724Snikos.nikoleris@arm.comBaseCache::CpuSidePort::recvAtomic(PacketPtr pkt) 223112724Snikos.nikoleris@arm.com{ 223212725Snikos.nikoleris@arm.com if (cache->system->bypassCaches()) { 223312725Snikos.nikoleris@arm.com // Forward the request if the system is in cache bypass mode. 223412725Snikos.nikoleris@arm.com return cache->memSidePort.sendAtomic(pkt); 223512725Snikos.nikoleris@arm.com } else { 223612725Snikos.nikoleris@arm.com return cache->recvAtomic(pkt); 223712725Snikos.nikoleris@arm.com } 223812724Snikos.nikoleris@arm.com} 223912724Snikos.nikoleris@arm.com 224012724Snikos.nikoleris@arm.comvoid 224112724Snikos.nikoleris@arm.comBaseCache::CpuSidePort::recvFunctional(PacketPtr pkt) 224212724Snikos.nikoleris@arm.com{ 224312725Snikos.nikoleris@arm.com if (cache->system->bypassCaches()) { 224412725Snikos.nikoleris@arm.com // The cache should be flushed if we are in cache bypass mode, 224512725Snikos.nikoleris@arm.com // so we don't need to check if we need to update anything. 224612725Snikos.nikoleris@arm.com cache->memSidePort.sendFunctional(pkt); 224712725Snikos.nikoleris@arm.com return; 224812725Snikos.nikoleris@arm.com } 224912725Snikos.nikoleris@arm.com 225012724Snikos.nikoleris@arm.com // functional request 225112724Snikos.nikoleris@arm.com cache->functionalAccess(pkt, true); 225212724Snikos.nikoleris@arm.com} 225312724Snikos.nikoleris@arm.com 225412724Snikos.nikoleris@arm.comAddrRangeList 225512724Snikos.nikoleris@arm.comBaseCache::CpuSidePort::getAddrRanges() const 225612724Snikos.nikoleris@arm.com{ 225712724Snikos.nikoleris@arm.com return cache->getAddrRanges(); 225812724Snikos.nikoleris@arm.com} 225912724Snikos.nikoleris@arm.com 226012724Snikos.nikoleris@arm.com 226112724Snikos.nikoleris@arm.comBaseCache:: 226212724Snikos.nikoleris@arm.comCpuSidePort::CpuSidePort(const std::string &_name, BaseCache *_cache, 226312724Snikos.nikoleris@arm.com const std::string &_label) 226412724Snikos.nikoleris@arm.com : CacheSlavePort(_name, _cache, _label), cache(_cache) 226512724Snikos.nikoleris@arm.com{ 226612724Snikos.nikoleris@arm.com} 226712724Snikos.nikoleris@arm.com 226812724Snikos.nikoleris@arm.com/////////////// 226912724Snikos.nikoleris@arm.com// 227012724Snikos.nikoleris@arm.com// MemSidePort 227112724Snikos.nikoleris@arm.com// 227212724Snikos.nikoleris@arm.com/////////////// 227312724Snikos.nikoleris@arm.combool 227412724Snikos.nikoleris@arm.comBaseCache::MemSidePort::recvTimingResp(PacketPtr pkt) 227512724Snikos.nikoleris@arm.com{ 227612724Snikos.nikoleris@arm.com cache->recvTimingResp(pkt); 227712724Snikos.nikoleris@arm.com return true; 227812724Snikos.nikoleris@arm.com} 227912724Snikos.nikoleris@arm.com 228012724Snikos.nikoleris@arm.com// Express snooping requests to memside port 228112724Snikos.nikoleris@arm.comvoid 228212724Snikos.nikoleris@arm.comBaseCache::MemSidePort::recvTimingSnoopReq(PacketPtr pkt) 228312724Snikos.nikoleris@arm.com{ 228412725Snikos.nikoleris@arm.com // Snoops shouldn't happen when bypassing caches 228512725Snikos.nikoleris@arm.com assert(!cache->system->bypassCaches()); 228612725Snikos.nikoleris@arm.com 228712724Snikos.nikoleris@arm.com // handle snooping requests 228812724Snikos.nikoleris@arm.com cache->recvTimingSnoopReq(pkt); 228912724Snikos.nikoleris@arm.com} 229012724Snikos.nikoleris@arm.com 229112724Snikos.nikoleris@arm.comTick 229212724Snikos.nikoleris@arm.comBaseCache::MemSidePort::recvAtomicSnoop(PacketPtr pkt) 229312724Snikos.nikoleris@arm.com{ 229412725Snikos.nikoleris@arm.com // Snoops shouldn't happen when bypassing caches 229512725Snikos.nikoleris@arm.com assert(!cache->system->bypassCaches()); 229612725Snikos.nikoleris@arm.com 229712724Snikos.nikoleris@arm.com return cache->recvAtomicSnoop(pkt); 229812724Snikos.nikoleris@arm.com} 229912724Snikos.nikoleris@arm.com 230012724Snikos.nikoleris@arm.comvoid 230112724Snikos.nikoleris@arm.comBaseCache::MemSidePort::recvFunctionalSnoop(PacketPtr pkt) 230212724Snikos.nikoleris@arm.com{ 230312725Snikos.nikoleris@arm.com // Snoops shouldn't happen when bypassing caches 230412725Snikos.nikoleris@arm.com assert(!cache->system->bypassCaches()); 230512725Snikos.nikoleris@arm.com 230612724Snikos.nikoleris@arm.com // functional snoop (note that in contrast to atomic we don't have 230712724Snikos.nikoleris@arm.com // a specific functionalSnoop method, as they have the same 230812724Snikos.nikoleris@arm.com // behaviour regardless) 230912724Snikos.nikoleris@arm.com cache->functionalAccess(pkt, false); 231012724Snikos.nikoleris@arm.com} 231112724Snikos.nikoleris@arm.com 231212724Snikos.nikoleris@arm.comvoid 231312724Snikos.nikoleris@arm.comBaseCache::CacheReqPacketQueue::sendDeferredPacket() 231412724Snikos.nikoleris@arm.com{ 231512724Snikos.nikoleris@arm.com // sanity check 231612724Snikos.nikoleris@arm.com assert(!waitingOnRetry); 231712724Snikos.nikoleris@arm.com 231812724Snikos.nikoleris@arm.com // there should never be any deferred request packets in the 231912724Snikos.nikoleris@arm.com // queue, instead we resly on the cache to provide the packets 232012724Snikos.nikoleris@arm.com // from the MSHR queue or write queue 232112724Snikos.nikoleris@arm.com assert(deferredPacketReadyTime() == MaxTick); 232212724Snikos.nikoleris@arm.com 232312724Snikos.nikoleris@arm.com // check for request packets (requests & writebacks) 232412724Snikos.nikoleris@arm.com QueueEntry* entry = cache.getNextQueueEntry(); 232512724Snikos.nikoleris@arm.com 232612724Snikos.nikoleris@arm.com if (!entry) { 232712724Snikos.nikoleris@arm.com // can happen if e.g. we attempt a writeback and fail, but 232812724Snikos.nikoleris@arm.com // before the retry, the writeback is eliminated because 232912724Snikos.nikoleris@arm.com // we snoop another cache's ReadEx. 233012724Snikos.nikoleris@arm.com } else { 233112724Snikos.nikoleris@arm.com // let our snoop responses go first if there are responses to 233212724Snikos.nikoleris@arm.com // the same addresses 233312724Snikos.nikoleris@arm.com if (checkConflictingSnoop(entry->blkAddr)) { 233412724Snikos.nikoleris@arm.com return; 233512724Snikos.nikoleris@arm.com } 233612724Snikos.nikoleris@arm.com waitingOnRetry = entry->sendPacket(cache); 233712724Snikos.nikoleris@arm.com } 233812724Snikos.nikoleris@arm.com 233912724Snikos.nikoleris@arm.com // if we succeeded and are not waiting for a retry, schedule the 234012724Snikos.nikoleris@arm.com // next send considering when the next queue is ready, note that 234112724Snikos.nikoleris@arm.com // snoop responses have their own packet queue and thus schedule 234212724Snikos.nikoleris@arm.com // their own events 234312724Snikos.nikoleris@arm.com if (!waitingOnRetry) { 234412724Snikos.nikoleris@arm.com schedSendEvent(cache.nextQueueReadyTime()); 234512724Snikos.nikoleris@arm.com } 234612724Snikos.nikoleris@arm.com} 234712724Snikos.nikoleris@arm.com 234812724Snikos.nikoleris@arm.comBaseCache::MemSidePort::MemSidePort(const std::string &_name, 234912724Snikos.nikoleris@arm.com BaseCache *_cache, 235012724Snikos.nikoleris@arm.com const std::string &_label) 235112724Snikos.nikoleris@arm.com : CacheMasterPort(_name, _cache, _reqQueue, _snoopRespQueue), 235212724Snikos.nikoleris@arm.com _reqQueue(*_cache, *this, _snoopRespQueue, _label), 235312724Snikos.nikoleris@arm.com _snoopRespQueue(*_cache, *this, _label), cache(_cache) 235412724Snikos.nikoleris@arm.com{ 235512724Snikos.nikoleris@arm.com} 2356