source: rtems/cpukit/score/src/schedulersimplesmp.c @ 0e754fac

5
Last change on this file since 0e754fac was 0e754fac, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 21, 2016 at 12:41:19 PM

score: Delete unused scheduler ask for help X op

  • Property mode set to 100644
File size: 9.8 KB
Line 
1/**
2 * @file
3 *
4 * @brief Simple SMP Scheduler Implementation
5 *
6 * @ingroup ScoreSchedulerSMPSimple
7 */
8
9/*
10 * Copyright (c) 2013, 2016 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  Scheduler_Node          *node,
48  Thread_Control          *the_thread,
49  Priority_Control         priority
50)
51{
52  Scheduler_SMP_Node *smp_node;
53
54  smp_node = _Scheduler_SMP_Node_downcast( node );
55  _Scheduler_SMP_Node_initialize( scheduler, smp_node, the_thread, priority );
56}
57
58static void _Scheduler_simple_SMP_Do_update(
59  Scheduler_Context *context,
60  Scheduler_Node    *node,
61  Priority_Control   new_priority
62)
63{
64  Scheduler_SMP_Node *smp_node;
65
66  (void) context;
67
68  smp_node = _Scheduler_SMP_Node_downcast( node );
69  _Scheduler_SMP_Node_update_priority( smp_node, new_priority );
70}
71
72static Scheduler_Node *_Scheduler_simple_SMP_Get_highest_ready(
73  Scheduler_Context *context,
74  Scheduler_Node    *node
75)
76{
77  Scheduler_simple_SMP_Context *self =
78    _Scheduler_simple_SMP_Get_self( context );
79  Scheduler_Node *first = (Scheduler_Node *) _Chain_First( &self->Ready );
80
81  (void) node;
82
83  _Assert( &first->Node != _Chain_Tail( &self->Ready ) );
84
85  return first;
86}
87
88static void _Scheduler_simple_SMP_Move_from_scheduled_to_ready(
89  Scheduler_Context *context,
90  Scheduler_Node    *scheduled_to_ready
91)
92{
93  Scheduler_simple_SMP_Context *self =
94    _Scheduler_simple_SMP_Get_self( context );
95
96  _Chain_Extract_unprotected( &scheduled_to_ready->Node );
97  _Chain_Insert_ordered_unprotected(
98    &self->Ready,
99    &scheduled_to_ready->Node,
100    _Scheduler_SMP_Insert_priority_lifo_order
101  );
102}
103
104static void _Scheduler_simple_SMP_Move_from_ready_to_scheduled(
105  Scheduler_Context *context,
106  Scheduler_Node    *ready_to_scheduled
107)
108{
109  Scheduler_simple_SMP_Context *self =
110    _Scheduler_simple_SMP_Get_self( context );
111
112  _Chain_Extract_unprotected( &ready_to_scheduled->Node );
113  _Chain_Insert_ordered_unprotected(
114    &self->Base.Scheduled,
115    &ready_to_scheduled->Node,
116    _Scheduler_SMP_Insert_priority_fifo_order
117  );
118}
119
120static void _Scheduler_simple_SMP_Insert_ready_lifo(
121  Scheduler_Context *context,
122  Scheduler_Node    *node_to_insert
123)
124{
125  Scheduler_simple_SMP_Context *self =
126    _Scheduler_simple_SMP_Get_self( context );
127
128  _Chain_Insert_ordered_unprotected(
129    &self->Ready,
130    &node_to_insert->Node,
131    _Scheduler_SMP_Insert_priority_lifo_order
132  );
133}
134
135static void _Scheduler_simple_SMP_Insert_ready_fifo(
136  Scheduler_Context *context,
137  Scheduler_Node    *node_to_insert
138)
139{
140  Scheduler_simple_SMP_Context *self =
141    _Scheduler_simple_SMP_Get_self( context );
142
143  _Chain_Insert_ordered_unprotected(
144    &self->Ready,
145    &node_to_insert->Node,
146    _Scheduler_SMP_Insert_priority_fifo_order
147  );
148}
149
150static void _Scheduler_simple_SMP_Extract_from_ready(
151  Scheduler_Context *context,
152  Scheduler_Node    *node_to_extract
153)
154{
155  (void) context;
156
157  _Chain_Extract_unprotected( &node_to_extract->Node );
158}
159
160void _Scheduler_simple_SMP_Block(
161  const Scheduler_Control *scheduler,
162  Thread_Control          *thread,
163  Scheduler_Node          *node
164)
165{
166  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
167
168  _Scheduler_SMP_Block(
169    context,
170    thread,
171    node,
172    _Scheduler_simple_SMP_Extract_from_ready,
173    _Scheduler_simple_SMP_Get_highest_ready,
174    _Scheduler_simple_SMP_Move_from_ready_to_scheduled,
175    _Scheduler_SMP_Allocate_processor_lazy
176  );
177}
178
179static Thread_Control *_Scheduler_simple_SMP_Enqueue_ordered(
180  Scheduler_Context    *context,
181  Scheduler_Node       *node,
182  Thread_Control       *needs_help,
183  Chain_Node_order      order,
184  Scheduler_SMP_Insert  insert_ready,
185  Scheduler_SMP_Insert  insert_scheduled
186)
187{
188  return _Scheduler_SMP_Enqueue_ordered(
189    context,
190    node,
191    needs_help,
192    order,
193    insert_ready,
194    insert_scheduled,
195    _Scheduler_simple_SMP_Move_from_scheduled_to_ready,
196    _Scheduler_SMP_Get_lowest_scheduled,
197    _Scheduler_SMP_Allocate_processor_lazy
198  );
199}
200
201static Thread_Control *_Scheduler_simple_SMP_Enqueue_lifo(
202  Scheduler_Context *context,
203  Scheduler_Node    *node,
204  Thread_Control    *needs_help
205)
206{
207  return _Scheduler_simple_SMP_Enqueue_ordered(
208    context,
209    node,
210    needs_help,
211    _Scheduler_SMP_Insert_priority_lifo_order,
212    _Scheduler_simple_SMP_Insert_ready_lifo,
213    _Scheduler_SMP_Insert_scheduled_lifo
214  );
215}
216
217static Thread_Control *_Scheduler_simple_SMP_Enqueue_fifo(
218  Scheduler_Context *context,
219  Scheduler_Node    *node,
220  Thread_Control    *needs_help
221)
222{
223  return _Scheduler_simple_SMP_Enqueue_ordered(
224    context,
225    node,
226    needs_help,
227    _Scheduler_SMP_Insert_priority_fifo_order,
228    _Scheduler_simple_SMP_Insert_ready_fifo,
229    _Scheduler_SMP_Insert_scheduled_fifo
230  );
231}
232
233static Thread_Control *_Scheduler_simple_SMP_Enqueue_scheduled_ordered(
234  Scheduler_Context *context,
235  Scheduler_Node *node,
236  Chain_Node_order order,
237  Scheduler_SMP_Insert insert_ready,
238  Scheduler_SMP_Insert insert_scheduled
239)
240{
241  return _Scheduler_SMP_Enqueue_scheduled_ordered(
242    context,
243    node,
244    order,
245    _Scheduler_simple_SMP_Extract_from_ready,
246    _Scheduler_simple_SMP_Get_highest_ready,
247    insert_ready,
248    insert_scheduled,
249    _Scheduler_simple_SMP_Move_from_ready_to_scheduled,
250    _Scheduler_SMP_Allocate_processor_lazy
251  );
252}
253
254static Thread_Control *_Scheduler_simple_SMP_Enqueue_scheduled_lifo(
255  Scheduler_Context *context,
256  Scheduler_Node *node
257)
258{
259  return _Scheduler_simple_SMP_Enqueue_scheduled_ordered(
260    context,
261    node,
262    _Scheduler_SMP_Insert_priority_lifo_order,
263    _Scheduler_simple_SMP_Insert_ready_lifo,
264    _Scheduler_SMP_Insert_scheduled_lifo
265  );
266}
267
268static Thread_Control *_Scheduler_simple_SMP_Enqueue_scheduled_fifo(
269  Scheduler_Context *context,
270  Scheduler_Node *node
271)
272{
273  return _Scheduler_simple_SMP_Enqueue_scheduled_ordered(
274    context,
275    node,
276    _Scheduler_SMP_Insert_priority_fifo_order,
277    _Scheduler_simple_SMP_Insert_ready_fifo,
278    _Scheduler_SMP_Insert_scheduled_fifo
279  );
280}
281
282Thread_Control *_Scheduler_simple_SMP_Unblock(
283  const Scheduler_Control *scheduler,
284  Thread_Control          *thread,
285  Scheduler_Node          *node
286)
287{
288  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
289
290  return _Scheduler_SMP_Unblock(
291    context,
292    thread,
293    node,
294    _Scheduler_simple_SMP_Do_update,
295    _Scheduler_simple_SMP_Enqueue_fifo
296  );
297}
298
299static bool _Scheduler_simple_SMP_Do_ask_for_help(
300  Scheduler_Context *context,
301  Thread_Control    *the_thread,
302  Scheduler_Node    *node
303)
304{
305  return _Scheduler_SMP_Ask_for_help(
306    context,
307    the_thread,
308    node,
309    _Scheduler_SMP_Insert_priority_lifo_order,
310    _Scheduler_simple_SMP_Insert_ready_lifo,
311    _Scheduler_SMP_Insert_scheduled_lifo,
312    _Scheduler_simple_SMP_Move_from_scheduled_to_ready,
313    _Scheduler_SMP_Get_lowest_scheduled,
314    _Scheduler_SMP_Allocate_processor_lazy
315  );
316}
317
318void _Scheduler_simple_SMP_Update_priority(
319  const Scheduler_Control *scheduler,
320  Thread_Control          *thread,
321  Scheduler_Node          *node
322)
323{
324  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
325
326  _Scheduler_SMP_Update_priority(
327    context,
328    thread,
329    node,
330    _Scheduler_simple_SMP_Extract_from_ready,
331    _Scheduler_simple_SMP_Do_update,
332    _Scheduler_simple_SMP_Enqueue_fifo,
333    _Scheduler_simple_SMP_Enqueue_lifo,
334    _Scheduler_simple_SMP_Enqueue_scheduled_fifo,
335    _Scheduler_simple_SMP_Enqueue_scheduled_lifo,
336    _Scheduler_simple_SMP_Do_ask_for_help
337  );
338}
339
340bool _Scheduler_simple_SMP_Ask_for_help(
341  const Scheduler_Control *scheduler,
342  Thread_Control          *the_thread,
343  Scheduler_Node          *node
344)
345{
346  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
347
348  return _Scheduler_simple_SMP_Do_ask_for_help( context, the_thread, node );
349}
350
351void _Scheduler_simple_SMP_Reconsider_help_request(
352  const Scheduler_Control *scheduler,
353  Thread_Control          *the_thread,
354  Scheduler_Node          *node
355)
356{
357  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
358
359  _Scheduler_SMP_Reconsider_help_request(
360    context,
361    the_thread,
362    node,
363    _Scheduler_simple_SMP_Extract_from_ready
364  );
365}
366
367void _Scheduler_simple_SMP_Withdraw_node(
368  const Scheduler_Control *scheduler,
369  Thread_Control          *the_thread,
370  Scheduler_Node          *node,
371  Thread_Scheduler_state   next_state
372)
373{
374  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
375
376  _Scheduler_SMP_Withdraw_node(
377    context,
378    the_thread,
379    node,
380    next_state,
381    _Scheduler_simple_SMP_Extract_from_ready,
382    _Scheduler_simple_SMP_Get_highest_ready,
383    _Scheduler_simple_SMP_Move_from_ready_to_scheduled,
384    _Scheduler_SMP_Allocate_processor_lazy
385  );
386}
387
388Thread_Control *_Scheduler_simple_SMP_Yield(
389  const Scheduler_Control *scheduler,
390  Thread_Control          *thread,
391  Scheduler_Node          *node
392)
393{
394  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
395
396  return _Scheduler_SMP_Yield(
397    context,
398    thread,
399    node,
400    _Scheduler_simple_SMP_Extract_from_ready,
401    _Scheduler_simple_SMP_Enqueue_fifo,
402    _Scheduler_simple_SMP_Enqueue_scheduled_fifo
403  );
404}
Note: See TracBrowser for help on using the repository browser.