2 * Copyright (c) 2002-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
34 * Miss Status and Handling Register (MSHR) definitions.
41 #include "mem/cache/miss/mshr.hh"
42 #include "sim/root.hh" // for curTick
43 #include "sim/host.hh"
44 #include "base/misc.hh"
45 #include "mem/cache/cache.hh"
57 MSHR::allocate(Packet::Command cmd
, Addr _addr
, int _asid
, int size
,
62 //Have a request, just use it
63 pkt
= new Packet(target
->req
, cmd
, Packet::Broadcast
, size
);
66 pkt
->senderState
= (Packet::SenderState
*)this;
67 allocateTarget(target
);
71 //need a request first
72 Request
* req
= new Request();
73 req
->setPhys(addr
, size
, 0);
75 pkt
= new Packet(req
, cmd
, Packet::Broadcast
, size
);
78 pkt
->senderState
= (Packet::SenderState
*)this;
82 // Since we aren't sure if data is being used, don't copy here.
84 * @todo When we have a "global" data flag, might want to copy data here.
87 MSHR::allocateAsBuffer(Packet
* &target
)
89 addr
= target
->getAddr();
90 asid
= target
->req
->getAsid();
91 threadNum
= target
->req
->getThreadNum();
92 pkt
= new Packet(target
->req
, target
->cmd
, -1);
94 pkt
->senderState
= (Packet::SenderState
*)this;
101 assert(targets
.empty());
102 assert(ntargets
== 0);
110 * Adds a target to an MSHR
113 MSHR::allocateTarget(Packet
* &target
)
115 //If we append an invalidate and we issued a read to the bus,
116 //but now have some pending writes, we need to move
117 //the invalidate to before the first non-read
118 if (inService
&& pkt
->isRead() && target
->isInvalidate()) {
119 std::list
<Packet
*> temp
;
121 while (!targets
.empty()) {
122 if (!targets
.front()->isRead()) break;
123 //Place on top of temp stack
124 temp
.push_front(targets
.front());
125 //Remove from targets
129 //Now that we have all the reads off until first non-read, we can
130 //place the invalidate on
131 targets
.push_front(target
);
133 //Now we pop off the temp_stack and put them back
134 while (!temp
.empty()) {
135 targets
.push_front(temp
.front());
140 targets
.push_back(target
);
144 assert(targets
.size() == ntargets
);
146 * @todo really prioritize the target commands.
149 if (!inService
&& target
->isWrite()) {
150 pkt
->cmd
= Packet::WriteReq
;
160 "inService: %d thread: %d\n"
161 "Addr: %x asid: %d ntargets %d\n"
163 inService
, threadNum
, addr
, asid
, ntargets
);
165 TargetListIterator tar_it
= targets
.begin();
166 for (int i
= 0; i
< ntargets
; i
++) {
167 assert(tar_it
!= targets
.end());
169 ccprintf(cerr
, "\t%d: Addr: %x cmd: %d\n",
170 i
, (*tar_it
)->getAddr(), (*tar_it
)->cmdToIndex());
174 ccprintf(cerr
, "\n");