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
32 // FIX ME: make trackBlkAddr use blocksize from actual cache, not hard coded
39 #include "base/misc.hh"
40 #include "base/statistics.hh"
41 #include "cpu/memtest/memtest.hh"
42 #include "mem/mem_object.hh"
43 #include "mem/port.hh"
44 #include "mem/packet.hh"
45 #include "mem/request.hh"
46 #include "sim/sim_events.hh"
47 #include "sim/stats.hh"
51 int TESTER_ALLOCATOR
=0;
54 MemTest::CpuPort::recvTiming(PacketPtr pkt
)
56 if (pkt
->isResponse()) {
57 memtest
->completeRequest(pkt
);
59 // must be snoop upcall
60 assert(pkt
->isRequest());
61 assert(pkt
->getDest() == Packet::Broadcast
);
67 MemTest::CpuPort::recvAtomic(PacketPtr pkt
)
69 // must be snoop upcall
70 assert(pkt
->isRequest());
71 assert(pkt
->getDest() == Packet::Broadcast
);
76 MemTest::CpuPort::recvFunctional(PacketPtr pkt
)
78 //Do nothing if we see one come through
79 // if (curTick != 0)//Supress warning durring initialization
80 // warn("Functional Writes not implemented in MemTester\n");
81 //Need to find any response values that intersect and update
86 MemTest::CpuPort::recvStatusChange(Status status
)
88 if (status
== RangeChange
) {
89 if (!snoopRangeSent
) {
90 snoopRangeSent
= true;
91 sendStatusChange(Port::RangeChange
);
96 panic("MemTest doesn't expect recvStatusChange callback!");
100 MemTest::CpuPort::recvRetry()
106 MemTest::sendPkt(PacketPtr pkt
) {
108 cachePort
.sendAtomic(pkt
);
109 completeRequest(pkt
);
111 else if (!cachePort
.sendTiming(pkt
)) {
118 MemTest::MemTest(const Params
*p
)
121 cachePort("test", this),
122 funcPort("functional", this),
124 // mainMem(main_mem),
125 // checkMem(check_mem),
126 size(p
->memory_size
),
127 percentReads(p
->percent_reads
),
128 percentFunctional(p
->percent_functional
),
129 percentUncacheable(p
->percent_uncacheable
),
130 progressInterval(p
->progress_interval
),
131 nextProgressMessage(p
->progress_interval
),
132 percentSourceUnaligned(p
->percent_source_unaligned
),
133 percentDestUnaligned(p
->percent_dest_unaligned
),
134 maxLoads(p
->max_loads
),
138 cmd
.push_back("/bin/ls");
139 vector
<string
> null_vec
;
140 // thread = new SimpleThread(NULL, 0, NULL, 0, mainMem);
143 cachePort
.snoopRangeSent
= false;
144 funcPort
.snoopRangeSent
= true;
146 // Needs to be masked off once we know the block size.
147 traceBlockAddr
= p
->trace_addr
;
148 baseAddr1
= 0x100000;
149 baseAddr2
= 0x400000;
150 uncacheAddr
= 0x800000;
153 noResponseCycles
= 0;
155 schedule(tickEvent
, 0);
157 id
= TESTER_ALLOCATOR
++;
163 MemTest::getPort(const std::string
&if_name
, int idx
)
165 if (if_name
== "functional")
167 else if (if_name
== "test")
170 panic("No Such Port\n");
176 // By the time init() is called, the ports should be hooked up.
177 blockSize
= cachePort
.peerBlockSize();
178 blockAddrMask
= blockSize
- 1;
179 traceBlockAddr
= blockAddr(traceBlockAddr
);
181 // initial memory contents for both physical memory and functional
182 // memory should be 0; no need to initialize them.
187 MemTest::completeRequest(PacketPtr pkt
)
189 Request
*req
= pkt
->req
;
191 DPRINTF(MemTest
, "completing %s at address %x (blk %x)\n",
192 pkt
->isWrite() ? "write" : "read",
193 req
->getPaddr(), blockAddr(req
->getPaddr()));
195 MemTestSenderState
*state
=
196 dynamic_cast<MemTestSenderState
*>(pkt
->senderState
);
198 uint8_t *data
= state
->data
;
199 uint8_t *pkt_data
= pkt
->getPtr
<uint8_t>();
201 //Remove the address from the list of outstanding
202 std::set
<unsigned>::iterator removeAddr
=
203 outstandingAddrs
.find(req
->getPaddr());
204 assert(removeAddr
!= outstandingAddrs
.end());
205 outstandingAddrs
.erase(removeAddr
);
207 assert(pkt
->isResponse());
210 if (memcmp(pkt_data
, data
, pkt
->getSize()) != 0) {
211 panic("%s: read of %x (blk %x) @ cycle %d "
212 "returns %x, expected %x\n", name(),
213 req
->getPaddr(), blockAddr(req
->getPaddr()), curTick
,
220 if (numReads
== nextProgressMessage
) {
221 ccprintf(cerr
, "%s: completed %d read accesses @%d\n",
222 name(), numReads
, curTick
);
223 nextProgressMessage
+= progressInterval
;
226 if (maxLoads
!= 0 && numReads
>= maxLoads
)
227 exitSimLoop("maximum number of loads reached");
229 assert(pkt
->isWrite());
233 noResponseCycles
= 0;
243 using namespace Stats
;
246 .name(name() + ".num_reads")
247 .desc("number of read accesses completed")
251 .name(name() + ".num_writes")
252 .desc("number of write accesses completed")
256 .name(name() + ".num_copies")
257 .desc("number of copy accesses completed")
264 if (!tickEvent
.scheduled())
265 schedule(tickEvent
, curTick
+ ticks(1));
267 if (++noResponseCycles
>= 500000) {
268 cerr
<< name() << ": deadlocked at cycle " << curTick
<< endl
;
277 unsigned cmd
= random() % 100;
278 unsigned offset
= random() % size
;
279 unsigned base
= random() % 2;
280 uint64_t data
= random();
281 unsigned access_size
= random() % 4;
282 unsigned cacheable
= random() % 100;
284 //If we aren't doing copies, use id as offset, and do a false sharing
286 //We can eliminate the lower bits of the offset, and then use the id
287 //to offset within the blks
288 offset
= blockAddr(offset
);
292 Request
*req
= new Request();
296 if (cacheable
< percentUncacheable
) {
297 flags
|= UNCACHEABLE
;
298 paddr
= uncacheAddr
+ offset
;
300 paddr
= ((base
) ? baseAddr1
: baseAddr2
) + offset
;
302 bool probe
= (random() % 100 < percentFunctional
) && !(flags
& UNCACHEABLE
);
303 //bool probe = false;
305 paddr
&= ~((1 << access_size
) - 1);
306 req
->setPhys(paddr
, 1 << access_size
, flags
);
307 req
->setThreadContext(id
,0);
309 uint8_t *result
= new uint8_t[8];
311 if (cmd
< percentReads
) {
314 // For now we only allow one outstanding request per address
315 // per tester This means we assume CPU does write forwarding
316 // to reads that alias something in the cpu store buffer.
317 if (outstandingAddrs
.find(paddr
) != outstandingAddrs
.end()) {
323 outstandingAddrs
.insert(paddr
);
325 // ***** NOTE FOR RON: I'm not sure how to access checkMem. - Kevin
326 funcPort
.readBlob(req
->getPaddr(), result
, req
->getSize());
329 "initiating read at address %x (blk %x) expecting %x\n",
330 req
->getPaddr(), blockAddr(req
->getPaddr()), *result
);
332 PacketPtr pkt
= new Packet(req
, MemCmd::ReadReq
, Packet::Broadcast
);
334 pkt
->dataDynamicArray(new uint8_t[req
->getSize()]);
335 MemTestSenderState
*state
= new MemTestSenderState(result
);
336 pkt
->senderState
= state
;
339 cachePort
.sendFunctional(pkt
);
340 completeRequest(pkt
);
347 // For now we only allow one outstanding request per addreess
348 // per tester. This means we assume CPU does write forwarding
349 // to reads that alias something in the cpu store buffer.
350 if (outstandingAddrs
.find(paddr
) != outstandingAddrs
.end()) {
356 outstandingAddrs
.insert(paddr
);
358 DPRINTF(MemTest
, "initiating write at address %x (blk %x) value %x\n",
359 req
->getPaddr(), blockAddr(req
->getPaddr()), data
& 0xff);
361 PacketPtr pkt
= new Packet(req
, MemCmd::WriteReq
, Packet::Broadcast
);
363 uint8_t *pkt_data
= new uint8_t[req
->getSize()];
364 pkt
->dataDynamicArray(pkt_data
);
365 memcpy(pkt_data
, &data
, req
->getSize());
366 MemTestSenderState
*state
= new MemTestSenderState(result
);
367 pkt
->senderState
= state
;
369 funcPort
.writeBlob(req
->getPaddr(), pkt_data
, req
->getSize());
372 cachePort
.sendFunctional(pkt
);
373 completeRequest(pkt
);
383 if (cachePort
.sendTiming(retryPkt
)) {
391 MemTest::printAddr(Addr a
)
393 cachePort
.printAddr(a
);
398 MemTestParams::create()
400 return new MemTest(this);