Go to the documentation of this file.
48 #include "debug/TrafficGen.hh"
49 #include "params/TrafficGen.hh"
55 configFile(
p.config_file),
79 "Traffic generator is only active in timing mode\n");
109 char *config_path = strdup(
configFile.c_str());
110 char *config_dir = dirname(config_path);
111 const std::string config_rel =
csprintf(
"%s/%s", config_dir,
name);
115 if (access(config_rel.c_str(), R_OK) == 0)
131 std::ifstream infile;
132 infile.open(
configFile.c_str(), std::ifstream::in);
133 if (!infile.is_open()) {
134 fatal(
"Traffic generator %s config file not found at %s\n",
138 bool init_state_set =
false;
145 while (getline(infile, line).good()) {
147 if (line.find(
'#') != 1) {
149 std::istringstream
is(line);
154 if (keyword ==
"STATE") {
160 is >>
id >> duration >>
mode;
162 if (
mode ==
"TRACE") {
163 std::string traceFile;
166 is >> traceFile >> addrOffset;
171 }
else if (
mode ==
"IDLE") {
174 }
else if (
mode ==
"EXIT") {
177 }
else if (
mode ==
"LINEAR" ||
mode ==
"RANDOM" ||
178 mode ==
"DRAM" ||
mode ==
"DRAM_ROTATE" ||
180 uint32_t read_percent;
188 is >> read_percent >> start_addr >> end_addr >>
189 blocksize >> min_period >> max_period >> data_limit;
192 " period %d to %d, %d%% reads\n",
193 mode, start_addr, end_addr, blocksize, min_period,
194 max_period, read_percent);
197 if (
mode ==
"LINEAR") {
200 min_period, max_period,
201 read_percent, data_limit);
203 }
else if (
mode ==
"RANDOM") {
206 min_period, max_period,
207 read_percent, data_limit);
209 }
else if (
mode ==
"DRAM" ||
mode ==
"DRAM_ROTATE" ||
213 unsigned int stride_size;
214 unsigned int page_size;
215 unsigned int nbr_of_banks;
216 unsigned int nbr_of_banks_util;
217 unsigned _addr_mapping;
218 unsigned int nbr_of_ranks;
220 is >> stride_size >> page_size >> nbr_of_banks >>
221 nbr_of_banks_util >> _addr_mapping >>
223 Enums::AddrMap addr_mapping =
224 static_cast<Enums::AddrMap
>(_addr_mapping);
226 if (stride_size > page_size)
227 warn(
"Memory generator stride size (%d) is greater"
228 " than page size (%d) of the memory\n",
229 blocksize, page_size);
233 unsigned int num_seq_pkts = 1;
235 if (stride_size > blocksize) {
236 num_seq_pkts =
divCeil(stride_size, blocksize);
238 "block size: %d, num_seq_pkts: %d\n",
239 stride_size, blocksize, num_seq_pkts);
242 if (
mode ==
"DRAM") {
245 min_period, max_period,
246 read_percent, data_limit,
247 num_seq_pkts, page_size,
253 }
else if (
mode ==
"DRAM_ROTATE") {
258 unsigned int max_seq_count_per_rank =
259 (read_percent == 50) ? nbr_of_banks_util * 2
264 min_period, max_period,
267 num_seq_pkts, page_size,
272 max_seq_count_per_rank);
277 min_period, max_period,
278 read_percent, data_limit,
279 num_seq_pkts, page_size,
288 fatal(
"%s: Unknown traffic generator mode: %s",
291 }
else if (keyword ==
"TRANSITION") {
300 }
else if (keyword ==
"INIT") {
304 init_state_set =
true;
312 fatal(
"%s: initial state not specified (add 'INIT <id>' line "
313 "to the config file)\n",
name());
317 for (
size_t i = 0;
i <
states.size();
i++) {
322 t != transitions.end(); ++
t) {
328 for (
size_t i = 0;
i <
states.size();
i++) {
330 for (
size_t j = 0;
j <
states.size();
j++) {
335 if (std::fabs(
sum - 1.0) > 0.001) {
336 fatal(
"%s has transition probability != 1 for state %d\n",
350 double cumulative = 0.0;
360 std::shared_ptr<BaseGen>
Struct to represent a probabilistic transition during parsing.
std::shared_ptr< BaseGen > createDramRot(Tick duration, Addr start_addr, Addr end_addr, Addr blocksize, Tick min_period, Tick max_period, uint8_t read_percent, Addr data_limit, unsigned int num_seq_pkts, unsigned int page_size, unsigned int nbr_of_banks, unsigned int nbr_of_banks_util, Enums::AddrMap addr_mapping, unsigned int nbr_of_ranks, unsigned int max_seq_count_per_rank)
#define fatal(...)
This implements a cprintf based fatal() function.
void serialize(CheckpointOut &cp) const override
Serialize an object.
std::string resolveFile(const std::string &name)
Resolve a file path in the configuration file.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
virtual void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
bool isTimingMode() const
Is the system in timing mode?
#define UNSERIALIZE_SCALAR(scalar)
std::shared_ptr< BaseGen > createRandom(Tick duration, Addr start_addr, Addr end_addr, Addr blocksize, Tick min_period, Tick max_period, uint8_t read_percent, Addr data_limit)
std::shared_ptr< BaseGen > activeGenerator
Currently active generator.
void transition()
Transition to the next generator.
uint64_t Tick
Tick count type.
std::unordered_map< uint32_t, std::shared_ptr< BaseGen > > states
Map of generator states.
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
std::shared_ptr< BaseGen > createDram(Tick duration, Addr start_addr, Addr end_addr, Addr blocksize, Tick min_period, Tick max_period, uint8_t read_percent, Addr data_limit, unsigned int num_seq_pkts, unsigned int page_size, unsigned int nbr_of_banks, unsigned int nbr_of_banks_util, Enums::AddrMap addr_mapping, unsigned int nbr_of_ranks)
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...
T divCeil(const T &a, const U &b)
The traffic generator is a module that generates stimuli for the memory system, based on a collection...
size_t nextState()
Use the transition matrix to find the next state index.
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
std::shared_ptr< BaseGen > createLinear(Tick duration, Addr start_addr, Addr end_addr, Addr blocksize, Tick min_period, Tick max_period, uint8_t read_percent, Addr data_limit)
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
std::shared_ptr< BaseGen > createTrace(Tick duration, const std::string &trace_file, Addr addr_offset)
std::shared_ptr< BaseGen > nextGenerator() override
uint32_t currState
Index of the current state.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
const std::string & name()
#define SERIALIZE_SCALAR(scalar)
std::vector< std::vector< double > > transitionMatrix
State transition matrix.
void serialize(CheckpointOut &cp) const override
Serialize an object.
virtual const std::string name() const
TrafficGen(const TrafficGenParams &p)
void parseConfig()
Parse the config file and build the state map and transition matrix.
std::ostream CheckpointOut
std::shared_ptr< BaseGen > createIdle(Tick duration)
const std::string configFile
The config file to parse.
std::shared_ptr< BaseGen > createExit(Tick duration)
The traffic generator is a module that generates stimuli for the memory system, based on a collection...
std::string csprintf(const char *format, const Args &...args)
System *const system
The system used to determine which mode we are currently operating in.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
std::shared_ptr< BaseGen > createNvm(Tick duration, Addr start_addr, Addr end_addr, Addr blocksize, Tick min_period, Tick max_period, uint8_t read_percent, Addr data_limit, unsigned int num_seq_pkts, unsigned int buffer_size, unsigned int nbr_of_banks, unsigned int nbr_of_banks_util, Enums::AddrMap addr_mapping, unsigned int nbr_of_ranks)
Generated on Tue Jun 22 2021 15:28:27 for gem5 by doxygen 1.8.17