Back to home page

LXR

 
 

    


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

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";
0043 
0044 rtems_task Test_task(
0045   rtems_task_argument argument
0046 );
0047 
0048 rtems_task Init(
0049   rtems_task_argument argument
0050 )
0051 {
0052   rtems_status_code status;
0053 
0054   Print_Warning();
0055 
0056   TEST_BEGIN();
0057 
0058   Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' );
0059   Task_name[ 2 ] = rtems_build_name( 'T', 'A', '2', ' ' );
0060   Task_name[ 3 ] = rtems_build_name( 'T', 'A', '3', ' ' );
0061 
0062   status = rtems_task_create(
0063     Task_name[ 1 ],
0064     (RTEMS_MAXIMUM_PRIORITY / 2u) + 1u,
0065     RTEMS_MINIMUM_STACK_SIZE,
0066     RTEMS_DEFAULT_MODES,
0067     RTEMS_DEFAULT_ATTRIBUTES,
0068     &Task_id[ 1 ]
0069   );
0070   directive_failed( status, "rtems_task_create of TA1" );
0071 
0072   status = rtems_task_start( Task_id[ 1 ], Test_task, 0 );
0073   directive_failed( status, "rtems_task_start of TA1" );
0074 
0075   rtems_task_exit();
0076 }
0077 
0078 rtems_task Test_task(
0079   rtems_task_argument argument
0080 )
0081 {
0082   uint32_t    semaphore_obtain_time;
0083   uint32_t    semaphore_release_time;
0084   uint32_t    semaphore_obtain_no_wait_time;
0085   uint32_t    semaphore_obtain_loop_time;
0086   uint32_t    semaphore_release_loop_time;
0087   uint32_t    index;
0088   uint32_t    iterations;
0089   rtems_name        name;
0090   rtems_id          smid;
0091   rtems_status_code status;
0092 
0093   name = rtems_build_name( 'S', 'M', '1', ' ' );
0094 
0095   semaphore_obtain_time          = 0;
0096   semaphore_release_time         = 0;
0097   semaphore_obtain_no_wait_time  = 0;
0098   semaphore_obtain_loop_time     = 0;
0099   semaphore_release_loop_time    = 0;
0100 
0101 
0102   /* Time one invocation of rtems_semaphore_create */
0103 
0104   benchmark_timer_initialize();
0105     (void) rtems_semaphore_create(
0106       name,
0107       OPERATION_COUNT,
0108       RTEMS_DEFAULT_MODES,
0109       RTEMS_NO_PRIORITY,
0110       &smid
0111     );
0112   end_time = benchmark_timer_read();
0113   put_time(
0114     "rtems_semaphore_create: only case",
0115     end_time,
0116     1,
0117     0,
0118     0
0119   );
0120 
0121   /* Time one invocation of rtems_semaphore_delete */
0122 
0123   benchmark_timer_initialize();
0124     (void) rtems_semaphore_delete( smid );
0125   end_time = benchmark_timer_read();
0126   put_time(
0127     "rtems_semaphore_delete: only case",
0128     end_time,
0129     1,
0130     0,
0131     0
0132   );
0133 
0134   status = rtems_semaphore_create(
0135     name,
0136     OPERATION_COUNT,
0137     RTEMS_DEFAULT_ATTRIBUTES,
0138     RTEMS_NO_PRIORITY,
0139     &smid
0140   );
0141   directive_failed( status, "rtems_task_create of TA1" );
0142 
0143   for ( iterations=OPERATION_COUNT ; iterations ; iterations-- ) {
0144 
0145     benchmark_timer_initialize();
0146       for ( index = 1 ; index<=OPERATION_COUNT ; index++ )
0147         (void) benchmark_timer_empty_function();
0148     end_time = benchmark_timer_read();
0149 
0150     semaphore_obtain_loop_time  += end_time;
0151     semaphore_release_loop_time += end_time;
0152 
0153     /* rtems_semaphore_obtain (available) */
0154 
0155     benchmark_timer_initialize();
0156       for ( index = 1 ; index<=OPERATION_COUNT ; index++ )
0157         (void) rtems_semaphore_obtain(
0158           smid,
0159           RTEMS_DEFAULT_OPTIONS,
0160           RTEMS_NO_TIMEOUT
0161         );
0162     end_time = benchmark_timer_read();
0163 
0164     semaphore_obtain_time += end_time;
0165 
0166     /* rtems_semaphore_release */
0167 
0168     benchmark_timer_initialize();
0169       for ( index = 1 ; index<=OPERATION_COUNT ; index++ )
0170         (void) rtems_semaphore_release( smid );
0171     end_time = benchmark_timer_read();
0172 
0173     semaphore_release_time += end_time;
0174 
0175     /* semaphore obtain (RTEMS_NO_WAIT) */
0176     benchmark_timer_initialize();
0177       for ( index = 1 ; index<=OPERATION_COUNT ; index++ )
0178         rtems_semaphore_obtain( smid, RTEMS_NO_WAIT, RTEMS_NO_TIMEOUT );
0179     semaphore_obtain_no_wait_time += benchmark_timer_read();
0180 
0181     benchmark_timer_initialize();
0182       for ( index = 1 ; index<=OPERATION_COUNT ; index++ )
0183         rtems_semaphore_release( smid );
0184     end_time = benchmark_timer_read();
0185 
0186     semaphore_release_time += end_time;
0187   }
0188 
0189   put_time(
0190     "rtems_semaphore_obtain: available",
0191     semaphore_obtain_time,
0192     OPERATION_COUNT * OPERATION_COUNT,
0193     semaphore_obtain_loop_time,
0194     0
0195   );
0196 
0197   put_time(
0198     "rtems_semaphore_obtain: not available NO_WAIT",
0199     semaphore_obtain_no_wait_time,
0200     OPERATION_COUNT * OPERATION_COUNT,
0201     semaphore_obtain_loop_time,
0202     0
0203   );
0204 
0205   put_time(
0206     "rtems_semaphore_release: no waiting tasks",
0207     semaphore_release_time,
0208     OPERATION_COUNT * OPERATION_COUNT * 2,
0209     semaphore_release_loop_time * 2,
0210     0
0211   );
0212 
0213   TEST_END();
0214   rtems_test_exit( 0 );
0215 }