source: rtems/testsuites/tmtests/tm26/task1.c @ 2617b345

4.104.114.84.9
Last change on this file since 2617b345 was 2617b345, checked in by Joel Sherrill <joel.sherrill@…>, on Feb 19, 1998 at 5:08:54 PM

Restructured so all times are placed in variables and printed in batch
mode at the end of the test. This eliminates the possibility of IO
blocking a task unexpectedly and messing up the test.

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