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 4";
0043 
0044 rtems_id         Semaphore_id;
0045 rtems_id         Task_id[OPERATION_COUNT+1];
0046 uint32_t         task_count;
0047 rtems_id         Highest_id;
0048 
0049 rtems_task Low_tasks(
0050   rtems_task_argument argument
0051 );
0052 
0053 rtems_task High_task(
0054   rtems_task_argument argument
0055 );
0056 
0057 rtems_task Highest_task(
0058   rtems_task_argument argument
0059 );
0060 
0061 rtems_task Restart_task(
0062   rtems_task_argument argument
0063 );
0064 
0065 void test_init(void);
0066 
0067 rtems_task Init(
0068   rtems_task_argument argument
0069 )
0070 {
0071   Print_Warning();
0072 
0073   TEST_BEGIN();
0074 
0075   test_init();
0076 
0077   rtems_task_exit();
0078 }
0079 
0080 void test_init(void)
0081 {
0082   rtems_status_code status;
0083   int               index;
0084 
0085   task_count = OPERATION_COUNT;
0086 
0087   for ( index = 1 ; index <= OPERATION_COUNT ; index++ ) {
0088 
0089     status = rtems_task_create(
0090       rtems_build_name( 'T', 'I', 'M', 'E' ),
0091       10,
0092       RTEMS_MINIMUM_STACK_SIZE,
0093       RTEMS_NO_PREEMPT,
0094       RTEMS_DEFAULT_ATTRIBUTES,
0095       &Task_id[ index ]
0096     );
0097     directive_failed( status, "rtems_task_create loop" );
0098 
0099     status = rtems_task_start( Task_id[ index ], Low_tasks, 0 );
0100     directive_failed( status, "rtems_task_start loop" );
0101   }
0102 
0103   status = rtems_semaphore_create(
0104     rtems_build_name( 'S', 'M', '1', ' ' ),
0105     0,
0106     RTEMS_DEFAULT_ATTRIBUTES,
0107     RTEMS_NO_PRIORITY,
0108     &Semaphore_id
0109   );
0110   directive_failed( status, "rtems_semaphore_create of SM1" );
0111 }
0112 
0113 rtems_task Highest_task(
0114   rtems_task_argument argument
0115 )
0116 {
0117   rtems_task_priority old_priority;
0118   rtems_status_code   status;
0119 
0120   if ( argument == 1 ) {
0121 
0122     end_time = benchmark_timer_read();
0123 
0124     put_time(
0125       "rtems_task_restart: blocked task preempts caller",
0126       end_time,
0127       1,
0128       0,
0129       0
0130     );
0131 
0132     status = rtems_task_set_priority(
0133       RTEMS_CURRENT_PRIORITY,
0134       RTEMS_MAXIMUM_PRIORITY - 1u,
0135       &old_priority
0136     );
0137     directive_failed( status, "rtems_task_set_priority" );
0138 
0139  } else if ( argument == 2 ) {
0140 
0141   end_time = benchmark_timer_read();
0142 
0143     put_time(
0144       "rtems_task_restart: ready task -- preempts caller",
0145       end_time,
0146       1,
0147       0,
0148       0
0149     );
0150 
0151     rtems_task_exit();
0152   } else
0153     (void) rtems_semaphore_obtain(
0154       Semaphore_id,
0155       RTEMS_DEFAULT_OPTIONS,
0156       RTEMS_NO_TIMEOUT
0157     );
0158 
0159 }
0160 
0161 rtems_task High_task(
0162   rtems_task_argument argument
0163 )
0164 {
0165   rtems_status_code   status;
0166   uint32_t      index;
0167   rtems_name          name;
0168   rtems_task_priority old_priority;
0169 
0170   benchmark_timer_initialize();
0171     (void) rtems_task_restart( Highest_id, 1 );
0172   /* preempted by Higher_task */
0173 
0174   benchmark_timer_initialize();
0175     (void) rtems_task_restart( Highest_id, 2 );
0176   /* preempted by Higher_task */
0177 
0178   benchmark_timer_initialize();
0179     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0180       (void) benchmark_timer_empty_function();
0181   overhead = benchmark_timer_read();
0182 
0183   benchmark_timer_initialize();
0184     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0185       rtems_semaphore_release( Semaphore_id );
0186   end_time = benchmark_timer_read();
0187 
0188   put_time(
0189     "rtems_semaphore_release: task readied -- returns to caller",
0190     end_time,
0191     OPERATION_COUNT,
0192     0,
0193     0
0194   );
0195 
0196   name = rtems_build_name( 'T', 'I', 'M', 'E' );
0197 
0198   for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
0199     status = rtems_task_delete( Task_id[index] );
0200     directive_failed( status, "rtems_task_delete" );
0201   }
0202 
0203   benchmark_timer_initialize();
0204     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0205      rtems_task_create(
0206         name,
0207         10,
0208         RTEMS_MINIMUM_STACK_SIZE,
0209         RTEMS_NO_PREEMPT,
0210         RTEMS_DEFAULT_ATTRIBUTES,
0211         &Task_id[ index ]
0212       );
0213   end_time = benchmark_timer_read();
0214 
0215   put_time(
0216     "rtems_task_create: only case",
0217     end_time,
0218     OPERATION_COUNT,
0219     overhead,
0220     0
0221   );
0222 
0223   benchmark_timer_initialize();
0224     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0225       rtems_task_start( Task_id[ index ], Low_tasks, 0 );
0226 
0227   end_time = benchmark_timer_read();
0228 
0229   put_time(
0230     "rtems_task_start: only case",
0231     end_time,
0232     OPERATION_COUNT,
0233     overhead,
0234     0
0235   );
0236 
0237   for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
0238     status = rtems_task_delete( Task_id[ index ] );
0239     directive_failed( status, "rtems_task_delete" );
0240   }
0241 
0242   for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
0243     status = rtems_task_create(
0244       name,
0245       RTEMS_MAXIMUM_PRIORITY - 4u,
0246       RTEMS_MINIMUM_STACK_SIZE,
0247       RTEMS_NO_PREEMPT,
0248       RTEMS_DEFAULT_ATTRIBUTES,
0249       &Task_id[ index ]
0250     );
0251     directive_failed( status, "rtems_task_create LOOP 1" );
0252 
0253     status = rtems_task_start( Task_id[ index ], Restart_task, 0 );
0254     directive_failed( status, "rtems_task_start LOOP 1" );
0255 
0256     status = rtems_task_suspend( Task_id[ index ] );
0257     directive_failed( status, "rtems_task_suspend LOOP 1" );
0258   }
0259 
0260   benchmark_timer_initialize();
0261     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0262       (void) rtems_task_restart( Task_id[ index ], 0 );
0263   end_time = benchmark_timer_read();
0264 
0265   put_time(
0266     "rtems_task_restart: suspended task -- returns to caller",
0267     end_time,
0268     OPERATION_COUNT,
0269     overhead,
0270     0
0271   );
0272 
0273   for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0274     (void) rtems_task_suspend( Task_id[ index ] );
0275 
0276   benchmark_timer_initialize();
0277     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0278       (void) rtems_task_delete( Task_id[ index ] );
0279   end_time = benchmark_timer_read();
0280 
0281   put_time(
0282     "rtems_task_delete: suspended task",
0283     end_time,
0284     OPERATION_COUNT,
0285     overhead,
0286     0
0287   );
0288 
0289   for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
0290     status = rtems_task_create(
0291       name,
0292       RTEMS_MAXIMUM_PRIORITY - 4u,
0293       RTEMS_MINIMUM_STACK_SIZE,
0294       RTEMS_DEFAULT_MODES,
0295       RTEMS_DEFAULT_ATTRIBUTES,
0296       &Task_id[ index ]
0297     );
0298     directive_failed( status, "rtems_task_create LOOP 2" );
0299 
0300     status = rtems_task_start( Task_id[ index ], Restart_task, 0 );
0301     directive_failed( status, "rtems_task_start LOOP 2" );
0302   }
0303 
0304   benchmark_timer_initialize();
0305     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0306       (void) rtems_task_restart( Task_id[ index ], 1 );
0307   end_time = benchmark_timer_read();
0308 
0309   put_time(
0310     "rtems_task_restart: ready task -- returns to caller",
0311     end_time,
0312     OPERATION_COUNT,
0313     overhead,
0314     0
0315   );
0316 
0317   for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
0318     status = rtems_task_set_priority( Task_id[ index ], 5, &old_priority );
0319     directive_failed( status, "rtems_task_set_priority loop" );
0320   }
0321 
0322   /* yield processor -- tasks block */
0323   status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
0324   directive_failed( status, "rtems_task_wake_after" );
0325 
0326   benchmark_timer_initialize();
0327     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0328       (void) rtems_task_restart( Task_id[ index ], 1 );
0329   end_time = benchmark_timer_read();
0330 
0331   put_time(
0332     "rtems_task_restart: blocked task -- returns to caller",
0333     end_time,
0334     OPERATION_COUNT,
0335     overhead,
0336     0
0337   );
0338 
0339   /* yield processor -- tasks block */
0340   status = rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
0341   directive_failed( status, "rtems_task_wake_after" );
0342 
0343   benchmark_timer_initialize();
0344     for ( index=1 ; index <= OPERATION_COUNT ; index++ )
0345       (void) rtems_task_delete( Task_id[ index ] );
0346   end_time = benchmark_timer_read();
0347 
0348   put_time(
0349     "rtems_task_delete: blocked task",
0350     end_time,
0351     OPERATION_COUNT,
0352     overhead,
0353     0
0354   );
0355 
0356   TEST_END();
0357   rtems_test_exit( 0 );
0358 }
0359 
0360 rtems_task Low_tasks(
0361   rtems_task_argument argument
0362 )
0363 {
0364   rtems_id          id;
0365   rtems_status_code status;
0366   rtems_mode        prev;
0367 
0368   task_count--;
0369 
0370   if ( task_count == 0 ) {
0371     status = rtems_task_create(
0372       rtems_build_name( 'H', 'I', ' ', ' ' ),
0373       5,
0374       RTEMS_MINIMUM_STACK_SIZE,
0375       RTEMS_DEFAULT_MODES,
0376       RTEMS_DEFAULT_ATTRIBUTES,
0377       &id
0378     );
0379     directive_failed( status, "rtems_task_create HI" );
0380 
0381     status = rtems_task_start( id, High_task, 0 );
0382     directive_failed( status, "rtems_task_start HI" );
0383 
0384     status = rtems_task_create(
0385       rtems_build_name( 'H', 'I', 'G', 'H' ),
0386       3,
0387       RTEMS_MINIMUM_STACK_SIZE,
0388       RTEMS_DEFAULT_MODES,
0389       RTEMS_DEFAULT_ATTRIBUTES,
0390       &Highest_id
0391     );
0392     directive_failed( status, "rtems_task_create HIGH" );
0393 
0394     status = rtems_task_start( Highest_id, Highest_task, 0 );
0395     directive_failed( status, "rtems_task_start HIGH" );
0396 
0397   }
0398   (void) rtems_semaphore_obtain(
0399     Semaphore_id,
0400     RTEMS_DEFAULT_OPTIONS,
0401     RTEMS_NO_TIMEOUT
0402   );
0403 
0404   rtems_task_mode(RTEMS_PREEMPT, RTEMS_PREEMPT_MASK, &prev);
0405 }
0406 
0407 rtems_task Restart_task(
0408   rtems_task_argument argument
0409 )
0410 {
0411   if ( argument == 1 )
0412     (void) rtems_semaphore_obtain(
0413       Semaphore_id,
0414       RTEMS_DEFAULT_OPTIONS,
0415       RTEMS_NO_TIMEOUT
0416     );
0417 }