1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup RTEMSScoreSchedulerPrioritySMP |
---|
7 | * |
---|
8 | * @brief This header file provides interfaces of the |
---|
9 | * @ref RTEMSScoreSchedulerPrioritySMP which are used by the implementation |
---|
10 | * and the @ref RTEMSImplApplConfig. |
---|
11 | */ |
---|
12 | |
---|
13 | /* |
---|
14 | * Copyright (c) 2013, 2018 embedded brains GmbH. All rights reserved. |
---|
15 | * |
---|
16 | * Redistribution and use in source and binary forms, with or without |
---|
17 | * modification, are permitted provided that the following conditions |
---|
18 | * are met: |
---|
19 | * 1. Redistributions of source code must retain the above copyright |
---|
20 | * notice, this list of conditions and the following disclaimer. |
---|
21 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
22 | * notice, this list of conditions and the following disclaimer in the |
---|
23 | * documentation and/or other materials provided with the distribution. |
---|
24 | * |
---|
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
35 | * POSSIBILITY OF SUCH DAMAGE. |
---|
36 | */ |
---|
37 | |
---|
38 | #ifndef _RTEMS_SCORE_SCHEDULERPRIORITYSMP_H |
---|
39 | #define _RTEMS_SCORE_SCHEDULERPRIORITYSMP_H |
---|
40 | |
---|
41 | #include <rtems/score/scheduler.h> |
---|
42 | #include <rtems/score/schedulerpriority.h> |
---|
43 | #include <rtems/score/schedulersmp.h> |
---|
44 | |
---|
45 | #ifdef __cplusplus |
---|
46 | extern "C" { |
---|
47 | #endif /* __cplusplus */ |
---|
48 | |
---|
49 | /** |
---|
50 | * @defgroup RTEMSScoreSchedulerPrioritySMP Deterministic Priority SMP Scheduler |
---|
51 | * |
---|
52 | * @ingroup RTEMSScoreSchedulerSMP |
---|
53 | * |
---|
54 | * @brief This group contains the Deterministic Priority SMP Scheduler implementation. |
---|
55 | * |
---|
56 | * This is an implementation of the global fixed priority scheduler (G-FP). It |
---|
57 | * uses one ready chain per priority to ensure constant time insert operations. |
---|
58 | * The scheduled chain uses linear insert operations and has at most processor |
---|
59 | * count entries. Since the processor and priority count are constants all |
---|
60 | * scheduler operations complete in a bounded execution time. |
---|
61 | * |
---|
62 | * The thread preempt mode will be ignored. |
---|
63 | * |
---|
64 | * @{ |
---|
65 | */ |
---|
66 | |
---|
67 | /** |
---|
68 | * @brief Scheduler context specialization for Deterministic Priority SMP |
---|
69 | * schedulers. |
---|
70 | */ |
---|
71 | typedef struct { |
---|
72 | Scheduler_SMP_Context Base; |
---|
73 | Chain_Control *idle_ready_queue; |
---|
74 | Priority_bit_map_Control Bit_map; |
---|
75 | Chain_Control Ready[ RTEMS_ZERO_LENGTH_ARRAY ]; |
---|
76 | } Scheduler_priority_SMP_Context; |
---|
77 | |
---|
78 | /** |
---|
79 | * @brief Scheduler node specialization for Deterministic Priority SMP |
---|
80 | * schedulers. |
---|
81 | */ |
---|
82 | typedef struct { |
---|
83 | /** |
---|
84 | * @brief SMP scheduler node. |
---|
85 | */ |
---|
86 | Scheduler_SMP_Node Base; |
---|
87 | |
---|
88 | /** |
---|
89 | * @brief The associated ready queue of this node. |
---|
90 | */ |
---|
91 | Scheduler_priority_Ready_queue Ready_queue; |
---|
92 | } Scheduler_priority_SMP_Node; |
---|
93 | |
---|
94 | /** |
---|
95 | * @brief Entry points for the Priority SMP Scheduler. |
---|
96 | */ |
---|
97 | #define SCHEDULER_PRIORITY_SMP_ENTRY_POINTS \ |
---|
98 | { \ |
---|
99 | _Scheduler_priority_SMP_Initialize, \ |
---|
100 | _Scheduler_default_Schedule, \ |
---|
101 | _Scheduler_priority_SMP_Yield, \ |
---|
102 | _Scheduler_priority_SMP_Block, \ |
---|
103 | _Scheduler_priority_SMP_Unblock, \ |
---|
104 | _Scheduler_priority_SMP_Update_priority, \ |
---|
105 | _Scheduler_default_Map_priority, \ |
---|
106 | _Scheduler_default_Unmap_priority, \ |
---|
107 | _Scheduler_priority_SMP_Ask_for_help, \ |
---|
108 | _Scheduler_priority_SMP_Reconsider_help_request, \ |
---|
109 | _Scheduler_priority_SMP_Withdraw_node, \ |
---|
110 | _Scheduler_priority_SMP_Make_sticky, \ |
---|
111 | _Scheduler_priority_SMP_Clean_sticky, \ |
---|
112 | _Scheduler_default_Pin_or_unpin_not_supported, \ |
---|
113 | _Scheduler_default_Pin_or_unpin_not_supported, \ |
---|
114 | _Scheduler_priority_SMP_Add_processor, \ |
---|
115 | _Scheduler_priority_SMP_Remove_processor, \ |
---|
116 | _Scheduler_priority_SMP_Node_initialize, \ |
---|
117 | _Scheduler_default_Node_destroy, \ |
---|
118 | _Scheduler_default_Release_job, \ |
---|
119 | _Scheduler_default_Cancel_job, \ |
---|
120 | _Scheduler_SMP_Start_idle \ |
---|
121 | SCHEDULER_DEFAULT_SET_AFFINITY_OPERATION \ |
---|
122 | } |
---|
123 | |
---|
124 | /** |
---|
125 | * @brief Initializes the priority SMP scheduler. |
---|
126 | * |
---|
127 | * This routine initializes the priority SMP scheduler. |
---|
128 | * |
---|
129 | * @param scheduler The scheduler to initialize. |
---|
130 | */ |
---|
131 | void _Scheduler_priority_SMP_Initialize( const Scheduler_Control *scheduler ); |
---|
132 | |
---|
133 | /** |
---|
134 | * @brief Initializes the node with the given priority. |
---|
135 | * |
---|
136 | * @param scheduler The scheduler instance. |
---|
137 | * @param[out] node The node to initialize. |
---|
138 | * @param the_thread The thread of the scheduler node. |
---|
139 | * @param priority The priority for the initialization. |
---|
140 | */ |
---|
141 | void _Scheduler_priority_SMP_Node_initialize( |
---|
142 | const Scheduler_Control *scheduler, |
---|
143 | Scheduler_Node *node, |
---|
144 | Thread_Control *the_thread, |
---|
145 | Priority_Control priority |
---|
146 | ); |
---|
147 | |
---|
148 | /** |
---|
149 | * @brief Blocks the thread. |
---|
150 | * |
---|
151 | * @param scheduler The scheduler instance. |
---|
152 | * @param[in, out] the_thread The thread to block. |
---|
153 | * @param[in, out] node The @a thread's scheduler node. |
---|
154 | */ |
---|
155 | void _Scheduler_priority_SMP_Block( |
---|
156 | const Scheduler_Control *scheduler, |
---|
157 | Thread_Control *thread, |
---|
158 | Scheduler_Node *node |
---|
159 | ); |
---|
160 | |
---|
161 | /** |
---|
162 | * @brief Unblocks the thread. |
---|
163 | * |
---|
164 | * @param scheduler The scheduler instance. |
---|
165 | * @param[in, out] the_thread The thread to unblock. |
---|
166 | * @param[in, out] node The @a thread's scheduler node. |
---|
167 | */ |
---|
168 | void _Scheduler_priority_SMP_Unblock( |
---|
169 | const Scheduler_Control *scheduler, |
---|
170 | Thread_Control *thread, |
---|
171 | Scheduler_Node *node |
---|
172 | ); |
---|
173 | |
---|
174 | /** |
---|
175 | * @brief Updates the priority of the node. |
---|
176 | * |
---|
177 | * @param scheduler The scheduler instance. |
---|
178 | * @param the_thread The thread for the operation. |
---|
179 | * @param base_node The thread's scheduler node. |
---|
180 | */ |
---|
181 | void _Scheduler_priority_SMP_Update_priority( |
---|
182 | const Scheduler_Control *scheduler, |
---|
183 | Thread_Control *the_thread, |
---|
184 | Scheduler_Node *node |
---|
185 | ); |
---|
186 | |
---|
187 | /** |
---|
188 | * @brief Asks for help operation. |
---|
189 | * |
---|
190 | * @param scheduler The scheduler instance to ask for help. |
---|
191 | * @param the_thread The thread needing help. |
---|
192 | * @param node The scheduler node. |
---|
193 | * |
---|
194 | * @retval true Ask for help was successful. |
---|
195 | * @retval false Ask for help was not successful. |
---|
196 | */ |
---|
197 | bool _Scheduler_priority_SMP_Ask_for_help( |
---|
198 | const Scheduler_Control *scheduler, |
---|
199 | Thread_Control *the_thread, |
---|
200 | Scheduler_Node *node |
---|
201 | ); |
---|
202 | |
---|
203 | /** |
---|
204 | * @brief Reconsiders help operation. |
---|
205 | * |
---|
206 | * @param scheduler The scheduler instance to reconsider the help |
---|
207 | * request. |
---|
208 | * @param the_thread The thread reconsidering a help request. |
---|
209 | * @param node The scheduler node. |
---|
210 | */ |
---|
211 | void _Scheduler_priority_SMP_Reconsider_help_request( |
---|
212 | const Scheduler_Control *scheduler, |
---|
213 | Thread_Control *the_thread, |
---|
214 | Scheduler_Node *node |
---|
215 | ); |
---|
216 | |
---|
217 | /** |
---|
218 | * @brief Withdraws node operation. |
---|
219 | * |
---|
220 | * @param scheduler The scheduler instance to withdraw the node. |
---|
221 | * @param the_thread The thread using the node. |
---|
222 | * @param node The scheduler node to withdraw. |
---|
223 | * @param next_state The next thread scheduler state in case the node is |
---|
224 | * scheduled. |
---|
225 | */ |
---|
226 | void _Scheduler_priority_SMP_Withdraw_node( |
---|
227 | const Scheduler_Control *scheduler, |
---|
228 | Thread_Control *the_thread, |
---|
229 | Scheduler_Node *node, |
---|
230 | Thread_Scheduler_state next_state |
---|
231 | ); |
---|
232 | |
---|
233 | /** |
---|
234 | * @brief Makes the node sticky. |
---|
235 | * |
---|
236 | * @param scheduler is the scheduler of the node. |
---|
237 | * |
---|
238 | * @param[in, out] the_thread is the thread owning the node. |
---|
239 | * |
---|
240 | * @param[in, out] node is the scheduler node to make sticky. |
---|
241 | */ |
---|
242 | void _Scheduler_priority_SMP_Make_sticky( |
---|
243 | const Scheduler_Control *scheduler, |
---|
244 | Thread_Control *the_thread, |
---|
245 | Scheduler_Node *node |
---|
246 | ); |
---|
247 | |
---|
248 | /** |
---|
249 | * @brief Cleans the sticky property from the node. |
---|
250 | * |
---|
251 | * @param scheduler is the scheduler of the node. |
---|
252 | * |
---|
253 | * @param[in, out] the_thread is the thread owning the node. |
---|
254 | * |
---|
255 | * @param[in, out] node is the scheduler node to clean the sticky property. |
---|
256 | */ |
---|
257 | void _Scheduler_priority_SMP_Clean_sticky( |
---|
258 | const Scheduler_Control *scheduler, |
---|
259 | Thread_Control *the_thread, |
---|
260 | Scheduler_Node *node |
---|
261 | ); |
---|
262 | |
---|
263 | /** |
---|
264 | * @brief Adds @a idle to @a scheduler. |
---|
265 | * |
---|
266 | * @param[in, out] scheduler The scheduler instance to add the processor to. |
---|
267 | * @param idle The idle thrad control. |
---|
268 | */ |
---|
269 | void _Scheduler_priority_SMP_Add_processor( |
---|
270 | const Scheduler_Control *scheduler, |
---|
271 | Thread_Control *idle |
---|
272 | ); |
---|
273 | |
---|
274 | /** |
---|
275 | * @brief Removes an idle thread from the given cpu. |
---|
276 | * |
---|
277 | * @param scheduler The scheduler instance. |
---|
278 | * @param cpu The cpu control to remove from @a scheduler. |
---|
279 | * |
---|
280 | * @return The idle thread of the processor. |
---|
281 | */ |
---|
282 | Thread_Control *_Scheduler_priority_SMP_Remove_processor( |
---|
283 | const Scheduler_Control *scheduler, |
---|
284 | struct Per_CPU_Control *cpu |
---|
285 | ); |
---|
286 | |
---|
287 | /** |
---|
288 | * @brief Performs the yield of a thread. |
---|
289 | * |
---|
290 | * @param scheduler The scheduler instance. |
---|
291 | * @param[in, out] the_thread The thread that performed the yield operation. |
---|
292 | * @param node The scheduler node of @a the_thread. |
---|
293 | */ |
---|
294 | void _Scheduler_priority_SMP_Yield( |
---|
295 | const Scheduler_Control *scheduler, |
---|
296 | Thread_Control *thread, |
---|
297 | Scheduler_Node *node |
---|
298 | ); |
---|
299 | |
---|
300 | /** @} */ |
---|
301 | |
---|
302 | #ifdef __cplusplus |
---|
303 | } |
---|
304 | #endif /* __cplusplus */ |
---|
305 | |
---|
306 | #endif /* _RTEMS_SCORE_SCHEDULERPRIORITYSMP_H */ |
---|