1 | /** |
---|
2 | * @file rtems/score/scheduler.h |
---|
3 | * |
---|
4 | * @brief Constants and Structures Associated with the Scheduler |
---|
5 | * |
---|
6 | * This include file contains all the constants and structures associated |
---|
7 | * with the scheduler. |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * Copyright (C) 2010 Gedare Bloom. |
---|
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_SCHEDULER_H |
---|
20 | #define _RTEMS_SCORE_SCHEDULER_H |
---|
21 | |
---|
22 | #include <rtems/score/percpu.h> |
---|
23 | #include <rtems/score/priority.h> |
---|
24 | #include <rtems/score/thread.h> |
---|
25 | #if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP) |
---|
26 | #include <sys/cpuset.h> |
---|
27 | #endif |
---|
28 | |
---|
29 | #ifdef __cplusplus |
---|
30 | extern "C" { |
---|
31 | #endif |
---|
32 | |
---|
33 | /** |
---|
34 | * @defgroup ScoreScheduler Scheduler Handler |
---|
35 | * |
---|
36 | * @ingroup Score |
---|
37 | * |
---|
38 | * This handler encapsulates functionality related to managing sets of threads |
---|
39 | * that are ready for execution. |
---|
40 | */ |
---|
41 | /**@{*/ |
---|
42 | |
---|
43 | typedef struct Scheduler_Control Scheduler_Control; |
---|
44 | |
---|
45 | typedef struct Scheduler_Node Scheduler_Node; |
---|
46 | |
---|
47 | /** |
---|
48 | * @brief The scheduler operations. |
---|
49 | */ |
---|
50 | typedef struct { |
---|
51 | /** @see _Scheduler_Handler_initialization() */ |
---|
52 | void ( *initialize )( const Scheduler_Control * ); |
---|
53 | |
---|
54 | /** @see _Scheduler_Schedule() */ |
---|
55 | void ( *schedule )( const Scheduler_Control *, Thread_Control *); |
---|
56 | |
---|
57 | /** @see _Scheduler_Yield() */ |
---|
58 | void ( *yield )( const Scheduler_Control *, Thread_Control *); |
---|
59 | |
---|
60 | /** @see _Scheduler_Block() */ |
---|
61 | void ( *block )( const Scheduler_Control *, Thread_Control * ); |
---|
62 | |
---|
63 | /** @see _Scheduler_Unblock() */ |
---|
64 | void ( *unblock )( const Scheduler_Control *, Thread_Control * ); |
---|
65 | |
---|
66 | /** @see _Scheduler_Allocate() */ |
---|
67 | bool ( *allocate )( const Scheduler_Control *, Thread_Control * ); |
---|
68 | |
---|
69 | /** @see _Scheduler_Free() */ |
---|
70 | void ( *free )( const Scheduler_Control *, Thread_Control * ); |
---|
71 | |
---|
72 | /** @see _Scheduler_Update() */ |
---|
73 | void ( *update )( const Scheduler_Control *, Thread_Control * ); |
---|
74 | |
---|
75 | /** @see _Scheduler_Enqueue() */ |
---|
76 | void ( *enqueue )( const Scheduler_Control *, Thread_Control * ); |
---|
77 | |
---|
78 | /** @see _Scheduler_Enqueue_first() */ |
---|
79 | void ( *enqueue_first )( const Scheduler_Control *, Thread_Control * ); |
---|
80 | |
---|
81 | /** @see _Scheduler_Extract() */ |
---|
82 | void ( *extract )( const Scheduler_Control *, Thread_Control * ); |
---|
83 | |
---|
84 | /** @see _Scheduler_Priority_compare() */ |
---|
85 | int ( *priority_compare )( |
---|
86 | Priority_Control, |
---|
87 | Priority_Control |
---|
88 | ); |
---|
89 | |
---|
90 | /** @see _Scheduler_Release_job() */ |
---|
91 | void ( *release_job ) ( |
---|
92 | const Scheduler_Control *, |
---|
93 | Thread_Control *, |
---|
94 | uint32_t |
---|
95 | ); |
---|
96 | |
---|
97 | /** @see _Scheduler_Tick() */ |
---|
98 | void ( *tick )( const Scheduler_Control *, Thread_Control * ); |
---|
99 | |
---|
100 | /** @see _Scheduler_Start_idle() */ |
---|
101 | void ( *start_idle )( |
---|
102 | const Scheduler_Control *, |
---|
103 | Thread_Control *, |
---|
104 | Per_CPU_Control * |
---|
105 | ); |
---|
106 | |
---|
107 | #if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP) |
---|
108 | /** @see _Scheduler_Get_affinity() */ |
---|
109 | bool ( *get_affinity )( |
---|
110 | const Scheduler_Control *, |
---|
111 | Thread_Control *, |
---|
112 | size_t, |
---|
113 | cpu_set_t * |
---|
114 | ); |
---|
115 | |
---|
116 | /** @see _Scheduler_Set_affinity() */ |
---|
117 | bool ( *set_affinity )( |
---|
118 | const Scheduler_Control *, |
---|
119 | Thread_Control *, |
---|
120 | size_t, |
---|
121 | const cpu_set_t * |
---|
122 | ); |
---|
123 | #endif |
---|
124 | } Scheduler_Operations; |
---|
125 | |
---|
126 | /** |
---|
127 | * @brief Scheduler context. |
---|
128 | * |
---|
129 | * The scheduler context of a particular scheduler implementation must place |
---|
130 | * this structure at the begin of its context structure. |
---|
131 | */ |
---|
132 | typedef struct Scheduler_Context { |
---|
133 | #if defined(RTEMS_SMP) |
---|
134 | /** |
---|
135 | * @brief Count of processors owned by this scheduler instance. |
---|
136 | */ |
---|
137 | uint32_t processor_count; |
---|
138 | #endif |
---|
139 | } Scheduler_Context; |
---|
140 | |
---|
141 | /** |
---|
142 | * @brief Scheduler control. |
---|
143 | */ |
---|
144 | struct Scheduler_Control { |
---|
145 | /** |
---|
146 | * @brief Reference to a statically allocated scheduler context. |
---|
147 | */ |
---|
148 | Scheduler_Context *context; |
---|
149 | |
---|
150 | /** |
---|
151 | * @brief The scheduler operations. |
---|
152 | */ |
---|
153 | Scheduler_Operations Operations; |
---|
154 | |
---|
155 | /** |
---|
156 | * @brief The scheduler name. |
---|
157 | */ |
---|
158 | uint32_t name; |
---|
159 | }; |
---|
160 | |
---|
161 | /** |
---|
162 | * @brief Scheduler node for per-thread data. |
---|
163 | */ |
---|
164 | struct Scheduler_Node { |
---|
165 | /* No fields yet */ |
---|
166 | }; |
---|
167 | |
---|
168 | /** |
---|
169 | * @brief Registered schedulers. |
---|
170 | * |
---|
171 | * Application provided via <rtems/confdefs.h>. |
---|
172 | * |
---|
173 | * @see _Scheduler_Count. |
---|
174 | */ |
---|
175 | extern const Scheduler_Control _Scheduler_Table[]; |
---|
176 | |
---|
177 | /** |
---|
178 | * @brief Count of registered schedulers. |
---|
179 | * |
---|
180 | * Application provided via <rtems/confdefs.h> on SMP configurations. |
---|
181 | * |
---|
182 | * It is very important that this is a compile-time constant on uni-processor |
---|
183 | * configurations (in this case RTEMS_SMP is not defined) so that the compiler |
---|
184 | * can optimize the some loops away |
---|
185 | * |
---|
186 | * @see _Scheduler_Table. |
---|
187 | */ |
---|
188 | #if defined(RTEMS_SMP) |
---|
189 | extern const size_t _Scheduler_Count; |
---|
190 | #else |
---|
191 | #define _Scheduler_Count ( (size_t) 1 ) |
---|
192 | #endif |
---|
193 | |
---|
194 | #if defined(RTEMS_SMP) |
---|
195 | /** |
---|
196 | * @brief The scheduler assignment default attributes. |
---|
197 | */ |
---|
198 | #define SCHEDULER_ASSIGN_DEFAULT UINT32_C(0x0) |
---|
199 | |
---|
200 | /** |
---|
201 | * @brief The presence of this processor is optional. |
---|
202 | */ |
---|
203 | #define SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL SCHEDULER_ASSIGN_DEFAULT |
---|
204 | |
---|
205 | /** |
---|
206 | * @brief The presence of this processor is mandatory. |
---|
207 | */ |
---|
208 | #define SCHEDULER_ASSIGN_PROCESSOR_MANDATORY UINT32_C(0x1) |
---|
209 | |
---|
210 | /** |
---|
211 | * @brief Scheduler assignment. |
---|
212 | */ |
---|
213 | typedef struct { |
---|
214 | /** |
---|
215 | * @brief The scheduler for this processor. |
---|
216 | */ |
---|
217 | const Scheduler_Control *scheduler; |
---|
218 | |
---|
219 | /** |
---|
220 | * @brief The scheduler assignment attributes. |
---|
221 | * |
---|
222 | * Use @ref SCHEDULER_ASSIGN_DEFAULT to select default attributes. |
---|
223 | * |
---|
224 | * The presence of a processor can be |
---|
225 | * - @ref SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL, or |
---|
226 | * - @ref SCHEDULER_ASSIGN_PROCESSOR_MANDATORY. |
---|
227 | */ |
---|
228 | uint32_t attributes; |
---|
229 | } Scheduler_Assignment; |
---|
230 | |
---|
231 | /** |
---|
232 | * @brief The scheduler assignments. |
---|
233 | * |
---|
234 | * The length of this array must be equal to the maximum processors. |
---|
235 | * |
---|
236 | * Application provided via <rtems/confdefs.h>. |
---|
237 | * |
---|
238 | * @see _Scheduler_Table and rtems_configuration_get_maximum_processors(). |
---|
239 | */ |
---|
240 | extern const Scheduler_Assignment _Scheduler_Assignments[]; |
---|
241 | #endif |
---|
242 | |
---|
243 | /** |
---|
244 | * @brief Returns an arbitrary non-NULL value. |
---|
245 | * |
---|
246 | * @param[in] scheduler Unused. |
---|
247 | * @param[in] the_thread Unused. |
---|
248 | * |
---|
249 | * @retval true Always. |
---|
250 | */ |
---|
251 | bool _Scheduler_default_Allocate( |
---|
252 | const Scheduler_Control *scheduler, |
---|
253 | Thread_Control *the_thread |
---|
254 | ); |
---|
255 | |
---|
256 | /** |
---|
257 | * @brief Does nothing. |
---|
258 | * |
---|
259 | * @param[in] scheduler Unused. |
---|
260 | * @param[in] the_thread Unused. |
---|
261 | */ |
---|
262 | void _Scheduler_default_Free( |
---|
263 | const Scheduler_Control *scheduler, |
---|
264 | Thread_Control *the_thread |
---|
265 | ); |
---|
266 | |
---|
267 | /** |
---|
268 | * @brief Does nothing. |
---|
269 | * |
---|
270 | * @param[in] scheduler Unused. |
---|
271 | * @param[in] the_thread Unused. |
---|
272 | */ |
---|
273 | void _Scheduler_default_Update( |
---|
274 | const Scheduler_Control *scheduler, |
---|
275 | Thread_Control *the_thread |
---|
276 | ); |
---|
277 | |
---|
278 | /** |
---|
279 | * @brief Does nothing. |
---|
280 | * |
---|
281 | * @param[in] scheduler Unused. |
---|
282 | * @param[in] the_thread Unused. |
---|
283 | * @param[in] deadline Unused. |
---|
284 | */ |
---|
285 | void _Scheduler_default_Release_job( |
---|
286 | const Scheduler_Control *scheduler, |
---|
287 | Thread_Control *the_thread, |
---|
288 | uint32_t deadline |
---|
289 | ); |
---|
290 | |
---|
291 | /** |
---|
292 | * @brief Performs tick operations depending on the CPU budget algorithm for |
---|
293 | * each executing thread. |
---|
294 | * |
---|
295 | * This routine is invoked as part of processing each clock tick. |
---|
296 | * |
---|
297 | * @param[in] scheduler The scheduler. |
---|
298 | * @param[in] execution An executing thread. |
---|
299 | */ |
---|
300 | void _Scheduler_default_Tick( |
---|
301 | const Scheduler_Control *scheduler, |
---|
302 | Thread_Control *executing |
---|
303 | ); |
---|
304 | |
---|
305 | /** |
---|
306 | * @brief Starts an idle thread. |
---|
307 | * |
---|
308 | * @param[in] scheduler The scheduler. |
---|
309 | * @param[in] the_thread An idle thread. |
---|
310 | * @param[in] cpu This parameter is unused. |
---|
311 | */ |
---|
312 | void _Scheduler_default_Start_idle( |
---|
313 | const Scheduler_Control *scheduler, |
---|
314 | Thread_Control *the_thread, |
---|
315 | Per_CPU_Control *cpu |
---|
316 | ); |
---|
317 | |
---|
318 | #if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP) |
---|
319 | /** |
---|
320 | * @brief Get affinity for the default scheduler. |
---|
321 | * |
---|
322 | * @param[in] thread The associated thread. |
---|
323 | * @param[in] cpusetsize The size of the cpuset. |
---|
324 | * @param[out] cpuset Affinity set containing all CPUs. |
---|
325 | * |
---|
326 | * @retval 0 Successfully got cpuset |
---|
327 | * @retval -1 The cpusetsize is invalid for the system |
---|
328 | */ |
---|
329 | bool _Scheduler_default_Get_affinity( |
---|
330 | const Scheduler_Control *scheduler, |
---|
331 | Thread_Control *thread, |
---|
332 | size_t cpusetsize, |
---|
333 | cpu_set_t *cpuset |
---|
334 | ); |
---|
335 | |
---|
336 | /** |
---|
337 | * @brief Set affinity for the default scheduler. |
---|
338 | * |
---|
339 | * @param[in] thread The associated thread. |
---|
340 | * @param[in] cpusetsize The size of the cpuset. |
---|
341 | * @param[in] cpuset Affinity new affinity set. |
---|
342 | * |
---|
343 | * @retval 0 Successful |
---|
344 | * |
---|
345 | * This method always returns successful and does not save |
---|
346 | * the cpuset. |
---|
347 | */ |
---|
348 | bool _Scheduler_default_Set_affinity( |
---|
349 | const Scheduler_Control *scheduler, |
---|
350 | Thread_Control *thread, |
---|
351 | size_t cpusetsize, |
---|
352 | const cpu_set_t *cpuset |
---|
353 | ); |
---|
354 | #endif |
---|
355 | |
---|
356 | /** |
---|
357 | * @brief Indicates if thread priority queues are broken with the configured |
---|
358 | * scheduler or not. |
---|
359 | * |
---|
360 | * See also PR2174: Memory corruption with EDF scheduler and thread priority |
---|
361 | * queues. |
---|
362 | */ |
---|
363 | extern const bool _Scheduler_FIXME_thread_priority_queues_are_broken; |
---|
364 | |
---|
365 | /**@}*/ |
---|
366 | |
---|
367 | #ifdef __cplusplus |
---|
368 | } |
---|
369 | #endif |
---|
370 | |
---|
371 | #endif |
---|
372 | /* end of include file */ |
---|