RecoSim  1.0
 All Classes Files Functions Variables Enumerations
reconfiguration_manager_base.h
Go to the documentation of this file.
1 
21 #ifndef RECONFIGURATION_MANAGER_BASE_H
22 #define RECONFIGURATION_MANAGER_BASE_H
23 
24 #define SC_INCLUDE_DYNAMIC_PROCESSES
25 
26 #include <systemc.h>
27 #include "tlm.h"
28 #include "tlm_utils/peq_with_cb_and_phase.h"
29 #include "tlm_utils/multi_passthrough_initiator_socket.h"
30 #include "tlm_utils/multi_passthrough_target_socket.h"
31 #include "tlm_utils/simple_target_socket.h"
32 #include "tlm_utils/simple_initiator_socket.h"
33 
34 #include "memory_manager.h"
35 #include "trace.h"
36 #include "utils.h"
37 #include "manager_interface.h"
38 #include "reconfigurable_zone.h"
40 #include "my_priority_queue.h"
41 #include "simulation_controller.h"
42 #include "fpga.h"
43 #include "task.h"
44 #include "application.h"
45 #include "scheduler_interface.h"
46 #include "scheduling.h"
47 #include "reconfiguration_unit.h"
48 #include "scheduler_request.h"
49 #include "configuration_request.h"
50 #include "monitoring_interface.h"
51 #include "qos_management.h"
52 
53 #include <map>
54 #include <vector>
55 #include <list>
56 
57 using namespace sc_core;
58 using namespace sc_dt;
59 using namespace std;
60 using namespace tlm;
61 using namespace tlm_utils;
62 
63 //#define GENERATE_RZ_STATE_FILE
64 //#define GENERATE_TASK_STATE_FILE
65 
66 /* For User : Return information from Mapping Algorithm */
68 
69  Task_state state;
70  sc_time last_running_time;
71  sc_time running_time_duration;
72 
73 public:
75  reset_time();
76  }
77 
79  state = other.state;
80  last_running_time = other.last_running_time;
81  running_time_duration = other.running_time_duration;
82  }
83 
84  // New Task Execution
85  void reset_time() {
86  state = IDLE;
87  last_running_time = sc_time(0, SC_NS);
88  running_time_duration = sc_time(0, SC_NS);
89  }
90 
91  void update_running_time(Task_state new_state) {
92 
93  sc_time current_time = sc_time_stamp();
94 
95  if (new_state == IDLE) {
96  reset_time();
97  }
98  else if (new_state == RUNNING && state != RUNNING) {
99  last_running_time = current_time;
100  }
101  else if (state == RUNNING) {
102  running_time_duration += (current_time - last_running_time);
103  last_running_time = current_time;
104  }
105 
106  state = new_state;
107  }
108 
109  sc_time get_running_time_duration() {
110  if (state == RUNNING)
111  return running_time_duration + (sc_time_stamp() - last_running_time);
112  else
113  return running_time_duration;
114  }
115 
116 };
117 
118 
119 class Reconfiguration_manager_base : public sc_module, public Scheduler_interface, public Monitoring_interface, public QoS_interface {
120 
121 protected:
122  //
123  // Simulation and scheduler parameters
124  //
125  static sc_time SCHEDULER_EXECUTION_TIME;
126  static double SCHEDULER_ENERGY_CONSUMPTION;
127  static double ENERGY_CONSUMPTION_LIMIT;
128  static bool GENERATE_ZERO_FILLED_LINE_IN_CSV;
129  static double SCHEDULER_PERFORMANCE_EFFORT;
130  static double SCHEDULER_POWER_EFFORT;
131  static double SCHEDULER_AREA_EFFORT;
132  static int NB_HW_RECONFIGURATION_UNITS;
133  static int NB_SW_RECONFIGURATION_UNITS;
134  static bool ALL_DEPENDENCIES_REQUIRED_BEFORE_REQUEST;
135  static sc_time TRACE_WINDOW_FUNCTION_LENGTH;
136  static sc_time MAXIMUM_SIMULATION_TIME;
137 
138  //
139  // Simulation controller part
140  //
143  //
144  // Constants
145  //
146  static int RZ_TASK_BLANK;
147  static bool CONSIDER_WAITING_STATE_AS_RUNNING_MODE;
148  static bool SEND_CONFIGURATION_NOTIFICATION_AFTER_IDLE_STATE;
149 
150 public:
151 
152  // Configuration interface to sub-modules
153  multi_passthrough_target_socket<Reconfiguration_manager_base> module_target_socket;
154 
155  // Communication interface, taking orders from user
156  multi_passthrough_target_socket<Reconfiguration_manager_base> testbench_target_socket;
157 
158  // Configuration interface to sub-modules
159  multi_passthrough_initiator_socket<Reconfiguration_manager_base> module_initiator_socket;
160 
161  // Communication interface, taking orders from user
162  multi_passthrough_initiator_socket<Reconfiguration_manager_base> testbench_initiator_socket;
163 
164 
165 protected:
166  // Memory manager
167  Memory_manager m_mm;
168 
169  // Events
170  sc_event scheduler_thread_event; // Event to check waiting queue
171 
172  // Log file stream
173  ofstream* fout;
174 #ifdef GENERATE_TASK_STATE_FILE
175  ofstream file_task_state;
176 #endif
177 #ifdef GENERATE_RZ_STATE_FILE
178  ofstream file_rz_state;
179 #endif
180 
181  // Trace file
182  sc_trace_file* tf;
183  trace_packet_manager_t* trace_packet;
184 
185  // Maps for scheduling
186  map<int, vector<RZ *> > map_compatible_rz;
187  map<RZ *, int> map_current_module;
188  vector<Task_state> task_state_table;
189 
190  // Application & Architecture
191  vector<Manager_interface *> modules_table;
192  vector<RZ *> rz_table;
193  TaskImplementation* previous_implementation_on_RZ;
194  TaskImplementation* current_implementation_on_RZ;
195  static vector<Application> applicationVector;
196 
197  // Preemption gestion
198  vector<int> preempted_tasks_list;
199 
200  // Running time of tasks
201  vector<Running_time_information> running_time_table;
202 
203  // Reconfiguration engine
204  ReconfigurationUnit* hw_reconfiguration_units;
205  list<ConfigurationRequest> reconfiguration_waiting_list;
206  sc_event* hw_reconfiguration_event_table;
207 
208  // Software reconfiguration engine
209  ReconfigurationUnit* sw_reconfiguration_units;
210  list<ConfigurationRequest> software_reconfiguration_waiting_list;
211  sc_event* sw_reconfiguration_event_table;
212 
213  // Scheduler
214  void (*waiting_queue_handler_ptr)(Scheduler_interface &);
215  int nb_calls_scheduler;
216  sc_time scheduler_busy_time;
217  vector<vector<int> > finished_precedence_vectors;
218 
219  // Monitoring
220  vector<sc_event* > monitoring_end_of_scheduling_event_list;
221  vector<sc_event* > monitoring_start_of_scheduling_event_list;
222  vector<sc_event* > monitoring_update_rz_state_event_list;
223  vector<sc_event* > monitoring_update_task_state_event_list;
224 
225  // QoS Management
226  QoS_management *qos_management;
227 
228  // Misc
229  static FPGA* fpga;
230  vector<Task> task_table;
231  double total_energy_consumption;
232 
233  map<string, RZ_config*> rz_parameter_table;
234 
235 
236  sc_time *deadlines_table;
237 
238  sc_buffer<ConfigurationRequest> *rz_configuration_request_buffer;
239  sc_event *rz_configured_event;
240 
241  bool simulationOK;
242 
243 public:
244  SC_HAS_PROCESS(Reconfiguration_manager_base);
245  Reconfiguration_manager_base(sc_module_name instname, vector<RZ *> rzs, vector<Task> tasks, void (*handler)(Scheduler_interface &), FPGA* device, ofstream& logfile, sc_trace_file* mtf, map<string, RZ_config*>& table) :
246  sc_module(instname),
247  module_initiator_socket("Manager2Module_initiator_socket"),
248  testbench_initiator_socket("Manager2Testbench_initiator_socket"),
249  module_target_socket("Manager2Module_target_socket"),
250  testbench_target_socket("Manager2Testbench_target_socket"),
251  rz_table(rzs),
252  fout(&logfile),
253 
254 #ifdef GENERATE_TASK_STATE_FILE
255  file_task_state("log/task.csv"),
256 #endif
257 #ifdef GENERATE_RZ_STATE_FILE
258  file_rz_state("log/rz.csv"),
259 #endif
260  scheduler_busy_time(SC_ZERO_TIME),
261  tf(mtf),
262  task_table(tasks),
263  rz_parameter_table(table),
264  waiting_queue_handler_ptr(handler) {
265 
266 #ifdef GENERATE_RZ_STATE_FILE
267  for(int i = 0; i < (int) rz_table.size(); i++) file_rz_state << "; " << rz_table[i]->getName();
268  file_rz_state << endl;
269 #endif
270 
271  nb_calls_scheduler = 0;
272  total_energy_consumption = 0;
273 
274  simulationOK = false;
275 
276  //fpga = new FPGA(device);
277 
278  fpga = device;
279 
280  previous_implementation_on_RZ = new TaskImplementation[(int) rz_table.size()];
281  current_implementation_on_RZ = new TaskImplementation[(int) rz_table.size()];
282  for(int i = 0; i < (int) rz_table.size(); i++) {
283  previous_implementation_on_RZ[i] = TaskImplementation();
284  current_implementation_on_RZ[i] = TaskImplementation();
285  }
286 
287  // Set Nominal Point for RZ
288  if (Scheduler_exist_rz_properties("RZDefaultGroupName") == true) {
289  RZ_config rz_config = Scheduler_get_rz_properties("RZDefaultGroupName");
290  Config_fct_point hwRZdefaultPt;
291  string hwRZdomainName = "";
292  if (rz_config.getConfigDomain() != NULL) {
293  hwRZdefaultPt = rz_config.getConfigDomain()->getNominalFctPoint();
294  hwRZdomainName = rz_config.getConfigDomain()->getGroupName();
295  }
296 
297  for(int i = 0; i < (int) rz_table.size(); i++) {
298  RZ *rz = rz_table.at(i);
299  if (rz->get_implementation_type() == HARD) {
300  rz->setConfigFctPoint(&hwRZdefaultPt);
301  rz->setGroupDomainName(hwRZdomainName);
302  }
303  else {
304  rz_config = Scheduler_get_rz_properties(rz);
305  if (rz_config.getConfigDomain() != NULL) {
306  Config_fct_point swRZdefaultPt = rz_config.getConfigDomain()->getNominalFctPoint();
307  rz->setConfigFctPoint(&swRZdefaultPt);
308  rz->setGroupDomainName(rz_config.getConfigDomain()->getGroupName());
309  }
310  }
311  }
312  }
313 
314  hw_reconfiguration_units = new ReconfigurationUnit[NB_HW_RECONFIGURATION_UNITS];
315  sw_reconfiguration_units = new ReconfigurationUnit[NB_SW_RECONFIGURATION_UNITS];
316 
317  hw_reconfiguration_event_table = new sc_event[NB_HW_RECONFIGURATION_UNITS];
318  sw_reconfiguration_event_table = new sc_event[NB_SW_RECONFIGURATION_UNITS];
319 
320  SC_THREAD(scheduler_thread); // Scheduler process
321  SC_THREAD(occupation_rate_update_thread); // Occupation rate automatic update thread
322 
323  // Register transport methods
324  module_target_socket.register_b_transport(this, &Reconfiguration_manager_base::b_transport_module);
325  testbench_target_socket.register_b_transport(this, &Reconfiguration_manager_base::b_transport_testbench);
326 
327  // HW reconfiguration engines dynamic threads
328  for(int i = 0; i < NB_HW_RECONFIGURATION_UNITS; i++) {
329  string process_name("HW_reconfiguration_unit_");
330  ostringstream out;
331  out << i;
332  process_name.append(out.str());
333 
334  sc_spawn(sc_bind(&Reconfiguration_manager_base::hardware_reconfiguration_engine_thread, this, i), process_name.c_str());
335  }
336 
337  // SW reconfiguration engines dynamic threads
338  for(int i = 0; i < NB_SW_RECONFIGURATION_UNITS; i++) {
339  string process_name("SW_reconfiguration_unit_");
340  ostringstream out;
341  out << i;
342  process_name.append(out.str());
343 
344  sc_spawn(sc_bind(&Reconfiguration_manager_base::software_reconfiguration_engine_thread, this, i), process_name.c_str());
345  }
346 
347  rz_configuration_request_buffer = new sc_buffer<ConfigurationRequest>[(int) rz_table.size()];
348  rz_configured_event = new sc_event[(int) rz_table.size()];
349  for(int i = 0; i < (int) rz_table.size(); i++) {
350  string process_name("RZ_configuration_request_handler_");
351  process_name.append(Utils::itoa(i));
352  sc_spawn(sc_bind(&Reconfiguration_manager_base::rz_configuration_request_thread, this, i), process_name.c_str());
353  }
354  }
355 
357  delete trace_packet;
358  delete deadlines_table;
359  delete[] previous_implementation_on_RZ;
360  delete[] current_implementation_on_RZ;
361  delete[] hw_reconfiguration_units;
362  delete[] sw_reconfiguration_units;
363  delete[] hw_reconfiguration_event_table;
364  delete[] sw_reconfiguration_event_table;
365  //delete qos_management;
366 
367  for (int i=0; i<(int)monitoring_end_of_scheduling_event_list.size(); i++) {
368  delete monitoring_end_of_scheduling_event_list.at(i);
369  delete monitoring_start_of_scheduling_event_list.at(i);
370  delete monitoring_update_rz_state_event_list.at(i);
371  delete monitoring_update_task_state_event_list.at(i);
372  }
373 
374  for(int i = 0; i < (int) rz_table.size(); i++) delete rz_table.at(i);
375  }
376 
377  // Application definition
378  int addApplication(string appName, string appPrefix, vector<Manager_interface *> table, double qos, int appInstanceID = -1);
379  void applicationDefined(void);
380 
381  // TLM transport methods
382  virtual void b_transport_module(int id, tlm_generic_payload& trans, sc_time& delay) = 0;
383  virtual void b_transport_testbench(int id, tlm_generic_payload& trans, sc_time& delay) = 0;
384 
385  // User interface
386  void set_scheduler_execution_time(sc_time t);
387  void set_generate_zeros_in_csv(bool gen);
388  void display_occupation_rates(void);
389  void generateSimulationResultFile(void);
390  void update_occupation_rate_end_simulation(void);
391  void enable_debug_signals_trace(void);
392  void activate_trace(void);
393  void generateCSVResultFile(string filename);
394 
395  static vector<Application> * getApplicationVectorPtr(void);
396 
397  // Simulation controller part
398  bool isSimulationOK(void);
399  static void endApplication(string appname, bool ok);
400  static void verifySimulationTimes(void);
401  static sc_time getMaximumSimulationTime(void);
402 
403  // ===== Scheduler interface =====
404  vector<RZ *> Scheduler_get_compatible_rz_vector(int task_id);
405  sc_time Scheduler_get_task_running_time(int task_id);
406  vector<RZ *> Scheduler_get_all_rz_vector(void);
407  int Scheduler_get_current_module_ID(RZ* rz);
408  bool Scheduler_is_RZ_blank(RZ *rz);
409  int Scheduler_get_module_ID(SchedulerRequest&);
410  int Scheduler_get_application_number(void);
411  Application_interface* Scheduler_get_application_interface(int index);
412  bool Scheduler_exist_rz_properties(string inst_name);
413  bool Scheduler_exist_rz_properties(RZ *rz);
414  RZ_config& Scheduler_get_rz_properties(string inst_name);
415  RZ_config& Scheduler_get_rz_properties(RZ* rz);
416  Config_fct_point& Scheduler_get_current_fct_point(RZ *rz);
417  void Scheduler_emulate_scheduler_behavior(void);
418  void Scheduler_set_scheduler_active(int taskid);
419  bool Scheduler_has_task_already_requested_mapping(int task_to_map, int request_owner);
420  void Scheduler_add_finished_precedence(int task_mapped, int precedence);
421  void Scheduler_notify_request_owner_module_ready(int owner, int ready);
422  void Scheduler_send_update_parameters_to_module(RZ* rz);
423  void Scheduler_print_finished_precedence_vector(int task_id);
424  void Scheduler_configure_task(RZ* rz, int id, int implID, int requestOwner);
425  void Scheduler_rerun_task(SchedulerRequest&);
426  void Scheduler_set_current_task(RZ *rz, int task_id);
427  Task_state Scheduler_get_task_state(int task_id);
428  bool Scheduler_set_blank(RZ *rz);
429  bool Scheduler_set_blank(int hosting_rz_id);
430  Task_state Scheduler_get_task_state(RZ *rz);
431  bool Scheduler_is_task_preempted(int taskid) const;
432  double Scheduler_get_performance_effort(void) const;
433  double Scheduler_get_power_effort(void) const;
434  double Scheduler_get_area_effort(void) const;
435  const char* Scheduler_get_name(void) const;
436  ostream& Scheduler_get_output_stream(void);
437  void Scheduler_display_task_state_table(void) const;
438  void Scheduler_display_rz_current_module_table(void) const;
439  Task_to_schedule_interface* Scheduler_get_task_to_schedule_ptr(int taskID);
440 
441  static FPGA* getFPGAptr(void);
442  //static bool isInterfaceDefined(string if_name);
443 
444  // Monitoring
445  void setMonitoringEvent(int threadNumber);
446  void notifyStartOfSchedulingEventMonitoringEvent();
447  void notifyEndOfSchedulingEventMonitoringEvent();
448  void notifyUpdateRZStateEvent();
449  void notifyUpdateTaskStateEvent();
450  RZ_config* getRZProperties(string inst_name);
451 
452  // Monitoring Interface
453  sc_event& endOfSchedulingEvent(int id);
454  sc_event& startOfSchedulingEvent(int id);
455  sc_event& updateRZStateEvent(int id);
456  sc_event& updateTaskStateEvent(int id);
457 
458  // QoS Interface
459  vector<Application>& getApplications();
460 
461  // Common QoS & Monitoring Interface
462  sc_trace_file* getTraceFile() const;
463  Scheduler_interface& getShedulerInterface();
464 
465 
466 protected:
467  // Communication with submodules / scheduling
468  void scheduler_thread(void);
469  void send_next_module_ready(int module_id, int module_ready_id);
470  void send_current_module_ready(int module_id);
471  void send_module_ready_to_testbench(int tbid, int module_ready_id);
472  void notify_request_owner_module_ready(int owner_id, int ready_module_id);
473  void send_update_parameters(int module_id, Algorithm_Parameters* rz);
474 
475  // Initialization
476  void init_maps(void);
477  void transcoder_initialisation_method(int id, sc_dt::uint64 data);
478 
479  // Reconfiguration engine
480  void configure_task(int id, int implID, RZ* rz);
481  void reconfiguration_engine_thread(void);
482  void hardware_reconfiguration_engine_thread(int unitID);
483  void software_reconfiguration_engine_thread(int unitID);
484 
485  // Simulation control
486  void check_deadline(int task_id);
487  void notify_simulation_controller(void);
488 
489  // Preemption stuff
490  bool is_task_preempted(int id) const;
491  bool is_task_preempted(string taskname) const;
492  void add_task_to_preemption_list(int id);
493  void remove_task_from_preemption_list(int id);
494 
495  // Trace packet & monitoring methods
496  void set_target_phase(tlm_phase phase);
497  void set_icap_reconf_task(int hw_unit, int id);
498  void set_icap_idle(int hw_unit);
499  void set_software_loader_config_task(int sw_unit, int id);
500  void set_software_loader_idle(int sw_unit);
501  void set_task_state(int id, int rz_id, Task_state state);
502  void set_rz_state(int rz_id, RZState state);
503  int get_hosting_rz_id(int taskid);
504  void update_occupation_rate(int rz_id, RZState newState);
505  void set_initiator_phase(int id, tlm_phase phase);
506  void set_scheduler_idle(void);
507  void set_scheduler_active(int taskID);
508  void occupation_rate_update_thread(void);
509  void update_resources_trace(int rz_id, int task_id);
510  void update_processor_occupation_rate(void);
511  void set_hyperperiod_status(int hpid);
512 
513  // Misc
514  void display_map_compatible_RZ(void);
515  void display_map_current_module(void);
516  void display_task_state_table(void) const;
517  void display_rz_current_module_table(void) const;
518  bool task_runs_on_implementation_type(int taskID, PEImplementation impl);
519  int getApplicationIncludingTask(int taskID);
520  void deadline_check_thread(int appID);
521 
522  int getRZID(RZ *rz);
523  void set_task_context_save(int task_id, int rz_id);
524  void set_task_context_restore(int task_id, int rz_id);
525 
526  int get_module_ID(string moduleName);
527 
528  void update_deadline(int modID);
529 
530  void rz_configuration_request_thread(int rzid);
531 
532 };
533 
534 #endif
Definition: qos_management.h:32
Definition: qos_interface.h:40
void software_reconfiguration_engine_thread(int unitID)
Definition: reconfiguration_manager_base.cpp:748
Definition: task_to_schedule_interface.h:28
Definition: reconfiguration_unit.h:32
Definition: monitoring_interface.h:63
Definition: memory_manager.h:29
Definition: fpga.h:30
Definition: config_fct_point.h:31
Definition: reconfiguration_manager_base.h:119
Definition: reconfigurable_zone.h:62
Definition: rz_config.h:36
Definition: scheduler_request.h:27
static int nbApplicationTerminated
Definition: reconfiguration_manager_base.h:141
Definition: application_interface.h:29
Definition: scheduler_request.h:47
void hardware_reconfiguration_engine_thread(int unitID)
Definition: reconfiguration_manager_base.cpp:681
Definition: reconfiguration_manager_base.h:67
Task_state
Definition: task_implementation.h:40
Definition: trace.h:184
Definition: task_implementation.h:46
Definition: scheduler_interface.h:138