source: rtems/cpukit/score/src/schedulersimplesmp.c @ 333f942

4.115
Last change on this file since 333f942 was 333f942, checked in by Sebastian Huber <sebastian.huber@…>, on 07/10/14 at 10:49:43

score: Fix assertions

  • Property mode set to 100644
File size: 9.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Simple SMP Scheduler Implementation
5 *
6 * @ingroup ScoreSchedulerSMPSimple
7 */
8
9/*
10 * Copyright (c) 2013-2014 embedded brains GmbH.
11 *
12 * The license and distribution terms for this file may be
13 * found in the file LICENSE in this distribution or at
14 * http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18  #include "config.h"
19#endif
20
21#include <rtems/score/schedulersimplesmp.h>
22#include <rtems/score/schedulersmpimpl.h>
23
24static Scheduler_simple_SMP_Context *
25_Scheduler_simple_SMP_Get_context( const Scheduler_Control *scheduler )
26{
27  return (Scheduler_simple_SMP_Context *) _Scheduler_Get_context( scheduler );
28}
29
30static Scheduler_simple_SMP_Context *
31_Scheduler_simple_SMP_Get_self( Scheduler_Context *context )
32{
33  return (Scheduler_simple_SMP_Context *) context;
34}
35
36void _Scheduler_simple_SMP_Initialize( const Scheduler_Control *scheduler )
37{
38  Scheduler_simple_SMP_Context *self =
39    _Scheduler_simple_SMP_Get_context( scheduler );
40
41  _Scheduler_SMP_Initialize( &self->Base );
42  _Chain_Initialize_empty( &self->Ready );
43}
44
45void _Scheduler_simple_SMP_Node_initialize(
46  const Scheduler_Control *scheduler,
47  Thread_Control          *the_thread
48)
49{
50  Scheduler_SMP_Node *node = _Scheduler_SMP_Thread_get_own_node( the_thread );
51
52  _Scheduler_SMP_Node_initialize( node, the_thread );
53}
54
55static void _Scheduler_simple_SMP_Do_update(
56  Scheduler_Context *context,
57  Scheduler_Node    *node_to_update,
58  Priority_Control   new_priority
59)
60{
61  Scheduler_SMP_Node *node = _Scheduler_SMP_Node_downcast( node_to_update );
62
63  (void) context;
64
65  _Scheduler_SMP_Node_update_priority( node, new_priority );
66}
67
68void _Scheduler_simple_SMP_Update_priority(
69  const Scheduler_Control *scheduler,
70  Thread_Control          *thread,
71  Priority_Control         new_priority
72)
73{
74  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
75  Scheduler_Node *node = _Scheduler_Thread_get_node( thread );
76
77  _Scheduler_simple_SMP_Do_update( context, node, new_priority );
78}
79
80static Scheduler_Node *_Scheduler_simple_SMP_Get_highest_ready(
81  Scheduler_Context *context,
82  Scheduler_Node    *node
83)
84{
85  Scheduler_simple_SMP_Context *self =
86    _Scheduler_simple_SMP_Get_self( context );
87  Scheduler_Node *first = (Scheduler_Node *) _Chain_First( &self->Ready );
88
89  (void) node;
90
91  _Assert( &first->Node != _Chain_Tail( &self->Ready ) );
92
93  return first;
94}
95
96static void _Scheduler_simple_SMP_Move_from_scheduled_to_ready(
97  Scheduler_Context *context,
98  Scheduler_Node    *scheduled_to_ready
99)
100{
101  Scheduler_simple_SMP_Context *self =
102    _Scheduler_simple_SMP_Get_self( context );
103
104  _Chain_Extract_unprotected( &scheduled_to_ready->Node );
105  _Chain_Insert_ordered_unprotected(
106    &self->Ready,
107    &scheduled_to_ready->Node,
108    _Scheduler_SMP_Insert_priority_lifo_order
109  );
110}
111
112static void _Scheduler_simple_SMP_Move_from_ready_to_scheduled(
113  Scheduler_Context *context,
114  Scheduler_Node    *ready_to_scheduled
115)
116{
117  Scheduler_simple_SMP_Context *self =
118    _Scheduler_simple_SMP_Get_self( context );
119
120  _Chain_Extract_unprotected( &ready_to_scheduled->Node );
121  _Chain_Insert_ordered_unprotected(
122    &self->Base.Scheduled,
123    &ready_to_scheduled->Node,
124    _Scheduler_SMP_Insert_priority_fifo_order
125  );
126}
127
128static void _Scheduler_simple_SMP_Insert_ready_lifo(
129  Scheduler_Context *context,
130  Scheduler_Node    *node_to_insert
131)
132{
133  Scheduler_simple_SMP_Context *self =
134    _Scheduler_simple_SMP_Get_self( context );
135
136  _Chain_Insert_ordered_unprotected(
137    &self->Ready,
138    &node_to_insert->Node,
139    _Scheduler_SMP_Insert_priority_lifo_order
140  );
141}
142
143static void _Scheduler_simple_SMP_Insert_ready_fifo(
144  Scheduler_Context *context,
145  Scheduler_Node    *node_to_insert
146)
147{
148  Scheduler_simple_SMP_Context *self =
149    _Scheduler_simple_SMP_Get_self( context );
150
151  _Chain_Insert_ordered_unprotected(
152    &self->Ready,
153    &node_to_insert->Node,
154    _Scheduler_SMP_Insert_priority_fifo_order
155  );
156}
157
158static void _Scheduler_simple_SMP_Extract_from_ready(
159  Scheduler_Context *context,
160  Scheduler_Node    *node_to_extract
161)
162{
163  (void) context;
164
165  _Chain_Extract_unprotected( &node_to_extract->Node );
166}
167
168static Thread_Control *_Scheduler_simple_SMP_Get_idle_thread(
169  Scheduler_Context *context
170)
171{
172  return _Scheduler_SMP_Get_idle_thread(
173    context,
174    _Scheduler_simple_SMP_Extract_from_ready
175  );
176}
177
178static void _Scheduler_simple_SMP_Release_idle_thread(
179  Scheduler_Context *context,
180  Thread_Control    *idle
181)
182{
183  _Scheduler_SMP_Release_idle_thread(
184    context,
185    idle,
186    _Scheduler_simple_SMP_Insert_ready_fifo
187  );
188}
189
190void _Scheduler_simple_SMP_Block(
191  const Scheduler_Control *scheduler,
192  Thread_Control *thread
193)
194{
195  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
196
197  _Scheduler_SMP_Block(
198    context,
199    thread,
200    _Scheduler_simple_SMP_Extract_from_ready,
201    _Scheduler_simple_SMP_Get_highest_ready,
202    _Scheduler_simple_SMP_Move_from_ready_to_scheduled,
203    _Scheduler_SMP_Allocate_processor_lazy,
204    _Scheduler_simple_SMP_Get_idle_thread
205  );
206}
207
208static Thread_Control *_Scheduler_simple_SMP_Enqueue_ordered(
209  Scheduler_Context    *context,
210  Scheduler_Node       *node,
211  Thread_Control       *needs_help,
212  Chain_Node_order      order,
213  Scheduler_SMP_Insert  insert_ready,
214  Scheduler_SMP_Insert  insert_scheduled
215)
216{
217  return _Scheduler_SMP_Enqueue_ordered(
218    context,
219    node,
220    needs_help,
221    order,
222    insert_ready,
223    insert_scheduled,
224    _Scheduler_simple_SMP_Move_from_scheduled_to_ready,
225    _Scheduler_SMP_Get_lowest_scheduled,
226    _Scheduler_SMP_Allocate_processor_lazy,
227    _Scheduler_simple_SMP_Release_idle_thread
228  );
229}
230
231static Thread_Control *_Scheduler_simple_SMP_Enqueue_lifo(
232  Scheduler_Context *context,
233  Scheduler_Node    *node,
234  Thread_Control    *needs_help
235)
236{
237  return _Scheduler_simple_SMP_Enqueue_ordered(
238    context,
239    node,
240    needs_help,
241    _Scheduler_SMP_Insert_priority_lifo_order,
242    _Scheduler_simple_SMP_Insert_ready_lifo,
243    _Scheduler_SMP_Insert_scheduled_lifo
244  );
245}
246
247static Thread_Control *_Scheduler_simple_SMP_Enqueue_fifo(
248  Scheduler_Context *context,
249  Scheduler_Node    *node,
250  Thread_Control    *needs_help
251)
252{
253  return _Scheduler_simple_SMP_Enqueue_ordered(
254    context,
255    node,
256    needs_help,
257    _Scheduler_SMP_Insert_priority_fifo_order,
258    _Scheduler_simple_SMP_Insert_ready_fifo,
259    _Scheduler_SMP_Insert_scheduled_fifo
260  );
261}
262
263static Thread_Control *_Scheduler_simple_SMP_Enqueue_scheduled_ordered(
264  Scheduler_Context *context,
265  Scheduler_Node *node,
266  Chain_Node_order order,
267  Scheduler_SMP_Insert insert_ready,
268  Scheduler_SMP_Insert insert_scheduled
269)
270{
271  return _Scheduler_SMP_Enqueue_scheduled_ordered(
272    context,
273    node,
274    order,
275    _Scheduler_simple_SMP_Extract_from_ready,
276    _Scheduler_simple_SMP_Get_highest_ready,
277    insert_ready,
278    insert_scheduled,
279    _Scheduler_simple_SMP_Move_from_ready_to_scheduled,
280    _Scheduler_SMP_Allocate_processor_lazy,
281    _Scheduler_simple_SMP_Get_idle_thread,
282    _Scheduler_simple_SMP_Release_idle_thread
283  );
284}
285
286static Thread_Control *_Scheduler_simple_SMP_Enqueue_scheduled_lifo(
287  Scheduler_Context *context,
288  Scheduler_Node *node
289)
290{
291  return _Scheduler_simple_SMP_Enqueue_scheduled_ordered(
292    context,
293    node,
294    _Scheduler_SMP_Insert_priority_lifo_order,
295    _Scheduler_simple_SMP_Insert_ready_lifo,
296    _Scheduler_SMP_Insert_scheduled_lifo
297  );
298}
299
300static Thread_Control *_Scheduler_simple_SMP_Enqueue_scheduled_fifo(
301  Scheduler_Context *context,
302  Scheduler_Node *node
303)
304{
305  return _Scheduler_simple_SMP_Enqueue_scheduled_ordered(
306    context,
307    node,
308    _Scheduler_SMP_Insert_priority_fifo_order,
309    _Scheduler_simple_SMP_Insert_ready_fifo,
310    _Scheduler_SMP_Insert_scheduled_fifo
311  );
312}
313
314Thread_Control *_Scheduler_simple_SMP_Unblock(
315  const Scheduler_Control *scheduler,
316  Thread_Control *thread
317)
318{
319  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
320
321  return _Scheduler_SMP_Unblock(
322    context,
323    thread,
324    _Scheduler_simple_SMP_Enqueue_fifo,
325    _Scheduler_simple_SMP_Release_idle_thread
326  );
327}
328
329Thread_Control *_Scheduler_simple_SMP_Change_priority(
330  const Scheduler_Control *scheduler,
331  Thread_Control          *thread,
332  Priority_Control         new_priority,
333  bool                     prepend_it
334)
335{
336  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
337
338  return _Scheduler_SMP_Change_priority(
339    context,
340    thread,
341    new_priority,
342    prepend_it,
343    _Scheduler_simple_SMP_Extract_from_ready,
344    _Scheduler_simple_SMP_Do_update,
345    _Scheduler_simple_SMP_Enqueue_fifo,
346    _Scheduler_simple_SMP_Enqueue_lifo,
347    _Scheduler_simple_SMP_Enqueue_scheduled_fifo,
348    _Scheduler_simple_SMP_Enqueue_scheduled_lifo
349  );
350}
351
352Thread_Control *_Scheduler_simple_SMP_Ask_for_help(
353  const Scheduler_Control *scheduler,
354  Thread_Control          *offers_help,
355  Thread_Control          *needs_help
356)
357{
358  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
359
360  return _Scheduler_SMP_Ask_for_help(
361    context,
362    offers_help,
363    needs_help,
364    _Scheduler_simple_SMP_Enqueue_fifo,
365    _Scheduler_simple_SMP_Release_idle_thread
366  );
367}
368
369Thread_Control *_Scheduler_simple_SMP_Yield(
370  const Scheduler_Control *scheduler,
371  Thread_Control *thread
372)
373{
374  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
375
376  return _Scheduler_SMP_Yield(
377    context,
378    thread,
379    _Scheduler_simple_SMP_Extract_from_ready,
380    _Scheduler_simple_SMP_Enqueue_fifo,
381    _Scheduler_simple_SMP_Enqueue_scheduled_fifo
382  );
383}
Note: See TracBrowser for help on using the repository browser.