47 #include "debug/TrafficGen.hh" 48 #include "params/TrafficGen.hh" 56 configFile(p->config_file),
62 TrafficGenParams::create()
86 "Traffic generator is only active in timing mode\n");
113 if (name.empty() || name[0] ==
'/')
116 char *config_path = strdup(
configFile.c_str());
117 char *config_dir = dirname(config_path);
118 const std::string config_rel =
csprintf(
"%s/%s", config_dir, name);
122 if (access(config_rel.c_str(), R_OK) == 0)
139 infile.open(
configFile.c_str(), ifstream::in);
140 if (!infile.is_open()) {
141 fatal(
"Traffic generator %s config file not found at %s\n",
145 bool init_state_set =
false;
152 while (getline(infile, line).good()) {
154 if (line.find(
'#') != 1) {
156 istringstream
is(line);
161 if (keyword ==
"STATE") {
167 is >>
id >> duration >>
mode;
169 if (mode ==
"TRACE") {
173 is >> traceFile >> addrOffset;
178 }
else if (mode ==
"IDLE") {
181 }
else if (mode ==
"EXIT") {
184 }
else if (mode ==
"LINEAR" || mode ==
"RANDOM" ||
185 mode ==
"DRAM" || mode ==
"DRAM_ROTATE") {
186 uint32_t read_percent;
194 is >> read_percent >> start_addr >> end_addr >>
195 blocksize >> min_period >> max_period >> data_limit;
198 " period %d to %d, %d%% reads\n",
199 mode, start_addr, end_addr, blocksize, min_period,
200 max_period, read_percent);
203 if (mode ==
"LINEAR") {
206 min_period, max_period,
207 read_percent, data_limit);
209 }
else if (mode ==
"RANDOM") {
212 min_period, max_period,
213 read_percent, data_limit);
215 }
else if (mode ==
"DRAM" || mode ==
"DRAM_ROTATE") {
218 unsigned int stride_size;
219 unsigned int page_size;
220 unsigned int nbr_of_banks_DRAM;
221 unsigned int nbr_of_banks_util;
222 unsigned _addr_mapping;
223 unsigned int nbr_of_ranks;
225 is >> stride_size >> page_size >> nbr_of_banks_DRAM >>
226 nbr_of_banks_util >> _addr_mapping >>
228 Enums::AddrMap addr_mapping =
229 static_cast<Enums::AddrMap
>(_addr_mapping);
231 if (stride_size > page_size)
232 warn(
"DRAM generator stride size (%d) is greater " 233 "than page size (%d) of the memory\n",
234 blocksize, page_size);
238 unsigned int num_seq_pkts = 1;
240 if (stride_size > blocksize) {
241 num_seq_pkts =
divCeil(stride_size, blocksize);
243 "block size: %d, num_seq_pkts: %d\n",
244 stride_size, blocksize, num_seq_pkts);
247 if (mode ==
"DRAM") {
250 min_period, max_period,
251 read_percent, data_limit,
252 num_seq_pkts, page_size,
263 unsigned int max_seq_count_per_rank =
264 (read_percent == 50) ? nbr_of_banks_util * 2
269 min_period, max_period,
272 num_seq_pkts, page_size,
277 max_seq_count_per_rank);
282 fatal(
"%s: Unknown traffic generator mode: %s",
285 }
else if (keyword ==
"TRANSITION") {
288 is >> transition.
from >> transition.
to >> transition.
p;
290 transitions.push_back(transition);
294 }
else if (keyword ==
"INIT") {
298 init_state_set =
true;
306 fatal(
"%s: initial state not specified (add 'INIT <id>' line " 307 "to the config file)\n",
name());
311 for (
size_t i = 0;
i <
states.size();
i++) {
316 t != transitions.end(); ++
t) {
322 for (
size_t i = 0;
i <
states.size();
i++) {
324 for (
size_t j = 0;
j <
states.size();
j++) {
329 if (abs(sum - 1.0) > 0.001)
330 fatal(
"%s has transition probability != 1 for state %d\n",
343 double cumulative = 0.0;
353 std::shared_ptr<BaseGen>
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
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_DRAM, unsigned int nbr_of_banks_util, Enums::AddrMap addr_mapping, unsigned int nbr_of_ranks, unsigned int max_seq_count_per_rank)
void unserialize(CheckpointIn &cp) override
Unserialize an object.
std::shared_ptr< BaseGen > createTrace(Tick duration, const std::string &trace_file, Addr addr_offset)
#define fatal(...)
This implements a cprintf based fatal() function.
std::shared_ptr< BaseGen > nextGenerator() override
TrafficGen(const TrafficGenParams *p)
Struct to represent a probabilistic transition during parsing.
virtual void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
void transition()
Transition to the next generator.
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)
uint32_t currState
Index of the current state.
std::shared_ptr< BaseGen > activeGenerator
Currently active generator.
void serialize(CheckpointOut &cp) const override
Serialize an object.
Overload hash function for BasicBlockRange type.
std::shared_ptr< BaseGen > createExit(Tick duration)
const std::string configFile
The config file to parse.
std::vector< std::vector< double > > transitionMatrix
State transition matrix.
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_DRAM, unsigned int nbr_of_banks_util, Enums::AddrMap addr_mapping, unsigned int nbr_of_ranks)
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...
void parseConfig()
Parse the config file and build the state map and transition matrix.
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)
#define UNSERIALIZE_SCALAR(scalar)
std::string csprintf(const char *format, const Args &...args)
The traffic generator is a master module that generates stimuli for the memory system, based on a collection of simple behaviours that are either probabilistic or based on traces.
uint64_t Tick
Tick count type.
std::shared_ptr< BaseGen > createIdle(Tick duration)
System *const system
The system used to determine which mode we are currently operating in.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void serialize(CheckpointOut &cp) const override
Serialize an object.
std::unordered_map< uint32_t, std::shared_ptr< BaseGen > > states
Map of generator states.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
#define SERIALIZE_SCALAR(scalar)
virtual const std::string name() const
std::string resolveFile(const std::string &name)
Resolve a file path in the configuration file.
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
std::ostream CheckpointOut
T divCeil(const T &a, const U &b)
The traffic generator is a master module that generates stimuli for the memory system, based on a collection of simple generator behaviours that are either probabilistic or based on traces.
bool isTimingMode() const
Is the system in timing mode?
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
size_t nextState()
Use the transition matrix to find the next state index.