[PATCH 3/5] tmtests/tm27: Simplify
Sebastian Huber
sebastian.huber at embedded-brains.de
Fri Nov 24 12:52:22 UTC 2017
Update #3254.
---
testsuites/tmtests/tm27/task1.c | 104 ++++++++++++++++++++++------------------
1 file changed, 57 insertions(+), 47 deletions(-)
diff --git a/testsuites/tmtests/tm27/task1.c b/testsuites/tmtests/tm27/task1.c
index c89c0956f1..9655936c65 100644
--- a/testsuites/tmtests/tm27/task1.c
+++ b/testsuites/tmtests/tm27/task1.c
@@ -28,24 +28,37 @@
const char rtems_test_name[] = "TIME TEST 27";
-rtems_task Task_1(
+typedef struct {
+ volatile bool interrupt_occurred;
+ uint32_t interrupt_enter_time;
+ uint32_t interrupt_enter_nested_time;
+ uint32_t interrupt_return_time;
+ uint32_t interrupt_return_nested_time;
+ uint32_t interrupt_nest;
+ uint32_t timer_overhead;
+} test_context;
+
+static test_context test_instance;
+
+static rtems_task Task_1(
rtems_task_argument argument
);
-rtems_task Task_2(
+static rtems_task Task_2(
rtems_task_argument argument
);
-volatile uint32_t Interrupt_occurred;
-volatile uint32_t Interrupt_enter_time, Interrupt_enter_nested_time;
-volatile uint32_t Interrupt_return_time, Interrupt_return_nested_time;
-uint32_t Interrupt_nest;
-uint32_t timer_overhead;
-
-rtems_isr Isr_handler(
+static rtems_isr Isr_handler(
rtems_vector_number vector
);
+static void wait_for_interrupt( test_context *ctx )
+{
+ while ( !ctx->interrupt_occurred ) {
+ /* Wait */
+ }
+}
+
static void set_thread_executing( Thread_Control *thread )
{
_Per_CPU_Get_snapshot()->executing = thread;
@@ -55,6 +68,7 @@ rtems_task Init(
rtems_task_argument argument
)
{
+ test_context *ctx = &test_instance;
rtems_status_code status;
Print_Warning();
@@ -82,7 +96,7 @@ rtems_task Init(
);
directive_failed( status, "rtems_task_create Task_1" );
- status = rtems_task_start( Task_id[ 1 ], Task_1, 0 );
+ status = rtems_task_start( Task_id[ 1 ], Task_1, (rtems_task_argument) ctx );
directive_failed( status, "rtems_task_start Task_1" );
status = rtems_task_create(
@@ -95,13 +109,13 @@ rtems_task Init(
);
directive_failed( status, "rtems_task_create of Task_2" );
- status = rtems_task_start( Task_id[ 2 ], Task_2, 0 );
+ status = rtems_task_start( Task_id[ 2 ], Task_2, (rtems_task_argument) ctx );
directive_failed( status, "rtems_task_start of Task_2" );
benchmark_timer_initialize();
benchmark_timer_read();
benchmark_timer_initialize();
- timer_overhead = benchmark_timer_read();
+ ctx->timer_overhead = benchmark_timer_read();
status = rtems_task_delete( RTEMS_SELF );
directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
@@ -111,6 +125,7 @@ rtems_task Task_1(
rtems_task_argument argument
)
{
+ test_context *ctx = (test_context *) argument;
Scheduler_priority_Context *scheduler_context =
_Scheduler_priority_Get_context( _Thread_Scheduler_get_home( _Thread_Get_executing() ) );
#if defined(RTEMS_SMP)
@@ -123,33 +138,31 @@ rtems_task Task_1(
* No preempt .. no nesting
*/
- Interrupt_nest = 0;
+ ctx->interrupt_nest = 0;
- Interrupt_occurred = 0;
+ ctx->interrupt_occurred = 0;
benchmark_timer_initialize();
Cause_tm27_intr();
/* goes to Isr_handler */
-#if (MUST_WAIT_FOR_INTERRUPT == 1)
- while ( Interrupt_occurred == 0 );
-#endif
- Interrupt_return_time = benchmark_timer_read();
+ wait_for_interrupt( ctx );
+ ctx->interrupt_return_time = benchmark_timer_read();
put_time(
"rtems interrupt: entry overhead returns to interrupted task",
- Interrupt_enter_time,
+ ctx->interrupt_enter_time,
1,
0,
- timer_overhead
+ ctx->timer_overhead
);
put_time(
"rtems interrupt: exit overhead returns to interrupted task",
- Interrupt_return_time,
+ ctx->interrupt_return_time,
1,
0,
- timer_overhead
+ ctx->timer_overhead
);
/*
@@ -158,23 +171,21 @@ rtems_task Task_1(
_Thread_Dispatch_disable();
- Interrupt_nest = 1;
+ ctx->interrupt_nest = 1;
- Interrupt_occurred = 0;
+ ctx->interrupt_occurred = 0;
benchmark_timer_initialize();
Cause_tm27_intr();
/* goes to Isr_handler */
-#if (MUST_WAIT_FOR_INTERRUPT == 1)
- while ( Interrupt_occurred == 0 );
-#endif
- Interrupt_return_time = benchmark_timer_read();
+ wait_for_interrupt( ctx );
+ ctx->interrupt_return_time = benchmark_timer_read();
_Thread_Dispatch_enable( _Per_CPU_Get() );
put_time(
"rtems interrupt: entry overhead returns to nested interrupt",
- Interrupt_enter_nested_time,
+ ctx->interrupt_enter_nested_time,
1,
0,
0
@@ -182,7 +193,7 @@ rtems_task Task_1(
put_time(
"rtems interrupt: exit overhead returns to nested interrupt",
- Interrupt_return_nested_time,
+ ctx->interrupt_return_nested_time,
1,
0,
0
@@ -206,7 +217,7 @@ rtems_task Task_1(
_ISR_Local_enable(level);
#endif
- Interrupt_occurred = 0;
+ ctx->interrupt_occurred = 0;
benchmark_timer_initialize();
Cause_tm27_intr();
@@ -230,6 +241,7 @@ rtems_task Task_2(
rtems_task_argument argument
)
{
+ test_context *ctx = (test_context *) argument;
Thread_Control *executing = _Thread_Get_executing();
const Scheduler_Control *scheduler;
Scheduler_priority_Context *scheduler_context;
@@ -241,17 +253,15 @@ rtems_task Task_2(
scheduler_context = _Scheduler_priority_Get_context( scheduler );
_Thread_State_release( executing, &state_lock_context );
-#if (MUST_WAIT_FOR_INTERRUPT == 1)
- while ( Interrupt_occurred == 0 );
-#endif
+ wait_for_interrupt( ctx );
end_time = benchmark_timer_read();
put_time(
"rtems interrupt: entry overhead returns to preempting task",
- Interrupt_enter_time,
+ ctx->interrupt_enter_time,
1,
0,
- timer_overhead
+ ctx->timer_overhead
);
put_time(
@@ -295,36 +305,36 @@ rtems_isr Isr_handler(
rtems_vector_number vector
)
{
+ test_context *ctx = &test_instance;
end_time = benchmark_timer_read();
- Interrupt_occurred = 1;
+ ctx->interrupt_occurred = 1;
Isr_handler_inner();
}
void Isr_handler_inner( void )
{
+ test_context *ctx = &test_instance;
/*enable_tracing();*/
Clear_tm27_intr();
- switch ( Interrupt_nest ) {
+ switch ( ctx->interrupt_nest ) {
case 0:
- Interrupt_enter_time = end_time;
+ ctx->interrupt_enter_time = end_time;
break;
case 1:
- Interrupt_enter_time = end_time;
- Interrupt_nest = 2;
- Interrupt_occurred = 0;
+ ctx->interrupt_enter_time = end_time;
+ ctx->interrupt_nest = 2;
+ ctx->interrupt_occurred = 0;
Lower_tm27_intr();
benchmark_timer_initialize();
Cause_tm27_intr();
/* goes to a nested copy of Isr_handler */
-#if (MUST_WAIT_FOR_INTERRUPT == 1)
- while ( Interrupt_occurred == 0 );
-#endif
- Interrupt_return_nested_time = benchmark_timer_read();
+ wait_for_interrupt( ctx );
+ ctx->interrupt_return_nested_time = benchmark_timer_read();
break;
case 2:
- Interrupt_enter_nested_time = end_time;
+ ctx->interrupt_enter_nested_time = end_time;
break;
}
--
2.12.3
More information about the devel
mailing list