Back to home page

LXR

 
 

    


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

0001 /*
0002  * Copyright (c) 2014 Daniel Ramirez. (javamonn@gmail.com)
0003  *
0004  * This file's license is 2-clause BSD as in this distribution's LICENSE file.
0005  */
0006 
0007 #include <timesys.h>
0008 #include <rtems/btimer.h>
0009 
0010 #define BENCHMARKS 50000
0011 
0012 const char rtems_test_name[] = "RHTASKSWITCH";
0013 
0014 rtems_task Task01( rtems_task_argument ignored );
0015 rtems_task Task02( rtems_task_argument ignored );
0016 rtems_task Init( rtems_task_argument ignored );
0017 
0018 rtems_id           Task_id[2];
0019 rtems_name         Task_name[2];
0020 uint32_t           loop_overhead;
0021 uint32_t           dir_overhead;
0022 unsigned long      count1, count2;
0023 rtems_status_code  status;
0024 
0025 rtems_task Task02( rtems_task_argument ignored )
0026 {
0027   uint32_t telapsed;
0028 
0029   /* All overhead accounted for now, we can begin benchmark */
0030   benchmark_timer_initialize();
0031 
0032   for ( count1 = 0; count1 < BENCHMARKS - 1; count1++ ) {
0033     rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
0034   }
0035 
0036   telapsed = benchmark_timer_read();
0037   put_time(
0038      "Rhealstone: Task switch",
0039      telapsed,
0040      ( BENCHMARKS * 2 ) - 1,   /* ( BENCHMARKS * 2 ) - 1 total benchmarks */
0041      loop_overhead,            /* Overhead of loop */
0042      dir_overhead              /* Overhead of rtems_task_wake_after directive */
0043   );
0044 
0045   TEST_END();
0046   rtems_test_exit( 0 );
0047 }
0048 
0049 rtems_task Task01( rtems_task_argument ignored )
0050 {
0051   status = rtems_task_start( Task_id[1], Task02, 0 );
0052   directive_failed( status, "rtems_task_start of TA02" );
0053 
0054   /* Yield processor so second task can startup and run */
0055   rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
0056 
0057   for ( count2 = 0; count2 < BENCHMARKS; count2++ ) {
0058     rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
0059   }
0060 
0061   /* Should never reach here */
0062   rtems_test_assert( false );
0063 
0064 }
0065 
0066 rtems_task Init( rtems_task_argument ignored )
0067 {
0068   Print_Warning();
0069 
0070   TEST_BEGIN();
0071 
0072   Task_name[0] = rtems_build_name( 'T','A','0','1' );
0073   status = rtems_task_create(
0074     Task_name[0],
0075     30,
0076     RTEMS_MINIMUM_STACK_SIZE,
0077     RTEMS_DEFAULT_MODES,
0078     RTEMS_DEFAULT_ATTRIBUTES,
0079     &Task_id[0]
0080   );
0081   directive_failed( status, "rtems_task_create of TA01" );
0082 
0083   Task_name[1] = rtems_build_name( 'T','A','0','2' );
0084   status = rtems_task_create(
0085     Task_name[1],
0086     30,
0087     RTEMS_MINIMUM_STACK_SIZE,
0088     RTEMS_DEFAULT_MODES,
0089     RTEMS_DEFAULT_ATTRIBUTES,
0090     &Task_id[1]
0091   );
0092   directive_failed( status, "rtems_task_create of TA02" );
0093 
0094   /* find overhead of routine (no task switches) */
0095   benchmark_timer_initialize();
0096   for ( count1 = 0; count1 < BENCHMARKS - 1; count1++ ) {
0097     /* rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ) */
0098   }
0099   for ( count2 = 0; count2 < BENCHMARKS; count2++ ) {
0100     /* rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ) */
0101   }
0102   loop_overhead = benchmark_timer_read();
0103 
0104   /* find overhead of rtems_task_wake_after call (no task switches) */
0105   benchmark_timer_initialize();
0106   rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
0107   dir_overhead = benchmark_timer_read();
0108 
0109   status = rtems_task_start( Task_id[0], Task01, 0);
0110   directive_failed( status, "rtems_task_start of TA01" );
0111 
0112   rtems_task_exit();
0113 }
0114 
0115 /* configuration information */
0116 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0117 #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
0118 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0119 #define CONFIGURE_MAXIMUM_TASKS 3
0120 #define CONFIGURE_INIT
0121 #include <rtems/confdefs.h>