1 | /* |
---|
2 | * |
---|
3 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
4 | * On-Line Applications Research Corporation (OAR). |
---|
5 | * All rights assigned to U.S. Government, 1994. |
---|
6 | * |
---|
7 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
8 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
9 | * notice must appear in all copies of this file and its derivatives. |
---|
10 | * |
---|
11 | * task1.c,v 1.3 1995/06/05 23:55:00 joel Exp |
---|
12 | */ |
---|
13 | |
---|
14 | #include <rtems.h> |
---|
15 | #include "system.h" |
---|
16 | #include "fptest.h" |
---|
17 | #include <coverhd.h> |
---|
18 | #include <tmacros.h> |
---|
19 | #include <timesys.h> |
---|
20 | |
---|
21 | #undef EXTERN |
---|
22 | #define EXTERN |
---|
23 | #include "gvar.h" |
---|
24 | #include "conftbl.h" |
---|
25 | #undef EXTERN |
---|
26 | #define EXTERN extern |
---|
27 | |
---|
28 | /* TEST DATA */ |
---|
29 | rtems_id Semaphore_id; |
---|
30 | |
---|
31 | Objects_Locations location; /* uses internal RTEMS type */ |
---|
32 | |
---|
33 | Thread_Control *Middle_tcb; /* uses internal RTEMS type */ |
---|
34 | |
---|
35 | Thread_Control *Low_tcb; /* uses internal RTEMS type */ |
---|
36 | |
---|
37 | rtems_task High_task( |
---|
38 | rtems_task_argument argument |
---|
39 | ); |
---|
40 | |
---|
41 | rtems_task Middle_task( |
---|
42 | rtems_task_argument argument |
---|
43 | ); |
---|
44 | |
---|
45 | rtems_task Low_task( |
---|
46 | rtems_task_argument argument |
---|
47 | ); |
---|
48 | |
---|
49 | rtems_task Floating_point_task_1( |
---|
50 | rtems_task_argument argument |
---|
51 | ); |
---|
52 | |
---|
53 | rtems_task Floating_point_task_2( |
---|
54 | rtems_task_argument argument |
---|
55 | ); |
---|
56 | |
---|
57 | void complete_test( void ); |
---|
58 | |
---|
59 | rtems_task null_task( |
---|
60 | rtems_task_argument argument |
---|
61 | ) |
---|
62 | { |
---|
63 | } |
---|
64 | |
---|
65 | rtems_task Init( |
---|
66 | rtems_task_argument argument |
---|
67 | ) |
---|
68 | { |
---|
69 | rtems_unsigned32 index; |
---|
70 | rtems_id task_id; |
---|
71 | rtems_status_code status; |
---|
72 | |
---|
73 | puts( "\n\n*** TIME TEST 26 ***" ); |
---|
74 | |
---|
75 | status = rtems_task_create( |
---|
76 | rtems_build_name( 'F', 'P', '1', ' ' ), |
---|
77 | 201, |
---|
78 | 2048, |
---|
79 | RTEMS_DEFAULT_MODES, |
---|
80 | RTEMS_FLOATING_POINT, |
---|
81 | &task_id |
---|
82 | ); |
---|
83 | directive_failed( status, "rtems_task_create of FP1" ); |
---|
84 | |
---|
85 | status = rtems_task_start( task_id, Floating_point_task_1, 0 ); |
---|
86 | directive_failed( status, "rtems_task_start of FP1" ); |
---|
87 | |
---|
88 | status = rtems_task_create( |
---|
89 | rtems_build_name( 'F', 'P', '2', ' ' ), |
---|
90 | 202, |
---|
91 | 2048, |
---|
92 | RTEMS_DEFAULT_MODES, |
---|
93 | RTEMS_FLOATING_POINT, |
---|
94 | &task_id |
---|
95 | ); |
---|
96 | directive_failed( status, "rtems_task_create of FP2" ); |
---|
97 | |
---|
98 | status = rtems_task_start( task_id, Floating_point_task_2, 0 ); |
---|
99 | directive_failed( status, "rtems_task_start of FP2" ); |
---|
100 | |
---|
101 | status = rtems_task_create( |
---|
102 | rtems_build_name( 'L', 'O', 'W', ' ' ), |
---|
103 | 200, |
---|
104 | 2048, |
---|
105 | RTEMS_DEFAULT_MODES, |
---|
106 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
107 | &task_id |
---|
108 | ); |
---|
109 | directive_failed( status, "rtems_task_create of LOW" ); |
---|
110 | |
---|
111 | status = rtems_task_start( task_id, Low_task, 0 ); |
---|
112 | directive_failed( status, "rtems_task_start of LOW" ); |
---|
113 | |
---|
114 | status = rtems_task_create( |
---|
115 | rtems_build_name( 'M', 'I', 'D', ' ' ), |
---|
116 | 128, |
---|
117 | 2048, |
---|
118 | RTEMS_DEFAULT_MODES, |
---|
119 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
120 | &task_id |
---|
121 | ); |
---|
122 | directive_failed( status, "rtems_task_create of MIDDLE" ); |
---|
123 | |
---|
124 | status = rtems_task_start( task_id, Middle_task, 0 ); |
---|
125 | directive_failed( status, "rtems_task_start of MIDDLE" ); |
---|
126 | |
---|
127 | status = rtems_task_create( |
---|
128 | rtems_build_name( 'H', 'I', 'G', 'H' ), |
---|
129 | 5, |
---|
130 | 2048, |
---|
131 | RTEMS_DEFAULT_MODES, |
---|
132 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
133 | &task_id |
---|
134 | ); |
---|
135 | directive_failed( status, "rtems_task_create of HIGH" ); |
---|
136 | |
---|
137 | status = rtems_task_start( task_id, High_task, 0 ); |
---|
138 | directive_failed( status, "rtems_task_start of HIGH" ); |
---|
139 | |
---|
140 | status = rtems_semaphore_create( |
---|
141 | rtems_build_name( 'S', 'E', 'M', '1' ), |
---|
142 | OPERATION_COUNT, |
---|
143 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
144 | &Semaphore_id |
---|
145 | ); |
---|
146 | directive_failed( status, "rtems_semaphore_create" ); |
---|
147 | |
---|
148 | for ( index = 1 ; index <= OPERATION_COUNT ; index++ ) { |
---|
149 | status = rtems_task_create( |
---|
150 | rtems_build_name( 'N', 'U', 'L', 'L' ), |
---|
151 | 254, |
---|
152 | 1024, |
---|
153 | RTEMS_DEFAULT_MODES, |
---|
154 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
155 | &task_id |
---|
156 | ); |
---|
157 | directive_failed( status, "rtems_task_create LOOP" ); |
---|
158 | |
---|
159 | status = rtems_task_start( task_id, null_task, 0 ); |
---|
160 | directive_failed( status, "rtems_task_start LOOP" ); |
---|
161 | } |
---|
162 | |
---|
163 | status = rtems_task_delete( RTEMS_SELF ); |
---|
164 | directive_failed( status, "rtems_task_delete of RTEMS_SELF" ); |
---|
165 | } |
---|
166 | |
---|
167 | rtems_task High_task( |
---|
168 | rtems_task_argument argument |
---|
169 | ) |
---|
170 | { |
---|
171 | rtems_interrupt_level level; |
---|
172 | |
---|
173 | Timer_initialize(); |
---|
174 | rtems_interrupt_disable( level ); |
---|
175 | end_time = Read_timer(); |
---|
176 | |
---|
177 | put_time( |
---|
178 | "INTERRUPT DISABLE", |
---|
179 | end_time, |
---|
180 | 1, |
---|
181 | 0, |
---|
182 | 0 |
---|
183 | ); |
---|
184 | |
---|
185 | Timer_initialize(); |
---|
186 | rtems_interrupt_flash( level ); |
---|
187 | end_time = Read_timer(); |
---|
188 | |
---|
189 | put_time( |
---|
190 | "INTERRUPT FLASH", |
---|
191 | end_time, |
---|
192 | 1, |
---|
193 | 0, |
---|
194 | 0 |
---|
195 | ); |
---|
196 | |
---|
197 | Timer_initialize(); |
---|
198 | rtems_interrupt_enable( level ); |
---|
199 | end_time = Read_timer(); |
---|
200 | |
---|
201 | put_time( |
---|
202 | "INTERRUPT ENABLE", |
---|
203 | end_time, |
---|
204 | 1, |
---|
205 | 0, |
---|
206 | 0 |
---|
207 | ); |
---|
208 | |
---|
209 | Timer_initialize(); |
---|
210 | _Thread_Disable_dispatch(); |
---|
211 | end_time = Read_timer(); |
---|
212 | |
---|
213 | put_time( |
---|
214 | "THREAD_DISABLE_DISPATCH", |
---|
215 | end_time, |
---|
216 | 1, |
---|
217 | 0, |
---|
218 | 0 |
---|
219 | ); |
---|
220 | |
---|
221 | Timer_initialize(); |
---|
222 | _Thread_Enable_dispatch(); |
---|
223 | end_time = Read_timer(); |
---|
224 | |
---|
225 | put_time( |
---|
226 | "THREAD_ENABLE_DISPATCH", |
---|
227 | end_time, |
---|
228 | 1, |
---|
229 | 0, |
---|
230 | 0 |
---|
231 | ); |
---|
232 | |
---|
233 | Timer_initialize(); |
---|
234 | _Thread_Set_state( _Thread_Executing, STATES_SUSPENDED ); |
---|
235 | end_time = Read_timer(); |
---|
236 | |
---|
237 | put_time( |
---|
238 | "THREAD_SET_STATE", |
---|
239 | end_time, |
---|
240 | 1, |
---|
241 | 0, |
---|
242 | 0 |
---|
243 | ); |
---|
244 | |
---|
245 | _Context_Switch_necessary = TRUE; |
---|
246 | |
---|
247 | Timer_initialize(); |
---|
248 | _Thread_Dispatch(); /* dispatches Middle_task */ |
---|
249 | } |
---|
250 | |
---|
251 | rtems_task Middle_task( |
---|
252 | rtems_task_argument argument |
---|
253 | ) |
---|
254 | { |
---|
255 | end_time = Read_timer(); |
---|
256 | |
---|
257 | put_time( |
---|
258 | "THREAD_DISPATCH (NO FP)", |
---|
259 | end_time, |
---|
260 | 1, |
---|
261 | 0, |
---|
262 | 0 |
---|
263 | ); |
---|
264 | |
---|
265 | _Thread_Set_state( _Thread_Executing, STATES_SUSPENDED ); |
---|
266 | |
---|
267 | Middle_tcb = _Thread_Executing; |
---|
268 | |
---|
269 | _Thread_Executing = |
---|
270 | (Thread_Control *) _Thread_Ready_chain[200].first; |
---|
271 | |
---|
272 | /* do not force context switch */ |
---|
273 | |
---|
274 | _Context_Switch_necessary = FALSE; |
---|
275 | |
---|
276 | _Thread_Disable_dispatch(); |
---|
277 | |
---|
278 | Timer_initialize(); |
---|
279 | _Context_Switch( &Middle_tcb->Registers, &_Thread_Executing->Registers ); |
---|
280 | |
---|
281 | Timer_initialize(); |
---|
282 | _Context_Switch(&Middle_tcb->Registers, &Low_tcb->Registers); |
---|
283 | } |
---|
284 | |
---|
285 | rtems_task Low_task( |
---|
286 | rtems_task_argument argument |
---|
287 | ) |
---|
288 | { |
---|
289 | Thread_Control *executing; |
---|
290 | |
---|
291 | end_time = Read_timer(); |
---|
292 | |
---|
293 | put_time( |
---|
294 | "CONTEXT_SWITCH (NO FP)", |
---|
295 | end_time, |
---|
296 | 1, |
---|
297 | 0, |
---|
298 | 0 |
---|
299 | ); |
---|
300 | |
---|
301 | executing = _Thread_Executing; |
---|
302 | |
---|
303 | Low_tcb = executing; |
---|
304 | |
---|
305 | Timer_initialize(); |
---|
306 | _Context_Switch( &executing->Registers, &executing->Registers ); |
---|
307 | |
---|
308 | end_time = Read_timer(); |
---|
309 | |
---|
310 | put_time( |
---|
311 | "CONTEXT_SWITCH (SELF)", |
---|
312 | end_time, |
---|
313 | 1, |
---|
314 | 0, |
---|
315 | 0 |
---|
316 | ); |
---|
317 | |
---|
318 | _Context_Switch(&executing->Registers, &Middle_tcb->Registers); |
---|
319 | |
---|
320 | end_time = Read_timer(); |
---|
321 | |
---|
322 | put_time( |
---|
323 | "CONTEXT_SWITCH (Initialised)", |
---|
324 | end_time, |
---|
325 | 1, |
---|
326 | 0, |
---|
327 | 0 |
---|
328 | ); |
---|
329 | |
---|
330 | _Thread_Executing = |
---|
331 | (Thread_Control *) _Thread_Ready_chain[201].first; |
---|
332 | |
---|
333 | /* do not force context switch */ |
---|
334 | |
---|
335 | _Context_Switch_necessary = FALSE; |
---|
336 | |
---|
337 | _Thread_Disable_dispatch(); |
---|
338 | |
---|
339 | Timer_initialize(); |
---|
340 | _Context_Restore_fp( &_Thread_Executing->fp_context ); |
---|
341 | _Context_Switch( &executing->Registers, &_Thread_Executing->Registers ); |
---|
342 | } |
---|
343 | |
---|
344 | rtems_task Floating_point_task_1( |
---|
345 | rtems_task_argument argument |
---|
346 | ) |
---|
347 | { |
---|
348 | Thread_Control *executing; |
---|
349 | FP_DECLARE; |
---|
350 | |
---|
351 | end_time = Read_timer(); |
---|
352 | |
---|
353 | put_time( |
---|
354 | "CONTEXT_SWITCH (restore 1st FP)", |
---|
355 | end_time, |
---|
356 | 1, |
---|
357 | 0, |
---|
358 | 0 |
---|
359 | ); |
---|
360 | |
---|
361 | executing = _Thread_Executing; |
---|
362 | |
---|
363 | _Thread_Executing = |
---|
364 | (Thread_Control *) _Thread_Ready_chain[202].first; |
---|
365 | |
---|
366 | /* do not force context switch */ |
---|
367 | |
---|
368 | _Context_Switch_necessary = FALSE; |
---|
369 | |
---|
370 | _Thread_Disable_dispatch(); |
---|
371 | |
---|
372 | Timer_initialize(); |
---|
373 | _Context_Save_fp( &executing->fp_context ); |
---|
374 | _Context_Restore_fp( &_Thread_Executing->fp_context ); |
---|
375 | _Context_Switch( &executing->Registers, &_Thread_Executing->Registers ); |
---|
376 | /* switch to Floating_point_task_2 */ |
---|
377 | |
---|
378 | end_time = Read_timer(); |
---|
379 | |
---|
380 | put_time( |
---|
381 | "CONTEXT_SWITCH (used->init FP)", |
---|
382 | end_time, |
---|
383 | 1, |
---|
384 | 0, |
---|
385 | 0 |
---|
386 | ); |
---|
387 | |
---|
388 | FP_LOAD( 1.0 ); |
---|
389 | |
---|
390 | executing = _Thread_Executing; |
---|
391 | |
---|
392 | _Thread_Executing = |
---|
393 | (Thread_Control *) _Thread_Ready_chain[202].first; |
---|
394 | |
---|
395 | /* do not force context switch */ |
---|
396 | |
---|
397 | _Context_Switch_necessary = FALSE; |
---|
398 | |
---|
399 | _Thread_Disable_dispatch(); |
---|
400 | |
---|
401 | Timer_initialize(); |
---|
402 | _Context_Save_fp( &executing->fp_context ); |
---|
403 | _Context_Restore_fp( &_Thread_Executing->fp_context ); |
---|
404 | _Context_Switch( &executing->Registers, &_Thread_Executing->Registers ); |
---|
405 | /* switch to Floating_point_task_2 */ |
---|
406 | } |
---|
407 | |
---|
408 | rtems_task Floating_point_task_2( |
---|
409 | rtems_task_argument argument |
---|
410 | ) |
---|
411 | { |
---|
412 | Thread_Control *executing; |
---|
413 | FP_DECLARE; |
---|
414 | |
---|
415 | end_time = Read_timer(); |
---|
416 | |
---|
417 | put_time( |
---|
418 | "CONTEXT_SWITCH (init->init FP)", |
---|
419 | end_time, |
---|
420 | 1, |
---|
421 | 0, |
---|
422 | 0 |
---|
423 | ); |
---|
424 | |
---|
425 | executing = _Thread_Executing; |
---|
426 | |
---|
427 | _Thread_Executing = |
---|
428 | (Thread_Control *) _Thread_Ready_chain[201].first; |
---|
429 | |
---|
430 | FP_LOAD( 1.0 ); |
---|
431 | |
---|
432 | /* do not force context switch */ |
---|
433 | |
---|
434 | _Context_Switch_necessary = FALSE; |
---|
435 | |
---|
436 | _Thread_Disable_dispatch(); |
---|
437 | |
---|
438 | Timer_initialize(); |
---|
439 | _Context_Save_fp( &executing->fp_context ); |
---|
440 | _Context_Restore_fp( &_Thread_Executing->fp_context ); |
---|
441 | _Context_Switch( &executing->Registers, &_Thread_Executing->Registers ); |
---|
442 | /* switch to Floating_point_task_1 */ |
---|
443 | |
---|
444 | end_time = Read_timer(); |
---|
445 | |
---|
446 | put_time( |
---|
447 | "CONTEXT_SWITCH (used->used FP)", |
---|
448 | end_time, |
---|
449 | 1, |
---|
450 | 0, |
---|
451 | 0 |
---|
452 | ); |
---|
453 | |
---|
454 | complete_test(); |
---|
455 | } |
---|
456 | |
---|
457 | void complete_test( void ) |
---|
458 | { |
---|
459 | rtems_unsigned32 index; |
---|
460 | rtems_id task_id; |
---|
461 | |
---|
462 | Timer_initialize(); |
---|
463 | _Thread_Resume( Middle_tcb ); |
---|
464 | end_time = Read_timer(); |
---|
465 | |
---|
466 | put_time( |
---|
467 | "THREAD_RESUME", |
---|
468 | end_time, |
---|
469 | 1, |
---|
470 | 0, |
---|
471 | 0 |
---|
472 | ); |
---|
473 | |
---|
474 | _Thread_Set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE ); |
---|
475 | |
---|
476 | Timer_initialize(); |
---|
477 | _Thread_Unblock( Middle_tcb ); |
---|
478 | end_time = Read_timer(); |
---|
479 | |
---|
480 | put_time( |
---|
481 | "THREAD_UNBLOCK", |
---|
482 | end_time, |
---|
483 | 1, |
---|
484 | 0, |
---|
485 | 0 |
---|
486 | ); |
---|
487 | |
---|
488 | _Thread_Set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE ); |
---|
489 | |
---|
490 | Timer_initialize(); |
---|
491 | _Thread_Ready( Middle_tcb ); |
---|
492 | end_time = Read_timer(); |
---|
493 | |
---|
494 | put_time( |
---|
495 | "THREAD_READY", |
---|
496 | end_time, |
---|
497 | 1, |
---|
498 | 0, |
---|
499 | 0 |
---|
500 | ); |
---|
501 | |
---|
502 | Timer_initialize(); |
---|
503 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
504 | (void) Empty_function(); |
---|
505 | overhead = Read_timer(); |
---|
506 | |
---|
507 | task_id = Middle_tcb->Object.id; |
---|
508 | |
---|
509 | Timer_initialize(); |
---|
510 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
511 | (void) _Thread_Get( task_id, &location ); |
---|
512 | end_time = Read_timer(); |
---|
513 | |
---|
514 | put_time( |
---|
515 | "THREAD_GET", |
---|
516 | end_time, |
---|
517 | OPERATION_COUNT, |
---|
518 | 0, |
---|
519 | 0 |
---|
520 | ); |
---|
521 | |
---|
522 | Timer_initialize(); |
---|
523 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
524 | (void) _Semaphore_Get( Semaphore_id, &location ); |
---|
525 | end_time = Read_timer(); |
---|
526 | |
---|
527 | put_time( |
---|
528 | "SEMAPHORE_GET", |
---|
529 | end_time, |
---|
530 | OPERATION_COUNT, |
---|
531 | 0, |
---|
532 | 0 |
---|
533 | ); |
---|
534 | |
---|
535 | Timer_initialize(); |
---|
536 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
537 | (void) _Thread_Get( 0x3, &location ); |
---|
538 | end_time = Read_timer(); |
---|
539 | |
---|
540 | put_time( |
---|
541 | "THREAD_GET invalid id", |
---|
542 | end_time, |
---|
543 | OPERATION_COUNT, |
---|
544 | 0, |
---|
545 | 0 |
---|
546 | ); |
---|
547 | exit( 0 ); |
---|
548 | } |
---|
549 | |
---|