diff options
Diffstat (limited to 'cpukit/include/rtems/score/percpu.h')
-rw-r--r-- | cpukit/include/rtems/score/percpu.h | 180 |
1 files changed, 130 insertions, 50 deletions
diff --git a/cpukit/include/rtems/score/percpu.h b/cpukit/include/rtems/score/percpu.h index 58a89ec7a9..288445bc6f 100644 --- a/cpukit/include/rtems/score/percpu.h +++ b/cpukit/include/rtems/score/percpu.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + /** * @file * @@ -11,11 +13,28 @@ * COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * - * Copyright (c) 2012, 2018 embedded brains GmbH + * Copyright (C) 2012, 2018 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_PERCPU_H @@ -38,18 +57,31 @@ extern "C" { #endif -#if defined(RTEMS_SMP) - #if defined(RTEMS_PROFILING) - #define PER_CPU_CONTROL_SIZE_APPROX \ - ( 512 + CPU_PER_CPU_CONTROL_SIZE + CPU_INTERRUPT_FRAME_SIZE ) - #elif defined(RTEMS_DEBUG) || CPU_SIZEOF_POINTER > 4 - #define PER_CPU_CONTROL_SIZE_APPROX \ - ( 256 + CPU_PER_CPU_CONTROL_SIZE + CPU_INTERRUPT_FRAME_SIZE ) +#if defined( RTEMS_SMP ) + #if defined( RTEMS_PROFILING ) + #define PER_CPU_CONTROL_SIZE_PROFILING 332 + #else + #define PER_CPU_CONTROL_SIZE_PROFILING 0 + #endif + + #if defined( RTEMS_DEBUG ) + #define PER_CPU_CONTROL_SIZE_DEBUG 76 + #else + #define PER_CPU_CONTROL_SIZE_DEBUG 0 + #endif + + #if CPU_SIZEOF_POINTER > 4 + #define PER_CPU_CONTROL_SIZE_BIG_POINTER 76 #else - #define PER_CPU_CONTROL_SIZE_APPROX \ - ( 180 + CPU_PER_CPU_CONTROL_SIZE + CPU_INTERRUPT_FRAME_SIZE ) + #define PER_CPU_CONTROL_SIZE_BIG_POINTER 0 #endif + #define PER_CPU_CONTROL_SIZE_BASE 180 + #define PER_CPU_CONTROL_SIZE_APPROX \ + ( PER_CPU_CONTROL_SIZE_BASE + CPU_PER_CPU_CONTROL_SIZE + \ + CPU_INTERRUPT_FRAME_SIZE + PER_CPU_CONTROL_SIZE_PROFILING + \ + PER_CPU_CONTROL_SIZE_DEBUG + PER_CPU_CONTROL_SIZE_BIG_POINTER ) + /* * This ensures that on SMP configurations the individual per-CPU controls * are on different cache lines to prevent false sharing. This define can be @@ -102,15 +134,18 @@ struct Scheduler_Context; * The processor state controls the life cycle of processors at the lowest * level. No multi-threading or other high-level concepts matter here. * - * State changes must be initiated via _Per_CPU_State_change(). This function - * may not return in case someone requested a shutdown. The - * _SMP_Send_message() function will be used to notify other processors about - * state changes if the other processor is in the up state. + * The state of a processor is indicated by the Per_CPU_Control::state membe. + * The current state of a processor can be get by _Per_CPU_Get_state(). Only + * the processor associated with the control may change its state using + * _Per_CPU_Set_state(). * * Due to the sequential nature of the basic system initialization one * processor has a special role. It is the processor executing the boot_card() * function. This processor is called the boot processor. All other - * processors are called secondary. + * processors are called secondary. The boot processor uses + * _SMP_Request_start_multitasking() to indicate that processors should start + * multiprocessing. Secondary processors will wait for this request in + * _SMP_Start_multitasking_on_secondary_processor(). * * @dot * digraph states { @@ -150,23 +185,13 @@ typedef enum { * the first time. The boot processor will wait for all secondary processors * to change into this state. In case a secondary processor does not reach * this state the system will not start. The secondary processors wait now - * for a change into the PER_CPU_STATE_REQUEST_START_MULTITASKING state set - * by the boot processor once all secondary processors reached the - * PER_CPU_STATE_READY_TO_START_MULTITASKING state. + * for a change into the PER_CPU_STATE_UP state set requested by the boot + * processor through ::_SMP_Ready_to_start_multitasking once all secondary + * processors reached the PER_CPU_STATE_READY_TO_START_MULTITASKING state. */ PER_CPU_STATE_READY_TO_START_MULTITASKING, /** - * @brief Multitasking start of processor is requested. - * - * The boot processor completed system initialization and is about to perform - * a context switch to its heir thread. Secondary processors should now - * issue a context switch to the heir thread. This normally enables - * interrupts on the processor for the first time. - */ - PER_CPU_STATE_REQUEST_START_MULTITASKING, - - /** * @brief Normal multitasking state. */ PER_CPU_STATE_UP, @@ -237,6 +262,13 @@ typedef struct Per_CPU_Job { /** * @brief Per-CPU statistics. */ + +/* + * This was added to address the following warning: + * warning: struct has no members + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" typedef struct { #if defined( RTEMS_PROFILING ) /** @@ -305,6 +337,7 @@ typedef struct { uint64_t total_interrupt_time; #endif /* defined( RTEMS_PROFILING ) */ } Per_CPU_Stats; +#pragma GCC diagnostic pop /** * @brief Per-CPU watchdog header index. @@ -459,10 +492,12 @@ typedef struct Per_CPU_Control { * @brief Watchdog state for this processor. */ struct { +#if defined(RTEMS_SMP) /** * @brief Protects all watchdog operations on this processor. */ - ISR_LOCK_MEMBER( Lock ) + ISR_lock_Control Lock; +#endif /** * @brief Watchdog ticks on this processor used for monotonic clock @@ -547,13 +582,14 @@ typedef struct Per_CPU_Control { char *data; /** - * @brief Indicates the current state of the CPU. + * @brief Indicates the current state of the processor. * - * This member is protected by the _Per_CPU_State_lock lock. + * Only the processor associated with this control is allowed to change + * this member. * - * @see _Per_CPU_State_change(). + * @see _Per_CPU_Get_state() and _Per_CPU_Set_state(). */ - Per_CPU_State state; + Atomic_Uint state; /** * @brief FIFO list of jobs to be performed by this processor. @@ -683,6 +719,16 @@ static inline struct _Thread_Control *_Per_CPU_Get_executing( return cpu->executing; } +static inline bool _Per_CPU_Is_ISR_in_progress( const Per_CPU_Control *cpu ) +{ +#if CPU_PROVIDES_ISR_IS_IN_PROGRESS == TRUE + (void) cpu; + return _ISR_Is_in_progress(); +#else + return cpu->isr_nest_level != 0; +#endif +} + static inline bool _Per_CPU_Is_processor_online( const Per_CPU_Control *cpu ) @@ -709,7 +755,7 @@ static inline bool _Per_CPU_Is_boot_processor( #endif } -RTEMS_INLINE_ROUTINE void _Per_CPU_Acquire_all( +static inline void _Per_CPU_Acquire_all( ISR_lock_Context *lock_context ) { @@ -736,7 +782,7 @@ RTEMS_INLINE_ROUTINE void _Per_CPU_Acquire_all( #endif } -RTEMS_INLINE_ROUTINE void _Per_CPU_Release_all( +static inline void _Per_CPU_Release_all( ISR_lock_Context *lock_context ) { @@ -766,16 +812,38 @@ RTEMS_INLINE_ROUTINE void _Per_CPU_Release_all( #if defined( RTEMS_SMP ) /** - * @brief Allocate and Initialize Per CPU Structures + * @brief Gets the current processor state. * - * This method allocates and initialize the per CPU structure. + * @param cpu is the processor control. + * + * @return Returns the current state of the processor. */ -void _Per_CPU_Initialize(void); +static inline Per_CPU_State _Per_CPU_Get_state( const Per_CPU_Control *cpu ) +{ + return (Per_CPU_State) + _Atomic_Load_uint( &cpu->state, ATOMIC_ORDER_ACQUIRE ); +} -void _Per_CPU_State_change( - Per_CPU_Control *cpu, - Per_CPU_State new_state -); +/** + * @brief Sets the processor state of the current processor. + * + * @param cpu_self is the processor control of the processor executing this + * function. + * + * @param state is the new processor state. + */ +static inline void _Per_CPU_Set_state( + Per_CPU_Control *cpu_self, + Per_CPU_State state +) +{ + _Assert( cpu_self == _Per_CPU_Get() ); + _Atomic_Store_uint( + &cpu_self->state, + (unsigned int) state, + ATOMIC_ORDER_RELEASE + ); +} /** * @brief Waits for a processor to change into a non-initial state. @@ -815,11 +883,10 @@ bool _Per_CPU_State_wait_for_non_initial_state( void _Per_CPU_Perform_jobs( Per_CPU_Control *cpu ); /** - * @brief Adds the job to the tail of the processing list of the specified - * processor. + * @brief Adds the job to the tail of the processing list of the processor. * - * This function does not send the SMP_MESSAGE_PERFORM_JOBS message the - * specified processor. + * This function does not send the ::SMP_MESSAGE_PERFORM_JOBS message to the + * processor, see also _Per_CPU_Submit_job(). * * @param[in, out] cpu The processor to add the job. * @param[in, out] job The job. The Per_CPU_Job::context member must be @@ -828,6 +895,19 @@ void _Per_CPU_Perform_jobs( Per_CPU_Control *cpu ); void _Per_CPU_Add_job( Per_CPU_Control *cpu, Per_CPU_Job *job ); /** + * @brief Adds the job to the tail of the processing list of the processor and + * notifies the processor to process the job. + * + * This function sends the ::SMP_MESSAGE_PERFORM_JOBS message to the processor + * if it is in the ::PER_CPU_STATE_UP state, see also _Per_CPU_Add_job(). + * + * @param[in, out] cpu The processor to add the job. + * @param[in, out] job The job. The Per_CPU_Job::context member must be + * initialized by the caller. + */ +void _Per_CPU_Submit_job( Per_CPU_Control *cpu, Per_CPU_Job *job ); + +/** * @brief Waits for the job carried out by the specified processor. * * This function may result in an SMP_FATAL_WRONG_CPU_STATE_TO_PERFORM_JOBS @@ -879,7 +959,7 @@ void _Per_CPU_Wait_for_job( * * @return The thread control block of the executing thread. */ -RTEMS_INLINE_ROUTINE struct _Thread_Control *_Thread_Get_executing( void ) +static inline struct _Thread_Control *_Thread_Get_executing( void ) { struct _Thread_Control *executing; |