gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
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/statistics.hh"
39#include "debug/GarnetSyntheticTraffic.hh"
40#include "mem/packet.hh"
41#include "mem/port.hh"
42#include "mem/request.hh"
43#include "sim/sim_events.hh"
44#include "sim/stats.hh"
45#include "sim/system.hh"
46
47namespace gem5
48{
49
51
52bool
54{
55 tester->completeRequest(pkt);
56 return true;
57}
58
59void
64
65void
67{
68 if (!cachePort.sendTimingReq(pkt)) {
69 retryPkt = pkt; // RubyPort will retry sending
70 }
72}
73
76 tickEvent([this]{ tick(); }, "GarnetSyntheticTraffic tick",
77 false, Event::CPU_Tick_Pri),
78 cachePort("GarnetSyntheticTraffic", this),
79 retryPkt(NULL),
80 size(p.memory_size),
81 blockSizeBits(p.block_offset),
82 numDestinations(p.num_dest),
83 simCycles(p.sim_cycles),
84 numPacketsMax(p.num_packets_max),
85 numPacketsSent(0),
86 singleSender(p.single_sender),
87 singleDest(p.single_dest),
88 trafficType(p.traffic_type),
89 injRate(p.inj_rate),
90 injVnet(p.inj_vnet),
91 precision(p.precision),
92 responseLimit(p.response_limit),
93 requestorId(p.system->getRequestorId(this))
94{
95 // set up counters
96 noResponseCycles = 0;
97 schedule(tickEvent, 0);
98
99 initTrafficType();
100 if (trafficStringToEnum.count(trafficType) == 0) {
101 fatal("Unknown Traffic Type: %s!\n", traffic);
102 }
103 traffic = trafficStringToEnum[trafficType];
104
105 id = TESTER_NETWORK++;
106 // Initialize random generator with unique seed based on tester ID
108 DPRINTF(GarnetSyntheticTraffic,"Config Created: Name = %s , and id = %d\n",
109 name(), id);
110}
111
112Port &
113GarnetSyntheticTraffic::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
121void
126
127
128void
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());
138 delete pkt;
139}
140
141
142void
144{
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 = rng->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
184void
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 {
199 } else if (traffic == UNIFORM_RANDOM_) {
200 destination = rng->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 = rng->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,
297 } else if (injReqType == 1) {
298 // generate packet for virtual network 1
299 requestType = MemCmd::ReadReq;
301 req = std::make_shared<Request>(
302 0x0, access_size, flags, requestorId, 0x0, 0);
303 req->setPaddr(paddr);
304 } else { // if (injReqType == 2)
305 // generate packet for virtual network 2
306 requestType = MemCmd::WriteReq;
307 req = std::make_shared<Request>(paddr, access_size, flags,
309 }
310
311 req->setContext(id);
312
313 //No need to do functional simulation
314 //We just do timing simulation of the network
315
317 "Generated packet with destination %d, embedded in address %x\n",
318 destination, req->getPaddr());
319
320 PacketPtr pkt = new Packet(req, requestType);
321 pkt->dataDynamic(new uint8_t[req->getSize()]);
322 pkt->senderState = NULL;
323
324 sendPkt(pkt);
325}
326
327void
329{
330 trafficStringToEnum["bit_complement"] = BIT_COMPLEMENT_;
331 trafficStringToEnum["bit_reverse"] = BIT_REVERSE_;
332 trafficStringToEnum["bit_rotation"] = BIT_ROTATION_;
333 trafficStringToEnum["neighbor"] = NEIGHBOR_;
334 trafficStringToEnum["shuffle"] = SHUFFLE_;
335 trafficStringToEnum["tornado"] = TORNADO_;
336 trafficStringToEnum["transpose"] = TRANSPOSE_;
337 trafficStringToEnum["uniform_random"] = UNIFORM_RANDOM_;
338}
339
340void
342{
343 if (cachePort.sendTimingReq(retryPkt)) {
344 retryPkt = NULL;
345 }
346}
347
348void
353
354} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
ClockedObject(const ClockedObjectParams &p)
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...
Cycles is a wrapper class for representing cycle counts, i.e.
Definition types.hh:79
virtual bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the peer.
virtual void recvReqRetry()
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
GarnetSyntheticTrafficParams Params
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
std::map< std::string, TrafficType > trafficStringToEnum
void printAddr(Addr a)
Print state of address in memory system via PrintReq (for debugging).
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Command
List of all commands associated with a packet.
Definition packet.hh:85
virtual std::string name() const
Definition named.hh:60
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
bool isResponse() const
Definition packet.hh:598
SenderState * senderState
This packet's sender state.
Definition packet.hh:545
bool isWrite() const
Definition packet.hh:594
RequestPtr req
A pointer to the original request.
Definition packet.hh:377
void dataDynamic(T *p)
Set the data pointer to a value that should have delete [] called on it.
Definition packet.hh:1213
Ports are used to interface objects to each other.
Definition port.hh:62
static uint64_t globalSeed
Definition random.hh:120
static RandomPtr genRandom(Random *r=nullptr)
Definition random.hh:68
@ INST_FETCH
The request was an instruction fetch.
Definition request.hh:115
gem5::Flags< FlagsType > Flags
Definition request.hh:102
void schedule(Event &event, Tick when)
Definition eventq.hh:1012
static const Priority CPU_Tick_Pri
CPU ticks must come after other associated CPU events (such as writebacks).
Definition eventq.hh:207
void set(Type mask)
Set all flag's bits matching the given mask.
Definition flags.hh:116
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:232
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Port Object Declaration.
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 8 > a
Definition misc_types.hh:66
Bitfield< 0 > p
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::shared_ptr< Request > RequestPtr
Definition request.hh:94
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245
void exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat, bool serialize)
The "old style" exitSimLoop functions.
Packet * PacketPtr
Declaration of the Packet class.
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
Declaration of Statistics objects.
const std::string & name()
Definition trace.cc:48

Generated on Mon Oct 27 2025 04:13:01 for gem5 by doxygen 1.14.0