1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2009. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #define CONFIGURE_INIT |
---|
13 | #include "system.h" |
---|
14 | |
---|
15 | rtems_id Semaphore_id; |
---|
16 | rtems_id Task_id[OPERATION_COUNT+1]; |
---|
17 | uint32_t task_count; |
---|
18 | rtems_id Highest_id; |
---|
19 | |
---|
20 | rtems_task Low_tasks( |
---|
21 | rtems_task_argument argument |
---|
22 | ); |
---|
23 | |
---|
24 | rtems_task High_task( |
---|
25 | rtems_task_argument argument |
---|
26 | ); |
---|
27 | |
---|
28 | rtems_task Highest_task( |
---|
29 | rtems_task_argument argument |
---|
30 | ); |
---|
31 | |
---|
32 | rtems_task Restart_task( |
---|
33 | rtems_task_argument argument |
---|
34 | ); |
---|
35 | |
---|
36 | void test_init(void); |
---|
37 | |
---|
38 | rtems_task Init( |
---|
39 | rtems_task_argument argument |
---|
40 | ) |
---|
41 | { |
---|
42 | rtems_status_code status; |
---|
43 | |
---|
44 | Print_Warning(); |
---|
45 | |
---|
46 | puts( "\n\n*** TIME TEST 4 ***" ); |
---|
47 | |
---|
48 | test_init(); |
---|
49 | |
---|
50 | status = rtems_task_delete( RTEMS_SELF ); |
---|
51 | directive_failed( status, "rtems_task_delete of RTEMS_SELF" ); |
---|
52 | } |
---|
53 | |
---|
54 | void test_init(void) |
---|
55 | { |
---|
56 | rtems_status_code status; |
---|
57 | int index; |
---|
58 | |
---|
59 | task_count = OPERATION_COUNT; |
---|
60 | |
---|
61 | for ( index = 1 ; index <= OPERATION_COUNT ; index++ ) { |
---|
62 | |
---|
63 | status = rtems_task_create( |
---|
64 | rtems_build_name( 'T', 'I', 'M', 'E' ), |
---|
65 | 10, |
---|
66 | RTEMS_MINIMUM_STACK_SIZE, |
---|
67 | RTEMS_NO_PREEMPT, |
---|
68 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
69 | &Task_id[ index ] |
---|
70 | ); |
---|
71 | directive_failed( status, "rtems_task_create loop" ); |
---|
72 | |
---|
73 | status = rtems_task_start( Task_id[ index ], Low_tasks, 0 ); |
---|
74 | directive_failed( status, "rtems_task_start loop" ); |
---|
75 | } |
---|
76 | |
---|
77 | status = rtems_semaphore_create( |
---|
78 | rtems_build_name( 'S', 'M', '1', ' ' ), |
---|
79 | 0, |
---|
80 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
81 | RTEMS_NO_PRIORITY, |
---|
82 | &Semaphore_id |
---|
83 | ); |
---|
84 | directive_failed( status, "rtems_semaphore_create of SM1" ); |
---|
85 | } |
---|
86 | |
---|
87 | rtems_task Highest_task( |
---|
88 | rtems_task_argument argument |
---|
89 | ) |
---|
90 | { |
---|
91 | rtems_task_priority old_priority; |
---|
92 | rtems_status_code status; |
---|
93 | |
---|
94 | if ( argument == 1 ) { |
---|
95 | |
---|
96 | end_time = benchmark_timer_read(); |
---|
97 | |
---|
98 | put_time( |
---|
99 | "rtems_task_restart: blocked task -- preempts caller", |
---|
100 | end_time, |
---|
101 | 1, |
---|
102 | 0, |
---|
103 | CALLING_OVERHEAD_TASK_RESTART |
---|
104 | ); |
---|
105 | |
---|
106 | status = rtems_task_set_priority( |
---|
107 | RTEMS_CURRENT_PRIORITY, |
---|
108 | RTEMS_MAXIMUM_PRIORITY - 1u, |
---|
109 | &old_priority |
---|
110 | ); |
---|
111 | directive_failed( status, "rtems_task_set_priority" ); |
---|
112 | |
---|
113 | } else if ( argument == 2 ) { |
---|
114 | |
---|
115 | end_time = benchmark_timer_read(); |
---|
116 | |
---|
117 | put_time( |
---|
118 | "rtems_task_restart: ready task -- preempts caller", |
---|
119 | end_time, |
---|
120 | 1, |
---|
121 | 0, |
---|
122 | CALLING_OVERHEAD_TASK_RESTART |
---|
123 | ); |
---|
124 | |
---|
125 | status = rtems_task_delete( RTEMS_SELF ); |
---|
126 | directive_failed( status, "rtems_task_delete of RTEMS_SELF" ); |
---|
127 | |
---|
128 | } else |
---|
129 | (void) rtems_semaphore_obtain( |
---|
130 | Semaphore_id, |
---|
131 | RTEMS_DEFAULT_OPTIONS, |
---|
132 | RTEMS_NO_TIMEOUT |
---|
133 | ); |
---|
134 | |
---|
135 | } |
---|
136 | |
---|
137 | rtems_task High_task( |
---|
138 | rtems_task_argument argument |
---|
139 | ) |
---|
140 | { |
---|
141 | rtems_status_code status; |
---|
142 | uint32_t index; |
---|
143 | rtems_name name; |
---|
144 | rtems_task_priority old_priority; |
---|
145 | |
---|
146 | benchmark_timer_initialize(); |
---|
147 | (void) rtems_task_restart( Highest_id, 1 ); |
---|
148 | /* preempted by Higher_task */ |
---|
149 | |
---|
150 | benchmark_timer_initialize(); |
---|
151 | (void) rtems_task_restart( Highest_id, 2 ); |
---|
152 | /* preempted by Higher_task */ |
---|
153 | |
---|
154 | benchmark_timer_initialize(); |
---|
155 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
156 | (void) benchmark_timer_empty_function(); |
---|
157 | overhead = benchmark_timer_read(); |
---|
158 | |
---|
159 | benchmark_timer_initialize(); |
---|
160 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
161 | rtems_semaphore_release( Semaphore_id ); |
---|
162 | end_time = benchmark_timer_read(); |
---|
163 | |
---|
164 | put_time( |
---|
165 | "rtems_semaphore_release: task readied -- returns to caller", |
---|
166 | end_time, |
---|
167 | OPERATION_COUNT, |
---|
168 | 0, |
---|
169 | CALLING_OVERHEAD_SEMAPHORE_RELEASE |
---|
170 | ); |
---|
171 | |
---|
172 | name = rtems_build_name( 'T', 'I', 'M', 'E' ); |
---|
173 | |
---|
174 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) { |
---|
175 | status = rtems_task_delete( Task_id[index] ); |
---|
176 | directive_failed( status, "rtems_task_delete" ); |
---|
177 | } |
---|
178 | |
---|
179 | benchmark_timer_initialize(); |
---|
180 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
181 | rtems_task_create( |
---|
182 | name, |
---|
183 | 10, |
---|
184 | RTEMS_MINIMUM_STACK_SIZE, |
---|
185 | RTEMS_NO_PREEMPT, |
---|
186 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
187 | &Task_id[ index ] |
---|
188 | ); |
---|
189 | end_time = benchmark_timer_read(); |
---|
190 | |
---|
191 | put_time( |
---|
192 | "rtems_task_create", |
---|
193 | end_time, |
---|
194 | OPERATION_COUNT, |
---|
195 | overhead, |
---|
196 | CALLING_OVERHEAD_TASK_CREATE |
---|
197 | ); |
---|
198 | |
---|
199 | benchmark_timer_initialize(); |
---|
200 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
201 | rtems_task_start( Task_id[ index ], Low_tasks, 0 ); |
---|
202 | |
---|
203 | end_time = benchmark_timer_read(); |
---|
204 | |
---|
205 | put_time( |
---|
206 | "rtems_task_start", |
---|
207 | end_time, |
---|
208 | OPERATION_COUNT, |
---|
209 | overhead, |
---|
210 | CALLING_OVERHEAD_TASK_START |
---|
211 | ); |
---|
212 | |
---|
213 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) { |
---|
214 | status = rtems_task_delete( Task_id[ index ] ); |
---|
215 | directive_failed( status, "rtems_task_delete" ); |
---|
216 | } |
---|
217 | |
---|
218 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) { |
---|
219 | status = rtems_task_create( |
---|
220 | name, |
---|
221 | RTEMS_MAXIMUM_PRIORITY - 4u, |
---|
222 | RTEMS_MINIMUM_STACK_SIZE, |
---|
223 | RTEMS_NO_PREEMPT, |
---|
224 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
225 | &Task_id[ index ] |
---|
226 | ); |
---|
227 | directive_failed( status, "rtems_task_create LOOP 1" ); |
---|
228 | |
---|
229 | status = rtems_task_start( Task_id[ index ], Restart_task, 0 ); |
---|
230 | directive_failed( status, "rtems_task_start LOOP 1" ); |
---|
231 | |
---|
232 | status = rtems_task_suspend( Task_id[ index ] ); |
---|
233 | directive_failed( status, "rtems_task_suspend LOOP 1" ); |
---|
234 | } |
---|
235 | |
---|
236 | benchmark_timer_initialize(); |
---|
237 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
238 | (void) rtems_task_restart( Task_id[ index ], 0 ); |
---|
239 | end_time = benchmark_timer_read(); |
---|
240 | |
---|
241 | put_time( |
---|
242 | "rtems_task_restart: suspended task -- returns to caller", |
---|
243 | end_time, |
---|
244 | OPERATION_COUNT, |
---|
245 | overhead, |
---|
246 | CALLING_OVERHEAD_TASK_RESTART |
---|
247 | ); |
---|
248 | |
---|
249 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
250 | (void) rtems_task_suspend( Task_id[ index ] ); |
---|
251 | |
---|
252 | benchmark_timer_initialize(); |
---|
253 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
254 | (void) rtems_task_delete( Task_id[ index ] ); |
---|
255 | end_time = benchmark_timer_read(); |
---|
256 | |
---|
257 | put_time( |
---|
258 | "rtems_task_delete: suspended task", |
---|
259 | end_time, |
---|
260 | OPERATION_COUNT, |
---|
261 | overhead, |
---|
262 | CALLING_OVERHEAD_TASK_DELETE |
---|
263 | ); |
---|
264 | |
---|
265 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) { |
---|
266 | status = rtems_task_create( |
---|
267 | name, |
---|
268 | RTEMS_MAXIMUM_PRIORITY - 4u, |
---|
269 | RTEMS_MINIMUM_STACK_SIZE, |
---|
270 | RTEMS_DEFAULT_MODES, |
---|
271 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
272 | &Task_id[ index ] |
---|
273 | ); |
---|
274 | directive_failed( status, "rtems_task_create LOOP 2" ); |
---|
275 | |
---|
276 | status = rtems_task_start( Task_id[ index ], Restart_task, 0 ); |
---|
277 | directive_failed( status, "rtems_task_start LOOP 2" ); |
---|
278 | } |
---|
279 | |
---|
280 | benchmark_timer_initialize(); |
---|
281 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
282 | (void) rtems_task_restart( Task_id[ index ], 1 ); |
---|
283 | end_time = benchmark_timer_read(); |
---|
284 | |
---|
285 | put_time( |
---|
286 | "rtems_task_restart: ready task -- returns to caller", |
---|
287 | end_time, |
---|
288 | OPERATION_COUNT, |
---|
289 | overhead, |
---|
290 | CALLING_OVERHEAD_TASK_RESTART |
---|
291 | ); |
---|
292 | |
---|
293 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) { |
---|
294 | status = rtems_task_set_priority( Task_id[ index ], 5, &old_priority ); |
---|
295 | directive_failed( status, "rtems_task_set_priority loop" ); |
---|
296 | } |
---|
297 | |
---|
298 | /* yield processor -- tasks block */ |
---|
299 | status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); |
---|
300 | directive_failed( status, "rtems_task_wake_after" ); |
---|
301 | |
---|
302 | benchmark_timer_initialize(); |
---|
303 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
304 | (void) rtems_task_restart( Task_id[ index ], 1 ); |
---|
305 | end_time = benchmark_timer_read(); |
---|
306 | |
---|
307 | put_time( |
---|
308 | "rtems_task_restart: blocked task -- returns to caller", |
---|
309 | end_time, |
---|
310 | OPERATION_COUNT, |
---|
311 | overhead, |
---|
312 | CALLING_OVERHEAD_TASK_RESTART |
---|
313 | ); |
---|
314 | |
---|
315 | /* yield processor -- tasks block */ |
---|
316 | status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); |
---|
317 | directive_failed( status, "rtems_task_wake_after" ); |
---|
318 | |
---|
319 | benchmark_timer_initialize(); |
---|
320 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
321 | (void) rtems_task_delete( Task_id[ index ] ); |
---|
322 | end_time = benchmark_timer_read(); |
---|
323 | |
---|
324 | put_time( |
---|
325 | "rtems_task_delete: blocked task", |
---|
326 | end_time, |
---|
327 | OPERATION_COUNT, |
---|
328 | overhead, |
---|
329 | CALLING_OVERHEAD_TASK_DELETE |
---|
330 | ); |
---|
331 | |
---|
332 | puts( "*** END OF TEST 4 ***" ); |
---|
333 | rtems_test_exit( 0 ); |
---|
334 | } |
---|
335 | |
---|
336 | rtems_task Low_tasks( |
---|
337 | rtems_task_argument argument |
---|
338 | ) |
---|
339 | { |
---|
340 | rtems_id id; |
---|
341 | rtems_status_code status; |
---|
342 | |
---|
343 | task_count--; |
---|
344 | |
---|
345 | if ( task_count == 0 ) { |
---|
346 | status = rtems_task_create( |
---|
347 | rtems_build_name( 'H', 'I', ' ', ' ' ), |
---|
348 | 5, |
---|
349 | RTEMS_MINIMUM_STACK_SIZE, |
---|
350 | RTEMS_DEFAULT_MODES, |
---|
351 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
352 | &id |
---|
353 | ); |
---|
354 | directive_failed( status, "rtems_task_create HI" ); |
---|
355 | |
---|
356 | status = rtems_task_start( id, High_task, 0 ); |
---|
357 | directive_failed( status, "rtems_task_start HI" ); |
---|
358 | |
---|
359 | status = rtems_task_create( |
---|
360 | rtems_build_name( 'H', 'I', 'G', 'H' ), |
---|
361 | 3, |
---|
362 | RTEMS_MINIMUM_STACK_SIZE, |
---|
363 | RTEMS_DEFAULT_MODES, |
---|
364 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
365 | &Highest_id |
---|
366 | ); |
---|
367 | directive_failed( status, "rtems_task_create HIGH" ); |
---|
368 | |
---|
369 | status = rtems_task_start( Highest_id, Highest_task, 0 ); |
---|
370 | directive_failed( status, "rtems_task_start HIGH" ); |
---|
371 | |
---|
372 | } |
---|
373 | (void) rtems_semaphore_obtain( |
---|
374 | Semaphore_id, |
---|
375 | RTEMS_DEFAULT_OPTIONS, |
---|
376 | RTEMS_NO_TIMEOUT |
---|
377 | ); |
---|
378 | } |
---|
379 | |
---|
380 | rtems_task Restart_task( |
---|
381 | rtems_task_argument argument |
---|
382 | ) |
---|
383 | { |
---|
384 | if ( argument == 1 ) |
---|
385 | (void) rtems_semaphore_obtain( |
---|
386 | Semaphore_id, |
---|
387 | RTEMS_DEFAULT_OPTIONS, |
---|
388 | RTEMS_NO_TIMEOUT |
---|
389 | ); |
---|
390 | } |
---|