From 494c2e300215c4bc539d243d6a5d060e0e2f2ef2 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 1 Apr 2014 11:48:59 +0200 Subject: score: Move priority bit map to scheduler instance Delete global variables _Priority_Major_bit_map and _Priority_Bit_map. This makes it possible to use multiple priority scheduler instances for example with clustered/partitioned scheduling on SMP. --- cpukit/score/src/schedulersimplesmp.c | 89 ++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 28 deletions(-) (limited to 'cpukit/score/src/schedulersimplesmp.c') diff --git a/cpukit/score/src/schedulersimplesmp.c b/cpukit/score/src/schedulersimplesmp.c index f4a20c104b..d222d02d42 100644 --- a/cpukit/score/src/schedulersimplesmp.c +++ b/cpukit/score/src/schedulersimplesmp.c @@ -7,7 +7,7 @@ */ /* - * Copyright (c) 2013 embedded brains GmbH. + * Copyright (c) 2013-2014 embedded brains GmbH. * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at @@ -22,23 +22,37 @@ #include #include +static Scheduler_simple_SMP_Control *_Scheduler_simple_SMP_Instance( void ) +{ + return _Scheduler.information; +} + +static Scheduler_simple_SMP_Control * +_Scheduler_simple_SMP_Self_from_SMP_base( Scheduler_SMP_Control *base ) +{ + return (Scheduler_simple_SMP_Control *) + ( (char *) base - offsetof( Scheduler_simple_SMP_Control, Base ) ); +} + void _Scheduler_simple_smp_Initialize( void ) { - Scheduler_SMP_Control *self = + Scheduler_simple_SMP_Control *self = _Workspace_Allocate_or_fatal_error( sizeof( *self ) ); - _Chain_Initialize_empty( &self->ready[ 0 ] ); - _Chain_Initialize_empty( &self->scheduled ); + _Scheduler_SMP_Initialize( &self->Base ); + _Chain_Initialize_empty( &self->Ready ); _Scheduler.information = self; } static Thread_Control *_Scheduler_simple_smp_Get_highest_ready( - Scheduler_SMP_Control *self + Scheduler_SMP_Control *base ) { + Scheduler_simple_SMP_Control *self = + _Scheduler_simple_SMP_Self_from_SMP_base( base ); Thread_Control *highest_ready = NULL; - Chain_Control *ready = &self->ready[ 0 ]; + Chain_Control *ready = &self->Ready; if ( !_Chain_Is_empty( ready ) ) { highest_ready = (Thread_Control *) _Chain_First( ready ); @@ -48,59 +62,68 @@ static Thread_Control *_Scheduler_simple_smp_Get_highest_ready( } static void _Scheduler_simple_smp_Move_from_scheduled_to_ready( - Scheduler_SMP_Control *self, + Scheduler_SMP_Control *base, Thread_Control *scheduled_to_ready ) { + Scheduler_simple_SMP_Control *self = + _Scheduler_simple_SMP_Self_from_SMP_base( base ); + _Chain_Extract_unprotected( &scheduled_to_ready->Object.Node ); _Scheduler_simple_Insert_priority_lifo( - &self->ready[ 0 ], + &self->Ready, scheduled_to_ready ); } static void _Scheduler_simple_smp_Move_from_ready_to_scheduled( - Scheduler_SMP_Control *self, + Scheduler_SMP_Control *base, Thread_Control *ready_to_scheduled ) { _Chain_Extract_unprotected( &ready_to_scheduled->Object.Node ); _Scheduler_simple_Insert_priority_fifo( - &self->scheduled, + &base->Scheduled, ready_to_scheduled ); } static void _Scheduler_simple_smp_Insert_ready_lifo( - Scheduler_SMP_Control *self, + Scheduler_SMP_Control *base, Thread_Control *thread ) { + Scheduler_simple_SMP_Control *self = + _Scheduler_simple_SMP_Self_from_SMP_base( base ); + _Chain_Insert_ordered_unprotected( - &self->ready[ 0 ], + &self->Ready, &thread->Object.Node, _Scheduler_simple_Insert_priority_lifo_order ); } static void _Scheduler_simple_smp_Insert_ready_fifo( - Scheduler_SMP_Control *self, + Scheduler_SMP_Control *base, Thread_Control *thread ) { + Scheduler_simple_SMP_Control *self = + _Scheduler_simple_SMP_Self_from_SMP_base( base ); + _Chain_Insert_ordered_unprotected( - &self->ready[ 0 ], + &self->Ready, &thread->Object.Node, _Scheduler_simple_Insert_priority_fifo_order ); } static void _Scheduler_simple_smp_Do_extract( - Scheduler_SMP_Control *self, + Scheduler_SMP_Control *base, Thread_Control *thread ) { - ( void ) self; + (void) base; thread->is_in_the_air = thread->is_scheduled; thread->is_scheduled = false; @@ -110,10 +133,10 @@ static void _Scheduler_simple_smp_Do_extract( void _Scheduler_simple_smp_Block( Thread_Control *thread ) { - Scheduler_SMP_Control *self = _Scheduler_SMP_Instance(); + Scheduler_simple_SMP_Control *self = _Scheduler_simple_SMP_Instance(); _Scheduler_SMP_Block( - self, + &self->Base, thread, _Scheduler_simple_smp_Do_extract, _Scheduler_simple_smp_Get_highest_ready, @@ -122,7 +145,7 @@ void _Scheduler_simple_smp_Block( Thread_Control *thread ) } static void _Scheduler_simple_smp_Enqueue_ordered( - Scheduler_SMP_Control *self, + Scheduler_SMP_Control *base, Thread_Control *thread, Chain_Node_order order, Scheduler_SMP_Insert insert_ready, @@ -130,7 +153,7 @@ static void _Scheduler_simple_smp_Enqueue_ordered( ) { _Scheduler_SMP_Enqueue_ordered( - self, + base, thread, order, _Scheduler_simple_smp_Get_highest_ready, @@ -143,10 +166,10 @@ static void _Scheduler_simple_smp_Enqueue_ordered( void _Scheduler_simple_smp_Enqueue_priority_lifo( Thread_Control *thread ) { - Scheduler_SMP_Control *self = _Scheduler_SMP_Instance(); + Scheduler_simple_SMP_Control *self = _Scheduler_simple_SMP_Instance(); _Scheduler_simple_smp_Enqueue_ordered( - self, + &self->Base, thread, _Scheduler_simple_Insert_priority_lifo_order, _Scheduler_simple_smp_Insert_ready_lifo, @@ -156,10 +179,10 @@ void _Scheduler_simple_smp_Enqueue_priority_lifo( Thread_Control *thread ) void _Scheduler_simple_smp_Enqueue_priority_fifo( Thread_Control *thread ) { - Scheduler_SMP_Control *self = _Scheduler_SMP_Instance(); + Scheduler_simple_SMP_Control *self = _Scheduler_simple_SMP_Instance(); _Scheduler_simple_smp_Enqueue_ordered( - self, + &self->Base, thread, _Scheduler_simple_Insert_priority_fifo_order, _Scheduler_simple_smp_Insert_ready_fifo, @@ -169,10 +192,10 @@ void _Scheduler_simple_smp_Enqueue_priority_fifo( Thread_Control *thread ) void _Scheduler_simple_smp_Extract( Thread_Control *thread ) { - Scheduler_SMP_Control *self = _Scheduler_SMP_Instance(); + Scheduler_simple_SMP_Control *self = _Scheduler_simple_SMP_Instance(); _Scheduler_SMP_Extract( - self, + &self->Base, thread, _Scheduler_simple_smp_Do_extract ); @@ -192,12 +215,22 @@ void _Scheduler_simple_smp_Yield( Thread_Control *thread ) void _Scheduler_simple_smp_Schedule( Thread_Control *thread ) { - Scheduler_SMP_Control *self = _Scheduler_SMP_Instance(); + Scheduler_simple_SMP_Control *self = _Scheduler_simple_SMP_Instance(); _Scheduler_SMP_Schedule( - self, + &self->Base, thread, _Scheduler_simple_smp_Get_highest_ready, _Scheduler_simple_smp_Move_from_ready_to_scheduled ); } + +void _Scheduler_simple_smp_Start_idle( + Thread_Control *thread, + Per_CPU_Control *cpu +) +{ + Scheduler_simple_SMP_Control *self = _Scheduler_simple_SMP_Instance(); + + _Scheduler_SMP_Start_idle( &self->Base, thread, cpu ); +} -- cgit v1.2.3