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 * Definition of MSHRQueue class functions.
35 #include "mem/cache/mshr_queue.hh"
39 MSHRQueue::MSHRQueue(const std::string
&_label
,
40 int num_entries
, int reserve
, int _index
)
42 numEntries(num_entries
+ reserve
- 1), numReserve(reserve
),
47 registers
= new MSHR
[numEntries
];
48 for (int i
= 0; i
< numEntries
; ++i
) {
49 registers
[i
].queue
= this;
50 freeList
.push_back(®isters
[i
]);
54 MSHRQueue::~MSHRQueue()
60 MSHRQueue::findMatch(Addr addr
) const
62 MSHR::ConstIterator i
= allocatedList
.begin();
63 MSHR::ConstIterator end
= allocatedList
.end();
64 for (; i
!= end
; ++i
) {
66 if (mshr
->addr
== addr
) {
74 MSHRQueue::findMatches(Addr addr
, vector
<MSHR
*>& matches
) const
76 // Need an empty vector
77 assert(matches
.empty());
79 MSHR::ConstIterator i
= allocatedList
.begin();
80 MSHR::ConstIterator end
= allocatedList
.end();
81 for (; i
!= end
; ++i
) {
83 if (mshr
->addr
== addr
) {
85 matches
.push_back(mshr
);
93 MSHRQueue::checkFunctional(PacketPtr pkt
, Addr blk_addr
)
95 pkt
->pushLabel(label
);
96 MSHR::ConstIterator i
= allocatedList
.begin();
97 MSHR::ConstIterator end
= allocatedList
.end();
98 for (; i
!= end
; ++i
) {
100 if (mshr
->addr
== blk_addr
&& mshr
->checkFunctional(pkt
)) {
111 MSHRQueue::findPending(Addr addr
, int size
) const
113 MSHR::ConstIterator i
= readyList
.begin();
114 MSHR::ConstIterator end
= readyList
.end();
115 for (; i
!= end
; ++i
) {
117 if (mshr
->addr
< addr
) {
118 if (mshr
->addr
+ mshr
->size
> addr
) {
122 if (addr
+ size
> mshr
->addr
) {
132 MSHRQueue::addToReadyList(MSHR
*mshr
)
134 if (readyList
.empty() || readyList
.back()->readyTime
<= mshr
->readyTime
) {
135 return readyList
.insert(readyList
.end(), mshr
);
138 MSHR::Iterator i
= readyList
.begin();
139 MSHR::Iterator end
= readyList
.end();
140 for (; i
!= end
; ++i
) {
141 if ((*i
)->readyTime
> mshr
->readyTime
) {
142 return readyList
.insert(i
, mshr
);
146 return end
; // keep stupid compilers happy
151 MSHRQueue::allocate(Addr addr
, int size
, PacketPtr
&pkt
,
152 Tick when
, Counter order
)
154 assert(!freeList
.empty());
155 MSHR
*mshr
= freeList
.front();
156 assert(mshr
->getNumTargets() == 0);
157 freeList
.pop_front();
159 mshr
->allocate(addr
, size
, pkt
, when
, order
);
160 mshr
->allocIter
= allocatedList
.insert(allocatedList
.end(), mshr
);
161 mshr
->readyIter
= addToReadyList(mshr
);
169 MSHRQueue::deallocate(MSHR
*mshr
)
175 MSHRQueue::deallocateOne(MSHR
*mshr
)
177 MSHR::Iterator retval
= allocatedList
.erase(mshr
->allocIter
);
178 freeList
.push_front(mshr
);
180 if (mshr
->inService
) {
183 readyList
.erase(mshr
->readyIter
);
190 MSHRQueue::moveToFront(MSHR
*mshr
)
192 if (!mshr
->inService
) {
193 assert(mshr
== *(mshr
->readyIter
));
194 readyList
.erase(mshr
->readyIter
);
195 mshr
->readyIter
= readyList
.insert(readyList
.begin(), mshr
);
200 MSHRQueue::markInService(MSHR
*mshr
)
202 if (mshr
->markInService()) {
205 readyList
.erase(mshr
->readyIter
);
206 inServiceEntries
+= 1;
211 MSHRQueue::markPending(MSHR
*mshr
)
213 assert(mshr
->inService
);
214 mshr
->inService
= false;
217 * @ todo might want to add rerequests to front of pending list for
220 mshr
->readyIter
= addToReadyList(mshr
);
224 MSHRQueue::squash(int threadNum
)
226 MSHR::Iterator i
= allocatedList
.begin();
227 MSHR::Iterator end
= allocatedList
.end();
230 if (mshr
->threadNum
== threadNum
) {
231 while (mshr
->hasTargets()) {
233 assert(0/*target->req->threadId()*/ == threadNum
);
235 assert(!mshr
->hasTargets());
236 assert(mshr
->ntargets
==0);
237 if (!mshr
->inService
) {
238 i
= deallocateOne(mshr
);
240 //mshr->pkt->flags &= ~CACHE_LINE_FILL;