base.hh revision 13352
12810SN/A/* 212724Snikos.nikoleris@arm.com * Copyright (c) 2012-2013, 2015-2016, 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 414458SN/A * Steve Reinhardt 424458SN/A * Ron Dreslinski 4312724Snikos.nikoleris@arm.com * Andreas Hansson 4412724Snikos.nikoleris@arm.com * Nikos Nikoleris 452810SN/A */ 462810SN/A 472810SN/A/** 482810SN/A * @file 492810SN/A * Declares a basic cache interface BaseCache. 502810SN/A */ 512810SN/A 5211051Sandreas.hansson@arm.com#ifndef __MEM_CACHE_BASE_HH__ 5311051Sandreas.hansson@arm.com#define __MEM_CACHE_BASE_HH__ 542810SN/A 5512724Snikos.nikoleris@arm.com#include <cassert> 5612724Snikos.nikoleris@arm.com#include <cstdint> 577676Snate@binkert.org#include <string> 582810SN/A 5912724Snikos.nikoleris@arm.com#include "base/addr_range.hh" 602810SN/A#include "base/statistics.hh" 612810SN/A#include "base/trace.hh" 626215Snate@binkert.org#include "base/types.hh" 638232Snate@binkert.org#include "debug/Cache.hh" 648232Snate@binkert.org#include "debug/CachePort.hh" 6512724Snikos.nikoleris@arm.com#include "enums/Clusivity.hh" 6613223Sodanrc@yahoo.com.br#include "mem/cache/cache_blk.hh" 675338Sstever@gmail.com#include "mem/cache/mshr_queue.hh" 6812724Snikos.nikoleris@arm.com#include "mem/cache/tags/base.hh" 6911375Sandreas.hansson@arm.com#include "mem/cache/write_queue.hh" 7012724Snikos.nikoleris@arm.com#include "mem/cache/write_queue_entry.hh" 712810SN/A#include "mem/mem_object.hh" 722810SN/A#include "mem/packet.hh" 7312724Snikos.nikoleris@arm.com#include "mem/packet_queue.hh" 748914Sandreas.hansson@arm.com#include "mem/qport.hh" 758229Snate@binkert.org#include "mem/request.hh" 7613352Snikos.nikoleris@arm.com#include "params/WriteAllocator.hh" 772811SN/A#include "sim/eventq.hh" 7812724Snikos.nikoleris@arm.com#include "sim/serialize.hh" 794626SN/A#include "sim/sim_exit.hh" 808833Sdam.sunwoo@arm.com#include "sim/system.hh" 812810SN/A 8212724Snikos.nikoleris@arm.comclass BaseMasterPort; 8312724Snikos.nikoleris@arm.comclass BasePrefetcher; 8412724Snikos.nikoleris@arm.comclass BaseSlavePort; 8512724Snikos.nikoleris@arm.comclass MSHR; 8612724Snikos.nikoleris@arm.comclass MasterPort; 8712724Snikos.nikoleris@arm.comclass QueueEntry; 8812724Snikos.nikoleris@arm.comstruct BaseCacheParams; 8912724Snikos.nikoleris@arm.com 902810SN/A/** 912810SN/A * A basic cache interface. Implements some common functions for speed. 922810SN/A */ 932810SN/Aclass BaseCache : public MemObject 942810SN/A{ 9511375Sandreas.hansson@arm.com protected: 964628SN/A /** 974628SN/A * Indexes to enumerate the MSHR queues. 984628SN/A */ 994628SN/A enum MSHRQueueIndex { 1004628SN/A MSHRQueue_MSHRs, 1014628SN/A MSHRQueue_WriteBuffer 1024628SN/A }; 1034628SN/A 1048737Skoansin.tan@gmail.com public: 1054628SN/A /** 1064628SN/A * Reasons for caches to be blocked. 1074628SN/A */ 1084628SN/A enum BlockedCause { 1094628SN/A Blocked_NoMSHRs = MSHRQueue_MSHRs, 1104628SN/A Blocked_NoWBBuffers = MSHRQueue_WriteBuffer, 1114628SN/A Blocked_NoTargets, 1124628SN/A NUM_BLOCKED_CAUSES 1134628SN/A }; 1144628SN/A 1158737Skoansin.tan@gmail.com protected: 1164628SN/A 1178856Sandreas.hansson@arm.com /** 1188856Sandreas.hansson@arm.com * A cache master port is used for the memory-side port of the 1198856Sandreas.hansson@arm.com * cache, and in addition to the basic timing port that only sends 1208856Sandreas.hansson@arm.com * response packets through a transmit list, it also offers the 1218856Sandreas.hansson@arm.com * ability to schedule and send request packets (requests & 12210942Sandreas.hansson@arm.com * writebacks). The send event is scheduled through schedSendEvent, 1238856Sandreas.hansson@arm.com * and the sendDeferredPacket of the timing port is modified to 1248856Sandreas.hansson@arm.com * consider both the transmit list and the requests from the MSHR. 1258856Sandreas.hansson@arm.com */ 1268922Swilliam.wang@arm.com class CacheMasterPort : public QueuedMasterPort 1272810SN/A { 1288856Sandreas.hansson@arm.com 1292844SN/A public: 1308856Sandreas.hansson@arm.com 1318856Sandreas.hansson@arm.com /** 1328856Sandreas.hansson@arm.com * Schedule a send of a request packet (from the MSHR). Note 13310713Sandreas.hansson@arm.com * that we could already have a retry outstanding. 1348856Sandreas.hansson@arm.com */ 13510942Sandreas.hansson@arm.com void schedSendEvent(Tick time) 1368856Sandreas.hansson@arm.com { 13710942Sandreas.hansson@arm.com DPRINTF(CachePort, "Scheduling send event at %llu\n", time); 13810713Sandreas.hansson@arm.com reqQueue.schedSendEvent(time); 1398856Sandreas.hansson@arm.com } 1408856Sandreas.hansson@arm.com 1413738SN/A protected: 1424458SN/A 1438856Sandreas.hansson@arm.com CacheMasterPort(const std::string &_name, BaseCache *_cache, 14410713Sandreas.hansson@arm.com ReqPacketQueue &_reqQueue, 14510713Sandreas.hansson@arm.com SnoopRespPacketQueue &_snoopRespQueue) : 14610713Sandreas.hansson@arm.com QueuedMasterPort(_name, _cache, _reqQueue, _snoopRespQueue) 1478914Sandreas.hansson@arm.com { } 1482810SN/A 1498856Sandreas.hansson@arm.com /** 1508856Sandreas.hansson@arm.com * Memory-side port always snoops. 1518856Sandreas.hansson@arm.com * 1528914Sandreas.hansson@arm.com * @return always true 1538856Sandreas.hansson@arm.com */ 1548922Swilliam.wang@arm.com virtual bool isSnooping() const { return true; } 1558856Sandreas.hansson@arm.com }; 1563013SN/A 1578856Sandreas.hansson@arm.com /** 15812724Snikos.nikoleris@arm.com * Override the default behaviour of sendDeferredPacket to enable 15912724Snikos.nikoleris@arm.com * the memory-side cache port to also send requests based on the 16012724Snikos.nikoleris@arm.com * current MSHR status. This queue has a pointer to our specific 16112724Snikos.nikoleris@arm.com * cache implementation and is used by the MemSidePort. 16212724Snikos.nikoleris@arm.com */ 16312724Snikos.nikoleris@arm.com class CacheReqPacketQueue : public ReqPacketQueue 16412724Snikos.nikoleris@arm.com { 16512724Snikos.nikoleris@arm.com 16612724Snikos.nikoleris@arm.com protected: 16712724Snikos.nikoleris@arm.com 16812724Snikos.nikoleris@arm.com BaseCache &cache; 16912724Snikos.nikoleris@arm.com SnoopRespPacketQueue &snoopRespQueue; 17012724Snikos.nikoleris@arm.com 17112724Snikos.nikoleris@arm.com public: 17212724Snikos.nikoleris@arm.com 17312724Snikos.nikoleris@arm.com CacheReqPacketQueue(BaseCache &cache, MasterPort &port, 17412724Snikos.nikoleris@arm.com SnoopRespPacketQueue &snoop_resp_queue, 17512724Snikos.nikoleris@arm.com const std::string &label) : 17612724Snikos.nikoleris@arm.com ReqPacketQueue(cache, port, label), cache(cache), 17712724Snikos.nikoleris@arm.com snoopRespQueue(snoop_resp_queue) { } 17812724Snikos.nikoleris@arm.com 17912724Snikos.nikoleris@arm.com /** 18012724Snikos.nikoleris@arm.com * Override the normal sendDeferredPacket and do not only 18112724Snikos.nikoleris@arm.com * consider the transmit list (used for responses), but also 18212724Snikos.nikoleris@arm.com * requests. 18312724Snikos.nikoleris@arm.com */ 18412724Snikos.nikoleris@arm.com virtual void sendDeferredPacket(); 18512724Snikos.nikoleris@arm.com 18612724Snikos.nikoleris@arm.com /** 18712724Snikos.nikoleris@arm.com * Check if there is a conflicting snoop response about to be 18812724Snikos.nikoleris@arm.com * send out, and if so simply stall any requests, and schedule 18912724Snikos.nikoleris@arm.com * a send event at the same time as the next snoop response is 19012724Snikos.nikoleris@arm.com * being sent out. 19112724Snikos.nikoleris@arm.com */ 19212724Snikos.nikoleris@arm.com bool checkConflictingSnoop(Addr addr) 19312724Snikos.nikoleris@arm.com { 19412724Snikos.nikoleris@arm.com if (snoopRespQueue.hasAddr(addr)) { 19512724Snikos.nikoleris@arm.com DPRINTF(CachePort, "Waiting for snoop response to be " 19612724Snikos.nikoleris@arm.com "sent\n"); 19712724Snikos.nikoleris@arm.com Tick when = snoopRespQueue.deferredPacketReadyTime(); 19812724Snikos.nikoleris@arm.com schedSendEvent(when); 19912724Snikos.nikoleris@arm.com return true; 20012724Snikos.nikoleris@arm.com } 20112724Snikos.nikoleris@arm.com return false; 20212724Snikos.nikoleris@arm.com } 20312724Snikos.nikoleris@arm.com }; 20412724Snikos.nikoleris@arm.com 20512724Snikos.nikoleris@arm.com 20612724Snikos.nikoleris@arm.com /** 20712724Snikos.nikoleris@arm.com * The memory-side port extends the base cache master port with 20812724Snikos.nikoleris@arm.com * access functions for functional, atomic and timing snoops. 20912724Snikos.nikoleris@arm.com */ 21012724Snikos.nikoleris@arm.com class MemSidePort : public CacheMasterPort 21112724Snikos.nikoleris@arm.com { 21212724Snikos.nikoleris@arm.com private: 21312724Snikos.nikoleris@arm.com 21412724Snikos.nikoleris@arm.com /** The cache-specific queue. */ 21512724Snikos.nikoleris@arm.com CacheReqPacketQueue _reqQueue; 21612724Snikos.nikoleris@arm.com 21712724Snikos.nikoleris@arm.com SnoopRespPacketQueue _snoopRespQueue; 21812724Snikos.nikoleris@arm.com 21912724Snikos.nikoleris@arm.com // a pointer to our specific cache implementation 22012724Snikos.nikoleris@arm.com BaseCache *cache; 22112724Snikos.nikoleris@arm.com 22212724Snikos.nikoleris@arm.com protected: 22312724Snikos.nikoleris@arm.com 22412724Snikos.nikoleris@arm.com virtual void recvTimingSnoopReq(PacketPtr pkt); 22512724Snikos.nikoleris@arm.com 22612724Snikos.nikoleris@arm.com virtual bool recvTimingResp(PacketPtr pkt); 22712724Snikos.nikoleris@arm.com 22812724Snikos.nikoleris@arm.com virtual Tick recvAtomicSnoop(PacketPtr pkt); 22912724Snikos.nikoleris@arm.com 23012724Snikos.nikoleris@arm.com virtual void recvFunctionalSnoop(PacketPtr pkt); 23112724Snikos.nikoleris@arm.com 23212724Snikos.nikoleris@arm.com public: 23312724Snikos.nikoleris@arm.com 23412724Snikos.nikoleris@arm.com MemSidePort(const std::string &_name, BaseCache *_cache, 23512724Snikos.nikoleris@arm.com const std::string &_label); 23612724Snikos.nikoleris@arm.com }; 23712724Snikos.nikoleris@arm.com 23812724Snikos.nikoleris@arm.com /** 2398856Sandreas.hansson@arm.com * A cache slave port is used for the CPU-side port of the cache, 2408856Sandreas.hansson@arm.com * and it is basically a simple timing port that uses a transmit 2418856Sandreas.hansson@arm.com * list for responses to the CPU (or connected master). In 2428856Sandreas.hansson@arm.com * addition, it has the functionality to block the port for 2438856Sandreas.hansson@arm.com * incoming requests. If blocked, the port will issue a retry once 2448856Sandreas.hansson@arm.com * unblocked. 2458856Sandreas.hansson@arm.com */ 2468922Swilliam.wang@arm.com class CacheSlavePort : public QueuedSlavePort 2478856Sandreas.hansson@arm.com { 2485314SN/A 2492811SN/A public: 2508856Sandreas.hansson@arm.com 2518856Sandreas.hansson@arm.com /** Do not accept any new requests. */ 2522810SN/A void setBlocked(); 2532810SN/A 2548856Sandreas.hansson@arm.com /** Return to normal operation and accept new requests. */ 2552810SN/A void clearBlocked(); 2562810SN/A 25710345SCurtis.Dunham@arm.com bool isBlocked() const { return blocked; } 25810345SCurtis.Dunham@arm.com 2598856Sandreas.hansson@arm.com protected: 2608856Sandreas.hansson@arm.com 2618856Sandreas.hansson@arm.com CacheSlavePort(const std::string &_name, BaseCache *_cache, 2628856Sandreas.hansson@arm.com const std::string &_label); 2633606SN/A 2648914Sandreas.hansson@arm.com /** A normal packet queue used to store responses. */ 26510713Sandreas.hansson@arm.com RespPacketQueue queue; 2668914Sandreas.hansson@arm.com 2672810SN/A bool blocked; 2682810SN/A 2692897SN/A bool mustSendRetry; 2702897SN/A 2718856Sandreas.hansson@arm.com private: 2724458SN/A 27310344Sandreas.hansson@arm.com void processSendRetry(); 27410344Sandreas.hansson@arm.com 27512084Sspwilson2@wisc.edu EventFunctionWrapper sendRetryEvent; 2768856Sandreas.hansson@arm.com 2772811SN/A }; 2782810SN/A 27912724Snikos.nikoleris@arm.com /** 28012724Snikos.nikoleris@arm.com * The CPU-side port extends the base cache slave port with access 28112724Snikos.nikoleris@arm.com * functions for functional, atomic and timing requests. 28212724Snikos.nikoleris@arm.com */ 28312724Snikos.nikoleris@arm.com class CpuSidePort : public CacheSlavePort 28412724Snikos.nikoleris@arm.com { 28512724Snikos.nikoleris@arm.com private: 28612724Snikos.nikoleris@arm.com 28712724Snikos.nikoleris@arm.com // a pointer to our specific cache implementation 28812724Snikos.nikoleris@arm.com BaseCache *cache; 28912724Snikos.nikoleris@arm.com 29012724Snikos.nikoleris@arm.com protected: 29112724Snikos.nikoleris@arm.com virtual bool recvTimingSnoopResp(PacketPtr pkt) override; 29212724Snikos.nikoleris@arm.com 29312724Snikos.nikoleris@arm.com virtual bool tryTiming(PacketPtr pkt) override; 29412724Snikos.nikoleris@arm.com 29512724Snikos.nikoleris@arm.com virtual bool recvTimingReq(PacketPtr pkt) override; 29612724Snikos.nikoleris@arm.com 29712724Snikos.nikoleris@arm.com virtual Tick recvAtomic(PacketPtr pkt) override; 29812724Snikos.nikoleris@arm.com 29912724Snikos.nikoleris@arm.com virtual void recvFunctional(PacketPtr pkt) override; 30012724Snikos.nikoleris@arm.com 30112724Snikos.nikoleris@arm.com virtual AddrRangeList getAddrRanges() const override; 30212724Snikos.nikoleris@arm.com 30312724Snikos.nikoleris@arm.com public: 30412724Snikos.nikoleris@arm.com 30512724Snikos.nikoleris@arm.com CpuSidePort(const std::string &_name, BaseCache *_cache, 30612724Snikos.nikoleris@arm.com const std::string &_label); 30712724Snikos.nikoleris@arm.com 30812724Snikos.nikoleris@arm.com }; 30912724Snikos.nikoleris@arm.com 31012724Snikos.nikoleris@arm.com CpuSidePort cpuSidePort; 31112724Snikos.nikoleris@arm.com MemSidePort memSidePort; 3123338SN/A 3134626SN/A protected: 3144626SN/A 3154626SN/A /** Miss status registers */ 3164626SN/A MSHRQueue mshrQueue; 3174626SN/A 3184626SN/A /** Write/writeback buffer */ 31911375Sandreas.hansson@arm.com WriteQueue writeBuffer; 3204626SN/A 32112724Snikos.nikoleris@arm.com /** Tag and data Storage */ 32212724Snikos.nikoleris@arm.com BaseTags *tags; 32312724Snikos.nikoleris@arm.com 32412724Snikos.nikoleris@arm.com /** Prefetcher */ 32512724Snikos.nikoleris@arm.com BasePrefetcher *prefetcher; 32612724Snikos.nikoleris@arm.com 32712724Snikos.nikoleris@arm.com /** 32812724Snikos.nikoleris@arm.com * Notify the prefetcher on every access, not just misses. 32912724Snikos.nikoleris@arm.com */ 33012724Snikos.nikoleris@arm.com const bool prefetchOnAccess; 33112724Snikos.nikoleris@arm.com 33212724Snikos.nikoleris@arm.com /** 33313352Snikos.nikoleris@arm.com * The writeAllocator drive optimizations for streaming writes. 33413352Snikos.nikoleris@arm.com * It first determines whether a WriteReq MSHR should be delayed, 33513352Snikos.nikoleris@arm.com * thus ensuring that we wait longer in cases when we are write 33613352Snikos.nikoleris@arm.com * coalescing and allowing all the bytes of the line to be written 33713352Snikos.nikoleris@arm.com * before the MSHR packet is sent downstream. This works in unison 33813352Snikos.nikoleris@arm.com * with the tracking in the MSHR to check if the entire line is 33913352Snikos.nikoleris@arm.com * written. The write mode also affects the behaviour on filling 34013352Snikos.nikoleris@arm.com * any whole-line writes. Normally the cache allocates the line 34113352Snikos.nikoleris@arm.com * when receiving the InvalidateResp, but after seeing enough 34213352Snikos.nikoleris@arm.com * consecutive lines we switch to using the tempBlock, and thus 34313352Snikos.nikoleris@arm.com * end up not allocating the line, and instead turning the 34413352Snikos.nikoleris@arm.com * whole-line write into a writeback straight away. 34513352Snikos.nikoleris@arm.com */ 34613352Snikos.nikoleris@arm.com WriteAllocator * const writeAllocator; 34713352Snikos.nikoleris@arm.com 34813352Snikos.nikoleris@arm.com /** 34912724Snikos.nikoleris@arm.com * Temporary cache block for occasional transitory use. We use 35012724Snikos.nikoleris@arm.com * the tempBlock to fill when allocation fails (e.g., when there 35112724Snikos.nikoleris@arm.com * is an outstanding request that accesses the victim block) or 35212724Snikos.nikoleris@arm.com * when we want to avoid allocation (e.g., exclusive caches) 35312724Snikos.nikoleris@arm.com */ 35412730Sodanrc@yahoo.com.br TempCacheBlk *tempBlock; 35512724Snikos.nikoleris@arm.com 35612724Snikos.nikoleris@arm.com /** 35712724Snikos.nikoleris@arm.com * Upstream caches need this packet until true is returned, so 35812724Snikos.nikoleris@arm.com * hold it for deletion until a subsequent call 35912724Snikos.nikoleris@arm.com */ 36012724Snikos.nikoleris@arm.com std::unique_ptr<Packet> pendingDelete; 36112724Snikos.nikoleris@arm.com 36210693SMarco.Balboni@ARM.com /** 36311375Sandreas.hansson@arm.com * Mark a request as in service (sent downstream in the memory 36411375Sandreas.hansson@arm.com * system), effectively making this MSHR the ordering point. 36510693SMarco.Balboni@ARM.com */ 36611375Sandreas.hansson@arm.com void markInService(MSHR *mshr, bool pending_modified_resp) 3674628SN/A { 36811375Sandreas.hansson@arm.com bool wasFull = mshrQueue.isFull(); 36911375Sandreas.hansson@arm.com mshrQueue.markInService(mshr, pending_modified_resp); 37010764Sandreas.hansson@arm.com 37111375Sandreas.hansson@arm.com if (wasFull && !mshrQueue.isFull()) { 37211375Sandreas.hansson@arm.com clearBlocked(Blocked_NoMSHRs); 3734628SN/A } 3744628SN/A } 3754628SN/A 37611375Sandreas.hansson@arm.com void markInService(WriteQueueEntry *entry) 3774628SN/A { 37811375Sandreas.hansson@arm.com bool wasFull = writeBuffer.isFull(); 37911375Sandreas.hansson@arm.com writeBuffer.markInService(entry); 38011375Sandreas.hansson@arm.com 38111375Sandreas.hansson@arm.com if (wasFull && !writeBuffer.isFull()) { 38211375Sandreas.hansson@arm.com clearBlocked(Blocked_NoWBBuffers); 3834628SN/A } 3844628SN/A } 3854628SN/A 3869347SAndreas.Sandberg@arm.com /** 38712724Snikos.nikoleris@arm.com * Determine whether we should allocate on a fill or not. If this 38812724Snikos.nikoleris@arm.com * cache is mostly inclusive with regards to the upstream cache(s) 38912724Snikos.nikoleris@arm.com * we always allocate (for any non-forwarded and cacheable 39012724Snikos.nikoleris@arm.com * requests). In the case of a mostly exclusive cache, we allocate 39112724Snikos.nikoleris@arm.com * on fill if the packet did not come from a cache, thus if we: 39212724Snikos.nikoleris@arm.com * are dealing with a whole-line write (the latter behaves much 39312724Snikos.nikoleris@arm.com * like a writeback), the original target packet came from a 39412724Snikos.nikoleris@arm.com * non-caching source, or if we are performing a prefetch or LLSC. 39511197Sandreas.hansson@arm.com * 39612724Snikos.nikoleris@arm.com * @param cmd Command of the incoming requesting packet 39712724Snikos.nikoleris@arm.com * @return Whether we should allocate on the fill 39812724Snikos.nikoleris@arm.com */ 39912724Snikos.nikoleris@arm.com inline bool allocOnFill(MemCmd cmd) const 40012724Snikos.nikoleris@arm.com { 40112724Snikos.nikoleris@arm.com return clusivity == Enums::mostly_incl || 40212724Snikos.nikoleris@arm.com cmd == MemCmd::WriteLineReq || 40312724Snikos.nikoleris@arm.com cmd == MemCmd::ReadReq || 40412724Snikos.nikoleris@arm.com cmd == MemCmd::WriteReq || 40512724Snikos.nikoleris@arm.com cmd.isPrefetch() || 40612724Snikos.nikoleris@arm.com cmd.isLLSC(); 40712724Snikos.nikoleris@arm.com } 40812724Snikos.nikoleris@arm.com 40912724Snikos.nikoleris@arm.com /** 41012730Sodanrc@yahoo.com.br * Regenerate block address using tags. 41112730Sodanrc@yahoo.com.br * Block address regeneration depends on whether we're using a temporary 41212730Sodanrc@yahoo.com.br * block or not. 41312730Sodanrc@yahoo.com.br * 41412730Sodanrc@yahoo.com.br * @param blk The block to regenerate address. 41512730Sodanrc@yahoo.com.br * @return The block's address. 41612730Sodanrc@yahoo.com.br */ 41712730Sodanrc@yahoo.com.br Addr regenerateBlkAddr(CacheBlk* blk); 41812730Sodanrc@yahoo.com.br 41912730Sodanrc@yahoo.com.br /** 42012724Snikos.nikoleris@arm.com * Does all the processing necessary to perform the provided request. 42112724Snikos.nikoleris@arm.com * @param pkt The memory request to perform. 42212724Snikos.nikoleris@arm.com * @param blk The cache block to be updated. 42312724Snikos.nikoleris@arm.com * @param lat The latency of the access. 42412724Snikos.nikoleris@arm.com * @param writebacks List for any writebacks that need to be performed. 42512724Snikos.nikoleris@arm.com * @return Boolean indicating whether the request was satisfied. 42612724Snikos.nikoleris@arm.com */ 42712724Snikos.nikoleris@arm.com virtual bool access(PacketPtr pkt, CacheBlk *&blk, Cycles &lat, 42812724Snikos.nikoleris@arm.com PacketList &writebacks); 42912724Snikos.nikoleris@arm.com 43012724Snikos.nikoleris@arm.com /* 43112724Snikos.nikoleris@arm.com * Handle a timing request that hit in the cache 43211197Sandreas.hansson@arm.com * 43312724Snikos.nikoleris@arm.com * @param ptk The request packet 43412724Snikos.nikoleris@arm.com * @param blk The referenced block 43512724Snikos.nikoleris@arm.com * @param request_time The tick at which the block lookup is compete 43611197Sandreas.hansson@arm.com */ 43712724Snikos.nikoleris@arm.com virtual void handleTimingReqHit(PacketPtr pkt, CacheBlk *blk, 43812724Snikos.nikoleris@arm.com Tick request_time); 43912724Snikos.nikoleris@arm.com 44012724Snikos.nikoleris@arm.com /* 44112724Snikos.nikoleris@arm.com * Handle a timing request that missed in the cache 44212724Snikos.nikoleris@arm.com * 44312724Snikos.nikoleris@arm.com * Implementation specific handling for different cache 44412724Snikos.nikoleris@arm.com * implementations 44512724Snikos.nikoleris@arm.com * 44612724Snikos.nikoleris@arm.com * @param ptk The request packet 44712724Snikos.nikoleris@arm.com * @param blk The referenced block 44812724Snikos.nikoleris@arm.com * @param forward_time The tick at which we can process dependent requests 44912724Snikos.nikoleris@arm.com * @param request_time The tick at which the block lookup is compete 45012724Snikos.nikoleris@arm.com */ 45112724Snikos.nikoleris@arm.com virtual void handleTimingReqMiss(PacketPtr pkt, CacheBlk *blk, 45212724Snikos.nikoleris@arm.com Tick forward_time, 45312724Snikos.nikoleris@arm.com Tick request_time) = 0; 45412724Snikos.nikoleris@arm.com 45512724Snikos.nikoleris@arm.com /* 45612724Snikos.nikoleris@arm.com * Handle a timing request that missed in the cache 45712724Snikos.nikoleris@arm.com * 45812724Snikos.nikoleris@arm.com * Common functionality across different cache implementations 45912724Snikos.nikoleris@arm.com * 46012724Snikos.nikoleris@arm.com * @param ptk The request packet 46112724Snikos.nikoleris@arm.com * @param blk The referenced block 46212724Snikos.nikoleris@arm.com * @param mshr Any existing mshr for the referenced cache block 46312724Snikos.nikoleris@arm.com * @param forward_time The tick at which we can process dependent requests 46412724Snikos.nikoleris@arm.com * @param request_time The tick at which the block lookup is compete 46512724Snikos.nikoleris@arm.com */ 46612724Snikos.nikoleris@arm.com void handleTimingReqMiss(PacketPtr pkt, MSHR *mshr, CacheBlk *blk, 46712724Snikos.nikoleris@arm.com Tick forward_time, Tick request_time); 46812724Snikos.nikoleris@arm.com 46912724Snikos.nikoleris@arm.com /** 47012724Snikos.nikoleris@arm.com * Performs the access specified by the request. 47112724Snikos.nikoleris@arm.com * @param pkt The request to perform. 47212724Snikos.nikoleris@arm.com */ 47312724Snikos.nikoleris@arm.com virtual void recvTimingReq(PacketPtr pkt); 47412724Snikos.nikoleris@arm.com 47512724Snikos.nikoleris@arm.com /** 47612724Snikos.nikoleris@arm.com * Handling the special case of uncacheable write responses to 47712724Snikos.nikoleris@arm.com * make recvTimingResp less cluttered. 47812724Snikos.nikoleris@arm.com */ 47912724Snikos.nikoleris@arm.com void handleUncacheableWriteResp(PacketPtr pkt); 48012724Snikos.nikoleris@arm.com 48112724Snikos.nikoleris@arm.com /** 48212724Snikos.nikoleris@arm.com * Service non-deferred MSHR targets using the received response 48312724Snikos.nikoleris@arm.com * 48412724Snikos.nikoleris@arm.com * Iterates through the list of targets that can be serviced with 48512724Snikos.nikoleris@arm.com * the current response. Any writebacks that need to performed 48612724Snikos.nikoleris@arm.com * must be appended to the writebacks parameter. 48712724Snikos.nikoleris@arm.com * 48812724Snikos.nikoleris@arm.com * @param mshr The MSHR that corresponds to the reponse 48912724Snikos.nikoleris@arm.com * @param pkt The response packet 49012724Snikos.nikoleris@arm.com * @param blk The reference block 49112724Snikos.nikoleris@arm.com * @param writebacks List of writebacks that need to be performed 49212724Snikos.nikoleris@arm.com */ 49312724Snikos.nikoleris@arm.com virtual void serviceMSHRTargets(MSHR *mshr, const PacketPtr pkt, 49412724Snikos.nikoleris@arm.com CacheBlk *blk, PacketList& writebacks) = 0; 49512724Snikos.nikoleris@arm.com 49612724Snikos.nikoleris@arm.com /** 49712724Snikos.nikoleris@arm.com * Handles a response (cache line fill/write ack) from the bus. 49812724Snikos.nikoleris@arm.com * @param pkt The response packet 49912724Snikos.nikoleris@arm.com */ 50012724Snikos.nikoleris@arm.com virtual void recvTimingResp(PacketPtr pkt); 50112724Snikos.nikoleris@arm.com 50212724Snikos.nikoleris@arm.com /** 50312724Snikos.nikoleris@arm.com * Snoops bus transactions to maintain coherence. 50412724Snikos.nikoleris@arm.com * @param pkt The current bus transaction. 50512724Snikos.nikoleris@arm.com */ 50612724Snikos.nikoleris@arm.com virtual void recvTimingSnoopReq(PacketPtr pkt) = 0; 50712724Snikos.nikoleris@arm.com 50812724Snikos.nikoleris@arm.com /** 50912724Snikos.nikoleris@arm.com * Handle a snoop response. 51012724Snikos.nikoleris@arm.com * @param pkt Snoop response packet 51112724Snikos.nikoleris@arm.com */ 51212724Snikos.nikoleris@arm.com virtual void recvTimingSnoopResp(PacketPtr pkt) = 0; 51312724Snikos.nikoleris@arm.com 51412724Snikos.nikoleris@arm.com /** 51512724Snikos.nikoleris@arm.com * Handle a request in atomic mode that missed in this cache 51612724Snikos.nikoleris@arm.com * 51712724Snikos.nikoleris@arm.com * Creates a downstream request, sends it to the memory below and 51812724Snikos.nikoleris@arm.com * handles the response. As we are in atomic mode all operations 51912724Snikos.nikoleris@arm.com * are performed immediately. 52012724Snikos.nikoleris@arm.com * 52112724Snikos.nikoleris@arm.com * @param pkt The packet with the requests 52212724Snikos.nikoleris@arm.com * @param blk The referenced block 52312724Snikos.nikoleris@arm.com * @param writebacks A list with packets for any performed writebacks 52412724Snikos.nikoleris@arm.com * @return Cycles for handling the request 52512724Snikos.nikoleris@arm.com */ 52613017Snikos.nikoleris@arm.com virtual Cycles handleAtomicReqMiss(PacketPtr pkt, CacheBlk *&blk, 52712724Snikos.nikoleris@arm.com PacketList &writebacks) = 0; 52812724Snikos.nikoleris@arm.com 52912724Snikos.nikoleris@arm.com /** 53012724Snikos.nikoleris@arm.com * Performs the access specified by the request. 53112724Snikos.nikoleris@arm.com * @param pkt The request to perform. 53212724Snikos.nikoleris@arm.com * @return The number of ticks required for the access. 53312724Snikos.nikoleris@arm.com */ 53412724Snikos.nikoleris@arm.com virtual Tick recvAtomic(PacketPtr pkt); 53512724Snikos.nikoleris@arm.com 53612724Snikos.nikoleris@arm.com /** 53712724Snikos.nikoleris@arm.com * Snoop for the provided request in the cache and return the estimated 53812724Snikos.nikoleris@arm.com * time taken. 53912724Snikos.nikoleris@arm.com * @param pkt The memory request to snoop 54012724Snikos.nikoleris@arm.com * @return The number of ticks required for the snoop. 54112724Snikos.nikoleris@arm.com */ 54212724Snikos.nikoleris@arm.com virtual Tick recvAtomicSnoop(PacketPtr pkt) = 0; 54312724Snikos.nikoleris@arm.com 54412724Snikos.nikoleris@arm.com /** 54512724Snikos.nikoleris@arm.com * Performs the access specified by the request. 54612724Snikos.nikoleris@arm.com * 54712724Snikos.nikoleris@arm.com * @param pkt The request to perform. 54812724Snikos.nikoleris@arm.com * @param fromCpuSide from the CPU side port or the memory side port 54912724Snikos.nikoleris@arm.com */ 55012724Snikos.nikoleris@arm.com virtual void functionalAccess(PacketPtr pkt, bool from_cpu_side); 55112724Snikos.nikoleris@arm.com 55212724Snikos.nikoleris@arm.com /** 55312724Snikos.nikoleris@arm.com * Handle doing the Compare and Swap function for SPARC. 55412724Snikos.nikoleris@arm.com */ 55512724Snikos.nikoleris@arm.com void cmpAndSwap(CacheBlk *blk, PacketPtr pkt); 55612724Snikos.nikoleris@arm.com 55712724Snikos.nikoleris@arm.com /** 55812724Snikos.nikoleris@arm.com * Return the next queue entry to service, either a pending miss 55912724Snikos.nikoleris@arm.com * from the MSHR queue, a buffered write from the write buffer, or 56012724Snikos.nikoleris@arm.com * something from the prefetcher. This function is responsible 56112724Snikos.nikoleris@arm.com * for prioritizing among those sources on the fly. 56212724Snikos.nikoleris@arm.com */ 56312724Snikos.nikoleris@arm.com QueueEntry* getNextQueueEntry(); 56412724Snikos.nikoleris@arm.com 56512724Snikos.nikoleris@arm.com /** 56612724Snikos.nikoleris@arm.com * Insert writebacks into the write buffer 56712724Snikos.nikoleris@arm.com */ 56812724Snikos.nikoleris@arm.com virtual void doWritebacks(PacketList& writebacks, Tick forward_time) = 0; 56912724Snikos.nikoleris@arm.com 57012724Snikos.nikoleris@arm.com /** 57112724Snikos.nikoleris@arm.com * Send writebacks down the memory hierarchy in atomic mode 57212724Snikos.nikoleris@arm.com */ 57312724Snikos.nikoleris@arm.com virtual void doWritebacksAtomic(PacketList& writebacks) = 0; 57412724Snikos.nikoleris@arm.com 57512724Snikos.nikoleris@arm.com /** 57612724Snikos.nikoleris@arm.com * Create an appropriate downstream bus request packet. 57712724Snikos.nikoleris@arm.com * 57812724Snikos.nikoleris@arm.com * Creates a new packet with the request to be send to the memory 57912724Snikos.nikoleris@arm.com * below, or nullptr if the current request in cpu_pkt should just 58012724Snikos.nikoleris@arm.com * be forwarded on. 58112724Snikos.nikoleris@arm.com * 58212724Snikos.nikoleris@arm.com * @param cpu_pkt The miss packet that needs to be satisfied. 58312724Snikos.nikoleris@arm.com * @param blk The referenced block, can be nullptr. 58412724Snikos.nikoleris@arm.com * @param needs_writable Indicates that the block must be writable 58512724Snikos.nikoleris@arm.com * even if the request in cpu_pkt doesn't indicate that. 58613350Snikos.nikoleris@arm.com * @param is_whole_line_write True if there are writes for the 58713350Snikos.nikoleris@arm.com * whole line 58812724Snikos.nikoleris@arm.com * @return A packet send to the memory below 58912724Snikos.nikoleris@arm.com */ 59012724Snikos.nikoleris@arm.com virtual PacketPtr createMissPacket(PacketPtr cpu_pkt, CacheBlk *blk, 59113350Snikos.nikoleris@arm.com bool needs_writable, 59213350Snikos.nikoleris@arm.com bool is_whole_line_write) const = 0; 59312724Snikos.nikoleris@arm.com 59412724Snikos.nikoleris@arm.com /** 59512724Snikos.nikoleris@arm.com * Determine if clean lines should be written back or not. In 59612724Snikos.nikoleris@arm.com * cases where a downstream cache is mostly inclusive we likely 59712724Snikos.nikoleris@arm.com * want it to act as a victim cache also for lines that have not 59812724Snikos.nikoleris@arm.com * been modified. Hence, we cannot simply drop the line (or send a 59912724Snikos.nikoleris@arm.com * clean evict), but rather need to send the actual data. 60012724Snikos.nikoleris@arm.com */ 60112724Snikos.nikoleris@arm.com const bool writebackClean; 60212724Snikos.nikoleris@arm.com 60312724Snikos.nikoleris@arm.com /** 60412724Snikos.nikoleris@arm.com * Writebacks from the tempBlock, resulting on the response path 60512724Snikos.nikoleris@arm.com * in atomic mode, must happen after the call to recvAtomic has 60612724Snikos.nikoleris@arm.com * finished (for the right ordering of the packets). We therefore 60712724Snikos.nikoleris@arm.com * need to hold on to the packets, and have a method and an event 60812724Snikos.nikoleris@arm.com * to send them. 60912724Snikos.nikoleris@arm.com */ 61012724Snikos.nikoleris@arm.com PacketPtr tempBlockWriteback; 61112724Snikos.nikoleris@arm.com 61212724Snikos.nikoleris@arm.com /** 61312724Snikos.nikoleris@arm.com * Send the outstanding tempBlock writeback. To be called after 61412724Snikos.nikoleris@arm.com * recvAtomic finishes in cases where the block we filled is in 61512724Snikos.nikoleris@arm.com * fact the tempBlock, and now needs to be written back. 61612724Snikos.nikoleris@arm.com */ 61712724Snikos.nikoleris@arm.com void writebackTempBlockAtomic() { 61812724Snikos.nikoleris@arm.com assert(tempBlockWriteback != nullptr); 61912724Snikos.nikoleris@arm.com PacketList writebacks{tempBlockWriteback}; 62012724Snikos.nikoleris@arm.com doWritebacksAtomic(writebacks); 62112724Snikos.nikoleris@arm.com tempBlockWriteback = nullptr; 62212724Snikos.nikoleris@arm.com } 62312724Snikos.nikoleris@arm.com 62412724Snikos.nikoleris@arm.com /** 62512724Snikos.nikoleris@arm.com * An event to writeback the tempBlock after recvAtomic 62612724Snikos.nikoleris@arm.com * finishes. To avoid other calls to recvAtomic getting in 62712724Snikos.nikoleris@arm.com * between, we create this event with a higher priority. 62812724Snikos.nikoleris@arm.com */ 62912724Snikos.nikoleris@arm.com EventFunctionWrapper writebackTempBlockAtomicEvent; 63012724Snikos.nikoleris@arm.com 63112724Snikos.nikoleris@arm.com /** 63212724Snikos.nikoleris@arm.com * Perform any necessary updates to the block and perform any data 63312724Snikos.nikoleris@arm.com * exchange between the packet and the block. The flags of the 63412724Snikos.nikoleris@arm.com * packet are also set accordingly. 63512724Snikos.nikoleris@arm.com * 63612724Snikos.nikoleris@arm.com * @param pkt Request packet from upstream that hit a block 63712724Snikos.nikoleris@arm.com * @param blk Cache block that the packet hit 63812724Snikos.nikoleris@arm.com * @param deferred_response Whether this request originally missed 63912724Snikos.nikoleris@arm.com * @param pending_downgrade Whether the writable flag is to be removed 64012724Snikos.nikoleris@arm.com */ 64112724Snikos.nikoleris@arm.com virtual void satisfyRequest(PacketPtr pkt, CacheBlk *blk, 64212724Snikos.nikoleris@arm.com bool deferred_response = false, 64312724Snikos.nikoleris@arm.com bool pending_downgrade = false); 64412724Snikos.nikoleris@arm.com 64512724Snikos.nikoleris@arm.com /** 64612724Snikos.nikoleris@arm.com * Maintain the clusivity of this cache by potentially 64712724Snikos.nikoleris@arm.com * invalidating a block. This method works in conjunction with 64812724Snikos.nikoleris@arm.com * satisfyRequest, but is separate to allow us to handle all MSHR 64912724Snikos.nikoleris@arm.com * targets before potentially dropping a block. 65012724Snikos.nikoleris@arm.com * 65112724Snikos.nikoleris@arm.com * @param from_cache Whether we have dealt with a packet from a cache 65212724Snikos.nikoleris@arm.com * @param blk The block that should potentially be dropped 65312724Snikos.nikoleris@arm.com */ 65412724Snikos.nikoleris@arm.com void maintainClusivity(bool from_cache, CacheBlk *blk); 65512724Snikos.nikoleris@arm.com 65612724Snikos.nikoleris@arm.com /** 65712724Snikos.nikoleris@arm.com * Handle a fill operation caused by a received packet. 65812724Snikos.nikoleris@arm.com * 65912724Snikos.nikoleris@arm.com * Populates a cache block and handles all outstanding requests for the 66012724Snikos.nikoleris@arm.com * satisfied fill request. This version takes two memory requests. One 66112724Snikos.nikoleris@arm.com * contains the fill data, the other is an optional target to satisfy. 66212724Snikos.nikoleris@arm.com * Note that the reason we return a list of writebacks rather than 66312724Snikos.nikoleris@arm.com * inserting them directly in the write buffer is that this function 66412724Snikos.nikoleris@arm.com * is called by both atomic and timing-mode accesses, and in atomic 66512724Snikos.nikoleris@arm.com * mode we don't mess with the write buffer (we just perform the 66612724Snikos.nikoleris@arm.com * writebacks atomically once the original request is complete). 66712724Snikos.nikoleris@arm.com * 66812724Snikos.nikoleris@arm.com * @param pkt The memory request with the fill data. 66912724Snikos.nikoleris@arm.com * @param blk The cache block if it already exists. 67012724Snikos.nikoleris@arm.com * @param writebacks List for any writebacks that need to be performed. 67112724Snikos.nikoleris@arm.com * @param allocate Whether to allocate a block or use the temp block 67212724Snikos.nikoleris@arm.com * @return Pointer to the new cache block. 67312724Snikos.nikoleris@arm.com */ 67412724Snikos.nikoleris@arm.com CacheBlk *handleFill(PacketPtr pkt, CacheBlk *blk, 67512724Snikos.nikoleris@arm.com PacketList &writebacks, bool allocate); 67612724Snikos.nikoleris@arm.com 67712724Snikos.nikoleris@arm.com /** 67812724Snikos.nikoleris@arm.com * Allocate a new block and perform any necessary writebacks 67912724Snikos.nikoleris@arm.com * 68012724Snikos.nikoleris@arm.com * Find a victim block and if necessary prepare writebacks for any 68112724Snikos.nikoleris@arm.com * existing data. May return nullptr if there are no replaceable 68212754Sodanrc@yahoo.com.br * blocks. If a replaceable block is found, it inserts the new block in 68312754Sodanrc@yahoo.com.br * its place. The new block, however, is not set as valid yet. 68412724Snikos.nikoleris@arm.com * 68512754Sodanrc@yahoo.com.br * @param pkt Packet holding the address to update 68612724Snikos.nikoleris@arm.com * @param writebacks A list of writeback packets for the evicted blocks 68712724Snikos.nikoleris@arm.com * @return the allocated block 68812724Snikos.nikoleris@arm.com */ 68912754Sodanrc@yahoo.com.br CacheBlk *allocateBlock(const PacketPtr pkt, PacketList &writebacks); 69012724Snikos.nikoleris@arm.com /** 69112724Snikos.nikoleris@arm.com * Evict a cache block. 69212724Snikos.nikoleris@arm.com * 69312724Snikos.nikoleris@arm.com * Performs a writeback if necesssary and invalidates the block 69412724Snikos.nikoleris@arm.com * 69512724Snikos.nikoleris@arm.com * @param blk Block to invalidate 69612724Snikos.nikoleris@arm.com * @return A packet with the writeback, can be nullptr 69712724Snikos.nikoleris@arm.com */ 69812724Snikos.nikoleris@arm.com M5_NODISCARD virtual PacketPtr evictBlock(CacheBlk *blk) = 0; 69912724Snikos.nikoleris@arm.com 70012724Snikos.nikoleris@arm.com /** 70112724Snikos.nikoleris@arm.com * Evict a cache block. 70212724Snikos.nikoleris@arm.com * 70312724Snikos.nikoleris@arm.com * Performs a writeback if necesssary and invalidates the block 70412724Snikos.nikoleris@arm.com * 70512724Snikos.nikoleris@arm.com * @param blk Block to invalidate 70612724Snikos.nikoleris@arm.com * @param writebacks Return a list of packets with writebacks 70712724Snikos.nikoleris@arm.com */ 70812724Snikos.nikoleris@arm.com virtual void evictBlock(CacheBlk *blk, PacketList &writebacks) = 0; 70912724Snikos.nikoleris@arm.com 71012724Snikos.nikoleris@arm.com /** 71112724Snikos.nikoleris@arm.com * Invalidate a cache block. 71212724Snikos.nikoleris@arm.com * 71312724Snikos.nikoleris@arm.com * @param blk Block to invalidate 71412724Snikos.nikoleris@arm.com */ 71512724Snikos.nikoleris@arm.com void invalidateBlock(CacheBlk *blk); 71612724Snikos.nikoleris@arm.com 71712724Snikos.nikoleris@arm.com /** 71812724Snikos.nikoleris@arm.com * Create a writeback request for the given block. 71912724Snikos.nikoleris@arm.com * 72012724Snikos.nikoleris@arm.com * @param blk The block to writeback. 72112724Snikos.nikoleris@arm.com * @return The writeback request for the block. 72212724Snikos.nikoleris@arm.com */ 72312724Snikos.nikoleris@arm.com PacketPtr writebackBlk(CacheBlk *blk); 72412724Snikos.nikoleris@arm.com 72512724Snikos.nikoleris@arm.com /** 72612724Snikos.nikoleris@arm.com * Create a writeclean request for the given block. 72712724Snikos.nikoleris@arm.com * 72812724Snikos.nikoleris@arm.com * Creates a request that writes the block to the cache below 72912724Snikos.nikoleris@arm.com * without evicting the block from the current cache. 73012724Snikos.nikoleris@arm.com * 73112724Snikos.nikoleris@arm.com * @param blk The block to write clean. 73212724Snikos.nikoleris@arm.com * @param dest The destination of the write clean operation. 73312724Snikos.nikoleris@arm.com * @param id Use the given packet id for the write clean operation. 73412724Snikos.nikoleris@arm.com * @return The generated write clean packet. 73512724Snikos.nikoleris@arm.com */ 73612724Snikos.nikoleris@arm.com PacketPtr writecleanBlk(CacheBlk *blk, Request::Flags dest, PacketId id); 73711197Sandreas.hansson@arm.com 73811197Sandreas.hansson@arm.com /** 7399347SAndreas.Sandberg@arm.com * Write back dirty blocks in the cache using functional accesses. 7409347SAndreas.Sandberg@arm.com */ 74112724Snikos.nikoleris@arm.com virtual void memWriteback() override; 74212724Snikos.nikoleris@arm.com 7439347SAndreas.Sandberg@arm.com /** 7449347SAndreas.Sandberg@arm.com * Invalidates all blocks in the cache. 7459347SAndreas.Sandberg@arm.com * 7469347SAndreas.Sandberg@arm.com * @warn Dirty cache lines will not be written back to 7479347SAndreas.Sandberg@arm.com * memory. Make sure to call functionalWriteback() first if you 7489347SAndreas.Sandberg@arm.com * want the to write them to memory. 7499347SAndreas.Sandberg@arm.com */ 75012724Snikos.nikoleris@arm.com virtual void memInvalidate() override; 75112724Snikos.nikoleris@arm.com 7529347SAndreas.Sandberg@arm.com /** 7539347SAndreas.Sandberg@arm.com * Determine if there are any dirty blocks in the cache. 7549347SAndreas.Sandberg@arm.com * 75512724Snikos.nikoleris@arm.com * @return true if at least one block is dirty, false otherwise. 7569347SAndreas.Sandberg@arm.com */ 75712724Snikos.nikoleris@arm.com bool isDirty() const; 7589347SAndreas.Sandberg@arm.com 75910821Sandreas.hansson@arm.com /** 76010821Sandreas.hansson@arm.com * Determine if an address is in the ranges covered by this 76110821Sandreas.hansson@arm.com * cache. This is useful to filter snoops. 76210821Sandreas.hansson@arm.com * 76310821Sandreas.hansson@arm.com * @param addr Address to check against 76410821Sandreas.hansson@arm.com * 76510821Sandreas.hansson@arm.com * @return If the address in question is in range 76610821Sandreas.hansson@arm.com */ 76710821Sandreas.hansson@arm.com bool inRange(Addr addr) const; 76810821Sandreas.hansson@arm.com 76912724Snikos.nikoleris@arm.com /** 77012724Snikos.nikoleris@arm.com * Find next request ready time from among possible sources. 77112724Snikos.nikoleris@arm.com */ 77212724Snikos.nikoleris@arm.com Tick nextQueueReadyTime() const; 77312724Snikos.nikoleris@arm.com 7744626SN/A /** Block size of this cache */ 7756227Snate@binkert.org const unsigned blkSize; 7764626SN/A 7774630SN/A /** 77810693SMarco.Balboni@ARM.com * The latency of tag lookup of a cache. It occurs when there is 77910693SMarco.Balboni@ARM.com * an access to the cache. 7804630SN/A */ 78110693SMarco.Balboni@ARM.com const Cycles lookupLatency; 7829263Smrinmoy.ghosh@arm.com 7839263Smrinmoy.ghosh@arm.com /** 78411722Ssophiane.senni@gmail.com * The latency of data access of a cache. It occurs when there is 78511722Ssophiane.senni@gmail.com * an access to the cache. 78611722Ssophiane.senni@gmail.com */ 78711722Ssophiane.senni@gmail.com const Cycles dataLatency; 78811722Ssophiane.senni@gmail.com 78911722Ssophiane.senni@gmail.com /** 79010693SMarco.Balboni@ARM.com * This is the forward latency of the cache. It occurs when there 79110693SMarco.Balboni@ARM.com * is a cache miss and a request is forwarded downstream, in 79210693SMarco.Balboni@ARM.com * particular an outbound miss. 79310693SMarco.Balboni@ARM.com */ 79410693SMarco.Balboni@ARM.com const Cycles forwardLatency; 79510693SMarco.Balboni@ARM.com 79610693SMarco.Balboni@ARM.com /** The latency to fill a cache block */ 79710693SMarco.Balboni@ARM.com const Cycles fillLatency; 79810693SMarco.Balboni@ARM.com 79910693SMarco.Balboni@ARM.com /** 80010693SMarco.Balboni@ARM.com * The latency of sending reponse to its upper level cache/core on 80110693SMarco.Balboni@ARM.com * a linefill. The responseLatency parameter captures this 80210693SMarco.Balboni@ARM.com * latency. 8039263Smrinmoy.ghosh@arm.com */ 8049288Sandreas.hansson@arm.com const Cycles responseLatency; 8054630SN/A 8064626SN/A /** The number of targets for each MSHR. */ 8074626SN/A const int numTarget; 8084626SN/A 8096122SSteve.Reinhardt@amd.com /** Do we forward snoops from mem side port through to cpu side port? */ 81011331Sandreas.hansson@arm.com bool forwardSnoops; 8114626SN/A 8122810SN/A /** 81312724Snikos.nikoleris@arm.com * Clusivity with respect to the upstream cache, determining if we 81412724Snikos.nikoleris@arm.com * fill into both this cache and the cache above on a miss. Note 81512724Snikos.nikoleris@arm.com * that we currently do not support strict clusivity policies. 81612724Snikos.nikoleris@arm.com */ 81712724Snikos.nikoleris@arm.com const Enums::Clusivity clusivity; 81812724Snikos.nikoleris@arm.com 81912724Snikos.nikoleris@arm.com /** 82010884Sandreas.hansson@arm.com * Is this cache read only, for example the instruction cache, or 82110884Sandreas.hansson@arm.com * table-walker cache. A cache that is read only should never see 82210884Sandreas.hansson@arm.com * any writes, and should never get any dirty data (and hence 82310884Sandreas.hansson@arm.com * never have to do any writebacks). 82410884Sandreas.hansson@arm.com */ 82510884Sandreas.hansson@arm.com const bool isReadOnly; 82610884Sandreas.hansson@arm.com 82710884Sandreas.hansson@arm.com /** 8282810SN/A * Bit vector of the blocking reasons for the access path. 8292810SN/A * @sa #BlockedCause 8302810SN/A */ 8312810SN/A uint8_t blocked; 8322810SN/A 8336122SSteve.Reinhardt@amd.com /** Increasing order number assigned to each incoming request. */ 8346122SSteve.Reinhardt@amd.com uint64_t order; 8356122SSteve.Reinhardt@amd.com 8362810SN/A /** Stores time the cache blocked for statistics. */ 8379288Sandreas.hansson@arm.com Cycles blockedCycle; 8382810SN/A 8394626SN/A /** Pointer to the MSHR that has no targets. */ 8404626SN/A MSHR *noTargetMSHR; 8412810SN/A 8422810SN/A /** The number of misses to trigger an exit event. */ 8432810SN/A Counter missCount; 8442810SN/A 8456122SSteve.Reinhardt@amd.com /** 8466122SSteve.Reinhardt@amd.com * The address range to which the cache responds on the CPU side. 8476122SSteve.Reinhardt@amd.com * Normally this is all possible memory addresses. */ 8489529Sandreas.hansson@arm.com const AddrRangeList addrRanges; 8496122SSteve.Reinhardt@amd.com 8508833Sdam.sunwoo@arm.com public: 8518833Sdam.sunwoo@arm.com /** System we are currently operating in. */ 8528833Sdam.sunwoo@arm.com System *system; 8536978SLisa.Hsu@amd.com 8542810SN/A // Statistics 8552810SN/A /** 8562810SN/A * @addtogroup CacheStatistics 8572810SN/A * @{ 8582810SN/A */ 8592810SN/A 86011483Snikos.nikoleris@arm.com /** Number of hits per thread for each type of command. 86111483Snikos.nikoleris@arm.com @sa Packet::Command */ 8625999Snate@binkert.org Stats::Vector hits[MemCmd::NUM_MEM_CMDS]; 8632810SN/A /** Number of hits for demand accesses. */ 8642810SN/A Stats::Formula demandHits; 8652810SN/A /** Number of hit for all accesses. */ 8662810SN/A Stats::Formula overallHits; 8672810SN/A 86811483Snikos.nikoleris@arm.com /** Number of misses per thread for each type of command. 86911483Snikos.nikoleris@arm.com @sa Packet::Command */ 8705999Snate@binkert.org Stats::Vector misses[MemCmd::NUM_MEM_CMDS]; 8712810SN/A /** Number of misses for demand accesses. */ 8722810SN/A Stats::Formula demandMisses; 8732810SN/A /** Number of misses for all accesses. */ 8742810SN/A Stats::Formula overallMisses; 8752810SN/A 8762810SN/A /** 8772810SN/A * Total number of cycles per thread/command spent waiting for a miss. 8782810SN/A * Used to calculate the average miss latency. 8792810SN/A */ 8805999Snate@binkert.org Stats::Vector missLatency[MemCmd::NUM_MEM_CMDS]; 8812810SN/A /** Total number of cycles spent waiting for demand misses. */ 8822810SN/A Stats::Formula demandMissLatency; 8832810SN/A /** Total number of cycles spent waiting for all misses. */ 8842810SN/A Stats::Formula overallMissLatency; 8852810SN/A 8862810SN/A /** The number of accesses per command and thread. */ 8874022SN/A Stats::Formula accesses[MemCmd::NUM_MEM_CMDS]; 8882810SN/A /** The number of demand accesses. */ 8892810SN/A Stats::Formula demandAccesses; 8902810SN/A /** The number of overall accesses. */ 8912810SN/A Stats::Formula overallAccesses; 8922810SN/A 8932810SN/A /** The miss rate per command and thread. */ 8944022SN/A Stats::Formula missRate[MemCmd::NUM_MEM_CMDS]; 8952810SN/A /** The miss rate of all demand accesses. */ 8962810SN/A Stats::Formula demandMissRate; 8972810SN/A /** The miss rate for all accesses. */ 8982810SN/A Stats::Formula overallMissRate; 8992810SN/A 9002810SN/A /** The average miss latency per command and thread. */ 9014022SN/A Stats::Formula avgMissLatency[MemCmd::NUM_MEM_CMDS]; 9022810SN/A /** The average miss latency for demand misses. */ 9032810SN/A Stats::Formula demandAvgMissLatency; 9042810SN/A /** The average miss latency for all misses. */ 9052810SN/A Stats::Formula overallAvgMissLatency; 9062810SN/A 9072810SN/A /** The total number of cycles blocked for each blocked cause. */ 9085999Snate@binkert.org Stats::Vector blocked_cycles; 9092810SN/A /** The number of times this cache blocked for each blocked cause. */ 9105999Snate@binkert.org Stats::Vector blocked_causes; 9112810SN/A 9122810SN/A /** The average number of cycles blocked for each blocked cause. */ 9132810SN/A Stats::Formula avg_blocked; 9142810SN/A 91511436SRekai.GonzalezAlberquilla@arm.com /** The number of times a HW-prefetched block is evicted w/o reference. */ 91611436SRekai.GonzalezAlberquilla@arm.com Stats::Scalar unusedPrefetches; 91711436SRekai.GonzalezAlberquilla@arm.com 9184626SN/A /** Number of blocks written back per thread. */ 9195999Snate@binkert.org Stats::Vector writebacks; 9204626SN/A 9214626SN/A /** Number of misses that hit in the MSHRs per command and thread. */ 9225999Snate@binkert.org Stats::Vector mshr_hits[MemCmd::NUM_MEM_CMDS]; 9234626SN/A /** Demand misses that hit in the MSHRs. */ 9244626SN/A Stats::Formula demandMshrHits; 9254626SN/A /** Total number of misses that hit in the MSHRs. */ 9264626SN/A Stats::Formula overallMshrHits; 9274626SN/A 9284626SN/A /** Number of misses that miss in the MSHRs, per command and thread. */ 9295999Snate@binkert.org Stats::Vector mshr_misses[MemCmd::NUM_MEM_CMDS]; 9304626SN/A /** Demand misses that miss in the MSHRs. */ 9314626SN/A Stats::Formula demandMshrMisses; 9324626SN/A /** Total number of misses that miss in the MSHRs. */ 9334626SN/A Stats::Formula overallMshrMisses; 9344626SN/A 9354626SN/A /** Number of misses that miss in the MSHRs, per command and thread. */ 9365999Snate@binkert.org Stats::Vector mshr_uncacheable[MemCmd::NUM_MEM_CMDS]; 9374626SN/A /** Total number of misses that miss in the MSHRs. */ 9384626SN/A Stats::Formula overallMshrUncacheable; 9394626SN/A 9404626SN/A /** Total cycle latency of each MSHR miss, per command and thread. */ 9415999Snate@binkert.org Stats::Vector mshr_miss_latency[MemCmd::NUM_MEM_CMDS]; 9424626SN/A /** Total cycle latency of demand MSHR misses. */ 9434626SN/A Stats::Formula demandMshrMissLatency; 9444626SN/A /** Total cycle latency of overall MSHR misses. */ 9454626SN/A Stats::Formula overallMshrMissLatency; 9464626SN/A 9474626SN/A /** Total cycle latency of each MSHR miss, per command and thread. */ 9485999Snate@binkert.org Stats::Vector mshr_uncacheable_lat[MemCmd::NUM_MEM_CMDS]; 9494626SN/A /** Total cycle latency of overall MSHR misses. */ 9504626SN/A Stats::Formula overallMshrUncacheableLatency; 9514626SN/A 9527461Snate@binkert.org#if 0 9534626SN/A /** The total number of MSHR accesses per command and thread. */ 9544626SN/A Stats::Formula mshrAccesses[MemCmd::NUM_MEM_CMDS]; 9554626SN/A /** The total number of demand MSHR accesses. */ 9564626SN/A Stats::Formula demandMshrAccesses; 9574626SN/A /** The total number of MSHR accesses. */ 9584626SN/A Stats::Formula overallMshrAccesses; 9597461Snate@binkert.org#endif 9604626SN/A 9614626SN/A /** The miss rate in the MSHRs pre command and thread. */ 9624626SN/A Stats::Formula mshrMissRate[MemCmd::NUM_MEM_CMDS]; 9634626SN/A /** The demand miss rate in the MSHRs. */ 9644626SN/A Stats::Formula demandMshrMissRate; 9654626SN/A /** The overall miss rate in the MSHRs. */ 9664626SN/A Stats::Formula overallMshrMissRate; 9674626SN/A 9684626SN/A /** The average latency of an MSHR miss, per command and thread. */ 9694626SN/A Stats::Formula avgMshrMissLatency[MemCmd::NUM_MEM_CMDS]; 9704626SN/A /** The average latency of a demand MSHR miss. */ 9714626SN/A Stats::Formula demandAvgMshrMissLatency; 9724626SN/A /** The average overall latency of an MSHR miss. */ 9734626SN/A Stats::Formula overallAvgMshrMissLatency; 9744626SN/A 9754626SN/A /** The average latency of an MSHR miss, per command and thread. */ 9764626SN/A Stats::Formula avgMshrUncacheableLatency[MemCmd::NUM_MEM_CMDS]; 9774626SN/A /** The average overall latency of an MSHR miss. */ 9784626SN/A Stats::Formula overallAvgMshrUncacheableLatency; 9794626SN/A 98012702Snikos.nikoleris@arm.com /** Number of replacements of valid blocks. */ 98112702Snikos.nikoleris@arm.com Stats::Scalar replacements; 98212702Snikos.nikoleris@arm.com 9832810SN/A /** 9842810SN/A * @} 9852810SN/A */ 9862810SN/A 9872810SN/A /** 9882810SN/A * Register stats for this object. 9892810SN/A */ 99012724Snikos.nikoleris@arm.com void regStats() override; 9912810SN/A 9922810SN/A public: 99311053Sandreas.hansson@arm.com BaseCache(const BaseCacheParams *p, unsigned blk_size); 99412724Snikos.nikoleris@arm.com ~BaseCache(); 9953606SN/A 99612724Snikos.nikoleris@arm.com void init() override; 9972858SN/A 99812724Snikos.nikoleris@arm.com BaseMasterPort &getMasterPort(const std::string &if_name, 99912724Snikos.nikoleris@arm.com PortID idx = InvalidPortID) override; 100012724Snikos.nikoleris@arm.com BaseSlavePort &getSlavePort(const std::string &if_name, 100112724Snikos.nikoleris@arm.com PortID idx = InvalidPortID) override; 10028922Swilliam.wang@arm.com 10032810SN/A /** 10042810SN/A * Query block size of a cache. 10052810SN/A * @return The block size 10062810SN/A */ 10076227Snate@binkert.org unsigned 10086227Snate@binkert.org getBlockSize() const 10092810SN/A { 10102810SN/A return blkSize; 10112810SN/A } 10122810SN/A 10138883SAli.Saidi@ARM.com const AddrRangeList &getAddrRanges() const { return addrRanges; } 10146122SSteve.Reinhardt@amd.com 101510942Sandreas.hansson@arm.com MSHR *allocateMissBuffer(PacketPtr pkt, Tick time, bool sched_send = true) 10164628SN/A { 101711892Snikos.nikoleris@arm.com MSHR *mshr = mshrQueue.allocate(pkt->getBlockAddr(blkSize), blkSize, 101811375Sandreas.hansson@arm.com pkt, time, order++, 101911375Sandreas.hansson@arm.com allocOnFill(pkt->cmd)); 102011375Sandreas.hansson@arm.com 102111375Sandreas.hansson@arm.com if (mshrQueue.isFull()) { 102211375Sandreas.hansson@arm.com setBlocked((BlockedCause)MSHRQueue_MSHRs); 102311375Sandreas.hansson@arm.com } 102411375Sandreas.hansson@arm.com 102511375Sandreas.hansson@arm.com if (sched_send) { 102611375Sandreas.hansson@arm.com // schedule the send 102711375Sandreas.hansson@arm.com schedMemSideSendEvent(time); 102811375Sandreas.hansson@arm.com } 102911375Sandreas.hansson@arm.com 103011375Sandreas.hansson@arm.com return mshr; 10314628SN/A } 10324628SN/A 103311375Sandreas.hansson@arm.com void allocateWriteBuffer(PacketPtr pkt, Tick time) 10344628SN/A { 103511191Sandreas.hansson@arm.com // should only see writes or clean evicts here 103611191Sandreas.hansson@arm.com assert(pkt->isWrite() || pkt->cmd == MemCmd::CleanEvict); 103711191Sandreas.hansson@arm.com 103811892Snikos.nikoleris@arm.com Addr blk_addr = pkt->getBlockAddr(blkSize); 103911375Sandreas.hansson@arm.com 104011375Sandreas.hansson@arm.com WriteQueueEntry *wq_entry = 104111375Sandreas.hansson@arm.com writeBuffer.findMatch(blk_addr, pkt->isSecure()); 104211375Sandreas.hansson@arm.com if (wq_entry && !wq_entry->inService) { 104311744Snikos.nikoleris@arm.com DPRINTF(Cache, "Potential to merge writeback %s", pkt->print()); 104411375Sandreas.hansson@arm.com } 104511375Sandreas.hansson@arm.com 104611375Sandreas.hansson@arm.com writeBuffer.allocate(blk_addr, blkSize, pkt, time, order++); 104711375Sandreas.hansson@arm.com 104811375Sandreas.hansson@arm.com if (writeBuffer.isFull()) { 104911375Sandreas.hansson@arm.com setBlocked((BlockedCause)MSHRQueue_WriteBuffer); 105011375Sandreas.hansson@arm.com } 105111375Sandreas.hansson@arm.com 105211375Sandreas.hansson@arm.com // schedule the send 105311375Sandreas.hansson@arm.com schedMemSideSendEvent(time); 10544628SN/A } 10554628SN/A 10562810SN/A /** 10572810SN/A * Returns true if the cache is blocked for accesses. 10582810SN/A */ 10599529Sandreas.hansson@arm.com bool isBlocked() const 10602810SN/A { 10612810SN/A return blocked != 0; 10622810SN/A } 10632810SN/A 10642810SN/A /** 10652810SN/A * Marks the access path of the cache as blocked for the given cause. This 10662810SN/A * also sets the blocked flag in the slave interface. 10672810SN/A * @param cause The reason for the cache blocking. 10682810SN/A */ 10692810SN/A void setBlocked(BlockedCause cause) 10702810SN/A { 10712810SN/A uint8_t flag = 1 << cause; 10722810SN/A if (blocked == 0) { 10732810SN/A blocked_causes[cause]++; 10749288Sandreas.hansson@arm.com blockedCycle = curCycle(); 107512724Snikos.nikoleris@arm.com cpuSidePort.setBlocked(); 10762810SN/A } 10774630SN/A blocked |= flag; 10784630SN/A DPRINTF(Cache,"Blocking for cause %d, mask=%d\n", cause, blocked); 10792810SN/A } 10802810SN/A 10812810SN/A /** 10822810SN/A * Marks the cache as unblocked for the given cause. This also clears the 10832810SN/A * blocked flags in the appropriate interfaces. 10842810SN/A * @param cause The newly unblocked cause. 10852810SN/A * @warning Calling this function can cause a blocked request on the bus to 10862810SN/A * access the cache. The cache must be in a state to handle that request. 10872810SN/A */ 10882810SN/A void clearBlocked(BlockedCause cause) 10892810SN/A { 10902810SN/A uint8_t flag = 1 << cause; 10914630SN/A blocked &= ~flag; 10924630SN/A DPRINTF(Cache,"Unblocking for cause %d, mask=%d\n", cause, blocked); 10934630SN/A if (blocked == 0) { 10949288Sandreas.hansson@arm.com blocked_cycles[cause] += curCycle() - blockedCycle; 109512724Snikos.nikoleris@arm.com cpuSidePort.clearBlocked(); 10962810SN/A } 10972810SN/A } 10982810SN/A 10992810SN/A /** 110010942Sandreas.hansson@arm.com * Schedule a send event for the memory-side port. If already 110110942Sandreas.hansson@arm.com * scheduled, this may reschedule the event at an earlier 110210942Sandreas.hansson@arm.com * time. When the specified time is reached, the port is free to 110310942Sandreas.hansson@arm.com * send either a response, a request, or a prefetch request. 110410942Sandreas.hansson@arm.com * 110510942Sandreas.hansson@arm.com * @param time The time when to attempt sending a packet. 11062810SN/A */ 110710942Sandreas.hansson@arm.com void schedMemSideSendEvent(Tick time) 11082810SN/A { 110912724Snikos.nikoleris@arm.com memSidePort.schedSendEvent(time); 11102811SN/A } 11113503SN/A 111212724Snikos.nikoleris@arm.com bool inCache(Addr addr, bool is_secure) const { 111312724Snikos.nikoleris@arm.com return tags->findBlock(addr, is_secure); 111412724Snikos.nikoleris@arm.com } 11154626SN/A 111612724Snikos.nikoleris@arm.com bool inMissQueue(Addr addr, bool is_secure) const { 111712724Snikos.nikoleris@arm.com return mshrQueue.findMatch(addr, is_secure); 111812724Snikos.nikoleris@arm.com } 11194626SN/A 11208833Sdam.sunwoo@arm.com void incMissCount(PacketPtr pkt) 11213503SN/A { 11228833Sdam.sunwoo@arm.com assert(pkt->req->masterId() < system->maxMasters()); 11238833Sdam.sunwoo@arm.com misses[pkt->cmdToIndex()][pkt->req->masterId()]++; 112410020Smatt.horsnell@ARM.com pkt->req->incAccessDepth(); 11254626SN/A if (missCount) { 11264626SN/A --missCount; 11274626SN/A if (missCount == 0) 11284626SN/A exitSimLoop("A cache reached the maximum miss count"); 11293503SN/A } 11303503SN/A } 11318833Sdam.sunwoo@arm.com void incHitCount(PacketPtr pkt) 11326978SLisa.Hsu@amd.com { 11338833Sdam.sunwoo@arm.com assert(pkt->req->masterId() < system->maxMasters()); 11348833Sdam.sunwoo@arm.com hits[pkt->cmdToIndex()][pkt->req->masterId()]++; 11356978SLisa.Hsu@amd.com 11366978SLisa.Hsu@amd.com } 11373503SN/A 113812724Snikos.nikoleris@arm.com /** 113912724Snikos.nikoleris@arm.com * Cache block visitor that writes back dirty cache blocks using 114012724Snikos.nikoleris@arm.com * functional writes. 114112724Snikos.nikoleris@arm.com */ 114212728Snikos.nikoleris@arm.com void writebackVisitor(CacheBlk &blk); 114312724Snikos.nikoleris@arm.com 114412724Snikos.nikoleris@arm.com /** 114512724Snikos.nikoleris@arm.com * Cache block visitor that invalidates all blocks in the cache. 114612724Snikos.nikoleris@arm.com * 114712724Snikos.nikoleris@arm.com * @warn Dirty cache lines will not be written back to memory. 114812724Snikos.nikoleris@arm.com */ 114912728Snikos.nikoleris@arm.com void invalidateVisitor(CacheBlk &blk); 115012724Snikos.nikoleris@arm.com 115112724Snikos.nikoleris@arm.com /** 115212724Snikos.nikoleris@arm.com * Take an MSHR, turn it into a suitable downstream packet, and 115312724Snikos.nikoleris@arm.com * send it out. This construct allows a queue entry to choose a suitable 115412724Snikos.nikoleris@arm.com * approach based on its type. 115512724Snikos.nikoleris@arm.com * 115612724Snikos.nikoleris@arm.com * @param mshr The MSHR to turn into a packet and send 115712724Snikos.nikoleris@arm.com * @return True if the port is waiting for a retry 115812724Snikos.nikoleris@arm.com */ 115912724Snikos.nikoleris@arm.com virtual bool sendMSHRQueuePacket(MSHR* mshr); 116012724Snikos.nikoleris@arm.com 116112724Snikos.nikoleris@arm.com /** 116212724Snikos.nikoleris@arm.com * Similar to sendMSHR, but for a write-queue entry 116312724Snikos.nikoleris@arm.com * instead. Create the packet, and send it, and if successful also 116412724Snikos.nikoleris@arm.com * mark the entry in service. 116512724Snikos.nikoleris@arm.com * 116612724Snikos.nikoleris@arm.com * @param wq_entry The write-queue entry to turn into a packet and send 116712724Snikos.nikoleris@arm.com * @return True if the port is waiting for a retry 116812724Snikos.nikoleris@arm.com */ 116912724Snikos.nikoleris@arm.com bool sendWriteQueuePacket(WriteQueueEntry* wq_entry); 117012724Snikos.nikoleris@arm.com 117112724Snikos.nikoleris@arm.com /** 117212724Snikos.nikoleris@arm.com * Serialize the state of the caches 117312724Snikos.nikoleris@arm.com * 117412724Snikos.nikoleris@arm.com * We currently don't support checkpointing cache state, so this panics. 117512724Snikos.nikoleris@arm.com */ 117612724Snikos.nikoleris@arm.com void serialize(CheckpointOut &cp) const override; 117712724Snikos.nikoleris@arm.com void unserialize(CheckpointIn &cp) override; 117812724Snikos.nikoleris@arm.com 117912724Snikos.nikoleris@arm.com}; 118012724Snikos.nikoleris@arm.com 118113352Snikos.nikoleris@arm.com/** 118213352Snikos.nikoleris@arm.com * The write allocator inspects write packets and detects streaming 118313352Snikos.nikoleris@arm.com * patterns. The write allocator supports a single stream where writes 118413352Snikos.nikoleris@arm.com * are expected to access consecutive locations and keeps track of 118513352Snikos.nikoleris@arm.com * size of the area covered by the concecutive writes in byteCount. 118613352Snikos.nikoleris@arm.com * 118713352Snikos.nikoleris@arm.com * 1) When byteCount has surpassed the coallesceLimit the mode 118813352Snikos.nikoleris@arm.com * switches from ALLOCATE to COALESCE where writes should be delayed 118913352Snikos.nikoleris@arm.com * until the whole block is written at which point a single packet 119013352Snikos.nikoleris@arm.com * (whole line write) can service them. 119113352Snikos.nikoleris@arm.com * 119213352Snikos.nikoleris@arm.com * 2) When byteCount has also exceeded the noAllocateLimit (whole 119313352Snikos.nikoleris@arm.com * line) we switch to NO_ALLOCATE when writes should not allocate in 119413352Snikos.nikoleris@arm.com * the cache but rather send a whole line write to the memory below. 119513352Snikos.nikoleris@arm.com */ 119613352Snikos.nikoleris@arm.comclass WriteAllocator : public SimObject { 119713352Snikos.nikoleris@arm.com public: 119813352Snikos.nikoleris@arm.com WriteAllocator(const WriteAllocatorParams *p) : 119913352Snikos.nikoleris@arm.com SimObject(p), 120013352Snikos.nikoleris@arm.com coalesceLimit(p->coalesce_limit * p->block_size), 120113352Snikos.nikoleris@arm.com noAllocateLimit(p->no_allocate_limit * p->block_size), 120213352Snikos.nikoleris@arm.com delayThreshold(p->delay_threshold) 120313352Snikos.nikoleris@arm.com { 120413352Snikos.nikoleris@arm.com reset(); 120513352Snikos.nikoleris@arm.com } 120613352Snikos.nikoleris@arm.com 120713352Snikos.nikoleris@arm.com /** 120813352Snikos.nikoleris@arm.com * Should writes be coalesced? This is true if the mode is set to 120913352Snikos.nikoleris@arm.com * NO_ALLOCATE. 121013352Snikos.nikoleris@arm.com * 121113352Snikos.nikoleris@arm.com * @return return true if the cache should coalesce writes. 121213352Snikos.nikoleris@arm.com */ 121313352Snikos.nikoleris@arm.com bool coalesce() const { 121413352Snikos.nikoleris@arm.com return mode != WriteMode::ALLOCATE; 121513352Snikos.nikoleris@arm.com } 121613352Snikos.nikoleris@arm.com 121713352Snikos.nikoleris@arm.com /** 121813352Snikos.nikoleris@arm.com * Should writes allocate? 121913352Snikos.nikoleris@arm.com * 122013352Snikos.nikoleris@arm.com * @return return true if the cache should not allocate for writes. 122113352Snikos.nikoleris@arm.com */ 122213352Snikos.nikoleris@arm.com bool allocate() const { 122313352Snikos.nikoleris@arm.com return mode != WriteMode::NO_ALLOCATE; 122413352Snikos.nikoleris@arm.com } 122513352Snikos.nikoleris@arm.com 122613352Snikos.nikoleris@arm.com /** 122713352Snikos.nikoleris@arm.com * Reset the write allocator state, meaning that it allocates for 122813352Snikos.nikoleris@arm.com * writes and has not recorded any information about qualifying 122913352Snikos.nikoleris@arm.com * writes that might trigger a switch to coalescing and later no 123013352Snikos.nikoleris@arm.com * allocation. 123113352Snikos.nikoleris@arm.com */ 123213352Snikos.nikoleris@arm.com void reset() { 123313352Snikos.nikoleris@arm.com mode = WriteMode::ALLOCATE; 123413352Snikos.nikoleris@arm.com byteCount = 0; 123513352Snikos.nikoleris@arm.com nextAddr = 0; 123613352Snikos.nikoleris@arm.com } 123713352Snikos.nikoleris@arm.com 123813352Snikos.nikoleris@arm.com /** 123913352Snikos.nikoleris@arm.com * Access whether we need to delay the current write. 124013352Snikos.nikoleris@arm.com * 124113352Snikos.nikoleris@arm.com * @param blk_addr The block address the packet writes to 124213352Snikos.nikoleris@arm.com * @return true if the current packet should be delayed 124313352Snikos.nikoleris@arm.com */ 124413352Snikos.nikoleris@arm.com bool delay(Addr blk_addr) { 124513352Snikos.nikoleris@arm.com if (delayCtr[blk_addr] > 0) { 124613352Snikos.nikoleris@arm.com --delayCtr[blk_addr]; 124713352Snikos.nikoleris@arm.com return true; 124813352Snikos.nikoleris@arm.com } else { 124913352Snikos.nikoleris@arm.com return false; 125013352Snikos.nikoleris@arm.com } 125113352Snikos.nikoleris@arm.com } 125213352Snikos.nikoleris@arm.com 125313352Snikos.nikoleris@arm.com /** 125413352Snikos.nikoleris@arm.com * Clear delay counter for the input block 125513352Snikos.nikoleris@arm.com * 125613352Snikos.nikoleris@arm.com * @param blk_addr The accessed cache block 125713352Snikos.nikoleris@arm.com */ 125813352Snikos.nikoleris@arm.com void resetDelay(Addr blk_addr) { 125913352Snikos.nikoleris@arm.com delayCtr.erase(blk_addr); 126013352Snikos.nikoleris@arm.com } 126113352Snikos.nikoleris@arm.com 126213352Snikos.nikoleris@arm.com /** 126313352Snikos.nikoleris@arm.com * Update the write mode based on the current write 126413352Snikos.nikoleris@arm.com * packet. This method compares the packet's address with any 126513352Snikos.nikoleris@arm.com * current stream, and updates the tracking and the mode 126613352Snikos.nikoleris@arm.com * accordingly. 126713352Snikos.nikoleris@arm.com * 126813352Snikos.nikoleris@arm.com * @param write_addr Start address of the write request 126913352Snikos.nikoleris@arm.com * @param write_size Size of the write request 127013352Snikos.nikoleris@arm.com * @param blk_addr The block address that this packet writes to 127113352Snikos.nikoleris@arm.com */ 127213352Snikos.nikoleris@arm.com void updateMode(Addr write_addr, unsigned write_size, Addr blk_addr); 127313352Snikos.nikoleris@arm.com 127413352Snikos.nikoleris@arm.com private: 127513352Snikos.nikoleris@arm.com /** 127613352Snikos.nikoleris@arm.com * The current mode for write coalescing and allocation, either 127713352Snikos.nikoleris@arm.com * normal operation (ALLOCATE), write coalescing (COALESCE), or 127813352Snikos.nikoleris@arm.com * write coalescing without allocation (NO_ALLOCATE). 127913352Snikos.nikoleris@arm.com */ 128013352Snikos.nikoleris@arm.com enum class WriteMode : char { 128113352Snikos.nikoleris@arm.com ALLOCATE, 128213352Snikos.nikoleris@arm.com COALESCE, 128313352Snikos.nikoleris@arm.com NO_ALLOCATE, 128413352Snikos.nikoleris@arm.com }; 128513352Snikos.nikoleris@arm.com WriteMode mode; 128613352Snikos.nikoleris@arm.com 128713352Snikos.nikoleris@arm.com /** Address to match writes against to detect streams. */ 128813352Snikos.nikoleris@arm.com Addr nextAddr; 128913352Snikos.nikoleris@arm.com 129013352Snikos.nikoleris@arm.com /** 129113352Snikos.nikoleris@arm.com * Bytes written contiguously. Saturating once we no longer 129213352Snikos.nikoleris@arm.com * allocate. 129313352Snikos.nikoleris@arm.com */ 129413352Snikos.nikoleris@arm.com uint32_t byteCount; 129513352Snikos.nikoleris@arm.com 129613352Snikos.nikoleris@arm.com /** 129713352Snikos.nikoleris@arm.com * Limits for when to switch between the different write modes. 129813352Snikos.nikoleris@arm.com */ 129913352Snikos.nikoleris@arm.com const uint32_t coalesceLimit; 130013352Snikos.nikoleris@arm.com const uint32_t noAllocateLimit; 130113352Snikos.nikoleris@arm.com /** 130213352Snikos.nikoleris@arm.com * The number of times the allocator will delay an WriteReq MSHR. 130313352Snikos.nikoleris@arm.com */ 130413352Snikos.nikoleris@arm.com const uint32_t delayThreshold; 130513352Snikos.nikoleris@arm.com 130613352Snikos.nikoleris@arm.com /** 130713352Snikos.nikoleris@arm.com * Keep track of the number of times the allocator has delayed an 130813352Snikos.nikoleris@arm.com * WriteReq MSHR. 130913352Snikos.nikoleris@arm.com */ 131013352Snikos.nikoleris@arm.com std::unordered_map<Addr, Counter> delayCtr; 131113352Snikos.nikoleris@arm.com}; 131213352Snikos.nikoleris@arm.com 131311051Sandreas.hansson@arm.com#endif //__MEM_CACHE_BASE_HH__ 1314