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 15";
0043 
0044 bool     time_set;
0045 uint32_t eventout;
0046 
0047 rtems_task High_tasks(
0048   rtems_task_argument argument
0049 );
0050 
0051 rtems_task Low_task(
0052   rtems_task_argument argument
0053 );
0054 
0055 void test_init(void);
0056 
0057 rtems_task Init(
0058   rtems_task_argument argument
0059 )
0060 {
0061   Print_Warning();
0062 
0063   TEST_BEGIN();
0064 
0065   test_init();
0066 
0067   rtems_task_exit();
0068 }
0069 
0070 void test_init(void)
0071 {
0072   rtems_id          id;
0073   uint32_t    index;
0074   rtems_event_set   event_out;
0075   rtems_status_code status;
0076 
0077   time_set = false;
0078 
0079   status = rtems_task_create(
0080     rtems_build_name( 'L', 'O', 'W', ' ' ),
0081     10,
0082     RTEMS_MINIMUM_STACK_SIZE,
0083     RTEMS_NO_PREEMPT,
0084     RTEMS_DEFAULT_ATTRIBUTES,
0085     &id
0086   );
0087   directive_failed( status, "rtems_task_create LOW" );
0088 
0089   status = rtems_task_start( id, Low_task, 0 );
0090   directive_failed( status, "rtems_task_start LOW" );
0091 
0092   for ( index = 1 ; index <= OPERATION_COUNT ; index++ ) {
0093     status = rtems_task_create(
0094       rtems_build_name( 'H', 'I', 'G', 'H' ),
0095       5,
0096       RTEMS_MINIMUM_STACK_SIZE,
0097       RTEMS_DEFAULT_MODES,
0098       RTEMS_DEFAULT_ATTRIBUTES,
0099       &Task_id[ index ]
0100     );
0101     directive_failed( status, "rtems_task_create LOOP" );
0102 
0103     status = rtems_task_start( Task_id[ index ], High_tasks, 0 );
0104     directive_failed( status, "rtems_task_start LOOP" );
0105   }
0106 
0107   benchmark_timer_initialize();
0108     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0109       (void) benchmark_timer_empty_function();
0110   overhead = benchmark_timer_read();
0111 
0112   benchmark_timer_initialize();
0113     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0114     {
0115         (void) rtems_event_receive(
0116                  RTEMS_PENDING_EVENTS,
0117                  RTEMS_DEFAULT_OPTIONS,
0118                  RTEMS_NO_TIMEOUT,
0119                  &event_out
0120                );
0121     }
0122 
0123   end_time = benchmark_timer_read();
0124 
0125   put_time(
0126     "rtems_event_receive: obtain current events",
0127     end_time,
0128     OPERATION_COUNT,
0129     overhead,
0130     0
0131   );
0132 
0133 
0134   benchmark_timer_initialize();
0135     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0136     {
0137       (void) rtems_event_receive(
0138                RTEMS_ALL_EVENTS,
0139                RTEMS_NO_WAIT,
0140                RTEMS_NO_TIMEOUT,
0141                &event_out
0142              );
0143     }
0144   end_time = benchmark_timer_read();
0145 
0146   put_time(
0147     "rtems_event_receive: not available NO_WAIT",
0148     end_time,
0149     OPERATION_COUNT,
0150     overhead,
0151     0
0152   );
0153 }
0154 
0155 rtems_task Low_task(
0156   rtems_task_argument argument
0157 )
0158 {
0159   uint32_t    index;
0160   rtems_event_set   event_out;
0161 
0162   end_time = benchmark_timer_read();
0163 
0164   put_time(
0165     "rtems_event_receive: not available caller blocks",
0166     end_time,
0167     OPERATION_COUNT,
0168     0,
0169     0
0170   );
0171 
0172   benchmark_timer_initialize();
0173     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0174       (void) benchmark_timer_empty_function();
0175   overhead = benchmark_timer_read();
0176 
0177   benchmark_timer_initialize();
0178     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0179       (void) rtems_event_send( RTEMS_SELF, RTEMS_EVENT_16 );
0180   end_time = benchmark_timer_read();
0181 
0182   put_time(
0183     "rtems_event_send: no task readied",
0184     end_time,
0185     OPERATION_COUNT,
0186     overhead,
0187     0
0188   );
0189 
0190   benchmark_timer_initialize();
0191     (void) rtems_event_receive(
0192              RTEMS_EVENT_16,
0193              RTEMS_DEFAULT_OPTIONS,
0194              RTEMS_NO_TIMEOUT,
0195              &event_out
0196            );
0197   end_time = benchmark_timer_read();
0198 
0199   put_time(
0200     "rtems_event_receive: available",
0201     end_time,
0202     1,
0203     0,
0204     0
0205   );
0206 
0207   benchmark_timer_initialize();
0208     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0209       (void) rtems_event_send( Task_id[ index ], RTEMS_EVENT_16 );
0210   end_time = benchmark_timer_read();
0211 
0212   put_time(
0213     "rtems_event_send: task readied returns to caller",
0214     end_time,
0215     OPERATION_COUNT,
0216     overhead,
0217     0
0218   );
0219 
0220   TEST_END();
0221   rtems_test_exit( 0 );
0222 }
0223 
0224 rtems_task High_tasks(
0225   rtems_task_argument argument
0226 )
0227 {
0228   if ( time_set )
0229     (void) rtems_event_receive(
0230       RTEMS_EVENT_16,
0231       RTEMS_DEFAULT_OPTIONS,
0232       RTEMS_NO_TIMEOUT,
0233       &eventout
0234     );
0235   else {
0236     time_set = true;
0237     /* start blocking rtems_event_receive time */
0238     benchmark_timer_initialize();
0239     (void) rtems_event_receive(
0240       RTEMS_EVENT_16,
0241       RTEMS_DEFAULT_OPTIONS,
0242       RTEMS_NO_TIMEOUT,
0243       &eventout
0244     );
0245   }
0246 }