2 * Copyright (c) 2012-2014 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include "mem/mem_checker_monitor.hh"
42 #include "base/logging.hh"
43 #include "base/output.hh"
44 #include "base/trace.hh"
45 #include "debug/MemCheckerMonitor.hh"
47 MemCheckerMonitor::MemCheckerMonitor(Params
* params
)
49 masterPort(name() + "-master", *this),
50 slavePort(name() + "-slave", *this),
51 warnOnly(params
->warn_only
),
52 memchecker(params
->memchecker
)
55 MemCheckerMonitor::~MemCheckerMonitor()
59 MemCheckerMonitorParams::create()
61 return new MemCheckerMonitor(this);
65 MemCheckerMonitor::init()
67 // make sure both sides of the monitor are connected
68 if (!slavePort
.isConnected() || !masterPort
.isConnected())
69 fatal("Communication monitor is not connected on both sides.\n");
73 MemCheckerMonitor::getPort(const std::string
&if_name
, PortID idx
)
75 if (if_name
== "master" || if_name
== "mem_side") {
77 } else if (if_name
== "slave" || if_name
== "cpu_side") {
80 return SimObject::getPort(if_name
, idx
);
85 MemCheckerMonitor::recvFunctional(PacketPtr pkt
)
87 Addr addr
= pkt
->getAddr();
88 unsigned size
= pkt
->getSize();
90 // Conservatively reset this address-range. Alternatively we could try to
91 // update the values seen by the memchecker, however, there may be other
92 // reads/writes to these location from other devices we do not see.
93 memchecker
->reset(addr
, size
);
95 masterPort
.sendFunctional(pkt
);
97 DPRINTF(MemCheckerMonitor
,
98 "Forwarded functional access: addr = %#llx, size = %d\n",
103 MemCheckerMonitor::recvFunctionalSnoop(PacketPtr pkt
)
105 Addr addr
= pkt
->getAddr();
106 unsigned size
= pkt
->getSize();
109 memchecker
->reset(addr
, size
);
111 slavePort
.sendFunctionalSnoop(pkt
);
113 DPRINTF(MemCheckerMonitor
,
114 "Received functional snoop: addr = %#llx, size = %d\n",
119 MemCheckerMonitor::recvAtomic(PacketPtr pkt
)
121 panic("Atomic not supported");
125 MemCheckerMonitor::recvAtomicSnoop(PacketPtr pkt
)
127 panic("Atomic not supported");
131 MemCheckerMonitor::recvTimingReq(PacketPtr pkt
)
133 // should always see a request
134 assert(pkt
->isRequest());
136 // Store relevant fields of packet, because packet may be modified
137 // or even deleted when sendTiming() is called.
139 // For reads we are only interested in real reads, and not prefetches, as
140 // it is not guaranteed that the prefetch returns any useful data.
141 bool is_read
= pkt
->isRead() && !pkt
->req
->isPrefetch();
142 bool is_write
= pkt
->isWrite();
143 unsigned size
= pkt
->getSize();
144 Addr addr
= pkt
->getAddr();
145 bool expects_response
= pkt
->needsResponse() && !pkt
->cacheResponding();
146 std::unique_ptr
<uint8_t[]> pkt_data
;
147 MemCheckerMonitorSenderState
* state
= NULL
;
149 if (expects_response
&& is_write
) {
150 // On receipt of a request, only need to allocate pkt_data if this is a
151 // write. For reads, we have no data yet, so it doesn't make sense to
153 pkt_data
.reset(new uint8_t[size
]);
154 pkt
->writeData(pkt_data
.get());
157 // If a cache miss is served by a cache, a monitor near the memory
158 // would see a request which needs a response, but this response
159 // would not come back from the memory. Therefore
160 // we additionally have to check the inhibit flag.
161 if (expects_response
&& (is_read
|| is_write
)) {
162 state
= new MemCheckerMonitorSenderState(0);
163 pkt
->pushSenderState(state
);
166 // Attempt to send the packet
167 bool successful
= masterPort
.sendTimingReq(pkt
);
169 // If not successful, restore the sender state
170 if (!successful
&& expects_response
&& (is_read
|| is_write
)) {
171 delete pkt
->popSenderState();
174 if (successful
&& expects_response
) {
176 MemChecker::Serial serial
= memchecker
->startRead(curTick(),
180 // At the time where we push the sender-state, we do not yet know
181 // the serial the MemChecker class will assign to this request. We
182 // cannot call startRead at the time we push the sender-state, as
183 // the masterPort may not be successful in executing sendTimingReq,
184 // and in case of a failure, we must not modify the state of the
187 // Once we know that sendTimingReq was successful, we can set the
188 // serial of the newly constructed sender-state. This is legal, as
189 // we know that nobody else will touch nor is responsible for
190 // deletion of our sender-state.
191 state
->serial
= serial
;
193 DPRINTF(MemCheckerMonitor
,
194 "Forwarded read request: serial = %d, addr = %#llx, "
197 } else if (is_write
) {
198 MemChecker::Serial serial
= memchecker
->startWrite(curTick(),
203 state
->serial
= serial
;
205 DPRINTF(MemCheckerMonitor
,
206 "Forwarded write request: serial = %d, addr = %#llx, "
210 DPRINTF(MemCheckerMonitor
,
211 "Forwarded non read/write request: addr = %#llx\n", addr
);
213 } else if (successful
) {
214 DPRINTF(MemCheckerMonitor
,
215 "Forwarded request marked for cache response: addr = %#llx\n",
223 MemCheckerMonitor::recvTimingResp(PacketPtr pkt
)
225 // should always see responses
226 assert(pkt
->isResponse());
228 // Store relevant fields of packet, because packet may be modified
229 // or even deleted when sendTiming() is called.
230 bool is_read
= pkt
->isRead() && !pkt
->req
->isPrefetch();
231 bool is_write
= pkt
->isWrite();
232 bool is_failed_LLSC
= pkt
->isLLSC() && pkt
->req
->getExtraData() == 0;
233 unsigned size
= pkt
->getSize();
234 Addr addr
= pkt
->getAddr();
235 std::unique_ptr
<uint8_t[]> pkt_data
;
236 MemCheckerMonitorSenderState
* received_state
= NULL
;
239 // On receipt of a response, only need to allocate pkt_data if this is
240 // a read. For writes, we have already given the MemChecker the data on
241 // the request, so it doesn't make sense to allocate on write.
242 pkt_data
.reset(new uint8_t[size
]);
243 pkt
->writeData(pkt_data
.get());
246 if (is_read
|| is_write
) {
248 dynamic_cast<MemCheckerMonitorSenderState
*>(pkt
->senderState
);
250 // Restore initial sender state
251 panic_if(received_state
== NULL
,
252 "Monitor got a response without monitor sender state\n");
255 pkt
->senderState
= received_state
->predecessor
;
258 // Attempt to send the packet
259 bool successful
= slavePort
.sendTimingResp(pkt
);
261 // If packet successfully send, complete transaction in MemChecker
262 // instance, and delete sender state, otherwise restore state.
265 DPRINTF(MemCheckerMonitor
,
266 "Received read response: serial = %d, addr = %#llx, "
268 received_state
->serial
, addr
, size
);
270 bool result
= memchecker
->completeRead(received_state
->serial
,
277 warn("%s: read of %#llx @ cycle %d failed:\n%s\n",
280 memchecker
->getErrorMessage().c_str());
282 panic_if(!warnOnly
, "MemChecker violation!");
285 delete received_state
;
286 } else if (is_write
) {
287 DPRINTF(MemCheckerMonitor
,
288 "Received write response: serial = %d, addr = %#llx, "
290 received_state
->serial
, addr
, size
);
292 if (is_failed_LLSC
) {
293 // The write was not successful, let MemChecker know.
294 memchecker
->abortWrite(received_state
->serial
,
298 memchecker
->completeWrite(received_state
->serial
,
304 delete received_state
;
306 DPRINTF(MemCheckerMonitor
,
307 "Received non read/write response: addr = %#llx\n", addr
);
309 } else if (is_read
|| is_write
) {
310 // Don't delete anything and let the packet look like we
312 pkt
->senderState
= received_state
;
319 MemCheckerMonitor::recvTimingSnoopReq(PacketPtr pkt
)
321 slavePort
.sendTimingSnoopReq(pkt
);
325 MemCheckerMonitor::recvTimingSnoopResp(PacketPtr pkt
)
327 return masterPort
.sendTimingSnoopResp(pkt
);
331 MemCheckerMonitor::isSnooping() const
333 // check if the connected master port is snooping
334 return slavePort
.isSnooping();
338 MemCheckerMonitor::getAddrRanges() const
340 // get the address ranges of the connected slave port
341 return masterPort
.getAddrRanges();
345 MemCheckerMonitor::recvReqRetry()
347 slavePort
.sendRetryReq();
351 MemCheckerMonitor::recvRespRetry()
353 masterPort
.sendRetryResp();
357 MemCheckerMonitor::recvRangeChange()
359 slavePort
.sendRangeChange();