mshr.hh revision 4899
12810SN/A/*
212599Snikos.nikoleris@arm.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
39663Suri.wiener@arm.com * All rights reserved.
49663Suri.wiener@arm.com *
59663Suri.wiener@arm.com * Redistribution and use in source and binary forms, with or without
69663Suri.wiener@arm.com * modification, are permitted provided that the following conditions are
79663Suri.wiener@arm.com * met: redistributions of source code must retain the above copyright
89663Suri.wiener@arm.com * notice, this list of conditions and the following disclaimer;
99663Suri.wiener@arm.com * redistributions in binary form must reproduce the above copyright
109663Suri.wiener@arm.com * notice, this list of conditions and the following disclaimer in the
119663Suri.wiener@arm.com * documentation and/or other materials provided with the distribution;
129663Suri.wiener@arm.com * neither the name of the copyright holders nor the names of its
139663Suri.wiener@arm.com * contributors may be used to endorse or promote products derived from
142810SN/A * this software without specific prior written permission.
152810SN/A *
162810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272810SN/A *
282810SN/A * Authors: Erik Hallnor
292810SN/A */
302810SN/A
312810SN/A/**
322810SN/A * @file
332810SN/A * Miss Status and Handling Register (MSHR) declaration.
342810SN/A */
352810SN/A
362810SN/A#ifndef __MSHR_HH__
372810SN/A#define __MSHR_HH__
382810SN/A
392810SN/A#include <list>
402810SN/A
412810SN/A#include "mem/packet.hh"
422810SN/A
432810SN/Aclass CacheBlk;
442810SN/Aclass MSHRQueue;
452810SN/A
462810SN/A/**
472810SN/A * Miss Status and handling Register. This class keeps all the information
4810764Sandreas.hansson@arm.com * needed to handle a cache miss including a list of target requests.
4910764Sandreas.hansson@arm.com */
502810SN/Aclass MSHR : public Packet::SenderState
5112727Snikos.nikoleris@arm.com{
5212727Snikos.nikoleris@arm.com
534626SN/A  public:
5412727Snikos.nikoleris@arm.com
554626SN/A    class Target {
565314SN/A      public:
5712727Snikos.nikoleris@arm.com        Tick recvTime;  //!< Time when request was received (for stats)
5811375Sandreas.hansson@arm.com        Tick readyTime; //!< Time when request is ready to be serviced
5912727Snikos.nikoleris@arm.com        Counter order;  //!< Global order (for memory consistency mgmt)
6012727Snikos.nikoleris@arm.com        PacketPtr pkt;  //!< Pending request packet.
612810SN/A        bool cpuSide;   //!< Did request come from cpu side or mem side?
6212724Snikos.nikoleris@arm.com
632810SN/A        bool isCpuSide() { return cpuSide; }
642810SN/A
652810SN/A        Target(PacketPtr _pkt, Tick _readyTime, Counter _order, bool _cpuSide)
663374SN/A            : recvTime(curTick), readyTime(_readyTime), order(_order),
679264Sdjordje.kovacevic@arm.com              pkt(_pkt), cpuSide(_cpuSide)
682810SN/A        {}
6911375Sandreas.hansson@arm.com    };
704626SN/A
714626SN/A    /** Defines the Data structure of the MSHR targetlist. */
729725Sandreas.hansson@arm.com    typedef std::list<Target> TargetList;
7311375Sandreas.hansson@arm.com    /** Target list iterator. */
749725Sandreas.hansson@arm.com    typedef std::list<Target>::iterator TargetListIterator;
7511375Sandreas.hansson@arm.com    /** A list of MSHRs. */
7611375Sandreas.hansson@arm.com    typedef std::list<MSHR *> List;
779725Sandreas.hansson@arm.com    /** MSHR list iterator. */
789725Sandreas.hansson@arm.com    typedef List::iterator Iterator;
799725Sandreas.hansson@arm.com    /** MSHR list const_iterator. */
809725Sandreas.hansson@arm.com    typedef List::const_iterator ConstIterator;
819725Sandreas.hansson@arm.com
829725Sandreas.hansson@arm.com    /** Pointer to queue containing this MSHR. */
839725Sandreas.hansson@arm.com    MSHRQueue *queue;
8411284Sandreas.hansson@arm.com
8511284Sandreas.hansson@arm.com    /** Cycle when ready to issue */
8611284Sandreas.hansson@arm.com    Tick readyTime;
8711284Sandreas.hansson@arm.com
8811284Sandreas.hansson@arm.com    /** Order number assigned by the miss queue. */
8911284Sandreas.hansson@arm.com    Counter order;
9011284Sandreas.hansson@arm.com
9111284Sandreas.hansson@arm.com    /** Address of the request. */
9211284Sandreas.hansson@arm.com    Addr addr;
9311284Sandreas.hansson@arm.com
9411284Sandreas.hansson@arm.com    /** Size of the request. */
9511284Sandreas.hansson@arm.com    int size;
9611284Sandreas.hansson@arm.com
9711284Sandreas.hansson@arm.com    /** True if the request has been sent to the bus. */
9811284Sandreas.hansson@arm.com    bool inService;
9911284Sandreas.hansson@arm.com
10011284Sandreas.hansson@arm.com    /** True if we will be putting the returned block in the cache */
10111284Sandreas.hansson@arm.com    bool isCacheFill;
10211284Sandreas.hansson@arm.com    /** True if we need to get an exclusive copy of the block. */
10311284Sandreas.hansson@arm.com    bool needsExclusive;
10411284Sandreas.hansson@arm.com
10511284Sandreas.hansson@arm.com    /** True if the request is uncacheable */
10611284Sandreas.hansson@arm.com    bool _isUncacheable;
10711284Sandreas.hansson@arm.com
10811284Sandreas.hansson@arm.com    bool deferredNeedsExclusive;
1099725Sandreas.hansson@arm.com    bool pendingInvalidate;
1109725Sandreas.hansson@arm.com    bool pendingShared;
1119725Sandreas.hansson@arm.com
1129725Sandreas.hansson@arm.com    /** Thread number of the miss. */
1139725Sandreas.hansson@arm.com    short threadNum;
1149725Sandreas.hansson@arm.com    /** The number of currently allocated targets. */
1159725Sandreas.hansson@arm.com    short ntargets;
1162810SN/A
1174626SN/A
11811375Sandreas.hansson@arm.com    /** Data buffer (if needed).  Currently used only for pending
11911375Sandreas.hansson@arm.com     * upgrade handling. */
12011375Sandreas.hansson@arm.com    uint8_t *data;
1214626SN/A
1224626SN/A    /**
1235875Ssteve.reinhardt@amd.com     * Pointer to this MSHR on the ready list.
1245875Ssteve.reinhardt@amd.com     * @sa MissQueue, MSHRQueue::readyList
1255875Ssteve.reinhardt@amd.com     */
1265875Ssteve.reinhardt@amd.com    Iterator readyIter;
1275875Ssteve.reinhardt@amd.com
1285875Ssteve.reinhardt@amd.com    /**
1295875Ssteve.reinhardt@amd.com     * Pointer to this MSHR on the allocated list.
13010766Sandreas.hansson@arm.com     * @sa MissQueue, MSHRQueue::allocatedList
13110766Sandreas.hansson@arm.com     */
13210766Sandreas.hansson@arm.com    Iterator allocIter;
13310766Sandreas.hansson@arm.com
13410766Sandreas.hansson@arm.comprivate:
13511742Snikos.nikoleris@arm.com    /** List of all requests that match the address */
13611742Snikos.nikoleris@arm.com    TargetList targets;
13711742Snikos.nikoleris@arm.com
13811742Snikos.nikoleris@arm.com    TargetList deferredTargets;
13911742Snikos.nikoleris@arm.com
14011742Snikos.nikoleris@arm.compublic:
14111742Snikos.nikoleris@arm.com
14211742Snikos.nikoleris@arm.com    bool isUncacheable() { return _isUncacheable; }
14311742Snikos.nikoleris@arm.com
14411742Snikos.nikoleris@arm.com    /**
14511742Snikos.nikoleris@arm.com     * Allocate a miss to this MSHR.
14611742Snikos.nikoleris@arm.com     * @param cmd The requesting command.
14711742Snikos.nikoleris@arm.com     * @param addr The address of the miss.
14811742Snikos.nikoleris@arm.com     * @param asid The address space id of the miss.
14911742Snikos.nikoleris@arm.com     * @param size The number of bytes to request.
15011742Snikos.nikoleris@arm.com     * @param pkt  The original miss.
15111742Snikos.nikoleris@arm.com     */
15211742Snikos.nikoleris@arm.com    void allocate(Addr addr, int size, PacketPtr pkt,
15311741Snikos.nikoleris@arm.com                  Tick when, Counter _order);
15411741Snikos.nikoleris@arm.com
1554626SN/A    /**
1565318SN/A     * Mark this MSHR as free.
15711741Snikos.nikoleris@arm.com     */
1587823Ssteve.reinhardt@amd.com    void deallocate();
15911741Snikos.nikoleris@arm.com
16011741Snikos.nikoleris@arm.com    /**
1614626SN/A     * Add a request to the list of targets.
1624626SN/A     * @param target The target.
1634626SN/A     */
1644903SN/A    void allocateTarget(PacketPtr target, Tick when, Counter order);
1654903SN/A    void allocateSnoopTarget(PacketPtr target, Tick when, Counter order);
1664903SN/A
16711284Sandreas.hansson@arm.com    /** A simple constructor. */
1684903SN/A    MSHR();
16911741Snikos.nikoleris@arm.com    /** A simple destructor. */
17011741Snikos.nikoleris@arm.com    ~MSHR();
17112715Snikos.nikoleris@arm.com
17212715Snikos.nikoleris@arm.com    /**
17312715Snikos.nikoleris@arm.com     * Returns the current number of allocated targets.
17412715Snikos.nikoleris@arm.com     * @return The current number of allocated targets.
17512715Snikos.nikoleris@arm.com     */
1764903SN/A    int getNumTargets() { return ntargets; }
1774903SN/A
17811740Snikos.nikoleris@arm.com    /**
17911740Snikos.nikoleris@arm.com     * Returns a pointer to the target list.
18011740Snikos.nikoleris@arm.com     * @return a pointer to the target list.
18111740Snikos.nikoleris@arm.com     */
18211740Snikos.nikoleris@arm.com    TargetList* getTargetList() { return &targets; }
18311740Snikos.nikoleris@arm.com
18411740Snikos.nikoleris@arm.com    /**
18511741Snikos.nikoleris@arm.com     * Returns true if there are targets left.
18611740Snikos.nikoleris@arm.com     * @return true if there are targets
18711741Snikos.nikoleris@arm.com     */
18811741Snikos.nikoleris@arm.com    bool hasTargets() { return !targets.empty(); }
18911740Snikos.nikoleris@arm.com
19012715Snikos.nikoleris@arm.com    /**
19112715Snikos.nikoleris@arm.com     * Returns a reference to the first target.
19212715Snikos.nikoleris@arm.com     * @return A pointer to the first target.
19312715Snikos.nikoleris@arm.com     */
19412715Snikos.nikoleris@arm.com    Target *getTarget() { assert(hasTargets());  return &targets.front(); }
19512715Snikos.nikoleris@arm.com
19611740Snikos.nikoleris@arm.com    /**
19711740Snikos.nikoleris@arm.com     * Pop first target.
19811740Snikos.nikoleris@arm.com     */
19911740Snikos.nikoleris@arm.com    void popTarget()
20011740Snikos.nikoleris@arm.com    {
20111740Snikos.nikoleris@arm.com        --ntargets;
20211740Snikos.nikoleris@arm.com        targets.pop_front();
20311740Snikos.nikoleris@arm.com    }
20411740Snikos.nikoleris@arm.com
20511741Snikos.nikoleris@arm.com    bool isSimpleForward()
20611741Snikos.nikoleris@arm.com    {
20711741Snikos.nikoleris@arm.com        if (getNumTargets() != 1)
20811741Snikos.nikoleris@arm.com            return false;
20911741Snikos.nikoleris@arm.com        Target *tgt = getTarget();
21012715Snikos.nikoleris@arm.com        return tgt->isCpuSide() && !tgt->pkt->needsResponse();
21112715Snikos.nikoleris@arm.com    }
21211741Snikos.nikoleris@arm.com
21311741Snikos.nikoleris@arm.com    bool promoteDeferredTargets();
21411741Snikos.nikoleris@arm.com
21511741Snikos.nikoleris@arm.com    void handleFill(Packet *pkt, CacheBlk *blk);
21611741Snikos.nikoleris@arm.com
21711741Snikos.nikoleris@arm.com    /**
21811741Snikos.nikoleris@arm.com     * Prints the contents of this MSHR to stderr.
21911741Snikos.nikoleris@arm.com     */
22011741Snikos.nikoleris@arm.com    void dump();
22111741Snikos.nikoleris@arm.com};
22211741Snikos.nikoleris@arm.com
22311741Snikos.nikoleris@arm.com#endif //__MSHR_HH__
22411741Snikos.nikoleris@arm.com