1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Priority Handler API |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * COPYRIGHT (c) 1989-2011. |
---|
9 | * On-Line Applications Research Corporation (OAR). |
---|
10 | * |
---|
11 | * Copyright (c) 2016, 2017 embedded brains GmbH. |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.org/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #ifndef _RTEMS_SCORE_PRIORITY_H |
---|
19 | #define _RTEMS_SCORE_PRIORITY_H |
---|
20 | |
---|
21 | #include <rtems/score/chain.h> |
---|
22 | #include <rtems/score/cpu.h> |
---|
23 | #include <rtems/score/rbtree.h> |
---|
24 | |
---|
25 | struct _Scheduler_Control; |
---|
26 | |
---|
27 | #ifdef __cplusplus |
---|
28 | extern "C" { |
---|
29 | #endif |
---|
30 | |
---|
31 | /** |
---|
32 | * @defgroup RTEMSScorePriority Priority Handler |
---|
33 | * |
---|
34 | * @ingroup RTEMSScore |
---|
35 | * |
---|
36 | * This handler encapsulates functionality which is used to manage thread |
---|
37 | * priorities. The actual priority of a thread is an aggregation of priority |
---|
38 | * nodes. The thread priority aggregation for the home scheduler instance of a |
---|
39 | * thread consists of at least one priority node, which is normally the real |
---|
40 | * priority of the thread. The locking protocols (e.g. priority ceiling and |
---|
41 | * priority inheritance), rate-monotonic period objects and the POSIX sporadic |
---|
42 | * server add, change and remove priority nodes. |
---|
43 | * |
---|
44 | * @{ |
---|
45 | */ |
---|
46 | |
---|
47 | /** |
---|
48 | * @brief The thread priority control. |
---|
49 | * |
---|
50 | * Lower values represent higher priorities. So, a priority value of zero |
---|
51 | * represents the highest priority thread. This value is reserved for internal |
---|
52 | * threads and the priority ceiling protocol. |
---|
53 | * |
---|
54 | * The format of the thread priority control depends on the context. A thread |
---|
55 | * priority control may contain a user visible priority for API import/export. |
---|
56 | * It may also contain a scheduler internal priority value. Values are |
---|
57 | * translated via the scheduler map/unmap priority operations. The format of |
---|
58 | * scheduler interal values depend on the particular scheduler implementation. |
---|
59 | * It may for example encode a deadline in case of the EDF scheduler. |
---|
60 | * |
---|
61 | * The thread priority control value contained in the scheduler node |
---|
62 | * (Scheduler_Node::Priority::value) uses the least-significant bit to indicate |
---|
63 | * if the thread should be appended or prepended to its priority group, see |
---|
64 | * SCHEDULER_PRIORITY_APPEND(). |
---|
65 | */ |
---|
66 | typedef uint64_t Priority_Control; |
---|
67 | |
---|
68 | /** |
---|
69 | * @brief The highest (most important) thread priority value. |
---|
70 | */ |
---|
71 | #define PRIORITY_MINIMUM 0 |
---|
72 | |
---|
73 | /** |
---|
74 | * @brief The priority value of pseudo-ISR threads. |
---|
75 | * |
---|
76 | * Examples are the MPCI and timer server threads. |
---|
77 | */ |
---|
78 | #define PRIORITY_PSEUDO_ISR PRIORITY_MINIMUM |
---|
79 | |
---|
80 | /** |
---|
81 | * @brief The default lowest (least important) thread priority value. |
---|
82 | * |
---|
83 | * This value is CPU port dependent. |
---|
84 | */ |
---|
85 | #if defined (CPU_PRIORITY_MAXIMUM) |
---|
86 | #define PRIORITY_DEFAULT_MAXIMUM CPU_PRIORITY_MAXIMUM |
---|
87 | #else |
---|
88 | #define PRIORITY_DEFAULT_MAXIMUM 255 |
---|
89 | #endif |
---|
90 | |
---|
91 | /** |
---|
92 | * @brief The priority node to build up a priority aggregation. |
---|
93 | */ |
---|
94 | typedef struct { |
---|
95 | /** |
---|
96 | * @brief Node component for a chain or red-black tree. |
---|
97 | */ |
---|
98 | union { |
---|
99 | Chain_Node Chain; |
---|
100 | RBTree_Node RBTree; |
---|
101 | } Node; |
---|
102 | |
---|
103 | /** |
---|
104 | * @brief The priority value of this node. |
---|
105 | */ |
---|
106 | Priority_Control priority; |
---|
107 | } Priority_Node; |
---|
108 | |
---|
109 | /** |
---|
110 | * @brief The priority action type. |
---|
111 | */ |
---|
112 | typedef enum { |
---|
113 | PRIORITY_ACTION_ADD, |
---|
114 | PRIORITY_ACTION_CHANGE, |
---|
115 | PRIORITY_ACTION_REMOVE, |
---|
116 | PRIORITY_ACTION_INVALID |
---|
117 | } Priority_Action_type; |
---|
118 | |
---|
119 | typedef struct Priority_Aggregation Priority_Aggregation; |
---|
120 | |
---|
121 | /** |
---|
122 | * @brief The priority aggregation. |
---|
123 | * |
---|
124 | * This structure serves two purposes. Firstly, it provides a place to |
---|
125 | * register priority nodes and reflects the overall priority of its |
---|
126 | * contributors. Secondly, it provides an action block to signal addition, |
---|
127 | * change and removal of a priority node. |
---|
128 | */ |
---|
129 | struct Priority_Aggregation { |
---|
130 | /** |
---|
131 | * @brief This priority node reflects the overall priority of the aggregation. |
---|
132 | * |
---|
133 | * The overall priority of the aggregation is the minimum priority of the |
---|
134 | * priority nodes in the contributors tree. |
---|
135 | * |
---|
136 | * This priority node may be used to add this aggregation to another |
---|
137 | * aggregation to build up a recursive priority scheme. |
---|
138 | * |
---|
139 | * In case priority nodes of the contributors tree are added, changed or |
---|
140 | * removed the priority of this node may change. To signal such changes to a |
---|
141 | * priority aggregation the action block may be used. |
---|
142 | */ |
---|
143 | Priority_Node Node; |
---|
144 | |
---|
145 | /** |
---|
146 | * @brief A red-black tree to contain priority nodes contributing to the |
---|
147 | * overall priority of this priority aggregation. |
---|
148 | */ |
---|
149 | RBTree_Control Contributors; |
---|
150 | |
---|
151 | #if defined(RTEMS_SMP) |
---|
152 | /** |
---|
153 | * @brief The scheduler instance of this priority aggregation. |
---|
154 | */ |
---|
155 | const struct _Scheduler_Control *scheduler; |
---|
156 | #endif |
---|
157 | |
---|
158 | /** |
---|
159 | * @brief A priority action block to manage priority node additions, changes |
---|
160 | * and removals. |
---|
161 | */ |
---|
162 | struct { |
---|
163 | #if defined(RTEMS_SMP) |
---|
164 | /** |
---|
165 | * @brief The next priority aggregation in the action list. |
---|
166 | */ |
---|
167 | Priority_Aggregation *next; |
---|
168 | #endif |
---|
169 | |
---|
170 | /** |
---|
171 | * @brief The priority node of the action. |
---|
172 | */ |
---|
173 | Priority_Node *node; |
---|
174 | |
---|
175 | /** |
---|
176 | * @brief The type of the action. |
---|
177 | */ |
---|
178 | Priority_Action_type type; |
---|
179 | } Action; |
---|
180 | }; |
---|
181 | |
---|
182 | /** |
---|
183 | * @brief A list of priority actions. |
---|
184 | * |
---|
185 | * Actions are only added to the list. The action lists reside on the stack |
---|
186 | * and have a short life-time. They are moved, processed or destroyed as a |
---|
187 | * whole. |
---|
188 | */ |
---|
189 | typedef struct { |
---|
190 | /** |
---|
191 | * @brief The first action of a priority action list. |
---|
192 | */ |
---|
193 | Priority_Aggregation *actions; |
---|
194 | } Priority_Actions; |
---|
195 | |
---|
196 | #ifdef __cplusplus |
---|
197 | } |
---|
198 | #endif |
---|
199 | |
---|
200 | /**@}*/ |
---|
201 | |
---|
202 | #endif |
---|
203 | /* end of include file */ |
---|