mshr.hh revision 2810
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Erik Hallnor
29 */
30
31/**
32 * @file
33 * Miss Status and Handling Register (MSHR) declaration.
34 */
35
36#ifndef __MSHR_HH__
37#define __MSHR_HH__
38
39#include "mem/packet.hh"
40#include <list>
41#include <deque>
42
43class MSHR;
44
45/**
46 * Miss Status and handling Register. This class keeps all the information
47 * needed to handle a cache miss including a list of target requests.
48 */
49class MSHR {
50  public:
51    /** Defines the Data structure of the MSHR targetlist. */
52    typedef std::list<Packet *> TargetList;
53    /** Target list iterator. */
54    typedef std::list<Packet *>::iterator TargetListIterator;
55    /** A list of MSHRs. */
56    typedef std::list<MSHR *> List;
57    /** MSHR list iterator. */
58    typedef List::iterator Iterator;
59    /** MSHR list const_iterator. */
60    typedef List::const_iterator ConstIterator;
61
62    /** Address of the miss. */
63    Addr addr;
64    /** Adress space id of the miss. */
65    short asid;
66    /** True if the request has been sent to the bus. */
67    bool inService;
68    /** Thread number of the miss. */
69    int threadNum;
70    /** The request that is forwarded to the next level of the hierarchy. */
71    Packet * pkt;
72    /** The number of currently allocated targets. */
73    short ntargets;
74    /** The original requesting command. */
75    Packet::Command originalCmd;
76    /** Order number of assigned by the miss queue. */
77    uint64_t order;
78
79    /**
80     * Pointer to this MSHR on the ready list.
81     * @sa MissQueue, MSHRQueue::readyList
82     */
83    Iterator readyIter;
84    /**
85     * Pointer to this MSHR on the allocated list.
86     * @sa MissQueue, MSHRQueue::allocatedList
87     */
88    Iterator allocIter;
89
90private:
91    /** List of all requests that match the address */
92    TargetList targets;
93
94public:
95    /**
96     * Allocate a miss to this MSHR.
97     * @param cmd The requesting command.
98     * @param addr The address of the miss.
99     * @param asid The address space id of the miss.
100     * @param size The number of bytes to request.
101     * @param req  The original miss.
102     */
103    void allocate(Packet::Command cmd, Addr addr, int asid, int size,
104                  Packet * &pkt);
105
106    /**
107     * Allocate this MSHR as a buffer for the given request.
108     * @param target The memory request to buffer.
109     */
110    void allocateAsBuffer(Packet * &target);
111
112    /**
113     * Mark this MSHR as free.
114     */
115    void deallocate();
116
117    /**
118     * Add a request to the list of targets.
119     * @param target The target.
120     */
121    void allocateTarget(Packet * &target);
122
123    /** A simple constructor. */
124    MSHR();
125    /** A simple destructor. */
126    ~MSHR();
127
128    /**
129     * Returns the current number of allocated targets.
130     * @return The current number of allocated targets.
131     */
132    int getNumTargets()
133    {
134        return(ntargets);
135    }
136
137    /**
138     * Returns a pointer to the target list.
139     * @return a pointer to the target list.
140     */
141    TargetList* getTargetList()
142    {
143        return &targets;
144    }
145
146    /**
147     * Returns a reference to the first target.
148     * @return A pointer to the first target.
149     */
150    Packet * getTarget()
151    {
152        return targets.front();
153    }
154
155    /**
156     * Pop first target.
157     */
158    void popTarget()
159    {
160        --ntargets;
161        targets.pop_front();
162    }
163
164    /**
165     * Returns true if there are targets left.
166     * @return true if there are targets
167     */
168    bool hasTargets()
169    {
170        return !targets.empty();
171    }
172
173    /**
174     * Prints the contents of this MSHR to stderr.
175     */
176    void dump();
177};
178
179#endif //__MSHR_HH__
180