From e97b7c9a7af2f4e19a8bdeaf13033617f8c4c2b6 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 11 Apr 2019 13:47:50 +0200 Subject: score: Use an ISR lock for Per_CPU_Control::Lock The use of a hand crafted lock for Per_CPU_Control::Lock was necessary at some point in the SMP support development, but it is no longer justified. --- cpukit/score/src/schedulersmp.c | 13 +++++++------ cpukit/score/src/smp.c | 3 +-- cpukit/score/src/threaddispatch.c | 17 ++++++++++------- cpukit/score/src/userextaddset.c | 6 ++---- cpukit/score/src/userextremoveset.c | 6 +++--- 5 files changed, 23 insertions(+), 22 deletions(-) (limited to 'cpukit/score/src') diff --git a/cpukit/score/src/schedulersmp.c b/cpukit/score/src/schedulersmp.c index d68ac4fc8b..a498bda90a 100644 --- a/cpukit/score/src/schedulersmp.c +++ b/cpukit/score/src/schedulersmp.c @@ -14,25 +14,26 @@ void _Scheduler_Request_ask_for_help( Thread_Control *the_thread ) { - ISR_lock_Context lock_context; + ISR_lock_Context scheduler_lock_context; - _Thread_Scheduler_acquire_critical( the_thread, &lock_context ); + _Thread_Scheduler_acquire_critical( the_thread, &scheduler_lock_context ); if ( _Chain_Is_node_off_chain( &the_thread->Scheduler.Help_node ) ) { - Per_CPU_Control *cpu; + Per_CPU_Control *cpu; + ISR_lock_Context per_cpu_lock_context; cpu = _Thread_Get_CPU( the_thread ); - _Per_CPU_Acquire( cpu ); + _Per_CPU_Acquire( cpu, &per_cpu_lock_context ); _Chain_Append_unprotected( &cpu->Threads_in_need_for_help, &the_thread->Scheduler.Help_node ); - _Per_CPU_Release( cpu ); + _Per_CPU_Release( cpu, &per_cpu_lock_context ); _Thread_Dispatch_request( _Per_CPU_Get(), cpu ); } - _Thread_Scheduler_release_critical( the_thread, &lock_context ); + _Thread_Scheduler_release_critical( the_thread, &scheduler_lock_context ); } diff --git a/cpukit/score/src/smp.c b/cpukit/score/src/smp.c index 822ecfd4ff..873682962d 100644 --- a/cpukit/score/src/smp.c +++ b/cpukit/score/src/smp.c @@ -117,8 +117,7 @@ void _SMP_Handler_initialize( void ) Per_CPU_Control *cpu; cpu = _Per_CPU_Get_by_index( cpu_index ); - _SMP_ticket_lock_Initialize( &cpu->Lock ); - _SMP_lock_Stats_initialize( &cpu->Lock_stats, "Per-CPU" ); + _ISR_lock_Set_name( &cpu->Lock, "Per-CPU" ); _ISR_lock_Set_name( &cpu->Watchdog.Lock, "Per-CPU Watchdog" ); _Chain_Initialize_empty( &cpu->Threads_in_need_for_help ); } diff --git a/cpukit/score/src/threaddispatch.c b/cpukit/score/src/threaddispatch.c index 55dc437eaf..65951cccfe 100644 --- a/cpukit/score/src/threaddispatch.c +++ b/cpukit/score/src/threaddispatch.c @@ -158,27 +158,30 @@ static ISR_Level _Thread_Preemption_intervention( ) { #if defined(RTEMS_SMP) + ISR_lock_Context lock_context; + level = _Thread_Check_pinning( executing, cpu_self, level ); - _Per_CPU_Acquire( cpu_self ); + _Per_CPU_Acquire( cpu_self, &lock_context ); while ( !_Chain_Is_empty( &cpu_self->Threads_in_need_for_help ) ) { - Chain_Node *node; - Thread_Control *the_thread; - ISR_lock_Context lock_context; + Chain_Node *node; + Thread_Control *the_thread; node = _Chain_Get_first_unprotected( &cpu_self->Threads_in_need_for_help ); _Chain_Set_off_chain( node ); the_thread = THREAD_OF_SCHEDULER_HELP_NODE( node ); - _Per_CPU_Release( cpu_self ); + _Per_CPU_Release( cpu_self, &lock_context ); + _Thread_State_acquire( the_thread, &lock_context ); _Thread_Ask_for_help( the_thread ); _Thread_State_release( the_thread, &lock_context ); - _Per_CPU_Acquire( cpu_self ); + + _Per_CPU_Acquire( cpu_self, &lock_context ); } - _Per_CPU_Release( cpu_self ); + _Per_CPU_Release( cpu_self, &lock_context ); #else (void) cpu_self; #endif diff --git a/cpukit/score/src/userextaddset.c b/cpukit/score/src/userextaddset.c index 585712e043..2b13dfad62 100644 --- a/cpukit/score/src/userextaddset.c +++ b/cpukit/score/src/userextaddset.c @@ -41,17 +41,15 @@ void _User_extensions_Add_set( */ if ( the_extension->Callouts.thread_switch != NULL ) { - ISR_Level level; - the_extension->Switch.thread_switch = the_extension->Callouts.thread_switch; - _Per_CPU_Acquire_all( level ); + _Per_CPU_Acquire_all( &lock_context ); _Chain_Initialize_node( &the_extension->Switch.Node ); _Chain_Append_unprotected( &_User_extensions_Switches_list, &the_extension->Switch.Node ); - _Per_CPU_Release_all( level ); + _Per_CPU_Release_all( &lock_context ); } } diff --git a/cpukit/score/src/userextremoveset.c b/cpukit/score/src/userextremoveset.c index adaf049677..4eb13f0c55 100644 --- a/cpukit/score/src/userextremoveset.c +++ b/cpukit/score/src/userextremoveset.c @@ -41,10 +41,10 @@ void _User_extensions_Remove_set ( */ if ( the_extension->Callouts.thread_switch != NULL ) { - ISR_Level level; + ISR_lock_Context lock_context; - _Per_CPU_Acquire_all( level ); + _Per_CPU_Acquire_all( &lock_context ); _Chain_Extract_unprotected( &the_extension->Switch.Node ); - _Per_CPU_Release_all( level ); + _Per_CPU_Release_all( &lock_context ); } } -- cgit v1.2.3