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
,
60 assert(targets
.empty());
64 pkt
= new Packet(); // allocate new memory request
65 pkt
->addr
= addr
; //picked physical address for now
68 pkt
->data
= new uint8_t[size
];
69 pkt
->senderState
= this;
70 //Set the time here for latency calculations
71 //pkt->time = curTick;
74 pkt
->req
= target
->req
;
75 allocateTarget(target
);
79 // Since we aren't sure if data is being used, don't copy here.
81 * @todo When we have a "global" data flag, might want to copy data here.
84 MSHR::allocateAsBuffer(Packet
* &target
)
87 asid
= target
->req
->asid
;
88 threadNum
= target
->thread_num
;
90 pkt
->addr
= target
->addr
;
91 pkt
->dest
= target
->dest
;
92 pkt
->cmd
= target
->cmd
;
93 pkt
->size
= target
->size
;
94 pkt
->req
= target
->req
;
95 pkt
->data
= new uint8_t[target
->size
];
96 pkt
->senderState
= this;
102 assert(targets
.empty());
103 assert(ntargets
== 0);
111 * Adds a target to an MSHR
114 MSHR::allocateTarget(Packet
* &target
)
116 //If we append an invalidate and we issued a read to the bus,
117 //but now have some pending writes, we need to move
118 //the invalidate to before the first non-read
119 if (inService
&& pkt
->cmd
.isRead() && target
->cmd
.isInvalidate()) {
120 std::list
<Packet
*> temp
;
122 while (!targets
.empty()) {
123 if (!targets
.front()->cmd
.isRead()) break;
124 //Place on top of temp stack
125 temp
.push_front(targets
.front());
126 //Remove from targets
130 //Now that we have all the reads off until first non-read, we can
131 //place the invalidate on
132 targets
.push_front(target
);
134 //Now we pop off the temp_stack and put them back
135 while (!temp
.empty()) {
136 targets
.push_front(temp
.front());
141 targets
.push_back(target
);
145 assert(targets
.size() == ntargets
);
147 * @todo really prioritize the target commands.
150 if (!inService
&& target
->cmd
.isWrite()) {
161 "inService: %d thread: %d\n"
162 "Addr: %x asid: %d ntargets %d\n"
164 inService
, threadNum
, addr
, asid
, ntargets
);
166 TargetListIterator tar_it
= targets
.begin();
167 for (int i
= 0; i
< ntargets
; i
++) {
168 assert(tar_it
!= targets
.end());
170 ccprintf(cerr
, "\t%d: Addr: %x cmd: %d\n",
171 i
, (*tar_it
)->paddr
, (*tar_it
)->cmd
.toIndex());
175 ccprintf(cerr
, "\n");