28 #ifndef SC_SIMCONTEXT_H 
   29 #define SC_SIMCONTEXT_H 
   38 #include <unordered_map> 
   44 #ifndef _SYSC_PRINT_VERBOSE_MESSAGE_ENV_VAR 
   45 #define _SYSC_PRINT_VERBOSE_MESSAGE_ENV_VAR "SYSC_PRINT_VERBOSE_MESSAGE" 
   56 class sc_export_registry;
 
   59 class sc_module_registry;
 
   62 class sc_object_manager;
 
   63 class sc_phase_callback_registry;
 
   64 class sc_process_handle;
 
   65 class sc_port_registry;
 
   66 class sc_prim_channel_registry;
 
   67 class sc_process_table;
 
   68 class sc_signal_bool_deval;
 
   71 class sc_process_host;
 
   72 class sc_method_process;
 
   73 class sc_cthread_process;
 
   74 class sc_thread_process;
 
   94 extern void sc_start( 
const sc_time& duration, 
 
  117         const   sc_simcontext* simc_p);
 
  119         const   sc_simcontext* simc_p);
 
  133 struct sc_invoke_method; 
 
  440                                  bool preserve_first = 
false  
  454     int seg_id, 
int inst_id );
 
  465     int seg_id, 
int inst_id );
 
  476     int seg_id, 
int inst_id );
 
  531         { 
return m_cor_pkg; }
 
  620     void clean_up_old_event_notifications();
 
  621     void predict_wakeup_time_by_running_ready_threads(std::unordered_map<sc_process_b*, sc_timestamp>& wkup_t_prd_run_rdy);
 
  622     void predict_wakeup_time_by_events(std::unordered_map<
sc_process_b*,
 
  623         std::map<sc_event*, sc_timestamp> >& wkup_t_evnt);
 
  624     void predict_wakeup_time_by_waiting_threads(
 
  625         std::unordered_map<sc_process_b*, sc_timestamp>& wkup_t_pred_and_evnt,
 
  626         std::unordered_map<
sc_process_b*, std::map<sc_event*, sc_timestamp> >& wkup_t_evnt,
 
  627         std::unordered_map<sc_process_b*, sc_timestamp>& wkup_t_prd_run_rdy);
 
  628     bool check_and_deliver_events();
 
  633     void remove_child_event( 
sc_event* );
 
  639     void remove_delta_event( 
sc_event* );
 
  642     void trace_cycle( 
bool delta_cycle );
 
  644     const ::std::vector<sc_event*>& get_child_events_internal() 
const;
 
  645     const ::std::vector<sc_object*>& get_child_objects_internal() 
const;
 
  676     void requeue_current_process();
 
  677     void suspend_current_process();
 
  679     void do_sc_stop_action();
 
  686     void acquire_sched_mutex();
 
  692     void release_sched_mutex();
 
  698     bool has_no_conflicts( 
sc_process_b*, std::list<sc_method_handle>, std::list<sc_thread_handle> );
 
  716   int combined_data_conflict_table_index_lookup( 
int , 
int  );
 
  722   int event_prediction_table_index_lookup( 
int , 
int  );
 
  728   int prediction_time_advance_table_index_lookup( 
int);
 
  734   bool conflict_between_two_segs(
 
  765     void update_oldest_time( 
sc_time& curr_time );
 
  770     enum execution_phases {
 
  771         phase_initialize = 0,
 
  776     sc_object_manager*          m_object_manager;
 
  778     sc_module_registry*         m_module_registry;
 
  779     sc_port_registry*           m_port_registry;
 
  780     sc_export_registry*         m_export_registry;
 
  781     sc_prim_channel_registry*   m_prim_channel_registry;
 
  784     sc_name_gen*                m_name_gen;
 
  786     sc_process_table*           m_process_table;
 
  791     std::list<sc_process_b*>    m_curr_proc_queue;
 
  802     std::vector<sc_thread_handle> m_active_invokers;
 
  804     std::vector<sc_event*>      m_child_events;
 
  805     std::vector<sc_object*>     m_child_objects;
 
  807     std::vector<sc_event*>      m_delta_events;
 
  808     sc_ppq<sc_event_timed*>*    m_timed_events;
 
  810     std::vector<sc_trace_file*> m_trace_files;
 
  811     bool                        m_something_to_trace;
 
  816     sc_time_params*             m_time_params;
 
  831     bool                        m_ready_to_simulate;
 
  832     bool                        m_elaboration_done;
 
  833     execution_phases            m_execution_phase;
 
  835     bool                        m_in_simulator_control;   
 
  836     bool                        m_end_of_simulation_called;
 
  838     bool                        m_start_of_simulation_called;
 
  840     sc_cor_pkg*                 m_cor_pkg; 
 
  845     bool                        m_one_delta_cycle; 
 
  846     bool                        m_one_timed_cycle;
 
  853   long*           workload_table;
 
  859   std::list<sc_process_b*>    m_waiting_proc_queue;
 
  878     std::vector<sc_process_b*>      m_paused_processes;
 
  892 std::map<sc_process_b*,Invoker*> method_to_invoker_map;
 
  893 std::vector<Invoker*> m_invokers;
 
  894 std::set<Invoker*> ready_invokers;
 
  895 std::set<Invoker*> running_invokers;
 
  897 bool event_notification_update;
 
  899 unsigned int running_methods;
 
  934     return m_elaboration_done;
 
  941                   m_simulation_status :
 
  952     if( m_forced_stop ) {
 
  963     return m_object_manager;
 
  970     return m_module_registry;
 
  977     return m_port_registry;
 
  984     return m_export_registry;
 
  991     return m_prim_channel_registry;
 
  999     return ( ++ m_next_proc_id );
 
 1023     return m_change_stamp;
 
 1032     return m_change_stamp == last_change_stamp;
 
 1039     return (m_execution_phase == phase_evaluate) &&
 
 1040            m_ready_to_simulate;
 
 1047     return m_execution_phase == phase_update;
 
 1054     return m_execution_phase == phase_notify;
 
 1070     return m_error != NULL;
 
 1075 sc_simcontext::add_delta_event( 
sc_event* e )
 
 1077     m_delta_events.push_back( e );
 
 1078     return ( m_delta_events.size() - 1 );
 
 1083 sc_simcontext::add_timed_event( sc_event_timed* et )
 
 1085     m_timed_events->insert( et );
 
 1098     return m_write_check;
 
 1104     m_curr_proc_queue.remove( proc );
 
 1110     for ( std::list<sc_process_b*>::iterator it = m_curr_proc_queue.begin(); 
 
 1111           it != m_curr_proc_queue.end(); it++ )
 
 1183     return simc_p->m_child_events;
 
 1190     return simc_p->m_child_objects;
 
 1217     return simc_p->m_ready_to_simulate;
 
 1232   return simc_p->pending_activity_at_current_time();
 
 1241   return simc_p->next_time( ignored );
 
int _OoO_Prediction_Event_Notification_Table_Delta[]
friend sc_dt::uint64 sc_delta_count()
This function returns the local delta count of the running process. 
void sc_set_time_resolution(double, sc_time_unit)
sc_process_b * sc_get_current_process_b()
void hierarchy_push(sc_module *)
friend struct sc_invoke_method
long long _OoO_Next_Time_Advance_Table_Time[]
Next time advance table (timed cycles) for the out-of-order simulation. 
bool evaluation_phase() const 
unsigned int _OoO_Combined_Data_Conflict_Lookup_Table_Number_Segments
friend sc_time sc_time_to_pending_activity(const sc_simcontext *)
static sc_time from_value(value_type)
unsigned int _OoO_Time_Advance_Index_Lookup_Table_Size
Size of the index lookup table for the time advance table. 
friend sc_cor * get_cor_pointer(sc_process_b *process_p)
bool notify_phase() const 
A scoped mutex for the kernel lock. 
unsigned int _OoO_Curr_Time_Advance_Table_Size
Size of the current time advance table. 
Coroutine package abstract base class. 
sc_process_b sc_process_b
void simulate(const sc_time &duration)
A time stamp combining timed cycles and delta cycles. 
Registry for all modules. 
void print_events_states()
sc_object * get_current_writer() const 
unsigned int _OoO_Prediction_Event_Notification_Table_No_Indirect_Max_Instances
sc_object * sc_find_object(const char *name)
void oooschedule(sc_cor *cor)
Scheduling function in the OoO simulation. 
const sc_time & get_current_trace_time()
Class for storing the time to notify a timed event. 
int sc_get_simulator_status()
sc_port_registry * get_port_registry()
This class provides access to an sc_process_b object instance in a manner which allows some persisten...
sc_time sc_get_time_resolution()
bool sc_allow_process_control_corners
int _OoO_Combined_Data_Conflict_Table[]
void(sc_process_host::* SC_ENTRY_FUNC)()
Registry for all exports. 
bool sc_pending_activity(const sc_simcontext *simc_p=sc_get_curr_simcontext())
bool is_not_owner()
Check whether the kernel lock is not owned by the currently running coroutine. 
void add_trace_file(sc_trace_file *)
unsigned int _OoO_Data_Conflict_Table_Size
Size of the data conflict table. 
sc_object * next_object()
sc_time sc_get_default_time_unit()
sc_object * find_object(const char *name)
void cycle(const sc_time &)
This function is not supported by the out-of-order simulation in the current release. 
sc_curr_proc_kind sc_get_curr_process_kind()
friend void sc_set_default_time_unit(double, sc_time_unit)
unsigned int _OoO_Combined_Data_Conflict_Lookup_Table_Max_Instances
friend bool sc_end_of_simulation_invoked()
friend class sc_phase_callback_registry
friend void sc_method_cor_fn(void *)
Coroutine abstract base class. 
sc_starvation_policy m_starvation_policy
long long _OoO_Curr_Time_Advance_Table_Time[]
Current time advance table (timed cycles) for the out-of-order simulation. 
unsigned int conflict_table_index_lookup(int, int)
Convert segment ID and instance ID to index in the data conflict table and event notification table...
bool update_phase() const 
sc_timestamp m_simulation_time
unsigned int _OoO_Event_Notify_Table_Size
Size of the event notification table. 
class sc_method_process * sc_method_handle
bool event_occurred(sc_dt::uint64 last_change_count) const 
bool is_locked_and_owner()
Check whether the kernel lock is acquired and owned by the currently running coroutine. 
sc_process_b * get_curr_proc() const 
bool sc_is_running(const sc_simcontext *simc_p)
void sc_set_random_seed(unsigned int seed_)
bool _OoO_Data_Conflict_Table[]
Data conflict table for the out-of-order simulation. 
sc_object * active_object()
User initiated dynamic process support. 
const std::vector< sc_object * > & sc_get_top_level_objects(const sc_simcontext *simc_p)
unsigned int _OoO_Next_Time_Advance_Table_Size
Size of the next time advance table. 
unsigned int _OoO_Combined_Data_Conflict_Table_Size
bool next_time(sc_time &t) const 
friend sc_time sc_get_time_resolution()
sc_dt::uint64 sc_delta_count()
This function returns the local delta count of the running process. 
friend const std::vector< sc_event * > & sc_get_top_level_events(const sc_simcontext *simc_p)
bool pending_activity_at_current_time() const 
bool _OoO_Event_Notify_Table[]
Event notification table for the out-of-order simulation. 
sc_curr_proc_kind proc_kind() const 
sc_module_registry * get_module_registry()
const char * sc_gen_unique_name(const char *, bool preserve_first)
void resume_cor(sc_cor *)
Resume a coroutine. 
Class that manages the ready-to-run queues. 
int _OoO_Prediction_Time_Advance_Lookup_Table[]
const char * gen_unique_name(const char *basename_, bool preserve_first=false)
unsigned int _OoO_Prediction_Event_Notification_Table_Max_Instances
friend void sc_set_time_resolution(double, sc_time_unit)
bool elaboration_done() const 
sc_object * sc_get_current_object()
class sc_thread_process * sc_thread_handle
int _OoO_Combined_Data_Conflict_Lookup_Table[]
friend sc_time sc_get_default_time_unit()
unsigned int _OoO_Prediction_Event_Notification_Table_Number_Segments
const char * _OoO_Table_File_Name
unsigned int _OoO_Prediction_Time_Advance_Table_Number_Segments
std::list< sc_process_b * > m_all_proc
int _OoO_Time_Advance_Index_Lookup_Table[]
Index lookup table for the time advance table. 
void remove_running_process(sc_process_b *)
Remove a process from the running queue. 
friend const std::vector< sc_object * > & sc_get_top_level_objects(const sc_simcontext *simc_p)
sc_simcontext * sc_curr_simcontext
sc_status sc_get_status()
friend bool sc_is_running(const sc_simcontext *simc_p)
const sc_time & sc_time_stamp()
sc_module * hierarchy_pop()
std::list< sc_process_b * > m_synch_thread_queue
sc_timestamp m_simulation_duration
sc_process_handle sc_get_current_process_handle()
bool is_unlocked()
Check whether the kernel lock is released. 
const sc_time & max_time() const 
const sc_time & get_oldest_untraced_time()
sc_prim_channel_registry * get_prim_channel_registry()
sc_time sc_time_to_pending_activity(const sc_simcontext *)
int _OoO_Prediction_Event_Notification_Lookup_Table[]
long long _OoO_Prediction_Time_Advance_Table_Time_Units[]
const sc_time & time_stamp()
unsigned int _OoO_Number_of_Segments
The number of segments. 
int _OoO_Prediction_Time_Advance_Table_Delta[]
Base class for all structural entities. 
int _OoO_Prediction_Event_Notification_Table_No_Indirect_Delta[]
const ::std::vector< sc_object * > & get_child_objects() const 
sc_object_manager * get_object_manager()
sc_process_handle create_cthread_process(const char *name_p, bool free_host, SC_ENTRY_FUNC method_p, sc_process_host *host_p, const sc_spawn_options *opt_p, int seg_id, int inst_id)
Two new parameters segment ID and instance ID are added for the out-of-order simulation. 
void print_threads_states()
bool is_running_process(sc_process_b *)
Check whether a process is in the running queue. 
std::list< sc_process_b * > m_waking_up_threads
void initialize(bool=false)
bool is_locked()
Check whether the kernel lock is acquired. 
void sc_set_stop_mode(sc_stop_mode mode)
void remove_trace_file(sc_trace_file *)
void initial_crunch(bool no_crunch)
This function is partially supported by the out-of-order simulation in the current release...
Registry for all primitive channels. 
unsigned int _OoO_Prediction_Event_Notification_Table_No_Indirect_Number_Segments
double sc_simulation_time()
unsigned int _OoO_Prediction_Time_Advance_Table_Number_Steps
Base class for all hierarchical channels. 
const std::vector< sc_event * > & sc_get_top_level_events(const sc_simcontext *simc_p)
friend void sc_start(const sc_time &, sc_starvation_policy)
bool sc_pending_activity_at_current_time(const sc_simcontext *)
long long _OoO_Prediction_Event_Notification_Table_No_Indirect_Time_Units[]
friend bool sc_pending_activity_at_current_time(const sc_simcontext *)
friend bool sc_start_of_simulation_invoked()
bool is_lock_owner()
Check whether the kernel lock is owned by the currently running coroutine. 
sc_simcontext * sc_get_curr_simcontext()
int _OoO_Conflict_Index_Lookup_Table[]
Index lookup table for the data conflict table and event notification table. 
sc_plist< sc_process_b * > sc_process_list
void set_curr_proc(sc_process_b *)
This function is not supported by the out-of-order simulation in the current release. 
int _OoO_Next_Time_Advance_Table_Delta[]
Next time advance table (delta cycles) for the out-of-order simulation. 
const sc_time SC_ZERO_TIME
bool sc_hierarchical_name_exists(const char *name)
void set_error(sc_report *)
bool sc_end_of_simulation_invoked()
int _OoO_Curr_Time_Advance_Table_Delta[]
Current time advance table (delta cycles) for the out-of-order simulation. 
This is the base class for objects which may have processes defined for their methods (e...
sc_simcontext * sc_default_global_context
sc_process_b * sc_get_curr_process_handle()
sc_dt::uint64 change_stamp() const 
sc_status get_status() const 
friend void sc_thread_cor_fn(void *)
unsigned int time_adv_table_index_lookup(int)
Convert segment ID to index in the time advance table. 
unsigned int _OoO_Max_Number_of_Instances
The maximum number of instances. 
const int SC_SIM_USER_STOP
sc_module * hierarchy_curr() const 
const sc_timestamp & get_timestamp()
Set the local time stamp of this process. 
value_type get_delta_count() const 
Get the value of delta cycles. 
int _OoO_Prediction_Event_Notification_No_Indirect_Lookup_Table[]
sc_stop_mode sc_get_stop_mode()
sc_process_handle create_method_process(const char *name_p, bool free_host, SC_ENTRY_FUNC method_p, sc_process_host *host_p, const sc_spawn_options *opt_p, int seg_id, int inst_id)
Two new parameters segment ID and instance ID are added for the out-of-order simulation. 
const sc_time & sc_max_time()
sc_dt::uint64 delta_count() const 
friend bool sc_pending_activity_at_future_time(const sc_simcontext *)
sc_object * first_object()
segment id currently only used for sc_fifo::read(...) as a bug fix 
bool sc_pending_activity_at_future_time(const sc_simcontext *)
sc_process_handle create_thread_process(const char *name_p, bool free_host, SC_ENTRY_FUNC method_p, sc_process_host *host_p, const sc_spawn_options *opt_p, int seg_id, int inst_id)
Two new parameters segment ID and instance ID are added for the out-of-order simulation. 
void suspend_cor(sc_cor *)
Suspend a coroutine. 
std::vector< sc_thread_handle > & get_active_invokers()
Abstract base class of all primitive channel classes. 
Abstract base class of all SystemC `simulation' objects. 
sc_event * sc_find_event(const char *name)
void sc_set_default_time_unit(double, sc_time_unit)
void prepare_to_simulate()
sc_export_registry * get_export_registry()
bool sc_start_of_simulation_invoked()
long long _OoO_Prediction_Event_Notification_Table_Time_Units[]