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::recvTiming(PacketPtr pkt
)
56 if (pkt
->isResponse()) {
57 networktest
->completeRequest(pkt
);
59 // must be snoop upcall
60 assert(pkt
->isRequest());
61 assert(pkt
->getDest() == Packet::Broadcast
);
67 NetworkTest::CpuPort::recvAtomic(PacketPtr pkt
)
69 panic("NetworkTest doesn't expect recvAtomic call!");
71 assert(pkt
->isRequest());
72 assert(pkt
->getDest() == Packet::Broadcast
);
77 NetworkTest::CpuPort::recvFunctional(PacketPtr pkt
)
79 panic("NetworkTest doesn't expect recvFunctional call!");
85 NetworkTest::CpuPort::recvRangeChange()
90 NetworkTest::CpuPort::recvRetry()
92 networktest
->doRetry();
96 NetworkTest::sendPkt(PacketPtr pkt
)
98 if (!cachePort
.sendTiming(pkt
)) {
99 retryPkt
= pkt
; // RubyPort will retry sending
104 NetworkTest::NetworkTest(const Params
*p
)
107 cachePort("network-test", this),
109 size(p
->memory_size
),
110 blockSizeBits(p
->block_offset
),
111 numMemories(p
->num_memories
),
112 simCycles(p
->sim_cycles
),
113 fixedPkts(p
->fixed_pkts
),
114 maxPackets(p
->max_packets
),
115 trafficType(p
->traffic_type
),
116 injRate(p
->inj_rate
),
117 precision(p
->precision
),
118 masterId(p
->system
->getMasterId(name()))
121 noResponseCycles
= 0;
122 schedule(tickEvent
, 0);
124 id
= TESTER_NETWORK
++;
125 DPRINTF(NetworkTest
,"Config Created: Name = %s , and id = %d\n",
130 NetworkTest::getPort(const std::string
&if_name
, int idx
)
132 if (if_name
== "test")
135 panic("No Such Port\n");
146 NetworkTest::completeRequest(PacketPtr pkt
)
148 Request
*req
= pkt
->req
;
150 DPRINTF(NetworkTest
, "Completed injection of %s packet for address %x\n",
151 pkt
->isWrite() ? "write" : "read\n",
154 assert(pkt
->isResponse());
155 noResponseCycles
= 0;
164 if (++noResponseCycles
>= 500000) {
165 cerr
<< name() << ": deadlocked at cycle " << curTick() << endl
;
169 // make new request based on injection rate
170 // (injection rate's range depends on precision)
171 // - generate a random number between 0 and 10^precision
172 // - send pkt if this number is < injRate*(10^precision)
173 bool send_this_cycle
;
174 double injRange
= pow((double) 10, (double) precision
);
175 unsigned trySending
= random() % (int) injRange
;
176 if (trySending
< injRate
*injRange
)
177 send_this_cycle
= true;
179 send_this_cycle
= false;
181 // always generatePkt unless fixedPkts is enabled
182 if (send_this_cycle
) {
184 if (numPacketsSent
< maxPackets
) {
193 if (curTick() >= simCycles
)
194 exitSimLoop("Network Tester completed simCycles");
196 if (!tickEvent
.scheduled())
197 schedule(tickEvent
, curTick() + ticks(1));
202 NetworkTest::generatePkt()
204 unsigned destination
= id
;
205 if (trafficType
== 0) { // Uniform Random
206 destination
= random() % numMemories
;
207 } else if (trafficType
== 1) { // Tornado
208 int networkDimension
= (int) sqrt(numMemories
);
209 int my_x
= id
%networkDimension
;
210 int my_y
= id
/networkDimension
;
212 int dest_x
= my_x
+ (int) ceil(networkDimension
/2) - 1;
213 dest_x
= dest_x
%networkDimension
;
216 destination
= dest_y
*networkDimension
+ dest_x
;
217 } else if (trafficType
== 2) { // Bit Complement
218 int networkDimension
= (int) sqrt(numMemories
);
219 int my_x
= id
%networkDimension
;
220 int my_y
= id
/networkDimension
;
222 int dest_x
= networkDimension
- my_x
- 1;
223 int dest_y
= networkDimension
- my_y
- 1;
225 destination
= dest_y
*networkDimension
+ dest_x
;
228 Request
*req
= new Request();
229 Request::Flags flags
;
231 // The source of the packets is a cache.
232 // The destination of the packets is a directory.
233 // The destination bits are embedded in the address after byte-offset.
234 Addr paddr
= destination
;
235 paddr
<<= blockSizeBits
;
236 unsigned access_size
= 1; // Does not affect Ruby simulation
238 // Modeling different coherence msg types over different msg classes.
240 // networktest assumes the Network_test coherence protocol
241 // which models three message classes/virtual networks.
242 // These are: request, forward, response.
243 // requests and forwards are "control" packets (typically 8 bytes),
244 // while responses are "data" packets (typically 72 bytes).
246 // Life of a packet from the tester into the network:
247 // (1) This function generatePkt() generates packets of one of the
248 // following 3 types (randomly) : ReadReq, INST_FETCH, WriteReq
249 // (2) mem/ruby/system/RubyPort.cc converts these to RubyRequestType_LD,
250 // RubyRequestType_IFETCH, RubyRequestType_ST respectively
251 // (3) mem/ruby/system/Sequencer.cc sends these to the cache controllers
252 // in the coherence protocol.
253 // (4) Network_test-cache.sm tags RubyRequestType:LD,
254 // RubyRequestType:IFETCH and RubyRequestType:ST as
255 // Request, Forward, and Response events respectively;
256 // and injects them into virtual networks 0, 1 and 2 respectively.
257 // It immediately calls back the sequencer.
258 // (5) The packet traverses the network (simple/garnet) and reaches its
259 // destination (Directory), and network stats are updated.
260 // (6) Network_test-dir.sm simply drops the packet.
262 MemCmd::Command requestType
;
264 unsigned randomReqType
= random() % 3;
265 if (randomReqType
== 0) {
266 // generate packet for virtual network 0
267 requestType
= MemCmd::ReadReq
;
268 req
->setPhys(paddr
, access_size
, flags
, masterId
);
269 } else if (randomReqType
== 1) {
270 // generate packet for virtual network 1
271 requestType
= MemCmd::ReadReq
;
272 flags
.set(Request::INST_FETCH
);
273 req
->setVirt(0, 0x0, access_size
, flags
, 0x0, masterId
);
274 req
->setPaddr(paddr
);
275 } else { // if (randomReqType == 2)
276 // generate packet for virtual network 2
277 requestType
= MemCmd::WriteReq
;
278 req
->setPhys(paddr
, access_size
, flags
, masterId
);
281 req
->setThreadContext(id
,0);
282 uint8_t *result
= new uint8_t[8];
284 //No need to do functional simulation
285 //We just do timing simulation of the network
288 "Generated packet with destination %d, embedded in address %x\n",
289 destination
, req
->getPaddr());
291 PacketPtr pkt
= new Packet(req
, requestType
, 0);
292 pkt
->setSrc(0); //Not used
293 pkt
->dataDynamicArray(new uint8_t[req
->getSize()]);
294 NetworkTestSenderState
*state
= new NetworkTestSenderState(result
);
295 pkt
->senderState
= state
;
301 NetworkTest::doRetry()
303 if (cachePort
.sendTiming(retryPkt
)) {
309 NetworkTest::printAddr(Addr a
)
311 cachePort
.printAddr(a
);
316 NetworkTestParams::create()
318 return new NetworkTest(this);