diff options
Diffstat (limited to 'cpukit/include/rtems/score/schedulerimpl.h')
-rw-r--r-- | cpukit/include/rtems/score/schedulerimpl.h | 156 |
1 files changed, 55 insertions, 101 deletions
diff --git a/cpukit/include/rtems/score/schedulerimpl.h b/cpukit/include/rtems/score/schedulerimpl.h index dda1b4ee6e..2ca3e6e8b7 100644 --- a/cpukit/include/rtems/score/schedulerimpl.h +++ b/cpukit/include/rtems/score/schedulerimpl.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -10,11 +12,28 @@ /* * Copyright (C) 2010 Gedare Bloom. * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). - * Copyright (c) 2014, 2017 embedded brains GmbH - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. + * Copyright (C) 2014, 2017 embedded brains GmbH & Co. KG + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _RTEMS_SCORE_SCHEDULERIMPL_H @@ -82,7 +101,7 @@ void _Scheduler_Handler_initialization( void ); * * @return The context of @a scheduler. */ -RTEMS_INLINE_ROUTINE Scheduler_Context *_Scheduler_Get_context( +static inline Scheduler_Context *_Scheduler_Get_context( const Scheduler_Control *scheduler ) { @@ -96,7 +115,7 @@ RTEMS_INLINE_ROUTINE Scheduler_Context *_Scheduler_Get_context( * * @return The scheduler for the cpu. */ -RTEMS_INLINE_ROUTINE const Scheduler_Control *_Scheduler_Get_by_CPU( +static inline const Scheduler_Control *_Scheduler_Get_by_CPU( const Per_CPU_Control *cpu ) { @@ -116,7 +135,7 @@ RTEMS_INLINE_ROUTINE const Scheduler_Control *_Scheduler_Get_by_CPU( * @param lock_context The lock context to use for * _Scheduler_Release_critical(). */ -RTEMS_INLINE_ROUTINE void _Scheduler_Acquire_critical( +static inline void _Scheduler_Acquire_critical( const Scheduler_Control *scheduler, ISR_lock_Context *lock_context ) @@ -140,7 +159,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Acquire_critical( * @param lock_context The lock context used for * _Scheduler_Acquire_critical(). */ -RTEMS_INLINE_ROUTINE void _Scheduler_Release_critical( +static inline void _Scheduler_Release_critical( const Scheduler_Control *scheduler, ISR_lock_Context *lock_context ) @@ -166,7 +185,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Release_critical( * @return True if the non-preempt mode for threads is supported by the * scheduler, otherwise false. */ -RTEMS_INLINE_ROUTINE bool _Scheduler_Is_non_preempt_mode_supported( +static inline bool _Scheduler_Is_non_preempt_mode_supported( const Scheduler_Control *scheduler ) { @@ -197,7 +216,7 @@ RTEMS_INLINE_ROUTINE bool _Scheduler_Is_non_preempt_mode_supported( * * @param the_thread The thread which state changed previously. */ -RTEMS_INLINE_ROUTINE void _Scheduler_Schedule( Thread_Control *the_thread ) +static inline void _Scheduler_Schedule( Thread_Control *the_thread ) { const Scheduler_Control *scheduler; ISR_lock_Context lock_context; @@ -218,7 +237,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Schedule( Thread_Control *the_thread ) * * @param the_thread The yielding thread. */ -RTEMS_INLINE_ROUTINE void _Scheduler_Yield( Thread_Control *the_thread ) +static inline void _Scheduler_Yield( Thread_Control *the_thread ) { const Scheduler_Control *scheduler; ISR_lock_Context lock_context; @@ -243,7 +262,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Yield( Thread_Control *the_thread ) * * @param the_thread The thread. */ -RTEMS_INLINE_ROUTINE void _Scheduler_Block( Thread_Control *the_thread ) +static inline void _Scheduler_Block( Thread_Control *the_thread ) { #if defined(RTEMS_SMP) Chain_Node *node; @@ -305,7 +324,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Block( Thread_Control *the_thread ) * * @see _Scheduler_Node_get_priority(). */ -RTEMS_INLINE_ROUTINE void _Scheduler_Unblock( Thread_Control *the_thread ) +static inline void _Scheduler_Unblock( Thread_Control *the_thread ) { Scheduler_Node *scheduler_node; const Scheduler_Control *scheduler; @@ -340,7 +359,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Unblock( Thread_Control *the_thread ) * * @see _Scheduler_Node_get_priority(). */ -RTEMS_INLINE_ROUTINE void _Scheduler_Update_priority( Thread_Control *the_thread ) +static inline void _Scheduler_Update_priority( Thread_Control *the_thread ) { #if defined(RTEMS_SMP) Chain_Node *node; @@ -394,7 +413,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Update_priority( Thread_Control *the_thread * * @return The corresponding thread priority of the scheduler domain is returned. */ -RTEMS_INLINE_ROUTINE Priority_Control _Scheduler_Map_priority( +static inline Priority_Control _Scheduler_Map_priority( const Scheduler_Control *scheduler, Priority_Control priority ) @@ -410,7 +429,7 @@ RTEMS_INLINE_ROUTINE Priority_Control _Scheduler_Map_priority( * * @return The corresponding thread priority of the user domain is returned. */ -RTEMS_INLINE_ROUTINE Priority_Control _Scheduler_Unmap_priority( +static inline Priority_Control _Scheduler_Unmap_priority( const Scheduler_Control *scheduler, Priority_Control priority ) @@ -431,7 +450,7 @@ RTEMS_INLINE_ROUTINE Priority_Control _Scheduler_Unmap_priority( * @param the_thread The thread of the scheduler node to initialize. * @param priority The thread priority. */ -RTEMS_INLINE_ROUTINE void _Scheduler_Node_initialize( +static inline void _Scheduler_Node_initialize( const Scheduler_Control *scheduler, Scheduler_Node *node, Thread_Control *the_thread, @@ -455,7 +474,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Node_initialize( * @param scheduler The scheduler instance. * @param[out] node The scheduler node to destroy. */ -RTEMS_INLINE_ROUTINE void _Scheduler_Node_destroy( +static inline void _Scheduler_Node_destroy( const Scheduler_Control *scheduler, Scheduler_Node *node ) @@ -472,7 +491,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Node_destroy( * @param queue_context The thread queue context to provide the set of * threads for _Thread_Priority_update(). */ -RTEMS_INLINE_ROUTINE void _Scheduler_Release_job( +static inline void _Scheduler_Release_job( Thread_Control *the_thread, Priority_Node *priority_node, uint64_t deadline, @@ -499,7 +518,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Release_job( * @param queue_context The thread queue context to provide the set of * threads for _Thread_Priority_update(). */ -RTEMS_INLINE_ROUTINE void _Scheduler_Cancel_job( +static inline void _Scheduler_Cancel_job( Thread_Control *the_thread, Priority_Node *priority_node, Thread_queue_Context *queue_context @@ -525,7 +544,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Cancel_job( * * @see _Thread_Create_idle(). */ -RTEMS_INLINE_ROUTINE void _Scheduler_Start_idle( +static inline void _Scheduler_Start_idle( const Scheduler_Control *scheduler, Thread_Control *the_thread, Per_CPU_Control *cpu @@ -544,7 +563,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Start_idle( * @retval true The scheduler of the cpu is the given @a scheduler. * @retval false The scheduler of the cpu is not the given @a scheduler. */ -RTEMS_INLINE_ROUTINE bool _Scheduler_Has_processor_ownership( +static inline bool _Scheduler_Has_processor_ownership( const Scheduler_Control *scheduler, uint32_t cpu_index ) @@ -572,7 +591,7 @@ RTEMS_INLINE_ROUTINE bool _Scheduler_Has_processor_ownership( * * @return The processors of the context of the given scheduler. */ -RTEMS_INLINE_ROUTINE const Processor_mask *_Scheduler_Get_processors( +static inline const Processor_mask *_Scheduler_Get_processors( const Scheduler_Control *scheduler ) { @@ -613,7 +632,7 @@ Status_Control _Scheduler_Get_affinity( * @retval STATUS_INVALID_NUMBER The affinity is not a subset of the online * processors. */ -RTEMS_INLINE_ROUTINE Status_Control _Scheduler_default_Set_affinity_body( +static inline Status_Control _Scheduler_default_Set_affinity_body( const Scheduler_Control *scheduler, Thread_Control *the_thread, Scheduler_Node *node, @@ -650,47 +669,13 @@ Status_Control _Scheduler_Set_affinity( ); /** - * @brief Blocks the thread. - * - * @param scheduler The scheduler instance. - * @param the_thread The thread to block. - * @param node The corresponding scheduler node. - * @param extract Method to extract the thread. - * @param schedule Method for scheduling threads. - */ -RTEMS_INLINE_ROUTINE void _Scheduler_Generic_block( - const Scheduler_Control *scheduler, - Thread_Control *the_thread, - Scheduler_Node *node, - void ( *extract )( - const Scheduler_Control *, - Thread_Control *, - Scheduler_Node * - ), - void ( *schedule )( - const Scheduler_Control *, - Thread_Control *, - bool - ) -) -{ - ( *extract )( scheduler, the_thread, node ); - - /* TODO: flash critical section? */ - - if ( _Thread_Is_heir( the_thread ) ) { - ( *schedule )( scheduler, the_thread, true ); - } -} - -/** * @brief Gets the number of processors of the scheduler. * * @param scheduler The scheduler instance to get the number of processors of. * * @return The number of processors. */ -RTEMS_INLINE_ROUTINE uint32_t _Scheduler_Get_processor_count( +static inline uint32_t _Scheduler_Get_processor_count( const Scheduler_Control *scheduler ) { @@ -712,7 +697,7 @@ RTEMS_INLINE_ROUTINE uint32_t _Scheduler_Get_processor_count( * * @return The build id. */ -RTEMS_INLINE_ROUTINE Objects_Id _Scheduler_Build_id( uint32_t scheduler_index ) +static inline Objects_Id _Scheduler_Build_id( uint32_t scheduler_index ) { return _Objects_Build_id( OBJECTS_FAKE_OBJECTS_API, @@ -729,7 +714,7 @@ RTEMS_INLINE_ROUTINE Objects_Id _Scheduler_Build_id( uint32_t scheduler_index ) * * @return The scheduler index. */ -RTEMS_INLINE_ROUTINE uint32_t _Scheduler_Get_index_by_id( Objects_Id id ) +static inline uint32_t _Scheduler_Get_index_by_id( Objects_Id id ) { uint32_t minimum_id = _Scheduler_Build_id( 0 ); @@ -743,7 +728,7 @@ RTEMS_INLINE_ROUTINE uint32_t _Scheduler_Get_index_by_id( Objects_Id id ) * * @return The scheduler to the object id. */ -RTEMS_INLINE_ROUTINE const Scheduler_Control *_Scheduler_Get_by_id( +static inline const Scheduler_Control *_Scheduler_Get_by_id( Objects_Id id ) { @@ -765,7 +750,7 @@ RTEMS_INLINE_ROUTINE const Scheduler_Control *_Scheduler_Get_by_id( * * @return The index of the given scheduler. */ -RTEMS_INLINE_ROUTINE uint32_t _Scheduler_Get_index( +static inline uint32_t _Scheduler_Get_index( const Scheduler_Control *scheduler ) { @@ -802,7 +787,7 @@ typedef void ( *Scheduler_Release_idle_node )( * @param[out] the_thread The thread to change the state of. * @param new_state The new state for @a the_thread. */ -RTEMS_INLINE_ROUTINE void _Scheduler_Thread_change_state( +static inline void _Scheduler_Thread_change_state( Thread_Control *the_thread, Thread_Scheduler_state new_state ) @@ -825,7 +810,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Thread_change_state( * * @param arg is the handler argument. */ -RTEMS_INLINE_ROUTINE Thread_Control *_Scheduler_Use_idle_thread( +static inline Thread_Control *_Scheduler_Use_idle_thread( Scheduler_Node *node, Scheduler_Get_idle_node get_idle_node, void *arg @@ -853,7 +838,7 @@ RTEMS_INLINE_ROUTINE Thread_Control *_Scheduler_Use_idle_thread( * * @param arg is the handler argument. */ -RTEMS_INLINE_ROUTINE void _Scheduler_Release_idle_thread( +static inline void _Scheduler_Release_idle_thread( Scheduler_Node *node, const Thread_Control *idle, Scheduler_Release_idle_node release_idle_node, @@ -885,7 +870,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Release_idle_thread( * * @return Returns the idle thread used by the scheduler node. */ -RTEMS_INLINE_ROUTINE Thread_Control *_Scheduler_Release_idle_thread_if_necessary( +static inline Thread_Control *_Scheduler_Release_idle_thread_if_necessary( Scheduler_Node *node, Scheduler_Release_idle_node release_idle_node, void *arg @@ -913,7 +898,7 @@ RTEMS_INLINE_ROUTINE Thread_Control *_Scheduler_Release_idle_thread_if_necessary * * @param arg is the handler argument. */ -RTEMS_INLINE_ROUTINE void _Scheduler_Discard_idle_thread( +static inline void _Scheduler_Discard_idle_thread( Thread_Control *the_thread, Scheduler_Node *node, Scheduler_Release_idle_node release_idle_node, @@ -933,37 +918,6 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Discard_idle_thread( #endif /** - * @brief Updates the heir. - * - * @param[in, out] new_heir The new heir. - * @param force_dispatch Indicates whether the dispatch happens also if the - * currently running thread is set as not preemptible. - */ -RTEMS_INLINE_ROUTINE void _Scheduler_Update_heir( - Thread_Control *new_heir, - bool force_dispatch -) -{ - Thread_Control *heir = _Thread_Heir; - - if ( heir != new_heir && ( heir->is_preemptible || force_dispatch ) ) { -#if defined(RTEMS_SMP) - /* - * We need this state only for _Thread_Get_CPU_time_used_locked(). Cannot - * use _Scheduler_Thread_change_state() since THREAD_SCHEDULER_BLOCKED to - * THREAD_SCHEDULER_BLOCKED state changes are illegal for the real SMP - * schedulers. - */ - heir->Scheduler.state = THREAD_SCHEDULER_BLOCKED; - new_heir->Scheduler.state = THREAD_SCHEDULER_SCHEDULED; -#endif - _Thread_Update_CPU_time_used( heir, _Thread_Get_CPU( heir ) ); - _Thread_Heir = new_heir; - _Thread_Dispatch_necessary = true; - } -} - -/** * @brief Sets a new scheduler. * * @param new_scheduler The new scheduler to set. @@ -974,7 +928,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Update_heir( * @retval STATUS_RESOURCE_IN_USE The thread's wait queue is not empty. * @retval STATUS_UNSATISFIED The new scheduler has no processors. */ -RTEMS_INLINE_ROUTINE Status_Control _Scheduler_Set( +static inline Status_Control _Scheduler_Set( const Scheduler_Control *new_scheduler, Thread_Control *the_thread, Priority_Control priority |