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

4.104.114.84.95
Last change on this file since e642446 was e642446, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 6, 1996 at 9:37:43 PM

As part of reducing visibility into rtems and hiding the .inl files
from the application code, this file required more visibility than
is given by default to application code.

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