1 #include "orbsvcs/Sched/Strategy_Scheduler.h"
2 #include "orbsvcs/Time_Utilities.h"
3 #if defined (ACE_HAS_QUANTIFY)
5 #endif /* ACE_HAS_QUANTIFY */
7 // period times, in 100 nanoseconds
8 #define ONE_HZ 10000000
9 #define FIVE_HZ 2000000
10 #define TEN_HZ 1000000
11 #define TWENTY_HZ 500000
15 // DynSched Test wrapper
17 // Wraps static functions for test
20 static void setup_rt_info (RtecScheduler::RT_Info
&info
,
21 const char *entry_point
,
23 RtecScheduler::Time execution
,
24 RtecScheduler::Criticality_t criticality
,
25 RtecScheduler::Importance_t importance
,
27 // Initializes an RT_Info.
29 static int register_rt_info (ACE_DynScheduler
&scheduler
,
30 RtecScheduler::RT_Info
&info
);
31 // Registers an RT_Info.
34 #if 0 /* not currently used */
35 static void setup_conjunction (RtecScheduler::RT_Info
&info
,
36 const char *entry_point
);
37 // Sets up a conjunction.
39 static void setup_disjunction (RtecScheduler::RT_Info
&info
,
40 const char *entry_point
);
41 // Sets up a disjunction.
43 #endif /* not currently used */
45 static int run_schedule (ACE_Scheduler_Strategy
&strategy
,
46 const char *output_filename
,
48 // Creates the schedule, runs timelines.
52 // Initializes an RT_Info.
55 DynSched_Test::setup_rt_info (RtecScheduler::RT_Info
&info
,
56 const char *entry_point
,
58 RtecScheduler::Time execution
,
59 RtecScheduler::Criticality_t criticality
,
60 RtecScheduler::Importance_t importance
,
63 // copy the passed entry point string into the RT_Info
64 info
.entry_point
= CORBA::string_dup (entry_point
);
66 // initialize other values
68 info
.worst_case_execution_time
= execution
;
69 info
.typical_execution_time
= execution
;
70 info
.cached_execution_time
= ORBSVCS_Time::zero ();
72 info
.criticality
= criticality
;
73 info
.importance
= importance
;
74 info
.quantum
= ORBSVCS_Time::zero ();
75 info
.threads
= threads
;
77 info
.preemption_subpriority
= 0;
78 info
.preemption_priority
= 0;
79 info
.info_type
= RtecScheduler::OPERATION
;
80 info
.volatile_token
= 0;
84 // Registers an RT_Info.
87 DynSched_Test::register_rt_info (ACE_DynScheduler
&scheduler
,
88 RtecScheduler::RT_Info
&info
)
92 if (scheduler
.register_task (&info
, info
.handle
) !=
93 ACE_DynScheduler::SUCCEEDED
)
96 ACE_OS::printf ("Could not register info for \"%s\"\n", info
.entry_point
.in ());
102 #if 0 /* not currently used */
104 // Sets up a conjunction.
107 DynSched_Test::setup_conjunction (RtecScheduler::RT_Info
&info
,
108 const char *entry_point
)
110 // copy the passed entry point string into the RT_Info
111 info
.entry_point
= CORBA::string_dup (entry_point
);
113 // initialize other values
115 info
.worst_case_execution_time
= ORBSVCS_Time::zero ();
116 info
.typical_execution_time
= ORBSVCS_Time::zero ();
117 info
.cached_execution_time
= ORBSVCS_Time::zero ();
119 info
.criticality
= RtecScheduler::VERY_LOW_CRITICALITY
;
120 info
.importance
= RtecScheduler::VERY_LOW_IMPORTANCE
;
121 info
.quantum
= ORBSVCS_Time::zero ();
124 info
.preemption_subpriority
= 0;
125 info
.preemption_priority
= 0;
126 info
.info_type
= RtecScheduler::CONJUNCTION
;
127 info
.volatile_token
= 0;
131 // Sets up a disjunction.
134 DynSched_Test::setup_disjunction (RtecScheduler::RT_Info
&info
,
135 const char *entry_point
)
137 // copy the passed entry point string into the RT_Info
138 info
.entry_point
= CORBA::string_dup (entry_point
);
140 // initialize other values
142 info
.worst_case_execution_time
= ORBSVCS_Time::zero ();
143 info
.typical_execution_time
= ORBSVCS_Time::zero ();
144 info
.cached_execution_time
= ORBSVCS_Time::zero ();
146 info
.criticality
= RtecScheduler::VERY_LOW_CRITICALITY
;
147 info
.importance
= RtecScheduler::VERY_LOW_IMPORTANCE
;
148 info
.quantum
= ORBSVCS_Time::zero ();
151 info
.preemption_subpriority
= 0;
152 info
.preemption_priority
= 0;
153 info
.info_type
= RtecScheduler::DISJUNCTION
;
154 info
.volatile_token
= 0;
156 #endif /* not currently used */
159 // Creates the schedule, runs timelines.
162 DynSched_Test::run_schedule (ACE_Scheduler_Strategy
&strategy
,
163 const char *output_filename
,
166 RtecScheduler::RT_Info low_1
, low_5
, low_10
, low_20
;
167 RtecScheduler::RT_Info high_1
, high_5
, high_10
, high_20
;
169 ACE_Strategy_Scheduler
scheduler (strategy
);
171 DynSched_Test::setup_rt_info (low_1
, "low_1", ONE_HZ
, 180000,
172 RtecScheduler::LOW_CRITICALITY
,
173 RtecScheduler::HIGH_IMPORTANCE
, 1);
174 DynSched_Test::setup_rt_info (low_5
, "low_5", FIVE_HZ
, 180000,
175 RtecScheduler::LOW_CRITICALITY
,
176 RtecScheduler::HIGH_IMPORTANCE
, 1);
177 DynSched_Test::setup_rt_info (low_10
, "low_10", TEN_HZ
, 180000,
178 RtecScheduler::LOW_CRITICALITY
,
179 RtecScheduler::HIGH_IMPORTANCE
, 1);
180 DynSched_Test::setup_rt_info (low_20
, "low_20", TWENTY_HZ
, 180000,
181 RtecScheduler::LOW_CRITICALITY
,
182 RtecScheduler::HIGH_IMPORTANCE
, 1);
183 DynSched_Test::setup_rt_info (high_1
, "high_1", ONE_HZ
, 180000,
184 RtecScheduler::HIGH_CRITICALITY
,
185 RtecScheduler::LOW_IMPORTANCE
, 1);
186 DynSched_Test::setup_rt_info (high_5
, "high_5", FIVE_HZ
, 180000,
187 RtecScheduler::HIGH_CRITICALITY
,
188 RtecScheduler::LOW_IMPORTANCE
, 1);
189 DynSched_Test::setup_rt_info (high_10
, "high_10", TEN_HZ
, 180000,
190 RtecScheduler::HIGH_CRITICALITY
,
191 RtecScheduler::LOW_IMPORTANCE
, 1);
192 DynSched_Test::setup_rt_info (high_20
, "high_20", TWENTY_HZ
, 180000,
193 RtecScheduler::HIGH_CRITICALITY
,
194 RtecScheduler::LOW_IMPORTANCE
, 1);
197 DynSched_Test::register_rt_info (scheduler
, low_1
) ||
198 DynSched_Test::register_rt_info (scheduler
, low_5
) ||
199 DynSched_Test::register_rt_info (scheduler
, low_10
) ||
200 DynSched_Test::register_rt_info (scheduler
, low_20
) ||
201 DynSched_Test::register_rt_info (scheduler
, high_1
) ||
202 DynSched_Test::register_rt_info (scheduler
, high_5
) ||
203 DynSched_Test::register_rt_info (scheduler
, high_10
) ||
204 DynSched_Test::register_rt_info (scheduler
, high_20
))
209 #if defined (ACE_HAS_QUANTIFY)
210 quantify_start_recording_data ();
211 #endif /* ACE_HAS_QUANTIFY */
213 ACE_Unbounded_Set
<RtecScheduler::Scheduling_Anomaly
*> anomaly_set
;
214 ACE_DynScheduler::status_t status
= scheduler
.schedule (anomaly_set
);
216 #if defined (ACE_HAS_QUANTIFY)
217 quantify_stop_recording_data ();
218 #endif /* ACE_HAS_QUANTIFY */
222 case ACE_DynScheduler::SUCCEEDED
:
223 case ACE_DynScheduler::ST_UTILIZATION_BOUND_EXCEEDED
:
225 status
= scheduler
.output_timeline (output_filename
, heading
);
228 case ACE_DynScheduler::SUCCEEDED
:
229 case ACE_DynScheduler::ST_UTILIZATION_BOUND_EXCEEDED
:
233 ACE_ERROR_RETURN ((LM_ERROR
,
234 "scheduler.output_timeline (\"%s\") failed: "
236 output_filename
, status
), -1);
243 ACE_ERROR_RETURN ((LM_ERROR
,
244 "scheduler.schedule () failed: "
253 ACE_TMAIN(int, ACE_TCHAR
*[])
257 // create a bunch of different strategies, indicating the minimum critical
258 // priority level (number of priority levels in critical set - 1) for each.
260 ACE_RMS_Scheduler_Strategy
rms_strategy (3);
262 ACE_MLF_Scheduler_Strategy
mlf_strategy (0);
263 ACE_EDF_Scheduler_Strategy
edf_strategy (0);
265 ACE_MUF_Scheduler_Strategy
muf_strategy (0);
268 DynSched_Test::run_schedule (rms_strategy
, "RMS_Timelines",
269 "RMS Scheduling Strategy");
272 ACE_OS::printf ("run_schedule (rms_strategy, \"RMS_Timelines\", "
273 "\"RMS Scheduling Strategy\") returned %d\n",
279 DynSched_Test::run_schedule (mlf_strategy
, "MLF_Timelines",
280 "MLF Scheduling Strategy");
283 ACE_OS::printf ("run_schedule (mlf_strategy, \"MLF_Timelines\", "
284 "\"MLF Scheduling Strategy\") returned %d\n",
290 DynSched_Test::run_schedule (edf_strategy
, "EDF_Timelines",
291 "EDF Scheduling Strategy");
294 ACE_OS::printf ("run_schedule (edf_strategy, \"EDF_Timelines\", "
295 "\"EDF Scheduling Strategy\") returned %d\n",
301 DynSched_Test::run_schedule (muf_strategy
, "MUF_Timelines",
302 "MUF Scheduling Strategy");
305 ACE_OS::printf ("run_schedule (muf_strategy, \"MUF_Timelines\", "
306 "\"MUF Scheduling Strategy\") returned %d\n",