source: rtems/cpukit/score/src/schedulerprioritysmp.c @ 647b95d

4.115
Last change on this file since 647b95d was 647b95d, checked in by Sebastian Huber <sebastian.huber@…>, on 06/10/14 at 14:32:12

score: Use chain nodes for ready queue support

This reduces the API to the minimum data structures to maximize the
re-usability.

  • Property mode set to 100644
File size: 5.9 KB
Line 
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#include <rtems/score/schedulersmpimpl.h>
29
30static Scheduler_priority_SMP_Context *
31_Scheduler_priority_SMP_Get_context( const Scheduler_Control *scheduler )
32{
33  return (Scheduler_priority_SMP_Context *) _Scheduler_Get_context( scheduler );
34}
35
36void _Scheduler_priority_SMP_Initialize( const Scheduler_Control *scheduler )
37{
38  Scheduler_priority_SMP_Context *self =
39    _Scheduler_priority_SMP_Get_context( scheduler );
40
41  _Scheduler_SMP_Initialize( &self->Base );
42  _Priority_bit_map_Initialize( &self->Bit_map );
43  _Scheduler_priority_Ready_queue_initialize( &self->Ready[ 0 ] );
44}
45
46void _Scheduler_priority_SMP_Node_initialize(
47  const Scheduler_Control *scheduler,
48  Thread_Control *thread
49)
50{
51  Scheduler_SMP_Node *node = _Scheduler_SMP_Node_get( thread );
52
53  _Scheduler_SMP_Node_initialize( node );
54}
55
56void _Scheduler_priority_SMP_Update_priority(
57  const Scheduler_Control *scheduler,
58  Thread_Control *thread,
59  Priority_Control new_priority
60)
61{
62  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
63  Scheduler_Node *node = _Scheduler_Node_get( thread );
64
65  _Scheduler_priority_SMP_Do_update( context, node, new_priority );
66}
67
68static Thread_Control *_Scheduler_priority_SMP_Get_highest_ready(
69  Scheduler_Context *context,
70  Thread_Control    *thread
71)
72{
73  Scheduler_priority_SMP_Context *self =
74    _Scheduler_priority_SMP_Get_self( context );
75
76  (void) thread;
77
78  return (Thread_Control *) _Scheduler_priority_Ready_queue_first(
79    &self->Bit_map,
80    &self->Ready[ 0 ]
81  );
82}
83
84void _Scheduler_priority_SMP_Block(
85  const Scheduler_Control *scheduler,
86  Thread_Control *thread
87)
88{
89  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
90
91  _Scheduler_SMP_Block(
92    context,
93    thread,
94    _Scheduler_priority_SMP_Extract_from_ready,
95    _Scheduler_priority_SMP_Get_highest_ready,
96    _Scheduler_priority_SMP_Move_from_ready_to_scheduled,
97    _Scheduler_SMP_Allocate_processor
98  );
99}
100
101static void _Scheduler_priority_SMP_Enqueue_ordered(
102  Scheduler_Context *context,
103  Thread_Control *thread,
104  Chain_Node_order order,
105  Scheduler_SMP_Insert insert_ready,
106  Scheduler_SMP_Insert insert_scheduled
107)
108{
109  _Scheduler_SMP_Enqueue_ordered(
110    context,
111    thread,
112    order,
113    insert_ready,
114    insert_scheduled,
115    _Scheduler_priority_SMP_Move_from_scheduled_to_ready,
116    _Scheduler_SMP_Get_lowest_scheduled,
117    _Scheduler_SMP_Allocate_processor
118  );
119}
120
121static void _Scheduler_priority_SMP_Enqueue_lifo(
122  Scheduler_Context *context,
123  Thread_Control *thread
124)
125{
126  _Scheduler_priority_SMP_Enqueue_ordered(
127    context,
128    thread,
129    _Scheduler_simple_Insert_priority_lifo_order,
130    _Scheduler_priority_SMP_Insert_ready_lifo,
131    _Scheduler_SMP_Insert_scheduled_lifo
132  );
133}
134
135static void _Scheduler_priority_SMP_Enqueue_fifo(
136  Scheduler_Context *context,
137  Thread_Control *thread
138)
139{
140  _Scheduler_priority_SMP_Enqueue_ordered(
141    context,
142    thread,
143    _Scheduler_simple_Insert_priority_fifo_order,
144    _Scheduler_priority_SMP_Insert_ready_fifo,
145    _Scheduler_SMP_Insert_scheduled_fifo
146  );
147}
148
149static void _Scheduler_priority_SMP_Enqueue_scheduled_ordered(
150  Scheduler_Context *context,
151  Thread_Control *thread,
152  Chain_Node_order order,
153  Scheduler_SMP_Insert insert_ready,
154  Scheduler_SMP_Insert insert_scheduled
155)
156{
157  _Scheduler_SMP_Enqueue_scheduled_ordered(
158    context,
159    thread,
160    order,
161    _Scheduler_priority_SMP_Get_highest_ready,
162    insert_ready,
163    insert_scheduled,
164    _Scheduler_priority_SMP_Move_from_ready_to_scheduled,
165    _Scheduler_SMP_Allocate_processor
166  );
167}
168
169static void _Scheduler_priority_SMP_Enqueue_scheduled_lifo(
170  Scheduler_Context *context,
171  Thread_Control *thread
172)
173{
174  _Scheduler_priority_SMP_Enqueue_scheduled_ordered(
175    context,
176    thread,
177    _Scheduler_simple_Insert_priority_lifo_order,
178    _Scheduler_priority_SMP_Insert_ready_lifo,
179    _Scheduler_SMP_Insert_scheduled_lifo
180  );
181}
182
183static void _Scheduler_priority_SMP_Enqueue_scheduled_fifo(
184  Scheduler_Context *context,
185  Thread_Control *thread
186)
187{
188  _Scheduler_priority_SMP_Enqueue_scheduled_ordered(
189    context,
190    thread,
191    _Scheduler_simple_Insert_priority_fifo_order,
192    _Scheduler_priority_SMP_Insert_ready_fifo,
193    _Scheduler_SMP_Insert_scheduled_fifo
194  );
195}
196
197void _Scheduler_priority_SMP_Unblock(
198  const Scheduler_Control *scheduler,
199  Thread_Control *thread
200)
201{
202  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
203
204  _Scheduler_SMP_Unblock(
205    context,
206    thread,
207    _Scheduler_priority_SMP_Enqueue_fifo
208  );
209}
210
211void _Scheduler_priority_SMP_Change_priority(
212  const Scheduler_Control *scheduler,
213  Thread_Control          *thread,
214  Priority_Control         new_priority,
215  bool                     prepend_it
216)
217{
218  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
219
220  _Scheduler_SMP_Change_priority(
221    context,
222    thread,
223    new_priority,
224    prepend_it,
225    _Scheduler_priority_SMP_Extract_from_ready,
226    _Scheduler_priority_SMP_Do_update,
227    _Scheduler_priority_SMP_Enqueue_fifo,
228    _Scheduler_priority_SMP_Enqueue_lifo,
229    _Scheduler_priority_SMP_Enqueue_scheduled_fifo,
230    _Scheduler_priority_SMP_Enqueue_scheduled_lifo
231  );
232}
233
234void _Scheduler_priority_SMP_Yield(
235  const Scheduler_Control *scheduler,
236  Thread_Control *thread
237)
238{
239  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
240
241  return _Scheduler_SMP_Yield(
242    context,
243    thread,
244    _Scheduler_priority_SMP_Extract_from_ready,
245    _Scheduler_priority_SMP_Enqueue_fifo,
246    _Scheduler_priority_SMP_Enqueue_scheduled_fifo
247  );
248}
Note: See TracBrowser for help on using the repository browser.