Skip to content

Commit

Permalink
Add rt nap stats for sim shutdown that includes total number of rt na…
Browse files Browse the repository at this point in the history
…ps that are greater than 10% software frame, the longest rt nap, and the shortest rt nap.
  • Loading branch information
hchen99 committed Feb 20, 2024
1 parent bfb6419 commit 7e94be8
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 2 deletions.
19 changes: 19 additions & 0 deletions include/trick/Executive.hh
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ namespace Trick {
/** S_run_summary - Trick version.\n */
std::string current_version; /**< trick_units(--) */

/** rt_nap statistics - total number of rt_nap that is longer than 10% of the software frame.\n */
int rt_nap_count; /**< trick_units(--) */

/** rt_nap statistics - the longest rt_nap.\n */
double longest_rt_nap; /**< trick_units(s) */

/** rt_nap statistics - the shortest rt_nap.\n */
double shortest_rt_nap; /**< trick_units(s) */

/**
@userdesc Command to reset job cycle times after the time_tic_value has changed.
@return void
Expand Down Expand Up @@ -875,6 +884,16 @@ namespace Trick {
*/
int set_current_version(std::string version) ;

/**
@userdesc Set stats after each RELEASE() when rt_nap is true. The stats contains the counts of
RELEASE() if the time delta between before and after RELEASE() is greater than 10% of the
software frame time, the longest delta, and the shortest delta of before and after RELEASE().
@param clock_time_before_rt_nap - clock time before RELEASE() is called when rt_nap is true.
@param clock_time_after_rt_nap - clock time after RELEASE() is done when rt_nap is true.
@reutnr void
*/
void set_rt_nap_stats(long long clock_time_before_rt_nap, long long clock_time_after_rt_nap) ;

// END GET and SET FUNCTIONS

/**
Expand Down
5 changes: 5 additions & 0 deletions trick_source/sim_services/Clock/Clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "trick/Clock.hh"
#include "trick/exec_proto.h"
#include "trick/exec_proto.hh"
#include "trick/release.h"

Trick::Clock * the_clock = NULL ;
Expand Down Expand Up @@ -84,11 +85,15 @@ long long Trick::Clock::clock_time() {
*/
long long Trick::Clock::clock_spin(long long req_time) {
long long curr_time ;
long long time_before_rt_nap, time_after_rt_nap ;
curr_time = clock_time() ;
/* Perform spin loop to allow current time to catch up to requested time */
while (curr_time < req_time) {
if ( exec_get_rt_nap() == 1 ) {
time_before_rt_nap = wall_clock_time() ;
RELEASE();
time_after_rt_nap = wall_clock_time() ;
exec_get_exec_cpp()->set_rt_nap_stats(time_before_rt_nap, time_after_rt_nap) ;
}
curr_time = clock_time();
}
Expand Down
16 changes: 16 additions & 0 deletions trick_source/sim_services/Executive/Executive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,19 @@ int Trick::Executive::set_current_version(std::string version) {
int Trick::Executive::get_except_return() const {
return except_return;
}

void Trick::Executive::set_rt_nap_stats(long long clock_time_before_rt_nap, long long clock_time_after_rt_nap) {
double rt_nap_elapsed_time = (double)(clock_time_after_rt_nap - clock_time_before_rt_nap) / time_tic_value ;
if (rt_nap_elapsed_time / software_frame > 0.1) {
rt_nap_count++ ;
}
if (longest_rt_nap < rt_nap_elapsed_time) {
longest_rt_nap = rt_nap_elapsed_time ;
}

if (shortest_rt_nap == 0.0) {
shortest_rt_nap = rt_nap_elapsed_time ;
} else if (shortest_rt_nap > rt_nap_elapsed_time) {
shortest_rt_nap = rt_nap_elapsed_time ;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "trick/Executive.hh"
#include "trick/exec_proto.h"
#include "trick/release.h"
#include "trick/clock_proto.h"
#include "trick/Executive.hh"

/**
@details
Expand Down Expand Up @@ -40,13 +42,17 @@ int Trick::Executive::loop_multi_thread() {
unsigned int ii ;
Trick::ScheduledJobQueue * main_sched_queue ;
int ret = 0 ;
long long time_before_rt_nap, time_after_rt_nap;

/* Wait for all threads to finish initializing and set the child_complete flag. */
for (ii = 1; ii < threads.size() ; ii++) {
Threads * curr_thread = threads[ii] ;
while (curr_thread->child_complete == false ) {
if (rt_nap == true) {
RELEASE();
time_before_rt_nap = clock_wall_time() ;
RELEASE() ;
time_after_rt_nap = clock_wall_time() ;
set_rt_nap_stats(time_before_rt_nap, time_after_rt_nap) ;
}
}
}
Expand Down Expand Up @@ -146,7 +152,10 @@ int Trick::Executive::loop_multi_thread() {
depend_job = curr_job->depends[ii] ;
while (! depend_job->complete) {
if (rt_nap == true) {
time_before_rt_nap = clock_wall_time() ;
RELEASE();
time_after_rt_nap = clock_wall_time() ;
set_rt_nap_stats(time_before_rt_nap, time_after_rt_nap) ;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "trick/Executive.hh"
#include "trick/release.h"
#include "trick/clock_proto.h"

/**
@design
Expand All @@ -12,14 +13,17 @@
int Trick::Executive::scheduled_thread_sync() {

unsigned int ii ;

long long time_before_rt_nap, time_after_rt_nap ;
/* Wait for synchronous threads to finish before testing for adjusting time_tics */
for (ii = 1; ii < threads.size() ; ii++) {
Threads * curr_thread = threads[ii] ;
if ( curr_thread->enabled and curr_thread->process_type == PROCESS_TYPE_SCHEDULED) {
while (curr_thread->child_complete == false ) {
if (rt_nap == true) {
time_before_rt_nap = clock_wall_time() ;
RELEASE();
time_after_rt_nap = clock_wall_time() ;
set_rt_nap_stats(time_before_rt_nap, time_after_rt_nap) ;
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions trick_source/sim_services/Executive/Executive_shutdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ int Trick::Executive::shutdown() {
user_cpu_time, kernal_cpu_time, sim_to_cpu,
user_cpu_init, kernal_cpu_init, sim_mem) ;

if (rt_nap == true) {
message_publish(MSG_NORMAL , "\n\n"
" SIMULATION RT NAP STATS\n"
" RT NAP COUNTS: %17d\n"
" (RT NAP / SOFTWARE FRAME > 0.1)\n"
" LONGEST RT NAP: %12.15f\n"
" SHORTEST RT NAP: %12.15f\n",
rt_nap_count, longest_rt_nap, shortest_rt_nap) ;
}

/* Kill all threads. */
for (ii = 1; ii < threads.size() ; ii++) {
if ( threads[ii]->running ) {
Expand Down
5 changes: 5 additions & 0 deletions trick_source/sim_services/Executive/Executive_thread_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "trick/Executive.hh"
#include "trick/release.h"
#include "trick/clock_proto.h"

/**
@design
Expand All @@ -22,6 +23,7 @@
int Trick::Executive::thread_sync() {

unsigned int ii ;
long long time_before_rt_nap, time_after_rt_nap ;

/* Wait for async_must finish to complete at the current time_tics */
for (ii = 1; ii < threads.size() ; ii++) {
Expand All @@ -30,7 +32,10 @@ int Trick::Executive::thread_sync() {
(curr_thread->amf_next_tics == time_tics )) {
while (curr_thread->child_complete == false ) {
if (rt_nap == true) {
time_before_rt_nap = clock_wall_time() ;
RELEASE();
time_after_rt_nap = clock_wall_time() ;
set_rt_nap_stats(time_before_rt_nap, time_after_rt_nap) ;
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions trick_source/sim_services/Executive/Threads_child.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@

#include "trick/Threads.hh"
#include "trick/release.h"
#include "trick/Executive.hh"
#include "trick/ExecutiveException.hh"
#include "trick/exec_proto.h"
#include "trick/TrickConstant.hh"
#include "trick/message_proto.h"
#include "trick/clock_proto.h"


/**
Expand All @@ -41,6 +43,7 @@ static int call_next_job(Trick::JobData * curr_job, Trick::ScheduledJobQueue & j
Trick::JobData * depend_job ;
unsigned int ii ;
int ret = 0 ;
long long time_before_rt_nap, time_after_rt_nap ;

//cout << "time = " << curr_time_tics << " " << curr_job->name << " job next = "
// << curr_job->next_tics << " id = " << curr_job->id << endl ;
Expand All @@ -50,7 +53,10 @@ static int call_next_job(Trick::JobData * curr_job, Trick::ScheduledJobQueue & j
depend_job = curr_job->depends[ii] ;
while (! depend_job->complete) {
if (rt_nap == true) {
time_before_rt_nap = clock_wall_time() ;
RELEASE();
time_after_rt_nap = clock_wall_time() ;
the_exec->set_rt_nap_stats(time_before_rt_nap, time_after_rt_nap) ;
}
}
}
Expand Down

0 comments on commit 7e94be8

Please sign in to comment.