![]() |
|
|||
File indexing completed on 2025-05-11 08:24:13
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /** 0004 * @file 0005 * 0006 * @ingroup RTEMSScoreSchedulerCBS 0007 * 0008 * @brief This header file provides interfaces of the 0009 * @ref RTEMSScoreSchedulerCBS which are used by the implementation and the 0010 * @ref RTEMSImplApplConfig. 0011 */ 0012 0013 /* 0014 * Copryight (c) 2011 Petr Benes. 0015 * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). 0016 * 0017 * Redistribution and use in source and binary forms, with or without 0018 * modification, are permitted provided that the following conditions 0019 * are met: 0020 * 1. Redistributions of source code must retain the above copyright 0021 * notice, this list of conditions and the following disclaimer. 0022 * 2. Redistributions in binary form must reproduce the above copyright 0023 * notice, this list of conditions and the following disclaimer in the 0024 * documentation and/or other materials provided with the distribution. 0025 * 0026 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0027 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0028 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0029 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0030 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0031 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0032 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0033 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0034 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0035 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0036 * POSSIBILITY OF SUCH DAMAGE. 0037 */ 0038 0039 #ifndef _RTEMS_SCORE_SCHEDULERCBS_H 0040 #define _RTEMS_SCORE_SCHEDULERCBS_H 0041 0042 #include <rtems/score/chain.h> 0043 #include <rtems/score/priority.h> 0044 #include <rtems/score/scheduler.h> 0045 #include <rtems/score/rbtree.h> 0046 #include <rtems/score/scheduleredf.h> 0047 #include <rtems/rtems/signal.h> 0048 #include <rtems/rtems/timer.h> 0049 #include <rtems/score/thread.h> 0050 0051 #ifdef __cplusplus 0052 extern "C" { 0053 #endif 0054 0055 /** 0056 * @defgroup RTEMSScoreSchedulerCBS Constant Bandwidth Server (CBS) Scheduler 0057 * 0058 * @ingroup RTEMSScoreScheduler 0059 * 0060 * @brief This group contains the Constant Bandwidth Server (CBS) Scheduler 0061 * implementation. 0062 * 0063 * @{ 0064 */ 0065 0066 #define SCHEDULER_CBS_MAXIMUM_PRIORITY SCHEDULER_EDF_MAXIMUM_PRIORITY 0067 0068 /** 0069 * Entry points for the Constant Bandwidth Server Scheduler. 0070 * 0071 * @note: The CBS scheduler is an enhancement of EDF scheduler, 0072 * therefor some routines are similar. 0073 */ 0074 #define SCHEDULER_CBS_ENTRY_POINTS \ 0075 { \ 0076 _Scheduler_EDF_Initialize, /* initialize entry point */ \ 0077 _Scheduler_EDF_Schedule, /* schedule entry point */ \ 0078 _Scheduler_EDF_Yield, /* yield entry point */ \ 0079 _Scheduler_EDF_Block, /* block entry point */ \ 0080 _Scheduler_CBS_Unblock, /* unblock entry point */ \ 0081 _Scheduler_EDF_Update_priority, /* update priority entry point */ \ 0082 _Scheduler_EDF_Map_priority, /* map priority entry point */ \ 0083 _Scheduler_EDF_Unmap_priority, /* unmap priority entry point */ \ 0084 SCHEDULER_DEFAULT_SMP_OPERATIONS \ 0085 _Scheduler_CBS_Node_initialize, /* node initialize entry point */ \ 0086 _Scheduler_default_Node_destroy, /* node destroy entry point */ \ 0087 _Scheduler_CBS_Release_job, /* new period of task */ \ 0088 _Scheduler_CBS_Cancel_job, /* cancel period of task */ \ 0089 _Scheduler_default_Start_idle /* start idle entry point */ \ 0090 SCHEDULER_DEFAULT_SET_AFFINITY_OPERATION \ 0091 } 0092 0093 /* Return values for CBS server. */ 0094 #define SCHEDULER_CBS_OK 0 0095 #define SCHEDULER_CBS_ERROR_GENERIC -16 0096 #define SCHEDULER_CBS_ERROR_NO_MEMORY -17 0097 #define SCHEDULER_CBS_ERROR_INVALID_PARAMETER -18 0098 #define SCHEDULER_CBS_ERROR_UNAUTHORIZED -19 0099 #define SCHEDULER_CBS_ERROR_UNIMPLEMENTED -20 0100 #define SCHEDULER_CBS_ERROR_MISSING_COMPONENT -21 0101 #define SCHEDULER_CBS_ERROR_INCONSISTENT_STATE -22 0102 #define SCHEDULER_CBS_ERROR_SYSTEM_OVERLOAD -23 0103 #define SCHEDULER_CBS_ERROR_INTERNAL_ERROR -24 0104 #define SCHEDULER_CBS_ERROR_NOT_FOUND -25 0105 #define SCHEDULER_CBS_ERROR_FULL -26 0106 #define SCHEDULER_CBS_ERROR_EMPTY -27 0107 #define SCHEDULER_CBS_ERROR_NOSERVER SCHEDULER_CBS_ERROR_NOT_FOUND 0108 0109 /** Maximum number of simultaneous servers. */ 0110 extern const uint32_t _Scheduler_CBS_Maximum_servers; 0111 0112 /** Server id. */ 0113 typedef uint32_t Scheduler_CBS_Server_id; 0114 0115 /** Callback function invoked when a budget overrun of a task occurs. */ 0116 typedef void (*Scheduler_CBS_Budget_overrun)( 0117 Scheduler_CBS_Server_id server_id 0118 ); 0119 0120 /** 0121 * This structure handles server parameters. 0122 */ 0123 typedef struct { 0124 /** Relative deadline of the server. */ 0125 time_t deadline; 0126 /** Budget (computation time) of the server. */ 0127 time_t budget; 0128 } Scheduler_CBS_Parameters; 0129 0130 /** 0131 * This structure represents a time server. 0132 */ 0133 typedef struct { 0134 /** 0135 * Task id. 0136 * 0137 * @note: The current implementation of CBS handles only one task per server. 0138 */ 0139 rtems_id task_id; 0140 /** Server paramenters. */ 0141 Scheduler_CBS_Parameters parameters; 0142 /** Callback function invoked when a budget overrun occurs. */ 0143 Scheduler_CBS_Budget_overrun cbs_budget_overrun; 0144 0145 /** 0146 * @brief Indicates if this CBS server is initialized. 0147 * 0148 * @see _Scheduler_CBS_Create_server() and _Scheduler_CBS_Destroy_server(). 0149 */ 0150 bool initialized; 0151 } Scheduler_CBS_Server; 0152 0153 /** 0154 * This structure handles CBS specific data of a thread. 0155 */ 0156 typedef struct { 0157 /** EDF scheduler specific data of a task. */ 0158 Scheduler_EDF_Node Base; 0159 /** CBS server specific data of a task. */ 0160 Scheduler_CBS_Server *cbs_server; 0161 0162 Priority_Node *deadline_node; 0163 } Scheduler_CBS_Node; 0164 0165 0166 /** 0167 * List of servers. The @a Scheduler_CBS_Server is the index to the array 0168 * of pointers to @a _Scheduler_CBS_Server_list. 0169 */ 0170 extern Scheduler_CBS_Server _Scheduler_CBS_Server_list[]; 0171 0172 /** 0173 * @brief Unblocks a thread. 0174 * 0175 * @param scheduler The scheduler control. 0176 * @param the_thread The thread to unblock. 0177 * @param node The scheduler node. 0178 */ 0179 void _Scheduler_CBS_Unblock( 0180 const Scheduler_Control *scheduler, 0181 Thread_Control *the_thread, 0182 Scheduler_Node *node 0183 ); 0184 0185 /** 0186 * @brief Releases a job. 0187 * 0188 * @param scheduler The scheduler for the operation. 0189 * @param the_thread The corresponding thread. 0190 * @param priority_node The priority node for the operation. 0191 * @param deadline The deadline for the job. 0192 * @param queue_context The thread queue context. 0193 */ 0194 void _Scheduler_CBS_Release_job( 0195 const Scheduler_Control *scheduler, 0196 Thread_Control *the_thread, 0197 Priority_Node *priority_node, 0198 uint64_t deadline, 0199 Thread_queue_Context *queue_context 0200 ); 0201 0202 /** 0203 * @brief Cancels a job. 0204 * 0205 * @param scheduler The scheduler for the operation. 0206 * @param the_thread The corresponding thread. 0207 * @param priority_node The priority node for the operation. 0208 * @param queue_context The thread queue context. 0209 */ 0210 void _Scheduler_CBS_Cancel_job( 0211 const Scheduler_Control *scheduler, 0212 Thread_Control *the_thread, 0213 Priority_Node *priority_node, 0214 Thread_queue_Context *queue_context 0215 ); 0216 0217 /** 0218 * @brief _Scheduler_CBS_Initialize 0219 * 0220 * Initializes the CBS library. 0221 * 0222 * @return SCHEDULER_CBS_OK This method always returns this status. 0223 */ 0224 int _Scheduler_CBS_Initialize(void); 0225 0226 /** 0227 * @brief Attaches a task to an already existing server. 0228 * 0229 * Attach a task to an already existing server. 0230 * 0231 * @param server_id The id of the existing server. 0232 * @param task_id The id of the task to attach. 0233 * 0234 * @retval SCHEDULER_CBS_OK The operation was successful. 0235 * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is so big 0236 * or there is no thread for this task id. 0237 * @retval SCHEDULER_CBS_ERROR_NOSERVER The server is not yet initialized. 0238 * @retval SCHEDULER_CBS_ERROR_FULL The server already has a task. 0239 */ 0240 int _Scheduler_CBS_Attach_thread ( 0241 Scheduler_CBS_Server_id server_id, 0242 rtems_id task_id 0243 ); 0244 0245 /** 0246 * @brief Detaches from the CBS Server. 0247 * 0248 * Detach from the CBS Server. 0249 * 0250 * @param server_id The id of the existing server. 0251 * @param task_id The id of the task to attach. 0252 * 0253 * @retval SCHEDULER_CBS_OK The operation was successful. 0254 * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is to big, 0255 * or the task with this id is not attached to this server or there is 0256 * no thread with this task. 0257 * @retval SCHEDULER_CBS_ERROR_NOSERVER The server is not yet initialized. 0258 */ 0259 int _Scheduler_CBS_Detach_thread ( 0260 Scheduler_CBS_Server_id server_id, 0261 rtems_id task_id 0262 ); 0263 0264 /** 0265 * @brief Cleans up resources associated to the CBS Library. 0266 * 0267 * Cleanup resources associated to the CBS Library. 0268 * 0269 * @return This method always returns SCHEDULER_CBS_OK. 0270 */ 0271 int _Scheduler_CBS_Cleanup (void); 0272 0273 /** 0274 * @brief Creates a new server with specified parameters. 0275 * 0276 * Create a new server with specified parameters. 0277 * 0278 * @param params The parameters for the server. 0279 * @param budget_overrun_callback The budget overrun for the new server. 0280 * @param[out] server_id In the case of success, this parameter contains the 0281 * id of the newly created server. 0282 * 0283 * @retval SCHEDULER_CBS_OK The operation succeeded. 0284 * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The given parameters are invalid. 0285 * @retval SCHEDULER_CBS_ERROR_FULL The maximum number of servers was already 0286 * created, a new server cannot be created. 0287 */ 0288 int _Scheduler_CBS_Create_server ( 0289 Scheduler_CBS_Parameters *params, 0290 Scheduler_CBS_Budget_overrun budget_overrun_callback, 0291 rtems_id *server_id 0292 ); 0293 0294 /** 0295 * @brief Detaches all tasks from a server and destroys it. 0296 * 0297 * Detach all tasks from a server and destroy it. 0298 * 0299 * @param server_id The id of the server to destroy. 0300 * 0301 * @retval SCHEDULER_CBS_OK The operation was successful. 0302 * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is too big. 0303 * @retval SCHEDULER_CBS_ERROR_NOSERVER There is no initialized server with this id. 0304 */ 0305 int _Scheduler_CBS_Destroy_server ( 0306 Scheduler_CBS_Server_id server_id 0307 ); 0308 0309 /** 0310 * @brief Retrieves the approved budget. 0311 * 0312 * Retrieve the budget that has been approved for the subsequent 0313 * server instances. 0314 * 0315 * @param server_id The id of the server instance of which the budget is wanted. 0316 * @param[out] approved_budget Contains the approved budget after a successful method call. 0317 * 0318 * @retval SCHEDULER_CBS_OK The operation was successful. 0319 * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is too big. 0320 * @retval SCHEDULER_CBS_ERROR_NOSERVER There is no initialized server with this id. 0321 */ 0322 int _Scheduler_CBS_Get_approved_budget ( 0323 Scheduler_CBS_Server_id server_id, 0324 time_t *approved_budget 0325 ); 0326 0327 /** 0328 * @brief Retrieves remaining budget for the current server instance. 0329 * 0330 * Retrieve remaining budget for the current server instance. 0331 * 0332 * @param server_id The id of the server instance of which the remaining budget is wanted. 0333 * @param[out] remaining_budget Contains the remaining budget after a successful method call. 0334 * 0335 * @retval SCHEDULER_CBS_OK The operation was successful. 0336 * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is too big. 0337 * @retval SCHEDULER_CBS_ERROR_NOSERVER There is no initialized server with this id. 0338 */ 0339 int _Scheduler_CBS_Get_remaining_budget ( 0340 Scheduler_CBS_Server_id server_id, 0341 time_t *remaining_budget 0342 ); 0343 0344 /** 0345 * @brief Gets relative time info. 0346 * 0347 * Retrieve time info relative to @a server_id. The server status code is returned. 0348 * 0349 * @param server_id is the server to get the status code from. 0350 * @param[out] exec_time Contains the execution time after a successful method call. 0351 * @param abs_time Not apparently used. 0352 * 0353 * @retval SCHEDULER_CBS_OK The operation was successful. 0354 * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is too big. 0355 * @retval SCHEDULER_CBS_ERROR_NOSERVER There is no initialized server with this id. 0356 */ 0357 int _Scheduler_CBS_Get_execution_time ( 0358 Scheduler_CBS_Server_id server_id, 0359 time_t *exec_time, 0360 time_t *abs_time 0361 ); 0362 0363 /** 0364 * @brief Retrieves CBS scheduling parameters. 0365 * 0366 * Retrieve CBS scheduling parameters. 0367 * 0368 * @param server_id The id of the server to get the scheduling parameters from. 0369 * @param[out] params Will contain the scheduling parameters after successful method call. 0370 * 0371 * @retval SCHEDULER_CBS_OK The operation was successful. 0372 * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is too big. 0373 * @retval SCHEDULER_CBS_ERROR_NOSERVER There is no initialized server with this id. 0374 */ 0375 int _Scheduler_CBS_Get_parameters ( 0376 Scheduler_CBS_Server_id server_id, 0377 Scheduler_CBS_Parameters *params 0378 ); 0379 0380 /** 0381 * @brief Gets a thread server id. 0382 * 0383 * Get a thread server id, or SCHEDULER_CBS_ERROR_NOT_FOUND if it is not 0384 * attached to any server. 0385 * 0386 * @param task_id The id of the task to get the corresponding server. 0387 * @param[out] server_id Will contain the server id after successful method call. 0388 * @retval SCHEDULER_CBS_OK The operation was successful 0389 * @retval SCHEDULER_CBS_ERROR_NOSERVER There is no server with this task attached. 0390 */ 0391 int _Scheduler_CBS_Get_server_id ( 0392 rtems_id task_id, 0393 Scheduler_CBS_Server_id *server_id 0394 ); 0395 0396 /** 0397 * @brief Sets parameters for CBS scheduling. 0398 * 0399 * Change CBS scheduling parameters. 0400 * 0401 * @param server_id The id of the server. 0402 * @param parameters The parameters to set. 0403 * 0404 * @retval SCHEDULER_CBS_OK The operation was successful. 0405 * @retval SCHEDULER_CBS_ERROR_INVALID_PARAMETER The server id is too big or the 0406 * given parameters are invalid. 0407 * @retval SCHEDULER_CBS_ERROR_NOSERVER There is no server with this id. 0408 */ 0409 int _Scheduler_CBS_Set_parameters ( 0410 Scheduler_CBS_Server_id server_id, 0411 Scheduler_CBS_Parameters *parameters 0412 ); 0413 0414 /** 0415 * @brief These are the CBS CPU budget operations. 0416 */ 0417 extern const Thread_CPU_budget_operations _Scheduler_CBS_Budget; 0418 0419 /** 0420 * @brief Initializes a CBS specific scheduler node of @a the_thread. 0421 * 0422 * @param scheduler The scheduler control for the operation. 0423 * @param[out] node The scheduler node to initalize. 0424 * @param the_thread The thread to initialize a scheduler node for. 0425 * @param priority The priority for the node. 0426 */ 0427 void _Scheduler_CBS_Node_initialize( 0428 const Scheduler_Control *scheduler, 0429 Scheduler_Node *node, 0430 Thread_Control *the_thread, 0431 Priority_Control priority 0432 ); 0433 0434 #ifdef __cplusplus 0435 } 0436 #endif 0437 0438 /** @} */ 0439 0440 #endif 0441 /* end of include file */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |