2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
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.
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.
28 * Authors: Erik Hallnor
32 * Declaration of a structure to manage MSHRs.
35 #ifndef __MSHR_QUEUE_HH__
36 #define __MSHR_QUEUE_HH__
39 #include "mem/cache/miss/mshr.hh"
42 * A Class for maintaining a list of pending and allocated memory requests.
48 /** Holds pointers to all allocated MSHRs. */
49 MSHR::List allocatedList;
50 /** Holds pointers to MSHRs that haven't been sent to the bus. */
51 MSHR::List pendingList;
52 /** Holds non allocated MSHRs. */
57 * The total number of MSHRs in this queue. This number is set as the
58 * number of MSHRs requested plus (numReserve - 1). This allows for
59 * the same number of effective MSHRs while still maintaining the reserve.
64 * The number of MSHRs to hold in reserve. This is needed because copy
65 * operations can allocate upto 4 MSHRs at one time.
70 /** The number of allocated MSHRs. */
72 /** The number of MSHRs that have been forwarded to the bus. */
74 /** The number of targets waiting for response. */
78 * Create a queue with a given number of MSHRs.
79 * @param num_mshrs The number of MSHRs in this queue.
80 * @param reserve The minimum number of MSHRs needed to satisfy any access.
82 MSHRQueue(int num_mshrs, int reserve = 1);
88 * Find the first MSHR that matches the provide address and asid.
89 * @param addr The address to find.
90 * @param asid The address space id.
91 * @return Pointer to the matching MSHR, null if not found.
93 MSHR* findMatch(Addr addr, int asid) const;
96 * Find and return all the matching MSHRs in the provided vector.
97 * @param addr The address to find.
98 * @param asid The address space ID.
99 * @param matches The vector to return pointers to the matching MSHRs.
100 * @return True if any matches are found, false otherwise.
101 * @todo Typedef the vector??
103 bool findMatches(Addr addr, int asid, std::vector<MSHR*>& matches) const;
106 * Find any pending requests that overlap the given request.
107 * @param req The request to find.
108 * @return A pointer to the earliest matching MSHR.
110 MSHR* findPending(Packet * &pkt) const;
113 * Allocates a new MSHR for the request and size. This places the request
114 * as the first target in the MSHR.
115 * @param req The request to handle.
116 * @param size The number in bytes to fetch from memory.
117 * @return The a pointer to the MSHR allocated.
119 * @pre There are free MSHRs.
121 MSHR* allocate(Packet * &pkt, int size = 0);
124 * Allocate a read request for the given address, and places the given
125 * target on the target list.
126 * @param addr The address to fetch.
127 * @param asid The address space for the fetch.
128 * @param size The number of bytes to request.
129 * @param target The first target for the request.
130 * @return Pointer to the new MSHR.
132 MSHR* allocateFetch(Addr addr, int asid, int size, Packet * &target);
135 * Allocate a target list for the given address.
136 * @param addr The address to fetch.
137 * @param asid The address space for the fetch.
138 * @param size The number of bytes to request.
139 * @return Pointer to the new MSHR.
141 MSHR* allocateTargetList(Addr addr, int asid, int size);
144 * Removes the given MSHR from the queue. This places the MSHR on the
148 void deallocate(MSHR* mshr);
151 * Allocates a target to the given MSHR. Used to keep track of the number
152 * of outstanding targets.
153 * @param mshr The MSHR to allocate the target to.
154 * @param req The target request.
156 void allocateTarget(MSHR* mshr, Packet * &pkt)
158 mshr->allocateTarget(pkt);
159 allocatedTargets += 1;
163 * Remove a MSHR from the queue. Returns an iterator into the allocatedList
164 * for faster squash implementation.
165 * @param mshr The MSHR to remove.
166 * @return An iterator to the next entry in the allocatedList.
168 MSHR::Iterator deallocateOne(MSHR* mshr);
171 * Moves the MSHR to the front of the pending list if it is not in service.
172 * @param mshr The mshr to move.
174 void moveToFront(MSHR *mshr);
177 * Mark the given MSHR as in service. This removes the MSHR from the
178 * pendingList. Deallocates the MSHR if it does not expect a response.
179 * @param mshr The MSHR to mark in service.
181 void markInService(MSHR* mshr);
184 * Mark an in service mshr as pending, used to resend a request.
185 * @param mshr The MSHR to resend.
186 * @param cmd The command to resend.
188 void markPending(MSHR* mshr, Packet::Command cmd);
191 * Squash outstanding requests with the given thread number. If a request
192 * is in service, just squashes the targets.
193 * @param req->getThreadNum()ber The thread to squash.
195 void squash(int threadNum);
198 * Returns true if the pending list is not empty.
199 * @return True if there are outstanding requests.
201 bool havePending() const
203 return !pendingList.empty();
207 * Returns true if there are no free MSHRs.
208 * @return True if this queue is full.
212 return (allocated > numMSHRs - numReserve);
216 * Returns the request at the head of the pendingList.
217 * @return The next request to service.
219 Packet * getReq() const
221 if (pendingList.empty()) {
224 MSHR* mshr = pendingList.front();
229 * Returns the number of outstanding targets.
230 * @return the number of allocated targets.
232 int getAllocatedTargets() const
234 return allocatedTargets;
239 #endif //__MSHR_QUEUE_HH__