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
)) {
107 retryPkt
= pkt
; // RubyPort will retry sending
112 NetworkTest::NetworkTest(const Params
*p
)
115 cachePort("network-test", this),
117 size(p
->memory_size
),
118 blockSizeBits(p
->block_offset
),
119 numMemories(p
->num_memories
),
120 simCycles(p
->sim_cycles
),
121 fixedPkts(p
->fixed_pkts
),
122 maxPackets(p
->max_packets
),
123 trafficType(p
->traffic_type
),
124 injRate(p
->inj_rate
),
125 precision(p
->precision
)
127 cachePort
.snoopRangeSent
= false;
130 noResponseCycles
= 0;
131 schedule(tickEvent
, 0);
133 id
= TESTER_NETWORK
++;
134 DPRINTF(NetworkTest
,"Config Created: Name = %s , and id = %d\n",
139 NetworkTest::getPort(const std::string
&if_name
, int idx
)
141 if (if_name
== "test")
144 panic("No Such Port\n");
155 NetworkTest::completeRequest(PacketPtr pkt
)
157 Request
*req
= pkt
->req
;
159 DPRINTF(NetworkTest
, "Completed injection of %s packet for address %x\n",
160 pkt
->isWrite() ? "write" : "read\n",
163 assert(pkt
->isResponse());
164 noResponseCycles
= 0;
173 if (++noResponseCycles
>= 500000) {
174 cerr
<< name() << ": deadlocked at cycle " << curTick() << endl
;
178 // make new request based on injection rate
179 // (injection rate's range depends on precision)
180 // - generate a random number between 0 and 10^precision
181 // - send pkt if this number is < injRate*(10^precision)
182 bool send_this_cycle
;
183 double injRange
= pow((double) 10, (double) precision
);
184 unsigned trySending
= random() % (int) injRange
;
185 if (trySending
< injRate
*injRange
)
186 send_this_cycle
= true;
188 send_this_cycle
= false;
190 // always generatePkt unless fixedPkts is enabled
191 if (send_this_cycle
) {
193 if (numPacketsSent
< maxPackets
) {
202 if (curTick() >= simCycles
)
203 exitSimLoop("Network Tester completed simCycles");
205 if (!tickEvent
.scheduled())
206 schedule(tickEvent
, curTick() + ticks(1));
211 NetworkTest::generatePkt()
213 unsigned destination
= id
;
214 if (trafficType
== 0) { // Uniform Random
215 destination
= random() % numMemories
;
216 } else if (trafficType
== 1) { // Tornado
217 int networkDimension
= (int) sqrt(numMemories
);
218 int my_x
= id
%networkDimension
;
219 int my_y
= id
/networkDimension
;
221 int dest_x
= my_x
+ (int) ceil(networkDimension
/2) - 1;
222 dest_x
= dest_x
%networkDimension
;
225 destination
= dest_y
*networkDimension
+ dest_x
;
226 } else if (trafficType
== 2) { // Bit Complement
227 int networkDimension
= (int) sqrt(numMemories
);
228 int my_x
= id
%networkDimension
;
229 int my_y
= id
/networkDimension
;
231 int dest_x
= networkDimension
- my_x
- 1;
232 int dest_y
= networkDimension
- my_y
- 1;
234 destination
= dest_y
*networkDimension
+ dest_x
;
237 Request
*req
= new Request();
238 Request::Flags flags
;
240 // The source of the packets is a cache.
241 // The destination of the packets is a directory.
242 // The destination bits are embedded in the address after byte-offset.
243 Addr paddr
= destination
;
244 paddr
<<= blockSizeBits
;
245 unsigned access_size
= 1; // Does not affect Ruby simulation
247 // Modeling different coherence msg types over different msg classes.
249 // networktest assumes the Network_test coherence protocol
250 // which models three message classes/virtual networks.
251 // These are: request, forward, response.
252 // requests and forwards are "control" packets (typically 8 bytes),
253 // while responses are "data" packets (typically 72 bytes).
255 // Life of a packet from the tester into the network:
256 // (1) This function generatePkt() generates packets of one of the
257 // following 3 types (randomly) : ReadReq, INST_FETCH, WriteReq
258 // (2) mem/ruby/system/RubyPort.cc converts these to RubyRequestType_LD,
259 // RubyRequestType_IFETCH, RubyRequestType_ST respectively
260 // (3) mem/ruby/system/Sequencer.cc sends these to the cache controllers
261 // in the coherence protocol.
262 // (4) Network_test-cache.sm tags RubyRequestType:LD,
263 // RubyRequestType:IFETCH and RubyRequestType:ST as
264 // Request, Forward, and Response events respectively;
265 // and injects them into virtual networks 0, 1 and 2 respectively.
266 // It immediately calls back the sequencer.
267 // (5) The packet traverses the network (simple/garnet) and reaches its
268 // destination (Directory), and network stats are updated.
269 // (6) Network_test-dir.sm simply drops the packet.
271 MemCmd::Command requestType
;
273 unsigned randomReqType
= random() % 3;
274 if (randomReqType
== 0) {
275 // generate packet for virtual network 0
276 requestType
= MemCmd::ReadReq
;
277 req
->setPhys(paddr
, access_size
, flags
);
278 } else if (randomReqType
== 1) {
279 // generate packet for virtual network 1
280 requestType
= MemCmd::ReadReq
;
281 flags
.set(Request::INST_FETCH
);
282 req
->setVirt(0, 0x0, access_size
, flags
, 0x0);
283 req
->setPaddr(paddr
);
284 } else { // if (randomReqType == 2)
285 // generate packet for virtual network 2
286 requestType
= MemCmd::WriteReq
;
287 req
->setPhys(paddr
, access_size
, flags
);
290 req
->setThreadContext(id
,0);
291 uint8_t *result
= new uint8_t[8];
293 //No need to do functional simulation
294 //We just do timing simulation of the network
297 "Generated packet with destination %d, embedded in address %x\n",
298 destination
, req
->getPaddr());
300 PacketPtr pkt
= new Packet(req
, requestType
, 0);
301 pkt
->setSrc(0); //Not used
302 pkt
->dataDynamicArray(new uint8_t[req
->getSize()]);
303 NetworkTestSenderState
*state
= new NetworkTestSenderState(result
);
304 pkt
->senderState
= state
;
310 NetworkTest::doRetry()
312 if (cachePort
.sendTiming(retryPkt
)) {
318 NetworkTest::printAddr(Addr a
)
320 cachePort
.printAddr(a
);
325 NetworkTestParams::create()
327 return new NetworkTest(this);