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"
47 #include "sim/system.hh"
54 NetworkTest::CpuPort::recvTimingResp(PacketPtr pkt
)
56 networktest
->completeRequest(pkt
);
61 NetworkTest::CpuPort::recvRetry()
63 networktest
->doRetry();
67 NetworkTest::sendPkt(PacketPtr pkt
)
69 if (!cachePort
.sendTimingReq(pkt
)) {
70 retryPkt
= pkt
; // RubyPort will retry sending
75 NetworkTest::NetworkTest(const Params
*p
)
78 cachePort("network-test", this),
81 blockSizeBits(p
->block_offset
),
82 numMemories(p
->num_memories
),
83 simCycles(p
->sim_cycles
),
84 fixedPkts(p
->fixed_pkts
),
85 maxPackets(p
->max_packets
),
86 trafficType(p
->traffic_type
),
88 precision(p
->precision
),
89 masterId(p
->system
->getMasterId(name()))
93 schedule(tickEvent
, 0);
95 id
= TESTER_NETWORK
++;
96 DPRINTF(NetworkTest
,"Config Created: Name = %s , and id = %d\n",
101 NetworkTest::getMasterPort(const std::string
&if_name
, PortID idx
)
103 if (if_name
== "test")
106 return MemObject::getMasterPort(if_name
, idx
);
117 NetworkTest::completeRequest(PacketPtr pkt
)
119 Request
*req
= pkt
->req
;
121 DPRINTF(NetworkTest
, "Completed injection of %s packet for address %x\n",
122 pkt
->isWrite() ? "write" : "read\n",
125 assert(pkt
->isResponse());
126 noResponseCycles
= 0;
135 if (++noResponseCycles
>= 500000) {
136 cerr
<< name() << ": deadlocked at cycle " << curTick() << endl
;
140 // make new request based on injection rate
141 // (injection rate's range depends on precision)
142 // - generate a random number between 0 and 10^precision
143 // - send pkt if this number is < injRate*(10^precision)
144 bool send_this_cycle
;
145 double injRange
= pow((double) 10, (double) precision
);
146 unsigned trySending
= random() % (int) injRange
;
147 if (trySending
< injRate
*injRange
)
148 send_this_cycle
= true;
150 send_this_cycle
= false;
152 // always generatePkt unless fixedPkts is enabled
153 if (send_this_cycle
) {
155 if (numPacketsSent
< maxPackets
) {
164 if (curTick() >= simCycles
)
165 exitSimLoop("Network Tester completed simCycles");
167 if (!tickEvent
.scheduled())
168 schedule(tickEvent
, clockEdge(Cycles(1)));
173 NetworkTest::generatePkt()
175 unsigned destination
= id
;
176 if (trafficType
== 0) { // Uniform Random
177 destination
= random() % numMemories
;
178 } else if (trafficType
== 1) { // Tornado
179 int networkDimension
= (int) sqrt(numMemories
);
180 int my_x
= id
%networkDimension
;
181 int my_y
= id
/networkDimension
;
183 int dest_x
= my_x
+ (int) ceil(networkDimension
/2) - 1;
184 dest_x
= dest_x
%networkDimension
;
187 destination
= dest_y
*networkDimension
+ dest_x
;
188 } else if (trafficType
== 2) { // Bit Complement
189 int networkDimension
= (int) sqrt(numMemories
);
190 int my_x
= id
%networkDimension
;
191 int my_y
= id
/networkDimension
;
193 int dest_x
= networkDimension
- my_x
- 1;
194 int dest_y
= networkDimension
- my_y
- 1;
196 destination
= dest_y
*networkDimension
+ dest_x
;
199 Request
*req
= new Request();
200 Request::Flags flags
;
202 // The source of the packets is a cache.
203 // The destination of the packets is a directory.
204 // The destination bits are embedded in the address after byte-offset.
205 Addr paddr
= destination
;
206 paddr
<<= blockSizeBits
;
207 unsigned access_size
= 1; // Does not affect Ruby simulation
209 // Modeling different coherence msg types over different msg classes.
211 // networktest assumes the Network_test coherence protocol
212 // which models three message classes/virtual networks.
213 // These are: request, forward, response.
214 // requests and forwards are "control" packets (typically 8 bytes),
215 // while responses are "data" packets (typically 72 bytes).
217 // Life of a packet from the tester into the network:
218 // (1) This function generatePkt() generates packets of one of the
219 // following 3 types (randomly) : ReadReq, INST_FETCH, WriteReq
220 // (2) mem/ruby/system/RubyPort.cc converts these to RubyRequestType_LD,
221 // RubyRequestType_IFETCH, RubyRequestType_ST respectively
222 // (3) mem/ruby/system/Sequencer.cc sends these to the cache controllers
223 // in the coherence protocol.
224 // (4) Network_test-cache.sm tags RubyRequestType:LD,
225 // RubyRequestType:IFETCH and RubyRequestType:ST as
226 // Request, Forward, and Response events respectively;
227 // and injects them into virtual networks 0, 1 and 2 respectively.
228 // It immediately calls back the sequencer.
229 // (5) The packet traverses the network (simple/garnet) and reaches its
230 // destination (Directory), and network stats are updated.
231 // (6) Network_test-dir.sm simply drops the packet.
233 MemCmd::Command requestType
;
235 unsigned randomReqType
= random() % 3;
236 if (randomReqType
== 0) {
237 // generate packet for virtual network 0
238 requestType
= MemCmd::ReadReq
;
239 req
->setPhys(paddr
, access_size
, flags
, masterId
);
240 } else if (randomReqType
== 1) {
241 // generate packet for virtual network 1
242 requestType
= MemCmd::ReadReq
;
243 flags
.set(Request::INST_FETCH
);
244 req
->setVirt(0, 0x0, access_size
, flags
, 0x0, masterId
);
245 req
->setPaddr(paddr
);
246 } else { // if (randomReqType == 2)
247 // generate packet for virtual network 2
248 requestType
= MemCmd::WriteReq
;
249 req
->setPhys(paddr
, access_size
, flags
, masterId
);
252 req
->setThreadContext(id
,0);
254 //No need to do functional simulation
255 //We just do timing simulation of the network
258 "Generated packet with destination %d, embedded in address %x\n",
259 destination
, req
->getPaddr());
261 PacketPtr pkt
= new Packet(req
, requestType
);
262 pkt
->dataDynamicArray(new uint8_t[req
->getSize()]);
263 pkt
->senderState
= NULL
;
269 NetworkTest::doRetry()
271 if (cachePort
.sendTimingReq(retryPkt
)) {
277 NetworkTest::printAddr(Addr a
)
279 cachePort
.printAddr(a
);
284 NetworkTestParams::create()
286 return new NetworkTest(this);