summaryrefslogtreecommitdiff
path: root/TAO/examples/RTScheduling/DT_Creator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/examples/RTScheduling/DT_Creator.cpp')
-rw-r--r--TAO/examples/RTScheduling/DT_Creator.cpp373
1 files changed, 180 insertions, 193 deletions
diff --git a/TAO/examples/RTScheduling/DT_Creator.cpp b/TAO/examples/RTScheduling/DT_Creator.cpp
index a0ae68a61ce..4a7db7dd4ab 100644
--- a/TAO/examples/RTScheduling/DT_Creator.cpp
+++ b/TAO/examples/RTScheduling/DT_Creator.cpp
@@ -2,14 +2,12 @@
#include "DT_Creator.h"
#include "Thread_Task.h"
+#include "tao/ORB_Core.h"
#include "Task_Stats.h"
+#include "ace/High_Res_Timer.h"
#include "DT_Creator.h"
-
-#include "tao/ORB_Core.h"
#include "tao/RTScheduling/Current.h"
-#include "ace/High_Res_Timer.h"
-
ACE_Atomic_Op<TAO_SYNCH_MUTEX, long> guid_counter;
int
@@ -23,7 +21,6 @@ DT_Creator::dt_task_init (ACE_Arg_Shifter& arg_shifter)
char *job_name = 0;
int dist = 0;
const ACE_TCHAR* current_arg = 0;
-
if (arg_shifter.cur_arg_strncasecmp ("-Importance") == 0)
{
arg_shifter.consume_arg ();
@@ -31,44 +28,38 @@ DT_Creator::dt_task_init (ACE_Arg_Shifter& arg_shifter)
importance = ACE_OS::atoi (current_arg);
arg_shifter.consume_arg ();
}
-
if ((current_arg = arg_shifter.get_the_parameter ("-Start_Time")))
{
start_time = ACE_OS::atoi (current_arg);
arg_shifter.consume_arg ();
}
-
if ((current_arg = arg_shifter.get_the_parameter ("-Iter")))
{
iter = ACE_OS::atoi (current_arg);
arg_shifter.consume_arg ();
}
-
if ((current_arg = arg_shifter.get_the_parameter ("-Load")))
{
load = ACE_OS::atoi (current_arg);
arg_shifter.consume_arg ();
}
-
if ((current_arg = arg_shifter.get_the_parameter ("-JobName")))
{
job_name = (char *)current_arg;
dist = 1;
arg_shifter.consume_arg ();
}
-
dt_list_ [dt_index++] = this->create_thr_task (importance,
- start_time,
- load,
- iter,
- dist,
- job_name);
-
+ start_time,
+ load,
+ iter,
+ dist,
+ job_name);
return 0;
+
}
int log_index = 0;
-
int
DT_Creator::init (int argc, char *argv [])
{
@@ -90,18 +81,18 @@ DT_Creator::init (int argc, char *argv [])
int job_count = 0;
while (arg_shifter.is_anything_left ())
{
- if ((current_arg = arg_shifter.get_the_parameter ("-GuidSeed")))
+ if ((current_arg = arg_shifter.get_the_parameter ("-GuidSeed")))
{
- guid_counter = (long) ACE_OS::atoi (current_arg);
- arg_shifter.consume_arg ();
- }
- else if ((current_arg = arg_shifter.get_the_parameter ("-DT_Count")))
- {
- dt_count_ = ACE_OS::atoi (current_arg);
+ guid_counter = (long) ACE_OS::atoi (current_arg);
+ arg_shifter.consume_arg ();
+ }
+ else if ((current_arg = arg_shifter.get_the_parameter ("-DT_Count")))
+ {
+ dt_count_ = ACE_OS::atoi (current_arg);
ACE_NEW_RETURN (dt_list_, Thread_Task*[dt_count_], -1);
- active_dt_count_ = dt_count_;
+ active_dt_count_ = dt_count_;
arg_shifter.consume_arg ();
- }
+ }
else if ((current_arg = arg_shifter.get_the_parameter ("-POA_Count")))
{
poa_count_ = ACE_OS::atoi (current_arg);
@@ -111,17 +102,17 @@ DT_Creator::init (int argc, char *argv [])
else if ((current_arg = arg_shifter.get_the_parameter ("-JOB_Count")))
{
job_count_ = ACE_OS::atoi (current_arg);
- active_job_count_ = job_count_;
- ACE_NEW_RETURN (job_list_, Job_i*[job_count_], -1);
+ active_job_count_ = job_count_;
+ ACE_NEW_RETURN (job_list_, Job_i*[job_count_], -1);
arg_shifter.consume_arg ();
}
else if (arg_shifter.cur_arg_strncasecmp ("-DT_Task") == 0)
- {
+ {
arg_shifter.consume_arg ();
- dt_task_init (arg_shifter);
- }
+ dt_task_init (arg_shifter);
+ }
else if (arg_shifter.cur_arg_strncasecmp ("-POA") == 0)
- {
+ {
arg_shifter.consume_arg ();
ACE_NEW_RETURN (this->poa_list_[poa_count], POA_Holder (), -1);
@@ -131,37 +122,33 @@ DT_Creator::init (int argc, char *argv [])
delete this->poa_list_[poa_count];
return -1;
}
- else
- {
- poa_count++;
- }
- }
+ else
+ poa_count++;
+ }
else if (arg_shifter.cur_arg_strncasecmp ("-Job") == 0)
- {
+ {
arg_shifter.consume_arg ();
ACE_NEW_RETURN (this->job_list_[job_count], Job_i (this), -1);
if (this->job_list_[job_count]->init (arg_shifter) == -1)
- {
- delete this->job_list_[job_count];
- return -1;
- }
- else
- {
- job_count++;
- }
- }
+ {
+ delete this->job_list_[job_count];
+ return -1;
+ }
+ else
+ job_count++;
+ }
else if ((current_arg = arg_shifter.get_the_parameter ("-OutFile")))
- {
- file_name_ = CORBA::string_dup (current_arg);
- arg_shifter.consume_arg ();
- }
+ {
+ file_name_ = CORBA::string_dup (current_arg);
+ arg_shifter.consume_arg ();
+ }
else if ((current_arg = arg_shifter.get_the_parameter ("-LogFile")))
- {
- log_file_name_ = CORBA::string_dup (current_arg);
- arg_shifter.consume_arg ();
- }
+ {
+ log_file_name_ = CORBA::string_dup (current_arg);
+ arg_shifter.consume_arg ();
+ }
else
{
arg_shifter.ignore_arg ();
@@ -186,7 +173,7 @@ DT_Creator::register_synch_obj (ACE_ENV_SINGLE_ARG_DECL)
CORBA::string_dup ("Synch");
synch_context = this->naming_->bind_new_context (name
- ACE_ENV_ARG_PARAMETER);
+ ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
//
@@ -208,7 +195,7 @@ DT_Creator::register_synch_obj (ACE_ENV_SINGLE_ARG_DECL)
CORBA::Object_var object =
this->naming_->resolve (name
- ACE_ENV_ARG_PARAMETER);
+ ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
synch_context = CosNaming::NamingContext::_narrow (object.in ());
@@ -227,19 +214,19 @@ DT_Creator::register_synch_obj (ACE_ENV_SINGLE_ARG_DECL)
CORBA::string_dup (synch_name.c_str ());
ACE_DEBUG ((LM_DEBUG,
- "Synch Name %s\n",
- synch_name.c_str ()));
-
+ "Synch Name %s\n",
+ synch_name.c_str ()));
+
ACE_NEW (synch_,
- Synch_i);
-
+ Synch_i);
+
Synch_var synch = synch_->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
// Register the synch object with the Synch context.
synch_context->rebind (name,
- synch.in ()
- ACE_ENV_ARG_PARAMETER);
+ synch.in ()
+ ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
}
@@ -250,12 +237,12 @@ DT_Creator::activate_root_poa (ACE_ENV_SINGLE_ARG_DECL)
{
CORBA::Object_var object =
orb_->resolve_initial_references ("RootPOA"
- ACE_ENV_ARG_PARAMETER);
+ ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
root_poa_ =
PortableServer::POA::_narrow (object.in ()
- ACE_ENV_ARG_PARAMETER);
+ ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
PortableServer::POAManager_var poa_manager =
@@ -273,25 +260,25 @@ DT_Creator::activate_poa_list (ACE_ENV_SINGLE_ARG_DECL)
{
if (TAO_debug_level > 0)
ACE_DEBUG ((LM_DEBUG,
- "DT_Creator::activate_poa_list\n"));
+ "DT_Creator::activate_poa_list\n"));
if (poa_count_ > 0)
{
CORBA::Object_var object =
- orb_->resolve_initial_references ("RTORB"
- ACE_ENV_ARG_PARAMETER);
+ orb_->resolve_initial_references ("RTORB"
+ ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
this->rt_orb_ =
- RTCORBA::RTORB::_narrow (object.in ()
- ACE_ENV_ARG_PARAMETER);
+ RTCORBA::RTORB::_narrow (object.in ()
+ ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
}
-
+
for (int i = 0; i < poa_count_; ++i)
{
poa_list_[i]->activate (this->rt_orb_.in(), this->root_poa_.in ()
- ACE_ENV_ARG_PARAMETER);
+ ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
}
}
@@ -302,7 +289,7 @@ DT_Creator::activate_job_list (ACE_ENV_SINGLE_ARG_DECL)
if (TAO_debug_level > 0)
ACE_DEBUG ((LM_DEBUG,
- "DT_Creator::activate_job_list\n"));
+ "DT_Creator::activate_job_list\n"));
Job_i* job;
@@ -362,8 +349,8 @@ DT_Creator::activate_schedule (ACE_ENV_SINGLE_ARG_DECL)
{
if (TAO_debug_level > 0)
ACE_DEBUG ((LM_DEBUG,
- "Activating schedule, task count = %d\n",
- dt_count_));
+ "Activating schedule, task count = %d\n",
+ dt_count_));
Thread_Task* task;
@@ -372,60 +359,60 @@ DT_Creator::activate_schedule (ACE_ENV_SINGLE_ARG_DECL)
task = dt_list_[i];
if (task->dist ())
- {
- // resolve the object from the naming service
- CosNaming::Name name (1);
- name.length (1);
- name[0].id = CORBA::string_dup (task->job ());
-
- CORBA::Object_var obj =
- this->naming_->resolve (name ACE_ENV_ARG_PARAMETER);
- ACE_CHECK;
-
- Job_var job = Job::_narrow (obj.in () ACE_ENV_ARG_PARAMETER);
- ACE_CHECK;
-
- // if (TAO_debug_level > 0)
- // {
- // Check that the object is configured with some
- // PriorityModelPolicy.
- CORBA::Policy_var policy =
- job->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE
- ACE_ENV_ARG_PARAMETER);
- ACE_CHECK;
-
- RTCORBA::PriorityModelPolicy_var priority_policy =
- RTCORBA::PriorityModelPolicy::_narrow (policy.in ()
- ACE_ENV_ARG_PARAMETER);
- ACE_CHECK;
-
- if (CORBA::is_nil (priority_policy.in ()))
- ACE_DEBUG ((LM_DEBUG,
- "ERROR: Priority Model Policy not exposed!\n"));
- else
- {
+ {
+ // resolve the object from the naming service
+ CosNaming::Name name (1);
+ name.length (1);
+ name[0].id = CORBA::string_dup (task->job ());
+
+ CORBA::Object_var obj =
+ this->naming_->resolve (name ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK;
+
+ Job_var job = Job::_narrow (obj.in () ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK;
+
+ // if (TAO_debug_level > 0)
+ // {
+ // Check that the object is configured with some
+ // PriorityModelPolicy.
+ CORBA::Policy_var policy =
+ job->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE
+ ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK;
+
+ RTCORBA::PriorityModelPolicy_var priority_policy =
+ RTCORBA::PriorityModelPolicy::_narrow (policy.in ()
+ ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK;
+
+ if (CORBA::is_nil (priority_policy.in ()))
+ ACE_DEBUG ((LM_DEBUG,
+ "ERROR: Priority Model Policy not exposed!\n"));
+ else
+ {
/*
- RTCORBA::PriorityModel priority_model =
- priority_policy->priority_model (ACE_ENV_SINGLE_ARG_PARAMETER);
- ACE_CHECK;
-
- if (priority_model == RTCORBA::CLIENT_PROPAGATED)
- ACE_DEBUG ((LM_DEBUG,
- "%s priority_model = RTCORBA::CLIENT_PROPAGATED\n", task->job ()));
- else
- ACE_DEBUG ((LM_DEBUG,
- "%s priority_model = RTCORBA::SERVER_DECLARED\n", task->job ()));
- */
- }
- //} /* if (TAO_debug_level > 0) */
-
- task->job (job.in ());
- }
+ RTCORBA::PriorityModel priority_model =
+ priority_policy->priority_model (ACE_ENV_SINGLE_ARG_PARAMETER);
+ ACE_CHECK;
+
+ if (priority_model == RTCORBA::CLIENT_PROPAGATED)
+ ACE_DEBUG ((LM_DEBUG,
+ "%s priority_model = RTCORBA::CLIENT_PROPAGATED\n", task->job ()));
+ else
+ ACE_DEBUG ((LM_DEBUG,
+ "%s priority_model = RTCORBA::SERVER_DECLARED\n", task->job ()));
+ */
+ }
+ //} /* if (TAO_debug_level > 0) */
+
+ task->job (job.in ());
+ }
}
if (TAO_debug_level > 0 && dt_count_ > 0)
ACE_DEBUG ((LM_DEBUG,
- "Activated schedule, task count = %d\n",
- dt_count_));
+ "Activated schedule, task count = %d\n",
+ dt_count_));
}
@@ -455,7 +442,7 @@ DT_Creator::resolve_naming_service (ACE_ENV_SINGLE_ARG_DECL)
void
DT_Creator::create_distributable_threads (RTScheduling::Current_ptr current
- ACE_ENV_ARG_DECL)
+ ACE_ENV_ARG_DECL)
{
current_ = RTScheduling::Current::_duplicate (current);
@@ -467,24 +454,24 @@ DT_Creator::create_distributable_threads (RTScheduling::Current_ptr current
ACE_DEBUG ((LM_DEBUG,
"Waiting to Synch\n"));
-
+
while (!this->synch ()->synched ())
{
this->orb_->perform_work (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
}
-
+
CORBA::Policy_var sched_param;
sched_param = CORBA::Policy::_duplicate (this->sched_param (100));
const char * name = 0;
current_->begin_scheduling_segment (name,
- sched_param.in (),
- sched_param.in ()
- ACE_ENV_ARG_PARAMETER);
+ sched_param.in (),
+ sched_param.in ()
+ ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
ACE_NEW (base_time_,
- ACE_Time_Value (*(this->synch ()->base_time ())));
+ ACE_Time_Value (*(this->synch ()->base_time ())));
for (int i = 0; i < this->dt_count_; i++)
{
@@ -494,9 +481,9 @@ DT_Creator::create_distributable_threads (RTScheduling::Current_ptr current
char buf [BUFSIZ];
ACE_OS::sprintf (buf, "elapsed time = %d\n now = %d\n base_time_ = %d\n",
- (int) elapsed_time.sec (),
- (int) now.sec (),
- (int) base_time_->sec());
+ (int) elapsed_time.sec (),
+ (int) now.sec (),
+ (int) base_time_->sec());
log [log_index++] = ACE_OS::strdup (buf) ;
@@ -504,21 +491,21 @@ DT_Creator::create_distributable_threads (RTScheduling::Current_ptr current
ACE_Thread::self (curr_thr);
if (dt_list_ [i]->start_time () != 0 && (elapsed_time.sec () < dt_list_[i]->start_time ()))
- {
- int suspension_time = dt_list_[i]->start_time () - elapsed_time.sec ();
- ACE_OS::sprintf (buf,"suspension_tome = %d\n",
- suspension_time);
- log [log_index++] = ACE_OS::strdup (buf);
- yield (suspension_time,
- dt_list_[i]);
- }
+ {
+ int suspension_time = dt_list_[i]->start_time () - elapsed_time.sec ();
+ ACE_OS::sprintf (buf,"suspension_tome = %d\n",
+ suspension_time);
+ log [log_index++] = ACE_OS::strdup (buf);
+ yield (suspension_time,
+ dt_list_[i]);
+ }
sched_param = CORBA::Policy::_duplicate (this->sched_param (dt_list_ [i]->importance ()));
dt_list_ [i]->activate_task (current,
- sched_param.in (),
- flags,
- base_time_
- ACE_ENV_ARG_PARAMETER);
+ sched_param.in (),
+ flags,
+ base_time_
+ ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
}
@@ -526,7 +513,7 @@ DT_Creator::create_distributable_threads (RTScheduling::Current_ptr current
this->wait ();
current_->end_scheduling_segment (name
- ACE_ENV_ARG_PARAMETER);
+ ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
this->check_ifexit ();
@@ -566,9 +553,9 @@ DT_Creator::check_ifexit (void)
{
if (TAO_debug_level > 0)
ACE_DEBUG ((LM_DEBUG,
- "Checking exit status Job# = %d DT# = %d\n",
- active_job_count_,
- active_dt_count_));
+ "Checking exit status Job# = %d DT# = %d\n",
+ active_job_count_,
+ active_dt_count_));
static int shutdown = 0;
@@ -577,47 +564,47 @@ DT_Creator::check_ifexit (void)
if (!shutdown)
{
- // All tasks have finished and all jobs have been shutdown.
- if (active_dt_count_ == 0 && active_job_count_ == 0)
- {
-
- ACE_DEBUG ((LM_DEBUG, "Shutdown in progress ...\n"));
-
- /*
- for (int i = 0; i < dt_count_; i++)
- {
- dt_list_[i]->dump_stats ();
- }
-
- for (int i = 0; i < job_count_; i ++)
- {
- job_list_[i]->dump_stats ();
- }
- */
- TASK_STATS::instance ()->dump_samples (file_name_,
- "#Schedule Output",
- ACE_High_Res_Timer::global_scale_factor ());
-
- shutdown = 1;
-
- FILE* log_file = ACE_OS::fopen (log_file_name_, "w");
-
- if (log_file != NULL)
- {
- // first dump what the caller has to say.
- ACE_OS::fprintf (log_file, "Log File\n");
-
- for (int i = 0; i < log_index; i++)
- {
- ACE_OS::fprintf (log_file, "%s\n", log [i]);
- }
-
- ACE_OS::fclose (log_file);
- }
- ACE_DEBUG ((LM_DEBUG,
- "Log File Ready\n"));
-
- }
+ // All tasks have finished and all jobs have been shutdown.
+ if (active_dt_count_ == 0 && active_job_count_ == 0)
+ {
+
+ ACE_DEBUG ((LM_DEBUG, "Shutdown in progress ...\n"));
+
+ /*
+ for (int i = 0; i < dt_count_; i++)
+ {
+ dt_list_[i]->dump_stats ();
+ }
+
+ for (int i = 0; i < job_count_; i ++)
+ {
+ job_list_[i]->dump_stats ();
+ }
+ */
+ TASK_STATS::instance ()->dump_samples (file_name_,
+ "#Schedule Output",
+ ACE_High_Res_Timer::global_scale_factor ());
+
+ shutdown = 1;
+
+ FILE* log_file = ACE_OS::fopen (log_file_name_, "w");
+
+ if (log_file != NULL)
+ {
+ // first dump what the caller has to say.
+ ACE_OS::fprintf (log_file, "Log File\n");
+
+ for (int i = 0; i < log_index; i++)
+ {
+ ACE_OS::fprintf (log_file, "%s\n", log [i]);
+ }
+
+ ACE_OS::fclose (log_file);
+ }
+ ACE_DEBUG ((LM_DEBUG,
+ "Log File Ready\n"));
+
+ }
}
}
}