2 * Copyright (c) 2009 Advanced Micro Devices, Inc.
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: Tushar Krishna
37 #include "base/misc.hh"
38 #include "base/statistics.hh"
39 #include "cpu/testers/networktest/networktest.hh"
40 #include "debug/NetworkTest.hh"
41 #include "mem/mem_object.hh"
42 #include "mem/packet.hh"
43 #include "mem/port.hh"
44 #include "mem/request.hh"
45 #include "sim/sim_events.hh"
46 #include "sim/stats.hh"
53 NetworkTest::CpuPort::recvTiming(PacketPtr pkt
)
55 if (pkt
->isResponse()) {
56 networktest
->completeRequest(pkt
);
58 // must be snoop upcall
59 assert(pkt
->isRequest());
60 assert(pkt
->getDest() == Packet::Broadcast
);
66 NetworkTest::CpuPort::recvAtomic(PacketPtr pkt
)
68 panic("NetworkTest doesn't expect recvAtomic call!");
70 assert(pkt
->isRequest());
71 assert(pkt
->getDest() == Packet::Broadcast
);
76 NetworkTest::CpuPort::recvFunctional(PacketPtr pkt
)
78 panic("NetworkTest doesn't expect recvFunctional call!");
84 NetworkTest::CpuPort::recvStatusChange(Status status
)
86 if (status
== RangeChange
) {
87 if (!snoopRangeSent
) {
88 snoopRangeSent
= true;
89 sendStatusChange(Port::RangeChange
);
94 panic("NetworkTest doesn't expect recvStatusChange callback!");
98 NetworkTest::CpuPort::recvRetry()
100 networktest
->doRetry();
104 NetworkTest::sendPkt(PacketPtr pkt
)
106 if (cachePort
.sendTiming(pkt
)) {
115 NetworkTest::NetworkTest(const Params
*p
)
118 cachePort("network-test", this),
120 size(p
->memory_size
),
121 blockSizeBits(p
->block_offset
),
122 numMemories(p
->num_memories
),
123 fixedPkts(p
->fixed_pkts
),
124 maxPackets(p
->max_packets
),
125 trafficType(p
->traffic_type
),
126 injRate(p
->inj_rate
),
127 precision(p
->precision
)
129 cachePort
.snoopRangeSent
= false;
132 noResponseCycles
= 0;
133 schedule(tickEvent
, 0);
135 id
= TESTER_NETWORK
++;
136 DPRINTF(NetworkTest
,"Config Created: Name = %s , and id = %d\n",
143 NetworkTest::getPort(const std::string
&if_name
, int idx
)
145 if (if_name
== "test")
148 panic("No Such Port\n");
159 NetworkTest::completeRequest(PacketPtr pkt
)
161 Request
*req
= pkt
->req
;
163 DPRINTF(NetworkTest
, "Completed injection of %s packet for address %x\n",
164 pkt
->isWrite() ? "write" : "read\n",
167 assert(pkt
->isResponse());
168 noResponseCycles
= 0;
177 if (!tickEvent
.scheduled())
178 schedule(tickEvent
, curTick() + ticks(1));
180 if (++noResponseCycles
>= 500000) {
181 cerr
<< name() << ": deadlocked at cycle " << curTick() << endl
;
190 // make new request based on injection rate
191 // (injection rate's range depends on precision)
192 // - generate a random number between 0 and 10^precision
193 // - send pkt if this number is < injRate*(10^precision)
194 bool send_this_cycle
;
195 double injRange
= pow((double) 10, (double) precision
);
196 unsigned trySending
= random() % (int) injRange
;
197 if (trySending
< injRate
*injRange
)
198 send_this_cycle
= true;
200 send_this_cycle
= false;
202 // always generatePkt unless fixedPkts is enabled
203 if (send_this_cycle
) {
205 if (numPacketsSent
< maxPackets
) {
215 NetworkTest::generatePkt()
217 unsigned destination
= id
;
218 if (trafficType
== 0) { // Uniform Random
219 while (destination
== id
)
220 destination
= random() % numMemories
;
221 } else if (trafficType
== 1) { // Tornado
222 int networkDimension
= (int) sqrt(numMemories
);
223 int my_x
= id
%networkDimension
;
224 int my_y
= id
/networkDimension
;
226 int dest_x
= my_x
+ (int) ceil(networkDimension
/2) - 1;
227 dest_x
= dest_x
%networkDimension
;
230 destination
= dest_y
*networkDimension
+ dest_x
;
231 } else if (trafficType
== 2) { // Bit Complement
232 int networkDimension
= (int) sqrt(numMemories
);
233 int my_x
= id
%networkDimension
;
234 int my_y
= id
/networkDimension
;
236 int dest_x
= networkDimension
- my_x
- 1;
237 int dest_y
= networkDimension
- my_y
- 1;
239 destination
= dest_y
*networkDimension
+ dest_x
;
242 Request
*req
= new Request();
243 Request::Flags flags
;
245 // The source of the packets is a cache.
246 // The destination of the packets is a directory.
247 // The destination bits are embedded in the address after byte-offset.
248 Addr paddr
= destination
;
249 paddr
<<= blockSizeBits
;
250 unsigned access_size
= 1; // Does not affect Ruby simulation
252 // Modeling different coherence msg types over different msg classes.
254 // networktest assumes the Network_test coherence protocol
255 // which models three message classes/virtual networks.
256 // These are: request, forward, response.
257 // requests and forwards are "control" packets (typically 8 bytes),
258 // while responses are "data" packets (typically 72 bytes).
260 // Life of a packet from the tester into the network:
261 // (1) This function generatePkt() generates packets of one of the
262 // following 3 types (randomly) : ReadReq, INST_FETCH, WriteReq
263 // (2) mem/ruby/system/RubyPort.cc converts these to RubyRequestType_LD,
264 // RubyRequestType_IFETCH, RubyRequestType_ST respectively
265 // (3) mem/ruby/system/Sequencer.cc sends these to the cache controllers
266 // in the coherence protocol.
267 // (4) Network_test-cache.sm tags RubyRequestType:LD,
268 // RubyRequestType:IFETCH and RubyRequestType:ST as
269 // Request, Forward, and Response events respectively;
270 // and injects them into virtual networks 0, 1 and 2 respectively.
271 // It immediately calls back the sequencer.
272 // (5) The packet traverses the network (simple/garnet) and reaches its
273 // destination (Directory), and network stats are updated.
274 // (6) Network_test-dir.sm simply drops the packet.
276 MemCmd::Command requestType
;
278 unsigned randomReqType
= random() % 3;
279 if (randomReqType
== 0) {
280 // generate packet for virtual network 0
281 requestType
= MemCmd::ReadReq
;
282 req
->setPhys(paddr
, access_size
, flags
);
283 } else if (randomReqType
== 1) {
284 // generate packet for virtual network 1
285 requestType
= MemCmd::ReadReq
;
286 flags
.set(Request::INST_FETCH
);
287 req
->setVirt(0, 0x0, access_size
, flags
, 0x0);
288 req
->setPaddr(paddr
);
289 } else { // if (randomReqType == 2)
290 // generate packet for virtual network 2
291 requestType
= MemCmd::WriteReq
;
292 req
->setPhys(paddr
, access_size
, flags
);
295 req
->setThreadContext(id
,0);
296 uint8_t *result
= new uint8_t[8];
298 //No need to do functional simulation
299 //We just do timing simulation of the network
302 "Generated packet with destination %d, embedded in address %x\n",
303 destination
, req
->getPaddr());
305 PacketPtr pkt
= new Packet(req
, requestType
, 0);
306 pkt
->setSrc(0); //Not used
307 pkt
->dataDynamicArray(new uint8_t[req
->getSize()]);
308 NetworkTestSenderState
*state
= new NetworkTestSenderState(result
);
309 pkt
->senderState
= state
;
315 NetworkTest::doRetry()
317 if (cachePort
.sendTiming(retryPkt
)) {
324 NetworkTest::printAddr(Addr a
)
326 cachePort
.printAddr(a
);
331 NetworkTestParams::create()
333 return new NetworkTest(this);