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 const char rtems_test_name[] = "RHTASKPREEMPT";
0011 
0012 #define BENCHMARKS 50000   /* Number of benchmarks to run and average over */
0013 
0014 rtems_task Task02( rtems_task_argument ignored );
0015 rtems_task Task01( 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 
0021 uint32_t           telapsed;          /* total time elapsed during benchmark */
0022 uint32_t           tloop_overhead;    /* overhead of loops */
0023 uint32_t           tswitch_overhead;  /* overhead of time it takes to switch
0024                                        * from TA02 to TA01, includes rtems_suspend
0025                                        * overhead
0026                                        */
0027 unsigned long      count1;
0028 rtems_status_code  status;
0029 
0030 rtems_task Task01( rtems_task_argument ignored )
0031 {
0032   /* Start up TA02, get preempted */
0033   status = rtems_task_start( Task_id[1], Task02, 0);
0034   directive_failed( status, "rtems_task_start of TA02");
0035 
0036   tswitch_overhead = benchmark_timer_read();
0037 
0038   benchmark_timer_initialize();
0039   /* Benchmark code */
0040   for ( count1 = 0; count1 < BENCHMARKS; count1++ ) {
0041     rtems_task_resume( Task_id[1] );  /* Awaken TA02, preemption occurs */
0042   }
0043 
0044   /* Should never reach here */
0045   rtems_test_assert( false );
0046 }
0047 
0048 rtems_task Task02( rtems_task_argument ignored )
0049 {
0050   /* Find overhead of task switch back to TA01 (not a preemption) */
0051   benchmark_timer_initialize();
0052   rtems_task_suspend( RTEMS_SELF );
0053 
0054   /* Benchmark code */
0055   for ( ; count1 < BENCHMARKS - 1; ) {
0056     rtems_task_suspend( RTEMS_SELF );
0057   }
0058 
0059   telapsed = benchmark_timer_read();
0060   put_time(
0061      "Rhealstone: Task Preempt",
0062      telapsed,                     /* Total time of all benchmarks */
0063      BENCHMARKS - 1,               /* BENCHMARKS - 1 total preemptions */
0064      tloop_overhead,               /* Overhead of loops */
0065      tswitch_overhead              /* Overhead of task switch back to TA01 */
0066   );
0067 
0068   TEST_END();
0069   rtems_test_exit( 0 );
0070 }
0071 
0072 rtems_task Init( rtems_task_argument ignored )
0073 {
0074   Print_Warning();
0075 
0076   TEST_BEGIN();
0077 
0078   Task_name[0] = rtems_build_name( 'T','A','0','1' );
0079   status = rtems_task_create(
0080     Task_name[0],
0081     30,               /* TA01 is low priority task */
0082     RTEMS_MINIMUM_STACK_SIZE,
0083     RTEMS_DEFAULT_MODES,
0084     RTEMS_DEFAULT_ATTRIBUTES,
0085     &Task_id[0]
0086   );
0087   directive_failed( status, "rtems_task_create of TA01");
0088 
0089   Task_name[1] = rtems_build_name( 'T','A','0','2' );
0090   status = rtems_task_create(
0091     Task_name[1],
0092     28,               /* TA02 is high priority task */
0093     RTEMS_MINIMUM_STACK_SIZE,
0094     RTEMS_DEFAULT_MODES,
0095     RTEMS_DEFAULT_ATTRIBUTES,
0096     &Task_id[1]
0097   );
0098   directive_failed( status, "rtems_task_create of TA02");
0099 
0100   /* Find loop overhead */
0101   benchmark_timer_initialize();
0102   for ( count1 = 0; count1 < ( BENCHMARKS * 2 ) - 1; count1++ ) {
0103      /* no statement */ ;
0104   }
0105   tloop_overhead = benchmark_timer_read();
0106 
0107   status = rtems_task_start( Task_id[0], Task01, 0 );
0108   directive_failed( status, "rtems_task_start of TA01");
0109 
0110   rtems_task_exit();
0111 }
0112 
0113 /* configuration information */
0114 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0115 #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
0116 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0117 #define CONFIGURE_MAXIMUM_TASKS 3
0118 #define CONFIGURE_INIT
0119 #include <rtems/confdefs.h>