source: rtems/cpukit/score/src/schedulerprioritysmp.c

Last change on this file was bcef89f2, checked in by Sebastian Huber <sebastian.huber@…>, on 05/19/23 at 06:18:25

Update company name

The embedded brains GmbH & Co. KG is the legal successor of embedded
brains GmbH.

  • Property mode set to 100644
File size: 10.5 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSScoreSchedulerPrioritySMP
7 *
8 * @brief This source file contains the implementation of
9 *   _Scheduler_priority_SMP_Add_processor(),
10 *   _Scheduler_priority_SMP_Ask_for_help(), _Scheduler_priority_SMP_Block(),
11 *   _Scheduler_priority_SMP_Initialize(),
12 *   _Scheduler_priority_SMP_Node_initialize(),
13 *   _Scheduler_priority_SMP_Reconsider_help_request(),
14 *   _Scheduler_priority_SMP_Remove_processor(),
15 *   _Scheduler_priority_SMP_Unblock(),
16 *   _Scheduler_priority_SMP_Update_priority(),
17 *   _Scheduler_priority_SMP_Withdraw_node(),
18 *   _Scheduler_priority_SMP_Make_sticky(),
19 *   _Scheduler_priority_SMP_Clean_sticky(), and
20 *   _Scheduler_priority_SMP_Yield().
21 */
22
23/*
24 * Copyright (C) 2013, 2014 embedded brains GmbH & Co. KG
25 *
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
28 * are met:
29 * 1. Redistributions of source code must retain the above copyright
30 *    notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 *    notice, this list of conditions and the following disclaimer in the
33 *    documentation and/or other materials provided with the distribution.
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
36 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
39 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
40 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
41 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
42 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
43 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
44 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
45 * POSSIBILITY OF SUCH DAMAGE.
46 */
47
48#ifdef HAVE_CONFIG_H
49#include "config.h"
50#endif
51
52#include <rtems/score/schedulerprioritysmpimpl.h>
53
54static Scheduler_priority_SMP_Context *
55_Scheduler_priority_SMP_Get_context( const Scheduler_Control *scheduler )
56{
57  return (Scheduler_priority_SMP_Context *) _Scheduler_Get_context( scheduler );
58}
59
60void _Scheduler_priority_SMP_Initialize( const Scheduler_Control *scheduler )
61{
62  Scheduler_priority_SMP_Context *self =
63    _Scheduler_priority_SMP_Get_context( scheduler );
64
65  _Scheduler_SMP_Initialize( &self->Base );
66  self->idle_ready_queue = &self->Ready[ scheduler->maximum_priority ];
67  _Priority_bit_map_Initialize( &self->Bit_map );
68  _Scheduler_priority_Ready_queue_initialize(
69    &self->Ready[ 0 ],
70    scheduler->maximum_priority
71  );
72}
73
74void _Scheduler_priority_SMP_Node_initialize(
75  const Scheduler_Control *scheduler,
76  Scheduler_Node          *node,
77  Thread_Control          *the_thread,
78  Priority_Control         priority
79)
80{
81  Scheduler_Context              *context;
82  Scheduler_priority_SMP_Context *self;
83  Scheduler_priority_SMP_Node    *the_node;
84
85  the_node = _Scheduler_priority_SMP_Node_downcast( node );
86  _Scheduler_SMP_Node_initialize(
87    scheduler,
88    &the_node->Base,
89    the_thread,
90    priority
91  );
92
93  context = _Scheduler_Get_context( scheduler );
94  self = _Scheduler_priority_SMP_Get_self( context );
95  _Scheduler_priority_Ready_queue_update(
96    &the_node->Ready_queue,
97    SCHEDULER_PRIORITY_UNMAP( priority ),
98    &self->Bit_map,
99    &self->Ready[ 0 ]
100  );
101}
102
103static Scheduler_Node *_Scheduler_priority_SMP_Get_highest_ready(
104  Scheduler_Context *context,
105  Scheduler_Node    *node
106)
107{
108  Scheduler_priority_SMP_Context *self =
109    _Scheduler_priority_SMP_Get_self( context );
110
111  (void) node;
112
113  return (Scheduler_Node *) _Scheduler_priority_Ready_queue_first(
114    &self->Bit_map,
115    &self->Ready[ 0 ]
116  );
117}
118
119void _Scheduler_priority_SMP_Block(
120  const Scheduler_Control *scheduler,
121  Thread_Control          *thread,
122  Scheduler_Node          *node
123)
124{
125  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
126
127  _Scheduler_SMP_Block(
128    context,
129    thread,
130    node,
131    _Scheduler_SMP_Extract_from_scheduled,
132    _Scheduler_priority_SMP_Extract_from_ready,
133    _Scheduler_priority_SMP_Get_highest_ready,
134    _Scheduler_priority_SMP_Move_from_ready_to_scheduled,
135    _Scheduler_SMP_Allocate_processor_lazy,
136    _Scheduler_priority_SMP_Get_idle
137  );
138}
139
140static bool _Scheduler_priority_SMP_Enqueue(
141  Scheduler_Context *context,
142  Scheduler_Node    *node,
143  Priority_Control   insert_priority
144)
145{
146  return _Scheduler_SMP_Enqueue(
147    context,
148    node,
149    insert_priority,
150    _Scheduler_SMP_Priority_less_equal,
151    _Scheduler_priority_SMP_Insert_ready,
152    _Scheduler_SMP_Insert_scheduled,
153    _Scheduler_priority_SMP_Move_from_scheduled_to_ready,
154    _Scheduler_priority_SMP_Move_from_ready_to_scheduled,
155    _Scheduler_SMP_Get_lowest_scheduled,
156    _Scheduler_SMP_Allocate_processor_lazy,
157    _Scheduler_priority_SMP_Get_idle,
158    _Scheduler_priority_SMP_Release_idle
159  );
160}
161
162static void _Scheduler_priority_SMP_Enqueue_scheduled(
163  Scheduler_Context *context,
164  Scheduler_Node    *node,
165  Priority_Control   insert_priority
166)
167{
168  _Scheduler_SMP_Enqueue_scheduled(
169    context,
170    node,
171    insert_priority,
172    _Scheduler_SMP_Priority_less_equal,
173    _Scheduler_priority_SMP_Extract_from_ready,
174    _Scheduler_priority_SMP_Get_highest_ready,
175    _Scheduler_priority_SMP_Insert_ready,
176    _Scheduler_SMP_Insert_scheduled,
177    _Scheduler_priority_SMP_Move_from_ready_to_scheduled,
178    _Scheduler_SMP_Allocate_processor_lazy,
179    _Scheduler_priority_SMP_Get_idle,
180    _Scheduler_priority_SMP_Release_idle
181  );
182}
183
184void _Scheduler_priority_SMP_Unblock(
185  const Scheduler_Control *scheduler,
186  Thread_Control          *thread,
187  Scheduler_Node          *node
188)
189{
190  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
191
192  _Scheduler_SMP_Unblock(
193    context,
194    thread,
195    node,
196    _Scheduler_priority_SMP_Do_update,
197    _Scheduler_priority_SMP_Enqueue,
198    _Scheduler_priority_SMP_Release_idle
199  );
200}
201
202static bool _Scheduler_priority_SMP_Do_ask_for_help(
203  Scheduler_Context *context,
204  Thread_Control    *the_thread,
205  Scheduler_Node    *node
206)
207{
208  return _Scheduler_SMP_Ask_for_help(
209    context,
210    the_thread,
211    node,
212    _Scheduler_SMP_Priority_less_equal,
213    _Scheduler_priority_SMP_Insert_ready,
214    _Scheduler_SMP_Insert_scheduled,
215    _Scheduler_priority_SMP_Move_from_scheduled_to_ready,
216    _Scheduler_SMP_Get_lowest_scheduled,
217    _Scheduler_SMP_Allocate_processor_lazy,
218    _Scheduler_priority_SMP_Release_idle
219  );
220}
221
222void _Scheduler_priority_SMP_Update_priority(
223  const Scheduler_Control *scheduler,
224  Thread_Control          *thread,
225  Scheduler_Node          *node
226)
227{
228  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
229
230  _Scheduler_SMP_Update_priority(
231    context,
232    thread,
233    node,
234    _Scheduler_SMP_Extract_from_scheduled,
235    _Scheduler_priority_SMP_Extract_from_ready,
236    _Scheduler_priority_SMP_Do_update,
237    _Scheduler_priority_SMP_Enqueue,
238    _Scheduler_priority_SMP_Enqueue_scheduled,
239    _Scheduler_priority_SMP_Do_ask_for_help
240  );
241}
242
243bool _Scheduler_priority_SMP_Ask_for_help(
244  const Scheduler_Control *scheduler,
245  Thread_Control          *the_thread,
246  Scheduler_Node          *node
247)
248{
249  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
250
251  return _Scheduler_priority_SMP_Do_ask_for_help( context, the_thread, node );
252}
253
254void _Scheduler_priority_SMP_Reconsider_help_request(
255  const Scheduler_Control *scheduler,
256  Thread_Control          *the_thread,
257  Scheduler_Node          *node
258)
259{
260  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
261
262  _Scheduler_SMP_Reconsider_help_request(
263    context,
264    the_thread,
265    node,
266    _Scheduler_priority_SMP_Extract_from_ready
267  );
268}
269
270void _Scheduler_priority_SMP_Withdraw_node(
271  const Scheduler_Control *scheduler,
272  Thread_Control          *the_thread,
273  Scheduler_Node          *node,
274  Thread_Scheduler_state   next_state
275)
276{
277  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
278
279  _Scheduler_SMP_Withdraw_node(
280    context,
281    the_thread,
282    node,
283    next_state,
284    _Scheduler_SMP_Extract_from_scheduled,
285    _Scheduler_priority_SMP_Extract_from_ready,
286    _Scheduler_priority_SMP_Get_highest_ready,
287    _Scheduler_priority_SMP_Move_from_ready_to_scheduled,
288    _Scheduler_SMP_Allocate_processor_lazy,
289    _Scheduler_priority_SMP_Get_idle
290  );
291}
292
293void _Scheduler_priority_SMP_Make_sticky(
294  const Scheduler_Control *scheduler,
295  Thread_Control          *the_thread,
296  Scheduler_Node          *node
297)
298{
299  _Scheduler_SMP_Make_sticky(
300    scheduler,
301    the_thread,
302    node,
303    _Scheduler_priority_SMP_Do_update,
304    _Scheduler_priority_SMP_Enqueue
305  );
306}
307
308void _Scheduler_priority_SMP_Clean_sticky(
309  const Scheduler_Control *scheduler,
310  Thread_Control          *the_thread,
311  Scheduler_Node          *node
312)
313{
314  _Scheduler_SMP_Clean_sticky(
315    scheduler,
316    the_thread,
317    node,
318    _Scheduler_SMP_Extract_from_scheduled,
319    _Scheduler_priority_SMP_Extract_from_ready,
320    _Scheduler_priority_SMP_Get_highest_ready,
321    _Scheduler_priority_SMP_Move_from_ready_to_scheduled,
322    _Scheduler_SMP_Allocate_processor_lazy,
323    _Scheduler_priority_SMP_Get_idle,
324    _Scheduler_priority_SMP_Release_idle
325  );
326}
327
328void _Scheduler_priority_SMP_Add_processor(
329  const Scheduler_Control *scheduler,
330  Thread_Control          *idle
331)
332{
333  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
334
335  _Scheduler_SMP_Add_processor(
336    context,
337    idle,
338    _Scheduler_priority_SMP_Has_ready,
339    _Scheduler_priority_SMP_Enqueue_scheduled,
340    _Scheduler_SMP_Do_nothing_register_idle
341  );
342}
343
344Thread_Control *_Scheduler_priority_SMP_Remove_processor(
345  const Scheduler_Control *scheduler,
346  Per_CPU_Control         *cpu
347)
348{
349  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
350
351  return _Scheduler_SMP_Remove_processor(
352    context,
353    cpu,
354    _Scheduler_SMP_Extract_from_scheduled,
355    _Scheduler_priority_SMP_Extract_from_ready,
356    _Scheduler_priority_SMP_Enqueue,
357    _Scheduler_priority_SMP_Get_idle,
358    _Scheduler_priority_SMP_Release_idle
359  );
360}
361
362void _Scheduler_priority_SMP_Yield(
363  const Scheduler_Control *scheduler,
364  Thread_Control          *thread,
365  Scheduler_Node          *node
366)
367{
368  Scheduler_Context *context = _Scheduler_Get_context( scheduler );
369
370  _Scheduler_SMP_Yield(
371    context,
372    thread,
373    node,
374    _Scheduler_SMP_Extract_from_scheduled,
375    _Scheduler_priority_SMP_Extract_from_ready,
376    _Scheduler_priority_SMP_Enqueue,
377    _Scheduler_priority_SMP_Enqueue_scheduled
378  );
379}
Note: See TracBrowser for help on using the repository browser.