source: rtems/testsuites/tmtests/tm26/task1.c @ 3d67661

4.104.114.84.95
Last change on this file since 3d67661 was 3d67661, checked in by Joel Sherrill <joel.sherrill@…>, on 11/09/99 at 23:10:48

Added nesting count for suspend/resume.

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