1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup ScoreSchedulerPrioritySMP |
---|
5 | * |
---|
6 | * @brief Deterministic Priority SMP Scheduler Implementation |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2013-2014 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Dornierstr. 4 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <rtems@embedded-brains.de> |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.org/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #if HAVE_CONFIG_H |
---|
24 | #include "config.h" |
---|
25 | #endif |
---|
26 | |
---|
27 | #include <rtems/score/schedulerprioritysmpimpl.h> |
---|
28 | |
---|
29 | static Scheduler_priority_SMP_Context * |
---|
30 | _Scheduler_priority_SMP_Get_context( const Scheduler_Control *scheduler ) |
---|
31 | { |
---|
32 | return (Scheduler_priority_SMP_Context *) _Scheduler_Get_context( scheduler ); |
---|
33 | } |
---|
34 | |
---|
35 | void _Scheduler_priority_SMP_Initialize( const Scheduler_Control *scheduler ) |
---|
36 | { |
---|
37 | Scheduler_priority_SMP_Context *self = |
---|
38 | _Scheduler_priority_SMP_Get_context( scheduler ); |
---|
39 | |
---|
40 | _Scheduler_SMP_Initialize( &self->Base ); |
---|
41 | _Priority_bit_map_Initialize( &self->Bit_map ); |
---|
42 | _Scheduler_priority_Ready_queue_initialize( &self->Ready[ 0 ] ); |
---|
43 | } |
---|
44 | |
---|
45 | void _Scheduler_priority_SMP_Node_initialize( |
---|
46 | const Scheduler_Control *scheduler, |
---|
47 | Thread_Control *thread |
---|
48 | ) |
---|
49 | { |
---|
50 | Scheduler_SMP_Node *node = _Scheduler_SMP_Thread_get_own_node( thread ); |
---|
51 | |
---|
52 | _Scheduler_SMP_Node_initialize( node, thread ); |
---|
53 | } |
---|
54 | |
---|
55 | void _Scheduler_priority_SMP_Update_priority( |
---|
56 | const Scheduler_Control *scheduler, |
---|
57 | Thread_Control *thread, |
---|
58 | Priority_Control new_priority |
---|
59 | ) |
---|
60 | { |
---|
61 | Scheduler_Context *context = _Scheduler_Get_context( scheduler ); |
---|
62 | Scheduler_Node *node = _Scheduler_Thread_get_node( thread ); |
---|
63 | |
---|
64 | _Scheduler_priority_SMP_Do_update( context, node, new_priority ); |
---|
65 | } |
---|
66 | |
---|
67 | static Scheduler_Node *_Scheduler_priority_SMP_Get_highest_ready( |
---|
68 | Scheduler_Context *context, |
---|
69 | Scheduler_Node *node |
---|
70 | ) |
---|
71 | { |
---|
72 | Scheduler_priority_SMP_Context *self = |
---|
73 | _Scheduler_priority_SMP_Get_self( context ); |
---|
74 | |
---|
75 | (void) node; |
---|
76 | |
---|
77 | return (Scheduler_Node *) _Scheduler_priority_Ready_queue_first( |
---|
78 | &self->Bit_map, |
---|
79 | &self->Ready[ 0 ] |
---|
80 | ); |
---|
81 | } |
---|
82 | |
---|
83 | void _Scheduler_priority_SMP_Block( |
---|
84 | const Scheduler_Control *scheduler, |
---|
85 | Thread_Control *thread |
---|
86 | ) |
---|
87 | { |
---|
88 | Scheduler_Context *context = _Scheduler_Get_context( scheduler ); |
---|
89 | |
---|
90 | _Scheduler_SMP_Block( |
---|
91 | context, |
---|
92 | thread, |
---|
93 | _Scheduler_priority_SMP_Extract_from_ready, |
---|
94 | _Scheduler_priority_SMP_Get_highest_ready, |
---|
95 | _Scheduler_priority_SMP_Move_from_ready_to_scheduled, |
---|
96 | _Scheduler_SMP_Allocate_processor_lazy |
---|
97 | ); |
---|
98 | } |
---|
99 | |
---|
100 | static Thread_Control *_Scheduler_priority_SMP_Enqueue_ordered( |
---|
101 | Scheduler_Context *context, |
---|
102 | Scheduler_Node *node, |
---|
103 | Thread_Control *needs_help, |
---|
104 | Chain_Node_order order, |
---|
105 | Scheduler_SMP_Insert insert_ready, |
---|
106 | Scheduler_SMP_Insert insert_scheduled |
---|
107 | ) |
---|
108 | { |
---|
109 | return _Scheduler_SMP_Enqueue_ordered( |
---|
110 | context, |
---|
111 | node, |
---|
112 | needs_help, |
---|
113 | order, |
---|
114 | insert_ready, |
---|
115 | insert_scheduled, |
---|
116 | _Scheduler_priority_SMP_Move_from_scheduled_to_ready, |
---|
117 | _Scheduler_SMP_Get_lowest_scheduled, |
---|
118 | _Scheduler_SMP_Allocate_processor_lazy |
---|
119 | ); |
---|
120 | } |
---|
121 | |
---|
122 | static Thread_Control *_Scheduler_priority_SMP_Enqueue_lifo( |
---|
123 | Scheduler_Context *context, |
---|
124 | Scheduler_Node *node, |
---|
125 | Thread_Control *needs_help |
---|
126 | ) |
---|
127 | { |
---|
128 | return _Scheduler_priority_SMP_Enqueue_ordered( |
---|
129 | context, |
---|
130 | node, |
---|
131 | needs_help, |
---|
132 | _Scheduler_SMP_Insert_priority_lifo_order, |
---|
133 | _Scheduler_priority_SMP_Insert_ready_lifo, |
---|
134 | _Scheduler_SMP_Insert_scheduled_lifo |
---|
135 | ); |
---|
136 | } |
---|
137 | |
---|
138 | static Thread_Control *_Scheduler_priority_SMP_Enqueue_fifo( |
---|
139 | Scheduler_Context *context, |
---|
140 | Scheduler_Node *node, |
---|
141 | Thread_Control *needs_help |
---|
142 | ) |
---|
143 | { |
---|
144 | return _Scheduler_priority_SMP_Enqueue_ordered( |
---|
145 | context, |
---|
146 | node, |
---|
147 | needs_help, |
---|
148 | _Scheduler_SMP_Insert_priority_fifo_order, |
---|
149 | _Scheduler_priority_SMP_Insert_ready_fifo, |
---|
150 | _Scheduler_SMP_Insert_scheduled_fifo |
---|
151 | ); |
---|
152 | } |
---|
153 | |
---|
154 | static Thread_Control *_Scheduler_priority_SMP_Enqueue_scheduled_ordered( |
---|
155 | Scheduler_Context *context, |
---|
156 | Scheduler_Node *node, |
---|
157 | Chain_Node_order order, |
---|
158 | Scheduler_SMP_Insert insert_ready, |
---|
159 | Scheduler_SMP_Insert insert_scheduled |
---|
160 | ) |
---|
161 | { |
---|
162 | return _Scheduler_SMP_Enqueue_scheduled_ordered( |
---|
163 | context, |
---|
164 | node, |
---|
165 | order, |
---|
166 | _Scheduler_priority_SMP_Extract_from_ready, |
---|
167 | _Scheduler_priority_SMP_Get_highest_ready, |
---|
168 | insert_ready, |
---|
169 | insert_scheduled, |
---|
170 | _Scheduler_priority_SMP_Move_from_ready_to_scheduled, |
---|
171 | _Scheduler_SMP_Allocate_processor_lazy |
---|
172 | ); |
---|
173 | } |
---|
174 | |
---|
175 | static Thread_Control *_Scheduler_priority_SMP_Enqueue_scheduled_lifo( |
---|
176 | Scheduler_Context *context, |
---|
177 | Scheduler_Node *node |
---|
178 | ) |
---|
179 | { |
---|
180 | return _Scheduler_priority_SMP_Enqueue_scheduled_ordered( |
---|
181 | context, |
---|
182 | node, |
---|
183 | _Scheduler_SMP_Insert_priority_lifo_order, |
---|
184 | _Scheduler_priority_SMP_Insert_ready_lifo, |
---|
185 | _Scheduler_SMP_Insert_scheduled_lifo |
---|
186 | ); |
---|
187 | } |
---|
188 | |
---|
189 | static Thread_Control *_Scheduler_priority_SMP_Enqueue_scheduled_fifo( |
---|
190 | Scheduler_Context *context, |
---|
191 | Scheduler_Node *node |
---|
192 | ) |
---|
193 | { |
---|
194 | return _Scheduler_priority_SMP_Enqueue_scheduled_ordered( |
---|
195 | context, |
---|
196 | node, |
---|
197 | _Scheduler_SMP_Insert_priority_fifo_order, |
---|
198 | _Scheduler_priority_SMP_Insert_ready_fifo, |
---|
199 | _Scheduler_SMP_Insert_scheduled_fifo |
---|
200 | ); |
---|
201 | } |
---|
202 | |
---|
203 | Thread_Control *_Scheduler_priority_SMP_Unblock( |
---|
204 | const Scheduler_Control *scheduler, |
---|
205 | Thread_Control *thread |
---|
206 | ) |
---|
207 | { |
---|
208 | Scheduler_Context *context = _Scheduler_Get_context( scheduler ); |
---|
209 | |
---|
210 | return _Scheduler_SMP_Unblock( |
---|
211 | context, |
---|
212 | thread, |
---|
213 | _Scheduler_priority_SMP_Enqueue_fifo |
---|
214 | ); |
---|
215 | } |
---|
216 | |
---|
217 | Thread_Control *_Scheduler_priority_SMP_Change_priority( |
---|
218 | const Scheduler_Control *scheduler, |
---|
219 | Thread_Control *thread, |
---|
220 | Priority_Control new_priority, |
---|
221 | bool prepend_it |
---|
222 | ) |
---|
223 | { |
---|
224 | Scheduler_Context *context = _Scheduler_Get_context( scheduler ); |
---|
225 | |
---|
226 | return _Scheduler_SMP_Change_priority( |
---|
227 | context, |
---|
228 | thread, |
---|
229 | new_priority, |
---|
230 | prepend_it, |
---|
231 | _Scheduler_priority_SMP_Extract_from_ready, |
---|
232 | _Scheduler_priority_SMP_Do_update, |
---|
233 | _Scheduler_priority_SMP_Enqueue_fifo, |
---|
234 | _Scheduler_priority_SMP_Enqueue_lifo, |
---|
235 | _Scheduler_priority_SMP_Enqueue_scheduled_fifo, |
---|
236 | _Scheduler_priority_SMP_Enqueue_scheduled_lifo |
---|
237 | ); |
---|
238 | } |
---|
239 | |
---|
240 | Thread_Control *_Scheduler_priority_SMP_Ask_for_help( |
---|
241 | const Scheduler_Control *scheduler, |
---|
242 | Thread_Control *offers_help, |
---|
243 | Thread_Control *needs_help |
---|
244 | ) |
---|
245 | { |
---|
246 | Scheduler_Context *context = _Scheduler_Get_context( scheduler ); |
---|
247 | |
---|
248 | return _Scheduler_SMP_Ask_for_help( |
---|
249 | context, |
---|
250 | offers_help, |
---|
251 | needs_help, |
---|
252 | _Scheduler_priority_SMP_Enqueue_fifo |
---|
253 | ); |
---|
254 | } |
---|
255 | |
---|
256 | Thread_Control *_Scheduler_priority_SMP_Yield( |
---|
257 | const Scheduler_Control *scheduler, |
---|
258 | Thread_Control *thread |
---|
259 | ) |
---|
260 | { |
---|
261 | Scheduler_Context *context = _Scheduler_Get_context( scheduler ); |
---|
262 | |
---|
263 | return _Scheduler_SMP_Yield( |
---|
264 | context, |
---|
265 | thread, |
---|
266 | _Scheduler_priority_SMP_Extract_from_ready, |
---|
267 | _Scheduler_priority_SMP_Enqueue_fifo, |
---|
268 | _Scheduler_priority_SMP_Enqueue_scheduled_fifo |
---|
269 | ); |
---|
270 | } |
---|