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

5
Last change on this file since fdeaa64 was fdeaa64, checked in by Sebastian Huber <sebastian.huber@…>, on 03/03/20 at 12:01:56

config: Remove <rtems/btimer.h> include

The use of CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER does not define
anything, so remove the <rtems/btimer.h> include.

Update #3875.

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