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

4.115
Last change on this file since a4bc4d6e was a4bc4d6e, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/22/11 at 10:00:39

Add HAVE_CONFIG_H.

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