Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:13

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSScoreSchedulerPriorityAffinitySMP
0007  *
0008  * @brief This header file provides the interfaces of the
0009  *   @ref RTEMSScoreSchedulerPriorityAffinitySMP.
0010  */
0011 
0012 /*
0013  *  COPYRIGHT (c) 2014.
0014  *  On-Line Applications Research Corporation (OAR).
0015  *
0016  * Redistribution and use in source and binary forms, with or without
0017  * modification, are permitted provided that the following conditions
0018  * are met:
0019  * 1. Redistributions of source code must retain the above copyright
0020  *    notice, this list of conditions and the following disclaimer.
0021  * 2. Redistributions in binary form must reproduce the above copyright
0022  *    notice, this list of conditions and the following disclaimer in the
0023  *    documentation and/or other materials provided with the distribution.
0024  *
0025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0026  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0028  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0029  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0030  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0031  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0032  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0033  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0034  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0035  * POSSIBILITY OF SUCH DAMAGE.
0036  */
0037 
0038 #ifndef _RTEMS_SCORE_SCHEDULERPRIORITYAFFINITYSMP_H
0039 #define _RTEMS_SCORE_SCHEDULERPRIORITYAFFINITYSMP_H
0040 
0041 #include <rtems/score/scheduler.h>
0042 #include <rtems/score/schedulerpriority.h>
0043 #include <rtems/score/schedulersmp.h>
0044 #include <rtems/score/schedulerprioritysmp.h>
0045 
0046 #include <sys/cpuset.h>
0047 
0048 #ifdef __cplusplus
0049 extern "C" {
0050 #endif /* __cplusplus */
0051 
0052 /**
0053  * @defgroup RTEMSScoreSchedulerPriorityAffinitySMP Deterministic Priority Affinity SMP Scheduler
0054  *
0055  * @ingroup RTEMSScoreSchedulerPrioritySMP
0056  *
0057  * @brief This group contains the Deterministic Priority Affinity SMP Scheduler
0058  *   implementation.
0059  *
0060  * This is an extension of the Deterministic Priority SMP Scheduler. which
0061  * is an implementation of the global fixed priority scheduler (G-FP). 
0062  * It adds thread to core affinity support.
0063  *
0064  * @note This is the first iteration of this scheduler. It currently tracks
0065  *       the requested affinity to exercise the Scheduler Framework but it
0066  *       does not honor that affinity in assigning threads to cores. This
0067  *       will be added in a subsequent revision.
0068  * @{
0069  */
0070 
0071 /**
0072  * @brief Entry points for the Deterministic Priority Affinity SMP Scheduler.
0073  */
0074 #define SCHEDULER_PRIORITY_AFFINITY_SMP_ENTRY_POINTS \
0075   { \
0076     _Scheduler_priority_SMP_Initialize, \
0077     _Scheduler_default_Schedule, \
0078     _Scheduler_priority_affinity_SMP_Yield, \
0079     _Scheduler_priority_affinity_SMP_Block, \
0080     _Scheduler_priority_affinity_SMP_Unblock, \
0081     _Scheduler_priority_affinity_SMP_Update_priority, \
0082     _Scheduler_default_Map_priority, \
0083     _Scheduler_default_Unmap_priority, \
0084     _Scheduler_priority_affinity_SMP_Ask_for_help, \
0085     _Scheduler_priority_affinity_SMP_Reconsider_help_request, \
0086     _Scheduler_priority_affinity_SMP_Withdraw_node, \
0087     _Scheduler_priority_affinity_SMP_Make_sticky, \
0088     _Scheduler_priority_affinity_SMP_Clean_sticky, \
0089     _Scheduler_default_Pin_or_unpin_not_supported, \
0090     _Scheduler_default_Pin_or_unpin_not_supported, \
0091     _Scheduler_priority_affinity_SMP_Add_processor, \
0092     _Scheduler_priority_affinity_SMP_Remove_processor, \
0093     _Scheduler_priority_affinity_SMP_Node_initialize, \
0094     _Scheduler_default_Node_destroy, \
0095     _Scheduler_default_Release_job, \
0096     _Scheduler_default_Cancel_job, \
0097     _Scheduler_SMP_Start_idle, \
0098     _Scheduler_priority_affinity_SMP_Set_affinity \
0099   }
0100 
0101 /**
0102  * @brief Initializes per thread scheduler information.
0103  *
0104  * This routine allocates @a thread->scheduler.
0105  *
0106  * @param scheduler Points to the scheduler specific information.
0107  * @param[in, out] node The node the scheduler is allocating
0108  *            management memory for.
0109  * @param the_thread The thread of the node.
0110  * @param priority The thread priority.
0111  */
0112 void _Scheduler_priority_affinity_SMP_Node_initialize(
0113   const Scheduler_Control *scheduler,
0114   Scheduler_Node          *node,
0115   Thread_Control          *the_thread,
0116   Priority_Control         priority
0117 );
0118 
0119 /**
0120  * @brief Blocks a thread.
0121  *
0122  * @param scheduler The scheduler instance.
0123  * @param[in, out] The thread to block.
0124  * @param[in, out] node The scheduler node of the thread.
0125  */
0126 void _Scheduler_priority_affinity_SMP_Block(
0127   const Scheduler_Control *scheduler,
0128   Thread_Control          *thread,
0129   Scheduler_Node          *node
0130 );
0131 
0132 void _Scheduler_priority_affinity_SMP_Yield(
0133   const Scheduler_Control *scheduler,
0134   Thread_Control          *thread,
0135   Scheduler_Node          *node
0136 );
0137 
0138 /**
0139  * @brief Unblocks a thread.
0140  *
0141  * @param scheduler The scheduler instance.
0142  * @param[in, out] The thread to unblock.
0143  * @param[in, out] node The scheduler node of the thread.
0144  */
0145 void _Scheduler_priority_affinity_SMP_Unblock(
0146   const Scheduler_Control *scheduler,
0147   Thread_Control          *thread,
0148   Scheduler_Node          *node
0149 );
0150 
0151 /**
0152  * @brief Updates the priority of the node.
0153  *
0154  * @param scheduler The scheduler instance.
0155  * @param the_thread The thread of the node.
0156  * @param[in, out] The node to update the priority of.
0157  */
0158 void _Scheduler_priority_affinity_SMP_Update_priority(
0159   const Scheduler_Control *scheduler,
0160   Thread_Control          *the_thread,
0161   Scheduler_Node          *node
0162 );
0163 
0164 /**
0165  * @brief Asks for help.
0166  *
0167  * @param scheduler The scheduler instance to ask for help.
0168  * @param the_thread The thread needing help.
0169  * @param node The scheduler node.
0170  *
0171  * @retval true Ask for help was successful.
0172  * @retval false Ask for help was not successful.
0173  */
0174 bool _Scheduler_priority_affinity_SMP_Ask_for_help(
0175   const Scheduler_Control *scheduler,
0176   Thread_Control          *the_thread,
0177   Scheduler_Node          *node
0178 );
0179 
0180 /**
0181  * @brief Reconsiders help.
0182  *
0183  * @param scheduler The scheduler instance to reconsider the help
0184  *   request.
0185  * @param the_thread The thread reconsidering a help request.
0186  * @param node The scheduler node.
0187  */
0188 void _Scheduler_priority_affinity_SMP_Reconsider_help_request(
0189   const Scheduler_Control *scheduler,
0190   Thread_Control          *the_thread,
0191   Scheduler_Node          *node
0192 );
0193 
0194 /**
0195  * @brief Withdraws node.
0196  *
0197  * @param scheduler The scheduler instance to withdraw the node.
0198  * @param the_thread The thread using the node.
0199  * @param node The scheduler node to withdraw.
0200  * @param next_state The next thread scheduler state in the case the node is
0201  *   scheduled.
0202  */
0203 void _Scheduler_priority_affinity_SMP_Withdraw_node(
0204   const Scheduler_Control *scheduler,
0205   Thread_Control          *the_thread,
0206   Scheduler_Node          *node,
0207   Thread_Scheduler_state   next_state
0208 );
0209 
0210 /**
0211  * @brief Makes the node sticky.
0212  *
0213  * @param scheduler is the scheduler of the node.
0214  *
0215  * @param[in, out] the_thread is the thread owning the node.
0216  *
0217  * @param[in, out] node is the scheduler node to make sticky.
0218  */
0219 void _Scheduler_priority_affinity_SMP_Make_sticky(
0220   const Scheduler_Control *scheduler,
0221   Thread_Control          *the_thread,
0222   Scheduler_Node          *node
0223 );
0224 
0225 /**
0226  * @brief Cleans the sticky property from the node.
0227  *
0228  * @param scheduler is the scheduler of the node.
0229  *
0230  * @param[in, out] the_thread is the thread owning the node.
0231  *
0232  * @param[in, out] node is the scheduler node to clean the sticky property.
0233  */
0234 void _Scheduler_priority_affinity_SMP_Clean_sticky(
0235   const Scheduler_Control *scheduler,
0236   Thread_Control          *the_thread,
0237   Scheduler_Node          *node
0238 );
0239 
0240 /**
0241  * @brief Adds @a idle to @a scheduler.
0242  *
0243  * @param[in, out] scheduler The scheduler instance to add the processor to.
0244  * @param idle The idle thread control.
0245  */
0246 void _Scheduler_priority_affinity_SMP_Add_processor(
0247   const Scheduler_Control *scheduler,
0248   Thread_Control          *idle
0249 );
0250 
0251 /**
0252  * @brief Removes an idle thread from the given cpu.
0253  *
0254  * @param scheduler The scheduler instance.
0255  * @param cpu The cpu control to remove from @a scheduler.
0256  *
0257  * @return The idle thread of the processor.
0258  */
0259 Thread_Control *_Scheduler_priority_affinity_SMP_Remove_processor(
0260   const Scheduler_Control *scheduler,
0261   struct Per_CPU_Control  *cpu
0262 );
0263 
0264 /** 
0265  * @brief Sets affinity for the priority affinity SMP scheduler.
0266  *
0267  * @param scheduler The scheduler of the thread.
0268  * @param[in, out] thread The associated thread.
0269  * @param[in, out] node The scheduler node.
0270  * @param affinity The new affinity set.
0271  *
0272  * @retval STATUS_SUCCESSFUL if successful
0273  * @retval STATUS_INVALID_NUMBER if unsuccessful
0274  */
0275 Status_Control _Scheduler_priority_affinity_SMP_Set_affinity(
0276   const Scheduler_Control *scheduler,
0277   Thread_Control          *thread,
0278   Scheduler_Node          *node,
0279   const Processor_mask    *affinity
0280 );
0281 
0282 /**
0283  * @brief Scheduler node specialization for Deterministic Priority Affinity SMP
0284  * schedulers.
0285  *
0286  * This is a per thread structure.
0287  */
0288 typedef struct {
0289   /**
0290    * @brief SMP priority scheduler node.
0291    */
0292   Scheduler_priority_SMP_Node Base;
0293 
0294   /**
0295    * @brief The thread processor affinity set.
0296    */
0297   Processor_mask Affinity;
0298 } Scheduler_priority_affinity_SMP_Node;
0299 
0300 /** @} */
0301 
0302 #ifdef __cplusplus
0303 }
0304 #endif /* __cplusplus */
0305 
0306 #endif /* _RTEMS_SCORE_SCHEDULERPRIORITYAFFINITYSMP_H */