diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:21 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:21 +0000 |
commit | 3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c (patch) | |
tree | 197c810e5f5bce17b1233a7cb8d7b50c0bcd25e2 /TAO/examples/RTCORBA | |
parent | 6b846cf03c0bcbd8c276cb0af61a181e5f98eaae (diff) | |
download | ATCD-3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c.tar.gz |
Repo restructuring
Diffstat (limited to 'TAO/examples/RTCORBA')
27 files changed, 2386 insertions, 0 deletions
diff --git a/TAO/examples/RTCORBA/Activity/Activity.cpp b/TAO/examples/RTCORBA/Activity/Activity.cpp new file mode 100644 index 00000000000..4207926db61 --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Activity.cpp @@ -0,0 +1,461 @@ +//$Id$ +#include "Activity.h" +#include "Thread_Task.h" +#include "Job_i.h" +#include "POA_Holder.h" +#include "Builder.h" + +#include "tao/ORB_Core.h" +#include "tao/debug.h" + +#include "ace/High_Res_Timer.h" +#include "ace/Barrier.h" +#include "ace/Timer_Heap.h" +#include "ace/Service_Config.h" +#include "ace/Arg_Shifter.h" +#include "ace/Get_Opt.h" +#include "ace/Argv_Type_Converter.h" +#include "ace/Signal.h" +#include "ace/Reactor.h" + + +//***************************************************************// +extern "C" void handler (int) +{ + ACE_Service_Config::reconfig_occurred (1); +} + +//***************************************************************// + +Activity::Activity (void) + :builder_ (0), + barrier_ (0), + active_task_count_ (0), + active_job_count_ (0) +{ + state_lock_ = new ACE_Lock_Adapter <TAO_SYNCH_MUTEX>; +} + +Activity::~Activity (void) +{ + delete state_lock_; + delete barrier_; +} + +void +Activity::builder (Builder* builder) +{ + builder_ = builder; +} + +CORBA::ORB_ptr +Activity::orb (void) +{ + return orb_.in (); +} + +RTCORBA::Current_ptr +Activity::current (void) +{ + return current_.in (); +} + +int +Activity::init (int& argc, char *argv [] + ACE_ENV_ARG_DECL) +{ + // Copy command line parameter. + ACE_Argv_Type_Converter command_line(argc, argv); + + this->orb_ = CORBA::ORB_init (command_line.get_argc(), + command_line.get_ASCII_argv(), + "" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + CORBA::Object_var object = + orb_->resolve_initial_references ("RootPOA" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + root_poa_ = + PortableServer::POA::_narrow (object.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + PortableServer::POAManager_var poa_manager = + root_poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + object = + orb_->resolve_initial_references ("RTORB" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + this->rt_orb_ = + RTCORBA::RTORB::_narrow (object.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + object = + orb_->resolve_initial_references ("RTCurrent" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + current_ = + RTCORBA::Current::_narrow (object.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + object = this->orb_->resolve_initial_references ("PriorityMappingManager" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + RTCORBA::PriorityMappingManager_var mapping_manager = + RTCORBA::PriorityMappingManager::_narrow (object.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + this->priority_mapping_ = mapping_manager->mapping (); + + return 0; +} + +int +Activity::resolve_naming_service (ACE_ENV_SINGLE_ARG_DECL) +{ + CORBA::Object_var naming_obj = + this->orb_->resolve_initial_references ("NameService" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Need to check return value for errors. + if (CORBA::is_nil (naming_obj.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Unable to resolve the Naming Service.\n"), + -1); + + this->naming_ = + CosNaming::NamingContextExt::_narrow (naming_obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + //@@tmp hack, otherwise crashes on exit!..?? + CosNaming::NamingContextExt::_duplicate (this->naming_.in()); + return 0; +} + +void +Activity::activate_poa_list (ACE_ENV_SINGLE_ARG_DECL) +{ + POA_LIST list; + int count = builder_->poa_list (list); + + for (int i = 0; i < count; ++i) + { + list[i]->activate (this->rt_orb_.in(), this->root_poa_.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + } +} + +void +Activity::activate_job_list (ACE_ENV_SINGLE_ARG_DECL) +{ + JOB_LIST list; + int count = builder_->job_list (list); + Job_i* job; + + for (int i = 0; i < count; ++i) + { + job = list[i]; + + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, "Activating job:%s\n", job->name ().c_str ())); + + // find your poa + PortableServer::POA_var host_poa = + root_poa_->find_POA (job->poa ().c_str (), 0 + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + PortableServer::ServantBase_var servant_var (job); + + // Register with poa. + PortableServer::ObjectId_var id; + + id = host_poa->activate_object (job + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + CORBA::Object_var server = + host_poa->id_to_reference (id.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + CORBA::String_var ior = + orb_->object_to_string (server.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + const ACE_CString &job_name = job->name (); + + CosNaming::Name_var name = + this->naming_->to_name (job_name.c_str () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + this->naming_->rebind (name.in (), + server.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + ACE_DEBUG ((LM_DEBUG, + "Registered %s with the naming service\n", + job_name.c_str ())); + + active_job_count_++; + + } /* while */ +} + +void +Activity::activate_schedule (ACE_ENV_SINGLE_ARG_DECL) +{ + TASK_LIST list; + int count = builder_->task_list (list); + + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, "Activating schedule, task count = %d\n", + count)); + + ACE_NEW (barrier_, ACE_Barrier (count+1)); + + Periodic_Task* task; + + for (int i = 0; i < count; ++i) + { + task = list[i]; + + // 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 ()); + task->activate_task (this->barrier_, this->priority_mapping_); + active_task_count_++; + + ACE_DEBUG ((LM_DEBUG, "Job %s scheduled\n", task->job ())); + } + + ACE_DEBUG ((LM_DEBUG, "(%P,%t) Waiting for tasks to synch...\n")); + barrier_->wait (); + ACE_DEBUG ((LM_DEBUG, "(%P,%t) Tasks have synched...\n")); +} + +void +Activity::task_ended (Periodic_Task* /*ended_task*/) +{ + ACE_DEBUG ((LM_DEBUG, "Active task count = %d\n",active_task_count_)); + { + ACE_GUARD (ACE_Lock, ace_mon, *state_lock_); + --active_task_count_; + } + + this->check_ifexit (); +} + +void +Activity::job_ended (Job_i* /*ended_job*/) +{ + ACE_DEBUG ((LM_DEBUG, "Active job count = %d\n",active_job_count_)); + { + ACE_GUARD (ACE_Lock, ace_mon, *state_lock_); + --active_job_count_; + } + + this->check_ifexit (); +} + +void +Activity::check_ifexit (void) +{ + // All tasks have finished and all jobs have been shutdown. + if (active_task_count_ == 0 && active_job_count_ == 0) + { + ACE_DEBUG ((LM_DEBUG, "Shutdown in progress ...\n")); + // ask all tasks to dump stats. + + TASK_LIST task_list; + int count = builder_->task_list (task_list); + + char msg[BUFSIZ]; + ACE_OS::sprintf (msg, "# Stats generated on --\n"); + + for (int i = 0; i < count; ++i) + { + task_list[i]->dump_stats (msg); + } + + // shutdown the ORB + orb_->shutdown (0); + } +} + +CORBA::Short +Activity::get_server_priority (CORBA::Object_ptr server + ACE_ENV_ARG_DECL) +{ + // Get the Priority Model Policy from the stub. + CORBA::Policy_var policy = + server->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Narrow down to correct type. + RTCORBA::PriorityModelPolicy_var priority_policy = + RTCORBA::PriorityModelPolicy::_narrow (policy.in () ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Make sure that we have the SERVER_DECLARED priority model. + RTCORBA::PriorityModel priority_model = + priority_policy->priority_model (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + if (priority_model != RTCORBA::SERVER_DECLARED) + return -1; + + // Return the server priority. + return priority_policy->server_priority (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +void +Activity::run (int argc, char *argv[] ACE_ENV_ARG_DECL) +{ + this->init (argc, argv ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + if (this->resolve_naming_service (ACE_ENV_SINGLE_ARG_PARAMETER) == -1) + return; + ACE_CHECK; + + this->activate_poa_list (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + this->activate_job_list (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + this->activate_schedule (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + this->create_started_flag_file (argc, argv); + + orb_->run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + orb_->destroy (); + + ACE_Thread_Manager::instance ()->wait (); +} + +void +Activity::create_started_flag_file (int argc, char *argv[]) +{ + ACE_Arg_Shifter arg_shifter (argc, argv); + + const ACE_TCHAR* current_arg = 0; + + while (arg_shifter.is_anything_left ()) + { + if ((current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-Started_Flag")))) + { + FILE *file = ACE_OS::fopen (current_arg, ACE_TEXT("w")); + + if (file == 0) + ACE_ERROR ((LM_ERROR, + "Unable to open %s for writing: %p\n", + current_arg)); + + ACE_OS::fprintf (file, "ignore"); + + ACE_OS::fclose (file); + + arg_shifter.consume_arg (); + } + else + { + arg_shifter.ignore_arg (); + } + } +} + +int +main (int argc, char *argv[]) +{ + ACE_Service_Config::static_svcs ()->insert (&ace_svc_desc_Builder); + + ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGHUP); + + ACE_Timer_Heap timer_queue; + ACE_Reactor::instance ()->timer_queue (&timer_queue); + + ACE_TRY_NEW_ENV + { + ACTIVITY::instance()->run (argc, argv ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Caught exception:"); + return 1; + } + ACE_ENDTRY; + + return 0; +} + +#if defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION) +template ACE_Singleton<Activity, ACE_Null_Mutex> *ACE_Singleton<Activity, ACE_Null_Mutex>::singleton_; +#endif /* ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION */ diff --git a/TAO/examples/RTCORBA/Activity/Activity.h b/TAO/examples/RTCORBA/Activity/Activity.h new file mode 100644 index 00000000000..346b2c6a414 --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Activity.h @@ -0,0 +1,132 @@ +/* -*- C++ -*- */ +//============================================================================= +/** + * @file Activity.h + * + * $Id$ + * + * An activity is a process that contains Tasks. + * Each Task is composed of certain units of Jobs. + * A Job can perform work that is local/remote. + * Each Job is identified with a name. + * + * @author Pradeep Gore <pradeep@cs.wustl.edu> + */ +//============================================================================= +#ifndef ACTIVITY_H +#define ACTIVITY_H + +#include "ace/Singleton.h" +#include "ace/Sched_Params.h" +#include "orbsvcs/CosNamingC.h" +#include "tao/RTPortableServer/RTPortableServer.h" +#include "tao/RTCORBA/Priority_Mapping_Manager.h" +#include "activity_export.h" +#include "ace/Null_Mutex.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL +class ACE_Barrier; +ACE_END_VERSIONED_NAMESPACE_DECL + +class Job_i; +class Periodic_Task; +class Builder; + +/** + * @class Activity + * + * @brief Driver class that maintains the orb and collections of objects for + * generating activity in this process. + * + */ +class activity_Export Activity +{ + friend class ACE_Singleton<Activity, ACE_Null_Mutex>; + +private: + Activity (); + ~Activity (); + +public: + /// initialize the ORB et. al. + int init (int& argc, char *argv [] ACE_ENV_ARG_DECL); + + + /// Activate the tasks, jobs, poas. + void run (int argc, char *argv[] ACE_ENV_ARG_DECL); + + /// Resolve the naming service. + int resolve_naming_service (ACE_ENV_SINGLE_ARG_DECL); + + /// = Accessors + CORBA::ORB_ptr orb (void); + RTCORBA::Current_ptr current (void); + void builder (Builder* builder); + + /// Returns priority if server declared model else -1 + CORBA::Short get_server_priority (CORBA::Object_ptr server + ACE_ENV_ARG_DECL); + /// = Callbacks + /// Task ended notification + void task_ended (Periodic_Task* ended_task); + + /// Job shutdown notification + void job_ended (Job_i* ended_job); + + protected: + /// = Activation methods. + /// Activate the POA's + void activate_poa_list (ACE_ENV_SINGLE_ARG_DECL); + + /// Activate the task list. + void activate_schedule (ACE_ENV_SINGLE_ARG_DECL); + + /// Activate the Job's + void activate_job_list (ACE_ENV_SINGLE_ARG_DECL); + + /// Check if we should process exit + void check_ifexit (void); + + /// Create a file whose name is specified in the -Started_Flag <file_name> argument at startup. + /// This file flags that the Activity has finished its bootstrapping step. + void create_started_flag_file (int argc, char *argv[]); + + /// = Data members + + /// The Builder object. + Builder* builder_; + + /// ACE_Barrier to synch. tasks. + ACE_Barrier* barrier_; + + /// Mutex to serialize access to our internal state. + ACE_Lock* state_lock_; + + /// The ORB that we use. + CORBA::ORB_var orb_; + + /// RT ORB + RTCORBA::RTORB_var rt_orb_; + + /// Current + RTCORBA::Current_var current_; + + /// Reference to the root poa. + PortableServer::POA_var root_poa_; + + /// A naming context. + CosNaming::NamingContextExt_var naming_; + + /// The Priority Mapping helper. + RTCORBA::PriorityMapping *priority_mapping_; + + /// Count the number of periodic tasks active. + int active_task_count_; + + /// Count the number of Jobs active + int active_job_count_; +}; + +typedef ACE_Singleton<Activity, ACE_Null_Mutex> ACTIVITY; + +#endif /* ACTIVITY_H */ diff --git a/TAO/examples/RTCORBA/Activity/Activity.mpc b/TAO/examples/RTCORBA/Activity/Activity.mpc new file mode 100644 index 00000000000..0d7054ff5b0 --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Activity.mpc @@ -0,0 +1,18 @@ +// -*- MPC -*- +// $Id$ + +project : orbsvcslib, namingexe, rt_server { + exename = activity + // We use macros instead of dynamicflags so that + // the symbols will be exported from an exe. + macros += ACTIVITY_BUILD_DLL + Source_Files { + Activity.cpp + Builder.cpp + Job_i.cpp + Periodic_Task.cpp + POA_Holder.cpp + Task_Stats.cpp + Thread_Task.cpp + } +} diff --git a/TAO/examples/RTCORBA/Activity/Builder.cpp b/TAO/examples/RTCORBA/Activity/Builder.cpp new file mode 100644 index 00000000000..1f4433aca95 --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Builder.cpp @@ -0,0 +1,145 @@ +//$Id$ +#include "Builder.h" + +#include "ace/Get_Opt.h" +#include "POA_Holder.h" +#include "Job_i.h" +#include "Thread_Task.h" +#include "Activity.h" + +Builder::Builder(void) + :poa_count_ (0), + poa_list_ (0), + task_count_ (0), + task_list_ (0), + job_count_ (0), + job_list_ (0) +{ + ACTIVITY::instance()->builder (this); +} + +Builder::~Builder(void) +{ + delete[] this->poa_list_; + delete[] this->task_list_; + delete[] this->job_list_; +} + +int +Builder::init (int argc, char *argv[]) +{ + ACE_Arg_Shifter arg_shifter (argc, argv); + + const ACE_TCHAR* current_arg = 0; + + int task_count = 0; + int poa_count = 0; + int job_count = 0; + + while (arg_shifter.is_anything_left ()) + { + if ((current_arg = arg_shifter.get_the_parameter ("-TaskCount"))) + { + task_count_ = ACE_OS::atoi (current_arg); + ACE_NEW_RETURN (task_list_, Periodic_Task*[task_count_], -1); + arg_shifter.consume_arg (); + } + if ((current_arg = arg_shifter.get_the_parameter ("-JobCount"))) + { + job_count_ = ACE_OS::atoi (current_arg); + ACE_NEW_RETURN (job_list_, Job_i*[job_count_], -1); + arg_shifter.consume_arg (); + } + if ((current_arg = arg_shifter.get_the_parameter ("-POACount"))) + { + poa_count_ = ACE_OS::atoi (current_arg); + ACE_NEW_RETURN (poa_list_, POA_Holder*[poa_count_], -1); + arg_shifter.consume_arg (); + } + else if (arg_shifter.cur_arg_strncasecmp ("-ThreadTask") == 0) + { + arg_shifter.consume_arg (); + + Periodic_Task *task = 0; + + ACE_NEW_RETURN (task, Thread_Task (), -1); + + if (task->init_task (arg_shifter) == -1) + return -1; + + task_list_[task_count++] = task; + } + else if (arg_shifter.cur_arg_strncasecmp ("-Job") == 0) + { + arg_shifter.consume_arg (); + + Job_i *job = 0; + + ACE_NEW_RETURN (job, Job_i (), -1); + + if (job->init (arg_shifter) == -1) + return -1; + + this->job_list_[job_count++] = job; + } + else if (arg_shifter.cur_arg_strncasecmp ("-POA") == 0) + { + arg_shifter.consume_arg (); + + POA_Holder *poa_holder; + + ACE_NEW_RETURN (poa_holder, POA_Holder (), -1); + + if (poa_holder->init (arg_shifter) == -1) + { + delete poa_holder; + return -1; + } + + this->poa_list_[poa_count++] = poa_holder; + } + else + { + arg_shifter.ignore_arg (); + } + } + + return 0; +} + +int +Builder::fini (void) +{ + return 0; +} + +int +Builder::poa_list (POA_LIST& poa_list) +{ + poa_list = poa_list_; + return poa_count_; +} + +int +Builder::task_list (TASK_LIST& task_list) +{ + task_list = task_list_; + return task_count_; +} + +int +Builder::job_list (JOB_LIST& job_list) +{ + job_list = job_list_; + return job_count_; +} + + +ACE_STATIC_SVC_DEFINE(Builder, + ACE_TEXT ("Builder"), + ACE_SVC_OBJ_T, + &ACE_SVC_NAME (Builder), + ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ, + 0) + +ACE_FACTORY_DEFINE (activity, Builder) diff --git a/TAO/examples/RTCORBA/Activity/Builder.h b/TAO/examples/RTCORBA/Activity/Builder.h new file mode 100644 index 00000000000..114456dabeb --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Builder.h @@ -0,0 +1,80 @@ +/* -*- C++ -*- */ +//============================================================================= +/** + * @file Builder.h + * + * $Id$ + * + * The builder creates Tasks, Jobs, POAs. + * + * @author Pradeep Gore <pradeep@cs.wustl.edu> + */ +//============================================================================= +#ifndef BUILDER_H +#define BUILDER_H + +#include "orbsvcs/CosNamingC.h" +#include "tao/RTPortableServer/RTPortableServer.h" + +#include "ace/Service_Config.h" +#include "ace/Service_Object.h" +#include "ace/Arg_Shifter.h" +#include "activity_export.h" + +class Activity; +class Periodic_Task; +class Job_i; +class POA_Holder; + +typedef POA_Holder** POA_LIST; +typedef Periodic_Task** TASK_LIST; +typedef Job_i** JOB_LIST; + +/** + * @class Builder + * + * @brief A service object that creates Tasks, Jobs, POAs. + * + */ +class activity_Export Builder : public ACE_Service_Object +{ + public: + /// = Initialization and termination + Builder (); + ~Builder (); + + /// = Service_Object virtual method overloads. + virtual int init (int argc, char *argv[]); + virtual int fini (void); + + /// = List access + int poa_list (POA_LIST& poa_list); + int task_list (TASK_LIST& task_list); + int job_list (JOB_LIST &job_list); + + protected: + + /// Number of POA's declared + int poa_count_; + + /// The list of POA's. + POA_LIST poa_list_; + + /// Number of Tasks's declared + int task_count_; + + /// The list of Tasks. + TASK_LIST task_list_; + + /// Number of Jobs's declared + int job_count_; + + /// The list of Jobs + JOB_LIST job_list_; +}; + +ACE_STATIC_SVC_DECLARE_EXPORT (activity, Builder) + +ACE_FACTORY_DECLARE (activity, Builder) + +#endif /* BUILDER_H */ diff --git a/TAO/examples/RTCORBA/Activity/Job.idl b/TAO/examples/RTCORBA/Activity/Job.idl new file mode 100755 index 00000000000..67c6efa531b --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Job.idl @@ -0,0 +1,10 @@ +// +// $Id$ +// + +interface Job +{ + void work (in unsigned long work); + + oneway void shutdown (); +}; diff --git a/TAO/examples/RTCORBA/Activity/Job_i.cpp b/TAO/examples/RTCORBA/Activity/Job_i.cpp new file mode 100644 index 00000000000..637ea2cd7f6 --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Job_i.cpp @@ -0,0 +1,58 @@ +//$Id$ +#include "Job_i.h" + +#include "tao/debug.h" + +#include "Activity.h" + +Job_i::Job_i () +{ +} + +const ACE_CString& +Job_i::name (void) +{ + return job_name_; +} + +const ACE_CString& +Job_i::poa (void) +{ + return POA_name_; +} + +int +Job_i::init (ACE_Arg_Shifter& arg_shifter) +{ + job_name_ = arg_shifter.get_current (); // Read the name of the Job + arg_shifter.consume_arg (); + + POA_name_ = arg_shifter.get_current (); // Read the name of the POA + arg_shifter.consume_arg (); + + return 0; +} + +void +Job_i::work (CORBA::ULong work ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + static CORBA::ULong prime_number = 9619; + + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, + "test_i::method: %hd units of work\n", + work)); + + for (; work != 0; work--) + ACE::is_prime (prime_number, + 2, + prime_number / 2); +} + +void +Job_i::shutdown (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + ACTIVITY::instance()->job_ended (this); +} diff --git a/TAO/examples/RTCORBA/Activity/Job_i.h b/TAO/examples/RTCORBA/Activity/Job_i.h new file mode 100644 index 00000000000..d1b4ceaa3e2 --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Job_i.h @@ -0,0 +1,58 @@ +/* -*- C++ -*- */ +//============================================================================= +/** + * @file Job_i.h + * + * $Id$ + * + * This file defines the servant for the Job.idl interface + * + * @author Pradeep Gore <pradeep@cs.wustl.edu> + */ +//============================================================================= +#ifndef JOB_I_H +#define JOB_I_H + +#include "JobS.h" +#include "activity_export.h" +#include "ace/SString.h" +#include "ace/Arg_Shifter.h" + +/** + * @class Job_i + * + * @brief Implements a Job that performs some cpu bound work. + * + */ +class activity_Export Job_i : public POA_Job +{ + public: + /// Constructor + Job_i (void); + + /// Init the state of this object. + int init (ACE_Arg_Shifter& arg_shifter); + + /// = Accessors + const ACE_CString& name (void); + const ACE_CString& poa (void); + + /// = inteface Job method implementation. + virtual void work (CORBA::ULong work ACE_ENV_ARG_DECL) + ACE_THROW_SPEC (( + CORBA::SystemException + )); + + virtual void shutdown (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC (( + CORBA::SystemException + )); + protected: + /// The name of this Job + ACE_CString job_name_; + + /// The name of the POA that we live in. + ACE_CString POA_name_; +}; + +#endif /* JOB_I_H */ diff --git a/TAO/examples/RTCORBA/Activity/Makefile.am b/TAO/examples/RTCORBA/Activity/Makefile.am new file mode 100644 index 00000000000..4b1f24cf431 --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Makefile.am @@ -0,0 +1,108 @@ +## Process this file with automake to create Makefile.in +## +## $Id$ +## +## This file was generated by MPC. Any changes made directly to +## this file will be lost the next time it is generated. +## +## MPC Command: +## ../bin/mwc.pl -type automake -noreldefs TAO.mwc + +ACE_BUILDDIR = $(top_builddir)/.. +ACE_ROOT = $(top_srcdir)/.. +TAO_BUILDDIR = $(top_builddir) +TAO_IDL = ACE_ROOT=$(ACE_ROOT) TAO_ROOT=$(TAO_ROOT) $(TAO_BUILDDIR)/TAO_IDL/tao_idl +TAO_IDL_DEP = $(TAO_BUILDDIR)/TAO_IDL/tao_idl +TAO_IDLFLAGS = -Ge 1 -Wb,pre_include=ace/pre.h -Wb,post_include=ace/post.h -I$(TAO_ROOT) -I$(srcdir) -g $(ACE_BUILDDIR)/apps/gperf/src/gperf +TAO_ROOT = $(top_srcdir) + + +## Makefile.Activity.am + +if BUILD_RT_CORBA + +BUILT_SOURCES = \ + JobC.cpp \ + JobC.h \ + JobC.inl \ + JobS.cpp \ + JobS.h \ + JobS.inl \ + JobS_T.cpp \ + JobS_T.h \ + JobS_T.inl + +CLEANFILES = \ + Job-stamp \ + JobC.cpp \ + JobC.h \ + JobC.inl \ + JobS.cpp \ + JobS.h \ + JobS.inl \ + JobS_T.cpp \ + JobS_T.h \ + JobS_T.inl + +JobC.cpp JobC.h JobC.inl JobS.cpp JobS.h JobS.inl JobS_T.cpp JobS_T.h JobS_T.inl: Job-stamp + +Job-stamp: $(srcdir)/Job.idl $(TAO_IDL_DEP) + $(TAO_IDL) $(TAO_IDLFLAGS) -I$(TAO_ROOT)/orbsvcs -GT $(srcdir)/Job.idl + @touch $@ + +noinst_PROGRAMS = activity + +activity_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(TAO_ROOT) \ + -I$(TAO_BUILDDIR) \ + -I$(TAO_ROOT)/orbsvcs \ + -I$(TAO_BUILDDIR)/orbsvcs \ + -DACTIVITY_BUILD_DLL + +activity_SOURCES = \ + Activity.cpp \ + Builder.cpp \ + JobC.cpp \ + JobS.cpp \ + Job_i.cpp \ + POA_Holder.cpp \ + Periodic_Task.cpp \ + Task_Stats.cpp \ + Thread_Task.cpp \ + Activity.h \ + Builder.h \ + JobC.h \ + JobC.inl \ + JobS.h \ + JobS.inl \ + JobS_T.h \ + JobS_T.inl \ + Job_i.h \ + POA_Holder.h \ + Periodic_Task.h \ + Task_Stats.h \ + Task_Stats.inl \ + Thread_Task.h + +activity_LDADD = \ + $(TAO_BUILDDIR)/tao/libTAO_RTPortableServer.la \ + $(TAO_BUILDDIR)/tao/libTAO_RTCORBA.la \ + $(TAO_BUILDDIR)/tao/libTAO_PortableServer.la \ + $(TAO_BUILDDIR)/tao/libTAO_PI.la \ + $(TAO_BUILDDIR)/tao/libTAO_CodecFactory.la \ + $(TAO_BUILDDIR)/orbsvcs/orbsvcs/libTAO_CosNaming.la \ + $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ + $(TAO_BUILDDIR)/tao/libTAO.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif BUILD_RT_CORBA + +## Clean up template repositories, etc. +clean-local: + -rm -f *~ *.bak *.rpo *.sym lib*.*_pure_* core core.* + -rm -f gcctemp.c gcctemp so_locations *.ics + -rm -rf cxx_repository ptrepository ti_files + -rm -rf templateregistry ir.out + -rm -rf ptrepository SunWS_cache Templates.DB diff --git a/TAO/examples/RTCORBA/Activity/POA_Holder.cpp b/TAO/examples/RTCORBA/Activity/POA_Holder.cpp new file mode 100644 index 00000000000..16eb3cd1e4d --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/POA_Holder.cpp @@ -0,0 +1,219 @@ +//$Id$ +#include "POA_Holder.h" +#include "tao/debug.h" +#include "ace/Log_Msg.h" + +POA_Holder::POA_Holder (void) + :priority_model_ (RTCORBA::CLIENT_PROPAGATED), + server_priority_ (0) + { + } + +int +POA_Holder::init (ACE_Arg_Shifter& arg_shifter) +{ + const ACE_TCHAR *current_arg = 0; + + POA_name_ = arg_shifter.get_current (); // Read the name of the POA + arg_shifter.consume_arg (); + + while (arg_shifter.is_anything_left ()) + { + if ((current_arg = arg_shifter.get_the_parameter ("-PriorityModel"))) + { + if (arg_shifter.cur_arg_strncasecmp ("CLIENT") == 0) + priority_model_ = RTCORBA::CLIENT_PROPAGATED; + else + priority_model_ = RTCORBA::SERVER_DECLARED; + arg_shifter.consume_arg (); + + server_priority_ = ACE_OS::atoi (current_arg); + arg_shifter.consume_arg (); + } + else if ((current_arg = arg_shifter.get_the_parameter ("-Lanes"))) + { + int lanecount = ACE_OS::atoi (current_arg); + lanes_.length (lanecount); + arg_shifter.consume_arg (); + + int l_index = 0; + //parse lane values ... + while (arg_shifter.is_anything_left ()) + { + if (arg_shifter.cur_arg_strncasecmp ("-Lane") == 0) + { + arg_shifter.consume_arg (); + + // read priority + lanes_[l_index].lane_priority = ACE_OS::atoi (arg_shifter.get_current ()); + arg_shifter.consume_arg (); + + // static thread count + lanes_[l_index].static_threads = ACE_OS::atoi (arg_shifter.get_current ()); + arg_shifter.consume_arg (); + + // dynamic thread count + lanes_[l_index].dynamic_threads = ACE_OS::atoi (arg_shifter.get_current ()); + arg_shifter.consume_arg (); + + //if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, "lane parsed - %d, %d, %d\n", + lanes_[l_index].lane_priority, lanes_[l_index].static_threads, lanes_[l_index].dynamic_threads)); + l_index++; + } + else + break; + } /* while -- lane values */ + } /* if -Lanes */ + else if ((current_arg = arg_shifter.get_the_parameter ("-Bands"))) + { + int bandcount = ACE_OS::atoi (current_arg); + bands_.length (bandcount); + arg_shifter.consume_arg (); + + int b_index = 0; + //parse band values ... + while (arg_shifter.is_anything_left ()) + { + if (arg_shifter.cur_arg_strncasecmp ("-Band") == 0) + { + arg_shifter.consume_arg (); + + // read low + bands_[b_index].low = ACE_OS::atoi (arg_shifter.get_current ()); + arg_shifter.consume_arg (); + + // read high + bands_[b_index].high = ACE_OS::atoi (arg_shifter.get_current ()); + arg_shifter.consume_arg (); + + //if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, "band parsed - %d, %d \n", + bands_[b_index].low, bands_[b_index].high)); + b_index++; + } + else + break; + } /* while -- Band values */ + + } /* if -Bands */ + else // something else is showing up ... + { + return 0; + } + } + return 0; +} + +void +POA_Holder::activate (RTCORBA::RTORB_ptr rt_orb, PortableServer::POA_ptr parent_poa ACE_ENV_ARG_DECL) +{ + + /* + lanes bands priomodel + + if lanes create lanespolicy + if bands create bands policy + + if lanes and bands , policy_list_length = 3 + else + if lanes policy_list_length = 2 + else + if bands policy_list_length = 2 + else + policy_list_length = 1 + + */ + + CORBA::Policy_var priority_model_policy; + CORBA::Policy_var lanes_policy; + CORBA::Policy_var bands_policy; + + // Create a priority model policy. + priority_model_policy = + rt_orb->create_priority_model_policy (priority_model_, + server_priority_ + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + if (lanes_.length () != 0) + { + // Create a thread-pool. + CORBA::ULong stacksize = 0; + CORBA::Boolean allow_request_buffering = 0; + CORBA::ULong max_buffered_requests = 0; + CORBA::ULong max_request_buffer_size = 0; + CORBA::Boolean allow_borrowing = 0; + // CORBA::ULong static_threads = 1; + // CORBA::ULong dynamic_threads = 0; + + // Create the thread-pool. + RTCORBA::ThreadpoolId threadpool_id = + rt_orb->create_threadpool_with_lanes (stacksize, + lanes_, + allow_borrowing, + allow_request_buffering, + max_buffered_requests, + max_request_buffer_size + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + + // Create a thread-pool policy. + lanes_policy = + rt_orb->create_threadpool_policy (threadpool_id + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + } + + if (bands_.length () != 0) + { + // Create a bands policy. + bands_policy = + rt_orb->create_priority_banded_connection_policy (this->bands_ + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + } + + CORBA::PolicyList poa_policy_list; + + if (lanes_.length () == 0 && bands_.length () == 0) + { + poa_policy_list.length (1); + poa_policy_list[0] = priority_model_policy; + } + else if (lanes_.length () != 0 && bands_.length () == 0) + { + poa_policy_list.length (2); + poa_policy_list[0] = priority_model_policy; + poa_policy_list[1] = lanes_policy; + } + else if (lanes_.length () == 0 && bands_.length () != 0) + { + poa_policy_list.length (2); + poa_policy_list[0] = priority_model_policy; + poa_policy_list[1] = bands_policy; + } + else + { + poa_policy_list.length (3); + poa_policy_list[0] = priority_model_policy; + poa_policy_list[1] = lanes_policy; + poa_policy_list[2] = bands_policy; + } + + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, "creating POA %s\n", POA_name_.c_str ())); + + // Get the POA Manager. + PortableServer::POAManager_var poa_manager = + parent_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + parent_poa->create_POA (POA_name_.c_str (), + poa_manager.in (), + poa_policy_list + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; +} diff --git a/TAO/examples/RTCORBA/Activity/POA_Holder.h b/TAO/examples/RTCORBA/Activity/POA_Holder.h new file mode 100644 index 00000000000..cce1b948364 --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/POA_Holder.h @@ -0,0 +1,50 @@ +/* -*- C++ -*- */ +//============================================================================= +/** + * @file POA_Holder.h + * + * $Id$ + * + * A helper to hold options for creating a POA. + * + * @author Pradeep Gore <pradeep@cs.wustl.edu> + */ +//============================================================================= +#ifndef POA_HOLDER_H +#define POA_HOLDER_H + +#include "tao/RTCORBA/RTCORBA.h" +#include "tao/PortableServer/PortableServer.h" +#include "activity_export.h" +#include "ace/SString.h" +#include "ace/Arg_Shifter.h" + +/** + * @class POA_Holder + * + * @brief An options holder for parameters to creating a poa. + * + */ +class activity_Export POA_Holder +{ + public: + /// Constructor + POA_Holder (void); + + /// The arg_shifter options are read in the following manner: -POA <name> -PriorityModel <CLIENT|SERVER> <priority> -Lanes <count> (-Lane <priority> ,<static_threads> <dynamic_threads>)* -Bands <count> (-Band <low> <high>)* + int init (ACE_Arg_Shifter& arg_shifter); + + /// Activate the new POA using the parameters initialized before. + void activate (RTCORBA::RTORB_ptr rt_orb, PortableServer::POA_ptr parent_poa + ACE_ENV_ARG_DECL); + + protected: + /// = POA create options. + ACE_CString POA_name_; + RTCORBA::PriorityModel priority_model_; + RTCORBA::Priority server_priority_; + RTCORBA::ThreadpoolLanes lanes_; + RTCORBA::PriorityBands bands_; +}; + +#endif /* POA_HOLDER_H */ diff --git a/TAO/examples/RTCORBA/Activity/Periodic_Task.cpp b/TAO/examples/RTCORBA/Activity/Periodic_Task.cpp new file mode 100644 index 00000000000..01e3ac4691a --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Periodic_Task.cpp @@ -0,0 +1,115 @@ +//$Id$ + +#include "Periodic_Task.h" + +#include "ace/High_Res_Timer.h" +#include "tao/debug.h" + +#include "Task_Stats.h" + +Periodic_Task::Periodic_Task (void) + :barrier_ (0), + task_priority_ (0), + period_ (0), + exec_time_ (0), + phase_ (0), + iter_ (0), + load_ (0), + task_stats_ (0) +{ +} + +Periodic_Task::~Periodic_Task () +{ + delete task_stats_; +} + +int +Periodic_Task::init_task (ACE_Arg_Shifter& arg_shifter) +{ + const ACE_TCHAR *current_arg = 0; + + while (arg_shifter.is_anything_left ()) + { + if ((current_arg = arg_shifter.get_the_parameter ("-JobName"))) + { + name_ = current_arg; + arg_shifter.consume_arg (); + } + else if ((current_arg = arg_shifter.get_the_parameter ("-Priority"))) + { + task_priority_ = ACE_OS::atoi (current_arg); + arg_shifter.consume_arg (); + } + else if ((current_arg = arg_shifter.get_the_parameter ("-Period"))) + { + period_ = ACE_OS::atoi (current_arg); + arg_shifter.consume_arg (); + } + else if ((current_arg = arg_shifter.get_the_parameter ("-ExecTime"))) + { + exec_time_ = ACE_OS::atoi (current_arg); + arg_shifter.consume_arg (); + } + else if ((current_arg = arg_shifter.get_the_parameter ("-Phase"))) + { + phase_ = ACE_OS::atoi (current_arg); + arg_shifter.consume_arg (); + } + else if ((current_arg = arg_shifter.get_the_parameter ("-Iter"))) + { + iter_ = ACE_OS::atoi (current_arg); + arg_shifter.consume_arg (); + + // create the stat object. + ACE_NEW_RETURN (task_stats_, Task_Stats (iter_), -1); + + if (task_stats_->init () == -1) + return -1; + } + else if ((current_arg = arg_shifter.get_the_parameter ("-Load"))) + { + load_ = ACE_OS::atoi (current_arg); + arg_shifter.consume_arg (); + + return 0; + } + else + { + ACE_DEBUG ((LM_DEBUG, "parse Task unknown option %s\n", + arg_shifter.get_current ())); + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, "name %s, priority %d, period %duS, exec_time %duS, phase %duS, iter %d, load %d\n", + name_.c_str(), task_priority_, period_, exec_time_, phase_, iter_, load_)); + break; + } + } + return 0; +} + +const char* +Periodic_Task::job (void) +{ + return name_.c_str (); +} + +void +Periodic_Task::job (Job_ptr job) +{ + job_ = Job::_duplicate (job); +} + +void +Periodic_Task::dump_stats (ACE_TCHAR* msg) +{ + char buf[BUFSIZ]; + ACE_OS::sprintf (buf, "%s%s", name_.c_str (),".dat"); + + ACE_CString fname (buf); + + ACE_OS::sprintf (buf,"#%s #name %s, priority %d, period %ld, exec_time %ld, phase %ld, iter_ %d , load_ %d", + msg, name_.c_str(), task_priority_, period_, exec_time_, phase_, iter_, load_); + + task_stats_->dump_samples (fname.c_str (), buf, + ACE_High_Res_Timer::global_scale_factor ()); +} diff --git a/TAO/examples/RTCORBA/Activity/Periodic_Task.h b/TAO/examples/RTCORBA/Activity/Periodic_Task.h new file mode 100644 index 00000000000..3973ee1036e --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Periodic_Task.h @@ -0,0 +1,94 @@ +/* -*- C++ -*- */ +//============================================================================= +/** + * @file Periodic_Task.h + * + * $Id$ + * + * Base class for Periodic Tasks + * + * @author Pradeep Gore <pradeep@cs.wustl.edu> + */ +//============================================================================= +#ifndef PERIODIC_TASK_H +#define PERIODIC_TASK_H + +#include "tao/RTCORBA/RTCORBA.h" +#include "tao/RTCORBA/Priority_Mapping_Manager.h" +#include "ace/Task.h" +#include "ace/SString.h" +#include "ace/Arg_Shifter.h" +#include "JobC.h" +#include "activity_export.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL +class ACE_Barrier; +ACE_END_VERSIONED_NAMESPACE_DECL + +class Task_Stats; + +/** + * @class Periodic_Task + * + * @brief Periodic_Task executes jobs. + * + */ +class activity_Export Periodic_Task : public ACE_Task <ACE_SYNCH> +{ + public: + /// = Initialization and termination code. + Periodic_Task (void); + ~Periodic_Task (); + + /// Init the state of this object. + int init_task (ACE_Arg_Shifter& arg_shifter); + + /// Activate this task, synch on the given barrier. + virtual int activate_task (ACE_Barrier* barrier, RTCORBA::PriorityMapping *priority_mapping) = 0; + + /// Dump the stats collected. + void dump_stats (ACE_TCHAR* msg); + + /// = Job get/set + /// Returns the name of the Job exec'ed by this Task. + const char* job (void); + + /// Sets the Job to exec. + void job (Job_ptr job); + + protected: + /// All tasks synch at this barrier. + ACE_Barrier* barrier_; + + /// The Job to execute. + Job_var job_; + + /// Name of the Job. + ACE_CString name_; + + /// = Task parameters + /// see http://www.cis.ksu.edu/~neilsen/classes/cis721/lectures/lecture2/sld009.htm + + /// The priority of this task. + RTCORBA::Priority task_priority_; + + /// Period + unsigned long period_; + + /// Worst case exec. time. + unsigned long exec_time_; + + /// Phase + long phase_; + + /// Number of times to exec. Job + int iter_; + + /// A load factor supplied to each Job. + int load_; + + /// = Stats house keeping + Task_Stats* task_stats_; +}; + +#endif /* PERIODIC_TASK_H */ diff --git a/TAO/examples/RTCORBA/Activity/README b/TAO/examples/RTCORBA/Activity/README new file mode 100755 index 00000000000..32264d094e1 --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/README @@ -0,0 +1,133 @@ +//$Id$ +=================== RT CORBA capabilities demo =================== + +Table of contents +----------------- +1. Introduction +2. Conf file parameters +3. Running the example. + +1. Introduction + +The Real-Time CORBA specification provides a high level API for programmers +to write distributed applications in which the priority of a distributed +thread of execution is maintained across separate hosts with potentially +different operating systems. It also provides support for explicit +binding, standard sychronizers, the ability to modify transport protocol +properties and thread pools as a standard. + +In this experiment we show the effect of maintaining end to end priorities. + +The experiment consists of the following participants: + +Job: A CORBA servant object that performs CPU intensive work. The ammount +of work depends on a load factor that is conveyed to the object per +invocation as an argument. + +Periodic Task: A periodic task is a thread of execution that is associated +with a Job. A Task periodically invokes the Job after a period of time +specified by the user. + +Activity: An activity is a collection of Jobs and Tasks hosted in a single +process. An activity reads a configuration file that can be used to +initialize in many ways such as a client or server. + +2. Conf file parameters +-------------------- +POA OPTIONS +========== +To specify POA options the format is: + +-POA <name> -PriorityModel <CLIENT|SERVER> <priority> -Lanes <count> (-Lane <priority> ,<static_threads> <dynamic_threads>)* -Bands <count> (-Band <low> <high>)* + +e.g. +-POA poa1 -PriorityModel CLIENT 10 -Bands 2 -Band 1 20 -Band 30 85 -Lanes 2 -Lane 10 1 0 -Lane 80 1 0 + +specifes a POA with: + +Name - poa1 + +Priority model - client propogated, def. priority = 10 + +Bands - 2 Bands with Band values as follows - + Band 1 : low priority = 1, high priority = 20 + Band 2 : low priority = 30, high priority = 85 + +Lanes - 2 Lanes with Lane values as follows - + Lane 1 : priority = 10, 1 static thread, 0 dynamic threads + Lane 2 : priority = 80, 1 static thread, 0 dynamic threads + +You can specify options for creating POA, Job and Task as shown +below. Please note that you must specify the number of POA, Job or Task via +the following options at the beginning of the conf. file: + +-POACount [count] +-TaskCount [count] +-JobCount [count] + +Job Options +=========== +The format for specify a Job is: +-Job <name> <poa_name> + +where, poa_name is the POA that this object is activated in. + +e.g. +-Job job_10 poa1 + +specifies a Job with, + +Name - job_10 +POA Name - poa1 + +Task Options +============ + +The format for specify a Task is: + +-ThreadTask -JobName <name> -Priority <priority> -Period <period> -ExecTime <exec_time> -Phase <phase> -Iter <iterations> -Load <load_weight> + +where, +-ThreadTask = Specifies a Thread based timer. +-JobName <name> = Name of the Job object that this task will exec. once every period. +-Priority <priority> = The OS thread priority at which to run this task. +-Period <period> = The period of execution. (in uS) +-ExecTime <exec_time> = The offline estimate of the worst case execution time for the Job. (uS) +-Phase <phase> = The phase to start at (uS) +-Iter <iterations> = Number of Periods to exec. +-Load <load_weight> = a load factor passed to the job that varies its processing. + +e.g. +-ThreadTask -JobName job_10 -Priority 10 -Period 1 -ExecTime 10000 -Phase 0 -Iter 20 -Load 1000 + +specifes a Thread Task in which, +JobName = job_10 +-Priority = 10 +-Period = 1uS +-ExecTime = 10000uS +-Phase = 0uS +-Iter = 20 iterations +-Load = 1000 + +4. Command-Line Options +---------------------- +-Started_Flag <file_name> : When a particular activity instance has +finished bootstrapping, it will create a file specified by <file_name> +to signal that it has started. This allows scripts to synchronize when +other instances of activity can be started. + +4. Running the example +---------------------- + +a). The activated Jobs are registered with a Naming service, so we need an NS running +e.g. ./Naming_Service -o naming_ior + +b). Start one or more instances of ./activity depending on the test configuration that you have designed. + +e.g. ./activity -ORBInitRef NameService=file://naming_ior -ORBSvcConf svc.conf.whatever -ORBDebugLevel 1 + +c) once all the instances exit, the test will generate data files: <job_name>.dat + +use gen_graph to generate a .png file to view the results in a graphical viewer. + + diff --git a/TAO/examples/RTCORBA/Activity/Task_Stats.cpp b/TAO/examples/RTCORBA/Activity/Task_Stats.cpp new file mode 100644 index 00000000000..bcd6ae53d88 --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Task_Stats.cpp @@ -0,0 +1,185 @@ +//$Id$ +#include "Task_Stats.h" +#include "ace/OS.h" +#include "ace/Log_Msg.h" + +#if !defined (__ACE_INLINE__) +#include "Task_Stats.inl" +#endif /* __ACE_INLINE__ */ + +Base_Time::Base_Time (void) +{ + base_time_ = ACE_OS::gethrtime (); +} + +Task_Stats::Task_Stats (size_t max_samples) + : base_time_(0), + end_time_ (0), + max_samples_ (max_samples), + samples_count_ (0), + time_inv_ (0), + time_exec_ (0), + exec_time_min_ (0), + exec_time_min_at_ (0), + exec_time_max_ (0), + exec_time_max_at_(0), + sum_ (0), + sum2_ (0) +{ +} + +Task_Stats::~Task_Stats (void) +{ + delete[] this->time_inv_; + delete[] this->time_exec_; +} + +int +Task_Stats::init (void) +{ + ACE_NEW_RETURN (this->time_inv_, ACE_UINT64[this->max_samples_], -1); + ACE_NEW_RETURN (this->time_exec_, ACE_UINT64[this->max_samples_], -1); + return 0; +} + +void +Task_Stats::base_time (ACE_hrtime_t time) +{ + base_time_ = time; +} + +void +Task_Stats::end_time (ACE_hrtime_t time) +{ + end_time_ = time; +} + +void +Task_Stats::dump_samples (const ACE_TCHAR *file_name, const ACE_TCHAR *msg, + ACE_UINT32 scale_factor) +{ + FILE* output_file = ACE_OS::fopen (file_name, "w"); + + // first dump what the caller has to say. + ACE_OS::fprintf (output_file, "%s\n",msg); + + // next, compose and dump what we want to say. + + // calc throughput. + + ACE_TCHAR out_msg[BUFSIZ]; + + ACE_hrtime_t elapsed_microseconds = (end_time_ - base_time_) / scale_factor; + double elapsed_seconds = + ACE_CU64_TO_CU32(elapsed_microseconds) / 1000000.0; + double throughput = + double(samples_count_) / elapsed_seconds; + + ACE_OS::sprintf (out_msg, "#Throughtput: %f\n", throughput); + ACE_OS::fprintf (output_file, "%s\n",out_msg); + + // dump latency stats. + this->dump_latency_stats (out_msg, scale_factor); + ACE_OS::fprintf (output_file, "%s\n",out_msg); + ACE_OS::fprintf (output_file, "#Invocation time \t Execution time\n"); + + // dump the samples recorded. + for (size_t i = 0; i != this->samples_count_; ++i) + { + ACE_UINT64 x = this->time_inv_[i] / scale_factor; + ACE_UINT32 val_1 = ACE_CU64_TO_CU32 (x); + + ACE_UINT64 y = this->time_exec_[i] / scale_factor; + ACE_UINT32 val_2 = ACE_CU64_TO_CU32 (y); + + ACE_OS::fprintf (output_file, "%u \t %u\n",val_1, val_2); + } + + ACE_OS::fclose (output_file); +} + +void +Task_Stats::dump_latency_stats (ACE_TCHAR *out_msg, ACE_UINT32 sf) +{ + if (this->samples_count_ == 0u) + { + ACE_OS::sprintf (out_msg, + ACE_TEXT ("# no data collected\n")); + return; + } + + ACE_UINT64 avg = this->sum_ / this->samples_count_; + ACE_UINT64 dev = +#if defined ACE_LACKS_LONGLONG_T + static_cast<ACE_U_LongLong> (this->sum2_ / this->samples_count_) + - avg * ACE_U64_TO_U32(avg); +#else /* ! ACE_LACKS_LONGLONG_T */ + this->sum2_ / this->samples_count_ - avg * avg; +#endif /* ! ACE_LACKS_LONGLONG_T */ + + ACE_UINT64 l_min_ = this->exec_time_min_ / sf; + ACE_UINT32 l_min = ACE_CU64_TO_CU32 (l_min_); + + ACE_UINT64 l_max_ = this->exec_time_max_ / sf; + ACE_UINT32 l_max = ACE_CU64_TO_CU32 (l_max_); + + /* + ACE_UINT64 l_avg_ = avg / sf; + ACE_UINT32 l_avg = ACE_CU64_TO_CU32 (l_avg_); + + ACE_UINT64 l_dev_ = dev / sf; + ACE_UINT32 l_dev = ACE_CU64_TO_CU32 (l_dev_); + */ + + double l_avg = ACE_CU64_TO_CU32 (avg) / sf; + double l_dev = ACE_CU64_TO_CU32 (dev) / (sf * sf); + + ACE_UINT64 tmin_ = this->time_inv_[0] / sf; + ACE_UINT32 tmin = ACE_CU64_TO_CU32 (tmin_); + + ACE_UINT64 tmax_ = this->time_inv_[samples_count_-1] / sf; + ACE_UINT32 tmax = ACE_CU64_TO_CU32 (tmax_); + + ACE_OS::sprintf(out_msg, + ACE_TEXT ("#latency : %u[%d]/%.2f/%u[%d]/%.2f (min/avg/max/var^2)\n #first invocation time = %u, last invocation time = %u\n"), + l_min, this->exec_time_min_at_, + l_avg, + l_max, this->exec_time_max_at_, + l_dev, + tmin,tmax); + /* + double l_min = ACE_CU64_TO_CU32 (this->exec_time_min_) / sf; + double l_max = ACE_CU64_TO_CU32 (this->exec_time_max_) / sf; + double l_avg = ACE_CU64_TO_CU32 (avg) / sf; + double l_dev = ACE_CU64_TO_CU32 (dev) / (sf * sf); + + double tmin = ACE_CU64_TO_CU32 (this->time_inv_[0])/sf; + double tmax = ACE_CU64_TO_CU32 (this->time_inv_[samples_count_-1])/sf; + + ACE_OS::sprintf(out_msg, + ACE_TEXT ("#latency : %.2f[%d]/%.2f/%.2f[%d]/%.2f (min/avg/max/var^2)\n #first invocation time = %.0f, last invocation time = %.0f\n"), + l_min, this->exec_time_min_at_, + l_avg, + l_max, this->exec_time_max_at_, + l_dev, + tmin,tmax); + + + ACE_OS::sprintf(out_msg, + ACE_TEXT ("#latency : %.2f[%d]/%.2f/%.2f[%d]/%.2f (min/avg/max/var^2)\n"), + l_min, this->exec_time_min_at_, + l_avg, + l_max, this->exec_time_max_at_, + l_dev); + + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("#latency : %.2f[%d]/%.2f/%.2f[%d]/%.2f (min/avg/max/var^2)\n"), + l_min, this->exec_time_min_at_, + l_avg, + l_max, this->exec_time_max_at_, + l_dev)); + */ +} + +#if defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION) +template ACE_Singleton<Base_Time, ACE_Thread_Mutex> *ACE_Singleton<Base_Time, ACE_Thread_Mutex>::singleton_; +#endif /* ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION */ diff --git a/TAO/examples/RTCORBA/Activity/Task_Stats.h b/TAO/examples/RTCORBA/Activity/Task_Stats.h new file mode 100644 index 00000000000..8252c071c89 --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Task_Stats.h @@ -0,0 +1,106 @@ +/* -*- C++ -*- */ +//============================================================================= +/** + * @file Task_Stats.h + * + * $Id$ + * + * Utility Stats class that maintains the readings. + * + * @author Pradeep Gore <pradeep@cs.wustl.edu> + */ +//============================================================================= +#ifndef TASK_STATS_H +#define TASK_STATS_H + +#include "ace/OS_NS_time.h" +#include "ace/Singleton.h" +#include "tao/orbconf.h" +#include "tao/debug.h" +#include "activity_export.h" + +/** + * @class Base_Time + * + * @brief maintains readings recorded by tasks. + * + */ +class activity_Export Base_Time +{ + public: + Base_Time (void); + ACE_hrtime_t base_time_; +}; + +typedef ACE_Singleton<Base_Time, TAO_SYNCH_MUTEX> BASE_TIME; + +/** + * @class Task_Stats + * + * @brief maintains readings recorded by tasks. + * + */ +class activity_Export Task_Stats +{ + public: + /// Constructor + Task_Stats (size_t max_samples); + + /// Destructor + ~Task_Stats (void); + + /// Init + int init (void); + + /// Set the base time value. + void base_time (ACE_hrtime_t time); + + /// Set the end time value. + void end_time (ACE_hrtime_t time); + + /// Record a sample + int sample (ACE_UINT64 inv_start_time, ACE_UINT64 inv_end_time); + + void dump_samples (const ACE_TCHAR *file_name, const ACE_TCHAR *msg, + ACE_UINT32 scale_factor); + protected: + void dump_latency_stats (ACE_TCHAR *out_msg, ACE_UINT32 sf); + + /// Base and end times + ACE_hrtime_t base_time_; + ACE_hrtime_t end_time_; + + /// The maximum number of samples + ACE_UINT32 max_samples_; + + /// The number of samples + ACE_UINT32 samples_count_; + + /// The samples : the time of invocation. and the recorded exec. time . + ACE_UINT64 *time_inv_; + ACE_UINT64 *time_exec_; + + /// The minimum value + ACE_UINT64 exec_time_min_; + + /// The number of the sample that had the minimum value + ACE_UINT32 exec_time_min_at_; + + /// The maximum value + ACE_UINT64 exec_time_max_; + + /// The number of the sample that had the maximum value + ACE_UINT32 exec_time_max_at_; + + /// The sum of all the values + ACE_UINT64 sum_; + + /// The sum of the square of all the values + ACE_UINT64 sum2_; +}; + +#if defined (__ACE_INLINE__) +#include "Task_Stats.inl" +#endif /* __ACE_INLINE__ */ + +#endif /* TASK_STATS_H */ diff --git a/TAO/examples/RTCORBA/Activity/Task_Stats.inl b/TAO/examples/RTCORBA/Activity/Task_Stats.inl new file mode 100644 index 00000000000..78ce13d05bc --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Task_Stats.inl @@ -0,0 +1,57 @@ +//$Id$ + +#include "ace/Log_Msg.h" + +ACE_INLINE int +Task_Stats::sample (ACE_UINT64 inv_start_time, ACE_UINT64 inv_end_time) +{ + if (this->samples_count_ >= this->max_samples_) + { + ACE_DEBUG ((LM_DEBUG, "Task_Stats::sample ret -1\n")); + return -1; + } + ACE_UINT64 inv_value, exec_value; + + inv_value = inv_start_time - base_time_; + exec_value = inv_end_time - inv_start_time; + + this->time_inv_[this->samples_count_] = inv_value; + this->time_exec_[this->samples_count_] = exec_value; + + this->samples_count_++; + + if (this->samples_count_ == 1u) + { + this->exec_time_min_ = exec_value; + this->exec_time_min_at_ = this->samples_count_; + this->exec_time_max_ = exec_value; + this->exec_time_max_at_ = this->samples_count_; + this->sum_ = exec_value; +#if defined ACE_LACKS_LONGLONG_T + this->sum2_ = exec_value * ACE_U64_TO_U32 (exec_value); +#else /* ! ACE_LACKS_LONGLONG_T */ + this->sum2_ = exec_value * exec_value; +#endif /* ! ACE_LACKS_LONGLONG_T */ + } + else + { + if (this->exec_time_min_ > exec_value) + { + this->exec_time_min_ = exec_value; + this->exec_time_min_at_ = this->samples_count_; + } + if (this->exec_time_max_ < exec_value) + { + this->exec_time_max_ = exec_value; + this->exec_time_max_at_ = this->samples_count_; + } + + this->sum_ += exec_value; +#if defined ACE_LACKS_LONGLONG_T + this->sum2_ += exec_value * ACE_U64_TO_U32 (exec_value); +#else /* ! ACE_LACKS_LONGLONG_T */ + this->sum2_ += exec_value * exec_value; +#endif /* ! ACE_LACKS_LONGLONG_T */ + } + return 0; +} diff --git a/TAO/examples/RTCORBA/Activity/Thread_Task.cpp b/TAO/examples/RTCORBA/Activity/Thread_Task.cpp new file mode 100644 index 00000000000..08c9450f44e --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Thread_Task.cpp @@ -0,0 +1,148 @@ +//$Id$ +#include "Thread_Task.h" + +#include "ace/High_Res_Timer.h" +#include "ace/OS_NS_unistd.h" +#include "tao/debug.h" +#include "tao/ORB_Core.h" + +#include "Activity.h" +#include "Task_Stats.h" +#include "ace/Barrier.h" + +Thread_Task::Thread_Task (void) +{ +} + +int +Thread_Task::activate_task (ACE_Barrier* barrier, RTCORBA::PriorityMapping *priority_mapping) +{ + barrier_ = barrier; + + // Convert the priority specified to this class to its native number. + RTCORBA::NativePriority native_priority; + + if (priority_mapping->to_native (this->task_priority_, native_priority) == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot convert CORBA priority %d to native priority\n", + this->task_priority_), + -1); + + long flags = + THR_NEW_LWP | + THR_JOINABLE | + ACTIVITY::instance()->orb ()->orb_core ()->orb_params ()->thread_creation_flags (); + + // Become an active object. + if (this->activate (flags, + 1, + 0, + native_priority) == -1) + { + if (ACE_OS::last_error () == EPERM) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Insufficient privilege to run this test.\n")), + -1); + else + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("(%t) task activation at priority %d failed, ") + ACE_TEXT ("exiting!\n%a"), + native_priority, + -1)); + } + return 0; +} + +int +Thread_Task::svc (void) +{ + // if debugging, dump the priority that we're actually at. + if (TAO_debug_level > 0) + { + ACE_DECLARE_NEW_CORBA_ENV; + + // Get the priority of the current thread. + RTCORBA::Priority prio = + ACTIVITY::instance()->current ()->the_priority (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + if (prio == this->task_priority_) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%t) actual prio of %d equals desired priority\n"), + prio)); + else + { + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("(%t) actual prio = %d, desired priority_ = %d!\n"), + prio, + this->task_priority_)); + } + } + + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, "Thread_Task (%t) - wait\n")); + + // First, wait for other threads. + this->barrier_->wait (); + + // first thread here inits the Base_Time. + task_stats_->base_time (BASE_TIME::instance ()->base_time_); + + // now wait till the phase_ period expires. + ACE_OS::sleep (ACE_Time_Value (0, phase_)); + + ACE_UINT32 gsf = ACE_High_Res_Timer::global_scale_factor (); + + ACE_hrtime_t before, after; + + for (int i = 0; i < iter_ ; ++i) + { + before = ACE_OS::gethrtime (); + + job_->work (load_); + + after = ACE_OS::gethrtime (); + + task_stats_->sample (before, after); + + if (period_ != 0) // blast mode, no sleep. + { + // convert to microseconds +#if !defined ACE_LACKS_LONGLONG_T + + ACE_UINT32 elapsed_microseconds = ACE_UINT32((after - before) / gsf); + +#else /* ! ACE_LACKS_LONGLONG_T */ + + ACE_UINT32 elapsed_microseconds = (after - before) / gsf; + +#endif /* ! ACE_LACKS_LONGLONG_T */ + +#if defined (ACE_WIN32) + elapsed_microseconds*=1000; // convert to uSec on Win32 +#endif /* ACE_WIN32 */ + + // did we miss any deadlines? + + int const missed = + elapsed_microseconds > period_ ? elapsed_microseconds/period_ : 0; + + long sleep_time = (missed + 1)*period_ ; + sleep_time -= elapsed_microseconds; + + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, "(%t) sleep time = %d\n", sleep_time)); + + ACE_Time_Value t_sleep (0, sleep_time); + ACE_OS::sleep (t_sleep); + } /* period != 0 */ + } /* for */ + + task_stats_->end_time (ACE_OS::gethrtime ()); + + job_->shutdown (); // tell the job that we're done. + + ACTIVITY::instance ()->task_ended (this); + + return 0; +} diff --git a/TAO/examples/RTCORBA/Activity/Thread_Task.h b/TAO/examples/RTCORBA/Activity/Thread_Task.h new file mode 100644 index 00000000000..ae8f3a3ef2a --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/Thread_Task.h @@ -0,0 +1,45 @@ +/* -*- C++ -*- */ +//============================================================================= +/** + * @file Thread_Task.h + * + * $Id$ + * + * A periodic task implementation that uses sleep. + * + * @author Pradeep Gore <pradeep@cs.wustl.edu> + */ +//============================================================================= +#ifndef THREAD_TASK_H +#define THREAD_TASK_H + +#include "Periodic_Task.h" + +/** + * @class Thread_Task + * + * @brief A periodic task implementation that uses sleep. + * + * simplified Periodic Task - + * if the <name_> activity, which is fired every <period_> time intervals, + * exceeds its <exec_time_>, it is "late". + * if <exec_time_> is greater than the <period_>, the activity(s) for the + * overlapped period(s) are considered "missed". + * + */ +class activity_Export Thread_Task : public Periodic_Task +{ + public: + /// Constructor + Thread_Task (void); + + /// Activate thread(s). + virtual int activate_task (ACE_Barrier* barrier, RTCORBA::PriorityMapping *priority_mapping); + + protected: + + /// task svc + virtual int svc (void); +}; + +#endif /* THREAD_TASK_H */ diff --git a/TAO/examples/RTCORBA/Activity/activity_export.h b/TAO/examples/RTCORBA/Activity/activity_export.h new file mode 100644 index 00000000000..a33eec53a40 --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/activity_export.h @@ -0,0 +1,38 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl +// ------------------------------ +#ifndef ACTIVITY_EXPORT_H +#define ACTIVITY_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (ACTIVITY_HAS_DLL) +# define ACTIVITY_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && ACTIVITY_HAS_DLL */ + +#if !defined (ACTIVITY_HAS_DLL) +# define ACTIVITY_HAS_DLL 1 +#endif /* ! ACTIVITY_HAS_DLL */ + +#if defined (ACTIVITY_HAS_DLL) && (ACTIVITY_HAS_DLL == 1) +# if defined (ACTIVITY_BUILD_DLL) +# define activity_Export ACE_Proper_Export_Flag +# define ACTIVITY_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define ACTIVITY_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* ACTIVITY_BUILD_DLL */ +# define activity_Export ACE_Proper_Import_Flag +# define ACTIVITY_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define ACTIVITY_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* ACTIVITY_BUILD_DLL */ +#else /* ACTIVITY_HAS_DLL == 1 */ +# define activity_Export +# define ACTIVITY_SINGLETON_DECLARATION(T) +# define ACTIVITY_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* ACTIVITY_HAS_DLL == 1 */ + +#endif /* ACTIVITY_EXPORT_H */ + +// End of auto generated file. diff --git a/TAO/examples/RTCORBA/Activity/client.conf b/TAO/examples/RTCORBA/Activity/client.conf new file mode 100644 index 00000000000..196de98c87d --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/client.conf @@ -0,0 +1,5 @@ +## Sanity check Client conf file to be run for SCHED_OTHER policy + +static RT_ORB_Loader "-ORBSchedPolicy SCHED_OTHER -ORBScopePolicy PROCESS -ORBPriorityMapping linear" + +static Builder "-TaskCount 1 -ThreadTask -JobName job_0 -Priority 0 -Period 1 -ExecTime 10000 -Phase 0 -Iter 20 -Load 1000" diff --git a/TAO/examples/RTCORBA/Activity/gen_graphs.sh b/TAO/examples/RTCORBA/Activity/gen_graphs.sh new file mode 100755 index 00000000000..50ceee794e1 --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/gen_graphs.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# +# $Id$ +# + +# test.dat test.png test +#gnuplot <<_EOF_ >/dev/null 2>&1 +/usr/bin/gnuplot <<_EOF_ + set xlabel 'time (uS)' + set ylabel 'Request latency (uS)' + set terminal png small color + set autoscale + set output "$2" + plot '$1' using 1:2 title '$3' w l + exit +_EOF_ diff --git a/TAO/examples/RTCORBA/Activity/run_test.pl b/TAO/examples/RTCORBA/Activity/run_test.pl new file mode 100755 index 00000000000..5dc0eef76ba --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/run_test.pl @@ -0,0 +1,68 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- +# +# +use lib "../../../../bin"; +use PerlACE::Run_Test; + +$status = 0; +$startup_timeout = 60; +$experiment_timeout = 60; +$naming_ior = PerlACE::LocalFile ("naming.ior"); +$server_flag_file = PerlACE::LocalFile ("server.flag"); +$server_conf = PerlACE::LocalFile ("server.conf"); +$client_conf = PerlACE::LocalFile ("client.conf"); + +$Naming = new PerlACE::Process ("../../../orbsvcs/Naming_Service/Naming_Service", + "-o $naming_ior"); + +$Activity_Client = new PerlACE::Process ("activity", + "-ORBInitRef NameService=file://$naming_ior " . + "-ORBSvcConf $client_conf"); + +$Activity_Server = new PerlACE::Process ("activity", + "-ORBInitRef NameService=file://$naming_ior " . + "-ORBSvcConf $server_conf " . + "-Started_Flag $server_flag_file"); + +unlink $naming_ior; +unlink $server_flag_file; + +print STDERR "Running Naming_Service\n"; + +$Naming->Spawn (); + +if (PerlACE::waitforfile_timed ($naming_ior, $startup_timeout) == -1) { + print STDERR "ERROR: waiting for the naming service to start\n"; + $Naming->Kill (); + exit 1; +} + + +print STDERR "Running Activity Server\n"; +$Activity_Server->Spawn (); + +if (PerlACE::waitforfile_timed ($server_flag_file, $startup_timeout) == -1) { + print STDERR "ERROR: waiting for the server to start\n"; + $Activity_Server->Kill (); + $Naming->Kill (); + exit 1; +} + +print STDERR "Running Activity Client\n"; + +$status = $Activity_Client->SpawnWaitKill ($experiment_timeout); + +if ($status != 0) + { + print STDERR "ERROR: Client Activity returned $status\n"; + } + +$Activity_Server->Kill (); +$Naming->Kill (); + +exit $status; diff --git a/TAO/examples/RTCORBA/Activity/server.conf b/TAO/examples/RTCORBA/Activity/server.conf new file mode 100644 index 00000000000..e375a3fb8c1 --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/server.conf @@ -0,0 +1,6 @@ +## Sanity check Server conf file to be run for SCHED_OTHER policy + +static RT_ORB_Loader "-ORBSchedPolicy SCHED_OTHER -ORBScopePolicy PROCESS -ORBPriorityMapping linear" + +static Builder "-POACount 1 -POA poa1 -PriorityModel CLIENT 0 -Lanes 1 -Lane 0 1 0 -JobCount 1 -Job job_0 poa1" + diff --git a/TAO/examples/RTCORBA/Activity/svc.conf.client b/TAO/examples/RTCORBA/Activity/svc.conf.client new file mode 100755 index 00000000000..83fdc67758a --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/svc.conf.client @@ -0,0 +1,12 @@ +# -- E X A M P L E conf. file -- + +# Note! priority values are for Linux + + + +static RT_ORB_Loader "-ORBSchedPolicy SCHED_RR -ORBScopePolicy PROCESS -ORBPriorityMapping direct" + + + +static Builder "-TaskCount 2 -ThreadTask -JobName job_10 -Priority 10 -Period 1 -ExecTime 10000 -Phase 0 -Iter 20 -Load 1000 -ThreadTask -JobName job_80 -Priority 80 -Period 1 -ExecTime 10000 -Phase 0 -Iter 20 -Load 1000" + diff --git a/TAO/examples/RTCORBA/Activity/svc.conf.server b/TAO/examples/RTCORBA/Activity/svc.conf.server new file mode 100755 index 00000000000..f5944646c05 --- /dev/null +++ b/TAO/examples/RTCORBA/Activity/svc.conf.server @@ -0,0 +1,6 @@ +# -- E X A M P L E conf. file -- +# Note! priority values are for Linux + +static RT_ORB_Loader "-ORBSchedPolicy SCHED_FIFO -ORBScopePolicy PROCESS -ORBPriorityMapping direct" + +static Builder "-POACount 1 -POA poa1 -PriorityModel CLIENT 10 -Bands 2 -Band 1 20 -Band 30 85 -Lanes 2 -Lane 10 1 0 -Lane 80 1 0 -JobCount 2 -Job job_10 poa1 -Job job_80 poa1" diff --git a/TAO/examples/RTCORBA/Makefile.am b/TAO/examples/RTCORBA/Makefile.am new file mode 100644 index 00000000000..481bc3e73a0 --- /dev/null +++ b/TAO/examples/RTCORBA/Makefile.am @@ -0,0 +1,13 @@ +## Process this file with automake to create Makefile.in +## +## $Id$ +## +## This file was generated by MPC. Any changes made directly to +## this file will be lost the next time it is generated. +## +## MPC Command: +## ../bin/mwc.pl -type automake -noreldefs TAO.mwc + +SUBDIRS = \ + Activity + |