[19e9bf8] | 1 | /* |
---|
| 2 | * Copyright (c) 2014 Daniel Ramirez. (javamonn@gmail.com) |
---|
| 3 | * |
---|
| 4 | * This file's license is 2-clause BSD as in this distribution's LICENSE file. |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | #include <rtems/timerdrv.h> |
---|
| 8 | #include <timesys.h> |
---|
| 9 | |
---|
| 10 | #define BENCHMARKS 50000 |
---|
| 11 | |
---|
| 12 | rtems_task Task01( rtems_task_argument ignored ); |
---|
| 13 | rtems_task Task02( rtems_task_argument ignored ); |
---|
| 14 | rtems_task Init( rtems_task_argument ignored ); |
---|
| 15 | |
---|
| 16 | rtems_id Task_id[2]; |
---|
| 17 | rtems_name Task_name[2]; |
---|
| 18 | uint32_t loop_overhead; |
---|
| 19 | uint32_t dir_overhead; |
---|
| 20 | unsigned long count1, count2; |
---|
| 21 | rtems_status_code status; |
---|
| 22 | |
---|
| 23 | rtems_task Task02( rtems_task_argument ignored ) |
---|
| 24 | { |
---|
| 25 | uint32_t telapsed; |
---|
| 26 | |
---|
| 27 | /* All overhead accounted for now, we can begin benchmark */ |
---|
| 28 | benchmark_timer_initialize(); |
---|
| 29 | |
---|
| 30 | for ( count1 = 0; count1 < BENCHMARKS - 1; count1++ ) { |
---|
| 31 | rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | telapsed = benchmark_timer_read(); |
---|
| 35 | put_time( |
---|
| 36 | "Rhealstone: Task switch", |
---|
| 37 | telapsed, |
---|
| 38 | ( BENCHMARKS * 2 ) - 1, /* ( BENCHMARKS * 2 ) - 1 total benchmarks */ |
---|
| 39 | loop_overhead, /* Overhead of loop */ |
---|
| 40 | dir_overhead /* Overhead of rtems_task_wake_after directive */ |
---|
| 41 | ); |
---|
| 42 | |
---|
| 43 | rtems_test_exit( 0 ); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | rtems_task Task01( rtems_task_argument ignored ) |
---|
| 47 | { |
---|
| 48 | status = rtems_task_start( Task_id[1], Task02, 0 ); |
---|
| 49 | directive_failed( status, "rtems_task_start of TA02" ); |
---|
| 50 | |
---|
| 51 | /* Yield processor so second task can startup and run */ |
---|
| 52 | rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); |
---|
| 53 | |
---|
| 54 | for ( count2 = 0; count2 < BENCHMARKS; count2++ ) { |
---|
| 55 | rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /* Should never reach here */ |
---|
| 59 | rtems_test_assert( false ); |
---|
| 60 | |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | rtems_task Init( rtems_task_argument ignored ) |
---|
| 64 | { |
---|
[e8c7dbe7] | 65 | Print_Warning(); |
---|
| 66 | |
---|
[19e9bf8] | 67 | Task_name[0] = rtems_build_name( 'T','A','0','1' ); |
---|
| 68 | status = rtems_task_create( |
---|
| 69 | Task_name[0], |
---|
| 70 | 30, |
---|
| 71 | RTEMS_MINIMUM_STACK_SIZE, |
---|
| 72 | RTEMS_DEFAULT_MODES, |
---|
| 73 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
| 74 | &Task_id[0] |
---|
| 75 | ); |
---|
| 76 | directive_failed( status, "rtems_task_create of TA01" ); |
---|
| 77 | |
---|
| 78 | Task_name[1] = rtems_build_name( 'T','A','0','2' ); |
---|
| 79 | status = rtems_task_create( |
---|
| 80 | Task_name[1], |
---|
| 81 | 30, |
---|
| 82 | RTEMS_MINIMUM_STACK_SIZE, |
---|
| 83 | RTEMS_DEFAULT_MODES, |
---|
| 84 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
| 85 | &Task_id[1] |
---|
| 86 | ); |
---|
| 87 | directive_failed( status, "rtems_task_create of TA02" ); |
---|
| 88 | |
---|
| 89 | /* find overhead of routine (no task switches) */ |
---|
| 90 | benchmark_timer_initialize(); |
---|
| 91 | for ( count1 = 0; count1 < BENCHMARKS - 1; count1++ ) { |
---|
| 92 | /* rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ) */ |
---|
| 93 | } |
---|
| 94 | for ( count2 = 0; count2 < BENCHMARKS; count2++ ) { |
---|
| 95 | /* rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ) */ |
---|
| 96 | } |
---|
| 97 | loop_overhead = benchmark_timer_read(); |
---|
| 98 | |
---|
| 99 | /* find overhead of rtems_task_wake_after call (no task switches) */ |
---|
| 100 | benchmark_timer_initialize(); |
---|
| 101 | rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); |
---|
| 102 | dir_overhead = benchmark_timer_read(); |
---|
| 103 | |
---|
| 104 | status = rtems_task_start( Task_id[0], Task01, 0); |
---|
| 105 | directive_failed( status, "rtems_task_start of TA01" ); |
---|
| 106 | |
---|
| 107 | status = rtems_task_delete( RTEMS_SELF); |
---|
| 108 | directive_failed( status, "rtems_task_delete of INIT" ); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | /* configuration information */ |
---|
| 112 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 113 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
| 114 | #define CONFIGURE_TICKS_PER_TIMESLICE 0 |
---|
| 115 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 116 | #define CONFIGURE_MAXIMUM_TASKS 3 |
---|
| 117 | #define CONFIGURE_INIT |
---|
| 118 | #include <rtems/confdefs.h> |
---|