From 122033701bf11ac3f7b02b02c7c261b4b04263cc Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Tue, 30 Aug 2016 13:08:01 -0500 Subject: [PATCH] unintended performance issue with integ_loop at end of scheduled job classes #243 Previous commit did not update the job complete flags correctly. Brought the fix back from 17 to 15. --- .../Executive/include/Executive.hh | 6 ++++ .../src/Executive_isThreadReadyToRun.cpp | 36 +++++++++++++++++++ .../src/Executive_loop_multi_thread.cpp | 30 ++-------------- .../Executive/src/Executive_thread_sync.cpp | 23 ++++++------ 4 files changed, 55 insertions(+), 40 deletions(-) create mode 100644 trick_source/sim_services/Executive/src/Executive_isThreadReadyToRun.cpp diff --git a/trick_source/sim_services/Executive/include/Executive.hh b/trick_source/sim_services/Executive/include/Executive.hh index 634988c4..9af2a279 100644 --- a/trick_source/sim_services/Executive/include/Executive.hh +++ b/trick_source/sim_services/Executive/include/Executive.hh @@ -282,6 +282,12 @@ namespace Trick { */ void reset_job_call_times() ; + /** + Internal call to test if thread is ready to run + @return bool + */ + bool isThreadReadyToRun( Trick::Threads * curr_thread , long long time_tics) ; + public: Executive() ; diff --git a/trick_source/sim_services/Executive/src/Executive_isThreadReadyToRun.cpp b/trick_source/sim_services/Executive/src/Executive_isThreadReadyToRun.cpp new file mode 100644 index 00000000..82b14d57 --- /dev/null +++ b/trick_source/sim_services/Executive/src/Executive_isThreadReadyToRun.cpp @@ -0,0 +1,36 @@ + +#include "sim_services/Executive/include/Executive.hh" + +/* +-# Switch on the type of thread + -# Scheduled threads are always ready to run + -# AMF thredas are ready to run if their previous frame just finished + -# ASYNC threads are ready to run if their complete flag is set and either they have + no cycle time or their previous frame just finished. +*/ +bool Trick::Executive::isThreadReadyToRun( Trick::Threads * curr_thread , long long time_tics) { + bool ret = false ; + switch ( curr_thread->process_type ) { + case Trick::PROCESS_TYPE_SCHEDULED: + ret = true ; + break ; + case Trick::PROCESS_TYPE_AMF_CHILD: + if ( curr_thread->amf_next_tics == time_tics ) { + ret = true ; + } + break ; + case Trick::PROCESS_TYPE_ASYNC_CHILD: + if ( curr_thread->child_complete == true ) { + if (curr_thread->amf_cycle_tics == 0 ) { + ret = true ; + } else { + if ( curr_thread->amf_next_tics == time_tics ) { + ret = true ; + } + } + } + break ; + } + return ret ; +} + diff --git a/trick_source/sim_services/Executive/src/Executive_loop_multi_thread.cpp b/trick_source/sim_services/Executive/src/Executive_loop_multi_thread.cpp index 2d5f7e7a..c21c6d06 100644 --- a/trick_source/sim_services/Executive/src/Executive_loop_multi_thread.cpp +++ b/trick_source/sim_services/Executive/src/Executive_loop_multi_thread.cpp @@ -8,32 +8,6 @@ #include "sim_services/Executive/include/exec_proto.h" #include "sim_services/include/release.h" -static bool isThreadReadyToRun( Trick::Threads * curr_thread , long long time_tics) { - bool ret = false ; - switch ( curr_thread->process_type ) { - case Trick::PROCESS_TYPE_SCHEDULED: - ret = true ; - break ; - case Trick::PROCESS_TYPE_AMF_CHILD: - if ( curr_thread->amf_next_tics == time_tics ) { - ret = true ; - } - break ; - case Trick::PROCESS_TYPE_ASYNC_CHILD: - if ( curr_thread->child_complete == true ) { - if (curr_thread->amf_cycle_tics == 0 ) { - ret = true ; - } else { - if ( curr_thread->amf_next_tics == time_tics ) { - ret = true ; - } - } - } - break ; - } - return ret ; -} - /** @details -# Wait for all synchronous threads to finish initializing before entering infinite loop @@ -55,9 +29,9 @@ static bool isThreadReadyToRun( Trick::Threads * curr_thread , long long time_ti calling Trick::ScheduledJobQueue::test_next_job_call_time(Trick::JobData *, long long) -# If the exec_command equals ExitCmd -# Call Trick::Executive::exec_terminate_with_return(int, char *, int, char *) - -# If the elapsed time has reached the termination time + -# If the elapsed time has reached the termination time -# Call Trick::Executive::exec_terminate_with_return(int, char *, int, char *) - -# If the elapsed time equals the next software frame time + -# If the elapsed time equals the next software frame time -# Call the end_of_frame jobs. Requirement [@ref r_exec_periodic_2] -# Set the end of frame execution time to the current time + software_frame */ diff --git a/trick_source/sim_services/Executive/src/Executive_thread_sync.cpp b/trick_source/sim_services/Executive/src/Executive_thread_sync.cpp index 778320db..564b6297 100644 --- a/trick_source/sim_services/Executive/src/Executive_thread_sync.cpp +++ b/trick_source/sim_services/Executive/src/Executive_thread_sync.cpp @@ -32,10 +32,6 @@ int Trick::Executive::thread_sync() { RELEASE(); } } - curr_thread->job_queue.reset_curr_index(); - while ( (curr_job = curr_thread->job_queue.find_job(time_tics)) != NULL ) { - curr_job->complete = false; - } } else if ( curr_thread->process_type == PROCESS_TYPE_ASYNC_CHILD ) { if ( curr_thread->child_complete == true ) { @@ -45,18 +41,21 @@ int Trick::Executive::thread_sync() { curr_thread->amf_next_tics += curr_thread->amf_cycle_tics ; } } - curr_thread->job_queue.reset_curr_index(); - while ( (curr_job = curr_thread->job_queue.find_job(time_tics)) != NULL ) { - curr_job->complete = false; - } } } } - /* reset the job complete flags on thread 0 (master thread) */ - threads[0]->job_queue.reset_curr_index(); - while ( (curr_job = threads[0]->job_queue.find_job(time_tics)) != NULL ) { - curr_job->complete = false; + /* Go through all of the job queues and mark all jobs that are to run this time step to not complete. */ + for (ii = 0; ii < threads.size() ; ii++) { + Threads * curr_thread = threads[ii] ; + /* For all threads that are waiting to start the next cycle (child_complete == true) + reset job completion flags */ + if ( isThreadReadyToRun(curr_thread, time_tics) ) { + curr_thread->job_queue.reset_curr_index(); + while ( (curr_job = curr_thread->job_queue.find_job(time_tics)) != NULL ) { + curr_job->complete = false; + } + } } return(0) ;