source: rtems/testsuites/tmtests/tm20/task1.c @ e58e29fd

5
Last change on this file since e58e29fd was e58e29fd, checked in by Sebastian Huber <sebastian.huber@…>, on 11/24/17 at 06:58:55

Remove coverhd.h

This header file contained timing overhead values which are hard to
maintain.

Update #3254.

  • Property mode set to 100644
File size: 10.1 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
17const char rtems_test_name[] = "TIME TEST 20";
18
19rtems_device_major_number _STUB_major = 1;
20
21rtems_id         Region_id;
22rtems_name       Region_name;
23uint8_t    Region_area[ 2048 ] CPU_STRUCTURE_ALIGNMENT;
24
25#define PARTITION_SIZE         2048
26#define PARTITION_ELEMENT_SIZE  128
27#define PARTITION_BUFFER_POINTERS \
28    ((PARTITION_SIZE / PARTITION_ELEMENT_SIZE) + 2)
29
30rtems_id         Partition_id;
31rtems_name       Partition_name;
32uint8_t    Partition_area[ PARTITION_SIZE ] CPU_STRUCTURE_ALIGNMENT;
33
34void  *Buffer_address_1;
35void  *Buffer_address_2;
36void  *Buffer_address_3;
37void  *Buffer_address_4;
38
39uint32_t   buffer_count;
40
41void  *Buffer_addresses[ PARTITION_BUFFER_POINTERS ];
42
43rtems_task Task_1(
44  rtems_task_argument argument
45);
46
47rtems_task Task_2(
48  rtems_task_argument argument
49);
50
51rtems_task Init(
52  rtems_task_argument argument
53)
54{
55  rtems_status_code status;
56
57  Print_Warning();
58
59  TEST_BEGIN();
60
61  status = rtems_task_create(
62    rtems_build_name( 'T', 'I', 'M', '1' ),
63    (RTEMS_MAXIMUM_PRIORITY / 2u) + 1u,
64    RTEMS_MINIMUM_STACK_SIZE,
65    RTEMS_DEFAULT_MODES,
66    RTEMS_DEFAULT_ATTRIBUTES,
67    &Task_id[ 1 ]
68  );
69  directive_failed( status, "rtems_task_create of TASK1" );
70
71  status = rtems_task_start( Task_id[ 1 ], Task_1, 0 );
72  directive_failed( status, "rtems_task_start of TASK1" );
73
74  status = rtems_task_create(
75    rtems_build_name( 'T', 'I', 'M', '2' ),
76    (RTEMS_MAXIMUM_PRIORITY / 2u) + 2u,
77    RTEMS_MINIMUM_STACK_SIZE,
78    RTEMS_DEFAULT_MODES,
79    RTEMS_DEFAULT_ATTRIBUTES,
80    &Task_id[ 2 ]
81  );
82  directive_failed( status, "rtems_task_create of TASK2" );
83
84  status = rtems_task_start( Task_id[ 2 ], Task_2, 0 );
85  directive_failed( status, "rtems_task_start of TASK2" );
86
87  status = rtems_task_delete( RTEMS_SELF );
88  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
89}
90
91rtems_task Task_1(
92  rtems_task_argument argument
93)
94{
95  uint32_t      index;
96  rtems_mode          previous_mode;
97  rtems_task_priority previous_priority;
98  rtems_status_code   status;
99
100  Partition_name = rtems_build_name( 'P', 'A', 'R', 'T' );
101
102  benchmark_timer_initialize();
103    rtems_partition_create(
104      Partition_name,
105      Partition_area,
106      PARTITION_SIZE,
107      128,
108      RTEMS_DEFAULT_ATTRIBUTES,
109      &Partition_id
110    );
111  end_time = benchmark_timer_read();
112
113  put_time(
114    "rtems_partition_create: only case",
115    end_time,
116    1,
117    0,
118    0
119  );
120
121  Region_name = rtems_build_name( 'R', 'E', 'G', 'N' );
122
123  benchmark_timer_initialize();
124    rtems_region_create(
125      Region_name,
126      Region_area,
127      2048,
128      16,
129      RTEMS_DEFAULT_ATTRIBUTES,
130      &Region_id
131    );
132  end_time = benchmark_timer_read();
133
134  put_time(
135    "rtems_region_create: only case",
136    end_time,
137    1,
138    0,
139    0
140  );
141
142  benchmark_timer_initialize();
143    (void) rtems_partition_get_buffer( Partition_id, &Buffer_address_1 );
144  end_time = benchmark_timer_read();
145
146  put_time(
147    "rtems_partition_get_buffer: available",
148    end_time,
149    1,
150    0,
151    0
152  );
153
154  buffer_count = 0;
155  while ( FOREVER ) {
156
157    status = rtems_partition_get_buffer(
158               Partition_id,
159               &Buffer_addresses[ buffer_count ]
160            );
161
162    if ( status == RTEMS_UNSATISFIED ) break;
163
164    buffer_count++;
165
166    rtems_test_assert( buffer_count < PARTITION_BUFFER_POINTERS );
167  }
168
169  benchmark_timer_initialize();
170    (void) rtems_partition_get_buffer( Partition_id, &Buffer_address_2 );
171  end_time = benchmark_timer_read();
172
173  put_time(
174    "rtems_partition_get_buffer: not available",
175    end_time,
176    1,
177    0,
178    0
179  );
180
181  benchmark_timer_initialize();
182    (void) rtems_partition_return_buffer( Partition_id, Buffer_address_1 );
183  end_time = benchmark_timer_read();
184
185  put_time(
186    "rtems_partition_return_buffer: only case",
187    end_time,
188    1,
189    0,
190    0
191  );
192
193  for ( index = 0 ; index < buffer_count ; index++ ) {
194
195    status = rtems_partition_return_buffer(
196               Partition_id,
197               Buffer_addresses[ index ]
198             );
199    directive_failed( status, "rtems_partition_return_buffer" );
200
201  }
202
203  benchmark_timer_initialize();
204    (void) rtems_partition_delete( Partition_id );
205  end_time = benchmark_timer_read();
206
207  put_time(
208    "rtems_partition_delete: only case",
209    end_time,
210    1,
211    0,
212    0
213  );
214
215  status = rtems_region_get_segment(
216             Region_id,
217             400,
218             RTEMS_DEFAULT_OPTIONS,
219             RTEMS_NO_TIMEOUT,
220             &Buffer_address_2
221           );
222  directive_failed( status, "region_get_segment" );
223
224  benchmark_timer_initialize();
225    (void) rtems_region_get_segment(
226      Region_id,
227      400,
228      RTEMS_DEFAULT_OPTIONS,
229      RTEMS_NO_TIMEOUT,
230      &Buffer_address_3
231    );
232  end_time = benchmark_timer_read();
233
234  put_time(
235    "rtems_region_get_segment: available",
236    end_time,
237    1,
238    0,
239    0
240  );
241
242  benchmark_timer_initialize();
243    (void) rtems_region_get_segment(
244      Region_id,
245      1700,
246      RTEMS_NO_WAIT,
247      RTEMS_NO_TIMEOUT,
248      &Buffer_address_4
249    );
250  end_time = benchmark_timer_read();
251
252  put_time(
253    "rtems_region_get_segment: not available NO_WAIT",
254    end_time,
255    1,
256    0,
257    0
258  );
259
260  status = rtems_region_return_segment( Region_id, Buffer_address_3 );
261  directive_failed( status, "rtems_region_return_segment" );
262
263  benchmark_timer_initialize();
264    (void) rtems_region_return_segment( Region_id, Buffer_address_2 );
265  end_time = benchmark_timer_read();
266
267  put_time(
268    "rtems_region_return_segment: no waiting tasks",
269    end_time,
270    1,
271    0,
272    0
273  );
274
275  status = rtems_region_get_segment(
276    Region_id,
277    400,
278    RTEMS_DEFAULT_OPTIONS,
279    RTEMS_NO_TIMEOUT,
280    &Buffer_address_1
281  );
282  directive_failed( status, "rtems_region_get_segment" );
283
284  benchmark_timer_initialize();
285    (void) rtems_region_get_segment(
286      Region_id,
287      1700,
288      RTEMS_DEFAULT_OPTIONS,
289      RTEMS_NO_TIMEOUT,
290      &Buffer_address_2
291    );
292
293  /* execute Task_2 */
294
295  end_time = benchmark_timer_read();
296
297  put_time(
298    "rtems_region_return_segment: task readied preempts caller",
299    end_time,
300    1,
301    0,
302    0
303  );
304
305  status = rtems_region_return_segment( Region_id, Buffer_address_2 );
306  directive_failed( status, "rtems_region_return_segment" );
307
308  status = rtems_task_mode(
309    RTEMS_NO_PREEMPT,
310    RTEMS_PREEMPT_MASK,
311    &previous_mode
312  );
313  directive_failed( status, "rtems_task_mode" );
314
315  status = rtems_task_set_priority(
316    RTEMS_SELF, RTEMS_MAXIMUM_PRIORITY - 1u, &previous_priority );
317  directive_failed( status, "rtems_task_set_priority" );
318
319  status = rtems_region_get_segment(
320    Region_id,
321    400,
322    RTEMS_DEFAULT_OPTIONS,
323    RTEMS_NO_TIMEOUT,
324    &Buffer_address_1
325  );
326  directive_failed( status, "rtems_region_return_segment" );
327
328  status = rtems_region_get_segment(
329    Region_id,
330    1700,
331    RTEMS_DEFAULT_OPTIONS,
332    RTEMS_NO_TIMEOUT,
333    &Buffer_address_2
334  );
335  directive_failed( status, "rtems_region_get_segment" );
336
337  /* execute Task_2 */
338
339  status = rtems_region_return_segment( Region_id, Buffer_address_2 );
340  directive_failed( status, "rtems_region_return_segment" );
341
342  benchmark_timer_initialize();
343    (void) rtems_region_delete( Region_id );
344  end_time = benchmark_timer_read();
345
346  put_time(
347    "rtems_region_delete: only case",
348    end_time,
349    1,
350    0,
351    0
352  );
353
354  benchmark_timer_initialize();
355    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
356      (void) benchmark_timer_empty_function();
357  overhead = benchmark_timer_read();
358
359  benchmark_timer_initialize();
360    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
361      (void) rtems_io_initialize( _STUB_major, 0, NULL );
362  end_time = benchmark_timer_read();
363
364  put_time(
365    "rtems_io_initialize: only case",
366    end_time,
367    OPERATION_COUNT,
368    overhead,
369    0
370  );
371
372  benchmark_timer_initialize();
373    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
374      (void) rtems_io_open( _STUB_major, 0, NULL );
375  end_time = benchmark_timer_read();
376
377  put_time(
378    "rtems_io_open: only case",
379    end_time,
380    OPERATION_COUNT,
381    overhead,
382    0
383  );
384
385  benchmark_timer_initialize();
386    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
387      (void) rtems_io_close( _STUB_major, 0, NULL );
388  end_time = benchmark_timer_read();
389
390  put_time(
391    "rtems_io_close: only case",
392    end_time,
393    OPERATION_COUNT,
394    overhead,
395    0
396  );
397
398  benchmark_timer_initialize();
399    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
400      (void) rtems_io_read( _STUB_major, 0, NULL );
401  end_time = benchmark_timer_read();
402
403  put_time(
404    "rtems_io_read: only case",
405    end_time,
406    OPERATION_COUNT,
407    overhead,
408    0
409  );
410
411  benchmark_timer_initialize();
412    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
413      (void) rtems_io_write( _STUB_major, 0, NULL );
414  end_time = benchmark_timer_read();
415
416  put_time(
417    "rtems_io_write: only case",
418    end_time,
419    OPERATION_COUNT,
420    overhead,
421    0
422  );
423
424  benchmark_timer_initialize();
425    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
426      (void) rtems_io_control( _STUB_major, 0, NULL );
427  end_time = benchmark_timer_read();
428
429  put_time(
430    "rtems_io_control: only case",
431    end_time,
432    OPERATION_COUNT,
433    overhead,
434    0
435  );
436
437  TEST_END();
438  rtems_test_exit( 0 );
439}
440
441rtems_task Task_2(
442  rtems_task_argument argument
443)
444{
445  rtems_status_code status;
446
447  end_time = benchmark_timer_read();
448
449  put_time(
450    "rtems_region_get_segment: not available caller blocks",
451    end_time,
452    1,
453    0,
454    0
455  );
456
457  benchmark_timer_initialize();
458    (void) rtems_region_return_segment( Region_id, Buffer_address_1 );
459
460  /* preempt back to Task_1 */
461
462  benchmark_timer_initialize();
463    (void) rtems_region_return_segment( Region_id, Buffer_address_1 );
464  end_time = benchmark_timer_read();
465
466  put_time(
467    "rtems_region_return_segment: task readied returns to caller",
468    end_time,
469    1,
470    0,
471    0
472  );
473
474  status = rtems_task_delete( RTEMS_SELF );
475  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
476}
Note: See TracBrowser for help on using the repository browser.