source: rtems/testsuites/tmtests/tm26/task1.c @ 0720ff4

4.104.114.84.95
Last change on this file since 0720ff4 was 0720ff4, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/28/04 at 07:20:11

2004-03-28 Ralf Corsepius <ralf_corsepius@…>

  • include/timesys.h, tm01/task1.c, tm02/task1.c, tm03/task1.c, tm04/task1.c, tm05/task1.c, tm06/task1.c, tm07/task1.c, tm08/task1.c, tm09/task1.c, tm10/task1.c, tm11/task1.c, tm12/task1.c, tm13/task1.c, tm14/task1.c, tm15/task1.c, tm16/task1.c, tm17/task1.c, tm18/task1.c, tm20/task1.c, tm21/task1.c, tm22/task1.c, tm23/task1.c, tm24/task1.c, tm25/task1.c, tm26/task1.c, tm27/task1.c, tm28/task1.c, tm29/task1.c, tmck/task1.c, tmoverhd/testtask.c: Convert to using c99 fixed size types.
  • Property mode set to 100644
File size: 12.7 KB
Line 
1/*
2 *
3 *  COPYRIGHT (c) 1989-1999.
4 *  On-Line Applications Research Corporation (OAR).
5 *
6 *  The license and distribution terms for this file may be
7 *  found in the file LICENSE in this distribution or at
8 *  http://www.rtems.com/license/LICENSE.
9 *
10 *  $Id$
11 */
12
13#define TEST_INIT
14#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
15#include <rtems.h>
16#include "system.h"
17#include "fptest.h"
18#include <coverhd.h>
19#include <tmacros.h>
20#include <timesys.h>
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
30Thread_Control *Low_tcb;      /* uses internal RTEMS type */
31
32/*
33 *  Variables to hold execution times until they are printed
34 *  at the end of the test.
35 */
36
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;
57
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{
90  uint32_t    index;
91  rtems_id          task_id;
92  rtems_status_code status;
93
94  Print_Warning();
95
96  puts( "\n\n*** TIME TEST 26 ***" );
97
98  status = rtems_task_create(
99    rtems_build_name( 'F', 'P', '1', ' ' ),
100    201,
101    RTEMS_MINIMUM_STACK_SIZE,
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,
114    RTEMS_MINIMUM_STACK_SIZE,
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,
127    RTEMS_MINIMUM_STACK_SIZE,
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,
140    RTEMS_MINIMUM_STACK_SIZE,
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,
153    RTEMS_MINIMUM_STACK_SIZE,
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,
167    RTEMS_NO_PRIORITY,
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,
176      RTEMS_MINIMUM_STACK_SIZE,
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{
195  rtems_interrupt_level level;
196
197  Timer_initialize();
198    rtems_interrupt_disable( level );
199  isr_disable_time = Read_timer();
200 
201  Timer_initialize();
202    rtems_interrupt_flash( level );
203  isr_flash_time = Read_timer();
204 
205  Timer_initialize();
206    rtems_interrupt_enable( level );
207  isr_enable_time = Read_timer();
208 
209  Timer_initialize();
210    _Thread_Disable_dispatch();
211  thread_disable_dispatch_time = Read_timer();
212
213  Timer_initialize();
214    _Thread_Enable_dispatch();
215  thread_enable_dispatch_time = Read_timer();
216
217  Timer_initialize();
218    _Thread_Set_state( _Thread_Executing, STATES_SUSPENDED );
219  thread_set_state_time = Read_timer();
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{
231  thread_dispatch_no_fp_time = Read_timer();
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
244  _Thread_Disable_dispatch();
245
246  Timer_initialize();
247    _Context_Switch( &Middle_tcb->Registers, &_Thread_Executing->Registers );
248
249  Timer_initialize();
250    _Context_Switch(&Middle_tcb->Registers, &Low_tcb->Registers);
251}
252
253rtems_task Low_task(
254  rtems_task_argument argument
255)
256{
257  Thread_Control *executing;
258
259  context_switch_no_fp_time = Read_timer();
260
261  executing    = _Thread_Executing;
262
263  Low_tcb = executing;
264
265  Timer_initialize();
266    _Context_Switch( &executing->Registers, &executing->Registers );
267
268  context_switch_self_time = Read_timer();
269
270  _Context_Switch(&executing->Registers, &Middle_tcb->Registers);
271
272  context_switch_another_task_time = Read_timer();
273
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
281  _Thread_Disable_dispatch();
282
283  Timer_initialize();
284#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
285    _Context_Restore_fp( &_Thread_Executing->fp_context );
286#endif
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
297  context_switch_restore_1st_fp_time = Read_timer();
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
308  _Thread_Disable_dispatch();
309
310  Timer_initialize();
311#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
312    _Context_Save_fp( &executing->fp_context );
313    _Context_Restore_fp( &_Thread_Executing->fp_context );
314#endif
315    _Context_Switch( &executing->Registers, &_Thread_Executing->Registers );
316  /* switch to Floating_point_task_2 */
317
318  context_switch_save_idle_restore_initted_time = Read_timer();
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
331  _Thread_Disable_dispatch();
332
333  Timer_initialize();
334#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
335    _Context_Save_fp( &executing->fp_context );
336    _Context_Restore_fp( &_Thread_Executing->fp_context );
337#endif
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
349  context_switch_save_restore_idle_time = Read_timer();
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
362  _Thread_Disable_dispatch();
363
364  Timer_initialize();
365#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
366    _Context_Save_fp( &executing->fp_context );
367    _Context_Restore_fp( &_Thread_Executing->fp_context );
368#endif
369    _Context_Switch( &executing->Registers, &_Thread_Executing->Registers );
370  /* switch to Floating_point_task_1 */
371
372  context_switch_save_restore_initted_time = Read_timer();
373
374  complete_test();
375}
376
377void complete_test( void )
378{
379  uint32_t    index;
380  rtems_id          task_id;
381
382  Timer_initialize();
383    _Thread_Resume( Middle_tcb, TRUE );
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
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
429  /*
430   *  Now dump all the times
431   */
432
433  put_time(
434    "_ISR_Disable",
435    isr_disable_time,
436    1,
437    0,
438    0
439  );
440
441  put_time(
442    "_ISR_Flash",
443    isr_flash_time,
444    1,
445    0,
446    0
447  );
448 
449  put_time(
450    "_ISR_Enable",
451    isr_enable_time,
452    1,
453    0,
454    0
455  );
456 
457  put_time(
458    "_Thread_Disable_dispatch",
459    thread_disable_dispatch_time,
460    1,
461    0,
462    0
463  );
464
465  put_time(
466    "_Thread_Enable_dispatch",
467    thread_enable_dispatch_time,
468    1,
469    0,
470    0
471  );
472
473  put_time(
474    "_Thread_Set_state",
475    thread_set_state_time,
476    1,
477    0,
478    0
479  );
480
481  put_time(
482    "_Thread_Disptach (NO FP)",
483    thread_dispatch_no_fp_time,
484    1,
485    0,
486    0
487  );
488
489  put_time(
490    "context switch: no floating point contexts",
491    context_switch_no_fp_time,
492    1,
493    0,
494    0
495  );
496
497  put_time(
498    "context switch: self",
499    context_switch_self_time,
500    1,
501    0,
502    0
503  );
504
505  put_time(
506    "context switch: to another task",
507    context_switch_another_task_time,
508    1,
509    0,
510    0
511  );
512
513#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
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  );
521
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  );
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
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  );
575
576  put_time(
577    "_Thread_Get",
578    thread_get_time,
579    OPERATION_COUNT,
580    0,
581    0
582  );
583
584  put_time(
585    "_Semaphore_Get",
586    semaphore_get_time,
587    OPERATION_COUNT,
588    0,
589    0
590  );
591
592  put_time(
593    "_Thread_Get: invalid id",
594    thread_get_invalid_time,
595    OPERATION_COUNT,
596    0,
597    0
598  );
599
600  puts( "*** END OF TEST 26 ***" );
601  rtems_test_exit( 0 );
602}
603
Note: See TracBrowser for help on using the repository browser.