[20f02c6] | 1 | /** |
---|
[300f6a48] | 2 | * @file |
---|
[ac7d5ef0] | 3 | * |
---|
[300f6a48] | 4 | * @brief Priority Handler API |
---|
[baff4da] | 5 | */ |
---|
| 6 | |
---|
| 7 | /* |
---|
[21242c2] | 8 | * COPYRIGHT (c) 1989-2011. |
---|
[ac7d5ef0] | 9 | * On-Line Applications Research Corporation (OAR). |
---|
| 10 | * |
---|
[c597fb1] | 11 | * Copyright (c) 2016, 2017 embedded brains GmbH. |
---|
[300f6a48] | 12 | * |
---|
[98e4ebf5] | 13 | * The license and distribution terms for this file may be |
---|
| 14 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 15 | * http://www.rtems.org/license/LICENSE. |
---|
[ac7d5ef0] | 16 | */ |
---|
| 17 | |
---|
[092f142a] | 18 | #ifndef _RTEMS_SCORE_PRIORITY_H |
---|
| 19 | #define _RTEMS_SCORE_PRIORITY_H |
---|
[ac7d5ef0] | 20 | |
---|
[300f6a48] | 21 | #include <rtems/score/chain.h> |
---|
[a552181] | 22 | #include <rtems/score/cpu.h> |
---|
[300f6a48] | 23 | #include <rtems/score/rbtree.h> |
---|
| 24 | |
---|
[e460cd00] | 25 | struct _Scheduler_Control; |
---|
[a552181] | 26 | |
---|
[b02f920f] | 27 | #ifdef __cplusplus |
---|
| 28 | extern "C" { |
---|
| 29 | #endif |
---|
| 30 | |
---|
[6a07436] | 31 | /** |
---|
[300f6a48] | 32 | * @defgroup ScorePriority Priority Handler |
---|
| 33 | * |
---|
| 34 | * @ingroup Score |
---|
| 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 | /** |
---|
[c597fb1] | 48 | * @brief The thread priority control. |
---|
[ac7d5ef0] | 49 | * |
---|
[300f6a48] | 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. |
---|
[c597fb1] | 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(). |
---|
[ac7d5ef0] | 65 | */ |
---|
[254dc82] | 66 | typedef uint64_t Priority_Control; |
---|
[ac7d5ef0] | 67 | |
---|
[300f6a48] | 68 | /** |
---|
| 69 | * @brief The highest (most important) thread priority value. |
---|
| 70 | */ |
---|
[6a07436] | 71 | #define PRIORITY_MINIMUM 0 |
---|
[a552181] | 72 | |
---|
[81b03c6] | 73 | /** |
---|
[300f6a48] | 74 | * @brief The priority value of pseudo-ISR threads. |
---|
[81b03c6] | 75 | * |
---|
| 76 | * Examples are the MPCI and timer server threads. |
---|
| 77 | */ |
---|
| 78 | #define PRIORITY_PSEUDO_ISR PRIORITY_MINIMUM |
---|
| 79 | |
---|
[300f6a48] | 80 | /** |
---|
| 81 | * @brief The default lowest (least important) thread priority value. |
---|
| 82 | * |
---|
| 83 | * This value is CPU port dependent. |
---|
| 84 | */ |
---|
[a552181] | 85 | #if defined (CPU_PRIORITY_MAXIMUM) |
---|
[80f9d77] | 86 | #define PRIORITY_DEFAULT_MAXIMUM CPU_PRIORITY_MAXIMUM |
---|
[a552181] | 87 | #else |
---|
[80f9d77] | 88 | #define PRIORITY_DEFAULT_MAXIMUM 255 |
---|
[a552181] | 89 | #endif |
---|
[ac7d5ef0] | 90 | |
---|
[300f6a48] | 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 | */ |
---|
[e460cd00] | 155 | const struct _Scheduler_Control *scheduler; |
---|
[300f6a48] | 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 | |
---|
[ac7d5ef0] | 196 | #ifdef __cplusplus |
---|
| 197 | } |
---|
| 198 | #endif |
---|
| 199 | |
---|
[baff4da] | 200 | /**@}*/ |
---|
| 201 | |
---|
[ac7d5ef0] | 202 | #endif |
---|
[b10825c] | 203 | /* end of include file */ |
---|