source: rtems/cpukit/score/src/schedulerprioritysmp.c @ 8f0c7a46

4.115
Last change on this file since 8f0c7a46 was 8f0c7a46, checked in by Sebastian Huber <sebastian.huber@…>, on 06/10/14 at 14:13:37

score: Decouple thread and scheduler nodes on SMP

Add a chain node to the scheduler node to decouple the thread and
scheduler nodes. It is now possible to enqueue a thread in a thread
wait queue and use its scheduler node at the same for other threads,
e.g. a resouce owner.

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