summaryrefslogtreecommitdiffstats
path: root/testsuites/tmtests/tm04/task1.c
blob: 2ba3932016bf252ce886f98675a96d83b4f976e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/*
 *
 *  COPYRIGHT (c) 1989-1998.
 *  On-Line Applications Research Corporation (OAR).
 *  Copyright assigned to U.S. Government, 1994.
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.OARcorp.com/rtems/license.html.
 *
 *  $Id$
 */

#define TEST_INIT
#include "system.h"

rtems_id         Semaphore_id;
rtems_id         Task_id[OPERATION_COUNT+1];
rtems_unsigned32 task_count;
rtems_id         Highest_id;

rtems_task Low_tasks(
  rtems_task_argument argument
);

rtems_task High_task(
  rtems_task_argument argument
);

rtems_task Restart_task(
  rtems_task_argument argument
);

void test_init();

rtems_task Init(
  rtems_task_argument argument
)
{
  rtems_status_code status;

  Print_Warning();

  puts( "\n\n*** TIME TEST 4 ***" );

  test_init();

  status = rtems_task_delete( RTEMS_SELF );
  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
}

void test_init()
{
  rtems_status_code status;
  rtems_unsigned32  index;

  task_count = OPERATION_COUNT;

  for ( index = 1 ; index <= OPERATION_COUNT ; index++ ) {

    status = rtems_task_create(
      rtems_build_name( 'T', 'I', 'M', 'E' ),
      10,
      RTEMS_MINIMUM_STACK_SIZE,
      RTEMS_NO_PREEMPT,
      RTEMS_DEFAULT_ATTRIBUTES,
      &Task_id[ index ]
    );
    directive_failed( status, "rtems_task_create loop" );

    status = rtems_task_start( Task_id[ index ], Low_tasks, 0 );
    directive_failed( status, "rtems_task_start loop" );
  }

  status = rtems_semaphore_create(
    rtems_build_name( 'S', 'M', '1', ' ' ),
    0,
    RTEMS_DEFAULT_ATTRIBUTES,
    RTEMS_NO_PRIORITY,
    &Semaphore_id
  );
  directive_failed( status, "rtems_semaphore_create of SM1" );
}

rtems_task Highest_task(
  rtems_task_argument argument
)
{
  rtems_task_priority old_priority;
  rtems_status_code   status;

  if ( argument == 1 ) {

    end_time = Read_timer();

    put_time(
      "rtems_task_restart: blocked task -- preempts caller",
      end_time,
      1,
      0,
      CALLING_OVERHEAD_TASK_RESTART
    );

    status = rtems_task_set_priority(
      RTEMS_CURRENT_PRIORITY,
      254,
      &old_priority
    );
    directive_failed( status, "rtems_task_set_priority" );

 } else if ( argument == 2 ) {

  end_time = Read_timer();

    put_time(
      "rtems_task_restart: ready task -- preempts caller",
      end_time,
      1,
      0,
      CALLING_OVERHEAD_TASK_RESTART
    );

    status = rtems_task_delete( RTEMS_SELF );
    directive_failed( status, "rtems_task_delete of RTEMS_SELF" );

  } else
    (void) rtems_semaphore_obtain(
      Semaphore_id,
      RTEMS_DEFAULT_OPTIONS,
      RTEMS_NO_TIMEOUT
    );

}

