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

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