diff options
Diffstat (limited to 'cpukit/include/rtems/score/thread.h')
-rw-r--r-- | cpukit/include/rtems/score/thread.h | 255 |
1 files changed, 150 insertions, 105 deletions
diff --git a/cpukit/include/rtems/score/thread.h b/cpukit/include/rtems/score/thread.h index aff2f58d77..8ca7d85205 100644 --- a/cpukit/include/rtems/score/thread.h +++ b/cpukit/include/rtems/score/thread.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -12,11 +14,28 @@ * COPYRIGHT (c) 1989-2014. * On-Line Applications Research Corporation (OAR). * - * Copyright (c) 2014, 2016 embedded brains GmbH. + * Copyright (C) 2014, 2016 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. * - * 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. + * 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_THREAD_H @@ -76,14 +95,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 +159,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 * ); + + /** + * @brief This operation is called right before a context switch to the + * thread is performed. + */ + void ( *at_context_switch )( Thread_Control * ); -/** This defines thes the entry point for the thread specific timeslice - * budget management algorithm. + /** + * @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 +213,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. */ @@ -293,10 +325,24 @@ typedef struct { Chain_Control Scheduler_nodes; /** - * @brief Node for the Per_CPU_Control::Threads_in_need_for_help chain. + * @brief If an ask for help request for the thread is pending, then this + * member references the processor on which the ask for help request is + * registered, otherwise it is NULL. * - * This chain is protected by the Per_CPU_Control::Lock lock of the assigned - * processor. + * Depending on the state of the thread and usage context, this member is + * protected by the Per_CPU_Control::Lock lock of the referenced processor, + * the scheduler lock of the thread (Thread_Scheduler_control::Lock), or the + * thread state lock. + */ + struct Per_CPU_Control *ask_for_help_cpu; + + /** + * @brief This member is the node for the + * Per_CPU_Control::Threads_in_need_for_help chain. + * + * This chain is protected by the Per_CPU_Control::Lock lock of the processor + * on which the ask for help request is registered + * (Thread_Scheduler_control::ask_for_help_cpu). */ Chain_Node Help_node; @@ -377,7 +423,7 @@ typedef union { * The mutually exclusive wait state flags are * - @ref THREAD_WAIT_STATE_INTEND_TO_BLOCK, * - @ref THREAD_WAIT_STATE_BLOCKED, and - * - @ref THREAD_WAIT_STATE_READY_AGAIN. + * - @ref THREAD_WAIT_STATE_READY. */ typedef unsigned int Thread_Wait_flags; @@ -646,10 +692,12 @@ typedef struct { */ RBTree_Control Key_value_pairs; +#if defined(RTEMS_SMP) /** * @brief Lock to protect the tree operations. */ - ISR_LOCK_MEMBER( Lock ) + ISR_lock_Control Lock; +#endif } Thread_Keys_information; /** @@ -671,50 +719,50 @@ typedef struct { * The individual state flags must be a power of two to allow use of bit * operations to manipulate and evaluate the thread life state. */ -typedef enum { - /** - * @brief Indicates that the thread life is protected. - * - * If this flag is set, then the thread restart or delete requests are deferred - * until the protection and deferred change flags are cleared. It is used by - * _Thread_Set_life_protection(). - */ - THREAD_LIFE_PROTECTED = 0x1, +typedef unsigned int Thread_Life_state; - /** - * @brief Indicates that thread is restarting. - * - * If this flag is set, then a thread restart request is in pending. See - * _Thread_Restart_self() and _Thread_Restart_other(). - */ - THREAD_LIFE_RESTARTING = 0x2, +/** + * @brief Indicates that the thread life is protected. + * + * If this flag is set, then the thread restart or delete requests are deferred + * until the protection and deferred change flags are cleared. It is used by + * _Thread_Set_life_protection(). + */ +#define THREAD_LIFE_PROTECTED 0x1U - /** - * @brief Indicates that thread is terminating. - * - * If this flag is set, then a thread termination request is in pending. See - * _Thread_Exit() and _Thread_Cancel(). - */ - THREAD_LIFE_TERMINATING = 0x4, +/** + * @brief Indicates that thread is restarting. + * + * If this flag is set, then a thread restart request is in pending. See + * _Thread_Restart_self() and _Thread_Restart_other(). + */ +#define THREAD_LIFE_RESTARTING 0x2U - /** - * @brief Indicates that thread life changes are deferred. - * - * If this flag is set, then the thread restart or delete requests are deferred - * until the protection and deferred change flags are cleared. It is used by - * pthread_setcanceltype(). - */ - THREAD_LIFE_CHANGE_DEFERRED = 0x8, +/** + * @brief Indicates that thread is terminating. + * + * If this flag is set, then a thread termination request is in pending. See + * _Thread_Exit() and _Thread_Cancel(). + */ +#define THREAD_LIFE_TERMINATING 0x4U - /** - * @brief Indicates that thread is detached. - * - * If this flag is set, then the thread is detached. Detached threads do not - * wait during termination for other threads to join. See rtems_task_delete(), - * rtems_task_exit(), and pthread_detach(). - */ - THREAD_LIFE_DETACHED = 0x10 -} Thread_Life_state; +/** + * @brief Indicates that thread life changes are deferred. + * + * If this flag is set, then the thread restart or delete requests are deferred + * until the protection and deferred change flags are cleared. It is used by + * pthread_setcanceltype(). + */ +#define THREAD_LIFE_CHANGE_DEFERRED 0x8U + +/** + * @brief Indicates that thread is detached. + * + * If this flag is set, then the thread is detached. Detached threads do not + * wait during termination for other threads to join. See rtems_task_delete(), + * rtems_task_exit(), and pthread_detach(). + */ +#define THREAD_LIFE_DETACHED 0x10U /** * @brief Thread life control. @@ -772,9 +820,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 @@ -812,6 +858,15 @@ struct _Thread_Control { #endif /*================= end of common block =================*/ + /** + * @brief This member contains the context of this thread. + * + * This member is placed directly after the end of the common block so that + * the structure offsets are as small as possible. This helps on instruction + * set architectures with a very limited range for intermediate values. + */ + Context_Control Registers; + #if defined(RTEMS_SMP) && defined(RTEMS_PROFILING) /** * @brief Potpourri lock statistics. @@ -841,18 +896,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 @@ -874,16 +922,18 @@ struct _Thread_Control { Thread_Action_control Post_switch_actions; - /** This field contains the context of this thread. */ - Context_Control Registers; #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) /** This field points to the floating point context for this thread. * If NULL, the thread is integer only. */ Context_Control_fp *fp_context; #endif + +#ifndef _REENT_THREAD_LOCAL /** This field points to the newlib reentrancy structure for this thread. */ struct _reent *libc_reent; +#endif + /** This array contains the API extension area pointers. */ void *API_Extensions[ THREAD_API_LAST + 1 ]; @@ -1108,9 +1158,11 @@ Objects_Control *_Thread_Allocate_unlimited( Objects_Information *information ); #define THREAD_INFORMATION_DEFINE( name, api, cls, max ) \ static Objects_Control * \ name##_Local_table[ _Objects_Maximum_per_allocation( max ) ]; \ -static Thread_Configured_control \ +static RTEMS_SECTION( ".noinit.rtems.content.objects." #name ) \ +Thread_Configured_control \ name##_Objects[ _Objects_Maximum_per_allocation( max ) ]; \ -static Thread_queue_Configured_heads \ +static RTEMS_SECTION( ".noinit.rtems.content.objects." #name ) \ +Thread_queue_Configured_heads \ name##_Heads[ _Objects_Maximum_per_allocation( max ) ]; \ Thread_Information name##_Information = { \ { \ @@ -1134,13 +1186,6 @@ Thread_Information name##_Information = { \ } \ } -/** - * @brief The idle thread stacks. - * - * Provided by the application via <rtems/confdefs.h>. - */ -extern char _Thread_Idle_stacks[]; - #if defined(RTEMS_MULTIPROCESSING) /** * @brief The configured thread control block. |