source: rtems/testsuites/tmtests/tm26/task1.c @ 9d47cd1

4.11
Last change on this file since 9d47cd1 was 9d47cd1, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 30, 2010 at 6:52:32 PM

2010-07-30 Gedare Bloom <giddyup44@…>

PR 1599/cpukit

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