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 29";
0043 
0044 rtems_name Period_name;
0045 
0046 rtems_task Tasks(
0047   rtems_task_argument argument
0048 );
0049 
0050 rtems_task Low_task(
0051   rtems_task_argument argument
0052 );
0053 
0054 uint32_t   Task_count;
0055 
0056 rtems_task Init(
0057   rtems_task_argument argument
0058 )
0059 {
0060   rtems_id          id;
0061   uint32_t    index;
0062   rtems_status_code status;
0063 
0064   Print_Warning();
0065 
0066   TEST_BEGIN();
0067 
0068   Period_name = rtems_build_name( 'P', 'R', 'D', ' ' );
0069 
0070   benchmark_timer_initialize();
0071     (void) rtems_rate_monotonic_create( Period_name, &id );
0072   end_time = benchmark_timer_read();
0073 
0074   put_time(
0075     "rtems_rate_monotonic_create: only case",
0076     end_time,
0077     1,
0078     0,
0079     0
0080   );
0081 
0082   benchmark_timer_initialize();
0083     (void) rtems_rate_monotonic_period( id, 10 );
0084   end_time = benchmark_timer_read();
0085 
0086   put_time(
0087     "rtems_rate_monotonic_period: initiate period returns to caller",
0088     end_time,
0089     1,
0090     0,
0091     0
0092   );
0093 
0094   benchmark_timer_initialize();
0095     (void) rtems_rate_monotonic_period( id, RTEMS_PERIOD_STATUS );
0096   end_time = benchmark_timer_read();
0097 
0098   put_time(
0099     "rtems_rate_monotonic_period: obtain status",
0100     end_time,
0101     1,
0102     0,
0103     0
0104   );
0105 
0106   benchmark_timer_initialize();
0107     (void) rtems_rate_monotonic_cancel( id );
0108   end_time = benchmark_timer_read();
0109 
0110   put_time(
0111     "rtems_rate_monotonic_cancel: only case",
0112     end_time,
0113     1,
0114     0,
0115     0
0116   );
0117 
0118   benchmark_timer_initialize();
0119     (void) rtems_rate_monotonic_delete( id );
0120   end_time = benchmark_timer_read();
0121 
0122   put_time(
0123     "rtems_rate_monotonic_delete: inactive",
0124     end_time,
0125     1,
0126     0,
0127     0
0128   );
0129 
0130   status = rtems_rate_monotonic_create( Period_name, &id );
0131   directive_failed( status, "rtems_rate_monotonic_create" );
0132 
0133   status = rtems_rate_monotonic_period( id, 10 );
0134   directive_failed( status, "rtems_rate_monotonic_period" );
0135 
0136   benchmark_timer_initialize();
0137     rtems_rate_monotonic_delete( id );
0138   end_time = benchmark_timer_read();
0139 
0140   put_time(
0141     "rtems_rate_monotonic_delete: active",
0142     end_time,
0143     1,
0144     0,
0145     0
0146   );
0147 
0148 #define LOOP_TASK_PRIORITY ((RTEMS_MAXIMUM_PRIORITY / 2u) + 1u)
0149   for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
0150     status = rtems_task_create(
0151       rtems_build_name( 'T', 'E', 'S', 'T' ),
0152       LOOP_TASK_PRIORITY,
0153       RTEMS_MINIMUM_STACK_SIZE,
0154       RTEMS_DEFAULT_MODES,
0155       RTEMS_DEFAULT_ATTRIBUTES,
0156       &id
0157     );
0158     directive_failed( status, "rtems_task_create LOOP" );
0159 
0160     status = rtems_task_start( id, Tasks, 0 );
0161     directive_failed( status, "rtems_task_start LOOP" );
0162   }
0163 
0164 #define MIDDLE_PRIORITY (RTEMS_MAXIMUM_PRIORITY - 2u)
0165   status = rtems_task_create(
0166     rtems_build_name( 'L', 'O', 'W', ' ' ),
0167     MIDDLE_PRIORITY,
0168     RTEMS_MINIMUM_STACK_SIZE,
0169     RTEMS_DEFAULT_MODES,
0170     RTEMS_DEFAULT_ATTRIBUTES,
0171     &id
0172   );
0173   directive_failed( status, "rtems_task_create LOW" );
0174 
0175   status = rtems_task_start( id, Low_task, 0 );
0176   directive_failed( status, "rtems_task_start LOW" );
0177 
0178   Task_count = 0;
0179 
0180   rtems_task_exit();
0181 }
0182 
0183 rtems_task Tasks(
0184   rtems_task_argument argument
0185 )
0186 {
0187   rtems_id          id;
0188   rtems_status_code status;
0189 
0190   status = rtems_rate_monotonic_create( 1, &id );
0191   directive_failed( status, "rtems_rate_monotonic_create" );
0192 
0193   status = rtems_rate_monotonic_period( id, 100 );
0194   directive_failed( status, "rtems_rate_monotonic_period" );
0195 
0196   /*
0197    *  Give up the processor to allow all tasks to actually
0198    *  create and start their period timer before the benchmark
0199    *  timer is initialized.
0200    */
0201 
0202   (void) rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
0203 
0204   Task_count++;
0205 
0206   if ( Task_count == 1 )
0207     benchmark_timer_initialize();
0208 
0209   (void) rtems_rate_monotonic_period( id, 100 );
0210 }
0211 
0212 rtems_task Low_task(
0213   rtems_task_argument argument
0214 )
0215 {
0216   uint32_t   index;
0217 
0218   end_time = benchmark_timer_read();
0219 
0220   benchmark_timer_initialize();
0221     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0222       (void) benchmark_timer_empty_function();
0223   overhead = benchmark_timer_read();
0224 
0225   put_time(
0226     "rtems_rate_monotonic_period: conclude periods caller blocks",
0227     end_time,
0228     OPERATION_COUNT,
0229     overhead,
0230     0
0231   );
0232 
0233   TEST_END();
0234   rtems_test_exit( 0 );
0235 }