[ac7d5ef0] | 1 | /* |
---|
[9410d011] | 2 | * COPYRIGHT (c) 1989-2013. |
---|
[ac7d5ef0] | 3 | * On-Line Applications Research Corporation (OAR). |
---|
| 4 | * |
---|
[98e4ebf5] | 5 | * The license and distribution terms for this file may be |
---|
| 6 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 7 | * http://www.rtems.org/license/LICENSE. |
---|
[ac7d5ef0] | 8 | */ |
---|
| 9 | |
---|
[9700578] | 10 | /* |
---|
[8f71a36] | 11 | * WARNING!!!!!!!!! |
---|
[9700578] | 12 | * |
---|
| 13 | * THIS TEST USES INTERNAL RTEMS VARIABLES!!! |
---|
| 14 | */ |
---|
| 15 | |
---|
[a4bc4d6e] | 16 | #ifdef HAVE_CONFIG_H |
---|
| 17 | #include "config.h" |
---|
| 18 | #endif |
---|
| 19 | |
---|
[d1128e2] | 20 | #define CONFIGURE_INIT |
---|
[ac7d5ef0] | 21 | #include "system.h" |
---|
| 22 | |
---|
| 23 | #include <bsp.h> |
---|
[e1598a6] | 24 | #include <rtems/score/schedulerpriorityimpl.h> |
---|
[ac7d5ef0] | 25 | |
---|
[b40e9cc] | 26 | #define _RTEMS_TMTEST27 |
---|
| 27 | #include <tm27.h> |
---|
| 28 | |
---|
[2ead50a] | 29 | const char rtems_test_name[] = "TIME TEST 27"; |
---|
| 30 | |
---|
[ac7d5ef0] | 31 | rtems_task Task_1( |
---|
| 32 | rtems_task_argument argument |
---|
| 33 | ); |
---|
| 34 | |
---|
| 35 | rtems_task Task_2( |
---|
| 36 | rtems_task_argument argument |
---|
| 37 | ); |
---|
| 38 | |
---|
[0720ff4] | 39 | volatile uint32_t Interrupt_occurred; |
---|
| 40 | volatile uint32_t Interrupt_enter_time, Interrupt_enter_nested_time; |
---|
| 41 | volatile uint32_t Interrupt_return_time, Interrupt_return_nested_time; |
---|
| 42 | uint32_t Interrupt_nest; |
---|
| 43 | uint32_t timer_overhead; |
---|
[ac7d5ef0] | 44 | |
---|
| 45 | rtems_isr Isr_handler( |
---|
| 46 | rtems_vector_number vector |
---|
| 47 | ); |
---|
| 48 | |
---|
| 49 | rtems_task Init( |
---|
| 50 | rtems_task_argument argument |
---|
| 51 | ) |
---|
| 52 | { |
---|
| 53 | rtems_status_code status; |
---|
| 54 | |
---|
[3a4ae6c] | 55 | Print_Warning(); |
---|
| 56 | |
---|
[2ead50a] | 57 | TEST_BEGIN(); |
---|
[e1598a6] | 58 | |
---|
| 59 | if ( |
---|
| 60 | _Scheduler_Table[ 0 ].Operations.initialize |
---|
| 61 | != _Scheduler_priority_Initialize |
---|
| 62 | ) { |
---|
[a1a5f92] | 63 | puts(" Error ==> " ); |
---|
| 64 | puts("Test only supported for deterministic priority scheduler\n" ); |
---|
[2ead50a] | 65 | TEST_END(); |
---|
[a1a5f92] | 66 | rtems_test_exit( 0 ); |
---|
| 67 | } |
---|
[ac7d5ef0] | 68 | |
---|
[1055ce20] | 69 | #define LOW_PRIORITY (RTEMS_MAXIMUM_PRIORITY - 1u) |
---|
[ac7d5ef0] | 70 | status = rtems_task_create( |
---|
| 71 | rtems_build_name( 'T', 'A', '1', ' ' ), |
---|
[4389287a] | 72 | LOW_PRIORITY, |
---|
[3652ad35] | 73 | RTEMS_MINIMUM_STACK_SIZE, |
---|
[ac7d5ef0] | 74 | RTEMS_DEFAULT_MODES, |
---|
| 75 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
| 76 | &Task_id[ 1 ] |
---|
| 77 | ); |
---|
| 78 | directive_failed( status, "rtems_task_create Task_1" ); |
---|
| 79 | |
---|
| 80 | status = rtems_task_start( Task_id[ 1 ], Task_1, 0 ); |
---|
| 81 | directive_failed( status, "rtems_task_start Task_1" ); |
---|
| 82 | |
---|
| 83 | status = rtems_task_create( |
---|
| 84 | rtems_build_name( 'T', 'A', '2', ' ' ), |
---|
[4389287a] | 85 | LOW_PRIORITY, |
---|
[3652ad35] | 86 | RTEMS_MINIMUM_STACK_SIZE, |
---|
[ac7d5ef0] | 87 | RTEMS_DEFAULT_MODES, |
---|
| 88 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
| 89 | &Task_id[ 2 ] |
---|
| 90 | ); |
---|
| 91 | directive_failed( status, "rtems_task_create of Task_2" ); |
---|
| 92 | |
---|
| 93 | status = rtems_task_start( Task_id[ 2 ], Task_2, 0 ); |
---|
| 94 | directive_failed( status, "rtems_task_start of Task_2" ); |
---|
| 95 | |
---|
[dbf4f17] | 96 | benchmark_timer_initialize(); |
---|
| 97 | benchmark_timer_read(); |
---|
| 98 | benchmark_timer_initialize(); |
---|
| 99 | timer_overhead = benchmark_timer_read(); |
---|
[ed07762] | 100 | |
---|
[ac7d5ef0] | 101 | status = rtems_task_delete( RTEMS_SELF ); |
---|
| 102 | directive_failed( status, "rtems_task_delete of RTEMS_SELF" ); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | rtems_task Task_1( |
---|
| 106 | rtems_task_argument argument |
---|
| 107 | ) |
---|
| 108 | { |
---|
[e1598a6] | 109 | Scheduler_priority_Context *scheduler_context = |
---|
| 110 | _Scheduler_priority_Get_context( _Scheduler_Get( _Thread_Get_executing() ) ); |
---|
[09c00ee] | 111 | #if defined(RTEMS_SMP) |
---|
| 112 | rtems_interrupt_level level; |
---|
| 113 | #endif |
---|
[df0f27f] | 114 | |
---|
[ea74482] | 115 | Install_tm27_vector( Isr_handler ); |
---|
[ac7d5ef0] | 116 | |
---|
[ea74482] | 117 | /* |
---|
| 118 | * No preempt .. no nesting |
---|
| 119 | */ |
---|
[ac7d5ef0] | 120 | |
---|
[ea74482] | 121 | Interrupt_nest = 0; |
---|
| 122 | |
---|
[ac7d5ef0] | 123 | Interrupt_occurred = 0; |
---|
[ed07762] | 124 | |
---|
[dbf4f17] | 125 | benchmark_timer_initialize(); |
---|
[ed07762] | 126 | Cause_tm27_intr(); |
---|
[ac7d5ef0] | 127 | /* goes to Isr_handler */ |
---|
| 128 | |
---|
| 129 | #if (MUST_WAIT_FOR_INTERRUPT == 1) |
---|
| 130 | while ( Interrupt_occurred == 0 ); |
---|
| 131 | #endif |
---|
[dbf4f17] | 132 | Interrupt_return_time = benchmark_timer_read(); |
---|
[ac7d5ef0] | 133 | |
---|
| 134 | put_time( |
---|
[9410d011] | 135 | "rtems interrupt: entry overhead returns to interrupted task", |
---|
[ea74482] | 136 | Interrupt_enter_time, |
---|
[ac7d5ef0] | 137 | 1, |
---|
| 138 | 0, |
---|
[ed07762] | 139 | timer_overhead |
---|
[ac7d5ef0] | 140 | ); |
---|
| 141 | |
---|
| 142 | put_time( |
---|
[9410d011] | 143 | "rtems interrupt: exit overhead returns to interrupted task", |
---|
[ea74482] | 144 | Interrupt_return_time, |
---|
[ac7d5ef0] | 145 | 1, |
---|
| 146 | 0, |
---|
[ed07762] | 147 | timer_overhead |
---|
[ac7d5ef0] | 148 | ); |
---|
| 149 | |
---|
[ea74482] | 150 | /* |
---|
| 151 | * No preempt .. nested |
---|
| 152 | */ |
---|
[ac7d5ef0] | 153 | |
---|
[dab902d5] | 154 | _Thread_Dispatch_disable(); |
---|
[ea74482] | 155 | |
---|
| 156 | Interrupt_nest = 1; |
---|
[ac7d5ef0] | 157 | |
---|
| 158 | Interrupt_occurred = 0; |
---|
[dbf4f17] | 159 | benchmark_timer_initialize(); |
---|
[ed07762] | 160 | Cause_tm27_intr(); |
---|
[ac7d5ef0] | 161 | /* goes to Isr_handler */ |
---|
| 162 | |
---|
| 163 | #if (MUST_WAIT_FOR_INTERRUPT == 1) |
---|
| 164 | while ( Interrupt_occurred == 0 ); |
---|
| 165 | #endif |
---|
[dbf4f17] | 166 | Interrupt_return_time = benchmark_timer_read(); |
---|
[ac7d5ef0] | 167 | |
---|
[dab902d5] | 168 | _Thread_Dispatch_enable( _Per_CPU_Get() ); |
---|
[54a43fe4] | 169 | |
---|
[ac7d5ef0] | 170 | put_time( |
---|
[9410d011] | 171 | "rtems interrupt: entry overhead returns to nested interrupt", |
---|
[ea74482] | 172 | Interrupt_enter_nested_time, |
---|
[ac7d5ef0] | 173 | 1, |
---|
| 174 | 0, |
---|
| 175 | 0 |
---|
| 176 | ); |
---|
| 177 | |
---|
| 178 | put_time( |
---|
[9410d011] | 179 | "rtems interrupt: exit overhead returns to nested interrupt", |
---|
[ea74482] | 180 | Interrupt_return_nested_time, |
---|
[ac7d5ef0] | 181 | 1, |
---|
| 182 | 0, |
---|
| 183 | 0 |
---|
| 184 | ); |
---|
| 185 | |
---|
[ea74482] | 186 | /* |
---|
| 187 | * Does a preempt .. not nested |
---|
| 188 | */ |
---|
| 189 | |
---|
[09c00ee] | 190 | #if defined(RTEMS_SMP) |
---|
[4b04cb61] | 191 | _ISR_Local_disable(level); |
---|
[09c00ee] | 192 | #endif |
---|
| 193 | |
---|
[df0f27f] | 194 | _Thread_Executing = |
---|
[e1598a6] | 195 | (Thread_Control *) _Chain_First(&scheduler_context->Ready[LOW_PRIORITY]); |
---|
[ac7d5ef0] | 196 | |
---|
[9d47cd1] | 197 | _Thread_Dispatch_necessary = 1; |
---|
[ac7d5ef0] | 198 | |
---|
[09c00ee] | 199 | #if defined(RTEMS_SMP) |
---|
[4b04cb61] | 200 | _ISR_Local_enable(level); |
---|
[09c00ee] | 201 | #endif |
---|
| 202 | |
---|
[ac7d5ef0] | 203 | Interrupt_occurred = 0; |
---|
[dbf4f17] | 204 | benchmark_timer_initialize(); |
---|
[ed07762] | 205 | Cause_tm27_intr(); |
---|
[9700578] | 206 | |
---|
| 207 | /* |
---|
| 208 | * goes to Isr_handler and then returns |
---|
| 209 | */ |
---|
| 210 | |
---|
[2ead50a] | 211 | TEST_END(); |
---|
[b454bc9] | 212 | rtems_test_exit( 0 ); |
---|
[ac7d5ef0] | 213 | } |
---|
| 214 | |
---|
[9700578] | 215 | /* |
---|
[8f71a36] | 216 | * NOTE: When this task is executing, some of the assumptions made |
---|
[9700578] | 217 | * regarding the placement of the currently executing task's TCB |
---|
| 218 | * on the ready chains have been violated. At least the assumption |
---|
| 219 | * that this task is at the head of the chain for its priority |
---|
| 220 | * has been violated. |
---|
| 221 | */ |
---|
| 222 | |
---|
[ac7d5ef0] | 223 | rtems_task Task_2( |
---|
| 224 | rtems_task_argument argument |
---|
| 225 | ) |
---|
| 226 | { |
---|
[f9090ac] | 227 | Thread_Control *executing = _Thread_Get_executing(); |
---|
[bd12dda] | 228 | const Scheduler_Control *scheduler; |
---|
| 229 | Scheduler_priority_Context *scheduler_context; |
---|
| 230 | ISR_lock_Context state_lock_context; |
---|
| 231 | ISR_lock_Context scheduler_lock_context; |
---|
| 232 | |
---|
| 233 | _Thread_State_acquire( executing, &state_lock_context ); |
---|
| 234 | scheduler = _Scheduler_Get( executing ); |
---|
| 235 | scheduler_context = _Scheduler_priority_Get_context( scheduler ); |
---|
| 236 | _Thread_State_release( executing, &state_lock_context ); |
---|
[df0f27f] | 237 | |
---|
[ac7d5ef0] | 238 | #if (MUST_WAIT_FOR_INTERRUPT == 1) |
---|
| 239 | while ( Interrupt_occurred == 0 ); |
---|
| 240 | #endif |
---|
[dbf4f17] | 241 | end_time = benchmark_timer_read(); |
---|
[ac7d5ef0] | 242 | |
---|
| 243 | put_time( |
---|
[9410d011] | 244 | "rtems interrupt: entry overhead returns to preempting task", |
---|
[ac7d5ef0] | 245 | Interrupt_enter_time, |
---|
| 246 | 1, |
---|
| 247 | 0, |
---|
[ed07762] | 248 | timer_overhead |
---|
[ac7d5ef0] | 249 | ); |
---|
| 250 | |
---|
| 251 | put_time( |
---|
[9410d011] | 252 | "rtems interrupt: exit overhead returns to preempting task", |
---|
[ac7d5ef0] | 253 | end_time, |
---|
| 254 | 1, |
---|
| 255 | 0, |
---|
| 256 | 0 |
---|
| 257 | ); |
---|
| 258 | |
---|
[9700578] | 259 | fflush( stdout ); |
---|
| 260 | |
---|
| 261 | /* |
---|
| 262 | * Switch back to the other task to exit the test. |
---|
| 263 | */ |
---|
| 264 | |
---|
[bd12dda] | 265 | _Thread_State_acquire( executing, &state_lock_context ); |
---|
| 266 | _Scheduler_Acquire_critical( scheduler, &scheduler_lock_context ); |
---|
[09c00ee] | 267 | |
---|
[df0f27f] | 268 | _Thread_Executing = |
---|
[e1598a6] | 269 | (Thread_Control *) _Chain_First(&scheduler_context->Ready[LOW_PRIORITY]); |
---|
[8f71a36] | 270 | |
---|
[9d47cd1] | 271 | _Thread_Dispatch_necessary = 1; |
---|
[9700578] | 272 | |
---|
[bd12dda] | 273 | _Scheduler_Release_critical( scheduler, &scheduler_lock_context ); |
---|
| 274 | _Thread_State_release( executing, &state_lock_context ); |
---|
[09c00ee] | 275 | |
---|
[9700578] | 276 | _Thread_Dispatch(); |
---|
| 277 | |
---|
[ac7d5ef0] | 278 | } |
---|
| 279 | |
---|
| 280 | /* The Isr_handler() and Isr_handler_inner() routines are structured |
---|
| 281 | * so that there will be as little entry overhead as possible included |
---|
| 282 | * in the interrupt entry time. |
---|
| 283 | */ |
---|
| 284 | |
---|
| 285 | void Isr_handler_inner( void ); |
---|
| 286 | |
---|
| 287 | rtems_isr Isr_handler( |
---|
| 288 | rtems_vector_number vector |
---|
| 289 | ) |
---|
| 290 | { |
---|
[dbf4f17] | 291 | end_time = benchmark_timer_read(); |
---|
[ac7d5ef0] | 292 | |
---|
| 293 | Interrupt_occurred = 1; |
---|
| 294 | Isr_handler_inner(); |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | void Isr_handler_inner( void ) |
---|
| 298 | { |
---|
| 299 | |
---|
| 300 | /*enable_tracing();*/ |
---|
| 301 | Clear_tm27_intr(); |
---|
| 302 | switch ( Interrupt_nest ) { |
---|
| 303 | case 0: |
---|
| 304 | Interrupt_enter_time = end_time; |
---|
| 305 | break; |
---|
| 306 | case 1: |
---|
| 307 | Interrupt_enter_time = end_time; |
---|
| 308 | Interrupt_nest = 2; |
---|
| 309 | Interrupt_occurred = 0; |
---|
| 310 | Lower_tm27_intr(); |
---|
[dbf4f17] | 311 | benchmark_timer_initialize(); |
---|
[ed07762] | 312 | Cause_tm27_intr(); |
---|
[ac7d5ef0] | 313 | /* goes to a nested copy of Isr_handler */ |
---|
| 314 | #if (MUST_WAIT_FOR_INTERRUPT == 1) |
---|
| 315 | while ( Interrupt_occurred == 0 ); |
---|
| 316 | #endif |
---|
[dbf4f17] | 317 | Interrupt_return_nested_time = benchmark_timer_read(); |
---|
[ac7d5ef0] | 318 | break; |
---|
| 319 | case 2: |
---|
| 320 | Interrupt_enter_nested_time = end_time; |
---|
| 321 | break; |
---|
| 322 | } |
---|
| 323 | |
---|
[dbf4f17] | 324 | benchmark_timer_initialize(); |
---|
[ac7d5ef0] | 325 | } |
---|