source: rtems/testsuites/tmtests/tm04/task1.c @ a4bc4d6e

4.115
Last change on this file since a4bc4d6e was a4bc4d6e, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/22/11 at 10:00:39

Add HAVE_CONFIG_H.

  • Property mode set to 100644
File size: 9.2 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#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#define CONFIGURE_INIT
17#include "system.h"
18
19rtems_id         Semaphore_id;
20rtems_id         Task_id[OPERATION_COUNT+1];
21uint32_t         task_count;
22rtems_id         Highest_id;
23
24rtems_task Low_tasks(
25  rtems_task_argument argument
26);
27
28rtems_task High_task(
29  rtems_task_argument argument
30);
31
32rtems_task Highest_task(
33  rtems_task_argument argument
34);
35
36rtems_task Restart_task(
37  rtems_task_argument argument
38);
39
40void test_init(void);
41
42rtems_task Init(
43  rtems_task_argument argument
44)
45{
46  rtems_status_code status;
47
48  Print_Warning();
49
50  puts( "\n\n*** TIME TEST 4 ***" );
51
52  test_init();
53
54  status = rtems_task_delete( RTEMS_SELF );
55  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
56}
57
58void test_init(void)
59{
60  rtems_status_code status;
61  int               index;
62
63  task_count = OPERATION_COUNT;
64
65  for ( index = 1 ; index <= OPERATION_COUNT ; index++ ) {
66
67    status = rtems_task_create(
68      rtems_build_name( 'T', 'I', 'M', 'E' ),
69      10,
70      RTEMS_MINIMUM_STACK_SIZE,
71      RTEMS_NO_PREEMPT,
72      RTEMS_DEFAULT_ATTRIBUTES,
73      &Task_id[ index ]
74    );
75    directive_failed( status, "rtems_task_create loop" );
76
77    status = rtems_task_start( Task_id[ index ], Low_tasks, 0 );
78    directive_failed( status, "rtems_task_start loop" );
79  }
80
81  status = rtems_semaphore_create(
82    rtems_build_name( 'S', 'M', '1', ' ' ),
83    0,
84    RTEMS_DEFAULT_ATTRIBUTES,
85    RTEMS_NO_PRIORITY,
86    &Semaphore_id
87  );
88  directive_failed( status, "rtems_semaphore_create of SM1" );
89}
90
91rtems_task Highest_task(
92  rtems_task_argument argument
93)
94{
95  rtems_task_priority old_priority;
96  rtems_status_code   status;
97
98  if ( argument == 1 ) {
99
100    end_time = benchmark_timer_read();
101
102    put_time(
103      "rtems_task_restart: blocked task -- preempts caller",
104      end_time,
105      1,
106      0,
107      CALLING_OVERHEAD_TASK_RESTART
108    );
109
110    status = rtems_task_set_priority(
111      RTEMS_CURRENT_PRIORITY,
112      RTEMS_MAXIMUM_PRIORITY - 1u,
113      &old_priority
114    );
115    directive_failed( status, "rtems_task_set_priority" );
116
117 } else if ( argument == 2 ) {
118
119  end_time = benchmark_timer_read();
120
121    put_time(
122      "rtems_task_restart: ready task -- preempts caller",
123      end_time,
124      1,
125      0,
126      CALLING_OVERHEAD_TASK_RESTART
127    );
128
129    status = rtems_task_delete( RTEMS_SELF );
130    directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
131
132  } else
133    (void) rtems_semaphore_obtain(
134      Semaphore_id,
135      RTEMS_DEFAULT_OPTIONS,
136      RTEMS_NO_TIMEOUT
137    );
138
139}
140
141rtems_task High_task(
142  rtems_task_argument argument
143)
144{
145  rtems_status_code   status;
146  uint32_t      index;
147  rtems_name          name;
148  rtems_task_priority old_priority;
149
150  benchmark_timer_initialize();
151    (void) rtems_task_restart( Highest_id, 1 );
152  /* preempted by Higher_task */
153
154  benchmark_timer_initialize();
155    (void) rtems_task_restart( Highest_id, 2 );
156  /* preempted by Higher_task */
157
158  benchmark_timer_initialize();
159    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
160      (void) benchmark_timer_empty_function();
161  overhead = benchmark_timer_read();
162
163  benchmark_timer_initialize();
164    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
165      rtems_semaphore_release( Semaphore_id );
166  end_time = benchmark_timer_read();
167
168  put_time(
169    "rtems_semaphore_release: task readied -- returns to caller",
170    end_time,
171    OPERATION_COUNT,
172    0,
173    CALLING_OVERHEAD_SEMAPHORE_RELEASE
174  );
175
176  name = rtems_build_name( 'T', 'I', 'M', 'E' );
177
178  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
179    status = rtems_task_delete( Task_id[index] );
180    directive_failed( status, "rtems_task_delete" );
181  }
182
183  benchmark_timer_initialize();
184    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
185     rtems_task_create(
186        name,
187        10,
188        RTEMS_MINIMUM_STACK_SIZE,
189        RTEMS_NO_PREEMPT,
190        RTEMS_DEFAULT_ATTRIBUTES,
191        &Task_id[ index ]
192      );
193  end_time = benchmark_timer_read();
194
195  put_time(
196    "rtems_task_create",
197    end_time,
198    OPERATION_COUNT,
199    overhead,
200    CALLING_OVERHEAD_TASK_CREATE
201  );
202
203  benchmark_timer_initialize();
204    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
205      rtems_task_start( Task_id[ index ], Low_tasks, 0 );
206
207  end_time = benchmark_timer_read();
208
209  put_time(
210    "rtems_task_start",
211    end_time,
212    OPERATION_COUNT,
213    overhead,
214    CALLING_OVERHEAD_TASK_START
215  );
216
217  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
218    status = rtems_task_delete( Task_id[ index ] );
219    directive_failed( status, "rtems_task_delete" );
220  }
221
222  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
223    status = rtems_task_create(
224      name,
225      RTEMS_MAXIMUM_PRIORITY - 4u,
226      RTEMS_MINIMUM_STACK_SIZE,
227      RTEMS_NO_PREEMPT,
228      RTEMS_DEFAULT_ATTRIBUTES,
229      &Task_id[ index ]
230    );
231    directive_failed( status, "rtems_task_create LOOP 1" );
232
233    status = rtems_task_start( Task_id[ index ], Restart_task, 0 );
234    directive_failed( status, "rtems_task_start LOOP 1" );
235
236    status = rtems_task_suspend( Task_id[ index ] );
237    directive_failed( status, "rtems_task_suspend LOOP 1" );
238  }
239
240  benchmark_timer_initialize();
241    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
242      (void) rtems_task_restart( Task_id[ index ], 0 );
243  end_time = benchmark_timer_read();
244
245  put_time(
246    "rtems_task_restart: suspended task -- returns to caller",
247    end_time,
248    OPERATION_COUNT,
249    overhead,
250    CALLING_OVERHEAD_TASK_RESTART
251  );
252
253  for ( index=1 ; index <= OPERATION_COUNT ; index++ )
254    (void) rtems_task_suspend( Task_id[ index ] );
255
256  benchmark_timer_initialize();
257    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
258      (void) rtems_task_delete( Task_id[ index ] );
259  end_time = benchmark_timer_read();
260
261  put_time(
262    "rtems_task_delete: suspended task",
263    end_time,
264    OPERATION_COUNT,
265    overhead,
266    CALLING_OVERHEAD_TASK_DELETE
267  );
268
269  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
270    status = rtems_task_create(
271      name,
272      RTEMS_MAXIMUM_PRIORITY - 4u,
273      RTEMS_MINIMUM_STACK_SIZE,
274      RTEMS_DEFAULT_MODES,
275      RTEMS_DEFAULT_ATTRIBUTES,
276      &Task_id[ index ]
277    );
278    directive_failed( status, "rtems_task_create LOOP 2" );
279
280    status = rtems_task_start( Task_id[ index ], Restart_task, 0 );
281    directive_failed( status, "rtems_task_start LOOP 2" );
282  }
283
284  benchmark_timer_initialize();
285    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
286      (void) rtems_task_restart( Task_id[ index ], 1 );
287  end_time = benchmark_timer_read();
288
289  put_time(
290    "rtems_task_restart: ready task -- returns to caller",
291    end_time,
292    OPERATION_COUNT,
293    overhead,
294    CALLING_OVERHEAD_TASK_RESTART
295  );
296
297  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
298    status = rtems_task_set_priority( Task_id[ index ], 5, &old_priority );
299    directive_failed( status, "rtems_task_set_priority loop" );
300  }
301
302  /* yield processor -- tasks block */
303  status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
304  directive_failed( status, "rtems_task_wake_after" );
305
306  benchmark_timer_initialize();
307    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
308      (void) rtems_task_restart( Task_id[ index ], 1 );
309  end_time = benchmark_timer_read();
310
311  put_time(
312    "rtems_task_restart: blocked task -- returns to caller",
313    end_time,
314    OPERATION_COUNT,
315    overhead,
316    CALLING_OVERHEAD_TASK_RESTART
317  );
318
319  /* yield processor -- tasks block */
320  status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
321  directive_failed( status, "rtems_task_wake_after" );
322
323  benchmark_timer_initialize();
324    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
325      (void) rtems_task_delete( Task_id[ index ] );
326  end_time = benchmark_timer_read();
327
328  put_time(
329    "rtems_task_delete: blocked task",
330    end_time,
331    OPERATION_COUNT,
332    overhead,
333    CALLING_OVERHEAD_TASK_DELETE
334  );
335
336  puts( "*** END OF TEST 4 ***" );
337  rtems_test_exit( 0 );
338}
339
340rtems_task Low_tasks(
341  rtems_task_argument argument
342)
343{
344  rtems_id          id;
345  rtems_status_code status;
346
347  task_count--;
348
349  if ( task_count == 0 ) {
350    status = rtems_task_create(
351      rtems_build_name( 'H', 'I', ' ', ' ' ),
352      5,
353      RTEMS_MINIMUM_STACK_SIZE,
354      RTEMS_DEFAULT_MODES,
355      RTEMS_DEFAULT_ATTRIBUTES,
356      &id
357    );
358    directive_failed( status, "rtems_task_create HI" );
359
360    status = rtems_task_start( id, High_task, 0 );
361    directive_failed( status, "rtems_task_start HI" );
362
363    status = rtems_task_create(
364      rtems_build_name( 'H', 'I', 'G', 'H' ),
365      3,
366      RTEMS_MINIMUM_STACK_SIZE,
367      RTEMS_DEFAULT_MODES,
368      RTEMS_DEFAULT_ATTRIBUTES,
369      &Highest_id
370    );
371    directive_failed( status, "rtems_task_create HIGH" );
372
373    status = rtems_task_start( Highest_id, Highest_task, 0 );
374    directive_failed( status, "rtems_task_start HIGH" );
375
376  }
377  (void) rtems_semaphore_obtain(
378    Semaphore_id,
379    RTEMS_DEFAULT_OPTIONS,
380    RTEMS_NO_TIMEOUT
381  );
382}
383
384rtems_task Restart_task(
385  rtems_task_argument argument
386)
387{
388  if ( argument == 1 )
389    (void) rtems_semaphore_obtain(
390      Semaphore_id,
391      RTEMS_DEFAULT_OPTIONS,
392      RTEMS_NO_TIMEOUT
393    );
394}
Note: See TracBrowser for help on using the repository browser.