[e27421f] | 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 | |
---|
[ebdd2a3] | 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 | |
---|
[e27421f] | 62 | /** |
---|
| 63 | * @brief Scheduler node for per-thread data. |
---|
| 64 | */ |
---|
[ebdd2a3] | 65 | struct Scheduler_Node { |
---|
[e27421f] | 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 | * The node is here to simplify things, just like the object node in the |
---|
| 74 | * thread control block. It may be replaced with a union to add a red-black |
---|
| 75 | * tree node in the future. |
---|
| 76 | */ |
---|
| 77 | Chain_Node Node; |
---|
| 78 | |
---|
| 79 | /** |
---|
[6771359f] | 80 | * @brief The sticky level determines if this scheduler node should use an |
---|
| 81 | * idle thread in case this node is scheduled and the owner thread is |
---|
| 82 | * blocked. |
---|
[e27421f] | 83 | */ |
---|
[6771359f] | 84 | int sticky_level; |
---|
[e27421f] | 85 | |
---|
| 86 | /** |
---|
[6771359f] | 87 | * @brief The thread using this node. |
---|
| 88 | * |
---|
| 89 | * This is either the owner or an idle thread. |
---|
[e27421f] | 90 | */ |
---|
[6771359f] | 91 | struct _Thread_Control *user; |
---|
[e27421f] | 92 | |
---|
| 93 | /** |
---|
[6771359f] | 94 | * @brief The idle thread claimed by this node in case the sticky level is |
---|
| 95 | * greater than zero and the thread is block or is scheduled on another |
---|
| 96 | * scheduler instance. |
---|
[e27421f] | 97 | * |
---|
[6771359f] | 98 | * This is necessary to ensure the priority ceiling protocols work across |
---|
| 99 | * scheduler boundaries. |
---|
[e27421f] | 100 | */ |
---|
| 101 | struct _Thread_Control *idle; |
---|
[6771359f] | 102 | #endif |
---|
[e27421f] | 103 | |
---|
[6771359f] | 104 | /** |
---|
| 105 | * @brief The thread owning this node. |
---|
| 106 | */ |
---|
| 107 | struct _Thread_Control *owner; |
---|
| 108 | |
---|
| 109 | #if defined(RTEMS_SMP) |
---|
[266d383] | 110 | /** |
---|
| 111 | * @brief Block to register and manage this scheduler node in the thread |
---|
| 112 | * control block of the owner of this scheduler node. |
---|
| 113 | */ |
---|
| 114 | struct { |
---|
| 115 | /** |
---|
| 116 | * @brief Node to add this scheduler node to |
---|
| 117 | * Thread_Control::Scheduler::Wait_nodes. |
---|
| 118 | */ |
---|
| 119 | Chain_Node Wait_node; |
---|
[ebdd2a3] | 120 | |
---|
| 121 | /** |
---|
| 122 | * @brief Node to add this scheduler node to |
---|
[2403473] | 123 | * Thread_Control::Scheduler::Scheduler_nodes or a temporary remove list. |
---|
[ebdd2a3] | 124 | */ |
---|
| 125 | union { |
---|
| 126 | /** |
---|
| 127 | * @brief The node for Thread_Control::Scheduler::Scheduler_nodes. |
---|
| 128 | */ |
---|
| 129 | Chain_Node Chain; |
---|
[2403473] | 130 | |
---|
| 131 | /** |
---|
| 132 | * @brief The next pointer for a temporary remove list. |
---|
| 133 | * |
---|
| 134 | * @see _Thread_Scheduler_process_requests(). |
---|
| 135 | */ |
---|
| 136 | Scheduler_Node *next; |
---|
[ebdd2a3] | 137 | } Scheduler_node; |
---|
| 138 | |
---|
| 139 | /** |
---|
| 140 | * @brief Link to the next scheduler node in the |
---|
| 141 | * Thread_Control::Scheduler::requests list. |
---|
| 142 | */ |
---|
| 143 | Scheduler_Node *next_request; |
---|
| 144 | |
---|
| 145 | /** |
---|
| 146 | * @brief The current scheduler node request. |
---|
| 147 | */ |
---|
| 148 | Scheduler_Node_request request; |
---|
[266d383] | 149 | } Thread; |
---|
[e27421f] | 150 | #endif |
---|
| 151 | |
---|
[15b5678d] | 152 | /** |
---|
| 153 | * @brief Thread wait support block. |
---|
| 154 | */ |
---|
| 155 | struct { |
---|
[300f6a48] | 156 | Priority_Aggregation Priority; |
---|
[15b5678d] | 157 | } Wait; |
---|
| 158 | |
---|
[e27421f] | 159 | /** |
---|
| 160 | * @brief The thread priority information used by the scheduler. |
---|
| 161 | * |
---|
| 162 | * The thread priority is manifest in two independent areas. One area is the |
---|
| 163 | * user visible thread priority along with a potential thread queue. The |
---|
| 164 | * other is the scheduler. During a thread priority change, the user visible |
---|
| 165 | * thread priority and the thread queue are first updated and the thread |
---|
| 166 | * priority value here is changed. Once this is done the scheduler is |
---|
| 167 | * notified via the update priority operation, so that it can update its |
---|
| 168 | * internal state and honour a new thread priority value. |
---|
| 169 | */ |
---|
| 170 | struct { |
---|
| 171 | /** |
---|
| 172 | * @brief The thread priority value of this scheduler node. |
---|
| 173 | * |
---|
| 174 | * The producer of this value is _Thread_Change_priority(). The consumer |
---|
| 175 | * is the scheduler via the unblock and update priority operations. |
---|
| 176 | */ |
---|
| 177 | Priority_Control value; |
---|
| 178 | |
---|
| 179 | #if defined(RTEMS_SMP) |
---|
| 180 | /** |
---|
| 181 | * @brief Sequence lock to synchronize priority value updates. |
---|
| 182 | */ |
---|
| 183 | SMP_sequence_lock_Control Lock; |
---|
| 184 | #endif |
---|
| 185 | |
---|
| 186 | /** |
---|
| 187 | * @brief In case a priority update is necessary and this is true, then |
---|
| 188 | * enqueue the thread as the first of its priority group, otherwise enqueue |
---|
| 189 | * the thread as the last of its priority group. |
---|
| 190 | */ |
---|
| 191 | bool prepend_it; |
---|
| 192 | } Priority; |
---|
[ebdd2a3] | 193 | }; |
---|
[e27421f] | 194 | |
---|
[5d6b211] | 195 | #if defined(RTEMS_SMP) |
---|
| 196 | /** |
---|
| 197 | * @brief The size of a scheduler node. |
---|
| 198 | * |
---|
| 199 | * This value is provided via <rtems/confdefs.h>. |
---|
| 200 | */ |
---|
| 201 | extern const size_t _Scheduler_Node_size; |
---|
| 202 | #endif |
---|
| 203 | |
---|
[f6142c19] | 204 | #if defined(RTEMS_SMP) |
---|
| 205 | #define SCHEDULER_NODE_OF_THREAD_WAIT_NODE( node ) \ |
---|
| 206 | RTEMS_CONTAINER_OF( node, Scheduler_Node, Thread.Wait_node ) |
---|
[ebdd2a3] | 207 | |
---|
| 208 | #define SCHEDULER_NODE_OF_THREAD_SCHEDULER_NODE( node ) \ |
---|
| 209 | RTEMS_CONTAINER_OF( node, Scheduler_Node, Thread.Scheduler_node.Chain ) |
---|
[f6142c19] | 210 | #endif |
---|
| 211 | |
---|
[e27421f] | 212 | #ifdef __cplusplus |
---|
| 213 | } |
---|
| 214 | #endif /* __cplusplus */ |
---|
| 215 | |
---|
| 216 | #endif /* _RTEMS_SCORE_SCHEDULERNODE_H */ |
---|