mirror of
https://github.com/nasa/trick.git
synced 2024-12-18 20:57:55 +00:00
9-13-24
This commit is contained in:
parent
92b0168b7b
commit
dd7a2c7917
@ -34,6 +34,8 @@ namespace Trick {
|
||||
|
||||
public:
|
||||
|
||||
int restart_count;
|
||||
|
||||
/** Enable real-time frame logging.\n */
|
||||
bool frame_log_flag ; /**< trick_io(*io) trick_units(--) */
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace Trick {
|
||||
* @brief This is the constructor of the class. It initializes
|
||||
* the most member data to 0, or TRICK_MAX_LONG_LONG for next_job_time
|
||||
*/
|
||||
ScheduledJobQueue() ;
|
||||
ScheduledJobQueue(std::string name = "NONE") ;
|
||||
|
||||
/**
|
||||
* @brief This is the destructor of the class. It frees list.
|
||||
@ -45,7 +45,7 @@ namespace Trick {
|
||||
* @param in_job - Job to add to the list
|
||||
* @return always 0.
|
||||
*/
|
||||
int push(JobData * in_job ) ;
|
||||
int pushy(JobData * in_job ) ;
|
||||
|
||||
/**
|
||||
* @brief Adds a new job into list ignoring the sim_object id. This is useful for
|
||||
@ -190,7 +190,9 @@ namespace Trick {
|
||||
*/
|
||||
int test_next_job_call_time(Trick::JobData * curr_job, long long time_tics) ;
|
||||
|
||||
private:
|
||||
std::string queue_name;
|
||||
|
||||
char frame_log_restart_char;
|
||||
|
||||
/** number of jobs in list */
|
||||
unsigned int list_size ;
|
||||
@ -201,6 +203,8 @@ namespace Trick {
|
||||
/** current index to top job in list */
|
||||
unsigned int curr_index ;
|
||||
|
||||
private:
|
||||
|
||||
/** next lowest job call time as tracked by calls to find_next_job(long long) */
|
||||
long long next_job_time ;
|
||||
} ;
|
||||
|
@ -22,7 +22,11 @@
|
||||
|
||||
Trick::CheckPointRestart * the_cpr ;
|
||||
|
||||
Trick::CheckPointRestart::CheckPointRestart() {
|
||||
Trick::CheckPointRestart::CheckPointRestart() :
|
||||
checkpoint_queue("checkpoint_queue"),
|
||||
post_checkpoint_queue("post_checkpoint_queue"),
|
||||
preload_checkpoint_queue("preload_checkpoint_queue"),
|
||||
restart_queue("restart_queue") {
|
||||
|
||||
int num_classes = 0 ;
|
||||
|
||||
@ -332,6 +336,8 @@ int Trick::CheckPointRestart::load_checkpoint_job() {
|
||||
// the restart queue will be rebuilt by the executive.
|
||||
restart_queue.reset_curr_index() ;
|
||||
while ( (curr_job = restart_queue.get_next_job()) != NULL ) {
|
||||
std::cout << "***** checkpoint restart job:" << curr_job->name << " ***** " << &restart_queue << std::endl;
|
||||
std::cout << "\t" << curr_job << ", " << restart_queue.curr_index << ", " << restart_queue.list_size << std::endl;
|
||||
curr_job->call() ;
|
||||
}
|
||||
} else {
|
||||
|
@ -159,35 +159,35 @@ int Trick::Executive::add_job_to_queue( Trick::JobData * job ) {
|
||||
if ( job->thread != 0 ) {
|
||||
/* Add threaded scheduled jobs to the thread scheduled queue */
|
||||
if ( job->job_class >= scheduled_start_index ) {
|
||||
threads[job->thread]->job_queue.push(job) ;
|
||||
threads[job->thread]->job_queue.pushy(job) ;
|
||||
// Add all scheduled jobs to the scheduled_queue for use in the multi-threaded loop
|
||||
scheduled_queue.push(job) ;
|
||||
scheduled_queue.pushy(job) ;
|
||||
return 0 ;
|
||||
/* Threaded top_of_frame/end_of_frame jobs go to thread specific queues. */
|
||||
} else if ( ! job->job_class_name.compare("top_of_frame")) {
|
||||
threads[job->thread]->top_of_frame_queue.push(job) ;
|
||||
threads[job->thread]->top_of_frame_queue.pushy(job) ;
|
||||
return 0 ;
|
||||
} else if ( ! job->job_class_name.compare("end_of_frame")) {
|
||||
threads[job->thread]->end_of_frame_queue.push(job) ;
|
||||
threads[job->thread]->end_of_frame_queue.pushy(job) ;
|
||||
return 0 ;
|
||||
/* Other jobs classes are put into the main thread */
|
||||
} else if ( (queue_it = class_to_queue.find(job->job_class)) != class_to_queue.end() ) {
|
||||
/* for non-scheduled jobs, the class_to_queue map holds the correct queue to insert the job */
|
||||
curr_queue = queue_it->second ;
|
||||
curr_queue->push( job ) ;
|
||||
curr_queue->pushy( job ) ;
|
||||
return 0 ;
|
||||
}
|
||||
} else {
|
||||
/* if the job is a "scheduled" type job, insert the job into the proper thread queue */
|
||||
if ( job->job_class >= scheduled_start_index ) {
|
||||
threads[0]->job_queue.push(job) ;
|
||||
threads[0]->job_queue.pushy(job) ;
|
||||
// Add all scheduled jobs to the scheduled_queue for use in the multi-threaded loop
|
||||
scheduled_queue.push(job) ;
|
||||
scheduled_queue.pushy(job) ;
|
||||
return 0 ;
|
||||
} else if ( (queue_it = class_to_queue.find(job->job_class)) != class_to_queue.end() ) {
|
||||
/* for non-scheduled jobs, the class_to_queue map holds the correct queue to insert the job */
|
||||
curr_queue = queue_it->second ;
|
||||
curr_queue->push( job ) ;
|
||||
curr_queue->pushy( job ) ;
|
||||
return 0 ;
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ int Trick::Executive::restart() {
|
||||
std::vector <Trick::SimObject *>::iterator sit ;
|
||||
std::vector <Trick::JobData *>::iterator jit ;
|
||||
std::multimap<std::string, Trick::JobData *> all_jobs_from_checkpointed_objects ;
|
||||
bool name_match = false;
|
||||
|
||||
/*
|
||||
Save the current job index position of the input processor queue. This queue position is special
|
||||
@ -53,8 +54,10 @@ int Trick::Executive::restart() {
|
||||
(*jit)->parent_object = (*sit) ;
|
||||
(*jit)->frame_id = (*jit)->sim_object_id + ((double)(*jit)->id / 100.0);
|
||||
std::string so_name_and_period = (*sit)->name + "." ;
|
||||
std::cout << "$$$$$ ExecRestart_A:" << (*jit)->name << std::endl;
|
||||
if ( strncmp( (*jit)->name.c_str() , so_name_and_period.c_str(), so_name_and_period.length())) {
|
||||
(*jit)->name = (*sit)->name + "." + (*jit)->name ;
|
||||
std::cout << "$$$$$ ExecRestart_B:" << (*jit)->name << std::endl;
|
||||
}
|
||||
all_jobs_from_checkpointed_objects.insert(std::pair<std::string, JobData *>((*jit)->name,(*jit))) ;
|
||||
}
|
||||
|
@ -548,6 +548,7 @@ clear_data_record_info.
|
||||
*/
|
||||
int Trick::FrameLog::restart() {
|
||||
// removing the data record groups removed the restart jobs too. call them here.
|
||||
//if(restart_count < 1) {
|
||||
std::vector< Trick::FrameDataRecordGroup *>::iterator it ;
|
||||
for ( it = drg_users.begin() ; it != drg_users.end() ; ++it ) {
|
||||
(*it)->restart() ;
|
||||
@ -565,6 +566,8 @@ int Trick::FrameLog::restart() {
|
||||
remove_instrument_jobs() ; // these will be added back when frame log turned on
|
||||
framelog_on() ;
|
||||
}
|
||||
//}
|
||||
restart_count++;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
|
@ -16,13 +16,16 @@
|
||||
-# Set #curr_index to 0
|
||||
-# Set #next_job_time to TRICK_MAX_LONG_LONG
|
||||
*/
|
||||
Trick::ScheduledJobQueue::ScheduledJobQueue( ) {
|
||||
Trick::ScheduledJobQueue::ScheduledJobQueue( std::string name ) {
|
||||
|
||||
list = NULL ;
|
||||
list_size = 0 ;
|
||||
curr_index = 0 ;
|
||||
next_job_time = TRICK_MAX_LONG_LONG ;
|
||||
|
||||
queue_name = name;
|
||||
frame_log_restart_char = '0';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,10 +75,20 @@ static bool compare_job_data(const Trick::JobData *a, const Trick::JobData *b) {
|
||||
-# Insert the new job at the insertion point.
|
||||
-# Increment the size of the queue.
|
||||
*/
|
||||
int Trick::ScheduledJobQueue::push( JobData * new_job ) {
|
||||
int Trick::ScheduledJobQueue::pushy( JobData * new_job ) {
|
||||
std::string job_name = new_job->name;
|
||||
bool name_match = (job_name == "trick_frame_log.frame_log.restart");
|
||||
if(name_match) {
|
||||
std::stringstream ss;
|
||||
ss << "trick_frame_log.frame_log.restart" << frame_log_restart_char;
|
||||
new_job->name = ss.str();
|
||||
std::cout << "ZZZZZZZZZZ pushed FLR Job " << frame_log_restart_char++ << " next job is " << frame_log_restart_char << std::endl;
|
||||
std::cout << "\t" << new_job << std::endl;
|
||||
}
|
||||
|
||||
/* Allocate additional memory for the additional job in the queue */
|
||||
JobData ** new_list = (JobData **)realloc(list, (list_size + 1) * sizeof(JobData *)) ;
|
||||
std::cout << "@@@@@_1 Pushing:" << job_name << ", " << new_job << ", " << new_job->id << ", " << new_job->sim_object_id << ", " << this << ", " << list_size << ", list_ptr:" << list << ", new_list_ptr:" << new_list << std::endl;
|
||||
if (!new_list) {
|
||||
abort();
|
||||
}
|
||||
@ -91,6 +104,7 @@ int Trick::ScheduledJobQueue::push( JobData * new_job ) {
|
||||
|
||||
/* Increment the size of the queue */
|
||||
list_size++ ;
|
||||
std::cout << "@@@@@_2 Pushed:" << job_name << ", " << new_job->id << ", " << new_job->sim_object_id << ", " << this << ", " << list_size << std::endl;
|
||||
|
||||
return(0) ;
|
||||
|
||||
@ -112,7 +126,8 @@ int Trick::ScheduledJobQueue::push_ignore_sim_object( JobData * new_job ) {
|
||||
save_sim_object_id = new_job->sim_object_id ;
|
||||
new_job->sim_object_id = 1000000 ;
|
||||
/* push the job onto the scheduling queue as normal */
|
||||
ret = push(new_job) ;
|
||||
std::cout << "..... ScheduledJobQueue::push_ignore_sim_object ....." << std::endl;
|
||||
ret = pushy(new_job) ;
|
||||
/* restore the original sim_object id */
|
||||
new_job->sim_object_id = save_sim_object_id ;
|
||||
return(ret) ;
|
||||
|
@ -0,0 +1,539 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "trick/ScheduledJobQueue.hh"
|
||||
#include "trick/ScheduledJobQueueInstrument.hh"
|
||||
#include "trick/TrickConstant.hh"
|
||||
|
||||
/**
|
||||
@design
|
||||
-# Set #list to NULL
|
||||
-# Set #list_list to 0
|
||||
-# Set #curr_index to 0
|
||||
-# Set #next_job_time to TRICK_MAX_LONG_LONG
|
||||
*/
|
||||
Trick::ScheduledJobQueue::ScheduledJobQueue( std::string name ) {
|
||||
|
||||
list = NULL ;
|
||||
list_size = 0 ;
|
||||
curr_index = 0 ;
|
||||
next_job_time = TRICK_MAX_LONG_LONG ;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@design
|
||||
-# free list if it is not empty
|
||||
*/
|
||||
Trick::ScheduledJobQueue::~ScheduledJobQueue( ) {
|
||||
if (list != NULL ) {
|
||||
free(list) ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@design
|
||||
-# Allocate additional memory for the incoming job
|
||||
-# Find the insertion point in the queue based on the job_class, the phase,
|
||||
the sim_object id, and the job_id
|
||||
-# While searching for the correct insertion spot, copy all jobs that precede
|
||||
the incoming job to the newly allocated queue space followed by the new job.
|
||||
-# Copy jobs that are ordered after the incoming job to the new queue
|
||||
-# Increment the size of the queue.
|
||||
*/
|
||||
int Trick::ScheduledJobQueue::pushy( JobData * new_job ) {
|
||||
std::string job_name = new_job->name;
|
||||
std::cout << "@@@@@ Pushing:" << job_name << std::endl;
|
||||
|
||||
unsigned int ii , jj ;
|
||||
|
||||
/* Allocate additional memory for the additional job in the queue */
|
||||
JobData ** new_list = (JobData **)calloc( list_size + 1 , sizeof(JobData *)) ;
|
||||
|
||||
new_job->set_handled(true) ;
|
||||
|
||||
/* Find the correct insertion spot in the queue by comparing
|
||||
the job_class, the phase, the sim_object id, and the job_id in that order. */
|
||||
/* While searching for the correct insertion spot, copy all jobs that precede
|
||||
the incoming job to the newly allocated queue space. */
|
||||
for ( ii = jj = 0 ; ii < list_size ; ii++ ) {
|
||||
if ( list[ii]->job_class == new_job->job_class ) {
|
||||
if ( list[ii]->phase == new_job->phase ) {
|
||||
if ( list[ii]->sim_object_id == new_job->sim_object_id ) {
|
||||
if ( list[ii]->id <= new_job->id ) {
|
||||
new_list[jj++] = list[ii] ;
|
||||
} else {
|
||||
new_list[jj++] = new_job ;
|
||||
break ;
|
||||
}
|
||||
} else if ( list[ii]->sim_object_id < new_job->sim_object_id ) {
|
||||
new_list[jj++] = list[ii] ;
|
||||
} else {
|
||||
new_list[jj++] = new_job ;
|
||||
break ;
|
||||
}
|
||||
} else if ( list[ii]->phase < new_job->phase ) {
|
||||
new_list[jj++] = list[ii] ;
|
||||
} else {
|
||||
new_list[jj++] = new_job ;
|
||||
break ;
|
||||
}
|
||||
} else if ( list[ii]->job_class < new_job->job_class ) {
|
||||
new_list[jj++] = list[ii] ;
|
||||
} else {
|
||||
new_list[jj++] = new_job ;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
|
||||
/* Copy remaining jobs that execute after the incoming job to the new queue space. */
|
||||
if ( ii == list_size ) {
|
||||
/* ii == list_size means the incoming job is the last job */
|
||||
new_list[list_size] = new_job ;
|
||||
} else {
|
||||
/* Inserted new job before the current job. Increment curr_index to point to the correct job */
|
||||
if ( ii < curr_index ) {
|
||||
curr_index++ ;
|
||||
}
|
||||
for ( ; ii < list_size ; ii++ ) {
|
||||
new_list[jj++] = list[ii] ;
|
||||
}
|
||||
}
|
||||
|
||||
/* Increment the size of the queue */
|
||||
list_size++ ;
|
||||
|
||||
/* Free the old queue space */
|
||||
if ( list ) {
|
||||
free(list) ;
|
||||
}
|
||||
|
||||
/* Assign the queue pointer to the new space */
|
||||
list = new_list ;
|
||||
|
||||
return(0) ;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@design
|
||||
-# Temporarily assign a high sim_object id to the incoming job. This
|
||||
effectively removes the sim_object_id as an ordering field
|
||||
-# Call Trick::ScheduledJobQueue::push( JobData * ) to add the job to the queue.
|
||||
-# Restore the original sim_object id.
|
||||
*/
|
||||
int Trick::ScheduledJobQueue::push_ignore_sim_object( JobData * new_job ) {
|
||||
|
||||
int save_sim_object_id ;
|
||||
int ret ;
|
||||
|
||||
/* Temorarily assign a really high sim_object id */
|
||||
save_sim_object_id = new_job->sim_object_id ;
|
||||
new_job->sim_object_id = 1000000 ;
|
||||
/* push the job onto the scheduling queue as normal */
|
||||
ret = pushy(new_job) ;
|
||||
/* restore the original sim_object id */
|
||||
new_job->sim_object_id = save_sim_object_id ;
|
||||
return(ret) ;
|
||||
}
|
||||
|
||||
/**
|
||||
@design
|
||||
-# Traverse the list of jobs looking for the job to delete.
|
||||
-# If the job to delete is found
|
||||
-# Allocate a new list that holds 1 less job than the current list
|
||||
-# Copy all of the jobs that precede the deleted job to the new list
|
||||
-# Copy all of the jobs that are after the delete job to the new list
|
||||
-# Decrement the size of the list
|
||||
-# Free the memory associated with the current list
|
||||
-# Point the current list to the newly allocated list
|
||||
*/
|
||||
int Trick::ScheduledJobQueue::remove( JobData * delete_job ) {
|
||||
|
||||
unsigned int ii , jj ;
|
||||
|
||||
/* Find the job to delete in the queue. */
|
||||
for ( ii = 0 ; ii < list_size ; ii++ ) {
|
||||
if ( list[ii] == delete_job ) {
|
||||
/* allocate a new list that holds one less element than the current list. */
|
||||
JobData ** new_list = (JobData **)calloc( list_size - 1 , sizeof(JobData *)) ;
|
||||
/* copy all of the jobs that are before the deleted job to the new list */
|
||||
for ( jj = 0 ; jj < ii ; jj++ ) {
|
||||
new_list[jj] = list[jj] ;
|
||||
}
|
||||
/* copy all of the jobs that are after the deleted job to the new list */
|
||||
for ( jj = ii + 1 ; jj < list_size ; jj++ ) {
|
||||
new_list[jj-1] = list[jj] ;
|
||||
}
|
||||
if ( ii <= curr_index ) {
|
||||
curr_index-- ;
|
||||
}
|
||||
/* Decrement the size of the queue */
|
||||
list_size-- ;
|
||||
/* Free the old queue space */
|
||||
free(list) ;
|
||||
/* Assign the queue pointer to the new space */
|
||||
list = new_list ;
|
||||
return 0 ;
|
||||
}
|
||||
}
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
/**
|
||||
@design
|
||||
-# Returns the #curr_index of the queue.
|
||||
*/
|
||||
unsigned int Trick::ScheduledJobQueue::get_curr_index() {
|
||||
return curr_index ;
|
||||
}
|
||||
|
||||
/**
|
||||
@design
|
||||
-# Sets #curr_index to the incoming value.
|
||||
*/
|
||||
int Trick::ScheduledJobQueue::set_curr_index(unsigned int value ) {
|
||||
|
||||
if ( value < list_size ) {
|
||||
curr_index = value ;
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
/**
|
||||
@design
|
||||
-# Sets #curr_index to 0.
|
||||
*/
|
||||
int Trick::ScheduledJobQueue::reset_curr_index() {
|
||||
|
||||
curr_index = 0 ;
|
||||
return(0) ;
|
||||
}
|
||||
|
||||
/**
|
||||
@design
|
||||
-# Returns #list_size
|
||||
*/
|
||||
unsigned int Trick::ScheduledJobQueue::size() {
|
||||
return(list_size) ;
|
||||
}
|
||||
|
||||
/**
|
||||
@design
|
||||
-# Returns !(#list_size)
|
||||
*/
|
||||
bool Trick::ScheduledJobQueue::empty() {
|
||||
return(!list_size) ;
|
||||
}
|
||||
|
||||
/**
|
||||
@design
|
||||
-# If #list is not NULL free it.
|
||||
-# Set #list to NULL
|
||||
-# Set #list_list to 0
|
||||
-# Set #curr_index to 0
|
||||
-# Set #next_job_time to TRICK_MAX_LONG_LONG
|
||||
*/
|
||||
int Trick::ScheduledJobQueue::clear() {
|
||||
|
||||
/* free job list if one exists */
|
||||
if (list != NULL ) {
|
||||
free(list) ;
|
||||
}
|
||||
/* set all list variables to initial cleared values */
|
||||
list = NULL ;
|
||||
list_size = 0 ;
|
||||
curr_index = 0 ;
|
||||
next_job_time = TRICK_MAX_LONG_LONG ;
|
||||
return(0) ;
|
||||
}
|
||||
|
||||
/**
|
||||
@design
|
||||
-# If the list is empty return NULL
|
||||
-# Else return the current job without incrementing the #curr_index index.
|
||||
*/
|
||||
Trick::JobData * Trick::ScheduledJobQueue::top() {
|
||||
/* return NULL if list is empty */
|
||||
if ( list_size == 0 ) {
|
||||
return(NULL) ;
|
||||
}
|
||||
/* else return current list item */
|
||||
return(list[curr_index]) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@design
|
||||
-# If the #curr_index is greater than or equal to the #list_size
|
||||
-# Set the #curr_index to the #list_size
|
||||
-# Return NULL
|
||||
-# Else while the list #curr_list is less than the list size
|
||||
-# Increment the #curr_index.
|
||||
-# Return the current job if the job is enabled.
|
||||
*/
|
||||
Trick::JobData * Trick::ScheduledJobQueue::get_next_job() {
|
||||
|
||||
JobData * curr_job ;
|
||||
|
||||
/* return NULL if we are at the end of the list */
|
||||
if ( curr_index >= list_size ) {
|
||||
curr_index = list_size ;
|
||||
return(NULL) ;
|
||||
} else {
|
||||
/* return the next enabled job, or NULL if we reach the end of the list */
|
||||
while (curr_index < list_size ) {
|
||||
curr_job = list[curr_index++] ;
|
||||
if ( !curr_job->disabled ) {
|
||||
return(curr_job) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(NULL) ;
|
||||
}
|
||||
|
||||
/**
|
||||
@design
|
||||
-# While the list #curr_list is less than the list size
|
||||
-# If the current queue job next call matches the incoming simulation time
|
||||
-# If the job class is not a system class job, calculate the next
|
||||
time it will be called by current time + job cycle.
|
||||
-# Set the next job call time to TRICK_MAX_LONG_LONG if the next job call time
|
||||
is greater than the stop time.
|
||||
-# If the job's next job call time is lower than the overall next job call time
|
||||
set the overall job call time to the current job's next job call time.
|
||||
-# Increment the #curr_index.
|
||||
-# Return the current job if the job is enabled.
|
||||
-# Else
|
||||
-# If the job's next job call time is lower than the overall next job call time
|
||||
set the overall job call time to the current job's next job call time.
|
||||
-# Increment the #curr_index.
|
||||
-# Return NULL when the end of the list is reached.
|
||||
*/
|
||||
Trick::JobData * Trick::ScheduledJobQueue::find_next_job(long long time_tics ) {
|
||||
|
||||
JobData * curr_job ;
|
||||
long long next_call ;
|
||||
|
||||
/* Search through the rest of the queue starting at curr_index looking for
|
||||
the next job with it's next execution time is equal to the current simulation time. */
|
||||
while (curr_index < list_size ) {
|
||||
|
||||
curr_job = list[curr_index] ;
|
||||
|
||||
if ( curr_job->next_tics == time_tics ) {
|
||||
|
||||
/* If the job does not reschedule itself (system_job_classes), calculate the next time it will be called. */
|
||||
if ( ! curr_job->system_job_class ) {
|
||||
// calculate the next job call time
|
||||
next_call = curr_job->next_tics + curr_job->cycle_tics ;
|
||||
/* If the next time does not exceed the stop time, set the next call time for the module */
|
||||
if (next_call > curr_job->stop_tics) {
|
||||
curr_job->next_tics = TRICK_MAX_LONG_LONG ;
|
||||
} else {
|
||||
curr_job->next_tics = next_call;
|
||||
}
|
||||
/* Track next lowest job call time after the current time for jobs that match the current time. */
|
||||
if ( curr_job->next_tics < next_job_time ) {
|
||||
next_job_time = curr_job->next_tics ;
|
||||
}
|
||||
}
|
||||
curr_index++ ;
|
||||
if ( !curr_job->disabled ) {
|
||||
return(curr_job) ;
|
||||
}
|
||||
} else {
|
||||
/* Track next lowest job call time after the current time for jobs that do not match the current time */
|
||||
if ( curr_job->next_tics > time_tics && curr_job->next_tics < next_job_time ) {
|
||||
next_job_time = curr_job->next_tics ;
|
||||
}
|
||||
curr_index++ ;
|
||||
}
|
||||
}
|
||||
return(NULL) ;
|
||||
}
|
||||
|
||||
/**
|
||||
@design
|
||||
-# While the list #curr_list is less than the list size
|
||||
-# If the current queue job next call matches the incoming simulation time
|
||||
-# Increment the #curr_index.
|
||||
-# Return the current job if the job is enabled.
|
||||
-# Increment the #curr_index.
|
||||
-# Return NULL when the end of the list is reached.
|
||||
*/
|
||||
Trick::JobData* Trick::ScheduledJobQueue::find_job(long long time_tics) {
|
||||
JobData * curr_job ;
|
||||
|
||||
/* Search through the rest of the queue starting at curr_index looking for */
|
||||
/* the next job with it's next execution time is equal to the current simulation time. */
|
||||
while (curr_index < list_size) {
|
||||
curr_job = list[curr_index] ;
|
||||
|
||||
if (curr_job->next_tics == time_tics ) {
|
||||
if (!curr_job->disabled) {
|
||||
curr_index++ ;
|
||||
return(curr_job) ;
|
||||
}
|
||||
}
|
||||
curr_index++ ;
|
||||
}
|
||||
return(NULL) ;
|
||||
}
|
||||
|
||||
/**
|
||||
@details
|
||||
-# Sets #next_job_time to the incoming time
|
||||
*/
|
||||
int Trick::ScheduledJobQueue::set_next_job_call_time(long long in_time) {
|
||||
next_job_time = in_time ;
|
||||
return(0) ;
|
||||
}
|
||||
|
||||
/**
|
||||
@details
|
||||
-# Return the next_job_call_time in counts of tics/second
|
||||
Requirement [@ref r_exec_time_0]
|
||||
*/
|
||||
long long Trick::ScheduledJobQueue::get_next_job_call_time() {
|
||||
unsigned int temp_index = curr_index ;
|
||||
while (temp_index < list_size ) {
|
||||
if ( list[temp_index]->next_tics < next_job_time ) {
|
||||
next_job_time = list[temp_index]->next_tics ;
|
||||
}
|
||||
temp_index++ ;
|
||||
}
|
||||
return(next_job_time) ;
|
||||
}
|
||||
|
||||
/**
|
||||
@details
|
||||
-# If the current job next call time is less than the overall next job call time, and is
|
||||
greater than the current simulation time, set the overall next job call time to be the
|
||||
job next call time.
|
||||
*/
|
||||
int Trick::ScheduledJobQueue::test_next_job_call_time(Trick::JobData * curr_job, long long time_tics) {
|
||||
if ( curr_job->next_tics > time_tics && curr_job->next_tics < next_job_time ) {
|
||||
next_job_time = curr_job->next_tics ;
|
||||
}
|
||||
return(0) ;
|
||||
}
|
||||
|
||||
// Executes the jobs in a queue. saves and restores Trick::Executive::curr_job
|
||||
int Trick::ScheduledJobQueue::execute_all_jobs() {
|
||||
Trick::JobData * curr_job ;
|
||||
int ret ;
|
||||
|
||||
reset_curr_index() ;
|
||||
while ( (curr_job = get_next_job()) != NULL ) {
|
||||
ret = curr_job->call() ;
|
||||
if ( ret != 0 ) {
|
||||
return ret ;
|
||||
}
|
||||
}
|
||||
/* return 0 if there are no errors. */
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
int Trick::ScheduledJobQueue::write_sched_queue( FILE * fp ) {
|
||||
|
||||
Trick::JobData * curr_job ;
|
||||
unsigned int save_index ;
|
||||
|
||||
save_index = get_curr_index() ;
|
||||
reset_curr_index() ;
|
||||
while ( (curr_job = get_next_job()) != NULL ) {
|
||||
if ( curr_job->job_class_name.compare("instrumentation") ) {
|
||||
/* for each non instrumentation job write the job information to the open file pointer "fp" */
|
||||
fprintf(fp, "%7d | %3d |%-25s| %-5d | %08.6f | %8.6g | %8g | %5.02f | %s\n",
|
||||
!curr_job->disabled, curr_job->thread, curr_job->job_class_name.c_str(), curr_job->phase,
|
||||
curr_job->start, curr_job->cycle, curr_job->stop, curr_job->frame_id,
|
||||
curr_job->name.c_str());
|
||||
}
|
||||
}
|
||||
set_curr_index(save_index) ;
|
||||
return(0) ;
|
||||
}
|
||||
|
||||
int Trick::ScheduledJobQueue::write_non_sched_queue( FILE * fp ) {
|
||||
|
||||
Trick::JobData * curr_job ;
|
||||
unsigned int save_index ;
|
||||
|
||||
save_index = get_curr_index() ;
|
||||
reset_curr_index() ;
|
||||
while ( (curr_job = get_next_job()) != NULL ) {
|
||||
if ( curr_job->job_class_name.compare("instrumentation") ) {
|
||||
/* for each non instrumentation job write the job information to the open file pointer "fp" */
|
||||
fprintf(fp, "%7d | %3d |%-25s| %-5d | | | | %5.02f | %s\n",
|
||||
!curr_job->disabled, curr_job->thread, curr_job->job_class_name.c_str(), curr_job->phase,
|
||||
curr_job->frame_id, curr_job->name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
set_curr_index(save_index) ;
|
||||
return(0) ;
|
||||
}
|
||||
|
||||
/**
|
||||
@details
|
||||
-# For all jobs in the queue
|
||||
-# Create a new ScheduledJobQueueInstrument instance
|
||||
-# Add the new instrumentation job to the "before" instrumentation job list
|
||||
-# Return 0
|
||||
*/
|
||||
int Trick::ScheduledJobQueue::instrument_before(Trick::JobData * instrumentation_job) {
|
||||
|
||||
unsigned int ii ;
|
||||
ScheduledJobQueueInstrument * new_job ;
|
||||
|
||||
for ( ii = 0 ; ii < list_size ; ii++ ) {
|
||||
new_job = new ScheduledJobQueueInstrument( instrumentation_job, list[ii] );
|
||||
list[ii]->add_inst_before(new_job) ;
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
/**
|
||||
@details
|
||||
-# For all jobs in the queue
|
||||
-# Create a new ScheduledJobQueueInstrument instance
|
||||
-# Add the new instrumentation job to the "after" instrumentation job list
|
||||
-# Return 0
|
||||
*/
|
||||
int Trick::ScheduledJobQueue::instrument_after(Trick::JobData * instrumentation_job) {
|
||||
|
||||
unsigned int ii ;
|
||||
ScheduledJobQueueInstrument * new_job ;
|
||||
|
||||
/* Count the number of non-instrumentation jobs in the current queue. */
|
||||
for ( ii = 0 ; ii < list_size ; ii++ ) {
|
||||
new_job = new ScheduledJobQueueInstrument( instrumentation_job, list[ii] );
|
||||
list[ii]->add_inst_after(new_job) ;
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
/**
|
||||
@details
|
||||
-# For all jobs in the queue
|
||||
-# Create a new ScheduledJobQueueInstrument instance
|
||||
-# Add the new instrumentation job to the list
|
||||
-# Return 0
|
||||
*/
|
||||
int Trick::ScheduledJobQueue::instrument_remove(std::string job_name) {
|
||||
|
||||
unsigned int ii ;
|
||||
|
||||
for ( ii = 0 ; ii < list_size ; ii++ ) {
|
||||
list[ii]->remove_inst(job_name) ;
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
#include "trick/Scheduler.hh"
|
||||
#include <iostream>
|
||||
|
||||
Trick::Scheduler::~Scheduler() {}
|
||||
|
||||
@ -7,6 +8,8 @@ Trick::Scheduler::~Scheduler() {}
|
||||
// if this scheduler handles that job type
|
||||
int Trick::Scheduler::add_sim_object( Trick::SimObject * in_object ) {
|
||||
|
||||
std::cout << "..... Scheduler::add_sim_object SIM OBJ: " << in_object->name << " ..... " << in_object << std::endl;
|
||||
|
||||
unsigned int jj ;
|
||||
std::map<std::string, int>::iterator class_id_it ;
|
||||
JobData * job ;
|
||||
@ -15,11 +18,13 @@ int Trick::Scheduler::add_sim_object( Trick::SimObject * in_object ) {
|
||||
|
||||
for ( jj = 0 ; jj < in_object->jobs.size() ; jj++ ) {
|
||||
job = in_object->jobs[jj] ;
|
||||
bool name_match = (job->name == "trick_data_record_group_frame_trickjobs.trick_data_record_group_frame_trickjobs.restart");
|
||||
if ( (class_id_it = class_map.find(job->job_class_name)) != class_map.end() ) {
|
||||
job->job_class = class_id_it->second ;
|
||||
if ( (queue_it = class_to_queue.find(job->job_class)) != class_to_queue.end() ) {
|
||||
curr_queue = queue_it->second ;
|
||||
curr_queue->push( job ) ;
|
||||
std::cout << "..... Scheduler::add_sim_object JOB PUSH: " << job->name << " ..... " << job->job_class_name << ", " << &job << std::endl;
|
||||
curr_queue->pushy( job ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "trick/JobData.hh"
|
||||
#include "trick/SimObject.hh"
|
||||
#include <iostream>
|
||||
|
||||
long long Trick::JobData::time_tic_value = 0 ;
|
||||
|
||||
@ -174,6 +175,8 @@ int Trick::JobData::call() {
|
||||
int ret ;
|
||||
unsigned int ii , size ;
|
||||
InstrumentBase * curr_job ;
|
||||
std::string parent_name = parent_object->name;
|
||||
bool name_match = (name == "trick_frame_log.frame_log.restart");
|
||||
|
||||
size = inst_before.size() ;
|
||||
for ( ii = 0 ; ii < size ; ii++ ) {
|
||||
@ -181,6 +184,7 @@ int Trick::JobData::call() {
|
||||
curr_job->call() ;
|
||||
}
|
||||
|
||||
std::cout << "!!!!! Parent:" << parent_name << " !!!!! Job:" << name << std::endl;
|
||||
ret = parent_object->call_function(this) ;
|
||||
|
||||
size = inst_after.size() ;
|
||||
@ -215,6 +219,9 @@ double Trick::JobData::call_double() {
|
||||
}
|
||||
|
||||
int Trick::JobData::copy_from_checkpoint( JobData * in_job ) {
|
||||
std::string job_name = in_job->name;
|
||||
bool name_match = job_name == "trick_frame_log.frame_log.restart";
|
||||
std::cout << "##### Checkpoint copy:" << job_name << " #####" << std::endl;
|
||||
|
||||
/** @par Detailed Design */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user