1 #include "ace/Get_Opt.h"
3 #include "ace/High_Res_Timer.h"
4 #include "ace/OS_NS_unistd.h"
5 #include "tao/RTScheduling/RTScheduler_Manager.h"
7 #include "MIF_Scheduler.h"
9 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
12 int enable_dynamic_scheduling
= 0;
18 * Use the ACE_Task_Base class to run server threads
20 class Worker
: public ACE_Task_Base
23 Worker (CORBA::ORB_ptr orb
,
24 Simple_Server_ptr server_ptr
,
25 RTScheduling::Current_ptr current
,
26 MIF_Scheduler
* scheduler
,
27 CORBA::Short importance
,
28 CORBA::Long server_load
);
32 virtual int svc (void);
33 // The thread entry point.
39 Simple_Server_var server_
;
40 RTScheduling::Current_var scheduler_current_
;
41 MIF_Scheduler
* scheduler_
;
42 CORBA::Short importance_
;
43 CORBA::Long server_load_
;
48 parse_args (int argc
, ACE_TCHAR
*argv
[])
50 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("xk:i:ds"));
53 while ((c
= get_opts ()) != -1)
61 ior
= get_opts
.opt_arg ();
65 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
69 enable_dynamic_scheduling
= 1;
78 ACE_ERROR_RETURN ((LM_ERROR
,
82 "-d (enable dynamic scheduling)"
88 // Indicates successful parsing of the command line
93 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
95 MIF_Scheduler
* scheduler
=0;
96 RTScheduling::Current_var current
;
99 ACE_Sched_Params::Policy sched_policy
= ACE_SCHED_RR
;
100 int sched_scope
= ACE_SCOPE_THREAD
;
103 if (sched_policy
== ACE_SCHED_RR
)
104 flags
= THR_NEW_LWP
| THR_BOUND
| THR_JOINABLE
| THR_SCHED_RR
;
106 flags
= THR_NEW_LWP
| THR_BOUND
| THR_JOINABLE
| THR_SCHED_FIFO
;
108 ACE_hthread_t main_thr_handle
;
109 ACE_Thread::self (main_thr_handle
);
111 max_prio
= ACE_Sched_Params::priority_max (sched_policy
,
114 //FUZZ: disable check_for_lack_ACE_OS
115 ACE_Sched_Params
sched_params (sched_policy
, max_prio
);
116 //FUZZ: enable check_for_lack_ACE_OS
118 ACE_OS::sched_params (sched_params
);
120 if (ACE_Thread::getprio (main_thr_handle
, prio
) == -1)
122 if (errno
== ENOTSUP
)
125 ACE_TEXT ("getprio not supported\n")));
129 ACE_ERROR ((LM_ERROR
,
131 ACE_TEXT ("thr_getprio failed")));
135 ACE_DEBUG ((LM_DEBUG
, "(%t): main thread prio is %d\n", prio
));
139 RTScheduling::Scheduler_var sched_owner
;
142 CORBA::ORB_init (argc
, argv
);
144 if (parse_args (argc
, argv
) != 0)
147 CORBA::Object_var object
=
148 orb
->string_to_object (ior
);
150 Simple_Server_var server
=
151 Simple_Server::_narrow (object
.in ());
153 if (CORBA::is_nil (server
.in ()))
155 ACE_ERROR_RETURN ((LM_ERROR
,
156 "Object reference <%s> is nil.\n",
161 if (enable_dynamic_scheduling
)
163 ACE_DEBUG ((LM_DEBUG
, "Dyn Sched enabled\n"));
164 CORBA::Object_var manager_obj
=
165 orb
->resolve_initial_references ("RTSchedulerManager");
167 TAO_RTScheduler_Manager_var manager
=
168 TAO_RTScheduler_Manager::_narrow (manager_obj
.in ());
170 Kokyu::DSRT_Dispatcher_Impl_t disp_impl_type
;
173 disp_impl_type
= Kokyu::DSRT_CV_BASED
;
177 disp_impl_type
= Kokyu::DSRT_OS_BASED
;
180 ACE_NEW_RETURN (scheduler
,
181 MIF_Scheduler (orb
.in (),
185 sched_owner
= scheduler
;
187 manager
->rtscheduler (scheduler
);
189 CORBA::Object_var object
=
190 orb
->resolve_initial_references ("RTScheduler_Current");
193 RTScheduling::Current::_narrow (object
.in ());
197 Worker
worker1 (orb
.in (), server
.in (), current
.in (), scheduler
, 10, 15);
199 if (worker1
.activate (flags
, 1, 0, max_prio
) != 0)
201 ACE_ERROR ((LM_ERROR
,
202 "(%t|%T) cannot activate worker thread.\n"));
207 Worker
worker2 (orb
.in (), server
.in (), current
.in (), scheduler
, 12, 5);
209 if (worker2
.activate (flags
, 1, 0, max_prio
) != 0)
211 ACE_ERROR ((LM_ERROR
,
212 "(%t|%T) cannot activate scheduler thread in RT mode.\n"));
218 ACE_DEBUG ((LM_DEBUG
,
219 "(%t): wait for worker threads done in main thread\n"));
223 if (enable_dynamic_scheduling
)
225 MIF_Scheduling::SchedulingParameter sched_param
;
226 sched_param
.importance
= 0;
227 CORBA::Policy_var sched_param_policy
=
228 scheduler
->create_scheduling_parameter (sched_param
);
229 CORBA::Policy_ptr implicit_sched_param
= 0;
230 current
->begin_scheduling_segment (0,
231 sched_param_policy
.in (),
232 implicit_sched_param
);
235 ACE_DEBUG ((LM_DEBUG
, "(%t): about to call server shutdown\n"));
238 ACE_DEBUG ((LM_DEBUG
, "after shutdown call in main thread\n"));
241 if (enable_dynamic_scheduling
)
243 current
->end_scheduling_segment (0);
247 scheduler
->shutdown ();
248 ACE_DEBUG ((LM_DEBUG
, "scheduler shutdown done\n"));
252 catch (const CORBA::Exception
& ex
)
254 ex
._tao_print_exception ("Exception caught:");
261 // ****************************************************************
263 Worker::Worker (CORBA::ORB_ptr orb
,
264 Simple_Server_ptr server_ptr
,
265 RTScheduling::Current_ptr current
,
266 MIF_Scheduler
* scheduler
,
267 CORBA::Short importance
,
268 CORBA::Long server_load
)
270 : orb_ (CORBA::ORB::_duplicate (orb
)),
271 server_ (Simple_Server::_duplicate (server_ptr
)),
272 scheduler_current_ (RTScheduling::Current::_duplicate (current
)),
273 scheduler_ (scheduler
),
274 importance_ (importance
),
275 server_load_ (server_load
)
276 // sleep_time_ (sleep_time)
283 const char * name
= 0;
285 ACE_DEBUG ((LM_DEBUG, "(%t|%T):about to sleep for %d sec\n", sleep_time_));
286 ACE_OS::sleep (sleep_time_);
287 ACE_DEBUG ((LM_DEBUG, "(%t|%T):woke up from sleep for %d sec\n", sleep_time_));
289 ACE_hthread_t thr_handle
;
290 ACE_Thread::self (thr_handle
);
293 if (ACE_Thread::getprio (thr_handle
, prio
) == -1)
295 if (errno
== ENOTSUP
)
298 ACE_TEXT ("getprio not supported\n")));
302 ACE_ERROR ((LM_ERROR
,
304 ACE_TEXT ("thr_getprio failed")));
308 ACE_DEBUG ((LM_DEBUG
, "(%t|%T) worker activated with prio %d\n", prio
));
310 if (enable_dynamic_scheduling
)
312 MIF_Scheduling::SchedulingParameter sched_param
;
313 CORBA::Policy_var sched_param_policy
;
314 sched_param
.importance
= importance_
;
315 sched_param_policy
= scheduler_
->create_scheduling_parameter (sched_param
);
316 CORBA::Policy_ptr implicit_sched_param
= 0;
317 ACE_DEBUG ((LM_DEBUG
, "(%t|%T):before begin_sched_segment\n"));
318 scheduler_current_
->begin_scheduling_segment (name
,
319 sched_param_policy
.in (),
320 implicit_sched_param
);
321 ACE_DEBUG ((LM_DEBUG
, "(%t|%T):after begin_sched_segment\n"));
324 ACE_DEBUG ((LM_DEBUG
, "(%t|%T):about to make two way call\n"));
325 server_
->test_method (server_load_
);
326 ACE_DEBUG ((LM_DEBUG
, "(%t|%T):two way call done\n"));
328 if (enable_dynamic_scheduling
)
330 scheduler_current_
->end_scheduling_segment (name
);
333 ACE_DEBUG ((LM_DEBUG
, "client worker thread (%t) done\n"));