gem5  v21.0.1.0
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 
30 
31 #include <cmath>
32 #include <iomanip>
33 #include <set>
34 #include <string>
35 #include <vector>
36 
37 #include "base/logging.hh"
38 #include "base/random.hh"
39 #include "base/statistics.hh"
40 #include "debug/GarnetSyntheticTraffic.hh"
41 #include "mem/packet.hh"
42 #include "mem/port.hh"
43 #include "mem/request.hh"
44 #include "sim/sim_events.hh"
45 #include "sim/stats.hh"
46 #include "sim/system.hh"
47 
49 
50 bool
52 {
53  tester->completeRequest(pkt);
54  return true;
55 }
56 
57 void
59 {
60  tester->doRetry();
61 }
62 
63 void
65 {
66  if (!cachePort.sendTimingReq(pkt)) {
67  retryPkt = pkt; // RubyPort will retry sending
68  }
70 }
71 
73  : ClockedObject(p),
74  tickEvent([this]{ tick(); }, "GarnetSyntheticTraffic tick",
75  false, Event::CPU_Tick_Pri),
76  cachePort("GarnetSyntheticTraffic", this),
77  retryPkt(NULL),
78  size(p.memory_size),
79  blockSizeBits(p.block_offset),
80  numDestinations(p.num_dest),
81  simCycles(p.sim_cycles),
82  numPacketsMax(p.num_packets_max),
83  numPacketsSent(0),
84  singleSender(p.single_sender),
85  singleDest(p.single_dest),
86  trafficType(p.traffic_type),
87  injRate(p.inj_rate),
88  injVnet(p.inj_vnet),
89  precision(p.precision),
90  responseLimit(p.response_limit),
91  requestorId(p.system->getRequestorId(this))
92 {
93  // set up counters
94  noResponseCycles = 0;
95  schedule(tickEvent, 0);
96 
97  initTrafficType();
98  if (trafficStringToEnum.count(trafficType) == 0) {
99  fatal("Unknown Traffic Type: %s!\n", traffic);
100  }
101  traffic = trafficStringToEnum[trafficType];
102 
103  id = TESTER_NETWORK++;
104  DPRINTF(GarnetSyntheticTraffic,"Config Created: Name = %s , and id = %d\n",
105  name(), id);
106 }
107 
108 Port &
109 GarnetSyntheticTraffic::getPort(const std::string &if_name, PortID idx)
110 {
111  if (if_name == "test")
112  return cachePort;
113  else
114  return ClockedObject::getPort(if_name, idx);
115 }
116 
117 void
119 {
120  numPacketsSent = 0;
121 }
122 
123 
124 void
126 {
128  "Completed injection of %s packet for address %x\n",
129  pkt->isWrite() ? "write" : "read\n",
130  pkt->req->getPaddr());
131 
132  assert(pkt->isResponse());
133  noResponseCycles = 0;
134  delete pkt;
135 }
136 
137 
138 void
140 {
141  if (++noResponseCycles >= responseLimit) {
142  fatal("%s deadlocked at cycle %d\n", name(), curTick());
143  }
144 
145  // make new request based on injection rate
146  // (injection rate's range depends on precision)
147  // - generate a random number between 0 and 10^precision
148  // - send pkt if this number is < injRate*(10^precision)
149  bool sendAllowedThisCycle;
150  double injRange = pow((double) 10, (double) precision);
151  unsigned trySending = random_mt.random<unsigned>(0, (int) injRange);
152  if (trySending < injRate*injRange)
153  sendAllowedThisCycle = true;
154  else
155  sendAllowedThisCycle = false;
156 
157  // always generatePkt unless fixedPkts or singleSender is enabled
158  if (sendAllowedThisCycle) {
159  bool senderEnable = true;
160 
162  senderEnable = false;
163 
164  if (singleSender >= 0 && id != singleSender)
165  senderEnable = false;
166 
167  if (senderEnable)
168  generatePkt();
169  }
170 
171  // Schedule wakeup
172  if (curTick() >= simCycles)
173  exitSimLoop("Network Tester completed simCycles");
174  else {
175  if (!tickEvent.scheduled())
177  }
178 }
179 
180 void
182 {
183  int num_destinations = numDestinations;
184  int radix = (int) sqrt(num_destinations);
185  unsigned destination = id;
186  int dest_x = -1;
187  int dest_y = -1;
188  int source = id;
189  int src_x = id%radix;
190  int src_y = id/radix;
191 
192  if (singleDest >= 0)
193  {
195  } else if (traffic == UNIFORM_RANDOM_) {
196  destination = random_mt.random<unsigned>(0, num_destinations - 1);
197  } else if (traffic == BIT_COMPLEMENT_) {
198  dest_x = radix - src_x - 1;
199  dest_y = radix - src_y - 1;
200  destination = dest_y*radix + dest_x;
201  } else if (traffic == BIT_REVERSE_) {
202  unsigned int straight = source;
203  unsigned int reverse = source & 1; // LSB
204 
205  int num_bits = (int) log2(num_destinations);
206 
207  for (int i = 1; i < num_bits; i++)
208  {
209  reverse <<= 1;
210  straight >>= 1;
211  reverse |= (straight & 1); // LSB
212  }
214  } else if (traffic == BIT_ROTATION_) {
215  if (source%2 == 0)
216  destination = source/2;
217  else // (source%2 == 1)
218  destination = ((source/2) + (num_destinations/2));
219  } else if (traffic == NEIGHBOR_) {
220  dest_x = (src_x + 1) % radix;
221  dest_y = src_y;
222  destination = dest_y*radix + dest_x;
223  } else if (traffic == SHUFFLE_) {
224  if (source < num_destinations/2)
225  destination = source*2;
226  else
227  destination = (source*2 - num_destinations + 1);
228  } else if (traffic == TRANSPOSE_) {
229  dest_x = src_y;
230  dest_y = src_x;
231  destination = dest_y*radix + dest_x;
232  } else if (traffic == TORNADO_) {
233  dest_x = (src_x + (int) ceil(radix/2) - 1) % radix;
234  dest_y = src_y;
235  destination = dest_y*radix + dest_x;
236  }
237  else {
238  fatal("Unknown Traffic Type: %s!\n", traffic);
239  }
240 
241  // The source of the packets is a cache.
242  // The destination of the packets is a directory.
243  // The destination bits are embedded in the address after byte-offset.
244  Addr paddr = destination;
245  paddr <<= blockSizeBits;
246  unsigned access_size = 1; // Does not affect Ruby simulation
247 
248  // Modeling different coherence msg types over different msg classes.
249  //
250  // GarnetSyntheticTraffic assumes the Garnet_standalone coherence protocol
251  // which models three message classes/virtual networks.
252  // These are: request, forward, response.
253  // requests and forwards are "control" packets (typically 8 bytes),
254  // while responses are "data" packets (typically 72 bytes).
255  //
256  // Life of a packet from the tester into the network:
257  // (1) This function generatePkt() generates packets of one of the
258  // following 3 types (randomly) : ReadReq, INST_FETCH, WriteReq
259  // (2) mem/ruby/system/RubyPort.cc converts these to RubyRequestType_LD,
260  // RubyRequestType_IFETCH, RubyRequestType_ST respectively
261  // (3) mem/ruby/system/Sequencer.cc sends these to the cache controllers
262  // in the coherence protocol.
263  // (4) Network_test-cache.sm tags RubyRequestType:LD,
264  // RubyRequestType:IFETCH and RubyRequestType:ST as
265  // Request, Forward, and Response events respectively;
266  // and injects them into virtual networks 0, 1 and 2 respectively.
267  // It immediately calls back the sequencer.
268  // (5) The packet traverses the network (simple/garnet) and reaches its
269  // destination (Directory), and network stats are updated.
270  // (6) Network_test-dir.sm simply drops the packet.
271  //
272  MemCmd::Command requestType;
273 
274  RequestPtr req = nullptr;
275  Request::Flags flags;
276 
277  // Inject in specific Vnet
278  // Vnet 0 and 1 are for control packets (1-flit)
279  // Vnet 2 is for data packets (5-flit)
280  int injReqType = injVnet;
281 
282  if (injReqType < 0 || injReqType > 2)
283  {
284  // randomly inject in any vnet
285  injReqType = random_mt.random(0, 2);
286  }
287 
288  if (injReqType == 0) {
289  // generate packet for virtual network 0
290  requestType = MemCmd::ReadReq;
291  req = std::make_shared<Request>(paddr, access_size, flags,
292  requestorId);
293  } else if (injReqType == 1) {
294  // generate packet for virtual network 1
295  requestType = MemCmd::ReadReq;
296  flags.set(Request::INST_FETCH);
297  req = std::make_shared<Request>(
298  0x0, access_size, flags, requestorId, 0x0, 0);
299  req->setPaddr(paddr);
300  } else { // if (injReqType == 2)
301  // generate packet for virtual network 2
302  requestType = MemCmd::WriteReq;
303  req = std::make_shared<Request>(paddr, access_size, flags,
304  requestorId);
305  }
306 
307  req->setContext(id);
308 
309  //No need to do functional simulation
310  //We just do timing simulation of the network
311 
313  "Generated packet with destination %d, embedded in address %x\n",
314  destination, req->getPaddr());
315 
316  PacketPtr pkt = new Packet(req, requestType);
317  pkt->dataDynamic(new uint8_t[req->getSize()]);
318  pkt->senderState = NULL;
319 
320  sendPkt(pkt);
321 }
322 
323 void
325 {
326  trafficStringToEnum["bit_complement"] = BIT_COMPLEMENT_;
327  trafficStringToEnum["bit_reverse"] = BIT_REVERSE_;
328  trafficStringToEnum["bit_rotation"] = BIT_ROTATION_;
329  trafficStringToEnum["neighbor"] = NEIGHBOR_;
330  trafficStringToEnum["shuffle"] = SHUFFLE_;
331  trafficStringToEnum["tornado"] = TORNADO_;
332  trafficStringToEnum["transpose"] = TRANSPOSE_;
333  trafficStringToEnum["uniform_random"] = UNIFORM_RANDOM_;
334 }
335 
336 void
338 {
340  retryPkt = NULL;
341  }
342 }
343 
344 void
346 {
348 }
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
Event::scheduled
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:462
GarnetSyntheticTraffic::Params
GarnetSyntheticTrafficParams Params
Definition: GarnetSyntheticTraffic.hh:57
GarnetSyntheticTraffic::trafficStringToEnum
std::map< std::string, TrafficType > trafficStringToEnum
Definition: GarnetSyntheticTraffic.hh:112
GarnetSyntheticTraffic::generatePkt
void generatePkt()
Definition: GarnetSyntheticTraffic.cc:181
Packet::isResponse
bool isResponse() const
Definition: packet.hh:561
GarnetSyntheticTraffic::printAddr
void printAddr(Addr a)
Print state of address in memory system via PrintReq (for debugging).
Definition: GarnetSyntheticTraffic.cc:345
GarnetSyntheticTraffic::numPacketsSent
int numPacketsSent
Definition: GarnetSyntheticTraffic.hh:121
system.hh
EventBase::CPU_Tick_Pri
static const Priority CPU_Tick_Pri
CPU ticks must come after other associated CPU events (such as writebacks).
Definition: eventq.hh:201
GarnetSyntheticTraffic::getPort
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: GarnetSyntheticTraffic.cc:109
sim_events.hh
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
Flags< FlagsType >
GarnetSyntheticTraffic::CpuPort::tester
GarnetSyntheticTraffic * tester
Definition: GarnetSyntheticTraffic.hh:79
random.hh
GarnetSyntheticTraffic::injVnet
int injVnet
Definition: GarnetSyntheticTraffic.hh:128
MemCmd::ReadReq
@ ReadReq
Definition: packet.hh:83
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:243
RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:86
Packet::req
RequestPtr req
A pointer to the original request.
Definition: packet.hh:341
Packet::dataDynamic
void dataDynamic(T *p)
Set the data pointer to a value that should have delete [] called on it.
Definition: packet.hh:1146
SHUFFLE_
@ SHUFFLE_
Definition: GarnetSyntheticTraffic.hh:47
GarnetSyntheticTraffic::blockSizeBits
unsigned blockSizeBits
Definition: GarnetSyntheticTraffic.hh:114
GarnetSyntheticTraffic::init
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: GarnetSyntheticTraffic.cc:118
GarnetSyntheticTraffic::singleSender
int singleSender
Definition: GarnetSyntheticTraffic.hh:122
request.hh
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
packet.hh
GarnetSyntheticTraffic::requestorId
RequestorID requestorId
Definition: GarnetSyntheticTraffic.hh:133
Random::random
std::enable_if_t< std::is_integral< T >::value, T > random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
Definition: random.hh:86
GarnetSyntheticTraffic::singleDest
int singleDest
Definition: GarnetSyntheticTraffic.hh:123
MemCmd::Command
Command
List of all commands associated with a packet.
Definition: packet.hh:80
MemCmd::WriteReq
@ WriteReq
Definition: packet.hh:86
BIT_REVERSE_
@ BIT_REVERSE_
Definition: GarnetSyntheticTraffic.hh:44
GarnetSyntheticTraffic::cachePort
CpuPort cachePort
Definition: GarnetSyntheticTraffic.hh:94
random_mt
Random random_mt
Definition: random.cc:96
stats.hh
EventManager::schedule
void schedule(Event &event, Tick when)
Definition: eventq.hh:1016
GarnetSyntheticTraffic::responseLimit
const Cycles responseLimit
Definition: GarnetSyntheticTraffic.hh:131
ArmISA::a
Bitfield< 8 > a
Definition: miscregs_types.hh:62
NEIGHBOR_
@ NEIGHBOR_
Definition: GarnetSyntheticTraffic.hh:46
RequestPort::sendTimingReq
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the responder port by calling its corresponding receive function.
Definition: port.hh:492
GarnetSyntheticTraffic::id
int id
Definition: GarnetSyntheticTraffic.hh:110
SimObject::getPort
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Definition: sim_object.cc:120
GarnetSyntheticTraffic::numPacketsMax
int numPacketsMax
Definition: GarnetSyntheticTraffic.hh:120
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
statistics.hh
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
Clocked::clockEdge
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...
Definition: clocked_object.hh:174
port.hh
exitSimLoop
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:85
Flags::set
void set(Type mask)
Set all flag's bits matching the given mask.
Definition: flags.hh:113
sc_dt::reverse
const sc_lv_base reverse(const sc_proxy< X > &x)
Definition: sc_lv_base.hh:717
GarnetSyntheticTraffic::initTrafficType
void initTrafficType()
Definition: GarnetSyntheticTraffic.cc:324
GarnetSyntheticTraffic::noResponseCycles
Tick noResponseCycles
Definition: GarnetSyntheticTraffic.hh:116
GarnetSyntheticTraffic::retryPkt
PacketPtr retryPkt
Definition: GarnetSyntheticTraffic.hh:108
ProbePoints::Packet
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:103
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
GarnetSyntheticTraffic::tickEvent
EventFunctionWrapper tickEvent
Definition: GarnetSyntheticTraffic.hh:75
name
const std::string & name()
Definition: trace.cc:48
Request::INST_FETCH
@ INST_FETCH
The request was an instruction fetch.
Definition: request.hh:108
GarnetSyntheticTraffic
Definition: GarnetSyntheticTraffic.hh:54
GarnetSyntheticTraffic::doRetry
void doRetry()
Definition: GarnetSyntheticTraffic.cc:337
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:182
TRANSPOSE_
@ TRANSPOSE_
Definition: GarnetSyntheticTraffic.hh:49
GarnetSyntheticTraffic::CpuPort::recvReqRetry
virtual void recvReqRetry()
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
Definition: GarnetSyntheticTraffic.cc:58
GarnetSyntheticTraffic::tick
void tick()
Definition: GarnetSyntheticTraffic.cc:139
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:258
UNIFORM_RANDOM_
@ UNIFORM_RANDOM_
Definition: GarnetSyntheticTraffic.hh:50
GarnetSyntheticTraffic::sendPkt
void sendPkt(PacketPtr pkt)
Definition: GarnetSyntheticTraffic.cc:64
GarnetSyntheticTraffic::traffic
TrafficType traffic
Definition: GarnetSyntheticTraffic.hh:126
RequestPort::printAddr
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:154
GarnetSyntheticTraffic::numDestinations
int numDestinations
Definition: GarnetSyntheticTraffic.hh:118
logging.hh
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:79
Packet::isWrite
bool isWrite() const
Definition: packet.hh:558
GarnetSyntheticTraffic::GarnetSyntheticTraffic
GarnetSyntheticTraffic(const Params &p)
Definition: GarnetSyntheticTraffic.cc:72
GarnetSyntheticTraffic::injRate
double injRate
Definition: GarnetSyntheticTraffic.hh:127
GarnetSyntheticTraffic::simCycles
Tick simCycles
Definition: GarnetSyntheticTraffic.hh:119
curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:43
GarnetSyntheticTraffic::completeRequest
void completeRequest(PacketPtr pkt)
Definition: GarnetSyntheticTraffic.cc:125
BIT_ROTATION_
@ BIT_ROTATION_
Definition: GarnetSyntheticTraffic.hh:45
Packet::senderState
SenderState * senderState
This packet's sender state.
Definition: packet.hh:509
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
GarnetSyntheticTraffic::precision
int precision
Definition: GarnetSyntheticTraffic.hh:129
X86ISA::destination
destination
Definition: intmessage.hh:43
TESTER_NETWORK
int TESTER_NETWORK
Definition: GarnetSyntheticTraffic.cc:48
TORNADO_
@ TORNADO_
Definition: GarnetSyntheticTraffic.hh:48
GarnetSyntheticTraffic::CpuPort::recvTimingResp
virtual bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the peer.
Definition: GarnetSyntheticTraffic.cc:51
GarnetSyntheticTraffic.hh
BIT_COMPLEMENT_
@ BIT_COMPLEMENT_
Definition: GarnetSyntheticTraffic.hh:43

Generated on Tue Jun 22 2021 15:28:27 for gem5 by doxygen 1.8.17