source: rtems/testsuites/tmtests/tm26/task1.c @ 5c491aef

4.104.114.84.95
Last change on this file since 5c491aef was 5c491aef, checked in by Joel Sherrill <joel.sherrill@…>, on Dec 20, 1995 at 3:39:19 PM

changes remerged after lost in disk crash -- recovered from snapshot, partially recovered working tree, etc

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