source: rtems/testsuites/tmtests/tm26/task1.c @ 7f6a24ab

4.104.114.84.95
Last change on this file since 7f6a24ab was 7f6a24ab, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 28, 1995 at 3:30:29 PM

Added unused priority ceiling parameter to rtems_semaphore_create.

Rearranged code to created thread handler routines to initialize,
start, restart, and "close/delete" a thread.

Made internal threads their own object class. This now uses the
thread support routines for starting and initializing a thread.

Insured deleted tasks are freed to the Inactive pool associated with the
correct Information block.

Added an RTEMS API specific data area to the thread control block.

Beginnings of removing the word "rtems" from the core.

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