2 #include "ace/Get_Opt.h"
4 #include "ace/High_Res_Timer.h"
5 #include "tao/RTScheduling/RTScheduler_Manager.h"
6 #include "FP_Scheduler.h"
7 #include "Task_Stats.h"
9 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
12 int enable_dynamic_scheduling
= 0;
13 const CORBA::Short max_importance
= 100;
17 parse_args (int argc
, ACE_TCHAR
*argv
[])
19 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:n:ds"));
22 while ((c
= get_opts ()) != -1)
26 ior_output_file
= get_opts
.opt_arg ();
30 nthreads
= ACE_OS::atoi (get_opts
.opt_arg ());
34 enable_dynamic_scheduling
= 1;
43 ACE_ERROR_RETURN ((LM_ERROR
,
46 "-d (enable dynamic scheduling)"
52 // Indicates successful parsing of the command line
59 * Use the ACE_Task_Base class to run server threads
61 class Worker
: public ACE_Task_Base
64 Worker (CORBA::ORB_ptr orb
);
68 // The thread entry point.
75 Task_Stats task_stats
;
78 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
80 Fixed_Priority_Scheduler
* scheduler
=0;
81 RTScheduling::Current_var current
;
83 int sched_policy
= ACE_SCHED_RR
;
84 int sched_scope
= ACE_SCOPE_THREAD
;
86 if (sched_policy
== ACE_SCHED_RR
)
87 flags
= THR_NEW_LWP
| THR_BOUND
| THR_JOINABLE
| THR_SCHED_RR
;
89 flags
= THR_NEW_LWP
| THR_BOUND
| THR_JOINABLE
| THR_SCHED_FIFO
;
91 task_stats
.init (100000);
95 RTScheduling::Scheduler_var sched_owner
;
98 CORBA::ORB_init (argc
, argv
);
100 CORBA::Object_var poa_object
=
101 orb
->resolve_initial_references("RootPOA");
103 if (CORBA::is_nil (poa_object
.in ()))
104 ACE_ERROR_RETURN ((LM_ERROR
,
105 " (%P|%t) Unable to initialize the POA.\n"),
108 PortableServer::POA_var root_poa
=
109 PortableServer::POA::_narrow (poa_object
.in ());
111 PortableServer::POAManager_var poa_manager
=
112 root_poa
->the_POAManager ();
114 if (parse_args (argc
, argv
) != 0)
117 if (enable_dynamic_scheduling
)
119 CORBA::Object_var manager_obj
=
120 orb
->resolve_initial_references ("RTSchedulerManager");
122 TAO_RTScheduler_Manager_var manager
=
123 TAO_RTScheduler_Manager::_narrow (manager_obj
.in ());
125 Kokyu::DSRT_Dispatcher_Impl_t disp_impl_type
;
128 disp_impl_type
= Kokyu::DSRT_CV_BASED
;
132 disp_impl_type
= Kokyu::DSRT_OS_BASED
;
135 ACE_NEW_RETURN (scheduler
,
136 Fixed_Priority_Scheduler (orb
.in (),
140 sched_owner
= scheduler
;
142 manager
->rtscheduler (scheduler
);
144 CORBA::Object_var object
=
145 orb
->resolve_initial_references ("RTScheduler_Current");
148 RTScheduling::Current::_narrow (object
.in ());
151 Simple_Server_i
server_impl (orb
.in (),
156 Simple_Server_var server
=
157 server_impl
._this ();
159 CORBA::String_var ior
=
160 orb
->object_to_string (server
.in ());
162 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
164 // If the ior_output_file exists, output the ior to it
165 if (ior_output_file
!= 0)
167 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
168 if (output_file
== 0)
169 ACE_ERROR_RETURN ((LM_ERROR
,
170 "Cannot open output file for writing IOR: %s",
173 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
174 ACE_OS::fclose (output_file
);
177 poa_manager
->activate ();
179 Worker
worker (orb
.in ());
180 if (worker
.activate (flags
,
183 ACE_Sched_Params::priority_max(sched_policy
,
186 ACE_ERROR ((LM_ERROR
,
187 "Cannot activate threads in RT class.",
188 "Trying to activate in non-RT class\n"));
190 flags
= THR_NEW_LWP
| THR_JOINABLE
| THR_BOUND
;
191 if (worker
.activate (flags
, nthreads
) != 0)
193 ACE_ERROR_RETURN ((LM_ERROR
,
194 "Cannot activate server threads\n"),
201 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
203 ACE_DEBUG ((LM_DEBUG
, "shutting down scheduler\n"));
204 scheduler
->shutdown ();
208 catch (const CORBA::Exception
& ex
)
210 ex
._tao_print_exception ("Exception caught:");
214 ACE_DEBUG ((LM_DEBUG
, "Exiting main...\n"));
215 task_stats
.dump_samples (ACE_TEXT("timeline.txt"),
216 ACE_TEXT("Time\t\tGUID"));
220 // ****************************************************************
222 Worker::Worker (CORBA::ORB_ptr orb
)
223 : orb_ (CORBA::ORB::_duplicate (orb
))
230 ACE_Time_Value
tv(120);
234 this->orb_
->run (tv
);
236 catch (const CORBA::Exception
&)
239 ACE_DEBUG ((LM_DEBUG
, "(%t|%T): Worker thread exiting...\n"));