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 "FP_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 Fixed_Priority_Scheduler
* scheduler
,
27 CORBA::Short importance
,
28 CORBA::Long server_load
);
33 // The thread entry point.
39 Simple_Server_var server_
;
40 RTScheduling::Current_var scheduler_current_
;
41 Fixed_Priority_Scheduler
* scheduler_
;
42 RTCORBA::Priority prio_
;
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 Fixed_Priority_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 Fixed_Priority_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 ());
196 Worker
worker1 (orb
.in (),
201 if (worker1
.activate (flags
, 1, 0, max_prio
) != 0)
203 ACE_ERROR ((LM_ERROR
,
204 "(%t|%T) cannot activate worker thread.\n"));
209 Worker
worker2 (orb
.in (),
214 if (worker2
.activate (flags
, 1, 0, max_prio
) != 0)
216 ACE_ERROR ((LM_ERROR
,
217 "(%t|%T) cannot activate scheduler thread in RT mode.\n"));
223 ACE_DEBUG ((LM_DEBUG
,
224 "(%t): wait for worker threads done in main thread\n"));
228 if (enable_dynamic_scheduling
)
230 FP_Scheduling::SegmentSchedulingParameter sched_param
;
231 sched_param
.base_priority
= 0;
232 CORBA::Policy_var sched_param_policy
233 = scheduler
->create_segment_scheduling_parameter (sched_param
);
234 CORBA::Policy_ptr implicit_sched_param
= 0;
235 current
->begin_scheduling_segment (0,
236 sched_param_policy
.in (),
237 implicit_sched_param
);
240 ACE_DEBUG ((LM_DEBUG
, "(%t): about to call server shutdown\n"));
243 ACE_DEBUG ((LM_DEBUG
, "after shutdown call in main thread\n"));
246 if (enable_dynamic_scheduling
)
248 current
->end_scheduling_segment (0);
252 scheduler
->shutdown ();
253 ACE_DEBUG ((LM_DEBUG
, "scheduler shutdown done\n"));
257 catch (const CORBA::Exception
& ex
)
259 ex
._tao_print_exception ("Exception caught:");
266 // ****************************************************************
268 Worker::Worker (CORBA::ORB_ptr orb
,
269 Simple_Server_ptr server_ptr
,
270 RTScheduling::Current_ptr current
,
271 Fixed_Priority_Scheduler
* scheduler
,
272 RTCORBA::Priority prio
,
273 CORBA::Long server_load
)
275 : orb_ (CORBA::ORB::_duplicate (orb
)),
276 server_ (Simple_Server::_duplicate (server_ptr
)),
277 scheduler_current_ (RTScheduling::Current::_duplicate (current
)),
278 scheduler_ (scheduler
),
280 server_load_ (server_load
)
281 // sleep_time_ (sleep_time)
288 const char * name
= 0;
290 ACE_DEBUG ((LM_DEBUG, "(%t|%T):about to sleep for %d sec\n", sleep_time_));
291 ACE_OS::sleep (sleep_time_);
292 ACE_DEBUG ((LM_DEBUG, "(%t|%T):woke up from sleep for %d sec\n", sleep_time_));
294 ACE_hthread_t thr_handle
;
295 ACE_Thread::self (thr_handle
);
298 if (ACE_Thread::getprio (thr_handle
, prio
) == -1)
300 if (errno
== ENOTSUP
)
303 ACE_TEXT ("getprio not supported\n")));
307 ACE_ERROR ((LM_ERROR
,
309 ACE_TEXT ("thr_getprio failed")));
313 ACE_DEBUG ((LM_DEBUG
, "(%t|%T) worker activated with prio %d\n", prio
));
315 if (enable_dynamic_scheduling
)
317 FP_Scheduling::SegmentSchedulingParameter sched_param
;
318 sched_param
.base_priority
= prio_
;
319 CORBA::Policy_var sched_param_policy
320 = scheduler_
->create_segment_scheduling_parameter (sched_param
);
322 CORBA::Policy_ptr implicit_sched_param
= 0;
323 ACE_DEBUG ((LM_DEBUG
, "(%t|%T):before begin_sched_segment\n"));
324 scheduler_current_
->begin_scheduling_segment (name
,
325 sched_param_policy
.in (),
326 implicit_sched_param
);
328 ACE_DEBUG ((LM_DEBUG
, "(%t|%T):after begin_sched_segment\n"));
331 ACE_DEBUG ((LM_DEBUG
, "(%t|%T):about to make two way call\n"));
332 server_
->test_method (server_load_
);
334 ACE_DEBUG ((LM_DEBUG
, "(%t|%T):two way call done\n"));
336 if (enable_dynamic_scheduling
)
338 scheduler_current_
->end_scheduling_segment (name
);
341 ACE_DEBUG ((LM_DEBUG
, "client worker thread (%t) done\n"));