source: rtems/testsuites/tmtests/tm26/task1.c @ 8f71a36

4.104.114.84.95
Last change on this file since 8f71a36 was 8f71a36, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/20/04 at 07:09:31

Remove stray white spaces.

  • Property mode set to 100644
File size: 12.7 KB
RevLine 
[ac7d5ef0]1/*
2 *
[08311cc3]3 *  COPYRIGHT (c) 1989-1999.
[ac7d5ef0]4 *  On-Line Applications Research Corporation (OAR).
5 *
[98e4ebf5]6 *  The license and distribution terms for this file may be
7 *  found in the file LICENSE in this distribution or at
[95a81ab]8 *  http://www.rtems.com/license/LICENSE.
[ac7d5ef0]9 *
[3235ad9]10 *  $Id$
[ac7d5ef0]11 */
12
[3a4ae6c]13#define TEST_INIT
[e6424462]14#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
[ac7d5ef0]15#include <rtems.h>
16#include "system.h"
17#include "fptest.h"
[459f770]18#include <coverhd.h>
19#include <tmacros.h>
20#include <timesys.h>
[ac7d5ef0]21
22
23/* TEST DATA */
24rtems_id Semaphore_id;
25
26Objects_Locations location;   /* uses internal RTEMS type */
27
28Thread_Control *Middle_tcb;   /* uses internal RTEMS type */
29
[7950309]30Thread_Control *Low_tcb;      /* uses internal RTEMS type */
31
[2617b345]32/*
33 *  Variables to hold execution times until they are printed
34 *  at the end of the test.
35 */
36
[0720ff4]37uint32_t   isr_disable_time;
38uint32_t   isr_flash_time;
39uint32_t   isr_enable_time;
40uint32_t   thread_disable_dispatch_time;
41uint32_t   thread_enable_dispatch_time;
42uint32_t   thread_set_state_time;
43uint32_t   thread_dispatch_no_fp_time;
44uint32_t   context_switch_no_fp_time;
45uint32_t   context_switch_self_time;
46uint32_t   context_switch_another_task_time;
47uint32_t   context_switch_restore_1st_fp_time;
48uint32_t   context_switch_save_idle_restore_initted_time;
49uint32_t   context_switch_save_restore_idle_time;
50uint32_t   context_switch_save_restore_initted_time;
51uint32_t   thread_resume_time;
52uint32_t   thread_unblock_time;
53uint32_t   thread_ready_time;
54uint32_t   thread_get_time;
55uint32_t   semaphore_get_time;
56uint32_t   thread_get_invalid_time;
[2617b345]57
[ac7d5ef0]58rtems_task High_task(
59  rtems_task_argument argument
60);
61
62rtems_task Middle_task(
63  rtems_task_argument argument
64);
65
66rtems_task Low_task(
67  rtems_task_argument argument
68);
69
70rtems_task Floating_point_task_1(
71  rtems_task_argument argument
72);
73
74rtems_task Floating_point_task_2(
75  rtems_task_argument argument
76);
77
78void complete_test( void );
79
80rtems_task null_task(
81  rtems_task_argument argument
82)
83{
84}
85
86rtems_task Init(
87  rtems_task_argument argument
88)
89{
[0720ff4]90  uint32_t    index;
[ac7d5ef0]91  rtems_id          task_id;
92  rtems_status_code status;
93
[3a4ae6c]94  Print_Warning();
95
[ac7d5ef0]96  puts( "\n\n*** TIME TEST 26 ***" );
97
98  status = rtems_task_create(
99    rtems_build_name( 'F', 'P', '1', ' ' ),
100    201,
[3652ad35]101    RTEMS_MINIMUM_STACK_SIZE,
[ac7d5ef0]102    RTEMS_DEFAULT_MODES,
103    RTEMS_FLOATING_POINT,
104    &task_id
105  );
106  directive_failed( status, "rtems_task_create of FP1" );
107
108  status = rtems_task_start( task_id, Floating_point_task_1, 0 );
109  directive_failed( status, "rtems_task_start of FP1" );
110
111  status = rtems_task_create(
112    rtems_build_name( 'F', 'P', '2', ' ' ),
113    202,
[3652ad35]114    RTEMS_MINIMUM_STACK_SIZE,
[ac7d5ef0]115    RTEMS_DEFAULT_MODES,
116    RTEMS_FLOATING_POINT,
117    &task_id
118  );
119  directive_failed( status, "rtems_task_create of FP2" );
120
121  status = rtems_task_start( task_id, Floating_point_task_2, 0 );
122  directive_failed( status, "rtems_task_start of FP2" );
123
124  status = rtems_task_create(
125    rtems_build_name( 'L', 'O', 'W', ' ' ),
126    200,
[3652ad35]127    RTEMS_MINIMUM_STACK_SIZE,
[ac7d5ef0]128    RTEMS_DEFAULT_MODES,
129    RTEMS_DEFAULT_ATTRIBUTES,
130    &task_id
131  );
132  directive_failed( status, "rtems_task_create of LOW" );
133
134  status = rtems_task_start( task_id, Low_task, 0 );
135  directive_failed( status, "rtems_task_start of LOW" );
136
137  status = rtems_task_create(
138    rtems_build_name( 'M', 'I', 'D', ' ' ),
139    128,
[3652ad35]140    RTEMS_MINIMUM_STACK_SIZE,
[ac7d5ef0]141    RTEMS_DEFAULT_MODES,
142    RTEMS_DEFAULT_ATTRIBUTES,
143    &task_id
144  );
145  directive_failed( status, "rtems_task_create of MIDDLE" );
146
147  status = rtems_task_start( task_id, Middle_task, 0 );
148  directive_failed( status, "rtems_task_start of MIDDLE" );
149
150  status = rtems_task_create(
151    rtems_build_name( 'H', 'I', 'G', 'H' ),
152    5,
[3652ad35]153    RTEMS_MINIMUM_STACK_SIZE,
[ac7d5ef0]154    RTEMS_DEFAULT_MODES,
155    RTEMS_DEFAULT_ATTRIBUTES,
156    &task_id
157  );
158  directive_failed( status, "rtems_task_create of HIGH" );
159
160  status = rtems_task_start( task_id, High_task, 0 );
161  directive_failed( status, "rtems_task_start of HIGH" );
162
163  status = rtems_semaphore_create(
164    rtems_build_name( 'S', 'E', 'M', '1' ),
165    OPERATION_COUNT,
166    RTEMS_DEFAULT_ATTRIBUTES,
[7f6a24ab]167    RTEMS_NO_PRIORITY,
[ac7d5ef0]168    &Semaphore_id
169  );
170  directive_failed( status, "rtems_semaphore_create" );
171
172  for ( index = 1 ; index <= OPERATION_COUNT ; index++ ) {
173    status = rtems_task_create(
174      rtems_build_name( 'N', 'U', 'L', 'L' ),
175      254,
[3652ad35]176      RTEMS_MINIMUM_STACK_SIZE,
[ac7d5ef0]177      RTEMS_DEFAULT_MODES,
178      RTEMS_DEFAULT_ATTRIBUTES,
179      &task_id
180    );
181    directive_failed( status, "rtems_task_create LOOP" );
182
183    status = rtems_task_start( task_id, null_task, 0 );
184    directive_failed( status, "rtems_task_start LOOP" );
185  }
186
187  status = rtems_task_delete( RTEMS_SELF );
188  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
189}
190
191rtems_task High_task(
192  rtems_task_argument argument
193)
194{
[7950309]195  rtems_interrupt_level level;
196
197  Timer_initialize();
198    rtems_interrupt_disable( level );
[2617b345]199  isr_disable_time = Read_timer();
[8f71a36]200
[7950309]201  Timer_initialize();
202    rtems_interrupt_flash( level );
[2617b345]203  isr_flash_time = Read_timer();
[8f71a36]204
[7950309]205  Timer_initialize();
206    rtems_interrupt_enable( level );
[2617b345]207  isr_enable_time = Read_timer();
[8f71a36]208
[ac7d5ef0]209  Timer_initialize();
210    _Thread_Disable_dispatch();
[2617b345]211  thread_disable_dispatch_time = Read_timer();
[ac7d5ef0]212
213  Timer_initialize();
214    _Thread_Enable_dispatch();
[2617b345]215  thread_enable_dispatch_time = Read_timer();
[ac7d5ef0]216
217  Timer_initialize();
218    _Thread_Set_state( _Thread_Executing, STATES_SUSPENDED );
[2617b345]219  thread_set_state_time = Read_timer();
[ac7d5ef0]220
221  _Context_Switch_necessary = TRUE;
222
223  Timer_initialize();
224    _Thread_Dispatch();           /* dispatches Middle_task */
225}
226
227rtems_task Middle_task(
228  rtems_task_argument argument
229)
230{
[2617b345]231  thread_dispatch_no_fp_time = Read_timer();
[ac7d5ef0]232
233  _Thread_Set_state( _Thread_Executing, STATES_SUSPENDED );
234
235  Middle_tcb   = _Thread_Executing;
236
237  _Thread_Executing =
238        (Thread_Control *) _Thread_Ready_chain[200].first;
239
240  /* do not force context switch */
241
242  _Context_Switch_necessary = FALSE;
243
[459f770]244  _Thread_Disable_dispatch();
245
[ac7d5ef0]246  Timer_initialize();
247    _Context_Switch( &Middle_tcb->Registers, &_Thread_Executing->Registers );
[7950309]248
249  Timer_initialize();
250    _Context_Switch(&Middle_tcb->Registers, &Low_tcb->Registers);
[ac7d5ef0]251}
252
253rtems_task Low_task(
254  rtems_task_argument argument
255)
256{
257  Thread_Control *executing;
258
[2617b345]259  context_switch_no_fp_time = Read_timer();
[ac7d5ef0]260
261  executing    = _Thread_Executing;
262
[7950309]263  Low_tcb = executing;
264
265  Timer_initialize();
266    _Context_Switch( &executing->Registers, &executing->Registers );
267
[2617b345]268  context_switch_self_time = Read_timer();
[7950309]269
270  _Context_Switch(&executing->Registers, &Middle_tcb->Registers);
271
[2617b345]272  context_switch_another_task_time = Read_timer();
[7950309]273
[ac7d5ef0]274  _Thread_Executing =
275        (Thread_Control *) _Thread_Ready_chain[201].first;
276
277  /* do not force context switch */
278
279  _Context_Switch_necessary = FALSE;
280
[459f770]281  _Thread_Disable_dispatch();
282
[ac7d5ef0]283  Timer_initialize();
[ca7858bb]284#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
[ac7d5ef0]285    _Context_Restore_fp( &_Thread_Executing->fp_context );
[ca7858bb]286#endif
[ac7d5ef0]287    _Context_Switch( &executing->Registers, &_Thread_Executing->Registers );
288}
289
290rtems_task Floating_point_task_1(
291  rtems_task_argument argument
292)
293{
294  Thread_Control *executing;
295  FP_DECLARE;
296
[2617b345]297  context_switch_restore_1st_fp_time = Read_timer();
[ac7d5ef0]298
299  executing = _Thread_Executing;
300
301  _Thread_Executing =
302        (Thread_Control *) _Thread_Ready_chain[202].first;
303
304  /* do not force context switch */
305
306  _Context_Switch_necessary = FALSE;
307
[459f770]308  _Thread_Disable_dispatch();
309
[ac7d5ef0]310  Timer_initialize();
[ca7858bb]311#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
[ac7d5ef0]312    _Context_Save_fp( &executing->fp_context );
313    _Context_Restore_fp( &_Thread_Executing->fp_context );
[ca7858bb]314#endif
[ac7d5ef0]315    _Context_Switch( &executing->Registers, &_Thread_Executing->Registers );
316  /* switch to Floating_point_task_2 */
317
[2617b345]318  context_switch_save_idle_restore_initted_time = Read_timer();
[ac7d5ef0]319
320  FP_LOAD( 1.0 );
321
322  executing = _Thread_Executing;
323
324  _Thread_Executing =
325       (Thread_Control *) _Thread_Ready_chain[202].first;
326
327  /* do not force context switch */
328
329  _Context_Switch_necessary = FALSE;
330
[459f770]331  _Thread_Disable_dispatch();
332
[ac7d5ef0]333  Timer_initialize();
[ca7858bb]334#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
[ac7d5ef0]335    _Context_Save_fp( &executing->fp_context );
336    _Context_Restore_fp( &_Thread_Executing->fp_context );
[ca7858bb]337#endif
[ac7d5ef0]338    _Context_Switch( &executing->Registers, &_Thread_Executing->Registers );
339  /* switch to Floating_point_task_2 */
340}
341
342rtems_task Floating_point_task_2(
343  rtems_task_argument argument
344)
345{
346  Thread_Control *executing;
347  FP_DECLARE;
348
[2617b345]349  context_switch_save_restore_idle_time = Read_timer();
[ac7d5ef0]350
351  executing = _Thread_Executing;
352
353  _Thread_Executing =
354       (Thread_Control *) _Thread_Ready_chain[201].first;
355
356  FP_LOAD( 1.0 );
357
358  /* do not force context switch */
359
360  _Context_Switch_necessary = FALSE;
361
[459f770]362  _Thread_Disable_dispatch();
363
[ac7d5ef0]364  Timer_initialize();
[ca7858bb]365#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
[ac7d5ef0]366    _Context_Save_fp( &executing->fp_context );
367    _Context_Restore_fp( &_Thread_Executing->fp_context );
[ca7858bb]368#endif
[ac7d5ef0]369    _Context_Switch( &executing->Registers, &_Thread_Executing->Registers );
370  /* switch to Floating_point_task_1 */
371
[2617b345]372  context_switch_save_restore_initted_time = Read_timer();
[ac7d5ef0]373
374  complete_test();
375}
376
377void complete_test( void )
378{
[0720ff4]379  uint32_t    index;
[ac7d5ef0]380  rtems_id          task_id;
381
382  Timer_initialize();
[3d67661]383    _Thread_Resume( Middle_tcb, TRUE );
[2617b345]384  thread_resume_time = Read_timer();
385
386  _Thread_Set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE );
387
388  Timer_initialize();
389    _Thread_Unblock( Middle_tcb );
390  thread_unblock_time = Read_timer();
391
392  _Thread_Set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE );
393
394  Timer_initialize();
395    _Thread_Ready( Middle_tcb );
396  thread_ready_time = Read_timer();
397
398  Timer_initialize();
399    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
400      (void) Empty_function();
401  overhead = Read_timer();
402
403  task_id = Middle_tcb->Object.id;
404
405  Timer_initialize();
406    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
407      (void) _Thread_Get( task_id, &location );
408  thread_get_time = Read_timer();
409
410  Timer_initialize();
411    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
412      (void) _Semaphore_Get( Semaphore_id, &location );
413  semaphore_get_time = Read_timer();
414
415  Timer_initialize();
416    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
417      (void) _Thread_Get( 0x3, &location );
418  thread_get_invalid_time = Read_timer();
419
[54a43fe4]420  /*
421   *  This is the running task and we have tricked RTEMS out enough where
422   *  we need to set some internal tracking information to match this.
423   */
424
425  _Thread_Heir = _Thread_Executing;
426  _Context_Switch_necessary = FALSE;
427  _Thread_Dispatch_disable_level = 0;
428
[2617b345]429  /*
430   *  Now dump all the times
431   */
[ac7d5ef0]432
433  put_time(
[2617b345]434    "_ISR_Disable",
435    isr_disable_time,
[ac7d5ef0]436    1,
437    0,
438    0
439  );
440
[2617b345]441  put_time(
442    "_ISR_Flash",
443    isr_flash_time,
444    1,
445    0,
446    0
447  );
[8f71a36]448
[2617b345]449  put_time(
450    "_ISR_Enable",
451    isr_enable_time,
452    1,
453    0,
454    0
455  );
[8f71a36]456
[2617b345]457  put_time(
458    "_Thread_Disable_dispatch",
459    thread_disable_dispatch_time,
460    1,
461    0,
462    0
463  );
[ac7d5ef0]464
[2617b345]465  put_time(
466    "_Thread_Enable_dispatch",
467    thread_enable_dispatch_time,
468    1,
469    0,
470    0
471  );
[ac7d5ef0]472
473  put_time(
[2617b345]474    "_Thread_Set_state",
475    thread_set_state_time,
[ac7d5ef0]476    1,
477    0,
478    0
479  );
480
[2617b345]481  put_time(
482    "_Thread_Disptach (NO FP)",
483    thread_dispatch_no_fp_time,
484    1,
485    0,
486    0
487  );
[ac7d5ef0]488
[2617b345]489  put_time(
490    "context switch: no floating point contexts",
491    context_switch_no_fp_time,
492    1,
493    0,
494    0
495  );
[ac7d5ef0]496
497  put_time(
[2617b345]498    "context switch: self",
499    context_switch_self_time,
[ac7d5ef0]500    1,
501    0,
502    0
503  );
504
[2617b345]505  put_time(
506    "context switch: to another task",
507    context_switch_another_task_time,
508    1,
509    0,
510    0
511  );
[ac7d5ef0]512
[ca7858bb]513#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
[2617b345]514  put_time(
515    "fp context switch: restore 1st FP task",
516    context_switch_restore_1st_fp_time,
517    1,
518    0,
519    0
520  );
[ac7d5ef0]521
[2617b345]522  put_time(
523    "fp context switch: save idle, restore initialized",
524    context_switch_save_idle_restore_initted_time,
525    1,
526    0,
527    0
528  );
529
530  put_time(
531    "fp context switch: save idle, restore idle",
532    context_switch_save_restore_idle_time,
533    1,
534    0,
535    0
536  );
537
538  put_time(
539    "fp context switch: save initialized, restore initialized",
540    context_switch_save_restore_initted_time,
541    1,
542    0,
543    0
544  );
[ca7858bb]545#else
546    puts( "fp context switch: restore 1st FP task - NA" );
547    puts( "fp context switch: save idle, restore initialized - NA" );
548    puts( "fp context switch: save idle, restore idle - NA" );
549    puts( "fp context switch: save initialized, restore initialized - NA" );
550#endif
[2617b345]551
552  put_time(
553    "_Thread_Resume",
554    thread_resume_time,
555    1,
556    0,
557    0
558  );
559
560  put_time(
561    "_Thread_Unblock",
562    thread_unblock_time,
563    1,
564    0,
565    0
566  );
567
568  put_time(
569    "_Thread_Ready",
570    thread_ready_time,
571    1,
572    0,
573    0
574  );
[ac7d5ef0]575
576  put_time(
[5c491aef]577    "_Thread_Get",
[2617b345]578    thread_get_time,
[ac7d5ef0]579    OPERATION_COUNT,
580    0,
581    0
582  );
583
584  put_time(
[5c491aef]585    "_Semaphore_Get",
[2617b345]586    semaphore_get_time,
[ac7d5ef0]587    OPERATION_COUNT,
588    0,
589    0
590  );
591
592  put_time(
[5c491aef]593    "_Thread_Get: invalid id",
[2617b345]594    thread_get_invalid_time,
[ac7d5ef0]595    OPERATION_COUNT,
596    0,
597    0
598  );
[3a4ae6c]599
600  puts( "*** END OF TEST 26 ***" );
[b454bc9]601  rtems_test_exit( 0 );
[ac7d5ef0]602}
Note: See TracBrowser for help on using the repository browser.