51 #include "debug/TrafficGen.hh" 52 #include "params/TrafficGen.hh" 60 configFile(p->config_file),
66 TrafficGenParams::create()
90 "Traffic generator is only active in timing mode\n");
117 if (name.empty() || name[0] ==
'/')
120 char *config_path = strdup(
configFile.c_str());
121 char *config_dir = dirname(config_path);
122 const std::string config_rel =
csprintf(
"%s/%s", config_dir, name);
126 if (access(config_rel.c_str(), R_OK) == 0)
143 infile.open(
configFile.c_str(), ifstream::in);
144 if (!infile.is_open()) {
145 fatal(
"Traffic generator %s config file not found at %s\n",
149 bool init_state_set =
false;
156 while (getline(infile, line).good()) {
158 if (line.find(
'#') != 1) {
160 istringstream
is(line);
165 if (keyword ==
"STATE") {
171 is >>
id >> duration >>
mode;
173 if (mode ==
"TRACE") {
177 is >> traceFile >> addrOffset;
182 }
else if (mode ==
"IDLE") {
185 }
else if (mode ==
"EXIT") {
188 }
else if (mode ==
"LINEAR" || mode ==
"RANDOM" ||
189 mode ==
"DRAM" || mode ==
"DRAM_ROTATE") {
190 uint32_t read_percent;
198 is >> read_percent >> start_addr >> end_addr >>
199 blocksize >> min_period >> max_period >> data_limit;
202 " period %d to %d, %d%% reads\n",
203 mode, start_addr, end_addr, blocksize, min_period,
204 max_period, read_percent);
207 if (mode ==
"LINEAR") {
210 min_period, max_period,
211 read_percent, data_limit);
213 }
else if (mode ==
"RANDOM") {
216 min_period, max_period,
217 read_percent, data_limit);
219 }
else if (mode ==
"DRAM" || mode ==
"DRAM_ROTATE") {
222 unsigned int stride_size;
223 unsigned int page_size;
224 unsigned int nbr_of_banks_DRAM;
225 unsigned int nbr_of_banks_util;
226 unsigned _addr_mapping;
227 unsigned int nbr_of_ranks;
229 is >> stride_size >> page_size >> nbr_of_banks_DRAM >>
230 nbr_of_banks_util >> _addr_mapping >>
232 Enums::AddrMap addr_mapping =
233 static_cast<Enums::AddrMap
>(_addr_mapping);
235 if (stride_size > page_size)
236 warn(
"DRAM generator stride size (%d) is greater " 237 "than page size (%d) of the memory\n",
238 blocksize, page_size);
242 unsigned int num_seq_pkts = 1;
244 if (stride_size > blocksize) {
245 num_seq_pkts =
divCeil(stride_size, blocksize);
247 "block size: %d, num_seq_pkts: %d\n",
248 stride_size, blocksize, num_seq_pkts);
251 if (mode ==
"DRAM") {
254 min_period, max_period,
255 read_percent, data_limit,
256 num_seq_pkts, page_size,
267 unsigned int max_seq_count_per_rank =
268 (read_percent == 50) ? nbr_of_banks_util * 2
273 min_period, max_period,
276 num_seq_pkts, page_size,
281 max_seq_count_per_rank);
286 fatal(
"%s: Unknown traffic generator mode: %s",
289 }
else if (keyword ==
"TRANSITION") {
292 is >> transition.
from >> transition.
to >> transition.
p;
294 transitions.push_back(transition);
298 }
else if (keyword ==
"INIT") {
302 init_state_set =
true;
310 fatal(
"%s: initial state not specified (add 'INIT <id>' line " 311 "to the config file)\n",
name());
315 for (
size_t i = 0;
i <
states.size();
i++) {
320 t != transitions.end(); ++
t) {
326 for (
size_t i = 0;
i <
states.size();
i++) {
328 for (
size_t j = 0;
j <
states.size();
j++) {
333 if (abs(sum - 1.0) > 0.001)
334 fatal(
"%s has transition probability != 1 for state %d\n",
347 double cumulative = 0.0;
357 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.
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.
virtual const std::string name() const
#define SERIALIZE_SCALAR(scalar)
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)
virtual void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
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.