mshr.hh revision 12724
12810SN/A/* 212599Snikos.nikoleris@arm.com * Copyright (c) 2012-2013, 2015-2016, 2018 ARM Limited 39663Suri.wiener@arm.com * All rights reserved. 49663Suri.wiener@arm.com * 59663Suri.wiener@arm.com * The license below extends only to copyright in the software and shall 69663Suri.wiener@arm.com * not be construed as granting a license to any other intellectual 79663Suri.wiener@arm.com * property including but not limited to intellectual property relating 89663Suri.wiener@arm.com * to a hardware implementation of the functionality of the software 99663Suri.wiener@arm.com * licensed hereunder. You may use the software subject to the license 109663Suri.wiener@arm.com * terms below provided that you ensure that this notice is replicated 119663Suri.wiener@arm.com * unmodified and in its entirety in all distributions of the software, 129663Suri.wiener@arm.com * modified or unmodified, in source code or in binary form. 139663Suri.wiener@arm.com * 142810SN/A * Copyright (c) 2002-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 412810SN/A */ 422810SN/A 432810SN/A/** 442810SN/A * @file 452810SN/A * Miss Status and Handling Register (MSHR) declaration. 462810SN/A */ 472810SN/A 4810764Sandreas.hansson@arm.com#ifndef __MEM_CACHE_MSHR_HH__ 4910764Sandreas.hansson@arm.com#define __MEM_CACHE_MSHR_HH__ 502810SN/A 514626SN/A#include <list> 524626SN/A 535314SN/A#include "base/printable.hh" 5411375Sandreas.hansson@arm.com#include "mem/cache/queue_entry.hh" 552810SN/A 5612724Snikos.nikoleris@arm.comclass BaseCache; 572810SN/A 582810SN/A/** 592810SN/A * Miss Status and handling Register. This class keeps all the information 603374SN/A * needed to handle a cache miss including a list of target requests. 619264Sdjordje.kovacevic@arm.com * @sa \ref gem5MemorySystem "gem5 Memory System" 622810SN/A */ 6311375Sandreas.hansson@arm.comclass MSHR : public QueueEntry, public Printable 644626SN/A{ 654626SN/A 669725Sandreas.hansson@arm.com /** 6711375Sandreas.hansson@arm.com * Consider the queues friends to avoid making everything public. 689725Sandreas.hansson@arm.com */ 6911375Sandreas.hansson@arm.com template<typename Entry> 7011375Sandreas.hansson@arm.com friend class Queue; 719725Sandreas.hansson@arm.com friend class MSHRQueue; 729725Sandreas.hansson@arm.com 739725Sandreas.hansson@arm.com private: 749725Sandreas.hansson@arm.com 759725Sandreas.hansson@arm.com /** Flag set by downstream caches */ 769725Sandreas.hansson@arm.com bool downstreamPending; 779725Sandreas.hansson@arm.com 7811284Sandreas.hansson@arm.com /** 7911284Sandreas.hansson@arm.com * Here we use one flag to track both if: 8011284Sandreas.hansson@arm.com * 8111284Sandreas.hansson@arm.com * 1. We are going to become owner or not, i.e., we will get the 8211284Sandreas.hansson@arm.com * block in an ownership state (Owned or Modified) with BlkDirty 8311284Sandreas.hansson@arm.com * set. This determines whether or not we are going to become the 8411284Sandreas.hansson@arm.com * responder and ordering point for future requests that we snoop. 8511284Sandreas.hansson@arm.com * 8611284Sandreas.hansson@arm.com * 2. We know that we are going to get a writable block, i.e. we 8711284Sandreas.hansson@arm.com * will get the block in writable state (Exclusive or Modified 8811284Sandreas.hansson@arm.com * state) with BlkWritable set. That determines whether additional 8911284Sandreas.hansson@arm.com * targets with needsWritable set will be able to be satisfied, or 9011284Sandreas.hansson@arm.com * if not should be put on the deferred list to possibly wait for 9111284Sandreas.hansson@arm.com * another request that does give us writable access. 9211284Sandreas.hansson@arm.com * 9311284Sandreas.hansson@arm.com * Condition 2 is actually just a shortcut that saves us from 9411284Sandreas.hansson@arm.com * possibly building a deferred target list and calling 9511284Sandreas.hansson@arm.com * promoteWritable() every time we get a writable block. Condition 9611284Sandreas.hansson@arm.com * 1, tracking ownership, is what is important. However, we never 9711284Sandreas.hansson@arm.com * receive ownership without marking the block dirty, and 9811284Sandreas.hansson@arm.com * consequently use pendingModified to track both ownership and 9911284Sandreas.hansson@arm.com * writability rather than having separate pendingDirty and 10011284Sandreas.hansson@arm.com * pendingWritable flags. 10111284Sandreas.hansson@arm.com */ 10211284Sandreas.hansson@arm.com bool pendingModified; 1039725Sandreas.hansson@arm.com 1049725Sandreas.hansson@arm.com /** Did we snoop an invalidate while waiting for data? */ 1059725Sandreas.hansson@arm.com bool postInvalidate; 1069725Sandreas.hansson@arm.com 1079725Sandreas.hansson@arm.com /** Did we snoop a read while waiting for data? */ 1089725Sandreas.hansson@arm.com bool postDowngrade; 1099725Sandreas.hansson@arm.com 1102810SN/A public: 1114626SN/A 11211375Sandreas.hansson@arm.com /** True if the entry is just a simple forward from an upper level */ 11311375Sandreas.hansson@arm.com bool isForward; 11411375Sandreas.hansson@arm.com 1154626SN/A class Target { 1164626SN/A public: 1175875Ssteve.reinhardt@amd.com 1185875Ssteve.reinhardt@amd.com enum Source { 1195875Ssteve.reinhardt@amd.com FromCPU, 1205875Ssteve.reinhardt@amd.com FromSnoop, 1215875Ssteve.reinhardt@amd.com FromPrefetcher 1225875Ssteve.reinhardt@amd.com }; 1235875Ssteve.reinhardt@amd.com 12410766Sandreas.hansson@arm.com const Tick recvTime; //!< Time when request was received (for stats) 12510766Sandreas.hansson@arm.com const Tick readyTime; //!< Time when request is ready to be serviced 12610766Sandreas.hansson@arm.com const Counter order; //!< Global order (for memory consistency mgmt) 12710766Sandreas.hansson@arm.com const PacketPtr pkt; //!< Pending request packet. 12810766Sandreas.hansson@arm.com const Source source; //!< Request from cpu, memory, or prefetcher? 12911742Snikos.nikoleris@arm.com 13011742Snikos.nikoleris@arm.com /** 13111742Snikos.nikoleris@arm.com * We use this flag to track whether we have cleared the 13211742Snikos.nikoleris@arm.com * downstreamPending flag for the MSHR of the cache above 13311742Snikos.nikoleris@arm.com * where this packet originates from and guard noninitial 13411742Snikos.nikoleris@arm.com * attempts to clear it. 13511742Snikos.nikoleris@arm.com * 13611742Snikos.nikoleris@arm.com * The flag markedPending needs to be updated when the 13711742Snikos.nikoleris@arm.com * TargetList is in service which can be: 13811742Snikos.nikoleris@arm.com * 1) during the Target instantiation if the MSHR is in 13911742Snikos.nikoleris@arm.com * service and the target is not deferred, 14011742Snikos.nikoleris@arm.com * 2) when the MSHR becomes in service if the target is not 14111742Snikos.nikoleris@arm.com * deferred, 14211742Snikos.nikoleris@arm.com * 3) or when the TargetList is promoted (deferredTargets -> 14311742Snikos.nikoleris@arm.com * targets). 14411742Snikos.nikoleris@arm.com */ 14511742Snikos.nikoleris@arm.com bool markedPending; 14611742Snikos.nikoleris@arm.com 14711741Snikos.nikoleris@arm.com const bool allocOnFill; //!< Should the response servicing this 14811741Snikos.nikoleris@arm.com //!< target list allocate in the cache? 1494626SN/A 1505318SN/A Target(PacketPtr _pkt, Tick _readyTime, Counter _order, 15111741Snikos.nikoleris@arm.com Source _source, bool _markedPending, bool alloc_on_fill) 1527823Ssteve.reinhardt@amd.com : recvTime(curTick()), readyTime(_readyTime), order(_order), 15311741Snikos.nikoleris@arm.com pkt(_pkt), source(_source), markedPending(_markedPending), 15411741Snikos.nikoleris@arm.com allocOnFill(alloc_on_fill) 1554626SN/A {} 1564626SN/A }; 1574626SN/A 1584903SN/A class TargetList : public std::list<Target> { 1594903SN/A 1604903SN/A public: 16111284Sandreas.hansson@arm.com bool needsWritable; 1624903SN/A bool hasUpgrade; 16311741Snikos.nikoleris@arm.com /** Set when the response should allocate on fill */ 16411741Snikos.nikoleris@arm.com bool allocOnFill; 16512715Snikos.nikoleris@arm.com /** 16612715Snikos.nikoleris@arm.com * Determine whether there was at least one non-snooping 16712715Snikos.nikoleris@arm.com * target coming from another cache. 16812715Snikos.nikoleris@arm.com */ 16912715Snikos.nikoleris@arm.com bool hasFromCache; 1704903SN/A 1714903SN/A TargetList(); 17211740Snikos.nikoleris@arm.com 17311740Snikos.nikoleris@arm.com /** 17411740Snikos.nikoleris@arm.com * Use the provided packet and the source to update the 17511740Snikos.nikoleris@arm.com * flags of this TargetList. 17611740Snikos.nikoleris@arm.com * 17711740Snikos.nikoleris@arm.com * @param pkt Packet considered for the flag update 17811740Snikos.nikoleris@arm.com * @param source Indicates the source of the packet 17911741Snikos.nikoleris@arm.com * @param alloc_on_fill Whether the pkt would allocate on a fill 18011740Snikos.nikoleris@arm.com */ 18111741Snikos.nikoleris@arm.com void updateFlags(PacketPtr pkt, Target::Source source, 18211741Snikos.nikoleris@arm.com bool alloc_on_fill); 18311740Snikos.nikoleris@arm.com 18412715Snikos.nikoleris@arm.com void resetFlags() { 18512715Snikos.nikoleris@arm.com needsWritable = false; 18612715Snikos.nikoleris@arm.com hasUpgrade = false; 18712715Snikos.nikoleris@arm.com allocOnFill = false; 18812715Snikos.nikoleris@arm.com hasFromCache = false; 18912715Snikos.nikoleris@arm.com } 19011740Snikos.nikoleris@arm.com 19111740Snikos.nikoleris@arm.com /** 19211740Snikos.nikoleris@arm.com * Goes through the list of targets and uses them to populate 19311740Snikos.nikoleris@arm.com * the flags of this TargetList. When the function returns the 19411740Snikos.nikoleris@arm.com * flags are consistent with the properties of packets in the 19511740Snikos.nikoleris@arm.com * list. 19611740Snikos.nikoleris@arm.com */ 19711740Snikos.nikoleris@arm.com void populateFlags(); 19811740Snikos.nikoleris@arm.com 19911741Snikos.nikoleris@arm.com /** 20011741Snikos.nikoleris@arm.com * Tests if the flags of this TargetList have their default 20111741Snikos.nikoleris@arm.com * values. 20211741Snikos.nikoleris@arm.com */ 20311741Snikos.nikoleris@arm.com bool isReset() const { 20412715Snikos.nikoleris@arm.com return !needsWritable && !hasUpgrade && !allocOnFill && 20512715Snikos.nikoleris@arm.com !hasFromCache; 20611741Snikos.nikoleris@arm.com } 20711741Snikos.nikoleris@arm.com 20811741Snikos.nikoleris@arm.com /** 20911741Snikos.nikoleris@arm.com * Add the specified packet in the TargetList. This function 21011741Snikos.nikoleris@arm.com * stores information related to the added packet and updates 21111741Snikos.nikoleris@arm.com * accordingly the flags. 21211741Snikos.nikoleris@arm.com * 21311741Snikos.nikoleris@arm.com * @param pkt Packet considered for adding 21411741Snikos.nikoleris@arm.com * @param readTime Tick at which the packet is processed by this cache 21511741Snikos.nikoleris@arm.com * @param order A counter giving a unique id to each target 21611741Snikos.nikoleris@arm.com * @param source Indicates the source agent of the packet 21711741Snikos.nikoleris@arm.com * @param markPending Set for deferred targets or pending MSHRs 21811741Snikos.nikoleris@arm.com * @param alloc_on_fill Whether it should allocate on a fill 21911741Snikos.nikoleris@arm.com */ 2205318SN/A void add(PacketPtr pkt, Tick readyTime, Counter order, 22111741Snikos.nikoleris@arm.com Target::Source source, bool markPending, 22211741Snikos.nikoleris@arm.com bool alloc_on_fill); 22311357Sstephan.diestelhorst@arm.com 22411357Sstephan.diestelhorst@arm.com /** 22511357Sstephan.diestelhorst@arm.com * Convert upgrades to the equivalent request if the cache line they 22611357Sstephan.diestelhorst@arm.com * refer to would have been invalid (Upgrade -> ReadEx, SC* -> Fail). 22711357Sstephan.diestelhorst@arm.com * Used to rejig ordering between targets waiting on an MSHR. */ 2284903SN/A void replaceUpgrades(); 22911357Sstephan.diestelhorst@arm.com 2304908SN/A void clearDownstreamPending(); 2314920SN/A bool checkFunctional(PacketPtr pkt); 2325314SN/A void print(std::ostream &os, int verbosity, 2335314SN/A const std::string &prefix) const; 2344903SN/A }; 2354903SN/A 2362810SN/A /** A list of MSHRs. */ 2372810SN/A typedef std::list<MSHR *> List; 2382810SN/A /** MSHR list iterator. */ 2392810SN/A typedef List::iterator Iterator; 2404903SN/A 2417667Ssteve.reinhardt@amd.com /** The pending* and post* flags are only valid if inService is 2427667Ssteve.reinhardt@amd.com * true. Using the accessor functions lets us detect if these 2437667Ssteve.reinhardt@amd.com * flags are accessed improperly. 2447667Ssteve.reinhardt@amd.com */ 2457667Ssteve.reinhardt@amd.com 24611284Sandreas.hansson@arm.com /** True if we need to get a writable copy of the block. */ 24711284Sandreas.hansson@arm.com bool needsWritable() const { return targets.needsWritable; } 2489725Sandreas.hansson@arm.com 24912599Snikos.nikoleris@arm.com bool isCleaning() const { 25012599Snikos.nikoleris@arm.com PacketPtr pkt = targets.front().pkt; 25112599Snikos.nikoleris@arm.com return pkt->isClean(); 25212599Snikos.nikoleris@arm.com } 25312599Snikos.nikoleris@arm.com 25411284Sandreas.hansson@arm.com bool isPendingModified() const { 25511284Sandreas.hansson@arm.com assert(inService); return pendingModified; 2567667Ssteve.reinhardt@amd.com } 2577667Ssteve.reinhardt@amd.com 2587667Ssteve.reinhardt@amd.com bool hasPostInvalidate() const { 2597667Ssteve.reinhardt@amd.com assert(inService); return postInvalidate; 2607667Ssteve.reinhardt@amd.com } 2617667Ssteve.reinhardt@amd.com 2627667Ssteve.reinhardt@amd.com bool hasPostDowngrade() const { 2637667Ssteve.reinhardt@amd.com assert(inService); return postDowngrade; 2647667Ssteve.reinhardt@amd.com } 2654665SN/A 26612724Snikos.nikoleris@arm.com bool sendPacket(BaseCache &cache); 26711375Sandreas.hansson@arm.com 26811741Snikos.nikoleris@arm.com bool allocOnFill() const { 26911741Snikos.nikoleris@arm.com return targets.allocOnFill; 27011741Snikos.nikoleris@arm.com } 27112715Snikos.nikoleris@arm.com 27212715Snikos.nikoleris@arm.com /** 27312715Snikos.nikoleris@arm.com * Determine if there are non-deferred requests from other caches 27412715Snikos.nikoleris@arm.com * 27512715Snikos.nikoleris@arm.com * @return true if any of the targets is from another cache 27612715Snikos.nikoleris@arm.com */ 27712715Snikos.nikoleris@arm.com bool hasFromCache() const { 27812715Snikos.nikoleris@arm.com return targets.hasFromCache; 27912715Snikos.nikoleris@arm.com } 28012715Snikos.nikoleris@arm.com 2819725Sandreas.hansson@arm.com private: 2824668SN/A 2832810SN/A /** 2842810SN/A * Pointer to this MSHR on the ready list. 2852810SN/A * @sa MissQueue, MSHRQueue::readyList 2862810SN/A */ 2872810SN/A Iterator readyIter; 2884626SN/A 2892810SN/A /** 2902810SN/A * Pointer to this MSHR on the allocated list. 2912810SN/A * @sa MissQueue, MSHRQueue::allocatedList 2922810SN/A */ 2932810SN/A Iterator allocIter; 2942810SN/A 2953374SN/A /** List of all requests that match the address */ 2969725Sandreas.hansson@arm.com TargetList targets; 2972810SN/A 2989725Sandreas.hansson@arm.com TargetList deferredTargets; 2994665SN/A 3009725Sandreas.hansson@arm.com public: 3014626SN/A 3022810SN/A /** 3032810SN/A * Allocate a miss to this MSHR. 30410764Sandreas.hansson@arm.com * @param blk_addr The address of the block. 30510764Sandreas.hansson@arm.com * @param blk_size The number of bytes to request. 30610764Sandreas.hansson@arm.com * @param pkt The original miss. 30710764Sandreas.hansson@arm.com * @param when_ready When should the MSHR be ready to act upon. 30810764Sandreas.hansson@arm.com * @param _order The logical order of this MSHR 30911197Sandreas.hansson@arm.com * @param alloc_on_fill Should the cache allocate a block on fill 3102810SN/A */ 31110764Sandreas.hansson@arm.com void allocate(Addr blk_addr, unsigned blk_size, PacketPtr pkt, 31211197Sandreas.hansson@arm.com Tick when_ready, Counter _order, bool alloc_on_fill); 3132810SN/A 31411375Sandreas.hansson@arm.com void markInService(bool pending_modified_resp); 3154908SN/A 3165318SN/A void clearDownstreamPending(); 3175318SN/A 3182810SN/A /** 3192810SN/A * Mark this MSHR as free. 3202810SN/A */ 3212810SN/A void deallocate(); 3222810SN/A 3232810SN/A /** 3243374SN/A * Add a request to the list of targets. 3252810SN/A * @param target The target. 3262810SN/A */ 32711197Sandreas.hansson@arm.com void allocateTarget(PacketPtr target, Tick when, Counter order, 32811197Sandreas.hansson@arm.com bool alloc_on_fill); 3294902SN/A bool handleSnoop(PacketPtr target, Counter order); 3302810SN/A 3312810SN/A /** A simple constructor. */ 3322810SN/A MSHR(); 3332810SN/A 3342810SN/A /** 3352810SN/A * Returns the current number of allocated targets. 3362810SN/A * @return The current number of allocated targets. 3372810SN/A */ 3389725Sandreas.hansson@arm.com int getNumTargets() const 3399725Sandreas.hansson@arm.com { return targets.size() + deferredTargets.size(); } 3402810SN/A 3412810SN/A /** 34211742Snikos.nikoleris@arm.com * Extracts the subset of the targets that can be serviced given a 34311742Snikos.nikoleris@arm.com * received response. This function returns the targets list 34411742Snikos.nikoleris@arm.com * unless the response is a ReadRespWithInvalidate. The 34511742Snikos.nikoleris@arm.com * ReadRespWithInvalidate is only invalidating response that its 34611742Snikos.nikoleris@arm.com * invalidation was not expected when the request (a 34711742Snikos.nikoleris@arm.com * ReadSharedReq) was sent out. For ReadRespWithInvalidate we can 34811742Snikos.nikoleris@arm.com * safely service only the first FromCPU target and all FromSnoop 34911742Snikos.nikoleris@arm.com * targets (inform all snoopers that we no longer have the block). 35011742Snikos.nikoleris@arm.com * 35111742Snikos.nikoleris@arm.com * @param pkt The response from the downstream memory 35211742Snikos.nikoleris@arm.com */ 35311742Snikos.nikoleris@arm.com TargetList extractServiceableTargets(PacketPtr pkt); 35411742Snikos.nikoleris@arm.com 35511742Snikos.nikoleris@arm.com /** 3564899SN/A * Returns true if there are targets left. 3574899SN/A * @return true if there are targets 3584899SN/A */ 3599725Sandreas.hansson@arm.com bool hasTargets() const { return !targets.empty(); } 3604899SN/A 3614899SN/A /** 3622810SN/A * Returns a reference to the first target. 3632810SN/A * @return A pointer to the first target. 3642810SN/A */ 3659725Sandreas.hansson@arm.com Target *getTarget() 3665730SSteve.Reinhardt@amd.com { 3675730SSteve.Reinhardt@amd.com assert(hasTargets()); 3689725Sandreas.hansson@arm.com return &targets.front(); 3695730SSteve.Reinhardt@amd.com } 3702810SN/A 3712810SN/A /** 3722810SN/A * Pop first target. 3732810SN/A */ 3742810SN/A void popTarget() 3752810SN/A { 3769725Sandreas.hansson@arm.com targets.pop_front(); 3772810SN/A } 3782810SN/A 3794665SN/A bool promoteDeferredTargets(); 3804665SN/A 38111284Sandreas.hansson@arm.com void promoteWritable(); 3824668SN/A 3835314SN/A bool checkFunctional(PacketPtr pkt); 3844920SN/A 3852810SN/A /** 3865314SN/A * Prints the contents of this MSHR for debugging. 3872810SN/A */ 3885314SN/A void print(std::ostream &os, 3895314SN/A int verbosity = 0, 3905314SN/A const std::string &prefix = "") const; 3919663Suri.wiener@arm.com /** 3929663Suri.wiener@arm.com * A no-args wrapper of print(std::ostream...) meant to be 3939663Suri.wiener@arm.com * invoked from DPRINTFs avoiding string overheads in fast mode 3949663Suri.wiener@arm.com * 3959663Suri.wiener@arm.com * @return string with mshr fields + [deferred]targets 3969663Suri.wiener@arm.com */ 3979663Suri.wiener@arm.com std::string print() const; 3982810SN/A}; 3992810SN/A 40010764Sandreas.hansson@arm.com#endif // __MEM_CACHE_MSHR_HH__ 401