[82db8e56] | 1 | /** |
---|
| 2 | * @file rtems/score/schedulercbs.h |
---|
| 3 | * |
---|
[319cb20] | 4 | * @brief Thread manipulation for the CBS scheduler |
---|
| 5 | * |
---|
[82db8e56] | 6 | * This include file contains all the constants and structures associated |
---|
| 7 | * with the manipulation of threads for the CBS scheduler. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | /* |
---|
| 11 | * Copryight (c) 2011 Petr Benes. |
---|
| 12 | * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). |
---|
| 13 | * |
---|
| 14 | * The license and distribution terms for this file may be |
---|
| 15 | * found in the file LICENSE in this distribution or at |
---|
| 16 | * http://www.rtems.com/license/LICENSE. |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #ifndef _RTEMS_SCORE_SCHEDULERCBS_H |
---|
| 20 | #define _RTEMS_SCORE_SCHEDULERCBS_H |
---|
| 21 | |
---|
| 22 | #include <rtems/score/chain.h> |
---|
| 23 | #include <rtems/score/priority.h> |
---|
| 24 | #include <rtems/score/scheduler.h> |
---|
| 25 | #include <rtems/score/rbtree.h> |
---|
| 26 | #include <rtems/score/scheduleredf.h> |
---|
| 27 | #include <rtems/rtems/signal.h> |
---|
| 28 | #include <rtems/rtems/timer.h> |
---|
| 29 | #include <rtems/score/thread.h> |
---|
| 30 | |
---|
| 31 | #ifdef __cplusplus |
---|
| 32 | extern "C" { |
---|
| 33 | #endif |
---|
| 34 | |
---|
| 35 | /** |
---|
[a15eaaf] | 36 | * @defgroup ScoreSchedulerCBS CBS Scheduler |
---|
[82db8e56] | 37 | * |
---|
[a15eaaf] | 38 | * @ingroup ScoreScheduler |
---|
[82db8e56] | 39 | */ |
---|
| 40 | /**@{*/ |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | * Entry points for the Constant Bandwidth Server Scheduler. |
---|
| 44 | * |
---|
| 45 | * @note: The CBS scheduler is an enhancement of EDF scheduler, |
---|
| 46 | * therefor some routines are similar. |
---|
| 47 | */ |
---|
| 48 | #define SCHEDULER_CBS_ENTRY_POINTS \ |
---|
| 49 | { \ |
---|
| 50 | _Scheduler_EDF_Initialize, /* initialize entry point */ \ |
---|
| 51 | _Scheduler_EDF_Schedule, /* schedule entry point */ \ |
---|
| 52 | _Scheduler_EDF_Yield, /* yield entry point */ \ |
---|
| 53 | _Scheduler_EDF_Block, /* block entry point */ \ |
---|
| 54 | _Scheduler_CBS_Unblock, /* unblock entry point */ \ |
---|
[7a9288fe] | 55 | _Scheduler_CBS_Allocate, /* allocate entry point */ \ |
---|
[82db8e56] | 56 | _Scheduler_EDF_Free, /* free entry point */ \ |
---|
| 57 | _Scheduler_EDF_Update, /* update entry point */ \ |
---|
| 58 | _Scheduler_EDF_Enqueue, /* enqueue entry point */ \ |
---|
| 59 | _Scheduler_EDF_Enqueue_first, /* enqueue_first entry point */ \ |
---|
| 60 | _Scheduler_EDF_Extract, /* extract entry point */ \ |
---|
| 61 | _Scheduler_EDF_Priority_compare, /* compares two priorities */ \ |
---|
| 62 | _Scheduler_CBS_Release_job, /* new period of task */ \ |
---|
[1ccb64e1] | 63 | _Scheduler_priority_Tick, /* tick entry point */ \ |
---|
| 64 | _Scheduler_default_Start_idle /* start idle entry point */ \ |
---|
[82db8e56] | 65 | } |
---|
| 66 | |
---|
| 67 | /* Return values for CBS server. */ |
---|
| 68 | #define SCHEDULER_CBS_OK 0 |
---|
| 69 | #define SCHEDULER_CBS_ERROR_GENERIC -16 |
---|
| 70 | #define SCHEDULER_CBS_ERROR_NO_MEMORY -17 |
---|
| 71 | #define SCHEDULER_CBS_ERROR_INVALID_PARAMETER -18 |
---|
| 72 | #define SCHEDULER_CBS_ERROR_UNAUTHORIZED -19 |
---|
| 73 | #define SCHEDULER_CBS_ERROR_UNIMPLEMENTED -20 |
---|
| 74 | #define SCHEDULER_CBS_ERROR_MISSING_COMPONENT -21 |
---|
| 75 | #define SCHEDULER_CBS_ERROR_INCONSISTENT_STATE -22 |
---|
| 76 | #define SCHEDULER_CBS_ERROR_SYSTEM_OVERLOAD -23 |
---|
| 77 | #define SCHEDULER_CBS_ERROR_INTERNAL_ERROR -24 |
---|
| 78 | #define SCHEDULER_CBS_ERROR_NOT_FOUND -25 |
---|
| 79 | #define SCHEDULER_CBS_ERROR_FULL -26 |
---|
| 80 | #define SCHEDULER_CBS_ERROR_EMPTY -27 |
---|
| 81 | #define SCHEDULER_CBS_ERROR_NOSERVER SCHEDULER_CBS_ERROR_NOT_FOUND |
---|
| 82 | |
---|
| 83 | /** Maximum number of simultaneous servers. */ |
---|
| 84 | extern uint32_t _Scheduler_CBS_Maximum_servers; |
---|
| 85 | |
---|
| 86 | /** Server id. */ |
---|
| 87 | typedef uint32_t Scheduler_CBS_Server_id; |
---|
| 88 | |
---|
| 89 | /** Callback function invoked when a budget overrun of a task occurs. */ |
---|
| 90 | typedef void (*Scheduler_CBS_Budget_overrun)( |
---|
| 91 | Scheduler_CBS_Server_id server_id |
---|
| 92 | ); |
---|
| 93 | |
---|
| 94 | /** |
---|
| 95 | * This structure handles server parameters. |
---|
| 96 | */ |
---|
| 97 | typedef struct { |
---|
| 98 | /** Relative deadline of the server. */ |
---|
| 99 | time_t deadline; |
---|
| 100 | /** Budget (computation time) of the server. */ |
---|
| 101 | time_t budget; |
---|
| 102 | } Scheduler_CBS_Parameters; |
---|
| 103 | |
---|
| 104 | /** |
---|
| 105 | * This structure represents a time server. |
---|
| 106 | */ |
---|
| 107 | typedef struct { |
---|
| 108 | /** |
---|
| 109 | * Task id. |
---|
| 110 | * |
---|
| 111 | * @note: The current implementation of CBS handles only one task per server. |
---|
| 112 | */ |
---|
| 113 | rtems_id task_id; |
---|
| 114 | /** Server paramenters. */ |
---|
| 115 | Scheduler_CBS_Parameters parameters; |
---|
| 116 | /** Callback function invoked when a budget overrun occurs. */ |
---|
| 117 | Scheduler_CBS_Budget_overrun cbs_budget_overrun; |
---|
| 118 | } Scheduler_CBS_Server; |
---|
| 119 | |
---|
| 120 | /** |
---|
| 121 | * This structure handles CBS specific data of a thread. |
---|
| 122 | */ |
---|
| 123 | typedef struct { |
---|
| 124 | /** EDF scheduler specific data of a task. */ |
---|
| 125 | Scheduler_EDF_Per_thread edf_per_thread; |
---|
| 126 | /** CBS server specific data of a task. */ |
---|
| 127 | Scheduler_CBS_Server *cbs_server; |
---|
| 128 | } Scheduler_CBS_Per_thread; |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | /** |
---|
| 132 | * List of servers. The @a Scheduler_CBS_Server is the index to the array |
---|
| 133 | * of pointers to @a _Scheduler_CBS_Server_list. |
---|
| 134 | */ |
---|
[1072d53d] | 135 | extern Scheduler_CBS_Server **_Scheduler_CBS_Server_list; |
---|
[82db8e56] | 136 | |
---|
| 137 | /** |
---|
[319cb20] | 138 | * @brief Unblocks a thread from the queue. |
---|
[82db8e56] | 139 | * |
---|
| 140 | * This routine adds @a the_thread to the scheduling decision, that is, |
---|
| 141 | * adds it to the ready queue and updates any appropriate scheduling |
---|
[319cb20] | 142 | * variables, for example the heir thread. It is checked whether the |
---|
| 143 | * remaining budget is sufficient. If not, the thread continues as a |
---|
[f839bf5a] | 144 | * new job in order to protect concurrent threads. |
---|
[82db8e56] | 145 | * |
---|
[f839bf5a] | 146 | * @param[in] the_thread will be unblocked. |
---|
[82db8e56] | 147 | * |
---|
| 148 | * @note This has to be asessed as missed deadline of the current job. |
---|
| 149 | */ |
---|
| 150 | void _Scheduler_CBS_Unblock( |
---|
| 151 | Thread_Control *the_thread |
---|
| 152 | ); |
---|
| 153 | |
---|
| 154 | /** |
---|
[319cb20] | 155 | * @brief Called when a new job of task is released. |
---|
[82db8e56] | 156 | * |
---|
| 157 | * This routine is called when a new job of task is released. |
---|
| 158 | * It is called only from Rate Monotonic manager in the beginning |
---|
| 159 | * of new period. Deadline has to be shifted and budget replenished. |
---|
| 160 | * |
---|
| 161 | * @param[in] the_thread is the owner of the job. |
---|
| 162 | * @param[in] length of the new job from now. If equal to 0, |
---|
| 163 | * the job was cancelled or deleted. |
---|
| 164 | */ |
---|
| 165 | |
---|
| 166 | void _Scheduler_CBS_Release_job ( |
---|
| 167 | Thread_Control *the_thread, |
---|
| 168 | uint32_t length |
---|
| 169 | ); |
---|
| 170 | |
---|
| 171 | /** |
---|
| 172 | * @brief _Scheduler_CBS_Initialize |
---|
| 173 | * |
---|
| 174 | * Initializes the CBS library. |
---|
| 175 | * |
---|
[319cb20] | 176 | * @retval status code. |
---|
[82db8e56] | 177 | */ |
---|
| 178 | int _Scheduler_CBS_Initialize(void); |
---|
| 179 | |
---|
| 180 | /** |
---|
[319cb20] | 181 | * @brief Attach a task to an already existing server. |
---|
[82db8e56] | 182 | * |
---|
| 183 | * Attach a task to an already existing server. |
---|
| 184 | * |
---|
[319cb20] | 185 | * @retval status code. |
---|
[82db8e56] | 186 | */ |
---|
| 187 | int _Scheduler_CBS_Attach_thread ( |
---|
| 188 | Scheduler_CBS_Server_id server_id, |
---|
| 189 | rtems_id task_id |
---|
| 190 | ); |
---|
| 191 | |
---|
| 192 | /** |
---|
[319cb20] | 193 | * @brief Detach from the CBS Server. |
---|
[82db8e56] | 194 | * |
---|
| 195 | * Detach from the CBS Server. |
---|
| 196 | * |
---|
[319cb20] | 197 | * @retval status code. |
---|
[82db8e56] | 198 | */ |
---|
| 199 | int _Scheduler_CBS_Detach_thread ( |
---|
| 200 | Scheduler_CBS_Server_id server_id, |
---|
| 201 | rtems_id task_id |
---|
| 202 | ); |
---|
| 203 | |
---|
| 204 | /** |
---|
[319cb20] | 205 | * @brief Cleanup resources associated to the CBS Library. |
---|
[82db8e56] | 206 | * |
---|
| 207 | * Cleanup resources associated to the CBS Library. |
---|
| 208 | * |
---|
[319cb20] | 209 | * @retval status code. |
---|
[82db8e56] | 210 | */ |
---|
| 211 | int _Scheduler_CBS_Cleanup (void); |
---|
| 212 | |
---|
| 213 | /** |
---|
[319cb20] | 214 | * @brief Create a new server with specified parameters. |
---|
[82db8e56] | 215 | * |
---|
| 216 | * Create a new server with specified parameters. |
---|
| 217 | * |
---|
[319cb20] | 218 | * @retval status code. |
---|
[82db8e56] | 219 | */ |
---|
| 220 | int _Scheduler_CBS_Create_server ( |
---|
| 221 | Scheduler_CBS_Parameters *params, |
---|
| 222 | Scheduler_CBS_Budget_overrun budget_overrun_callback, |
---|
| 223 | rtems_id *server_id |
---|
| 224 | ); |
---|
| 225 | |
---|
| 226 | /** |
---|
[319cb20] | 227 | * @brief Detach all tasks from a server and destroy it. |
---|
[82db8e56] | 228 | * |
---|
| 229 | * Detach all tasks from a server and destroy it. |
---|
| 230 | * |
---|
[d4d7899] | 231 | * @param[in] server_id is the ID of the server |
---|
| 232 | * |
---|
[319cb20] | 233 | * @retval status code. |
---|
[82db8e56] | 234 | */ |
---|
| 235 | int _Scheduler_CBS_Destroy_server ( |
---|
| 236 | Scheduler_CBS_Server_id server_id |
---|
| 237 | ); |
---|
| 238 | |
---|
| 239 | /** |
---|
[319cb20] | 240 | * @brief Retrieve the approved budget. |
---|
[82db8e56] | 241 | * |
---|
| 242 | * Retrieve the budget that has been approved for the subsequent |
---|
| 243 | * server instances. |
---|
| 244 | * |
---|
[319cb20] | 245 | * @retval status code. |
---|
[82db8e56] | 246 | */ |
---|
| 247 | int _Scheduler_CBS_Get_approved_budget ( |
---|
| 248 | Scheduler_CBS_Server_id server_id, |
---|
| 249 | time_t *approved_budget |
---|
| 250 | ); |
---|
| 251 | |
---|
| 252 | /** |
---|
[319cb20] | 253 | * @brief Retrieve remaining budget for the current server instance. |
---|
[82db8e56] | 254 | * |
---|
| 255 | * Retrieve remaining budget for the current server instance. |
---|
| 256 | * |
---|
[319cb20] | 257 | * @retval status code. |
---|
[82db8e56] | 258 | */ |
---|
| 259 | int _Scheduler_CBS_Get_remaining_budget ( |
---|
| 260 | Scheduler_CBS_Server_id server_id, |
---|
| 261 | time_t *remaining_budget |
---|
| 262 | ); |
---|
| 263 | |
---|
| 264 | /** |
---|
[319cb20] | 265 | * @brief Get relative time info. |
---|
[82db8e56] | 266 | * |
---|
[1b475860] | 267 | * Retrieve time info relative to @a server_id. The server status code is returned. |
---|
| 268 | * |
---|
| 269 | * @param[in] server_id is the server to get the status code from. |
---|
| 270 | * @param[in] exec_time is the execution time. |
---|
[319cb20] | 271 | * @param[in] abs_time is not apparently used. |
---|
[82db8e56] | 272 | * |
---|
[319cb20] | 273 | * @retval status code. |
---|
[82db8e56] | 274 | */ |
---|
| 275 | int _Scheduler_CBS_Get_execution_time ( |
---|
| 276 | Scheduler_CBS_Server_id server_id, |
---|
| 277 | time_t *exec_time, |
---|
| 278 | time_t *abs_time |
---|
| 279 | ); |
---|
| 280 | |
---|
| 281 | /** |
---|
[319cb20] | 282 | * @brief Retrieve CBS scheduling parameters. |
---|
[82db8e56] | 283 | * |
---|
| 284 | * Retrieve CBS scheduling parameters. |
---|
| 285 | * |
---|
[319cb20] | 286 | * @retval status code. |
---|
[82db8e56] | 287 | */ |
---|
| 288 | int _Scheduler_CBS_Get_parameters ( |
---|
| 289 | Scheduler_CBS_Server_id server_id, |
---|
| 290 | Scheduler_CBS_Parameters *params |
---|
| 291 | ); |
---|
| 292 | |
---|
| 293 | /** |
---|
[319cb20] | 294 | * @brief Get a thread server id. |
---|
[82db8e56] | 295 | * |
---|
| 296 | * Get a thread server id, or SCHEDULER_CBS_ERROR_NOT_FOUND if it is not |
---|
| 297 | * attached to any server. |
---|
| 298 | * |
---|
[319cb20] | 299 | * @retval status code. |
---|
[82db8e56] | 300 | */ |
---|
| 301 | int _Scheduler_CBS_Get_server_id ( |
---|
| 302 | rtems_id task_id, |
---|
| 303 | Scheduler_CBS_Server_id *server_id |
---|
| 304 | ); |
---|
| 305 | |
---|
| 306 | /** |
---|
[319cb20] | 307 | * @brief Set parameters for CBS scheduling. |
---|
[82db8e56] | 308 | * |
---|
| 309 | * Change CBS scheduling parameters. |
---|
| 310 | * |
---|
[f839bf5a] | 311 | * @param[in] server_id is the ID of the server. |
---|
| 312 | * @param[in] parameters are the parameters to set. |
---|
| 313 | * |
---|
[319cb20] | 314 | * @retval status code. |
---|
[82db8e56] | 315 | */ |
---|
| 316 | int _Scheduler_CBS_Set_parameters ( |
---|
| 317 | Scheduler_CBS_Server_id server_id, |
---|
| 318 | Scheduler_CBS_Parameters *parameters |
---|
| 319 | ); |
---|
| 320 | |
---|
| 321 | /** |
---|
[319cb20] | 322 | * @brief Invoked when a limited time quantum is exceeded. |
---|
[82db8e56] | 323 | * |
---|
| 324 | * This routine is invoked when a limited time quantum is exceeded. |
---|
| 325 | */ |
---|
| 326 | void _Scheduler_CBS_Budget_callout( |
---|
| 327 | Thread_Control *the_thread |
---|
| 328 | ); |
---|
| 329 | |
---|
[7a9288fe] | 330 | /** |
---|
[319cb20] | 331 | * @brief Allocates CBS specific information of @a the_thread. |
---|
[7a9288fe] | 332 | * |
---|
| 333 | * This routine allocates CBS specific information of @a the_thread. |
---|
| 334 | * |
---|
| 335 | * @param[in] the_thread is the thread the scheduler is allocating |
---|
| 336 | * management memory for. |
---|
| 337 | */ |
---|
| 338 | void *_Scheduler_CBS_Allocate( |
---|
| 339 | Thread_Control *the_thread |
---|
| 340 | ); |
---|
[82db8e56] | 341 | #ifdef __cplusplus |
---|
| 342 | } |
---|
| 343 | #endif |
---|
| 344 | |
---|
| 345 | /**@}*/ |
---|
| 346 | |
---|
| 347 | #endif |
---|
[a15eaaf] | 348 | /* end of include file */ |
---|