28 #ifndef SC_SIMCONTEXT_H
29 #define SC_SIMCONTEXT_H
38 #include <unordered_map>
39 #include <unordered_set>
45 #ifndef _SYSC_PRINT_VERBOSE_MESSAGE_ENV_VAR
46 #define _SYSC_PRINT_VERBOSE_MESSAGE_ENV_VAR "SYSC_PRINT_VERBOSE_MESSAGE"
57 class sc_export_registry;
60 class sc_module_registry;
63 class sc_object_manager;
64 class sc_phase_callback_registry;
65 class sc_process_handle;
66 class sc_port_registry;
67 class sc_prim_channel_registry;
68 class sc_process_table;
69 class sc_signal_bool_deval;
72 class sc_process_host;
73 class sc_method_process;
74 class sc_cthread_process;
75 class sc_thread_process;
95 extern void sc_start(
const sc_time& duration,
118 const sc_simcontext* simc_p);
120 const sc_simcontext* simc_p);
134 struct sc_invoke_method;
444 bool preserve_first =
false
458 int seg_id,
int inst_id );
469 int seg_id,
int inst_id );
480 int seg_id,
int inst_id );
535 {
return m_cor_pkg; }
624 void clean_up_old_event_notifications();
625 void predict_wakeup_create_defining_tree(
626 std::unordered_map<
sc_process_b*, std::unordered_map<sc_event*, sc_timestamp> >& wkup_t_evnt);
627 void predict_wakeup_time_by_running_ready_threads();
628 void predict_wakeup_time_by_events(
629 std::unordered_map<
sc_process_b*, std::unordered_map<sc_event*, sc_timestamp> >& wkup_t_evnt);
630 void predict_wakeup_time_by_waiting_threads(
631 std::unordered_map<
sc_process_b*, std::unordered_map<sc_event*, sc_timestamp> >& wkup_t_evnt);
635 bool check_and_deliver_events();
640 void remove_child_event(
sc_event* );
646 void remove_delta_event(
sc_event* );
649 void trace_cycle(
bool delta_cycle );
651 const ::std::vector<sc_event*>& get_child_events_internal()
const;
652 const ::std::vector<sc_object*>& get_child_objects_internal()
const;
683 void requeue_current_process();
684 void suspend_current_process();
686 void do_sc_stop_action();
693 void acquire_sched_mutex();
699 void release_sched_mutex();
705 bool has_no_conflicts(
sc_process_b*, std::list<sc_method_handle>, std::list<sc_thread_handle> );
707 bool has_no_conflicts_method(
sc_process_b*, std::list<sc_method_handle>, std::list<sc_thread_handle> );
725 int combined_data_conflict_table_index_lookup(
int ,
int );
731 int event_prediction_table_index_lookup(
int ,
int );
737 int prediction_time_advance_table_index_lookup(
int);
743 bool conflict_between_two_segs(
774 void update_oldest_time(
sc_time& curr_time );
779 enum execution_phases {
780 phase_initialize = 0,
785 sc_object_manager* m_object_manager;
787 sc_module_registry* m_module_registry;
788 sc_port_registry* m_port_registry;
789 sc_export_registry* m_export_registry;
790 sc_prim_channel_registry* m_prim_channel_registry;
793 sc_name_gen* m_name_gen;
795 sc_process_table* m_process_table;
800 std::list<sc_process_b*> m_curr_proc_queue;
811 std::vector<sc_thread_handle> m_active_invokers;
813 std::vector<sc_event*> m_child_events;
814 std::vector<sc_object*> m_child_objects;
816 std::vector<sc_event*> m_delta_events;
817 sc_ppq<sc_event_timed*>* m_timed_events;
819 std::vector<sc_trace_file*> m_trace_files;
820 bool m_something_to_trace;
825 sc_time_params* m_time_params;
840 bool m_ready_to_simulate;
841 bool m_elaboration_done;
842 execution_phases m_execution_phase;
844 bool m_in_simulator_control;
845 bool m_end_of_simulation_called;
847 bool m_start_of_simulation_called;
849 sc_cor_pkg* m_cor_pkg;
854 bool m_one_delta_cycle;
855 bool m_one_timed_cycle;
862 long* workload_table;
869 std::unordered_set<sc_process_b*> m_waiting_proc_queue;
888 std::vector<sc_process_b*> m_paused_processes;
902 std::unordered_map<sc_process_b*,Invoker*> method_to_invoker_map;
903 std::vector<Invoker*> m_invokers;
904 std::unordered_set<Invoker*> ready_invokers;
905 std::unordered_set<Invoker*> running_invokers;
907 bool event_notification_update;
909 unsigned int running_methods;
911 int num_kernel_requests;
912 pthread_mutex_t kernel_request_mutex;
914 std::list<sc_process_b*> new_waiting_proc;
915 std::unordered_set<sc_process_b*> mod_wakeup_proc;
916 std::unordered_set<sc_process_b*> defining_tree;
917 unsigned long long total_runrdycheck;
918 unsigned long long total_eventcheck;
919 unsigned long long total_waitcheck;
920 unsigned long long total_threadevent;
921 unsigned long long total_delivery;
922 unsigned long long total_eventpred;
923 std::unordered_map<sc_process_b*,std::unordered_set<sc_event*> > new_event_notify;
960 return m_elaboration_done;
967 m_simulation_status :
978 if( m_forced_stop ) {
989 return m_object_manager;
996 return m_module_registry;
1003 return m_port_registry;
1010 return m_export_registry;
1017 return m_prim_channel_registry;
1025 return ( ++ m_next_proc_id );
1049 return m_change_stamp;
1058 return m_change_stamp == last_change_stamp;
1065 return (m_execution_phase == phase_evaluate) &&
1066 m_ready_to_simulate;
1073 return m_execution_phase == phase_update;
1080 return m_execution_phase == phase_notify;
1096 return m_error != NULL;
1101 sc_simcontext::add_delta_event(
sc_event* e )
1103 m_delta_events.push_back( e );
1104 return ( m_delta_events.size() - 1 );
1109 sc_simcontext::add_timed_event( sc_event_timed* et )
1111 m_timed_events->insert( et );
1124 return m_write_check;
1130 m_curr_proc_queue.remove( proc );
1136 for ( std::list<sc_process_b*>::iterator it = m_curr_proc_queue.begin();
1137 it != m_curr_proc_queue.end(); it++ )
1209 return simc_p->m_child_events;
1216 return simc_p->m_child_objects;
1243 return simc_p->m_ready_to_simulate;
1258 return simc_p->pending_activity_at_current_time();
1267 return simc_p->next_time( ignored );
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)
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()
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 *)
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 update_dependency_set()
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()