/**
@details
-# If real-time synchronization has been enabled:
   -# Set the active flag to true.
-# If real-time synchronization has been disabled set the active flag to false.
*/
int Trick::RealtimeSync::initialize() {

    if ( enable_flag ) {
        active = true ;
        enable_flag = false ;
    }

    if ( disable_flag ) {
        active = false ;
        disable_flag = false ;
    }

    tics_per_sec =  exec_get_time_tic_value();

    /* Start the sleep timer hardware if realtime is active */
    start_sleep_timer();

    if ( align_sim_to_wall_clock ) {
        rt_clock->sync_to_wall_clock( align_tic_mult , tics_per_sec ) ;
        message_publish(MSG_INFO, "Syncing sim to %f second wall clock interval\n", align_tic_mult ) ;
        if ( exec_get_mode() == Freeze ) {
            rt_clock->clock_spin(exec_get_freeze_time_tics()) ;
        } else {
            rt_clock->clock_spin(exec_get_time_tics()) ;
        }
    }

    return(0) ;
}
Beispiel #2
0
//Instrumentation job to save job timeline stop time and frame time.
int Trick::FrameLog::frame_clock_stop(Trick::JobData * curr_job) {

    Trick::JobData * target_job = (Trick::JobData *)curr_job->sup_class_data ;
    int thread, mode;

    /** @par Detailed Design: */
    if ( target_job != NULL ) {
        if ( target_job->rt_start_time >= 0 ) {
            /** @li Set current job's stop time and frame time. */
            target_job->rt_stop_time = clock_time() ;
            target_job->frame_time += (target_job->rt_stop_time - target_job->rt_start_time);
            thread = target_job->thread;

            mode = exec_get_mode();
            /** @li Whatever inits run after & including start_realtime, make them be timelined as cyclic. */
            if (mode == Initialization) {
                if (! target_job->name.compare(rt_sim_object_name + std::string(".rt_sync.start_realtime")) ) {
                    log_init_end = true;
                    // fixup: set start_realtime function's start time to 0 because it will have reset the clock
                    target_job->rt_start_time = 0;
                }
                if (log_init_end) {
                    mode = Run;
                }
            }
            /** @li Save all cyclic job start & stop times for this frame into timeline structure. */
            if ((mode==Run) || (mode==Step)) {                            // cyclic job
                if (tl_count[thread] < tl_max_samples) {
                    timeline[thread][tl_count[thread]].id    = target_job->frame_id;
                    timeline[thread][tl_count[thread]].start = target_job->rt_start_time;
                    timeline[thread][tl_count[thread]].stop  = target_job->rt_stop_time;
                    timeline[thread][tl_count[thread]].trick_job = target_job->tags.count("TRK");
                    tl_count[thread]++;
                }
            /** @li Save all non-cyclic job start & stop times for this frame into timeline_other structure. */
            } else {                                                      // non-cyclic job
                if (tl_other_count[thread] < tl_max_samples) {
                    timeline_other[thread][tl_other_count[thread]].id    = target_job->frame_id;
                    timeline_other[thread][tl_other_count[thread]].start = target_job->rt_start_time;
                    timeline_other[thread][tl_other_count[thread]].stop  = target_job->rt_stop_time;
                    timeline_other[thread][tl_other_count[thread]].trick_job = target_job->tags.count("TRK");
                    tl_other_count[thread]++;
                }
            }
            // start timeline over
            target_job->rt_start_time = 0;
            target_job->rt_stop_time = 0;
        } else {
            target_job->frame_time = 0 ;
        }
    }

    return(0) ;

}
Beispiel #3
0
int Trick::Master::checkpoint() {
    /** @par Detailed Design: */
    /** @li If chkpnt_dump_auto, tell slave to dump a checkpoint */
    unsigned int ii ;
    // do not tell slave to dump if this is a pre_init, post_init, or end checkpoint
    // those are handled with flags sent to slave in init()
    if ((exec_get_mode() == Initialization) || (exec_get_mode() == ExitMode)) {
        return(0);
    }
    if (enabled) {
        // Use 2 loops to read all slave status before writing any status out.
        for ( ii = 0 ; ii < slaves.size() ; ii++ ) {
            slaves[ii]->read_slave_status() ;
        }
        SIM_COMMAND save_command = exec_get_exec_command() ;
        std::string full_path_name = checkpoint_get_output_file();
        for ( ii = 0 ; ii < slaves.size() ; ii++ ) {
            if (slaves[ii]->chkpnt_dump_auto) {
                if (slaves[ii]->chkpnt_binary) {
                    if (slaves[ii]->slave_type == "dmtcp") {
                        exec_set_exec_command((SIM_COMMAND)MS_ChkpntDumpBinCmd) ;
                        slaves[ii]->write_master_status() ;
                        slaves[ii]->write_master_chkpnt_name(full_path_name) ;
                        exec_set_exec_command(save_command) ;
                    } else {
                        message_publish(MSG_ERROR, "Slave is not running under dmtcp control so it cannot dump binary checkpoint.\n") ;
                        slaves[ii]->write_master_status() ;
                    }
                } else { // ascii
                    exec_set_exec_command((SIM_COMMAND)MS_ChkpntDumpAsciiCmd) ;
                    slaves[ii]->write_master_status() ;
                    slaves[ii]->write_master_chkpnt_name(full_path_name) ;
                    exec_set_exec_command(save_command) ;
                }
            } else { // no auto dump
                slaves[ii]->write_master_status() ;
            }
        }
    }
    return(0) ;
}
/**
@details
-# Get the sim_mode
-# Reset the real-time clock reference
-# If sim_mode is Run
   -# Call start_realtime to start the real time clock
-# Else if sim_mode is Freeze
   -# Call freeze init to set the sleep timer to freeze mode.
*/
int Trick::RealtimeSync::restart(long long ref_time) {

    SIM_MODE sim_mode = exec_get_mode() ;

    rt_clock->clock_reset(ref_time) ;
    if ( sim_mode == Run ) {
        start_realtime(exec_get_software_frame() , ref_time) ;
    } else if ( sim_mode == Freeze ) {
        freeze_init(exec_get_freeze_frame()) ;
    }

    return 0 ;
}