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/chain.h> |
---|
24 | #include <rtems/score/priority.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 | /** |
---|
44 | * function jump table that holds pointers to the functions that |
---|
45 | * implement specific schedulers. |
---|
46 | */ |
---|
47 | typedef struct { |
---|
48 | /** Implements the scheduling decision logic (policy). */ |
---|
49 | void ( *initialize )(void); |
---|
50 | |
---|
51 | /** Implements the scheduling decision logic (policy). */ |
---|
52 | void ( *schedule )( Thread_Control *thread ); |
---|
53 | |
---|
54 | /** |
---|
55 | * @brief Voluntarily yields the processor per the scheduling policy. |
---|
56 | * |
---|
57 | * @see _Scheduler_Yield(). |
---|
58 | */ |
---|
59 | void ( *yield )( Thread_Control *thread ); |
---|
60 | |
---|
61 | /** Removes the given thread from scheduling decisions. */ |
---|
62 | void ( *block )(Thread_Control *); |
---|
63 | |
---|
64 | /** Adds the given thread to scheduling decisions. */ |
---|
65 | void ( *unblock )(Thread_Control *); |
---|
66 | |
---|
67 | /** allocates the scheduler field of the given thread */ |
---|
68 | void * ( *allocate )(Thread_Control *); |
---|
69 | |
---|
70 | /** frees the scheduler field of the given thread */ |
---|
71 | void ( *free )(Thread_Control *); |
---|
72 | |
---|
73 | /** updates the scheduler field of the given thread -- primarily used |
---|
74 | * when changing the thread's priority. */ |
---|
75 | void ( *update )(Thread_Control *); |
---|
76 | |
---|
77 | /** enqueue a thread as the last of its priority group */ |
---|
78 | void ( *enqueue )(Thread_Control *); |
---|
79 | |
---|
80 | /** enqueue a thread as the first of its priority group */ |
---|
81 | void ( *enqueue_first )(Thread_Control *); |
---|
82 | |
---|
83 | /** extract a thread from the ready set */ |
---|
84 | void ( *extract )(Thread_Control *); |
---|
85 | |
---|
86 | /** |
---|
87 | * Compares two priorities (returns >0 for higher priority, 0 for equal |
---|
88 | * and <0 for lower priority). |
---|
89 | */ |
---|
90 | int ( *priority_compare )(Priority_Control, Priority_Control); |
---|
91 | |
---|
92 | /** This routine is called upon release of a new job. */ |
---|
93 | void ( *release_job ) (Thread_Control *, uint32_t); |
---|
94 | |
---|
95 | /** perform scheduler update actions required at each clock tick */ |
---|
96 | void ( *tick )(void); |
---|
97 | |
---|
98 | /** |
---|
99 | * @brief Starts the idle thread for a particular processor. |
---|
100 | * |
---|
101 | * @see _Scheduler_Start_idle(). |
---|
102 | */ |
---|
103 | void ( *start_idle )( Thread_Control *thread, Per_CPU_Control *processor ); |
---|
104 | |
---|
105 | #if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP) |
---|
106 | /** |
---|
107 | * @brief Obtain the processor affinity for a thread. |
---|
108 | * |
---|
109 | * @see _Scheduler_Get_affinity(). |
---|
110 | */ |
---|
111 | bool ( *get_affinity )( Thread_Control *thread, size_t cpusetsize, cpu_set_t *cpuset ); |
---|
112 | |
---|
113 | /** |
---|
114 | * @brief Set the processor affinity for a thread. |
---|
115 | * |
---|
116 | * @see _Scheduler_Set_affinity(). |
---|
117 | */ |
---|
118 | bool ( *set_affinity )( |
---|
119 | Thread_Control *thread, |
---|
120 | size_t cpusetsize, |
---|
121 | const cpu_set_t *cpuset |
---|
122 | ); |
---|
123 | #endif |
---|
124 | |
---|
125 | } Scheduler_Operations; |
---|
126 | |
---|
127 | /** |
---|
128 | * This is the structure used to manage the scheduler. |
---|
129 | */ |
---|
130 | typedef struct { |
---|
131 | /** |
---|
132 | * This points to the data structure used to manage the ready set of |
---|
133 | * tasks. The pointer varies based upon the type of |
---|
134 | * ready queue required by the scheduler. |
---|
135 | */ |
---|
136 | void *information; |
---|
137 | |
---|
138 | /** The jump table for scheduler-specific functions */ |
---|
139 | Scheduler_Operations Operations; |
---|
140 | } Scheduler_Control; |
---|
141 | |
---|
142 | /** |
---|
143 | * The _Scheduler holds the structures used to manage the |
---|
144 | * scheduler. |
---|
145 | * |
---|
146 | * @note Can we make this per-cpu? then _Scheduler will be a macro. |
---|
147 | * |
---|
148 | * @note This is instantiated and initialized in confdefs.h. |
---|
149 | */ |
---|
150 | extern Scheduler_Control _Scheduler; |
---|
151 | |
---|
152 | /** |
---|
153 | * @brief Returns an arbitrary non-NULL value. |
---|
154 | * |
---|
155 | * @param[in] thread Unused. |
---|
156 | * |
---|
157 | * @return An arbitrary non-NULL value. |
---|
158 | */ |
---|
159 | void *_Scheduler_default_Allocate( |
---|
160 | Thread_Control *thread |
---|
161 | ); |
---|
162 | |
---|
163 | /** |
---|
164 | * @brief Does nothing. |
---|
165 | * |
---|
166 | * @param[in] thread Unused. |
---|
167 | */ |
---|
168 | void _Scheduler_default_Free( |
---|
169 | Thread_Control *thread |
---|
170 | ); |
---|
171 | |
---|
172 | /** |
---|
173 | * @brief Does nothing. |
---|
174 | * |
---|
175 | * @param[in] thread Unused. |
---|
176 | */ |
---|
177 | void _Scheduler_default_Update( |
---|
178 | Thread_Control *the_thread |
---|
179 | ); |
---|
180 | |
---|
181 | /** |
---|
182 | * @brief Does nothing. |
---|
183 | * |
---|
184 | * @param[in] thread Unused. |
---|
185 | * @param[in] deadline Unused. |
---|
186 | */ |
---|
187 | void _Scheduler_default_Release_job( |
---|
188 | Thread_Control *thread, |
---|
189 | uint32_t deadline |
---|
190 | ); |
---|
191 | |
---|
192 | /** |
---|
193 | * @brief Performs tick operations depending on the CPU budget algorithm for |
---|
194 | * each executing thread. |
---|
195 | * |
---|
196 | * This routine is invoked as part of processing each clock tick. |
---|
197 | */ |
---|
198 | void _Scheduler_default_Tick( void ); |
---|
199 | |
---|
200 | /** |
---|
201 | * @brief Unblocks the thread. |
---|
202 | * |
---|
203 | * @param[in,out] thread An idle thread. |
---|
204 | * @param[in] processor This parameter is unused. |
---|
205 | */ |
---|
206 | void _Scheduler_default_Start_idle( |
---|
207 | Thread_Control *thread, |
---|
208 | Per_CPU_Control *processor |
---|
209 | ); |
---|
210 | |
---|
211 | #if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP) |
---|
212 | /** |
---|
213 | * @brief Get affinity for the default scheduler. |
---|
214 | * |
---|
215 | * @param[in] thread The associated thread. |
---|
216 | * @param[in] cpusetsize The size of the cpuset. |
---|
217 | * @param[out] cpuset Affinity set containing all CPUs. |
---|
218 | * |
---|
219 | * @retval 0 Successfully got cpuset |
---|
220 | * @retval -1 The cpusetsize is invalid for the system |
---|
221 | */ |
---|
222 | bool _Scheduler_default_Get_affinity( |
---|
223 | Thread_Control *thread, |
---|
224 | size_t cpusetsize, |
---|
225 | cpu_set_t *cpuset |
---|
226 | ); |
---|
227 | |
---|
228 | /** |
---|
229 | * @brief Set affinity for the default scheduler. |
---|
230 | * |
---|
231 | * @param[in] thread The associated thread. |
---|
232 | * @param[in] cpusetsize The size of the cpuset. |
---|
233 | * @param[in] cpuset Affinity new affinity set. |
---|
234 | * |
---|
235 | * @retval 0 Successful |
---|
236 | * |
---|
237 | * This method always returns successful and does not save |
---|
238 | * the cpuset. |
---|
239 | */ |
---|
240 | bool _Scheduler_default_Set_affinity( |
---|
241 | Thread_Control *thread, |
---|
242 | size_t cpusetsize, |
---|
243 | const cpu_set_t *cpuset |
---|
244 | ); |
---|
245 | #endif |
---|
246 | |
---|
247 | /* |
---|
248 | * See also PR2174: Memory corruption with EDF scheduler and thread priority |
---|
249 | * queues. |
---|
250 | */ |
---|
251 | extern const bool _Scheduler_FIXME_thread_priority_queues_are_broken; |
---|
252 | |
---|
253 | /**@}*/ |
---|
254 | |
---|
255 | #ifdef __cplusplus |
---|
256 | } |
---|
257 | #endif |
---|
258 | |
---|
259 | #endif |
---|
260 | /* end of include file */ |
---|