gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GarnetSyntheticTraffic.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Georgia Institute of Technology
3  * All rights reserved.
4  *
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.
15  *
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.
27  *
28  * Authors: Tushar Krishna
29  */
30 
32 
33 #include <cmath>
34 #include <iomanip>
35 #include <set>
36 #include <string>
37 #include <vector>
38 
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"
49 
50 using namespace std;
51 
53 
54 bool
56 {
57  tester->completeRequest(pkt);
58  return true;
59 }
60 
61 void
63 {
64  tester->doRetry();
65 }
66 
67 void
69 {
70  if (!cachePort.sendTimingReq(pkt)) {
71  retryPkt = pkt; // RubyPort will retry sending
72  }
73  numPacketsSent++;
74 }
75 
77  : ClockedObject(p),
78  tickEvent([this]{ tick(); }, "GarnetSyntheticTraffic tick",
79  false, Event::CPU_Tick_Pri),
80  cachePort("GarnetSyntheticTraffic", this),
81  retryPkt(NULL),
82  size(p->memory_size),
83  blockSizeBits(p->block_offset),
84  numDestinations(p->num_dest),
85  simCycles(p->sim_cycles),
86  numPacketsMax(p->num_packets_max),
87  numPacketsSent(0),
88  singleSender(p->single_sender),
89  singleDest(p->single_dest),
90  trafficType(p->traffic_type),
91  injRate(p->inj_rate),
92  injVnet(p->inj_vnet),
93  precision(p->precision),
94  responseLimit(p->response_limit),
95  masterId(p->system->getMasterId(this))
96 {
97  // set up counters
98  noResponseCycles = 0;
99  schedule(tickEvent, 0);
100 
101  initTrafficType();
102  if (trafficStringToEnum.count(trafficType) == 0) {
103  fatal("Unknown Traffic Type: %s!\n", traffic);
104  }
106 
107  id = TESTER_NETWORK++;
108  DPRINTF(GarnetSyntheticTraffic,"Config Created: Name = %s , and id = %d\n",
109  name(), id);
110 }
111 
112 Port &
113 GarnetSyntheticTraffic::getPort(const std::string &if_name, PortID idx)
114 {
115  if (if_name == "test")
116  return cachePort;
117  else
118  return ClockedObject::getPort(if_name, idx);
119 }
120 
121 void
123 {
124  numPacketsSent = 0;
125 }
126 
127 
128 void
130 {
132  "Completed injection of %s packet for address %x\n",
133  pkt->isWrite() ? "write" : "read\n",
134  pkt->req->getPaddr());
135 
136  assert(pkt->isResponse());
137  noResponseCycles = 0;
138  delete pkt;
139 }
140 
141 
142 void
144 {
145  if (++noResponseCycles >= responseLimit) {
146  fatal("%s deadlocked at cycle %d\n", name(), curTick());
147  }
148 
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;
158  else
159  sendAllowedThisCycle = false;
160 
161  // always generatePkt unless fixedPkts or singleSender is enabled
162  if (sendAllowedThisCycle) {
163  bool senderEnable = true;
164 
166  senderEnable = false;
167 
168  if (singleSender >= 0 && id != singleSender)
169  senderEnable = false;
170 
171  if (senderEnable)
172  generatePkt();
173  }
174 
175  // Schedule wakeup
176  if (curTick() >= simCycles)
177  exitSimLoop("Network Tester completed simCycles");
178  else {
179  if (!tickEvent.scheduled())
181  }
182 }
183 
184 void
186 {
187  int num_destinations = numDestinations;
188  int radix = (int) sqrt(num_destinations);
189  unsigned destination = id;
190  int dest_x = -1;
191  int dest_y = -1;
192  int source = id;
193  int src_x = id%radix;
194  int src_y = id/radix;
195 
196  if (singleDest >= 0)
197  {
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
208 
209  int num_bits = (int) log2(num_destinations);
210 
211  for (int i = 1; i < num_bits; i++)
212  {
213  reverse <<= 1;
214  straight >>= 1;
215  reverse |= (straight & 1); // LSB
216  }
217  destination = reverse;
218  } else if (traffic == BIT_ROTATION_) {
219  if (source%2 == 0)
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;
225  dest_y = src_y;
226  destination = dest_y*radix + dest_x;
227  } else if (traffic == SHUFFLE_) {
228  if (source < num_destinations/2)
229  destination = source*2;
230  else
231  destination = (source*2 - num_destinations + 1);
232  } else if (traffic == TRANSPOSE_) {
233  dest_x = src_y;
234  dest_y = src_x;
235  destination = dest_y*radix + dest_x;
236  } else if (traffic == TORNADO_) {
237  dest_x = (src_x + (int) ceil(radix/2) - 1) % radix;
238  dest_y = src_y;
239  destination = dest_y*radix + dest_x;
240  }
241  else {
242  fatal("Unknown Traffic Type: %s!\n", traffic);
243  }
244 
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
251 
252  // Modeling different coherence msg types over different msg classes.
253  //
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).
259  //
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.
275  //
276  MemCmd::Command requestType;
277 
278  RequestPtr req = nullptr;
279  Request::Flags flags;
280 
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;
285 
286  if (injReqType < 0 || injReqType > 2)
287  {
288  // randomly inject in any vnet
289  injReqType = random_mt.random(0, 2);
290  }
291 
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);
307  }
308 
309  req->setContext(id);
310 
311  //No need to do functional simulation
312  //We just do timing simulation of the network
313 
315  "Generated packet with destination %d, embedded in address %x\n",
316  destination, req->getPaddr());
317 
318  PacketPtr pkt = new Packet(req, requestType);
319  pkt->dataDynamic(new uint8_t[req->getSize()]);
320  pkt->senderState = NULL;
321 
322  sendPkt(pkt);
323 }
324 
325 void
327 {
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_;
336 }
337 
338 void
340 {
342  retryPkt = NULL;
343  }
344 }
345 
346 void
348 {
349  cachePort.printAddr(a);
350 }
351 
352 
354 GarnetSyntheticTrafficParams::create()
355 {
356  return new GarnetSyntheticTraffic(this);
357 }
#define DPRINTF(x,...)
Definition: trace.hh:229
Ports are used to interface objects to each other.
Definition: port.hh:60
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Definition: sim_object.cc:126
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:175
Bitfield< 7 > i
int TESTER_NETWORK
static const Priority CPU_Tick_Pri
CPU ticks must come after other associated CPU events (such as writebacks).
Definition: eventq.hh:162
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
std::shared_ptr< Request > RequestPtr
Definition: request.hh:83
Bitfield< 8 > a
void completeRequest(PacketPtr pkt)
GarnetSyntheticTraffic(const Params *p)
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:586
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the slave port by calling its corresponding receive function...
Definition: port.hh:445
bool isWrite() const
Definition: packet.hh:529
Declaration of Statistics objects.
std::enable_if< std::is_integral< T >::value, T >::type random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
Definition: random.hh:83
const sc_lv_base reverse(const sc_proxy< X > &x)
Definition: sc_lv_base.hh:683
RequestPtr req
A pointer to the original request.
Definition: packet.hh:327
Tick curTick()
The current simulated tick.
Definition: core.hh:47
virtual bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the peer.
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:385
void printAddr(Addr a)
Print state of address in memory system via PrintReq (for debugging).
bool isResponse() const
Definition: packet.hh:532
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Port Object Declaration.
GarnetSyntheticTrafficParams Params
std::map< std::string, TrafficType > trafficStringToEnum
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
void printAddr(Addr a)
Inject a PrintReq for the given address to print the state of that address throughout the memory syst...
Definition: port.cc:99
virtual const std::string name() const
Definition: sim_object.hh:120
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
The request was an instruction fetch.
Definition: request.hh:105
void exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat, bool serialize)
Schedule an event to exit the simulation loop (returning to Python) at the end of the current cycle (...
Definition: sim_events.cc:90
Declaration of the Packet class.
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Random random_mt
Definition: random.cc:100
void schedule(Event &event, Tick when)
Definition: eventq.hh:744
virtual void recvReqRetry()
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
Command
List of all commands associated with a packet.
Definition: packet.hh:84
Bitfield< 0 > p
void set(Type flags)
Definition: flags.hh:70
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:104
EventFunctionWrapper tickEvent

Generated on Fri Feb 28 2020 16:27:00 for gem5 by doxygen 1.8.13