rtems_task High_task(
  rtems_task_argument argument
)
{
  rtems_status_code   status;
  rtems_unsigned32    index;
  rtems_name          name;
  rtems_task_priority old_priority;

  Timer_initialize();
    (void) rtems_task_restart( Highest_id, 1 );
  /* preempted by Higher_task */

  Timer_initialize();
    (void) rtems_task_restart( Highest_id, 2 );
  /* preempted by Higher_task */

  Timer_initialize();
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
      (void) Empty_function();
  overhead = Read_timer();

  Timer_initialize();
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
      rtems_semaphore_release( Semaphore_id );
  end_time = Read_timer();

  put_time(
    "rtems_semaphore_release: task readied -- returns to caller",
    end_time,
    OPERATION_COUNT,
    0,
    CALLING_OVERHEAD_SEMAPHORE_RELEASE
  );

  name = rtems_build_name( 'T', 'I', 'M', 'E' );

  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
    status = rtems_task_delete( Task_id[index] );
    directive_failed( status, "rtems_task_delete" );
  }

  Timer_initialize();
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
     rtems_task_create(
        name,
        10,
        RTEMS_MINIMUM_STACK_SIZE,
        RTEMS_NO_PREEMPT,
        RTEMS_DEFAULT_ATTRIBUTES,
        &Task_id[ index ]
      );
  end_time = Read_timer();

  put_time(
    "rtems_task_create",
    end_time,
    OPERATION_COUNT,
    overhead,
    CALLING_OVERHEAD_TASK_CREATE
  );

  Timer_initialize();
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
      rtems_task_start( Task_id[ index ], Low_tasks, 0 );

  end_time = Read_timer();

  put_time(
    "rtems_task_start",
    end_time,
    OPERATION_COUNT,
    overhead,
    CALLING_OVERHEAD_TASK_START
  );

  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
    status = rtems_task_delete( Task_id[ index ] );
    directive_failed( status, "rtems_task_delete" );
  }

  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
    status = rtems_task_create(
      name,
      250,
      RTEMS_MINIMUM_STACK_SIZE,
      RTEMS_NO_PREEMPT,
      RTEMS_DEFAULT_ATTRIBUTES,
      &Task_id[ index ]
    );
    directive_failed( status, "rtems_task_create LOOP" );

    status = rtems_task_start( Task_id[ index ], Restart_task, 0 );
    directive_failed( status, "rtems_task_start LOOP" );

    status = rtems_task_suspend( Task_id[ index ] );
    directive_failed( status, "rtems_task_suspend LOOP" );
  }

  Timer_initialize();
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
      (void) rtems_task_restart( Task_id[ index ], 0 );
  end_time = Read_timer();

  put_time(
    "rtems_task_restart: suspended task -- returns to caller",
    end_time,
    OPERATION_COUNT,
    overhead,
    CALLING_OVERHEAD_TASK_RESTART
  );

  for ( index=1 ; index <= OPERATION_COUNT ; index++ )
    (void) rtems_task_suspend( Task_id[ index ] );

  Timer_initialize();
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
      (void) rtems_task_delete( Task_id[ index ] );
  end_time = Read_timer();

  put_time(
    "rtems_task_delete: suspended task",
    end_time,
    OPERATION_COUNT,
    overhead,
    CALLING_OVERHEAD_TASK_DELETE
  );

  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
    status = rtems_task_create(
      name,
      250,
      RTEMS_MINIMUM_STACK_SIZE,
      RTEMS_DEFAULT_MODES,
      RTEMS_DEFAULT_ATTRIBUTES,
      &Task_id[ index ]
    );
    directive_failed( status, "rtems_task_create LOOP" );

    status = rtems_task_start( Task_id[ index ], Restart_task, 0 );
    directive_failed( status, "rtems_task_start LOOP" );
  }

  Timer_initialize();
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
      (void) rtems_task_restart( Task_id[ index ], 1 );
  end_time = Read_timer();

  put_time(
    "rtems_task_restart: ready task -- returns to caller",
    end_time,
    OPERATION_COUNT,
    overhead,
    CALLING_OVERHEAD_TASK_RESTART
  );

  for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
    status = rtems_task_set_priority( Task_id[ index ], 5, &old_priority );
    directive_failed( status, "rtems_task_set_priority loop" );
  }

  /* yield processor -- tasks block */
  status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
  directive_failed( status, "rtems_task_wake_after" );

  Timer_initialize();
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
      (void) rtems_task_restart( Task_id[ index ], 1 );
  end_time = Read_timer();

  put_time(
    "rtems_task_restart: blocked task -- returns to caller",
    end_time,
    OPERATION_COUNT,
    overhead,
    CALLING_OVERHEAD_TASK_RESTART
  );

  /* yield processor -- tasks block */
  status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
  directive_failed( status, "rtems_task_wake_after" );

  Timer_initialize();
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
      (void) rtems_task_delete( Task_id[ index ] );
  end_time = Read_timer();

  put_time(
    "rtems_task_delete: blocked task",
    end_time,
    OPERATION_COUNT,
    overhead,
    CALLING_OVERHEAD_TASK_DELETE
  );

  puts( "*** END OF TEST 4 ***" );
  exit( 0 );
}

rtems_task Low_tasks(
  rtems_task_argument argument
)
{
  rtems_id          id;
  rtems_status_code status;

  task_count--;

  if ( task_count == 0 ) {
    status = rtems_task_create(
      rtems_build_name( 'H', 'I', ' ', ' ' ),
      5,
      RTEMS_MINIMUM_STACK_SIZE,
      RTEMS_DEFAULT_MODES,
      RTEMS_DEFAULT_ATTRIBUTES,
      &id
    );
    directive_failed( status, "rtems_task_create HI" );

    status = rtems_task_start( id, High_task, 0 );
    directive_failed( status, "rtems_task_start HI" );

    status = rtems_task_create(
      rtems_build_name( 'H', 'I', 'G', 'H' ),
      3,
      RTEMS_MINIMUM_STACK_SIZE,
      RTEMS_DEFAULT_MODES,
      RTEMS_DEFAULT_ATTRIBUTES,
      &Highest_id
    );
    directive_failed( status, "rtems_task_create HIGH" );

    status = rtems_task_start( Highest_id, Highest_task, 0 );
    directive_failed( status, "rtems_task_start HIGH" );

  }
  (void) rtems_semaphore_obtain(
    Semaphore_id,
    RTEMS_DEFAULT_OPTIONS,
    RTEMS_NO_TIMEOUT
  );
}

rtems_task Restart_task(
  rtems_task_argument argument
)
{
  if ( argument == 1 )
    (void) rtems_semaphore_obtain(
      Semaphore_id,
      RTEMS_DEFAULT_OPTIONS,
      RTEMS_NO_TIMEOUT
    );
}