source: rtems/cpukit/score/src/schedulerstrongapa.c @ 9c238e1

5
Last change on this file since 9c238e1 was 9c238e1, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 21, 2016 at 12:33:01 PM

score: Simplify update priority scheduler op

Remove unused return status.

  • Property mode set to 100644
File size: 11.8 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ScoreSchedulerStrongAPA
5 *
6 * @brief Strong APA Scheduler Implementation
7 */
8
9/*
10 * Copyright (c) 2013, 2016 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/schedulerstrongapa.h>
28#include <rtems/score/schedulerpriorityimpl.h>
29#include <rtems/score/schedulersmpimpl.h>
30
31static Scheduler_strong_APA_Context *_Scheduler_strong_APA_Get_self(
32  Scheduler_Context *context
33)
34{
35  return (Scheduler_strong_APA_Context *) context;
36}
37
38static Scheduler_strong_APA_Node *
39_Scheduler_strong_APA_Node_downcast( Scheduler_Node *node )
40{
41  return (Scheduler_strong_APA_Node *) node;
42}
43
44static void _Scheduler_strong_APA_Move_from_scheduled_to_ready(
45  Scheduler_Context *context,
46  Scheduler_Node    *scheduled_to_ready
47)
48{
49  Scheduler_strong_APA_Context *self =
50    _Scheduler_strong_APA_Get_self( context );
51  Scheduler_strong_APA_Node *node =
52    _Scheduler_strong_APA_Node_downcast( scheduled_to_ready );
53
54  _Chain_Extract_unprotected( &node->Base.Base.Node );
55  _Scheduler_priority_Ready_queue_enqueue_first(
56    &node->Base.Base.Node,
57    &node->Ready_queue,
58    &self->Bit_map
59  );
60}
61
62static void _Scheduler_strong_APA_Move_from_ready_to_scheduled(
63  Scheduler_Context *context,
64  Scheduler_Node    *ready_to_scheduled
65)
66{
67  Scheduler_strong_APA_Context *self =
68    _Scheduler_strong_APA_Get_self( context );
69  Scheduler_strong_APA_Node *node =
70    _Scheduler_strong_APA_Node_downcast( ready_to_scheduled );
71
72  _Scheduler_priority_Ready_queue_extract(
73    &node->Base.Base.Node,
74    &node->Ready_queue,
75    &self->Bit_map
76  );
77  _Chain_Insert_ordered_unprotected(
78    &self->Base.Scheduled,
79    &node->Base.Base.Node,
80    _Scheduler_SMP_Insert_priority_fifo_order
81  );
82}
83
84static void _Scheduler_strong_APA_Insert_ready_lifo(
85  Scheduler_Context *context,
86  Scheduler_Node    *the_thread
87)
88{
89  Scheduler_strong_APA_Context *self =
90    _Scheduler_strong_APA_Get_self( context );
91  Scheduler_strong_APA_Node *node =
92    _Scheduler_strong_APA_Node_downcast( the_thread );
93
94  _Scheduler_priority_Ready_queue_enqueue(
95    &node->Base.Base.Node,
96    &node->Ready_queue,
97    &self->Bit_map
98  );
99}
100
101static void _Scheduler_strong_APA_Insert_ready_fifo(
102  Scheduler_Context *context,
103  Scheduler_Node    *the_thread
104)
105{
106  Scheduler_strong_APA_Context *self =
107    _Scheduler_strong_APA_Get_self( context );
108  Scheduler_strong_APA_Node *node =
109    _Scheduler_strong_APA_Node_downcast( the_thread );
110
111  _Scheduler_priority_Ready_queue_enqueue_first(
112    &node->Base.Base.Node,
113    &node->Ready_queue,
114    &self->Bit_map
115  );
116}
117
118static void _Scheduler_strong_APA_Extract_from_ready(
119  Scheduler_Context *context,
120  Scheduler_Node    *the_thread
121)
122{
123  Scheduler_strong_APA_Context *self =
124    _Scheduler_strong_APA_Get_self( context );
125  Scheduler_strong_APA_Node *node =
126    _Scheduler_strong_APA_Node_downcast( the_thread );
127
128  _Scheduler_priority_Ready_queue_extract(
129    &node->Base.Base.Node,
130    &node->Ready_queue,
131    &self->Bit_map
132  );
133}
134
135static void _Scheduler_strong_APA_Do_update(
136  Scheduler_Context *context,
137  Scheduler_Node *node_to_update,
138  Priority_Control new_priority
139)
140{
141  Scheduler_strong_APA_Context *self =
142    _Scheduler_strong_APA_Get_self( context );
143  Scheduler_strong_APA_Node *node =
144    _Scheduler_strong_APA_Node_downcast( node_to_update );
145
146  _Scheduler_SMP_Node_update_priority( &node->Base, new_priority );
147  _Scheduler_priority_Ready_queue_update(
148    &node->Ready_queue,
149    new_priority,
150    &self->Bit_map,
151    &self->Ready[ 0 ]
152  );
153}
154
155static Scheduler_strong_APA_Context *
156_Scheduler_strong_APA_Get_context( const Scheduler_Control *scheduler )
157{
158  return (Scheduler_strong_APA_Context *) _Scheduler_Get_context( scheduler );
159}
160
161void _Scheduler_strong_APA_Initialize( const Scheduler_Control *scheduler )
162{
163  Scheduler_strong_APA_Context *self =
164    _Scheduler_strong_APA_Get_context( scheduler );
165
166  _Scheduler_SMP_Initialize( &self->Base );
167  _Priority_bit_map_Initialize( &self->Bit_map );
168  _Scheduler_priority_Ready_queue_initialize(
169    &self->Ready[ 0 ],
170    scheduler->maximum_priority
171  );
172}
173
174void _Scheduler_strong_APA_Node_initialize(
175  const Scheduler_Control *scheduler,
176  Scheduler_Node          *node,
177  Thread_Control          *the_thread,
178  Priority_Control         priority
179)
180{
181  Scheduler_Context            *context;
182  Scheduler_strong_APA_Context *self;
183  Scheduler_strong_APA_Node    *the_node;
184
185  the_node = _Scheduler_strong_APA_Node_downcast( node );
186  _Scheduler_SMP_Node_initialize(
187    scheduler,
188    &the_node->Base,
189    the_thread,
190    priority
191  );
192
193  context = _Scheduler_Get_context( scheduler );
194  self = _Scheduler_strong_APA_Get_self( context );
195  _Scheduler_priority_Ready_queue_update(
196    &the_node->Ready_queue,
197    priority,
198    &self->Bit_map,
199    &self->Ready[ 0 ]
200  );
201}
202
203static Scheduler_Node *_Scheduler_strong_APA_Get_highest_ready(
204  Scheduler_Context *context,
205  Scheduler_Node    *node
206)
207{
208  Scheduler_strong_APA_Context *self =
209    _Scheduler_strong_APA_Get_self( context );
210
211  (void) node;
212
213  return (Scheduler_Node *) _Scheduler_priority_Ready_queue_first(
214    &self->Bit_map,
215    &self->Ready[ 0 ]
216  );
217}
218
219void _Scheduler_strong_APA_Block(
220  const Scheduler_Control *scheduler,
221  Thread_Control          *the_thread,
222  Scheduler_Node          *node
223)
224{
225  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
226
227  _Scheduler_SMP_Block(
228    context,
229    the_thread,
230    node,
231    _Scheduler_strong_APA_Extract_from_ready,
232    _Scheduler_strong_APA_Get_highest_ready,
233    _Scheduler_strong_APA_Move_from_ready_to_scheduled,
234    _Scheduler_SMP_Allocate_processor_exact
235  );
236}
237
238static Thread_Control *_Scheduler_strong_APA_Enqueue_ordered(
239  Scheduler_Context    *context,
240  Scheduler_Node       *node,
241  Thread_Control       *needs_help,
242  Chain_Node_order      order,
243  Scheduler_SMP_Insert  insert_ready,
244  Scheduler_SMP_Insert  insert_scheduled
245)
246{
247  return _Scheduler_SMP_Enqueue_ordered(
248    context,
249    node,
250    needs_help,
251    order,
252    insert_ready,
253    insert_scheduled,
254    _Scheduler_strong_APA_Move_from_scheduled_to_ready,
255    _Scheduler_SMP_Get_lowest_scheduled,
256    _Scheduler_SMP_Allocate_processor_exact
257  );
258}
259
260static Thread_Control *_Scheduler_strong_APA_Enqueue_lifo(
261  Scheduler_Context *context,
262  Scheduler_Node    *node,
263  Thread_Control    *needs_help
264)
265{
266  return _Scheduler_strong_APA_Enqueue_ordered(
267    context,
268    node,
269    needs_help,
270    _Scheduler_SMP_Insert_priority_lifo_order,
271    _Scheduler_strong_APA_Insert_ready_lifo,
272    _Scheduler_SMP_Insert_scheduled_lifo
273  );
274}
275
276static Thread_Control *_Scheduler_strong_APA_Enqueue_fifo(
277  Scheduler_Context *context,
278  Scheduler_Node    *node,
279  Thread_Control    *needs_help
280)
281{
282  return _Scheduler_strong_APA_Enqueue_ordered(
283    context,
284    node,
285    needs_help,
286    _Scheduler_SMP_Insert_priority_fifo_order,
287    _Scheduler_strong_APA_Insert_ready_fifo,
288    _Scheduler_SMP_Insert_scheduled_fifo
289  );
290}
291
292static Thread_Control *_Scheduler_strong_APA_Enqueue_scheduled_ordered(
293  Scheduler_Context    *context,
294  Scheduler_Node       *node,
295  Chain_Node_order      order,
296  Scheduler_SMP_Insert  insert_ready,
297  Scheduler_SMP_Insert  insert_scheduled
298)
299{
300  return _Scheduler_SMP_Enqueue_scheduled_ordered(
301    context,
302    node,
303    order,
304    _Scheduler_strong_APA_Extract_from_ready,
305    _Scheduler_strong_APA_Get_highest_ready,
306    insert_ready,
307    insert_scheduled,
308    _Scheduler_strong_APA_Move_from_ready_to_scheduled,
309    _Scheduler_SMP_Allocate_processor_exact
310  );
311}
312
313static Thread_Control *_Scheduler_strong_APA_Enqueue_scheduled_lifo(
314  Scheduler_Context *context,
315  Scheduler_Node    *node
316)
317{
318  return _Scheduler_strong_APA_Enqueue_scheduled_ordered(
319    context,
320    node,
321    _Scheduler_SMP_Insert_priority_lifo_order,
322    _Scheduler_strong_APA_Insert_ready_lifo,
323    _Scheduler_SMP_Insert_scheduled_lifo
324  );
325}
326
327static Thread_Control *_Scheduler_strong_APA_Enqueue_scheduled_fifo(
328  Scheduler_Context *context,
329  Scheduler_Node    *node
330)
331{
332  return _Scheduler_strong_APA_Enqueue_scheduled_ordered(
333    context,
334    node,
335    _Scheduler_SMP_Insert_priority_fifo_order,
336    _Scheduler_strong_APA_Insert_ready_fifo,
337    _Scheduler_SMP_Insert_scheduled_fifo
338  );
339}
340
341Thread_Control *_Scheduler_strong_APA_Unblock(
342  const Scheduler_Control *scheduler,
343  Thread_Control          *the_thread,
344  Scheduler_Node          *node
345)
346{
347  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
348
349  return _Scheduler_SMP_Unblock(
350    context,
351    the_thread,
352    node,
353    _Scheduler_strong_APA_Do_update,
354    _Scheduler_strong_APA_Enqueue_fifo
355  );
356}
357
358static bool _Scheduler_strong_APA_Do_ask_for_help(
359  Scheduler_Context *context,
360  Thread_Control    *the_thread,
361  Scheduler_Node    *node
362)
363{
364  return _Scheduler_SMP_Ask_for_help(
365    context,
366    the_thread,
367    node,
368    _Scheduler_SMP_Insert_priority_lifo_order,
369    _Scheduler_strong_APA_Insert_ready_lifo,
370    _Scheduler_SMP_Insert_scheduled_lifo,
371    _Scheduler_strong_APA_Move_from_scheduled_to_ready,
372    _Scheduler_SMP_Get_lowest_scheduled,
373    _Scheduler_SMP_Allocate_processor_lazy
374  );
375}
376
377void _Scheduler_strong_APA_Update_priority(
378  const Scheduler_Control *scheduler,
379  Thread_Control          *the_thread,
380  Scheduler_Node          *node
381)
382{
383  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
384
385  _Scheduler_SMP_Update_priority(
386    context,
387    the_thread,
388    node,
389    _Scheduler_strong_APA_Extract_from_ready,
390    _Scheduler_strong_APA_Do_update,
391    _Scheduler_strong_APA_Enqueue_fifo,
392    _Scheduler_strong_APA_Enqueue_lifo,
393    _Scheduler_strong_APA_Enqueue_scheduled_fifo,
394    _Scheduler_strong_APA_Enqueue_scheduled_lifo,
395    _Scheduler_strong_APA_Do_ask_for_help
396  );
397}
398
399bool _Scheduler_strong_APA_Ask_for_help(
400  const Scheduler_Control *scheduler,
401  Thread_Control          *the_thread,
402  Scheduler_Node          *node
403)
404{
405  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
406
407  return _Scheduler_strong_APA_Do_ask_for_help( context, the_thread, node );
408}
409
410void _Scheduler_strong_APA_Reconsider_help_request(
411  const Scheduler_Control *scheduler,
412  Thread_Control          *the_thread,
413  Scheduler_Node          *node
414)
415{
416  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
417
418  _Scheduler_SMP_Reconsider_help_request(
419    context,
420    the_thread,
421    node,
422    _Scheduler_strong_APA_Extract_from_ready
423  );
424}
425
426void _Scheduler_strong_APA_Withdraw_node(
427  const Scheduler_Control *scheduler,
428  Thread_Control          *the_thread,
429  Scheduler_Node          *node,
430  Thread_Scheduler_state   next_state
431)
432{
433  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
434
435  _Scheduler_SMP_Withdraw_node(
436    context,
437    the_thread,
438    node,
439    next_state,
440    _Scheduler_strong_APA_Extract_from_ready,
441    _Scheduler_strong_APA_Get_highest_ready,
442    _Scheduler_strong_APA_Move_from_ready_to_scheduled,
443    _Scheduler_SMP_Allocate_processor_lazy
444  );
445}
446
447Thread_Control *_Scheduler_strong_APA_Ask_for_help_X(
448  const Scheduler_Control *scheduler,
449  Thread_Control          *offers_help,
450  Thread_Control          *needs_help
451)
452{
453  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
454
455  return _Scheduler_SMP_Ask_for_help_X(
456    context,
457    offers_help,
458    needs_help,
459    _Scheduler_strong_APA_Enqueue_fifo
460  );
461}
462
463Thread_Control *_Scheduler_strong_APA_Yield(
464  const Scheduler_Control *scheduler,
465  Thread_Control          *the_thread,
466  Scheduler_Node          *node
467)
468{
469  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
470
471  return _Scheduler_SMP_Yield(
472    context,
473    the_thread,
474    node,
475    _Scheduler_strong_APA_Extract_from_ready,
476    _Scheduler_strong_APA_Enqueue_fifo,
477    _Scheduler_strong_APA_Enqueue_scheduled_fifo
478  );
479}
Note: See TracBrowser for help on using the repository browser.