5b542bc199a8d3a5dfd1f2fd385f149c012083e2
2 * Copyright (c) 2016 Georgia Institute of Technology
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
31 #include "cpu/testers/garnet_synthetic_traffic/GarnetSyntheticTraffic.hh"
39 #include "base/logging.hh"
40 #include "base/random.hh"
41 #include "base/statistics.hh"
42 #include "debug/GarnetSyntheticTraffic.hh"
43 #include "mem/packet.hh"
44 #include "mem/port.hh"
45 #include "mem/request.hh"
46 #include "sim/sim_events.hh"
47 #include "sim/stats.hh"
48 #include "sim/system.hh"
55 GarnetSyntheticTraffic::CpuPort::recvTimingResp(PacketPtr pkt
)
57 tester
->completeRequest(pkt
);
62 GarnetSyntheticTraffic::CpuPort::recvReqRetry()
68 GarnetSyntheticTraffic::sendPkt(PacketPtr pkt
)
70 if (!cachePort
.sendTimingReq(pkt
)) {
71 retryPkt
= pkt
; // RubyPort will retry sending
76 GarnetSyntheticTraffic::GarnetSyntheticTraffic(const Params
*p
)
78 tickEvent([this]{ tick(); }, "GarnetSyntheticTraffic tick",
79 false, Event::CPU_Tick_Pri
),
80 cachePort("GarnetSyntheticTraffic", this),
83 blockSizeBits(p
->block_offset
),
84 numDestinations(p
->num_dest
),
85 simCycles(p
->sim_cycles
),
86 numPacketsMax(p
->num_packets_max
),
88 singleSender(p
->single_sender
),
89 singleDest(p
->single_dest
),
90 trafficType(p
->traffic_type
),
93 precision(p
->precision
),
94 responseLimit(p
->response_limit
),
95 masterId(p
->system
->getMasterId(this))
99 schedule(tickEvent
, 0);
102 if (trafficStringToEnum
.count(trafficType
) == 0) {
103 fatal("Unknown Traffic Type: %s!\n", traffic
);
105 traffic
= trafficStringToEnum
[trafficType
];
107 id
= TESTER_NETWORK
++;
108 DPRINTF(GarnetSyntheticTraffic
,"Config Created: Name = %s , and id = %d\n",
113 GarnetSyntheticTraffic::getPort(const std::string
&if_name
, PortID idx
)
115 if (if_name
== "test")
118 return ClockedObject::getPort(if_name
, idx
);
122 GarnetSyntheticTraffic::init()
129 GarnetSyntheticTraffic::completeRequest(PacketPtr pkt
)
131 DPRINTF(GarnetSyntheticTraffic
,
132 "Completed injection of %s packet for address %x\n",
133 pkt
->isWrite() ? "write" : "read\n",
134 pkt
->req
->getPaddr());
136 assert(pkt
->isResponse());
137 noResponseCycles
= 0;
143 GarnetSyntheticTraffic::tick()
145 if (++noResponseCycles
>= responseLimit
) {
146 fatal("%s deadlocked at cycle %d\n", name(), curTick());
149 // make new request based on injection rate
150 // (injection rate's range depends on precision)
151 // - generate a random number between 0 and 10^precision
152 // - send pkt if this number is < injRate*(10^precision)
153 bool sendAllowedThisCycle
;
154 double injRange
= pow((double) 10, (double) precision
);
155 unsigned trySending
= random_mt
.random
<unsigned>(0, (int) injRange
);
156 if (trySending
< injRate
*injRange
)
157 sendAllowedThisCycle
= true;
159 sendAllowedThisCycle
= false;
161 // always generatePkt unless fixedPkts or singleSender is enabled
162 if (sendAllowedThisCycle
) {
163 bool senderEnable
= true;
165 if (numPacketsMax
>= 0 && numPacketsSent
>= numPacketsMax
)
166 senderEnable
= false;
168 if (singleSender
>= 0 && id
!= singleSender
)
169 senderEnable
= false;
176 if (curTick() >= simCycles
)
177 exitSimLoop("Network Tester completed simCycles");
179 if (!tickEvent
.scheduled())
180 schedule(tickEvent
, clockEdge(Cycles(1)));
185 GarnetSyntheticTraffic::generatePkt()
187 int num_destinations
= numDestinations
;
188 int radix
= (int) sqrt(num_destinations
);
189 unsigned destination
= id
;
193 int src_x
= id
%radix
;
194 int src_y
= id
/radix
;
198 destination
= singleDest
;
199 } else if (traffic
== UNIFORM_RANDOM_
) {
200 destination
= random_mt
.random
<unsigned>(0, num_destinations
- 1);
201 } else if (traffic
== BIT_COMPLEMENT_
) {
202 dest_x
= radix
- src_x
- 1;
203 dest_y
= radix
- src_y
- 1;
204 destination
= dest_y
*radix
+ dest_x
;
205 } else if (traffic
== BIT_REVERSE_
) {
206 unsigned int straight
= source
;
207 unsigned int reverse
= source
& 1; // LSB
209 int num_bits
= (int) log2(num_destinations
);
211 for (int i
= 1; i
< num_bits
; i
++)
215 reverse
|= (straight
& 1); // LSB
217 destination
= reverse
;
218 } else if (traffic
== BIT_ROTATION_
) {
220 destination
= source
/2;
221 else // (source%2 == 1)
222 destination
= ((source
/2) + (num_destinations
/2));
223 } else if (traffic
== NEIGHBOR_
) {
224 dest_x
= (src_x
+ 1) % radix
;
226 destination
= dest_y
*radix
+ dest_x
;
227 } else if (traffic
== SHUFFLE_
) {
228 if (source
< num_destinations
/2)
229 destination
= source
*2;
231 destination
= (source
*2 - num_destinations
+ 1);
232 } else if (traffic
== TRANSPOSE_
) {
235 destination
= dest_y
*radix
+ dest_x
;
236 } else if (traffic
== TORNADO_
) {
237 dest_x
= (src_x
+ (int) ceil(radix
/2) - 1) % radix
;
239 destination
= dest_y
*radix
+ dest_x
;
242 fatal("Unknown Traffic Type: %s!\n", traffic
);
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 // GarnetSyntheticTraffic assumes the Garnet_standalone 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 RequestPtr req
= nullptr;
279 Request::Flags flags
;
281 // Inject in specific Vnet
282 // Vnet 0 and 1 are for control packets (1-flit)
283 // Vnet 2 is for data packets (5-flit)
284 int injReqType
= injVnet
;
286 if (injReqType
< 0 || injReqType
> 2)
288 // randomly inject in any vnet
289 injReqType
= random_mt
.random(0, 2);
292 if (injReqType
== 0) {
293 // generate packet for virtual network 0
294 requestType
= MemCmd::ReadReq
;
295 req
= std::make_shared
<Request
>(paddr
, access_size
, flags
, masterId
);
296 } else if (injReqType
== 1) {
297 // generate packet for virtual network 1
298 requestType
= MemCmd::ReadReq
;
299 flags
.set(Request::INST_FETCH
);
300 req
= std::make_shared
<Request
>(
301 0, 0x0, access_size
, flags
, masterId
, 0x0, 0);
302 req
->setPaddr(paddr
);
303 } else { // if (injReqType == 2)
304 // generate packet for virtual network 2
305 requestType
= MemCmd::WriteReq
;
306 req
= std::make_shared
<Request
>(paddr
, access_size
, flags
, masterId
);
311 //No need to do functional simulation
312 //We just do timing simulation of the network
314 DPRINTF(GarnetSyntheticTraffic
,
315 "Generated packet with destination %d, embedded in address %x\n",
316 destination
, req
->getPaddr());
318 PacketPtr pkt
= new Packet(req
, requestType
);
319 pkt
->dataDynamic(new uint8_t[req
->getSize()]);
320 pkt
->senderState
= NULL
;
326 GarnetSyntheticTraffic::initTrafficType()
328 trafficStringToEnum
["bit_complement"] = BIT_COMPLEMENT_
;
329 trafficStringToEnum
["bit_reverse"] = BIT_REVERSE_
;
330 trafficStringToEnum
["bit_rotation"] = BIT_ROTATION_
;
331 trafficStringToEnum
["neighbor"] = NEIGHBOR_
;
332 trafficStringToEnum
["shuffle"] = SHUFFLE_
;
333 trafficStringToEnum
["tornado"] = TORNADO_
;
334 trafficStringToEnum
["transpose"] = TRANSPOSE_
;
335 trafficStringToEnum
["uniform_random"] = UNIFORM_RANDOM_
;
339 GarnetSyntheticTraffic::doRetry()
341 if (cachePort
.sendTimingReq(retryPkt
)) {
347 GarnetSyntheticTraffic::printAddr(Addr a
)
349 cachePort
.printAddr(a
);
353 GarnetSyntheticTraffic
*
354 GarnetSyntheticTrafficParams::create()
356 return new GarnetSyntheticTraffic(this);