Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:50

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2013.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #if !defined(OPERATION_COUNT)
0030 #define OPERATION_COUNT 100
0031 #endif
0032 
0033 #ifdef HAVE_CONFIG_H
0034 #include "config.h"
0035 #endif
0036 
0037 #include <rtems/btimer.h>
0038 
0039 #define CONFIGURE_INIT
0040 #include "system.h"
0041 
0042 const char rtems_test_name[] = "TIME TEST 20";
0043 
0044 rtems_device_major_number _STUB_major = 1;
0045 
0046 rtems_id         Region_id;
0047 rtems_name       Region_name;
0048 uint8_t    Region_area[ 2048 ] CPU_STRUCTURE_ALIGNMENT;
0049 
0050 #define PARTITION_SIZE         2048
0051 #define PARTITION_ELEMENT_SIZE  128
0052 #define PARTITION_BUFFER_POINTERS \
0053     ((PARTITION_SIZE / PARTITION_ELEMENT_SIZE) + 2)
0054 
0055 rtems_id         Partition_id;
0056 rtems_name       Partition_name;
0057 uint8_t    Partition_area[ PARTITION_SIZE ] CPU_STRUCTURE_ALIGNMENT;
0058 
0059 void  *Buffer_address_1;
0060 void  *Buffer_address_2;
0061 void  *Buffer_address_3;
0062 void  *Buffer_address_4;
0063 
0064 uint32_t   buffer_count;
0065 
0066 void  *Buffer_addresses[ PARTITION_BUFFER_POINTERS ];
0067 
0068 rtems_task Task_1(
0069   rtems_task_argument argument
0070 );
0071 
0072 rtems_task Task_2(
0073   rtems_task_argument argument
0074 );
0075 
0076 rtems_task Init(
0077   rtems_task_argument argument
0078 )
0079 {
0080   rtems_status_code status;
0081 
0082   Print_Warning();
0083 
0084   TEST_BEGIN();
0085 
0086   status = rtems_task_create(
0087     rtems_build_name( 'T', 'I', 'M', '1' ),
0088     (RTEMS_MAXIMUM_PRIORITY / 2u) + 1u,
0089     RTEMS_MINIMUM_STACK_SIZE,
0090     RTEMS_DEFAULT_MODES,
0091     RTEMS_DEFAULT_ATTRIBUTES,
0092     &Task_id[ 1 ]
0093   );
0094   directive_failed( status, "rtems_task_create of TASK1" );
0095 
0096   status = rtems_task_start( Task_id[ 1 ], Task_1, 0 );
0097   directive_failed( status, "rtems_task_start of TASK1" );
0098 
0099   status = rtems_task_create(
0100     rtems_build_name( 'T', 'I', 'M', '2' ),
0101     (RTEMS_MAXIMUM_PRIORITY / 2u) + 2u,
0102     RTEMS_MINIMUM_STACK_SIZE,
0103     RTEMS_DEFAULT_MODES,
0104     RTEMS_DEFAULT_ATTRIBUTES,
0105     &Task_id[ 2 ]
0106   );
0107   directive_failed( status, "rtems_task_create of TASK2" );
0108 
0109   status = rtems_task_start( Task_id[ 2 ], Task_2, 0 );
0110   directive_failed( status, "rtems_task_start of TASK2" );
0111 
0112   rtems_task_exit();
0113 }
0114 
0115 rtems_task Task_1(
0116   rtems_task_argument argument
0117 )
0118 {
0119   uint32_t      index;
0120   rtems_mode          previous_mode;
0121   rtems_task_priority previous_priority;
0122   rtems_status_code   status;
0123 
0124   Partition_name = rtems_build_name( 'P', 'A', 'R', 'T' );
0125 
0126   benchmark_timer_initialize();
0127     rtems_partition_create(
0128       Partition_name,
0129       Partition_area,
0130       PARTITION_SIZE,
0131       128,
0132       RTEMS_DEFAULT_ATTRIBUTES,
0133       &Partition_id
0134     );
0135   end_time = benchmark_timer_read();
0136 
0137   put_time(
0138     "rtems_partition_create: only case",
0139     end_time,
0140     1,
0141     0,
0142     0
0143   );
0144 
0145   Region_name = rtems_build_name( 'R', 'E', 'G', 'N' );
0146 
0147   benchmark_timer_initialize();
0148     rtems_region_create(
0149       Region_name,
0150       Region_area,
0151       2048,
0152       16,
0153       RTEMS_DEFAULT_ATTRIBUTES,
0154       &Region_id
0155     );
0156   end_time = benchmark_timer_read();
0157 
0158   put_time(
0159     "rtems_region_create: only case",
0160     end_time,
0161     1,
0162     0,
0163     0
0164   );
0165 
0166   benchmark_timer_initialize();
0167     (void) rtems_partition_get_buffer( Partition_id, &Buffer_address_1 );
0168   end_time = benchmark_timer_read();
0169 
0170   put_time(
0171     "rtems_partition_get_buffer: available",
0172     end_time,
0173     1,
0174     0,
0175     0
0176   );
0177 
0178   buffer_count = 0;
0179   while ( FOREVER ) {
0180 
0181     status = rtems_partition_get_buffer(
0182                Partition_id,
0183                &Buffer_addresses[ buffer_count ]
0184             );
0185 
0186     if ( status == RTEMS_UNSATISFIED ) break;
0187 
0188     buffer_count++;
0189 
0190     rtems_test_assert( buffer_count < PARTITION_BUFFER_POINTERS );
0191   }
0192 
0193   benchmark_timer_initialize();
0194     (void) rtems_partition_get_buffer( Partition_id, &Buffer_address_2 );
0195   end_time = benchmark_timer_read();
0196 
0197   put_time(
0198     "rtems_partition_get_buffer: not available",
0199     end_time,
0200     1,
0201     0,
0202     0
0203   );
0204 
0205   benchmark_timer_initialize();
0206     (void) rtems_partition_return_buffer( Partition_id, Buffer_address_1 );
0207   end_time = benchmark_timer_read();
0208 
0209   put_time(
0210     "rtems_partition_return_buffer: only case",
0211     end_time,
0212     1,
0213     0,
0214     0
0215   );
0216 
0217   for ( index = 0 ; index < buffer_count ; index++ ) {
0218 
0219     status = rtems_partition_return_buffer(
0220                Partition_id,
0221                Buffer_addresses[ index ]
0222              );
0223     directive_failed( status, "rtems_partition_return_buffer" );
0224 
0225   }
0226 
0227   benchmark_timer_initialize();
0228     (void) rtems_partition_delete( Partition_id );
0229   end_time = benchmark_timer_read();
0230 
0231   put_time(
0232     "rtems_partition_delete: only case",
0233     end_time,
0234     1,
0235     0,
0236     0
0237   );
0238 
0239   status = rtems_region_get_segment(
0240              Region_id,
0241              400,
0242              RTEMS_DEFAULT_OPTIONS,
0243              RTEMS_NO_TIMEOUT,
0244              &Buffer_address_2
0245            );
0246   directive_failed( status, "region_get_segment" );
0247 
0248   benchmark_timer_initialize();
0249     (void) rtems_region_get_segment(
0250       Region_id,
0251       400,
0252       RTEMS_DEFAULT_OPTIONS,
0253       RTEMS_NO_TIMEOUT,
0254       &Buffer_address_3
0255     );
0256   end_time = benchmark_timer_read();
0257 
0258   put_time(
0259     "rtems_region_get_segment: available",
0260     end_time,
0261     1,
0262     0,
0263     0
0264   );
0265 
0266   benchmark_timer_initialize();
0267     (void) rtems_region_get_segment(
0268       Region_id,
0269       1700,
0270       RTEMS_NO_WAIT,
0271       RTEMS_NO_TIMEOUT,
0272       &Buffer_address_4
0273     );
0274   end_time = benchmark_timer_read();
0275 
0276   put_time(
0277     "rtems_region_get_segment: not available NO_WAIT",
0278     end_time,
0279     1,
0280     0,
0281     0
0282   );
0283 
0284   status = rtems_region_return_segment( Region_id, Buffer_address_3 );
0285   directive_failed( status, "rtems_region_return_segment" );
0286 
0287   benchmark_timer_initialize();
0288     (void) rtems_region_return_segment( Region_id, Buffer_address_2 );
0289   end_time = benchmark_timer_read();
0290 
0291   put_time(
0292     "rtems_region_return_segment: no waiting tasks",
0293     end_time,
0294     1,
0295     0,
0296     0
0297   );
0298 
0299   status = rtems_region_get_segment(
0300     Region_id,
0301     400,
0302     RTEMS_DEFAULT_OPTIONS,
0303     RTEMS_NO_TIMEOUT,
0304     &Buffer_address_1
0305   );
0306   directive_failed( status, "rtems_region_get_segment" );
0307 
0308   benchmark_timer_initialize();
0309     (void) rtems_region_get_segment(
0310       Region_id,
0311       1700,
0312       RTEMS_DEFAULT_OPTIONS,
0313       RTEMS_NO_TIMEOUT,
0314       &Buffer_address_2
0315     );
0316 
0317   /* execute Task_2 */
0318 
0319   end_time = benchmark_timer_read();
0320 
0321   put_time(
0322     "rtems_region_return_segment: task readied preempts caller",
0323     end_time,
0324     1,
0325     0,
0326     0
0327   );
0328 
0329   status = rtems_region_return_segment( Region_id, Buffer_address_2 );
0330   directive_failed( status, "rtems_region_return_segment" );
0331 
0332   status = rtems_task_mode(
0333     RTEMS_NO_PREEMPT,
0334     RTEMS_PREEMPT_MASK,
0335     &previous_mode
0336   );
0337   directive_failed( status, "rtems_task_mode" );
0338 
0339   status = rtems_task_set_priority(
0340     RTEMS_SELF, RTEMS_MAXIMUM_PRIORITY - 1u, &previous_priority );
0341   directive_failed( status, "rtems_task_set_priority" );
0342 
0343   status = rtems_region_get_segment(
0344     Region_id,
0345     400,
0346     RTEMS_DEFAULT_OPTIONS,
0347     RTEMS_NO_TIMEOUT,
0348     &Buffer_address_1
0349   );
0350   directive_failed( status, "rtems_region_return_segment" );
0351 
0352   status = rtems_region_get_segment(
0353     Region_id,
0354     1700,
0355     RTEMS_DEFAULT_OPTIONS,
0356     RTEMS_NO_TIMEOUT,
0357     &Buffer_address_2
0358   );
0359   directive_failed( status, "rtems_region_get_segment" );
0360 
0361   /* execute Task_2 */
0362 
0363   status = rtems_region_return_segment( Region_id, Buffer_address_2 );
0364   directive_failed( status, "rtems_region_return_segment" );
0365 
0366   benchmark_timer_initialize();
0367     (void) rtems_region_delete( Region_id );
0368   end_time = benchmark_timer_read();
0369 
0370   put_time(
0371     "rtems_region_delete: only case",
0372     end_time,
0373     1,
0374     0,
0375     0
0376   );
0377 
0378   benchmark_timer_initialize();
0379     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0380       (void) benchmark_timer_empty_function();
0381   overhead = benchmark_timer_read();
0382 
0383   benchmark_timer_initialize();
0384     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0385       (void) rtems_io_initialize( _STUB_major, 0, NULL );
0386   end_time = benchmark_timer_read();
0387 
0388   put_time(
0389     "rtems_io_initialize: only case",
0390     end_time,
0391     OPERATION_COUNT,
0392     overhead,
0393     0
0394   );
0395 
0396   benchmark_timer_initialize();
0397     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0398       (void) rtems_io_open( _STUB_major, 0, NULL );
0399   end_time = benchmark_timer_read();
0400 
0401   put_time(
0402     "rtems_io_open: only case",
0403     end_time,
0404     OPERATION_COUNT,
0405     overhead,
0406     0
0407   );
0408 
0409   benchmark_timer_initialize();
0410     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0411       (void) rtems_io_close( _STUB_major, 0, NULL );
0412   end_time = benchmark_timer_read();
0413 
0414   put_time(
0415     "rtems_io_close: only case",
0416     end_time,
0417     OPERATION_COUNT,
0418     overhead,
0419     0
0420   );
0421 
0422   benchmark_timer_initialize();
0423     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0424       (void) rtems_io_read( _STUB_major, 0, NULL );
0425   end_time = benchmark_timer_read();
0426 
0427   put_time(
0428     "rtems_io_read: only case",
0429     end_time,
0430     OPERATION_COUNT,
0431     overhead,
0432     0
0433   );
0434 
0435   benchmark_timer_initialize();
0436     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0437       (void) rtems_io_write( _STUB_major, 0, NULL );
0438   end_time = benchmark_timer_read();
0439 
0440   put_time(
0441     "rtems_io_write: only case",
0442     end_time,
0443     OPERATION_COUNT,
0444     overhead,
0445     0
0446   );
0447 
0448   benchmark_timer_initialize();
0449     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0450       (void) rtems_io_control( _STUB_major, 0, NULL );
0451   end_time = benchmark_timer_read();
0452 
0453   put_time(
0454     "rtems_io_control: only case",
0455     end_time,
0456     OPERATION_COUNT,
0457     overhead,
0458     0
0459   );
0460 
0461   TEST_END();
0462   rtems_test_exit( 0 );
0463 }
0464 
0465 rtems_task Task_2(
0466   rtems_task_argument argument
0467 )
0468 {
0469   end_time = benchmark_timer_read();
0470 
0471   put_time(
0472     "rtems_region_get_segment: not available caller blocks",
0473     end_time,
0474     1,
0475     0,
0476     0
0477   );
0478 
0479   benchmark_timer_initialize();
0480     (void) rtems_region_return_segment( Region_id, Buffer_address_1 );
0481 
0482   /* preempt back to Task_1 */
0483 
0484   benchmark_timer_initialize();
0485     (void) rtems_region_return_segment( Region_id, Buffer_address_1 );
0486   end_time = benchmark_timer_read();
0487 
0488   put_time(
0489     "rtems_region_return_segment: task readied returns to caller",
0490     end_time,
0491     1,
0492     0,
0493     0
0494   );
0495 
0496   rtems_task_exit();
0497 }