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

4.115
Last change on this file since df40cc9 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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