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::recvRangeChange()
89 NetworkTest::CpuPort::recvRetry()
91 networktest
->doRetry();
95 NetworkTest::sendPkt(PacketPtr pkt
)
97 if (!cachePort
.sendTiming(pkt
)) {
98 retryPkt
= pkt
; // RubyPort will retry sending
103 NetworkTest::NetworkTest(const Params
*p
)
106 cachePort("network-test", this),
108 size(p
->memory_size
),
109 blockSizeBits(p
->block_offset
),
110 numMemories(p
->num_memories
),
111 simCycles(p
->sim_cycles
),
112 fixedPkts(p
->fixed_pkts
),
113 maxPackets(p
->max_packets
),
114 trafficType(p
->traffic_type
),
115 injRate(p
->inj_rate
),
116 precision(p
->precision
)
119 noResponseCycles
= 0;
120 schedule(tickEvent
, 0);
122 id
= TESTER_NETWORK
++;
123 DPRINTF(NetworkTest
,"Config Created: Name = %s , and id = %d\n",
128 NetworkTest::getPort(const std::string
&if_name
, int idx
)
130 if (if_name
== "test")
133 panic("No Such Port\n");
144 NetworkTest::completeRequest(PacketPtr pkt
)
146 Request
*req
= pkt
->req
;
148 DPRINTF(NetworkTest
, "Completed injection of %s packet for address %x\n",
149 pkt
->isWrite() ? "write" : "read\n",
152 assert(pkt
->isResponse());
153 noResponseCycles
= 0;
162 if (++noResponseCycles
>= 500000) {
163 cerr
<< name() << ": deadlocked at cycle " << curTick() << endl
;
167 // make new request based on injection rate
168 // (injection rate's range depends on precision)
169 // - generate a random number between 0 and 10^precision
170 // - send pkt if this number is < injRate*(10^precision)
171 bool send_this_cycle
;
172 double injRange
= pow((double) 10, (double) precision
);
173 unsigned trySending
= random() % (int) injRange
;
174 if (trySending
< injRate
*injRange
)
175 send_this_cycle
= true;
177 send_this_cycle
= false;
179 // always generatePkt unless fixedPkts is enabled
180 if (send_this_cycle
) {
182 if (numPacketsSent
< maxPackets
) {
191 if (curTick() >= simCycles
)
192 exitSimLoop("Network Tester completed simCycles");
194 if (!tickEvent
.scheduled())
195 schedule(tickEvent
, curTick() + ticks(1));
200 NetworkTest::generatePkt()
202 unsigned destination
= id
;
203 if (trafficType
== 0) { // Uniform Random
204 destination
= random() % numMemories
;
205 } else if (trafficType
== 1) { // Tornado
206 int networkDimension
= (int) sqrt(numMemories
);
207 int my_x
= id
%networkDimension
;
208 int my_y
= id
/networkDimension
;
210 int dest_x
= my_x
+ (int) ceil(networkDimension
/2) - 1;
211 dest_x
= dest_x
%networkDimension
;
214 destination
= dest_y
*networkDimension
+ dest_x
;
215 } else if (trafficType
== 2) { // Bit Complement
216 int networkDimension
= (int) sqrt(numMemories
);
217 int my_x
= id
%networkDimension
;
218 int my_y
= id
/networkDimension
;
220 int dest_x
= networkDimension
- my_x
- 1;
221 int dest_y
= networkDimension
- my_y
- 1;
223 destination
= dest_y
*networkDimension
+ dest_x
;
226 Request
*req
= new Request();
227 Request::Flags flags
;
229 // The source of the packets is a cache.
230 // The destination of the packets is a directory.
231 // The destination bits are embedded in the address after byte-offset.
232 Addr paddr
= destination
;
233 paddr
<<= blockSizeBits
;
234 unsigned access_size
= 1; // Does not affect Ruby simulation
236 // Modeling different coherence msg types over different msg classes.
238 // networktest assumes the Network_test coherence protocol
239 // which models three message classes/virtual networks.
240 // These are: request, forward, response.
241 // requests and forwards are "control" packets (typically 8 bytes),
242 // while responses are "data" packets (typically 72 bytes).
244 // Life of a packet from the tester into the network:
245 // (1) This function generatePkt() generates packets of one of the
246 // following 3 types (randomly) : ReadReq, INST_FETCH, WriteReq
247 // (2) mem/ruby/system/RubyPort.cc converts these to RubyRequestType_LD,
248 // RubyRequestType_IFETCH, RubyRequestType_ST respectively
249 // (3) mem/ruby/system/Sequencer.cc sends these to the cache controllers
250 // in the coherence protocol.
251 // (4) Network_test-cache.sm tags RubyRequestType:LD,
252 // RubyRequestType:IFETCH and RubyRequestType:ST as
253 // Request, Forward, and Response events respectively;
254 // and injects them into virtual networks 0, 1 and 2 respectively.
255 // It immediately calls back the sequencer.
256 // (5) The packet traverses the network (simple/garnet) and reaches its
257 // destination (Directory), and network stats are updated.
258 // (6) Network_test-dir.sm simply drops the packet.
260 MemCmd::Command requestType
;
262 unsigned randomReqType
= random() % 3;
263 if (randomReqType
== 0) {
264 // generate packet for virtual network 0
265 requestType
= MemCmd::ReadReq
;
266 req
->setPhys(paddr
, access_size
, flags
);
267 } else if (randomReqType
== 1) {
268 // generate packet for virtual network 1
269 requestType
= MemCmd::ReadReq
;
270 flags
.set(Request::INST_FETCH
);
271 req
->setVirt(0, 0x0, access_size
, flags
, 0x0);
272 req
->setPaddr(paddr
);
273 } else { // if (randomReqType == 2)
274 // generate packet for virtual network 2
275 requestType
= MemCmd::WriteReq
;
276 req
->setPhys(paddr
, access_size
, flags
);
279 req
->setThreadContext(id
,0);
280 uint8_t *result
= new uint8_t[8];
282 //No need to do functional simulation
283 //We just do timing simulation of the network
286 "Generated packet with destination %d, embedded in address %x\n",
287 destination
, req
->getPaddr());
289 PacketPtr pkt
= new Packet(req
, requestType
, 0);
290 pkt
->setSrc(0); //Not used
291 pkt
->dataDynamicArray(new uint8_t[req
->getSize()]);
292 NetworkTestSenderState
*state
= new NetworkTestSenderState(result
);
293 pkt
->senderState
= state
;
299 NetworkTest::doRetry()
301 if (cachePort
.sendTiming(retryPkt
)) {
307 NetworkTest::printAddr(Addr a
)
309 cachePort
.printAddr(a
);
314 NetworkTestParams::create()
316 return new NetworkTest(this);