mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-21 11:08:59 +08:00
score: Change scheduler node init and destroy
Provide the scheduler node to initialize or destroy to the corresponding operations. This makes it possible to have more than one scheduler node per thread.
This commit is contained in:
@@ -130,12 +130,13 @@ typedef struct {
|
||||
/** @see _Scheduler_Node_initialize() */
|
||||
void ( *node_initialize )(
|
||||
const Scheduler_Control *,
|
||||
Scheduler_Node *,
|
||||
Thread_Control *,
|
||||
Priority_Control
|
||||
);
|
||||
|
||||
/** @see _Scheduler_Node_destroy() */
|
||||
void ( *node_destroy )( const Scheduler_Control *, Thread_Control * );
|
||||
void ( *node_destroy )( const Scheduler_Control *, Scheduler_Node * );
|
||||
|
||||
/** @see _Scheduler_Release_job() */
|
||||
void ( *release_job ) (
|
||||
@@ -498,11 +499,13 @@ void _Scheduler_default_Schedule(
|
||||
* @brief Performs the scheduler base node initialization.
|
||||
*
|
||||
* @param[in] scheduler Unused.
|
||||
* @param[in] node The node to initialize.
|
||||
* @param[in] the_thread Unused.
|
||||
* @param[in] priority The thread priority.
|
||||
*/
|
||||
void _Scheduler_default_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
);
|
||||
@@ -511,11 +514,11 @@ void _Scheduler_default_Node_initialize(
|
||||
* @brief Does nothing.
|
||||
*
|
||||
* @param[in] scheduler Unused.
|
||||
* @param[in] the_thread Unused.
|
||||
* @param[in] node Unused.
|
||||
*/
|
||||
void _Scheduler_default_Node_destroy(
|
||||
const Scheduler_Control *scheduler,
|
||||
Thread_Control *the_thread
|
||||
Scheduler_Node *node
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@@ -345,6 +345,7 @@ void _Scheduler_CBS_Budget_callout(
|
||||
*/
|
||||
void _Scheduler_CBS_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
);
|
||||
|
||||
@@ -43,6 +43,13 @@ RTEMS_INLINE_ROUTINE Scheduler_CBS_Node *_Scheduler_CBS_Thread_get_node(
|
||||
return (Scheduler_CBS_Node *) _Scheduler_Thread_get_node( the_thread );
|
||||
}
|
||||
|
||||
RTEMS_INLINE_ROUTINE Scheduler_CBS_Node *_Scheduler_CBS_Node_downcast(
|
||||
Scheduler_Node *node
|
||||
)
|
||||
{
|
||||
return (Scheduler_CBS_Node *) node;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -152,11 +152,13 @@ void _Scheduler_EDF_Schedule(
|
||||
* @brief Initializes an EDF specific scheduler node of @a the_thread.
|
||||
*
|
||||
* @param[in] scheduler The scheduler instance.
|
||||
* @param[in] the_thread being initialized.
|
||||
* @param[in] node being initialized.
|
||||
* @param[in] the_thread the thread of the node.
|
||||
* @param[in] priority The thread priority.
|
||||
*/
|
||||
void _Scheduler_EDF_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
);
|
||||
|
||||
@@ -53,6 +53,13 @@ RTEMS_INLINE_ROUTINE Scheduler_EDF_Node *_Scheduler_EDF_Thread_get_node(
|
||||
return (Scheduler_EDF_Node *) _Scheduler_Thread_get_node( the_thread );
|
||||
}
|
||||
|
||||
RTEMS_INLINE_ROUTINE Scheduler_EDF_Node * _Scheduler_EDF_Node_downcast(
|
||||
Scheduler_Node *node
|
||||
)
|
||||
{
|
||||
return (Scheduler_EDF_Node *) node;
|
||||
}
|
||||
|
||||
RTEMS_INLINE_ROUTINE bool _Scheduler_EDF_Less(
|
||||
const void *left,
|
||||
const RBTree_Node *right
|
||||
|
||||
@@ -455,17 +455,20 @@ RTEMS_INLINE_ROUTINE Priority_Control _Scheduler_Unmap_priority(
|
||||
* destroyed.
|
||||
*
|
||||
* @param[in] scheduler The scheduler instance.
|
||||
* @param[in] the_thread The thread containing the scheduler node.
|
||||
* @param[in] node The scheduler node to initialize.
|
||||
* @param[in] the_thread The thread of the scheduler node to initialize.
|
||||
* @param[in] priority The thread priority.
|
||||
*/
|
||||
RTEMS_INLINE_ROUTINE void _Scheduler_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
)
|
||||
{
|
||||
( *scheduler->Operations.node_initialize )(
|
||||
scheduler,
|
||||
node,
|
||||
the_thread,
|
||||
priority
|
||||
);
|
||||
@@ -478,14 +481,14 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Node_initialize(
|
||||
* after a corresponding _Scheduler_Node_initialize().
|
||||
*
|
||||
* @param[in] scheduler The scheduler instance.
|
||||
* @param[in] the_thread The thread containing the scheduler node.
|
||||
* @param[in] node The scheduler node to destroy.
|
||||
*/
|
||||
RTEMS_INLINE_ROUTINE void _Scheduler_Node_destroy(
|
||||
const Scheduler_Control *scheduler,
|
||||
Thread_Control *the_thread
|
||||
Scheduler_Node *node
|
||||
)
|
||||
{
|
||||
( *scheduler->Operations.node_destroy )( scheduler, the_thread );
|
||||
( *scheduler->Operations.node_destroy )( scheduler, node );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1464,10 +1467,15 @@ RTEMS_INLINE_ROUTINE Status_Control _Scheduler_Set(
|
||||
_Scheduler_Block( the_thread );
|
||||
}
|
||||
|
||||
_Scheduler_Node_destroy( old_scheduler, the_thread );
|
||||
_Scheduler_Node_destroy( old_scheduler, own_node );
|
||||
the_thread->Scheduler.own_control = new_scheduler;
|
||||
the_thread->Scheduler.control = new_scheduler;
|
||||
_Scheduler_Node_initialize( new_scheduler, the_thread, priority );
|
||||
_Scheduler_Node_initialize(
|
||||
new_scheduler,
|
||||
own_node,
|
||||
the_thread,
|
||||
priority
|
||||
);
|
||||
|
||||
if ( _States_Is_ready( current_state ) ) {
|
||||
_Scheduler_Unblock( the_thread );
|
||||
|
||||
@@ -159,6 +159,7 @@ Scheduler_Void_or_thread _Scheduler_priority_Update_priority(
|
||||
|
||||
void _Scheduler_priority_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
);
|
||||
|
||||
@@ -73,12 +73,14 @@ extern "C" {
|
||||
* This routine allocates @a thread->scheduler.
|
||||
*
|
||||
* @param[in] scheduler points to the scheduler specific information.
|
||||
* @param[in] thread is the thread the scheduler is allocating
|
||||
* @param[in] node is the node the scheduler is allocating
|
||||
* management memory for.
|
||||
* @param[in] the_thread the thread of the node.
|
||||
* @param[in] priority is the thread priority.
|
||||
*/
|
||||
void _Scheduler_priority_affinity_SMP_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
);
|
||||
|
||||
@@ -48,6 +48,13 @@ RTEMS_INLINE_ROUTINE Scheduler_priority_Node *_Scheduler_priority_Thread_get_nod
|
||||
return (Scheduler_priority_Node *) _Scheduler_Thread_get_node( the_thread );
|
||||
}
|
||||
|
||||
RTEMS_INLINE_ROUTINE Scheduler_priority_Node *_Scheduler_priority_Node_downcast(
|
||||
Scheduler_Node *node
|
||||
)
|
||||
{
|
||||
return (Scheduler_priority_Node *) node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Ready queue initialization.
|
||||
*
|
||||
|
||||
@@ -99,6 +99,7 @@ void _Scheduler_priority_SMP_Initialize( const Scheduler_Control *scheduler );
|
||||
|
||||
void _Scheduler_priority_SMP_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
);
|
||||
|
||||
@@ -82,6 +82,7 @@ void _Scheduler_simple_SMP_Initialize( const Scheduler_Control *scheduler );
|
||||
|
||||
void _Scheduler_simple_SMP_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
);
|
||||
|
||||
@@ -99,6 +99,7 @@ void _Scheduler_strong_APA_Initialize( const Scheduler_Control *scheduler );
|
||||
|
||||
void _Scheduler_strong_APA_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
);
|
||||
|
||||
@@ -22,14 +22,15 @@
|
||||
|
||||
void _Scheduler_CBS_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
)
|
||||
{
|
||||
Scheduler_CBS_Node *node;
|
||||
Scheduler_CBS_Node *the_node;
|
||||
|
||||
_Scheduler_EDF_Node_initialize( scheduler, the_thread, priority );
|
||||
_Scheduler_EDF_Node_initialize( scheduler, node, the_thread, priority );
|
||||
|
||||
node = _Scheduler_CBS_Thread_get_node( the_thread );
|
||||
node->cbs_server = NULL;
|
||||
the_node = _Scheduler_CBS_Node_downcast( node );
|
||||
the_node->cbs_server = NULL;
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
|
||||
void _Scheduler_default_Node_destroy(
|
||||
const Scheduler_Control *scheduler,
|
||||
Thread_Control *the_thread
|
||||
Scheduler_Node *node
|
||||
)
|
||||
{
|
||||
(void) scheduler;
|
||||
(void) the_thread;
|
||||
(void) node;
|
||||
}
|
||||
|
||||
@@ -23,12 +23,11 @@
|
||||
|
||||
void _Scheduler_default_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
)
|
||||
{
|
||||
Scheduler_Node *node = _Scheduler_Thread_get_own_node( the_thread );
|
||||
|
||||
(void) scheduler;
|
||||
|
||||
_Scheduler_Node_do_initialize( node, the_thread, priority );
|
||||
|
||||
@@ -22,15 +22,17 @@
|
||||
|
||||
void _Scheduler_EDF_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
)
|
||||
{
|
||||
Scheduler_EDF_Node *node = _Scheduler_EDF_Thread_get_node( the_thread );
|
||||
Scheduler_EDF_Node *the_node;
|
||||
|
||||
(void) scheduler;
|
||||
|
||||
_Scheduler_Node_do_initialize( &node->Base, the_thread, priority );
|
||||
_Scheduler_Node_do_initialize( node, the_thread, priority );
|
||||
|
||||
node->thread = the_thread;
|
||||
the_node = _Scheduler_EDF_Node_downcast( node );
|
||||
the_node->thread = the_thread;
|
||||
}
|
||||
|
||||
@@ -35,19 +35,20 @@ void _Scheduler_priority_Initialize( const Scheduler_Control *scheduler )
|
||||
|
||||
void _Scheduler_priority_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
)
|
||||
{
|
||||
Scheduler_priority_Context *context;
|
||||
Scheduler_priority_Node *node;
|
||||
Scheduler_priority_Node *the_node;
|
||||
|
||||
_Scheduler_Node_do_initialize( node, the_thread, priority );
|
||||
|
||||
context = _Scheduler_priority_Get_context( scheduler );
|
||||
node = _Scheduler_priority_Thread_get_node( the_thread );
|
||||
|
||||
_Scheduler_Node_do_initialize( &node->Base, the_thread, priority );
|
||||
the_node = _Scheduler_priority_Node_downcast( node );
|
||||
_Scheduler_priority_Ready_queue_update(
|
||||
&node->Ready_queue,
|
||||
&the_node->Ready_queue,
|
||||
priority,
|
||||
&context->Bit_map,
|
||||
&context->Ready[ 0 ]
|
||||
|
||||
@@ -60,15 +60,6 @@ static bool _Scheduler_priority_affinity_SMP_Insert_priority_fifo_order(
|
||||
&& _Scheduler_SMP_Insert_priority_fifo_order( to_insert, next );
|
||||
}
|
||||
|
||||
static Scheduler_priority_affinity_SMP_Node *
|
||||
_Scheduler_priority_affinity_SMP_Thread_get_own_node(
|
||||
Thread_Control *thread
|
||||
)
|
||||
{
|
||||
return (Scheduler_priority_affinity_SMP_Node *)
|
||||
_Scheduler_Thread_get_own_node( thread );
|
||||
}
|
||||
|
||||
/*
|
||||
* This method returns the scheduler node for the specified thread
|
||||
* as a scheduler specific type.
|
||||
@@ -96,20 +87,21 @@ _Scheduler_priority_affinity_SMP_Node_downcast(
|
||||
*/
|
||||
void _Scheduler_priority_affinity_SMP_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
)
|
||||
{
|
||||
Scheduler_priority_affinity_SMP_Node *node =
|
||||
_Scheduler_priority_affinity_SMP_Thread_get_own_node( the_thread );
|
||||
Scheduler_priority_affinity_SMP_Node *the_node;
|
||||
|
||||
_Scheduler_priority_SMP_Node_initialize( scheduler, the_thread, priority );
|
||||
_Scheduler_priority_SMP_Node_initialize( scheduler, node, the_thread, priority );
|
||||
|
||||
/*
|
||||
* All we add is affinity information to the basic SMP node.
|
||||
*/
|
||||
node->Affinity = *_CPU_set_Default();
|
||||
node->Affinity.set = &node->Affinity.preallocated;
|
||||
the_node = _Scheduler_priority_affinity_SMP_Node_downcast( node );
|
||||
the_node->Affinity = *_CPU_set_Default();
|
||||
the_node->Affinity.set = &the_node->Affinity.preallocated;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -47,23 +47,22 @@ void _Scheduler_priority_SMP_Initialize( const Scheduler_Control *scheduler )
|
||||
|
||||
void _Scheduler_priority_SMP_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
)
|
||||
{
|
||||
Scheduler_Context *context;
|
||||
Scheduler_priority_SMP_Context *self;
|
||||
Scheduler_priority_SMP_Node *node;
|
||||
Scheduler_priority_SMP_Node *the_node;
|
||||
|
||||
the_node = _Scheduler_priority_SMP_Node_downcast( node );
|
||||
_Scheduler_SMP_Node_initialize( &the_node->Base, the_thread, priority );
|
||||
|
||||
context = _Scheduler_Get_context( scheduler );
|
||||
self = _Scheduler_priority_SMP_Get_self( context );
|
||||
node = _Scheduler_priority_SMP_Node_downcast(
|
||||
_Scheduler_Thread_get_own_node( the_thread )
|
||||
);
|
||||
|
||||
_Scheduler_SMP_Node_initialize( &node->Base, the_thread, priority );
|
||||
_Scheduler_priority_Ready_queue_update(
|
||||
&node->Ready_queue,
|
||||
&the_node->Ready_queue,
|
||||
priority,
|
||||
&self->Bit_map,
|
||||
&self->Ready[ 0 ]
|
||||
|
||||
@@ -44,26 +44,29 @@ void _Scheduler_simple_SMP_Initialize( const Scheduler_Control *scheduler )
|
||||
|
||||
void _Scheduler_simple_SMP_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
)
|
||||
{
|
||||
Scheduler_SMP_Node *node = _Scheduler_SMP_Thread_get_own_node( the_thread );
|
||||
Scheduler_SMP_Node *the_node;
|
||||
|
||||
_Scheduler_SMP_Node_initialize( node, the_thread, priority );
|
||||
the_node = _Scheduler_SMP_Node_downcast( node );
|
||||
_Scheduler_SMP_Node_initialize( the_node, the_thread, priority );
|
||||
}
|
||||
|
||||
static void _Scheduler_simple_SMP_Do_update(
|
||||
Scheduler_Context *context,
|
||||
Scheduler_Node *node_to_update,
|
||||
Scheduler_Node *node,
|
||||
Priority_Control new_priority
|
||||
)
|
||||
{
|
||||
Scheduler_SMP_Node *node = _Scheduler_SMP_Node_downcast( node_to_update );
|
||||
Scheduler_SMP_Node *the_node;
|
||||
|
||||
(void) context;
|
||||
|
||||
_Scheduler_SMP_Node_update_priority( node, new_priority );
|
||||
the_node = _Scheduler_SMP_Node_downcast( node );
|
||||
_Scheduler_SMP_Node_update_priority( the_node, new_priority );
|
||||
}
|
||||
|
||||
static Scheduler_Node *_Scheduler_simple_SMP_Get_highest_ready(
|
||||
|
||||
@@ -173,23 +173,22 @@ void _Scheduler_strong_APA_Initialize( const Scheduler_Control *scheduler )
|
||||
|
||||
void _Scheduler_strong_APA_Node_initialize(
|
||||
const Scheduler_Control *scheduler,
|
||||
Scheduler_Node *node,
|
||||
Thread_Control *the_thread,
|
||||
Priority_Control priority
|
||||
)
|
||||
{
|
||||
Scheduler_Context *context;
|
||||
Scheduler_strong_APA_Context *self;
|
||||
Scheduler_strong_APA_Node *node;
|
||||
Scheduler_strong_APA_Node *the_node;
|
||||
|
||||
the_node = _Scheduler_strong_APA_Node_downcast( node );
|
||||
_Scheduler_SMP_Node_initialize( &the_node->Base, the_thread, priority );
|
||||
|
||||
context = _Scheduler_Get_context( scheduler );
|
||||
self = _Scheduler_strong_APA_Get_self( context );
|
||||
node = _Scheduler_strong_APA_Node_downcast(
|
||||
_Scheduler_Thread_get_own_node( the_thread )
|
||||
);
|
||||
|
||||
_Scheduler_SMP_Node_initialize( &node->Base, the_thread, priority );
|
||||
_Scheduler_priority_Ready_queue_update(
|
||||
&node->Ready_queue,
|
||||
&the_node->Ready_queue,
|
||||
priority,
|
||||
&self->Bit_map,
|
||||
&self->Ready[ 0 ]
|
||||
|
||||
@@ -52,6 +52,7 @@ bool _Thread_Initialize(
|
||||
#endif
|
||||
bool extension_status;
|
||||
size_t i;
|
||||
Scheduler_Node *scheduler_node;
|
||||
bool scheduler_node_initialized = false;
|
||||
Per_CPU_Control *cpu = _Per_CPU_Get_by_index( 0 );
|
||||
|
||||
@@ -173,11 +174,13 @@ bool _Thread_Initialize(
|
||||
#endif
|
||||
}
|
||||
|
||||
scheduler_node = the_thread->Scheduler.node;
|
||||
|
||||
#if defined(RTEMS_SMP)
|
||||
RTEMS_STATIC_ASSERT( THREAD_SCHEDULER_BLOCKED == 0, Scheduler_state );
|
||||
the_thread->Scheduler.own_control = scheduler;
|
||||
the_thread->Scheduler.control = scheduler;
|
||||
the_thread->Scheduler.own_node = the_thread->Scheduler.node;
|
||||
the_thread->Scheduler.own_node = scheduler_node;
|
||||
_Resource_Node_initialize( &the_thread->Resource_node );
|
||||
_Atomic_Store_uintptr(
|
||||
&the_thread->Lock.current.atomic,
|
||||
@@ -204,7 +207,7 @@ bool _Thread_Initialize(
|
||||
|
||||
RTEMS_STATIC_ASSERT( THREAD_WAIT_FLAGS_INITIAL == 0, Wait_flags );
|
||||
|
||||
_Scheduler_Node_initialize( scheduler, the_thread, priority );
|
||||
_Scheduler_Node_initialize( scheduler, scheduler_node, the_thread, priority );
|
||||
scheduler_node_initialized = true;
|
||||
|
||||
/* POSIX Keys */
|
||||
@@ -232,7 +235,7 @@ bool _Thread_Initialize(
|
||||
failed:
|
||||
|
||||
if ( scheduler_node_initialized ) {
|
||||
_Scheduler_Node_destroy( scheduler, the_thread );
|
||||
_Scheduler_Node_destroy( scheduler, scheduler_node );
|
||||
}
|
||||
|
||||
_Workspace_Free( the_thread->Start.tls_area );
|
||||
|
||||
@@ -183,7 +183,10 @@ static void _Thread_Free( Thread_Control *the_thread )
|
||||
_User_extensions_Thread_delete( the_thread );
|
||||
_User_extensions_Destroy_iterators( the_thread );
|
||||
_ISR_lock_Destroy( &the_thread->Keys.Lock );
|
||||
_Scheduler_Node_destroy( _Scheduler_Get( the_thread ), the_thread );
|
||||
_Scheduler_Node_destroy(
|
||||
_Scheduler_Get( the_thread ),
|
||||
_Scheduler_Thread_get_own_node( the_thread )
|
||||
);
|
||||
_ISR_lock_Destroy( &the_thread->Timer.Lock );
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user