source: rtems/testsuites/tmtests/tm26/task1.c @ 1c95d94

4.115
Last change on this file since 1c95d94 was 1c95d94, checked in by Jennifer Averett <Jennifer.Averett@…>, on 04/21/11 at 19:05:34

2011-04-21 Jennifer Averett <Jennifer.Averett@…

PR 1777/cpukit

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