source: rtems/testsuites/tmtests/tm26/task1.c @ dc8fd01

5
Last change on this file since dc8fd01 was dc8fd01, checked in by Sebastian Huber <sebastian.huber@…>, on 02/09/18 at 07:56:20

tests: Support %g print format specifier

  • Property mode set to 100644
File size: 16.3 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2013.
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.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#define CONFIGURE_INIT
15#include <rtems.h>
16#include "system.h"
17#include "fptest.h"
18#include <tmacros.h>
19#include <timesys.h>
20
21#include <rtems/score/schedulerpriorityimpl.h>
22#include <rtems/rtems/semimpl.h>
23
24#if defined( RTEMS_SMP ) && defined( RTEMS_DEBUG )
25  #define PREVENT_SMP_ASSERT_FAILURES
26#endif
27
28const char rtems_test_name[] = "TIME TEST 26";
29
30/* TEST DATA */
31rtems_id Semaphore_id;
32
33Thread_Control *Middle_tcb;   /* uses internal RTEMS type */
34
35Thread_Control *Low_tcb;      /* uses internal RTEMS type */
36
37/*
38 *  Variables to hold execution times until they are printed
39 *  at the end of the test.
40 */
41
42uint32_t   isr_disable_time;
43uint32_t   isr_flash_time;
44uint32_t   isr_enable_time;
45uint32_t   thread_disable_dispatch_time;
46uint32_t   thread_enable_dispatch_time;
47uint32_t   thread_set_state_time;
48uint32_t   thread_dispatch_no_fp_time;
49uint32_t   context_switch_no_fp_time;
50uint32_t   context_switch_self_time;
51uint32_t   context_switch_another_task_time;
52uint32_t   context_switch_restore_1st_fp_time;
53uint32_t   context_switch_save_idle_restore_initted_time;
54uint32_t   context_switch_save_restore_idle_time;
55uint32_t   context_switch_save_restore_initted_time;
56uint32_t   thread_resume_time;
57uint32_t   thread_unblock_time;
58uint32_t   thread_ready_time;
59uint32_t   thread_get_time;
60uint32_t   semaphore_get_time;
61uint32_t   thread_get_invalid_time;
62
63rtems_task null_task(
64  rtems_task_argument argument
65);
66
67rtems_task High_task(
68  rtems_task_argument argument
69);
70
71rtems_task Middle_task(
72  rtems_task_argument argument
73);
74
75rtems_task Low_task(
76  rtems_task_argument argument
77);
78
79rtems_task Floating_point_task_1(
80  rtems_task_argument argument
81);
82
83rtems_task Floating_point_task_2(
84  rtems_task_argument argument
85);
86
87void complete_test( void );
88
89static void set_thread_dispatch_necessary( bool dispatch_necessary )
90{
91#if defined( PREVENT_SMP_ASSERT_FAILURES )
92  ISR_Level level;
93
94  _ISR_Local_disable( level );
95#endif
96
97  _Thread_Dispatch_necessary = dispatch_necessary;
98
99  if ( !dispatch_necessary ) {
100    _Thread_Heir = _Thread_Executing;
101  }
102
103#if defined( PREVENT_SMP_ASSERT_FAILURES )
104  _ISR_Local_enable( level );
105#endif
106}
107
108static void set_thread_heir( Thread_Control *thread )
109{
110#if defined( PREVENT_SMP_ASSERT_FAILURES )
111  ISR_Level level;
112
113  _ISR_Local_disable( level );
114#endif
115
116  _Thread_Heir = thread;
117
118#if defined( PREVENT_SMP_ASSERT_FAILURES )
119  _ISR_Local_enable( level );
120#endif
121}
122
123static void set_thread_executing( Thread_Control *thread )
124{
125  _Per_CPU_Get_snapshot()->executing = thread;
126}
127
128static void thread_resume( Thread_Control *thread )
129{
130  _Thread_Clear_state( thread, STATES_SUSPENDED );
131}
132
133rtems_task null_task(
134  rtems_task_argument argument
135)
136{
137}
138
139rtems_task Init(
140  rtems_task_argument argument
141)
142{
143  uint32_t    index;
144  rtems_id          task_id;
145  rtems_status_code status;
146
147  rtems_print_printer_fprintf_putc(&rtems_test_printer);
148  Print_Warning();
149
150  TEST_BEGIN();
151
152  if (
153    _Scheduler_Table[ 0 ].Operations.initialize
154      != _Scheduler_priority_Initialize
155  ) {
156    puts("  Error ==> " );
157    puts("Test only supported for deterministic priority scheduler\n" );
158    TEST_END();
159    rtems_test_exit( 0 );
160  }
161
162#define FP1_PRIORITY (RTEMS_MAXIMUM_PRIORITY - 3u)      /* 201, */
163  status = rtems_task_create(
164    rtems_build_name( 'F', 'P', '1', ' ' ),
165    FP1_PRIORITY,
166    RTEMS_MINIMUM_STACK_SIZE,
167    RTEMS_DEFAULT_MODES,
168    RTEMS_FLOATING_POINT,
169    &task_id
170  );
171  directive_failed( status, "rtems_task_create of FP1" );
172
173  status = rtems_task_start( task_id, Floating_point_task_1, 0 );
174  directive_failed( status, "rtems_task_start of FP1" );
175
176#define FP2_PRIORITY (RTEMS_MAXIMUM_PRIORITY - 2u)      /* 202, */
177  status = rtems_task_create(
178    rtems_build_name( 'F', 'P', '2', ' ' ),
179    FP2_PRIORITY,
180    RTEMS_MINIMUM_STACK_SIZE,
181    RTEMS_DEFAULT_MODES,
182    RTEMS_FLOATING_POINT,
183    &task_id
184  );
185  directive_failed( status, "rtems_task_create of FP2" );
186
187  status = rtems_task_start( task_id, Floating_point_task_2, 0 );
188  directive_failed( status, "rtems_task_start of FP2" );
189
190#define LOW_PRIORITY (RTEMS_MAXIMUM_PRIORITY - 4u)   /*  200, */
191  status = rtems_task_create(
192    rtems_build_name( 'L', 'O', 'W', ' ' ),
193    LOW_PRIORITY,
194    RTEMS_MINIMUM_STACK_SIZE,
195    RTEMS_DEFAULT_MODES,
196    RTEMS_DEFAULT_ATTRIBUTES,
197    &task_id
198  );
199  directive_failed( status, "rtems_task_create of LOW" );
200
201  status = rtems_task_start( task_id, Low_task, 0 );
202  directive_failed( status, "rtems_task_start of LOW" );
203
204#define MIDDLE_PRIORITY (RTEMS_MAXIMUM_PRIORITY - 5u)   /*  128, */
205  status = rtems_task_create(
206    rtems_build_name( 'M', 'I', 'D', ' ' ),
207    MIDDLE_PRIORITY,
208    RTEMS_MINIMUM_STACK_SIZE,
209    RTEMS_DEFAULT_MODES,
210    RTEMS_DEFAULT_ATTRIBUTES,
211    &task_id
212  );
213  directive_failed( status, "rtems_task_create of MIDDLE" );
214
215  status = rtems_task_start( task_id, Middle_task, 0 );
216  directive_failed( status, "rtems_task_start of MIDDLE" );
217
218  status = rtems_task_create(
219    rtems_build_name( 'H', 'I', 'G', 'H' ),
220    5,
221    RTEMS_MINIMUM_STACK_SIZE,
222    RTEMS_DEFAULT_MODES,
223    RTEMS_DEFAULT_ATTRIBUTES,
224    &task_id
225  );
226  directive_failed( status, "rtems_task_create of HIGH" );
227
228  status = rtems_task_start( task_id, High_task, 0 );
229  directive_failed( status, "rtems_task_start of HIGH" );
230
231  status = rtems_semaphore_create(
232    rtems_build_name( 'S', 'E', 'M', '1' ),
233    OPERATION_COUNT,
234    RTEMS_DEFAULT_ATTRIBUTES,
235    RTEMS_NO_PRIORITY,
236    &Semaphore_id
237  );
238  directive_failed( status, "rtems_semaphore_create" );
239
240  for ( index = 1 ; index <= OPERATION_COUNT ; index++ ) {
241    status = rtems_task_create(
242      rtems_build_name( 'N', 'U', 'L', 'L' ),
243      RTEMS_MAXIMUM_PRIORITY - 1u,      /* 254, */
244      RTEMS_MINIMUM_STACK_SIZE,
245      RTEMS_DEFAULT_MODES,
246      RTEMS_DEFAULT_ATTRIBUTES,
247      &task_id
248    );
249    directive_failed( status, "rtems_task_create LOOP" );
250
251    status = rtems_task_start( task_id, null_task, 0 );
252    directive_failed( status, "rtems_task_start LOOP" );
253  }
254
255  status = rtems_task_delete( RTEMS_SELF );
256  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
257}
258
259rtems_task High_task(
260  rtems_task_argument argument
261)
262{
263  rtems_interrupt_level level;
264
265  _Thread_Dispatch_disable();
266
267  benchmark_timer_initialize();
268    rtems_interrupt_local_disable( level );
269  isr_disable_time = benchmark_timer_read();
270
271  benchmark_timer_initialize();
272#if defined(RTEMS_SMP)
273    rtems_interrupt_local_enable( level );
274    rtems_interrupt_local_disable( level );
275#else
276    rtems_interrupt_flash( level );
277#endif
278  isr_flash_time = benchmark_timer_read();
279
280  benchmark_timer_initialize();
281    rtems_interrupt_local_enable( level );
282  isr_enable_time = benchmark_timer_read();
283
284  _Thread_Dispatch_enable( _Per_CPU_Get() );
285
286  benchmark_timer_initialize();
287    _Thread_Dispatch_disable();
288  thread_disable_dispatch_time = benchmark_timer_read();
289
290  benchmark_timer_initialize();
291    _Thread_Dispatch_enable( _Per_CPU_Get() );
292  thread_enable_dispatch_time = benchmark_timer_read();
293
294  benchmark_timer_initialize();
295    _Thread_Set_state( _Thread_Get_executing(), STATES_SUSPENDED );
296  thread_set_state_time = benchmark_timer_read();
297
298  set_thread_dispatch_necessary( true );
299
300  benchmark_timer_initialize();
301    _Thread_Dispatch();           /* dispatches Middle_task */
302}
303
304rtems_task Middle_task(
305  rtems_task_argument argument
306)
307{
308  Scheduler_priority_Context *scheduler_context =
309    _Scheduler_priority_Get_context( _Thread_Scheduler_get_home( _Thread_Get_executing() ) );
310
311  thread_dispatch_no_fp_time = benchmark_timer_read();
312
313  _Thread_Set_state( _Thread_Get_executing(), STATES_SUSPENDED );
314
315  Middle_tcb   = _Thread_Get_executing();
316
317  set_thread_executing(
318    (Thread_Control *) _Chain_First(&scheduler_context->Ready[LOW_PRIORITY])
319  );
320
321  /* do not force context switch */
322
323  set_thread_dispatch_necessary( false );
324
325  _Thread_Dispatch_disable();
326
327  benchmark_timer_initialize();
328    _Context_Switch(
329      &Middle_tcb->Registers,
330      &_Thread_Get_executing()->Registers
331    );
332
333  benchmark_timer_initialize();
334    _Context_Switch(&Middle_tcb->Registers, &Low_tcb->Registers);
335}
336
337rtems_task Low_task(
338  rtems_task_argument argument
339)
340{
341  Scheduler_priority_Context *scheduler_context =
342    _Scheduler_priority_Get_context( _Thread_Scheduler_get_home( _Thread_Get_executing() ) );
343  Thread_Control             *executing;
344
345  context_switch_no_fp_time = benchmark_timer_read();
346
347  executing    = _Thread_Get_executing();
348
349  Low_tcb = executing;
350
351  benchmark_timer_initialize();
352    _Context_Switch( &executing->Registers, &executing->Registers );
353
354  context_switch_self_time = benchmark_timer_read();
355
356  _Context_Switch(&executing->Registers, &Middle_tcb->Registers);
357
358  context_switch_another_task_time = benchmark_timer_read();
359
360  set_thread_executing(
361    (Thread_Control *) _Chain_First(&scheduler_context->Ready[FP1_PRIORITY])
362  );
363
364  /* do not force context switch */
365
366  set_thread_dispatch_necessary( false );
367
368  _Thread_Dispatch_disable();
369
370  benchmark_timer_initialize();
371    _Context_Switch(
372      &executing->Registers,
373      &_Thread_Get_executing()->Registers
374    );
375}
376
377rtems_task Floating_point_task_1(
378  rtems_task_argument argument
379)
380{
381  Scheduler_priority_Context *scheduler_context =
382    _Scheduler_priority_Get_context( _Thread_Scheduler_get_home( _Thread_Get_executing() ) );
383  Thread_Control             *executing;
384  FP_DECLARE;
385
386  context_switch_restore_1st_fp_time = benchmark_timer_read();
387
388  executing = _Thread_Get_executing();
389
390  set_thread_executing(
391    (Thread_Control *) _Chain_First(&scheduler_context->Ready[FP2_PRIORITY])
392  );
393
394  /* do not force context switch */
395
396  set_thread_dispatch_necessary( false );
397
398  _Thread_Dispatch_disable();
399
400  benchmark_timer_initialize();
401#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
402    _Context_Save_fp( &executing->fp_context );
403    _Context_Restore_fp( &_Thread_Get_executing()->fp_context );
404#endif
405    _Context_Switch(
406      &executing->Registers,
407      &_Thread_Get_executing()->Registers
408    );
409  /* switch to Floating_point_task_2 */
410
411  context_switch_save_idle_restore_initted_time = benchmark_timer_read();
412
413  FP_LOAD( 1.0 );
414
415  executing = _Thread_Get_executing();
416
417  set_thread_executing(
418    (Thread_Control *) _Chain_First(&scheduler_context->Ready[FP2_PRIORITY])
419  );
420
421  benchmark_timer_initialize();
422#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
423    _Context_Save_fp( &executing->fp_context );
424    _Context_Restore_fp( &_Thread_Get_executing()->fp_context );
425#endif
426    _Context_Switch(
427      &executing->Registers,
428      &_Thread_Get_executing()->Registers
429    );
430  /* switch to Floating_point_task_2 */
431}
432
433rtems_task Floating_point_task_2(
434  rtems_task_argument argument
435)
436{
437  Scheduler_priority_Context *scheduler_context =
438    _Scheduler_priority_Get_context( _Thread_Scheduler_get_home( _Thread_Get_executing() ) );
439  Thread_Control             *executing;
440  FP_DECLARE;
441
442  context_switch_save_restore_idle_time = benchmark_timer_read();
443
444  executing = _Thread_Get_executing();
445
446  set_thread_executing(
447    (Thread_Control *) _Chain_First(&scheduler_context->Ready[FP1_PRIORITY])
448  );
449
450  FP_LOAD( 1.0 );
451
452  benchmark_timer_initialize();
453#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
454    _Context_Save_fp( &executing->fp_context );
455    _Context_Restore_fp( &_Thread_Get_executing()->fp_context );
456#endif
457    _Context_Switch(
458      &executing->Registers,
459      &_Thread_Get_executing()->Registers
460    );
461  /* switch to Floating_point_task_1 */
462
463  context_switch_save_restore_initted_time = benchmark_timer_read();
464
465  complete_test();
466}
467
468void complete_test( void )
469{
470  uint32_t             index;
471  rtems_id             task_id;
472  ISR_lock_Context     lock_context;
473  Thread_queue_Context queue_context;
474
475  benchmark_timer_initialize();
476    thread_resume( Middle_tcb );
477  thread_resume_time = benchmark_timer_read();
478
479  _Thread_Set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE );
480
481  benchmark_timer_initialize();
482    _Thread_Unblock( Middle_tcb );
483  thread_unblock_time = benchmark_timer_read();
484
485  _Thread_Set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE );
486
487  benchmark_timer_initialize();
488    _Thread_Clear_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE );
489  thread_ready_time = benchmark_timer_read();
490
491  benchmark_timer_initialize();
492    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
493      (void) benchmark_timer_empty_function();
494  overhead = benchmark_timer_read();
495
496  task_id = Middle_tcb->Object.id;
497
498  benchmark_timer_initialize();
499    for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
500      (void) _Thread_Get( task_id, &lock_context );
501      _ISR_lock_ISR_enable( &lock_context );
502    }
503  thread_get_time = benchmark_timer_read();
504
505  benchmark_timer_initialize();
506    for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
507      (void) _Semaphore_Get( Semaphore_id, &queue_context );
508      _ISR_lock_ISR_enable( &queue_context.Lock_context.Lock_context );
509    }
510  semaphore_get_time = benchmark_timer_read();
511
512  benchmark_timer_initialize();
513    for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
514      (void) _Thread_Get( 0x3, &lock_context );
515      _ISR_lock_ISR_enable( &lock_context );
516    }
517  thread_get_invalid_time = benchmark_timer_read();
518
519  /*
520   *  This is the running task and we have tricked RTEMS out enough where
521   *  we need to set some internal tracking information to match this.
522   */
523
524  set_thread_heir( _Thread_Get_executing() );
525  set_thread_dispatch_necessary( false );
526
527  /*
528   *  Now dump all the times
529   */
530
531  put_time(
532    "rtems interrupt: _ISR_Local_disable",
533    isr_disable_time,
534    1,
535    0,
536    0
537  );
538
539  put_time(
540    "rtems interrupt: _ISR_Local_flash",
541    isr_flash_time,
542    1,
543    0,
544    0
545  );
546
547  put_time(
548    "rtems interrupt: _ISR_Local_enable",
549    isr_enable_time,
550    1,
551    0,
552    0
553  );
554
555  put_time(
556    "rtems internal: _Thread_Dispatch_disable",
557    thread_disable_dispatch_time,
558    1,
559    0,
560    0
561  );
562
563  put_time(
564    "rtems internal: _Thread_Dispatch_enable",
565    thread_enable_dispatch_time,
566    1,
567    0,
568    0
569  );
570
571  put_time(
572    "rtems internal: _Thread_Set_state",
573    thread_set_state_time,
574    1,
575    0,
576    0
577  );
578
579  put_time(
580    "rtems internal: _Thread_Dispatch NO FP",
581    thread_dispatch_no_fp_time,
582    1,
583    0,
584    0
585  );
586
587  put_time(
588    "rtems internal: context switch: no floating point contexts",
589    context_switch_no_fp_time,
590    1,
591    0,
592    0
593  );
594
595  put_time(
596    "rtems internal: context switch: self",
597    context_switch_self_time,
598    1,
599    0,
600    0
601  );
602
603  put_time(
604    "rtems internal: context switch to another task",
605    context_switch_another_task_time,
606    1,
607    0,
608    0
609  );
610
611#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
612  put_time(
613    "rtems internal: fp context switch restore 1st FP task",
614    context_switch_restore_1st_fp_time,
615    1,
616    0,
617    0
618  );
619
620  put_time(
621    "rtems internal: fp context switch save idle and restore initialized",
622    context_switch_save_idle_restore_initted_time,
623    1,
624    0,
625    0
626  );
627
628  put_time(
629    "rtems internal: fp context switch save idle, restore idle",
630    context_switch_save_restore_idle_time,
631    1,
632    0,
633    0
634  );
635
636  put_time(
637    "rtems internal: fp context switch save initialized, restore initialized",
638    context_switch_save_restore_initted_time,
639    1,
640    0,
641    0
642  );
643#else
644    puts(
645     "rtems internal: fp context switch restore 1st FP task - NA\n"
646     "rtems internal: fp context switch save idle restore initialized - NA\n"
647     "rtems internal: fp context switch save idle restore idle - NA\n"
648     "rtems internal: fp context switch save initialized\n"
649                      " restore initialized - NA"
650   );
651#endif
652
653  put_time(
654    "rtems internal: _Thread_Resume",
655    thread_resume_time,
656    1,
657    0,
658    0
659  );
660
661  put_time(
662    "rtems internal: _Thread_Unblock",
663    thread_unblock_time,
664    1,
665    0,
666    0
667  );
668
669  put_time(
670    "rtems internal: _Thread_Ready",
671    thread_ready_time,
672    1,
673    0,
674    0
675  );
676
677  put_time(
678    "rtems internal: _Thread_Get",
679    thread_get_time,
680    OPERATION_COUNT,
681    0,
682    0
683  );
684
685  put_time(
686    "rtems internal: _Semaphore_Get",
687    semaphore_get_time,
688    OPERATION_COUNT,
689    0,
690    0
691  );
692
693  put_time(
694    "rtems internal: _Thread_Get: invalid id",
695    thread_get_invalid_time,
696    OPERATION_COUNT,
697    0,
698    0
699  );
700
701  TEST_END();
702  rtems_test_exit( 0 );
703}
Note: See TracBrowser for help on using the repository browser.