[PATCH v1 1/3] priorityaffinitysmp: Update block state check

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Nov 17 16:13:12 UTC 2021


On 17/11/2021 16:33, Ryan Long wrote:
> The thread's blocked status is recorded in the thread's scheduler state,
> not directly in the thread state. This prevents blocking from being
> nested which violates asserts and eventually causes a crash.
> ---
>   cpukit/score/src/schedulerpriorityaffinitysmp.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/cpukit/score/src/schedulerpriorityaffinitysmp.c b/cpukit/score/src/schedulerpriorityaffinitysmp.c
> index 10f6808..2bad6ff 100644
> --- a/cpukit/score/src/schedulerpriorityaffinitysmp.c
> +++ b/cpukit/score/src/schedulerpriorityaffinitysmp.c
> @@ -550,7 +550,7 @@ Status_Control _Scheduler_priority_affinity_SMP_Set_affinity(
>   {
>     Scheduler_Context                    *context;
>     Scheduler_priority_affinity_SMP_Node *node;
> -  States_Control                        current_state;
> +  Thread_Scheduler_state                current_state;
>     Processor_mask                        my_affinity;
>   
>     context = _Scheduler_Get_context( scheduler );
> @@ -569,15 +569,15 @@ Status_Control _Scheduler_priority_affinity_SMP_Set_affinity(
>     if ( _Processor_mask_Is_equal( &node->Affinity, affinity ) )
>       return STATUS_SUCCESSFUL;
>   
> -  current_state = thread->current_state;
> +  current_state = thread->Scheduler.state;
>   
> -  if ( _States_Is_ready( current_state ) ) {
> +  if ( current_state == THREAD_SCHEDULER_READY ) {
>       _Scheduler_priority_affinity_SMP_Block( scheduler, thread, &node->Base.Base.Base );
>     }
>   
>     _Processor_mask_Assign( &node->Affinity, affinity );
>   
> -  if ( _States_Is_ready( current_state ) ) {
> +  if ( current_state == THREAD_SCHEDULER_READY ) {
>       /*
>        * FIXME: Do not ignore threads in need for help.
>        */

This change may fix this particular issue, however, looking at this code 
fragment, there are probably more issues. Firstly, the 
thread->Scheduler.state access needs to be protected by the thread 
scheduler lock. Secondly, this code should probably use the scheduler 
SMP node state.

I would rewrite it to use _Scheduler_SMP_Set_affinity().

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber at embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/


More information about the devel mailing list