diff options
Diffstat (limited to 'cpukit/include/rtems')
-rw-r--r-- | cpukit/include/rtems/posix/pthreadimpl.h | 15 | ||||
-rw-r--r-- | cpukit/include/rtems/rtems/modesimpl.h | 8 | ||||
-rw-r--r-- | cpukit/include/rtems/score/scheduler.h | 17 | ||||
-rw-r--r-- | cpukit/include/rtems/score/schedulercbs.h | 11 | ||||
-rw-r--r-- | cpukit/include/rtems/score/scheduleredf.h | 1 | ||||
-rw-r--r-- | cpukit/include/rtems/score/scheduleredfsmp.h | 1 | ||||
-rw-r--r-- | cpukit/include/rtems/score/schedulerimpl.h | 38 | ||||
-rw-r--r-- | cpukit/include/rtems/score/schedulerpriority.h | 1 | ||||
-rw-r--r-- | cpukit/include/rtems/score/schedulerpriorityaffinitysmp.h | 1 | ||||
-rw-r--r-- | cpukit/include/rtems/score/schedulerprioritysmp.h | 1 | ||||
-rw-r--r-- | cpukit/include/rtems/score/schedulersimple.h | 1 | ||||
-rw-r--r-- | cpukit/include/rtems/score/schedulersimplesmp.h | 1 | ||||
-rw-r--r-- | cpukit/include/rtems/score/schedulerstrongapa.h | 1 | ||||
-rw-r--r-- | cpukit/include/rtems/score/thread.h | 94 | ||||
-rw-r--r-- | cpukit/include/rtems/score/threadcpubudget.h | 102 | ||||
-rw-r--r-- | cpukit/include/rtems/score/threadimpl.h | 14 |
16 files changed, 164 insertions, 143 deletions
diff --git a/cpukit/include/rtems/posix/pthreadimpl.h b/cpukit/include/rtems/posix/pthreadimpl.h index 723b20e8d2..0dc7d9dac5 100644 --- a/cpukit/include/rtems/posix/pthreadimpl.h +++ b/cpukit/include/rtems/posix/pthreadimpl.h @@ -47,7 +47,7 @@ RTEMS_INLINE_ROUTINE void _POSIX_Threads_Sporadic_timer_insert( POSIX_API_Control *api ) { - the_thread->cpu_time_budget = + the_thread->CPU_budget.available = _Timespec_To_ticks( &api->Sporadic.sched_ss_init_budget ); _Watchdog_Per_CPU_insert_ticks( @@ -61,19 +61,12 @@ RTEMS_INLINE_ROUTINE void _POSIX_Threads_Sporadic_timer_insert( void _POSIX_Threads_Sporadic_timer( Watchdog_Control *watchdog ); /** - * @brief POSIX threads sporadic budget callout. - * - * This routine handles the sporadic scheduling algorithm. - * - * @param[in] the_thread is a pointer to the thread whose budget - * has been exceeded. + * @brief The POSIX threads sporadic budget operations. */ -void _POSIX_Threads_Sporadic_budget_callout( - Thread_Control *the_thread -); +extern const Thread_CPU_budget_operations _POSIX_Threads_Sporadic_budget; int _POSIX_Thread_Translate_to_sched_policy( - Thread_CPU_budget_algorithms budget_algorithm + const Thread_CPU_budget_operations *operations ); /** diff --git a/cpukit/include/rtems/rtems/modesimpl.h b/cpukit/include/rtems/rtems/modesimpl.h index 924e12fbee..8fdab263f1 100644 --- a/cpukit/include/rtems/rtems/modesimpl.h +++ b/cpukit/include/rtems/rtems/modesimpl.h @@ -22,6 +22,7 @@ #include <rtems/score/schedulerimpl.h> #include <rtems/score/smpimpl.h> #include <rtems/score/threadimpl.h> +#include <rtems/score/threadcpubudget.h> #include <rtems/config.h> #ifdef __cplusplus @@ -148,10 +149,11 @@ RTEMS_INLINE_ROUTINE void _Modes_Apply_timeslice_to_thread( ) { if ( _Modes_Is_timeslice( mode_set ) ) { - the_thread->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE; - the_thread->cpu_time_budget = rtems_configuration_get_ticks_per_timeslice(); + the_thread->CPU_budget.operations = &_Thread_CPU_budget_reset_timeslice; + the_thread->CPU_budget.available = + rtems_configuration_get_ticks_per_timeslice(); } else { - the_thread->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE; + the_thread->CPU_budget.operations = NULL; } } diff --git a/cpukit/include/rtems/score/scheduler.h b/cpukit/include/rtems/score/scheduler.h index df9477fbeb..ad9d630023 100644 --- a/cpukit/include/rtems/score/scheduler.h +++ b/cpukit/include/rtems/score/scheduler.h @@ -217,9 +217,6 @@ typedef struct { Thread_queue_Context * ); - /** @see _Scheduler_Tick() */ - void ( *tick )( const Scheduler_Control *, Thread_Control * ); - /** @see _Scheduler_Start_idle() */ void ( *start_idle )( const Scheduler_Control *, @@ -544,20 +541,6 @@ void _Scheduler_default_Cancel_job( ); /** - * @brief Performs tick operations depending on the CPU budget algorithm for - * each executing thread. - * - * This routine is invoked as part of processing each clock tick. - * - * @param scheduler The scheduler. - * @param[in, out] executing An executing thread. - */ -void _Scheduler_default_Tick( - const Scheduler_Control *scheduler, - Thread_Control *executing -); - -/** * @brief Starts an idle thread. * * @param scheduler This parameter is unused. diff --git a/cpukit/include/rtems/score/schedulercbs.h b/cpukit/include/rtems/score/schedulercbs.h index 4b7efc8340..8a9a49ccd9 100644 --- a/cpukit/include/rtems/score/schedulercbs.h +++ b/cpukit/include/rtems/score/schedulercbs.h @@ -67,7 +67,6 @@ extern "C" { _Scheduler_default_Node_destroy, /* node destroy entry point */ \ _Scheduler_CBS_Release_job, /* new period of task */ \ _Scheduler_CBS_Cancel_job, /* cancel period of task */ \ - _Scheduler_default_Tick, /* tick entry point */ \ _Scheduler_default_Start_idle /* start idle entry point */ \ SCHEDULER_DEFAULT_SET_AFFINITY_OPERATION \ } @@ -394,15 +393,9 @@ int _Scheduler_CBS_Set_parameters ( ); /** - * @brief Invoked when a limited time quantum is exceeded. - * - * This routine is invoked when a limited time quantum is exceeded. - * - * @param the_thread The thread that exceeded a limited time quantum. + * @brief These are the CBS CPU budget operations. */ -void _Scheduler_CBS_Budget_callout( - Thread_Control *the_thread -); +extern const Thread_CPU_budget_operations _Scheduler_CBS_Budget; /** * @brief Initializes a CBS specific scheduler node of @a the_thread. diff --git a/cpukit/include/rtems/score/scheduleredf.h b/cpukit/include/rtems/score/scheduleredf.h index 9e643b93eb..258563217f 100644 --- a/cpukit/include/rtems/score/scheduleredf.h +++ b/cpukit/include/rtems/score/scheduleredf.h @@ -66,7 +66,6 @@ extern "C" { _Scheduler_default_Node_destroy, /* node destroy entry point */ \ _Scheduler_EDF_Release_job, /* new period of task */ \ _Scheduler_EDF_Cancel_job, /* cancel period of task */ \ - _Scheduler_default_Tick, /* tick entry point */ \ _Scheduler_default_Start_idle /* start idle entry point */ \ SCHEDULER_DEFAULT_SET_AFFINITY_OPERATION \ } diff --git a/cpukit/include/rtems/score/scheduleredfsmp.h b/cpukit/include/rtems/score/scheduleredfsmp.h index 1841aa4a7b..85e438e81d 100644 --- a/cpukit/include/rtems/score/scheduleredfsmp.h +++ b/cpukit/include/rtems/score/scheduleredfsmp.h @@ -128,7 +128,6 @@ typedef struct { _Scheduler_default_Node_destroy, \ _Scheduler_EDF_Release_job, \ _Scheduler_EDF_Cancel_job, \ - _Scheduler_default_Tick, \ _Scheduler_EDF_SMP_Start_idle, \ _Scheduler_EDF_SMP_Set_affinity \ } diff --git a/cpukit/include/rtems/score/schedulerimpl.h b/cpukit/include/rtems/score/schedulerimpl.h index 50110ea6e7..2c53c05056 100644 --- a/cpukit/include/rtems/score/schedulerimpl.h +++ b/cpukit/include/rtems/score/schedulerimpl.h @@ -600,44 +600,6 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Cancel_job( } /** - * @brief Scheduler method invoked at each clock tick. - * - * This method is invoked at each clock tick to allow the scheduler - * implementation to perform any activities required. For the - * scheduler which support standard RTEMS features, this includes - * time-slicing management. - * - * @param cpu The cpu control for the operation. - */ -RTEMS_INLINE_ROUTINE void _Scheduler_Tick( const Per_CPU_Control *cpu ) -{ - const Scheduler_Control *scheduler; - Thread_Control *executing; - - scheduler = _Scheduler_Get_by_CPU( cpu ); - -#if defined(RTEMS_SMP) - if ( scheduler == NULL ) { - /* - * In SMP configurations, processors may be removed/added at runtime - * from/to a scheduler. There may be still clock interrupts on currently - * unassigned processors. - */ - return; - } -#endif - - /* - * Each online processor has at least an idle thread as the executing thread - * even in case it has currently no scheduler assigned. Clock interrupts on - * processors which are not online would be a severe bug of the Clock Driver. - */ - executing = _Per_CPU_Get_executing( cpu ); - _Assert( executing != NULL ); - ( *scheduler->Operations.tick )( scheduler, executing ); -} - -/** * @brief Starts the idle thread for a particular processor. * * @param scheduler The scheduler instance. diff --git a/cpukit/include/rtems/score/schedulerpriority.h b/cpukit/include/rtems/score/schedulerpriority.h index e0991f5e31..1ddbb4a8cc 100644 --- a/cpukit/include/rtems/score/schedulerpriority.h +++ b/cpukit/include/rtems/score/schedulerpriority.h @@ -57,7 +57,6 @@ extern "C" { _Scheduler_default_Node_destroy, /* node destroy entry point */ \ _Scheduler_default_Release_job, /* new period of task */ \ _Scheduler_default_Cancel_job, /* cancel period of task */ \ - _Scheduler_default_Tick, /* tick entry point */ \ _Scheduler_default_Start_idle /* start idle entry point */ \ SCHEDULER_DEFAULT_SET_AFFINITY_OPERATION \ } diff --git a/cpukit/include/rtems/score/schedulerpriorityaffinitysmp.h b/cpukit/include/rtems/score/schedulerpriorityaffinitysmp.h index 1b660fa296..e997e81128 100644 --- a/cpukit/include/rtems/score/schedulerpriorityaffinitysmp.h +++ b/cpukit/include/rtems/score/schedulerpriorityaffinitysmp.h @@ -73,7 +73,6 @@ extern "C" { _Scheduler_default_Node_destroy, \ _Scheduler_default_Release_job, \ _Scheduler_default_Cancel_job, \ - _Scheduler_default_Tick, \ _Scheduler_SMP_Start_idle, \ _Scheduler_priority_affinity_SMP_Set_affinity \ } diff --git a/cpukit/include/rtems/score/schedulerprioritysmp.h b/cpukit/include/rtems/score/schedulerprioritysmp.h index 56f4aa5a5b..fe314fb05b 100644 --- a/cpukit/include/rtems/score/schedulerprioritysmp.h +++ b/cpukit/include/rtems/score/schedulerprioritysmp.h @@ -101,7 +101,6 @@ typedef struct { _Scheduler_default_Node_destroy, \ _Scheduler_default_Release_job, \ _Scheduler_default_Cancel_job, \ - _Scheduler_default_Tick, \ _Scheduler_SMP_Start_idle \ SCHEDULER_DEFAULT_SET_AFFINITY_OPERATION \ } diff --git a/cpukit/include/rtems/score/schedulersimple.h b/cpukit/include/rtems/score/schedulersimple.h index 63310e9796..15471a6498 100644 --- a/cpukit/include/rtems/score/schedulersimple.h +++ b/cpukit/include/rtems/score/schedulersimple.h @@ -56,7 +56,6 @@ extern "C" { _Scheduler_default_Node_destroy, /* node destroy entry point */ \ _Scheduler_default_Release_job, /* new period of task */ \ _Scheduler_default_Cancel_job, /* cancel period of task */ \ - _Scheduler_default_Tick, /* tick entry point */ \ _Scheduler_default_Start_idle /* start idle entry point */ \ SCHEDULER_DEFAULT_SET_AFFINITY_OPERATION \ } diff --git a/cpukit/include/rtems/score/schedulersimplesmp.h b/cpukit/include/rtems/score/schedulersimplesmp.h index 961e60ae73..c8394781c9 100644 --- a/cpukit/include/rtems/score/schedulersimplesmp.h +++ b/cpukit/include/rtems/score/schedulersimplesmp.h @@ -83,7 +83,6 @@ typedef struct { _Scheduler_default_Node_destroy, \ _Scheduler_default_Release_job, \ _Scheduler_default_Cancel_job, \ - _Scheduler_default_Tick, \ _Scheduler_SMP_Start_idle \ SCHEDULER_DEFAULT_SET_AFFINITY_OPERATION \ } diff --git a/cpukit/include/rtems/score/schedulerstrongapa.h b/cpukit/include/rtems/score/schedulerstrongapa.h index a3a19d80c1..bbded1b493 100644 --- a/cpukit/include/rtems/score/schedulerstrongapa.h +++ b/cpukit/include/rtems/score/schedulerstrongapa.h @@ -169,7 +169,6 @@ typedef struct { _Scheduler_default_Node_destroy, \ _Scheduler_default_Release_job, \ _Scheduler_default_Cancel_job, \ - _Scheduler_default_Tick, \ _Scheduler_strong_APA_Start_idle, \ _Scheduler_strong_APA_Set_affinity \ } diff --git a/cpukit/include/rtems/score/thread.h b/cpukit/include/rtems/score/thread.h index aff2f58d77..4c8a97c0f7 100644 --- a/cpukit/include/rtems/score/thread.h +++ b/cpukit/include/rtems/score/thread.h @@ -76,14 +76,6 @@ extern "C" { *@{ */ -#define RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE - -/* - * With the addition of the Constant Block Scheduler (CBS), - * this feature is needed even when POSIX is disabled. - */ -#define RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT - #if defined(RTEMS_DEBUG) #define RTEMS_SCORE_THREAD_ENABLE_RESOURCE_COUNT #endif @@ -148,27 +140,47 @@ typedef struct { } Thread_Entry_information; /** - * The following lists the algorithms used to manage the thread cpu budget. - * - * Reset Timeslice: At each context switch, reset the time quantum. - * Exhaust Timeslice: Only reset the quantum once it is consumed. - * Callout: Execute routine when budget is consumed. + * @brief This structure contains operations which manage the CPU budget of a + * thread. */ -typedef enum { - THREAD_CPU_BUDGET_ALGORITHM_NONE, - THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE, - #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE) - THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE, - #endif - #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT) - THREAD_CPU_BUDGET_ALGORITHM_CALLOUT - #endif -} Thread_CPU_budget_algorithms; +typedef struct { + /** + * @brief This operation is called at each clock tick for the executing + * thread. + */ + void ( *at_tick )( Thread_Control * ); -/** This defines thes the entry point for the thread specific timeslice - * budget management algorithm. + /** + * @brief This operation is called right before a context switch to the + * thread is performed. + */ + void ( *at_context_switch )( Thread_Control * ); + + /** + * @brief This operation is called to initialize the CPU budget of the + * thread. + */ + void ( *initialize )( Thread_Control * ); +} Thread_CPU_budget_operations; + +/** + * @brief This structure is used to control the CPU budget of a thread. */ -typedef void (*Thread_CPU_budget_algorithm_callout )( Thread_Control * ); +typedef struct { + /** + * @brief If this member is not NULL, then it references the CPU budget + * operations used to manage the CPU budget of the thread, otherwise it is + * NULL. + */ + const Thread_CPU_budget_operations *operations; + + /** + * @brief This member contains the count of the time quantum that this thread + * is allowed to consume until an action takes place defined by the CPU + * budget operations. + */ + uint32_t available; +} Thread_CPU_budget_control; /** * The following structure contains the information which defines @@ -182,12 +194,13 @@ typedef struct { * it started. */ bool is_preemptible; - /** This field indicates the CPU budget algorith. */ - Thread_CPU_budget_algorithms budget_algorithm; - /** This field is the routine to invoke when the CPU allotment is - * consumed. + + /** + * @brief This member may provide the CPU budget operations activated when a + * thread is initialized before it is started or restarted. */ - Thread_CPU_budget_algorithm_callout budget_callout; + const Thread_CPU_budget_operations *cpu_budget_operations; + /** This field is the initial ISR disable level of this thread. */ uint32_t isr_level; /** This field is the initial priority. */ @@ -772,9 +785,7 @@ struct _Thread_Control { * the following fields * * - RTEMS_API_Control::Signal, - * - Thread_Control::budget_algorithm, - * - Thread_Control::budget_callout, - * - Thread_Control::cpu_time_budget, + * - Thread_Control::CPU_budget, * - Thread_Control::current_state, * - Thread_Control::Post_switch_actions, * - Thread_Control::Scheduler::control, and @@ -841,18 +852,11 @@ struct _Thread_Control { */ bool was_created_with_inherited_scheduler; - /** This field is the length of the time quantum that this thread is - * allowed to consume. The algorithm used to manage limits on CPU usage - * is specified by budget_algorithm. - */ - uint32_t cpu_time_budget; - /** This field is the algorithm used to manage this thread's time - * quantum. The algorithm may be specified as none which case, - * no limit is in place. + /** + * @brief This member contains the CPU budget control used to manage the CPU + * budget of the thread. */ - Thread_CPU_budget_algorithms budget_algorithm; - /** This field is the method invoked with the budgeted time is consumed. */ - Thread_CPU_budget_algorithm_callout budget_callout; + Thread_CPU_budget_control CPU_budget; /** * @brief This member contains the amount of CPU time consumed by this thread diff --git a/cpukit/include/rtems/score/threadcpubudget.h b/cpukit/include/rtems/score/threadcpubudget.h new file mode 100644 index 0000000000..bcbaa11bdb --- /dev/null +++ b/cpukit/include/rtems/score/threadcpubudget.h @@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSScoreThread + * + * @brief This header file provides interfaces used to implement the CPU budget + * management of threads. + */ + +/* + * Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de) + * + * 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_THREADCPUBUDGET_H +#define _RTEMS_SCORE_THREADCPUBUDGET_H + +#include <rtems/score/thread.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup RTEMSScoreThread + * + * @{ + */ + +/** + * @brief Does nothing. + * + * @param the_thread is an unused parameter. + */ +void _Thread_CPU_budget_do_nothing( Thread_Control *the_thread ); + +/** + * @brief Sets the available CPU budget of the thread to the configured clock + * ticks per timeslice. + * + * @param the_thread is the thread to set the available CPU budget. + */ +void _Thread_CPU_budget_set_to_ticks_per_timeslice( + Thread_Control *the_thread +); + +/** + * @brief Consumes one time quantum of the available CPU budget of the thread + * and yields the thread if the available CPU budget is fully consumed. + * + * While the thread enabled the non-preemptive mode or is not ready, no time + * quantum is consumed. + * + * @param the_thread is the thread to operate on. + */ +void _Thread_CPU_budget_consume_and_yield( Thread_Control *the_thread ); + +/** + * @brief These CPU budget operations allocate timeslices to the thread. + * + * The timeslice is not reset at a context switch to the thread. Once a + * timeslice is consumed, the thread yields. + */ +extern const Thread_CPU_budget_operations _Thread_CPU_budget_exhaust_timeslice; + +/** + * @brief These CPU budget operations allocate timeslices to the thread. + * + * The timeslice is reset at a context switch to the thread. Once a timeslice + * is consumed, the thread yields. + */ +extern const Thread_CPU_budget_operations _Thread_CPU_budget_reset_timeslice; + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* _RTEMS_SCORE_THREADCPUBUDGET_H */ diff --git a/cpukit/include/rtems/score/threadimpl.h b/cpukit/include/rtems/score/threadimpl.h index a983975568..b1ec05f1c4 100644 --- a/cpukit/include/rtems/score/threadimpl.h +++ b/cpukit/include/rtems/score/threadimpl.h @@ -176,19 +176,9 @@ typedef struct { Priority_Control priority; /** - * @brief The thread's budget algorithm. + * @brief The thread's initial CPU budget operations. */ - Thread_CPU_budget_algorithms budget_algorithm; - - /** - * @brief The thread's initial budget callout. - */ - Thread_CPU_budget_algorithm_callout budget_callout; - - /** - * @brief The thread's initial CPU time budget. - */ - uint32_t cpu_time_budget; + const Thread_CPU_budget_operations *cpu_budget_operations; /** * @brief 32-bit unsigned integer name of the object for the thread. |