Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Sched_Conf / Sched_Conf.cpp
blobd29a5967756acf15cc7e34f3117ea1f4c349e588
1 // This program performa a simple scheduler configuration run,
2 // and dumps the results of one scheduling into a C++ header file.
4 #include "ace/Sched_Params.h"
5 #include "ace/Get_Opt.h"
7 #include "orbsvcs/CosNamingC.h"
8 #include "orbsvcs/Scheduler_Factory.h"
9 #include "orbsvcs/Naming/Naming_Client.h"
10 #include "orbsvcs/Naming/Naming_Server.h"
12 const ACE_TCHAR *service_name = ACE_TEXT("ScheduleService");
14 const char* format_string = " {%-12s, %d, %d, %d, %d, %8d, "
15 " static_cast<RtecScheduler::Criticality_t> (%d), "
16 " static_cast<RtecScheduler::Importance_t> (%d), "
17 " %d, %d, %3d, %d, %d, "
18 "static_cast<RtecScheduler::Info_Type_t> (%d)}\n";
20 int
21 parse_args (int argc, ACE_TCHAR *argv [])
23 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("n:"));
24 int opt;
26 while ((opt = get_opt ()) != EOF)
28 switch (opt)
30 case 'n':
31 service_name = get_opt.opt_arg ();
32 break;
33 case '?':
34 default:
35 ACE_DEBUG ((LM_DEBUG,
36 "Usage: %s "
37 "-n service_name "
38 "\n",
39 argv[0]));
40 return -1;
44 return 0;
47 int
48 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
50 if (parse_args (argc, argv) != 0)
52 return 1;
55 // create initial data for supplier and consumer operations
56 const int operation_count = 16;
57 ACE_Scheduler_Factory::POD_RT_Info config_infos[operation_count] = {
58 // 20 Hz high criticality supplier
59 { "high_20_S", // entry point
60 0, // handle
61 5000, // worst case execution time
62 5000, // typical execution time (unused)
63 5000, // cached execution time
64 500000, // period (100 ns)
65 RtecScheduler::HIGH_CRITICALITY, // criticality
66 RtecScheduler::LOW_IMPORTANCE, // importance
67 0, // quantum (unused)
68 1, // threads
69 0, // OS priority
70 0, // Preemption subpriority
71 0, // Preemption priority
72 RtecScheduler::OPERATION, // info type
73 RtecScheduler::RT_INFO_ENABLED
75 // 20 Hz low criticality supplier
76 { "low_20_S", // entry point
77 0, // handle
78 5000, // worst case execution time
79 5000, // typical execution time (unused)
80 5000, // cached execution time
81 500000, // period (100 ns)
82 RtecScheduler::LOW_CRITICALITY, // criticality
83 RtecScheduler::HIGH_IMPORTANCE, // importance
84 0, // quantum (unused)
85 1, // threads
86 0, // OS priority
87 0, // Preemption subpriority
88 0, // Preemption priority
89 RtecScheduler::OPERATION, // info type
90 RtecScheduler::RT_INFO_ENABLED
92 // 10 Hz high criticality supplier
93 { "high_10_S", // entry point
94 0, // handle
95 10000, // worst case execution time
96 10000, // typical execution time (unused)
97 10000, // cached execution time
98 1000000, // period (100 ns)
99 RtecScheduler::HIGH_CRITICALITY, // criticality
100 RtecScheduler::LOW_IMPORTANCE, // importance
101 0, // quantum (unused)
102 1, // threads
103 0, // OS priority
104 0, // Preemption subpriority
105 0, // Preemption priority
106 RtecScheduler::OPERATION, // info type
107 RtecScheduler::RT_INFO_ENABLED
109 // 10 Hz low criticality supplier
110 { "low_10_S", // entry point
111 0, // handle
112 10000, // worst case execution time
113 10000, // typical execution time (unused)
114 10000, // cached execution time
115 1000000, // period (100 ns)
116 RtecScheduler::LOW_CRITICALITY, // criticality
117 RtecScheduler::HIGH_IMPORTANCE, // importance
118 0, // quantum (unused)
119 1, // threads
120 0, // OS priority
121 0, // Preemption subpriority
122 0, // Preemption priority
123 RtecScheduler::OPERATION, // info type
124 RtecScheduler::RT_INFO_ENABLED
126 // 5 Hz high criticality supplier
127 { "high_05_S", // entry point
128 0, // handle
129 20000, // worst case execution time
130 20000, // typical execution time (unused)
131 20000, // cached execution time
132 2000000, // period (100 ns)
133 RtecScheduler::HIGH_CRITICALITY, // criticality
134 RtecScheduler::LOW_IMPORTANCE, // importance
135 0, // quantum (unused)
136 1, // threads
137 0, // OS priority
138 0, // Preemption subpriority
139 0, // Preemption priority
140 RtecScheduler::OPERATION, // info type
141 RtecScheduler::RT_INFO_ENABLED
143 // 5 Hz low criticality supplier
144 { "low_05_S", // entry point
145 0, // handle
146 20000, // worst case execution time
147 20000, // typical execution time (unused)
148 20000, // cached execution time
149 2000000, // period (100 ns)
150 RtecScheduler::LOW_CRITICALITY, // criticality
151 RtecScheduler::HIGH_IMPORTANCE, // importance
152 0, // quantum (unused)
153 1, // threads
154 0, // OS priority
155 0, // Preemption subpriority
156 0, // Preemption priority
157 RtecScheduler::OPERATION, // info type
158 RtecScheduler:: RT_INFO_ENABLED
160 // 1 Hz high criticality supplier (declares a rate but no threads)
161 { "high_01_S", // entry point
162 0, // handle
163 100000, // worst case execution time
164 100000, // typical execution time (unused)
165 100000, // cached execution time
166 10000000, // period (100 ns)
167 RtecScheduler::HIGH_CRITICALITY, // criticality
168 RtecScheduler::LOW_IMPORTANCE, // importance
169 0, // quantum (unused)
170 0, // threads
171 0, // OS priority
172 0, // Preemption subpriority
173 0, // Preemption priority
174 RtecScheduler::OPERATION, // info type
175 RtecScheduler::RT_INFO_ENABLED
177 // 1 Hz low criticality supplier (remote dependant: scheduler should warn)
178 { "low_01_S", // entry point
179 0, // handle
180 100000, // worst case execution time
181 100000, // typical execution time (unused)
182 100000, // cached execution time
183 10000000, // period (100 ns)
184 RtecScheduler::LOW_CRITICALITY, // criticality
185 RtecScheduler::HIGH_IMPORTANCE, // importance
186 0, // quantum (unused)
187 0, // threads
188 0, // OS priority
189 0, // Preemption subpriority
190 0, // Preemption priority
191 RtecScheduler::OPERATION, // info type
192 RtecScheduler::RT_INFO_ENABLED
194 // 20 Hz high criticality consumer
195 { "high_20_C", // entry point
196 0, // handle
197 0, // worst case execution time
198 0, // typical execution time (unused)
199 0, // cached execution time
200 0, // period (zero)
201 RtecScheduler::HIGH_CRITICALITY, // criticality
202 RtecScheduler::LOW_IMPORTANCE, // importance
203 0, // quantum (unused)
204 0, // threads
205 0, // OS priority
206 0, // Preemption subpriority
207 0, // Preemption priority
208 RtecScheduler::OPERATION, // info type
209 RtecScheduler::RT_INFO_ENABLED
211 // 20 Hz low criticality consumer
212 { "low_20_C", // entry point
213 0, // handle
214 0, // worst case execution time
215 0, // typical execution time (unused)
216 0, // cached execution time
217 0, // period (zero)
218 RtecScheduler::LOW_CRITICALITY, // criticality
219 RtecScheduler::HIGH_IMPORTANCE, // importance
220 0, // quantum (unused)
221 0, // threads
222 0, // OS priority
223 0, // Preemption subpriority
224 0, // Preemption priority
225 RtecScheduler::OPERATION, // info type
226 RtecScheduler::RT_INFO_ENABLED
228 // 10 Hz high criticality consumer
229 { "high_10_C", // entry point
230 0, // handle
231 0, // worst case execution time
232 0, // typical execution time (unused)
233 0, // cached execution time
234 0, // period (zero)
235 RtecScheduler::HIGH_CRITICALITY, // criticality
236 RtecScheduler::LOW_IMPORTANCE, // importance
237 0, // quantum (unused)
238 0, // threads
239 0, // OS priority
240 0, // Preemption subpriority
241 0, // Preemption priority
242 RtecScheduler::OPERATION, // info type
243 RtecScheduler::RT_INFO_ENABLED
245 // 10 Hz low criticality consumer
246 { "low_10_C", // entry point
247 0, // handle
248 0, // worst case execution time
249 0, // typical execution time (unused)
250 0, // cached execution time
251 0, // period (zero)
252 RtecScheduler::LOW_CRITICALITY, // criticality
253 RtecScheduler::HIGH_IMPORTANCE, // importance
254 0, // quantum (unused)
255 0, // threads
256 0, // OS priority
257 0, // Preemption subpriority
258 0, // Preemption priority
259 RtecScheduler::OPERATION, // info type
260 RtecScheduler::RT_INFO_ENABLED
262 // 5 Hz high criticality consumer
263 { "high_05_C", // entry point
264 0, // handle
265 0, // worst case execution time
266 0, // typical execution time (unused)
267 0, // cached execution time
268 0, // period (zero)
269 RtecScheduler::HIGH_CRITICALITY, // criticality
270 RtecScheduler::LOW_IMPORTANCE, // importance
271 0, // quantum (unused)
272 0, // threads
273 0, // OS priority
274 0, // Preemption subpriority
275 0, // Preemption priority
276 RtecScheduler::OPERATION, // info type
277 RtecScheduler::RT_INFO_ENABLED
279 // 5 Hz low criticality consumer
280 { "low_05_C", // entry point
281 0, // handle
282 0, // worst case execution time
283 0, // typical execution time (unused)
284 0, // cached execution time
285 0, // period (zero)
286 RtecScheduler::LOW_CRITICALITY, // criticality
287 RtecScheduler::HIGH_IMPORTANCE, // importance
288 0, // quantum (unused)
289 0, // threads
290 0, // OS priority
291 0, // Preemption subpriority
292 0, // Preemption priority
293 RtecScheduler::OPERATION, // info type
294 RtecScheduler::RT_INFO_ENABLED
296 // 1 Hz high criticality consumer
297 { "high_01_C", // entry point
298 0, // handle
299 0, // worst case execution time
300 0, // typical execution time (unused)
301 0, // cached execution time
302 0, // period (zero)
303 RtecScheduler::HIGH_CRITICALITY, // criticality
304 RtecScheduler::LOW_IMPORTANCE, // importance
305 0, // quantum (unused)
306 0, // threads
307 0, // OS priority
308 0, // Preemption subpriority
309 0, // Preemption priority
310 RtecScheduler::OPERATION, // info type
311 RtecScheduler::RT_INFO_ENABLED
313 // 1 Hz low criticality consumer
314 { "low_01_C", // entry point
315 0, // handle
316 0, // worst case execution time
317 0, // typical execution time (unused)
318 0, // cached execution time
319 0, // period (zero)
320 RtecScheduler::LOW_CRITICALITY, // criticality
321 RtecScheduler::HIGH_IMPORTANCE, // importance
322 0, // quantum (unused)
323 0, // threads
324 0, // OS priority
325 0, // Preemption subpriority
326 0, // Preemption priority
327 RtecScheduler::OPERATION, // info type
328 RtecScheduler::RT_INFO_ENABLED
335 // Initialize ORB.
336 CORBA::ORB_var orb =
337 CORBA::ORB_init (argc, argv, "internet");
339 CORBA::Object_var poa_object =
340 orb->resolve_initial_references("RootPOA");
342 if (CORBA::is_nil(poa_object.in ()))
343 ACE_ERROR_RETURN ((LM_ERROR,
344 " (%P|%t) Unable to initialize the POA.\n"),
347 PortableServer::POA_var root_poa =
348 PortableServer::POA::_narrow (poa_object.in());
350 PortableServer::POAManager_var poa_manager =
351 root_poa->the_POAManager ();
353 poa_manager->activate ();
355 // Initialize the naming services
356 TAO_Naming_Client my_name_client;
357 if (my_name_client.init (orb.in ()) != 0)
358 ACE_ERROR_RETURN ((LM_ERROR,
359 " (%P|%t) Unable to initialize "
360 "the TAO_Naming_Client.\n"),
361 -1);
363 CosNaming::NamingContext_var context =
364 my_name_client.get_context ();
366 if (ACE_Scheduler_Factory::use_config (context.in (),
367 ACE_TEXT_ALWAYS_CHAR(service_name)) < 0)
368 ACE_ERROR_RETURN ((LM_ERROR,
369 " (%P|%t) Unable to bind to the scheduling service.\n"),
372 // Create and initialize RT_Infos in the scheduler, make second
373 // half of array depend on first half.
374 for (int i = 0; i < operation_count; ++i)
376 // create the RT_Info
377 config_infos[i].handle =
378 ACE_Scheduler_Factory::server ()->create (config_infos[i].entry_point);
380 // initialize the RT_Info
381 ACE_Scheduler_Factory::server ()->
382 set (config_infos[i].handle,
383 static_cast<RtecScheduler::Criticality_t> (config_infos[i].criticality),
384 config_infos[i].worst_case_execution_time,
385 config_infos[i].typical_execution_time,
386 config_infos[i].cached_execution_time,
387 config_infos[i].period,
388 static_cast<RtecScheduler::Importance_t> (config_infos[i].importance),
389 config_infos[i].quantum,
390 config_infos[i].threads,
391 static_cast<RtecScheduler::Info_Type_t> (config_infos[i].info_type));
393 // make operations in second half dependant on
394 // operations in the first half of the array,
395 // and have each called twice as a oneway call
396 if (i >= (operation_count / 2))
398 ACE_Scheduler_Factory::server ()->
399 add_dependency (config_infos[i].handle,
400 config_infos[i - (operation_count / 2)].handle,
401 2, // number of calls
402 RtecBase::ONE_WAY_CALL // type of dependency
407 RtecScheduler::RT_Info_Set_var infos;
408 RtecScheduler::Dependency_Set_var deps;
409 RtecScheduler::Config_Info_Set_var configs;
410 RtecScheduler::Scheduling_Anomaly_Set_var anomalies;
412 ACE_Scheduler_Factory::server ()->compute_scheduling
413 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO,
414 ACE_SCOPE_THREAD),
415 ACE_Sched_Params::priority_max (ACE_SCHED_FIFO,
416 ACE_SCOPE_THREAD),
417 infos.out (), deps.out (), configs.out (), anomalies.out ());
420 ACE_Scheduler_Factory::dump_schedule (infos.in (),
421 deps.in (),
422 configs.in (),
423 anomalies.in (),
424 ACE_TEXT("Sched_Conf_Runtime.h"),
425 format_string);
427 catch (const CORBA::Exception& ex)
429 ex._tao_print_exception ("SYS_EX");
432 return 0;