source: rtems/cpukit/score/src/schedulersimplesmp.c @ 3733b224

4.115
Last change on this file since 3733b224 was 3733b224, checked in by Sebastian Huber <sebastian.huber@…>, on 05/15/14 at 06:46:56

score: Add and use _Scheduler_default_Schedule()

  • Property mode set to 100644
File size: 6.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
45bool _Scheduler_simple_SMP_Allocate(
46  const Scheduler_Control *scheduler,
47  Thread_Control          *the_thread
48)
49{
50  Scheduler_SMP_Node *node = _Scheduler_SMP_Node_get( the_thread );
51
52  _Scheduler_SMP_Node_initialize( node );
53
54  return true;
55}
56
57static void _Scheduler_simple_SMP_Do_update(
58  Scheduler_Context *context,
59  Scheduler_Node *node,
60  Priority_Control new_priority
61)
62{
63  (void) context;
64  (void) node;
65  (void) new_priority;
66}
67
68static Thread_Control *_Scheduler_simple_SMP_Get_highest_ready(
69  Scheduler_Context *context
70)
71{
72  Scheduler_simple_SMP_Context *self =
73    _Scheduler_simple_SMP_Get_self( context );
74
75  return (Thread_Control *) _Chain_First( &self->Ready );
76}
77
78static void _Scheduler_simple_SMP_Move_from_scheduled_to_ready(
79  Scheduler_Context *context,
80  Thread_Control *scheduled_to_ready
81)
82{
83  Scheduler_simple_SMP_Context *self =
84    _Scheduler_simple_SMP_Get_self( context );
85
86  _Chain_Extract_unprotected( &scheduled_to_ready->Object.Node );
87  _Scheduler_simple_Insert_priority_lifo(
88    &self->Ready,
89    scheduled_to_ready
90  );
91}
92
93static void _Scheduler_simple_SMP_Move_from_ready_to_scheduled(
94  Scheduler_Context *context,
95  Thread_Control *ready_to_scheduled
96)
97{
98  Scheduler_simple_SMP_Context *self =
99    _Scheduler_simple_SMP_Get_self( context );
100
101  _Chain_Extract_unprotected( &ready_to_scheduled->Object.Node );
102  _Scheduler_simple_Insert_priority_fifo(
103    &self->Base.Scheduled,
104    ready_to_scheduled
105  );
106}
107
108static void _Scheduler_simple_SMP_Insert_ready_lifo(
109  Scheduler_Context *context,
110  Thread_Control *thread
111)
112{
113  Scheduler_simple_SMP_Context *self =
114    _Scheduler_simple_SMP_Get_self( context );
115
116  _Chain_Insert_ordered_unprotected(
117    &self->Ready,
118    &thread->Object.Node,
119    _Scheduler_simple_Insert_priority_lifo_order
120  );
121}
122
123static void _Scheduler_simple_SMP_Insert_ready_fifo(
124  Scheduler_Context *context,
125  Thread_Control *thread
126)
127{
128  Scheduler_simple_SMP_Context *self =
129    _Scheduler_simple_SMP_Get_self( context );
130
131  _Chain_Insert_ordered_unprotected(
132    &self->Ready,
133    &thread->Object.Node,
134    _Scheduler_simple_Insert_priority_fifo_order
135  );
136}
137
138static void _Scheduler_simple_SMP_Extract_from_ready(
139  Scheduler_Context *context,
140  Thread_Control *thread
141)
142{
143  (void) context;
144
145  _Chain_Extract_unprotected( &thread->Object.Node );
146}
147
148void _Scheduler_simple_SMP_Block(
149  const Scheduler_Control *scheduler,
150  Thread_Control *thread
151)
152{
153  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
154
155  _Scheduler_SMP_Block(
156    context,
157    thread,
158    _Scheduler_simple_SMP_Extract_from_ready,
159    _Scheduler_simple_SMP_Get_highest_ready,
160    _Scheduler_simple_SMP_Move_from_ready_to_scheduled
161  );
162}
163
164static void _Scheduler_simple_SMP_Enqueue_ordered(
165  Scheduler_Context *context,
166  Thread_Control *thread,
167  bool has_processor_allocated,
168  Chain_Node_order order,
169  Scheduler_SMP_Insert insert_ready,
170  Scheduler_SMP_Insert insert_scheduled
171)
172{
173  _Scheduler_SMP_Enqueue_ordered(
174    context,
175    thread,
176    has_processor_allocated,
177    order,
178    _Scheduler_simple_SMP_Get_highest_ready,
179    insert_ready,
180    insert_scheduled,
181    _Scheduler_simple_SMP_Move_from_ready_to_scheduled,
182    _Scheduler_simple_SMP_Move_from_scheduled_to_ready
183  );
184}
185
186static void _Scheduler_simple_SMP_Enqueue_lifo(
187  Scheduler_Context *context,
188  Thread_Control *thread,
189  bool has_processor_allocated
190)
191{
192  _Scheduler_simple_SMP_Enqueue_ordered(
193    context,
194    thread,
195    has_processor_allocated,
196    _Scheduler_simple_Insert_priority_lifo_order,
197    _Scheduler_simple_SMP_Insert_ready_lifo,
198    _Scheduler_SMP_Insert_scheduled_lifo
199  );
200}
201
202static void _Scheduler_simple_SMP_Enqueue_fifo(
203  Scheduler_Context *context,
204  Thread_Control *thread,
205  bool has_processor_allocated
206)
207{
208  _Scheduler_simple_SMP_Enqueue_ordered(
209    context,
210    thread,
211    has_processor_allocated,
212    _Scheduler_simple_Insert_priority_fifo_order,
213    _Scheduler_simple_SMP_Insert_ready_fifo,
214    _Scheduler_SMP_Insert_scheduled_fifo
215  );
216}
217
218void _Scheduler_simple_SMP_Unblock(
219  const Scheduler_Control *scheduler,
220  Thread_Control *thread
221)
222{
223  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
224
225  _Scheduler_simple_SMP_Enqueue_fifo( context, thread, false );
226}
227
228void _Scheduler_simple_SMP_Change_priority(
229  const Scheduler_Control *scheduler,
230  Thread_Control          *thread,
231  Priority_Control         new_priority,
232  bool                     prepend_it
233)
234{
235  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
236
237  _Scheduler_SMP_Change_priority(
238    context,
239    thread,
240    new_priority,
241    prepend_it,
242    _Scheduler_simple_SMP_Extract_from_ready,
243    _Scheduler_simple_SMP_Do_update,
244    _Scheduler_simple_SMP_Enqueue_fifo,
245    _Scheduler_simple_SMP_Enqueue_lifo
246  );
247}
248
249void _Scheduler_simple_SMP_Yield(
250  const Scheduler_Control *scheduler,
251  Thread_Control *thread
252)
253{
254  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
255  ISR_Level level;
256
257  _ISR_Disable( level );
258
259  _Scheduler_SMP_Extract_from_scheduled( thread );
260  _Scheduler_simple_SMP_Enqueue_fifo( context, thread, true );
261
262  _ISR_Enable( level );
263}
264
265void _Scheduler_simple_SMP_Start_idle(
266  const Scheduler_Control *scheduler,
267  Thread_Control *thread,
268  Per_CPU_Control *cpu
269)
270{
271  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
272
273  _Scheduler_SMP_Start_idle( context, thread, cpu );
274}
Note: See TracBrowser for help on using the repository browser.