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