[5472ad41] | 1 | /** |
---|
| 2 | * @file rtems/score/scheduleredf.h |
---|
| 3 | * |
---|
[a1f9934a] | 4 | * @brief Data Related to the Manipulation of Threads for the EDF Scheduler |
---|
| 5 | * |
---|
[5472ad41] | 6 | * This include file contains all the constants and structures associated |
---|
| 7 | * with the manipulation of threads for the EDF 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 |
---|
[c499856] | 16 | * http://www.rtems.org/license/LICENSE. |
---|
[5472ad41] | 17 | */ |
---|
| 18 | |
---|
| 19 | #ifndef _RTEMS_SCORE_SCHEDULEREDF_H |
---|
| 20 | #define _RTEMS_SCORE_SCHEDULEREDF_H |
---|
| 21 | |
---|
| 22 | #include <rtems/score/priority.h> |
---|
| 23 | #include <rtems/score/scheduler.h> |
---|
| 24 | #include <rtems/score/schedulerpriority.h> |
---|
| 25 | #include <rtems/score/rbtree.h> |
---|
| 26 | |
---|
| 27 | #ifdef __cplusplus |
---|
| 28 | extern "C" { |
---|
| 29 | #endif |
---|
| 30 | |
---|
| 31 | /** |
---|
[a15eaaf] | 32 | * @defgroup ScoreSchedulerEDF EDF Scheduler |
---|
[5472ad41] | 33 | * |
---|
[a15eaaf] | 34 | * @ingroup ScoreScheduler |
---|
[5472ad41] | 35 | */ |
---|
| 36 | /**@{*/ |
---|
| 37 | |
---|
[7dfb4b9] | 38 | #define SCHEDULER_EDF_MAXIMUM_PRIORITY 255 |
---|
| 39 | |
---|
[5472ad41] | 40 | /** |
---|
| 41 | * Entry points for the Earliest Deadline First Scheduler. |
---|
| 42 | */ |
---|
| 43 | #define SCHEDULER_EDF_ENTRY_POINTS \ |
---|
| 44 | { \ |
---|
| 45 | _Scheduler_EDF_Initialize, /* initialize entry point */ \ |
---|
| 46 | _Scheduler_EDF_Schedule, /* schedule entry point */ \ |
---|
| 47 | _Scheduler_EDF_Yield, /* yield entry point */ \ |
---|
| 48 | _Scheduler_EDF_Block, /* block entry point */ \ |
---|
| 49 | _Scheduler_EDF_Unblock, /* unblock entry point */ \ |
---|
[f39f667a] | 50 | _Scheduler_EDF_Change_priority, /* change priority entry point */ \ |
---|
[77ff5599] | 51 | _Scheduler_EDF_Map_priority, /* map priority entry point */ \ |
---|
| 52 | _Scheduler_EDF_Unmap_priority, /* unmap priority entry point */ \ |
---|
[5c3d250] | 53 | SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP \ |
---|
[8e467384] | 54 | _Scheduler_EDF_Node_initialize, /* node initialize entry point */ \ |
---|
| 55 | _Scheduler_default_Node_destroy, /* node destroy entry point */ \ |
---|
[4d1f500] | 56 | _Scheduler_EDF_Update_priority, /* update priority entry point */ \ |
---|
[5472ad41] | 57 | _Scheduler_EDF_Release_job, /* new period of task */ \ |
---|
[a344308] | 58 | _Scheduler_default_Tick, /* tick entry point */ \ |
---|
[1ccb64e1] | 59 | _Scheduler_default_Start_idle /* start idle entry point */ \ |
---|
[bd1431a] | 60 | SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \ |
---|
[5472ad41] | 61 | } |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * This is just a most significant bit of Priority_Control type. It |
---|
| 65 | * distinguishes threads which are deadline driven (priority |
---|
| 66 | * represented by a lower number than @a SCHEDULER_EDF_PRIO_MSB) from those |
---|
| 67 | * ones who do not have any deadlines and thus are considered background |
---|
| 68 | * tasks. |
---|
| 69 | */ |
---|
| 70 | #define SCHEDULER_EDF_PRIO_MSB 0x80000000 |
---|
| 71 | |
---|
[3891983] | 72 | typedef struct { |
---|
[e1598a6] | 73 | /** |
---|
| 74 | * @brief Basic scheduler context. |
---|
| 75 | */ |
---|
| 76 | Scheduler_Context Base; |
---|
| 77 | |
---|
[3891983] | 78 | /** |
---|
| 79 | * Top of the ready queue. |
---|
| 80 | */ |
---|
| 81 | RBTree_Control Ready; |
---|
[e1598a6] | 82 | } Scheduler_EDF_Context; |
---|
[3891983] | 83 | |
---|
[5472ad41] | 84 | /** |
---|
| 85 | * @typedef Scheduler_EDF_Queue_state |
---|
| 86 | * |
---|
| 87 | * This enumeration distiguishes state of a thread with respect to the |
---|
| 88 | * ready queue. |
---|
| 89 | */ |
---|
| 90 | typedef enum { |
---|
| 91 | SCHEDULER_EDF_QUEUE_STATE_NOT_PRESENTLY, |
---|
| 92 | SCHEDULER_EDF_QUEUE_STATE_YES, |
---|
| 93 | SCHEDULER_EDF_QUEUE_STATE_NEVER_HAS_BEEN |
---|
| 94 | } Scheduler_EDF_Queue_state; |
---|
| 95 | |
---|
| 96 | /** |
---|
[beab7329] | 97 | * @brief Scheduler node specialization for EDF schedulers. |
---|
[5472ad41] | 98 | */ |
---|
| 99 | typedef struct { |
---|
[beab7329] | 100 | /** |
---|
| 101 | * @brief Basic scheduler node. |
---|
| 102 | */ |
---|
| 103 | Scheduler_Node Base; |
---|
| 104 | |
---|
[5472ad41] | 105 | /** |
---|
| 106 | * Pointer to corresponding Thread Control Block. |
---|
| 107 | */ |
---|
| 108 | Thread_Control *thread; |
---|
| 109 | /** |
---|
| 110 | * Rbtree node related to this thread. |
---|
| 111 | */ |
---|
| 112 | RBTree_Node Node; |
---|
| 113 | /** |
---|
| 114 | * State of the thread with respect to ready queue. |
---|
| 115 | */ |
---|
| 116 | Scheduler_EDF_Queue_state queue_state; |
---|
[beab7329] | 117 | } Scheduler_EDF_Node; |
---|
[5472ad41] | 118 | |
---|
| 119 | /** |
---|
[a7e4de2] | 120 | * @brief Initialize EDF scheduler. |
---|
[5472ad41] | 121 | * |
---|
[a7e4de2] | 122 | * This routine initializes the EDF scheduler. |
---|
| 123 | * |
---|
| 124 | * @param[in] scheduler The scheduler instance. |
---|
[5472ad41] | 125 | */ |
---|
[e1598a6] | 126 | void _Scheduler_EDF_Initialize( const Scheduler_Control *scheduler ); |
---|
[5472ad41] | 127 | |
---|
| 128 | /** |
---|
[a1f9934a] | 129 | * @brief Removes thread from ready queue. |
---|
[5472ad41] | 130 | * |
---|
| 131 | * This routine removes @a the_thread from the scheduling decision, |
---|
| 132 | * that is, removes it from the ready queue. It performs |
---|
| 133 | * any necessary scheduling operations including the selection of |
---|
| 134 | * a new heir thread. |
---|
| 135 | * |
---|
[a7e4de2] | 136 | * @param[in] scheduler The scheduler instance. |
---|
[5472ad41] | 137 | * @param[in] the_thread is the thread to be blocked. |
---|
| 138 | */ |
---|
| 139 | void _Scheduler_EDF_Block( |
---|
[e1598a6] | 140 | const Scheduler_Control *scheduler, |
---|
| 141 | Thread_Control *the_thread |
---|
[5472ad41] | 142 | ); |
---|
| 143 | |
---|
| 144 | /** |
---|
[a1f9934a] | 145 | * @brief Sets the heir thread to be the next ready thread |
---|
| 146 | * in the rbtree ready queue. |
---|
[5472ad41] | 147 | * |
---|
| 148 | * This kernel routine sets the heir thread to be the next ready thread |
---|
| 149 | * in the rbtree ready queue. |
---|
[a7e4de2] | 150 | * |
---|
| 151 | * @param[in] scheduler The scheduler instance. |
---|
| 152 | * @param[in] the_thread being scheduled. |
---|
[5472ad41] | 153 | */ |
---|
[24934e36] | 154 | void _Scheduler_EDF_Schedule( |
---|
[e1598a6] | 155 | const Scheduler_Control *scheduler, |
---|
| 156 | Thread_Control *the_thread |
---|
[24934e36] | 157 | ); |
---|
[5472ad41] | 158 | |
---|
| 159 | /** |
---|
[8e467384] | 160 | * @brief Initializes an EDF specific scheduler node of @a the_thread. |
---|
[a7e4de2] | 161 | * |
---|
| 162 | * @param[in] scheduler The scheduler instance. |
---|
| 163 | * @param[in] the_thread being initialized. |
---|
[5472ad41] | 164 | */ |
---|
[8e467384] | 165 | void _Scheduler_EDF_Node_initialize( |
---|
[e1598a6] | 166 | const Scheduler_Control *scheduler, |
---|
| 167 | Thread_Control *the_thread |
---|
[5472ad41] | 168 | ); |
---|
| 169 | |
---|
| 170 | /** |
---|
[a1f9934a] | 171 | * @brief Updates position in the ready queue of @a the_thread. |
---|
[5472ad41] | 172 | * |
---|
| 173 | * This routine updates position in the ready queue of @a the_thread. |
---|
| 174 | * |
---|
[a7e4de2] | 175 | * @param[in] scheduler The scheduler instance. |
---|
[5472ad41] | 176 | * @param[in] the_thread will have its scheduler specific information |
---|
| 177 | * structure updated. |
---|
[a7e4de2] | 178 | * @param[in] new_priority is the desired new priority. |
---|
[5472ad41] | 179 | */ |
---|
[4d1f500] | 180 | void _Scheduler_EDF_Update_priority( |
---|
[e1598a6] | 181 | const Scheduler_Control *scheduler, |
---|
[4d1f500] | 182 | Thread_Control *the_thread, |
---|
| 183 | Priority_Control new_priority |
---|
[5472ad41] | 184 | ); |
---|
| 185 | |
---|
| 186 | /** |
---|
[a1f9934a] | 187 | * @brief Adds @a the_thread to the scheduling decision. |
---|
[5472ad41] | 188 | * |
---|
| 189 | * This routine adds @a the_thread to the scheduling decision, that is, |
---|
| 190 | * adds it to the ready queue and updates any appropriate scheduling |
---|
| 191 | * variables, for example the heir thread. |
---|
| 192 | * |
---|
[a7e4de2] | 193 | * @param[in] scheduler The scheduler instance. |
---|
[5472ad41] | 194 | * @param[in] the_thread will be unblocked. |
---|
| 195 | */ |
---|
[8568341] | 196 | Scheduler_Void_or_thread _Scheduler_EDF_Unblock( |
---|
[e1598a6] | 197 | const Scheduler_Control *scheduler, |
---|
| 198 | Thread_Control *the_thread |
---|
[5472ad41] | 199 | ); |
---|
| 200 | |
---|
[8568341] | 201 | Scheduler_Void_or_thread _Scheduler_EDF_Change_priority( |
---|
[f39f667a] | 202 | const Scheduler_Control *scheduler, |
---|
| 203 | Thread_Control *the_thread, |
---|
| 204 | Priority_Control new_priority, |
---|
| 205 | bool prepend_it |
---|
| 206 | ); |
---|
| 207 | |
---|
[77ff5599] | 208 | Priority_Control _Scheduler_EDF_Map_priority( |
---|
| 209 | const Scheduler_Control *scheduler, |
---|
| 210 | Priority_Control priority |
---|
| 211 | ); |
---|
| 212 | |
---|
| 213 | Priority_Control _Scheduler_EDF_Unmap_priority( |
---|
| 214 | const Scheduler_Control *scheduler, |
---|
| 215 | Priority_Control priority |
---|
| 216 | ); |
---|
| 217 | |
---|
[5472ad41] | 218 | /** |
---|
[a1f9934a] | 219 | * @brief invoked when a thread wishes to voluntarily |
---|
| 220 | * transfer control of the processor to another thread |
---|
| 221 | * with equal deadline. |
---|
[5472ad41] | 222 | * |
---|
| 223 | * This routine is invoked when a thread wishes to voluntarily |
---|
| 224 | * transfer control of the processor to another thread in the queue with |
---|
| 225 | * equal deadline. This does not have to happen very often. |
---|
| 226 | * |
---|
[6eba7c85] | 227 | * This routine will remove the specified THREAD from the ready queue |
---|
| 228 | * and place it back. The rbtree ready queue is responsible for FIFO ordering |
---|
[5472ad41] | 229 | * in such a case. |
---|
[6eba7c85] | 230 | * |
---|
[a7e4de2] | 231 | * @param[in] scheduler The scheduler instance. |
---|
| 232 | * @param[in,out] the_thread The yielding thread. |
---|
[5472ad41] | 233 | */ |
---|
[8568341] | 234 | Scheduler_Void_or_thread _Scheduler_EDF_Yield( |
---|
[e1598a6] | 235 | const Scheduler_Control *scheduler, |
---|
| 236 | Thread_Control *the_thread |
---|
[24934e36] | 237 | ); |
---|
[5472ad41] | 238 | |
---|
| 239 | /** |
---|
[a1f9934a] | 240 | * @brief Called when a new job of task is released. |
---|
[5472ad41] | 241 | * |
---|
| 242 | * This routine is called when a new job of task is released. |
---|
| 243 | * It is called only from Rate Monotonic manager in the beginning |
---|
| 244 | * of new period. |
---|
| 245 | * |
---|
[a7e4de2] | 246 | * @param[in] scheduler The scheduler instance. |
---|
[5472ad41] | 247 | * @param[in] the_thread is the owner of the job. |
---|
| 248 | * @param[in] deadline of the new job from now. If equal to 0, |
---|
| 249 | * the job was cancelled or deleted, thus a running task |
---|
| 250 | * has to be suspended. |
---|
| 251 | */ |
---|
| 252 | void _Scheduler_EDF_Release_job ( |
---|
[e1598a6] | 253 | const Scheduler_Control *scheduler, |
---|
| 254 | Thread_Control *the_thread, |
---|
[9a78f8a5] | 255 | uint64_t deadline |
---|
[5472ad41] | 256 | ); |
---|
| 257 | |
---|
| 258 | #ifdef __cplusplus |
---|
| 259 | } |
---|
| 260 | #endif |
---|
| 261 | |
---|
| 262 | /**@}*/ |
---|
| 263 | |
---|
| 264 | #endif |
---|
[a15eaaf] | 265 | /* end of include file */ |
---|