[PATCH 27/32] testsuites: Avoid Giant lock
Sebastian Huber
sebastian.huber at embedded-brains.de
Wed May 18 09:20:46 UTC 2016
Replace _Thread_Disable_dispatch() with _Thread_Dispatch_disable().
Replace _Thread_Enable_dispatch() with _Thread_Dispatch_enable().
This is a preparation to remove the Giant lock.
Update #2555.
---
testsuites/libtests/malloctest/init.c | 8 +--
testsuites/smptests/smpcache01/init.c | 17 +++---
testsuites/smptests/smpfatal03/init.c | 4 +-
testsuites/smptests/smpmigration02/init.c | 6 +-
testsuites/smptests/smpscheduler01/init.c | 10 +--
testsuites/smptests/smpthreadlife01/init.c | 4 +-
testsuites/sptests/sp37/init.c | 9 +--
testsuites/sptests/sp75/init.c | 9 +--
testsuites/sptests/spfatal01/testcase.h | 2 +-
testsuites/sptests/spfatal03/testcase.h | 6 +-
testsuites/sptests/spintrcritical20/init.c | 5 +-
testsuites/sptests/spthreadlife01/init.c | 9 +--
testsuites/sptests/spthreadq01/init.c | 4 +-
testsuites/tmtests/tm26/task1.c | 98 +++++-------------------------
testsuites/tmtests/tm27/task1.c | 4 +-
15 files changed, 65 insertions(+), 130 deletions(-)
diff --git a/testsuites/libtests/malloctest/init.c b/testsuites/libtests/malloctest/init.c
index 6123977..fb22e4d 100644
--- a/testsuites/libtests/malloctest/init.c
+++ b/testsuites/libtests/malloctest/init.c
@@ -95,10 +95,10 @@ static void test_realloc(void)
rtems_test_assert( malloc_walk_ok );
puts( "malloc_walk - in critical section path" );
- _Thread_Disable_dispatch();
+ _Thread_Dispatch_disable();
malloc_walk_ok = malloc_walk( 1234, false );
rtems_test_assert( malloc_walk_ok );
- _Thread_Enable_dispatch();
+ _Thread_Dispatch_enable( _Per_CPU_Get() );
/*
* Realloc with a bad pointer to force a point
@@ -1142,9 +1142,9 @@ static void test_rtems_heap_allocate_aligned_with_boundary(void)
rtems_test_assert( p != NULL );
free(p);
- _Thread_Disable_dispatch();
+ _Thread_Dispatch_disable();
p = rtems_heap_allocate_aligned_with_boundary(1, 1, 1);
- _Thread_Enable_dispatch();
+ _Thread_Dispatch_enable( _Per_CPU_Get() );
rtems_test_assert( p == NULL );
}
diff --git a/testsuites/smptests/smpcache01/init.c b/testsuites/smptests/smpcache01/init.c
index d8995e8..52ee997 100644
--- a/testsuites/smptests/smpcache01/init.c
+++ b/testsuites/smptests/smpcache01/init.c
@@ -166,19 +166,19 @@ static void call_tests_isr_disabled( size_t set_size,
}
}
-static void call_tests_with_giant_acquired( size_t set_size,
+static void call_tests_with_thread_dispatch_disabled( size_t set_size,
const cpu_set_t *cpu_set, SMP_barrier_State *bs )
{
size_t i;
for (i = 0; i < RTEMS_ARRAY_SIZE( test_cases ); ++i) {
- if ( rtems_get_current_processor() == 0)
- _Thread_Disable_dispatch();
+ Per_CPU_Control *cpu_self;
+
+ cpu_self = _Thread_Dispatch_disable();
call_test( set_size, cpu_set, bs, i );
- if ( rtems_get_current_processor() == 0)
- _Thread_Enable_dispatch();
+ _Thread_Dispatch_enable( cpu_self );
}
}
@@ -208,10 +208,9 @@ static void all_tests( void )
call_tests_isr_disabled( set_size, cpu_set, &bs );
cmlog( "Done!\n" );
- /* Call test cases with core 0 holding the giant lock */
- cmlog( "Calling test cases with CPU0 holding "
- "the giant lock. " );
- call_tests_with_giant_acquired( set_size, cpu_set, &bs );
+ /* Call test cases with thread dispatch disabled */
+ cmlog( "Calling test cases with thread_dispatch_disabled. ");
+ call_tests_with_thread_dispatch_disabled( set_size, cpu_set, &bs );
cmlog( "Done!\n");
/* Done. Free up memory. */
diff --git a/testsuites/smptests/smpfatal03/init.c b/testsuites/smptests/smpfatal03/init.c
index 788b071..2f3980b 100644
--- a/testsuites/smptests/smpfatal03/init.c
+++ b/testsuites/smptests/smpfatal03/init.c
@@ -42,7 +42,7 @@ static void acquire_giant_and_fatal_task(rtems_task_argument arg)
int i;
for (i = 0; i < 13; ++i) {
- _Thread_Disable_dispatch();
+ _Giant_Acquire();
}
_SMP_barrier_Wait(&giant_barrier, &state, CPU_COUNT);
@@ -62,7 +62,7 @@ static void wait_for_giant(void)
_SMP_barrier_Wait(&giant_barrier, &state, CPU_COUNT);
- _Thread_Disable_dispatch();
+ _Giant_Release();
}
static void Init(rtems_task_argument arg)
diff --git a/testsuites/smptests/smpmigration02/init.c b/testsuites/smptests/smpmigration02/init.c
index 40ac8ff..ed10c2b 100644
--- a/testsuites/smptests/smpmigration02/init.c
+++ b/testsuites/smptests/smpmigration02/init.c
@@ -140,6 +140,7 @@ static void test_double_migration(test_context *ctx)
uint32_t cpu_other_index = 1;
Per_CPU_Control *cpu_self = _Per_CPU_Get_by_index(cpu_self_index);
Per_CPU_Control *cpu_other = _Per_CPU_Get_by_index(cpu_other_index);
+ Per_CPU_Control *cpu_self_dispatch_disabled;
Thread_Control *self;
Thread_Control *other;
@@ -173,7 +174,8 @@ static void test_double_migration(test_context *ctx)
/* Wait */
}
- _Thread_Disable_dispatch();
+ cpu_self_dispatch_disabled = _Thread_Dispatch_disable();
+ rtems_test_assert(cpu_self == cpu_self_dispatch_disabled);
self = _Thread_Executing;
@@ -215,7 +217,7 @@ static void test_double_migration(test_context *ctx)
rtems_test_assert(cpu_other->heir == other);
- _Thread_Enable_dispatch();
+ _Thread_Dispatch_enable(cpu_self_dispatch_disabled);
while (!_Thread_Is_executing_on_a_processor(other)) {
/* Wait */
diff --git a/testsuites/smptests/smpscheduler01/init.c b/testsuites/smptests/smpscheduler01/init.c
index db61933..9518a4d 100644
--- a/testsuites/smptests/smpscheduler01/init.c
+++ b/testsuites/smptests/smpscheduler01/init.c
@@ -103,8 +103,9 @@ static bool is_per_cpu_state_ok(void)
static void test_scheduler_cross(void)
{
bool per_cpu_state_ok;
+ Per_CPU_Control *cpu_self;
- _Thread_Disable_dispatch();
+ cpu_self = _Thread_Dispatch_disable();
suspend(0);
suspend(1);
@@ -113,7 +114,7 @@ static void test_scheduler_cross(void)
per_cpu_state_ok = is_per_cpu_state_ok();
- _Thread_Enable_dispatch();
+ _Thread_Dispatch_enable( cpu_self );
rtems_test_assert(per_cpu_state_ok);
}
@@ -121,8 +122,9 @@ static void test_scheduler_cross(void)
static void test_scheduler_move_heir(void)
{
bool per_cpu_state_ok;
+ Per_CPU_Control *cpu_self;
- _Thread_Disable_dispatch();
+ cpu_self = _Thread_Dispatch_disable();
suspend(2);
suspend(3);
@@ -136,7 +138,7 @@ static void test_scheduler_move_heir(void)
resume(1);
- _Thread_Enable_dispatch();
+ _Thread_Dispatch_enable( cpu_self );
rtems_test_assert(per_cpu_state_ok);
}
diff --git a/testsuites/smptests/smpthreadlife01/init.c b/testsuites/smptests/smpthreadlife01/init.c
index bd4c88d..5bfa3bc 100644
--- a/testsuites/smptests/smpthreadlife01/init.c
+++ b/testsuites/smptests/smpthreadlife01/init.c
@@ -212,7 +212,7 @@ static void delay_ipi_task(rtems_task_argument variant)
rtems_counter_delay_nanoseconds(100000000);
if (variant != 0) {
- _Thread_Disable_dispatch();
+ _Thread_Dispatch_disable();
}
_ISR_Enable_without_giant(level);
@@ -224,7 +224,7 @@ static void delay_ipi_task(rtems_task_argument variant)
_Thread_Set_life_protection( THREAD_LIFE_PROTECTED );
if (variant != 0) {
- _Thread_Enable_dispatch();
+ _Thread_Dispatch_enable( _Per_CPU_Get() );
}
rtems_test_assert(0);
diff --git a/testsuites/sptests/sp37/init.c b/testsuites/sptests/sp37/init.c
index cec6d06..68b28a6 100644
--- a/testsuites/sptests/sp37/init.c
+++ b/testsuites/sptests/sp37/init.c
@@ -402,8 +402,9 @@ rtems_timer_service_routine test_unblock_task(
void *arg
)
{
- bool in_isr;
- rtems_status_code status;
+ bool in_isr;
+ rtems_status_code status;
+ Per_CPU_Control *cpu_self;
in_isr = rtems_interrupt_is_in_progress();
status = rtems_task_is_suspended( blocked_task_id );
@@ -420,9 +421,9 @@ rtems_timer_service_routine test_unblock_task(
}
blocked_task_status = 2;
- _Thread_Disable_dispatch();
+ cpu_self = _Thread_Dispatch_disable();
status = rtems_task_resume( blocked_task_id );
- _Thread_Unnest_dispatch();
+ _Thread_Dispatch_enable( cpu_self );
directive_failed( status, "rtems_task_resume" );
}
diff --git a/testsuites/sptests/sp75/init.c b/testsuites/sptests/sp75/init.c
index 2822586..e699e76 100644
--- a/testsuites/sptests/sp75/init.c
+++ b/testsuites/sptests/sp75/init.c
@@ -23,8 +23,9 @@ rtems_task Init(
rtems_task_argument argument
)
{
- rtems_status_code sc;
- rtems_id mutex;
+ rtems_status_code sc;
+ rtems_id mutex;
+ Per_CPU_Control *cpu_self;
TEST_BEGIN();
@@ -43,9 +44,9 @@ rtems_task Init(
* directive_failed() checks for dispatching being enabled.
*/
puts( "rtems_semaphore_obtain - with dispatching disabled" );
- _Thread_Disable_dispatch();
+ cpu_self = _Thread_Dispatch_disable();
sc = rtems_semaphore_obtain(mutex, RTEMS_NO_WAIT, RTEMS_NO_TIMEOUT);
- _Thread_Enable_dispatch();
+ _Thread_Dispatch_enable(cpu_self);
directive_failed(sc, "rtems_semaphore_obtain");
TEST_END();
diff --git a/testsuites/sptests/spfatal01/testcase.h b/testsuites/sptests/spfatal01/testcase.h
index 2bde3fa..9ac322a 100644
--- a/testsuites/sptests/spfatal01/testcase.h
+++ b/testsuites/sptests/spfatal01/testcase.h
@@ -33,7 +33,7 @@ void force_error()
/*
* Case 2: Null entry
* Case 3: semaphore_create
- * _Thread_Disable_dispatch
+ * _Thread_Dispatch_disable
* semaphore_obtain
*/
diff --git a/testsuites/sptests/spfatal03/testcase.h b/testsuites/sptests/spfatal03/testcase.h
index b9f1c22..86b3003 100644
--- a/testsuites/sptests/spfatal03/testcase.h
+++ b/testsuites/sptests/spfatal03/testcase.h
@@ -36,12 +36,10 @@ void force_error(void)
printk("Create semaphore S0\n");
printk("Obtain semaphore in dispatching critical section\n");
- _Thread_Disable_dispatch();
+ _Thread_Dispatch_disable();
status = rtems_semaphore_obtain( mutex, RTEMS_DEFAULT_OPTIONS, 0 );
/* !!! SHOULD NOT RETURN FROM THE ABOVE CALL */
- _Thread_Enable_dispatch();
- printk("ERROR -- Obtain semaphore should not have returned\n");
-
+ rtems_test_assert( 0 );
/* we will not run this far */
}
diff --git a/testsuites/sptests/spintrcritical20/init.c b/testsuites/sptests/spintrcritical20/init.c
index 85c1645..9c9b5f0 100644
--- a/testsuites/sptests/spintrcritical20/init.c
+++ b/testsuites/sptests/spintrcritical20/init.c
@@ -71,8 +71,9 @@ static bool test_body(void *arg)
{
test_context *ctx = arg;
int busy;
+ Per_CPU_Control *cpu_self;
- _Thread_Disable_dispatch();
+ cpu_self = _Thread_Dispatch_disable();
rtems_test_assert(
ctx->semaphore_task_tcb->Wait.return_code
@@ -105,7 +106,7 @@ static bool test_body(void *arg)
break;
}
- _Thread_Enable_dispatch();
+ _Thread_Dispatch_enable(cpu_self);
return ctx->thread_queue_was_null
&& ctx->status_was_successful
diff --git a/testsuites/sptests/spthreadlife01/init.c b/testsuites/sptests/spthreadlife01/init.c
index 7724635..8bf26b9 100644
--- a/testsuites/sptests/spthreadlife01/init.c
+++ b/testsuites/sptests/spthreadlife01/init.c
@@ -232,6 +232,7 @@ static void worker_task(rtems_task_argument arg)
test_state state = ctx->current;
rtems_status_code sc;
Thread_Life_state previous_thread_life_state;
+ Per_CPU_Control *cpu_self;
switch (state) {
case SET_PRIO:
@@ -272,22 +273,22 @@ static void worker_task(rtems_task_argument arg)
assert_priority(PRIO_HIGH);
break;
case SET_PROTECTION:
- _Thread_Disable_dispatch();
+ cpu_self = _Thread_Dispatch_disable();
previous_thread_life_state =
_Thread_Set_life_protection(THREAD_LIFE_PROTECTED);
rtems_test_assert(
(previous_thread_life_state & THREAD_LIFE_PROTECTED) == 0
);
- _Thread_Enable_dispatch();
+ _Thread_Dispatch_enable(cpu_self);
break;
case CLEAR_PROTECTION:
- _Thread_Disable_dispatch();
+ cpu_self = _Thread_Dispatch_disable();
previous_thread_life_state = _Thread_Set_life_protection(0);
rtems_test_assert(
(previous_thread_life_state & THREAD_LIFE_PROTECTED) != 0
);
ctx->current = DELETE_4;
- _Thread_Enable_dispatch();
+ _Thread_Dispatch_enable(cpu_self);
break;
case DELETE_SELF:
ctx->current = DELETE_7;
diff --git a/testsuites/sptests/spthreadq01/init.c b/testsuites/sptests/spthreadq01/init.c
index cb8d495..85df6bd 100644
--- a/testsuites/sptests/spthreadq01/init.c
+++ b/testsuites/sptests/spthreadq01/init.c
@@ -353,9 +353,7 @@ static rtems_task Init(
TEST_BEGIN();
puts( "Init - _Thread_queue_Extract - thread not blocked on a thread queue" );
- _Thread_Disable_dispatch();
- _Thread_queue_Extract( _Thread_Executing );
- _Thread_Enable_dispatch();
+ _Thread_queue_Extract( _Thread_Get_executing() );
/* is there more to check? */
test_context_init(ctx);
diff --git a/testsuites/tmtests/tm26/task1.c b/testsuites/tmtests/tm26/task1.c
index babd240..0eb7554 100644
--- a/testsuites/tmtests/tm26/task1.c
+++ b/testsuites/tmtests/tm26/task1.c
@@ -138,73 +138,9 @@ static void set_thread_executing( Thread_Control *thread )
#endif
}
-static void thread_disable_dispatch( void )
-{
-/* Yes, RTEMS_SMP and not PREVENT_SMP_ASSERT_FAILURES */
-#if defined( RTEMS_SMP )
- Per_CPU_Control *self_cpu;
- ISR_Level level;
-
- _ISR_Disable_without_giant( level );
- ( void ) level;
-
- self_cpu = _Per_CPU_Get();
- self_cpu->thread_dispatch_disable_level = 1;
-#else
- _Thread_Disable_dispatch();
-#endif
-}
-
-static void thread_set_state( Thread_Control *thread, States_Control state )
-{
-#if defined( PREVENT_SMP_ASSERT_FAILURES )
- _Thread_Disable_dispatch();
-#endif
-
- _Thread_Set_state( thread, state );
-
-#if defined( PREVENT_SMP_ASSERT_FAILURES )
- _Thread_Unnest_dispatch();
-#endif
-}
-
static void thread_resume( Thread_Control *thread )
{
-#if defined( PREVENT_SMP_ASSERT_FAILURES )
- _Thread_Disable_dispatch();
-#endif
-
_Thread_Clear_state( thread, STATES_SUSPENDED );
-
-#if defined( PREVENT_SMP_ASSERT_FAILURES )
- _Thread_Unnest_dispatch();
-#endif
-}
-
-static void thread_unblock( Thread_Control *thread )
-{
-#if defined( PREVENT_SMP_ASSERT_FAILURES )
- _Thread_Disable_dispatch();
-#endif
-
- _Thread_Unblock( thread );
-
-#if defined( PREVENT_SMP_ASSERT_FAILURES )
- _Thread_Unnest_dispatch();
-#endif
-}
-
-static void thread_clear_state( Thread_Control *thread, States_Control state )
-{
-#if defined( PREVENT_SMP_ASSERT_FAILURES )
- _Thread_Disable_dispatch();
-#endif
-
- _Thread_Clear_state( thread, state );
-
-#if defined( PREVENT_SMP_ASSERT_FAILURES )
- _Thread_Unnest_dispatch();
-#endif
}
rtems_task null_task(
@@ -338,7 +274,7 @@ rtems_task High_task(
{
rtems_interrupt_level level;
- _Thread_Disable_dispatch();
+ _Thread_Dispatch_disable();
benchmark_timer_initialize();
rtems_interrupt_local_disable( level );
@@ -357,18 +293,18 @@ rtems_task High_task(
rtems_interrupt_local_enable( level );
isr_enable_time = benchmark_timer_read();
- _Thread_Enable_dispatch();
+ _Thread_Dispatch_enable( _Per_CPU_Get() );
benchmark_timer_initialize();
- _Thread_Disable_dispatch();
+ _Thread_Dispatch_disable();
thread_disable_dispatch_time = benchmark_timer_read();
benchmark_timer_initialize();
- _Thread_Enable_dispatch();
+ _Thread_Dispatch_enable( _Per_CPU_Get() );
thread_enable_dispatch_time = benchmark_timer_read();
benchmark_timer_initialize();
- thread_set_state( _Thread_Get_executing(), STATES_SUSPENDED );
+ _Thread_Set_state( _Thread_Get_executing(), STATES_SUSPENDED );
thread_set_state_time = benchmark_timer_read();
set_thread_dispatch_necessary( true );
@@ -386,7 +322,7 @@ rtems_task Middle_task(
thread_dispatch_no_fp_time = benchmark_timer_read();
- thread_set_state( _Thread_Get_executing(), STATES_SUSPENDED );
+ _Thread_Set_state( _Thread_Get_executing(), STATES_SUSPENDED );
Middle_tcb = _Thread_Get_executing();
@@ -398,7 +334,7 @@ rtems_task Middle_task(
set_thread_dispatch_necessary( false );
- thread_disable_dispatch();
+ _Thread_Dispatch_disable();
benchmark_timer_initialize();
_Context_Switch(
@@ -441,7 +377,7 @@ rtems_task Low_task(
set_thread_dispatch_necessary( false );
- thread_disable_dispatch();
+ _Thread_Dispatch_disable();
benchmark_timer_initialize();
_Context_Switch(
@@ -471,7 +407,7 @@ rtems_task Floating_point_task_1(
set_thread_dispatch_necessary( false );
- thread_disable_dispatch();
+ _Thread_Dispatch_disable();
benchmark_timer_initialize();
#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
@@ -551,16 +487,16 @@ void complete_test( void )
thread_resume( Middle_tcb );
thread_resume_time = benchmark_timer_read();
- thread_set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE );
+ _Thread_Set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE );
benchmark_timer_initialize();
- thread_unblock( Middle_tcb );
+ _Thread_Unblock( Middle_tcb );
thread_unblock_time = benchmark_timer_read();
- thread_set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE );
+ _Thread_Set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE );
benchmark_timer_initialize();
- thread_clear_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE );
+ _Thread_Clear_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE );
thread_ready_time = benchmark_timer_read();
benchmark_timer_initialize();
@@ -603,10 +539,6 @@ void complete_test( void )
set_thread_heir( _Thread_Get_executing() );
set_thread_dispatch_necessary( false );
- for (index = 0; index < OPERATION_COUNT; ++index) {
- _Thread_Unnest_dispatch();
- }
-
/*
* Now dump all the times
*/
@@ -636,7 +568,7 @@ void complete_test( void )
);
put_time(
- "rtems internal: _Thread_Disable_dispatch",
+ "rtems internal: _Thread_Dispatch_disable",
thread_disable_dispatch_time,
1,
0,
@@ -644,7 +576,7 @@ void complete_test( void )
);
put_time(
- "rtems internal: _Thread_Enable_dispatch",
+ "rtems internal: _Thread_Dispatch_enable",
thread_enable_dispatch_time,
1,
0,
diff --git a/testsuites/tmtests/tm27/task1.c b/testsuites/tmtests/tm27/task1.c
index 77072bb..cae778f 100644
--- a/testsuites/tmtests/tm27/task1.c
+++ b/testsuites/tmtests/tm27/task1.c
@@ -151,7 +151,7 @@ rtems_task Task_1(
* No preempt .. nested
*/
- _Thread_Disable_dispatch();
+ _Thread_Dispatch_disable();
Interrupt_nest = 1;
@@ -165,7 +165,7 @@ rtems_task Task_1(
#endif
Interrupt_return_time = benchmark_timer_read();
- _Thread_Unnest_dispatch();
+ _Thread_Dispatch_enable( _Per_CPU_Get() );
put_time(
"rtems interrupt: entry overhead returns to nested interrupt",
--
1.8.4.5
More information about the devel
mailing list