1 | /* |
---|
2 | * Copyright (c) 2014, 2016 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifndef _RTEMS_SCORE_SCHEDULERNODE_H |
---|
16 | #define _RTEMS_SCORE_SCHEDULERNODE_H |
---|
17 | |
---|
18 | #include <rtems/score/basedefs.h> |
---|
19 | #include <rtems/score/chain.h> |
---|
20 | #include <rtems/score/priority.h> |
---|
21 | #include <rtems/score/smplockseq.h> |
---|
22 | |
---|
23 | struct _Thread_Control; |
---|
24 | |
---|
25 | #ifdef __cplusplus |
---|
26 | extern "C" { |
---|
27 | #endif /* __cplusplus */ |
---|
28 | |
---|
29 | #if defined(RTEMS_SMP) |
---|
30 | /** |
---|
31 | * @brief The scheduler node requests. |
---|
32 | */ |
---|
33 | typedef enum { |
---|
34 | /** |
---|
35 | * @brief The scheduler node is not on the list of pending requests. |
---|
36 | */ |
---|
37 | SCHEDULER_NODE_REQUEST_NOT_PENDING, |
---|
38 | |
---|
39 | /** |
---|
40 | * @brief There is a pending scheduler node request to add this scheduler |
---|
41 | * node to the Thread_Control::Scheduler::Scheduler_nodes chain. |
---|
42 | */ |
---|
43 | SCHEDULER_NODE_REQUEST_ADD, |
---|
44 | |
---|
45 | /** |
---|
46 | * @brief There is a pending scheduler node request to remove this scheduler |
---|
47 | * node from the Thread_Control::Scheduler::Scheduler_nodes chain. |
---|
48 | */ |
---|
49 | SCHEDULER_NODE_REQUEST_REMOVE, |
---|
50 | |
---|
51 | /** |
---|
52 | * @brief The scheduler node is on the list of pending requests, but nothing |
---|
53 | * should change. |
---|
54 | */ |
---|
55 | SCHEDULER_NODE_REQUEST_NOTHING, |
---|
56 | |
---|
57 | } Scheduler_Node_request; |
---|
58 | #endif |
---|
59 | |
---|
60 | typedef struct Scheduler_Node Scheduler_Node; |
---|
61 | |
---|
62 | /** |
---|
63 | * @brief Scheduler node for per-thread data. |
---|
64 | */ |
---|
65 | struct Scheduler_Node { |
---|
66 | #if defined(RTEMS_SMP) |
---|
67 | /** |
---|
68 | * @brief Chain node for usage in various scheduler data structures. |
---|
69 | * |
---|
70 | * Strictly, this is the wrong place for this field since the data structures |
---|
71 | * to manage scheduler nodes belong to the particular scheduler |
---|
72 | * implementation. Currently, all SMP scheduler implementations use chains |
---|
73 | * or red-black trees. The node is here to simplify things, just like the |
---|
74 | * object node in the thread control block. |
---|
75 | */ |
---|
76 | union { |
---|
77 | Chain_Node Chain; |
---|
78 | RBTree_Node RBTree; |
---|
79 | } Node; |
---|
80 | |
---|
81 | /** |
---|
82 | * @brief The sticky level determines if this scheduler node should use an |
---|
83 | * idle thread in case this node is scheduled and the owner thread is |
---|
84 | * blocked. |
---|
85 | */ |
---|
86 | int sticky_level; |
---|
87 | |
---|
88 | /** |
---|
89 | * @brief The thread using this node. |
---|
90 | * |
---|
91 | * This is either the owner or an idle thread. |
---|
92 | */ |
---|
93 | struct _Thread_Control *user; |
---|
94 | |
---|
95 | /** |
---|
96 | * @brief The idle thread claimed by this node in case the sticky level is |
---|
97 | * greater than zero and the thread is block or is scheduled on another |
---|
98 | * scheduler instance. |
---|
99 | * |
---|
100 | * This is necessary to ensure the priority ceiling protocols work across |
---|
101 | * scheduler boundaries. |
---|
102 | */ |
---|
103 | struct _Thread_Control *idle; |
---|
104 | #endif |
---|
105 | |
---|
106 | /** |
---|
107 | * @brief The thread owning this node. |
---|
108 | */ |
---|
109 | struct _Thread_Control *owner; |
---|
110 | |
---|
111 | #if defined(RTEMS_SMP) |
---|
112 | /** |
---|
113 | * @brief Block to register and manage this scheduler node in the thread |
---|
114 | * control block of the owner of this scheduler node. |
---|
115 | */ |
---|
116 | struct { |
---|
117 | /** |
---|
118 | * @brief Node to add this scheduler node to |
---|
119 | * Thread_Control::Scheduler::Wait_nodes. |
---|
120 | */ |
---|
121 | Chain_Node Wait_node; |
---|
122 | |
---|
123 | /** |
---|
124 | * @brief Node to add this scheduler node to |
---|
125 | * Thread_Control::Scheduler::Scheduler_nodes or a temporary remove list. |
---|
126 | */ |
---|
127 | union { |
---|
128 | /** |
---|
129 | * @brief The node for Thread_Control::Scheduler::Scheduler_nodes. |
---|
130 | */ |
---|
131 | Chain_Node Chain; |
---|
132 | |
---|
133 | /** |
---|
134 | * @brief The next pointer for a temporary remove list. |
---|
135 | * |
---|
136 | * @see _Thread_Scheduler_process_requests(). |
---|
137 | */ |
---|
138 | Scheduler_Node *next; |
---|
139 | } Scheduler_node; |
---|
140 | |
---|
141 | /** |
---|
142 | * @brief Link to the next scheduler node in the |
---|
143 | * Thread_Control::Scheduler::requests list. |
---|
144 | */ |
---|
145 | Scheduler_Node *next_request; |
---|
146 | |
---|
147 | /** |
---|
148 | * @brief The current scheduler node request. |
---|
149 | */ |
---|
150 | Scheduler_Node_request request; |
---|
151 | } Thread; |
---|
152 | #endif |
---|
153 | |
---|
154 | /** |
---|
155 | * @brief Thread wait support block. |
---|
156 | */ |
---|
157 | struct { |
---|
158 | Priority_Aggregation Priority; |
---|
159 | } Wait; |
---|
160 | |
---|
161 | /** |
---|
162 | * @brief The thread priority information used by the scheduler. |
---|
163 | * |
---|
164 | * The thread priority is manifest in two independent areas. One area is the |
---|
165 | * user visible thread priority along with a potential thread queue. The |
---|
166 | * other is the scheduler. During a thread priority change, the user visible |
---|
167 | * thread priority and the thread queue are first updated and the thread |
---|
168 | * priority value here is changed. Once this is done the scheduler is |
---|
169 | * notified via the update priority operation, so that it can update its |
---|
170 | * internal state and honour a new thread priority value. |
---|
171 | */ |
---|
172 | struct { |
---|
173 | /** |
---|
174 | * @brief The thread priority value of this scheduler node. |
---|
175 | * |
---|
176 | * The producer of this value is _Thread_Change_priority(). The consumer |
---|
177 | * is the scheduler via the unblock and update priority operations. |
---|
178 | * |
---|
179 | * This priority control consists of two parts. One part is the plain |
---|
180 | * priority value (most-significant 63 bits). The other part is the |
---|
181 | * least-significant bit which indicates if the thread should be appended |
---|
182 | * (bit set) or prepended (bit cleared) to its priority group, see |
---|
183 | * SCHEDULER_PRIORITY_APPEND(). |
---|
184 | */ |
---|
185 | Priority_Control value; |
---|
186 | |
---|
187 | #if defined(RTEMS_SMP) |
---|
188 | /** |
---|
189 | * @brief Sequence lock to synchronize priority value updates. |
---|
190 | */ |
---|
191 | SMP_sequence_lock_Control Lock; |
---|
192 | #endif |
---|
193 | } Priority; |
---|
194 | }; |
---|
195 | |
---|
196 | #if defined(RTEMS_SMP) |
---|
197 | /** |
---|
198 | * @brief The size of a scheduler node. |
---|
199 | * |
---|
200 | * This value is provided via <rtems/confdefs.h>. |
---|
201 | */ |
---|
202 | extern const size_t _Scheduler_Node_size; |
---|
203 | #endif |
---|
204 | |
---|
205 | #if defined(RTEMS_SMP) |
---|
206 | #define SCHEDULER_NODE_OF_THREAD_WAIT_NODE( node ) \ |
---|
207 | RTEMS_CONTAINER_OF( node, Scheduler_Node, Thread.Wait_node ) |
---|
208 | |
---|
209 | #define SCHEDULER_NODE_OF_THREAD_SCHEDULER_NODE( node ) \ |
---|
210 | RTEMS_CONTAINER_OF( node, Scheduler_Node, Thread.Scheduler_node.Chain ) |
---|
211 | #endif |
---|
212 | |
---|
213 | #ifdef __cplusplus |
---|
214 | } |
---|
215 | #endif /* __cplusplus */ |
---|
216 | |
---|
217 | #endif /* _RTEMS_SCORE_SCHEDULERNODE_H */ |
---|