source: rtems/cpukit/score/include/rtems/score/schedulerprioritysmpimpl.h @ 5c3d250

4.115
Last change on this file since 5c3d250 was 5c3d250, checked in by Sebastian Huber <sebastian.huber@…>, on 07/04/14 at 12:34:23

score: Implement scheduler helping protocol

The following scheduler operations return a thread in need for help

  • unblock,
  • change priority, and
  • yield.

A thread in need for help is a thread that encounters a scheduler state
change from scheduled to ready or a thread that cannot be scheduled in
an unblock operation. Such a thread can ask threads which depend on
resources owned by this thread for help.

Add a new ask for help scheduler operation. This operation is used by
_Scheduler_Ask_for_help() to help threads in need for help returned by
the operations mentioned above. This operation is also used by
_Scheduler_Thread_change_resource_root() in case the root of a resource
sub-tree changes. A use case is the ownership change of a resource.

In case it is not possible to schedule a thread in need for help, then
the corresponding scheduler node will be placed into the set of ready
scheduler nodes of the scheduler instance. Once a state change from
ready to scheduled happens for this scheduler node it may be used to
schedule the thread in need for help.

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ScoreSchedulerPrioritySMP
5 *
6 * @brief Deterministic Priority SMP Scheduler API
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#ifndef _RTEMS_SCORE_SCHEDULERPRIORITYSMPIMPL_H
24#define _RTEMS_SCORE_SCHEDULERPRIORITYSMPIMPL_H
25
26#include <rtems/score/schedulerprioritysmp.h>
27#include <rtems/score/schedulerpriorityimpl.h>
28#include <rtems/score/schedulersimpleimpl.h>
29#include <rtems/score/schedulersmpimpl.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif /* __cplusplus */
34
35/**
36 * @ingroup ScoreSchedulerPrioritySMP
37 * @{
38 */
39
40static inline Scheduler_priority_SMP_Context *_Scheduler_priority_SMP_Get_self(
41  Scheduler_Context *context
42)
43{
44  return (Scheduler_priority_SMP_Context *) context;
45}
46
47static inline Scheduler_priority_SMP_Node *_Scheduler_priority_SMP_Thread_get_node(
48  Thread_Control *thread
49)
50{
51  return (Scheduler_priority_SMP_Node *) _Scheduler_Thread_get_node( thread );
52}
53
54static inline Scheduler_priority_SMP_Node *
55_Scheduler_priority_SMP_Node_downcast( Scheduler_Node *node )
56{
57  return (Scheduler_priority_SMP_Node *) node;
58}
59
60static inline void _Scheduler_priority_SMP_Move_from_scheduled_to_ready(
61  Scheduler_Context *context,
62  Scheduler_Node    *scheduled_to_ready
63)
64{
65  Scheduler_priority_SMP_Context *self =
66    _Scheduler_priority_SMP_Get_self( context );
67  Scheduler_priority_SMP_Node *node =
68    _Scheduler_priority_SMP_Node_downcast( scheduled_to_ready );
69
70  _Chain_Extract_unprotected( &node->Base.Base.Node );
71  _Scheduler_priority_Ready_queue_enqueue_first(
72    &node->Base.Base.Node,
73    &node->Ready_queue,
74    &self->Bit_map
75  );
76}
77
78static inline void _Scheduler_priority_SMP_Move_from_ready_to_scheduled(
79  Scheduler_Context *context,
80  Scheduler_Node    *ready_to_scheduled
81)
82{
83  Scheduler_priority_SMP_Context *self =
84    _Scheduler_priority_SMP_Get_self( context );
85  Scheduler_priority_SMP_Node *node =
86    _Scheduler_priority_SMP_Node_downcast( ready_to_scheduled );
87
88  _Scheduler_priority_Ready_queue_extract(
89    &node->Base.Base.Node,
90    &node->Ready_queue,
91    &self->Bit_map
92  );
93  _Chain_Insert_ordered_unprotected(
94    &self->Base.Scheduled,
95    &node->Base.Base.Node,
96    _Scheduler_SMP_Insert_priority_fifo_order
97  );
98}
99
100static inline void _Scheduler_priority_SMP_Insert_ready_lifo(
101  Scheduler_Context *context,
102  Scheduler_Node    *thread
103)
104{
105  Scheduler_priority_SMP_Context *self =
106    _Scheduler_priority_SMP_Get_self( context );
107  Scheduler_priority_SMP_Node *node =
108    _Scheduler_priority_SMP_Node_downcast( thread );
109
110  _Scheduler_priority_Ready_queue_enqueue(
111    &node->Base.Base.Node,
112    &node->Ready_queue,
113    &self->Bit_map
114  );
115}
116
117static inline void _Scheduler_priority_SMP_Insert_ready_fifo(
118  Scheduler_Context *context,
119  Scheduler_Node    *thread
120)
121{
122  Scheduler_priority_SMP_Context *self =
123    _Scheduler_priority_SMP_Get_self( context );
124  Scheduler_priority_SMP_Node *node =
125    _Scheduler_priority_SMP_Node_downcast( thread );
126
127  _Scheduler_priority_Ready_queue_enqueue_first(
128    &node->Base.Base.Node,
129    &node->Ready_queue,
130    &self->Bit_map
131  );
132}
133
134static inline void _Scheduler_priority_SMP_Extract_from_ready(
135  Scheduler_Context *context,
136  Scheduler_Node    *thread
137)
138{
139  Scheduler_priority_SMP_Context *self =
140    _Scheduler_priority_SMP_Get_self( context );
141  Scheduler_priority_SMP_Node *node =
142    _Scheduler_priority_SMP_Node_downcast( thread );
143
144  _Scheduler_priority_Ready_queue_extract(
145    &node->Base.Base.Node,
146    &node->Ready_queue,
147    &self->Bit_map
148  );
149}
150
151static inline Thread_Control *_Scheduler_priority_SMP_Get_idle_thread(
152  Scheduler_Context *context
153)
154{
155  return _Scheduler_SMP_Get_idle_thread(
156    context,
157    _Scheduler_priority_SMP_Extract_from_ready
158  );
159}
160
161static void _Scheduler_priority_SMP_Release_idle_thread(
162  Scheduler_Context *context,
163  Thread_Control    *idle
164)
165{
166  _Scheduler_SMP_Release_idle_thread(
167    context,
168    idle,
169    _Scheduler_priority_SMP_Insert_ready_fifo
170  );
171}
172
173static inline void _Scheduler_priority_SMP_Do_update(
174  Scheduler_Context *context,
175  Scheduler_Node *node_to_update,
176  Priority_Control new_priority
177)
178{
179  Scheduler_priority_SMP_Context *self =
180    _Scheduler_priority_SMP_Get_self( context );
181  Scheduler_priority_SMP_Node *node =
182    _Scheduler_priority_SMP_Node_downcast( node_to_update );
183
184  _Scheduler_SMP_Node_update_priority( &node->Base, new_priority );
185  _Scheduler_priority_Ready_queue_update(
186    &node->Ready_queue,
187    new_priority,
188    &self->Bit_map,
189    &self->Ready[ 0 ]
190  );
191}
192
193/** @} */
194
195#ifdef __cplusplus
196}
197#endif /* __cplusplus */
198
199#endif /* _RTEMS_SCORE_SCHEDULERPRIORITYSMPIMPL_H */
Note: See TracBrowser for help on using the repository browser.