[a936aa49] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @brief Simple SMP Scheduler Implementation |
---|
| 5 | * |
---|
[beab7329] | 6 | * @ingroup ScoreSchedulerSMPSimple |
---|
[a936aa49] | 7 | */ |
---|
| 8 | |
---|
| 9 | /* |
---|
[494c2e3] | 10 | * Copyright (c) 2013-2014 embedded brains GmbH. |
---|
[a936aa49] | 11 | * |
---|
| 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 14 | * http://www.rtems.org/license/LICENSE. |
---|
[a936aa49] | 15 | */ |
---|
| 16 | |
---|
| 17 | #if HAVE_CONFIG_H |
---|
| 18 | #include "config.h" |
---|
| 19 | #endif |
---|
| 20 | |
---|
| 21 | #include <rtems/score/schedulersimplesmp.h> |
---|
[9d83f58a] | 22 | #include <rtems/score/schedulersmpimpl.h> |
---|
[a936aa49] | 23 | |
---|
[e1598a6] | 24 | static Scheduler_simple_SMP_Context * |
---|
| 25 | _Scheduler_simple_SMP_Get_context( const Scheduler_Control *scheduler ) |
---|
[494c2e3] | 26 | { |
---|
[2369b10] | 27 | return (Scheduler_simple_SMP_Context *) _Scheduler_Get_context( scheduler ); |
---|
[494c2e3] | 28 | } |
---|
| 29 | |
---|
[e1598a6] | 30 | static Scheduler_simple_SMP_Context * |
---|
[3730a07f] | 31 | _Scheduler_simple_SMP_Get_self( Scheduler_Context *context ) |
---|
[494c2e3] | 32 | { |
---|
[3730a07f] | 33 | return (Scheduler_simple_SMP_Context *) context; |
---|
[494c2e3] | 34 | } |
---|
| 35 | |
---|
[e9ee2f0] | 36 | void _Scheduler_simple_SMP_Initialize( const Scheduler_Control *scheduler ) |
---|
[a936aa49] | 37 | { |
---|
[e1598a6] | 38 | Scheduler_simple_SMP_Context *self = |
---|
| 39 | _Scheduler_simple_SMP_Get_context( scheduler ); |
---|
[a936aa49] | 40 | |
---|
[494c2e3] | 41 | _Scheduler_SMP_Initialize( &self->Base ); |
---|
| 42 | _Chain_Initialize_empty( &self->Ready ); |
---|
[a936aa49] | 43 | } |
---|
| 44 | |
---|
[e9ee2f0] | 45 | bool _Scheduler_simple_SMP_Allocate( |
---|
[beab7329] | 46 | const Scheduler_Control *scheduler, |
---|
| 47 | Thread_Control *the_thread |
---|
| 48 | ) |
---|
| 49 | { |
---|
| 50 | Scheduler_SMP_Node *node = _Scheduler_SMP_Node_get( the_thread ); |
---|
| 51 | |
---|
| 52 | _Scheduler_SMP_Node_initialize( node ); |
---|
| 53 | |
---|
| 54 | return true; |
---|
| 55 | } |
---|
| 56 | |
---|
[f39f667a] | 57 | static void _Scheduler_simple_SMP_Do_update( |
---|
| 58 | Scheduler_Context *context, |
---|
| 59 | Scheduler_Node *node, |
---|
| 60 | Priority_Control new_priority |
---|
| 61 | ) |
---|
| 62 | { |
---|
| 63 | (void) context; |
---|
| 64 | (void) node; |
---|
| 65 | (void) new_priority; |
---|
| 66 | } |
---|
| 67 | |
---|
[e9ee2f0] | 68 | static Thread_Control *_Scheduler_simple_SMP_Get_highest_ready( |
---|
[3730a07f] | 69 | Scheduler_Context *context |
---|
[aea4a91] | 70 | ) |
---|
| 71 | { |
---|
[e1598a6] | 72 | Scheduler_simple_SMP_Context *self = |
---|
[3730a07f] | 73 | _Scheduler_simple_SMP_Get_self( context ); |
---|
[aea4a91] | 74 | |
---|
[f39f667a] | 75 | return (Thread_Control *) _Chain_First( &self->Ready ); |
---|
[aea4a91] | 76 | } |
---|
| 77 | |
---|
[e9ee2f0] | 78 | static void _Scheduler_simple_SMP_Move_from_scheduled_to_ready( |
---|
[3730a07f] | 79 | Scheduler_Context *context, |
---|
[a936aa49] | 80 | Thread_Control *scheduled_to_ready |
---|
| 81 | ) |
---|
| 82 | { |
---|
[e1598a6] | 83 | Scheduler_simple_SMP_Context *self = |
---|
[3730a07f] | 84 | _Scheduler_simple_SMP_Get_self( context ); |
---|
[494c2e3] | 85 | |
---|
[a936aa49] | 86 | _Chain_Extract_unprotected( &scheduled_to_ready->Object.Node ); |
---|
[aea4a91] | 87 | _Scheduler_simple_Insert_priority_lifo( |
---|
[494c2e3] | 88 | &self->Ready, |
---|
[aea4a91] | 89 | scheduled_to_ready |
---|
| 90 | ); |
---|
[a936aa49] | 91 | } |
---|
| 92 | |
---|
[e9ee2f0] | 93 | static void _Scheduler_simple_SMP_Move_from_ready_to_scheduled( |
---|
[3730a07f] | 94 | Scheduler_Context *context, |
---|
[a936aa49] | 95 | Thread_Control *ready_to_scheduled |
---|
| 96 | ) |
---|
| 97 | { |
---|
[3730a07f] | 98 | Scheduler_simple_SMP_Context *self = |
---|
| 99 | _Scheduler_simple_SMP_Get_self( context ); |
---|
| 100 | |
---|
[a936aa49] | 101 | _Chain_Extract_unprotected( &ready_to_scheduled->Object.Node ); |
---|
[aea4a91] | 102 | _Scheduler_simple_Insert_priority_fifo( |
---|
[3730a07f] | 103 | &self->Base.Scheduled, |
---|
[aea4a91] | 104 | ready_to_scheduled |
---|
| 105 | ); |
---|
[a936aa49] | 106 | } |
---|
| 107 | |
---|
[e9ee2f0] | 108 | static void _Scheduler_simple_SMP_Insert_ready_lifo( |
---|
[3730a07f] | 109 | Scheduler_Context *context, |
---|
[48c4a55] | 110 | Thread_Control *thread |
---|
[a936aa49] | 111 | ) |
---|
| 112 | { |
---|
[e1598a6] | 113 | Scheduler_simple_SMP_Context *self = |
---|
[3730a07f] | 114 | _Scheduler_simple_SMP_Get_self( context ); |
---|
[494c2e3] | 115 | |
---|
[48c4a55] | 116 | _Chain_Insert_ordered_unprotected( |
---|
[494c2e3] | 117 | &self->Ready, |
---|
[48c4a55] | 118 | &thread->Object.Node, |
---|
| 119 | _Scheduler_simple_Insert_priority_lifo_order |
---|
| 120 | ); |
---|
[a936aa49] | 121 | } |
---|
| 122 | |
---|
[e9ee2f0] | 123 | static void _Scheduler_simple_SMP_Insert_ready_fifo( |
---|
[3730a07f] | 124 | Scheduler_Context *context, |
---|
[48c4a55] | 125 | Thread_Control *thread |
---|
[aea4a91] | 126 | ) |
---|
| 127 | { |
---|
[e1598a6] | 128 | Scheduler_simple_SMP_Context *self = |
---|
[3730a07f] | 129 | _Scheduler_simple_SMP_Get_self( context ); |
---|
[494c2e3] | 130 | |
---|
[48c4a55] | 131 | _Chain_Insert_ordered_unprotected( |
---|
[494c2e3] | 132 | &self->Ready, |
---|
[48c4a55] | 133 | &thread->Object.Node, |
---|
| 134 | _Scheduler_simple_Insert_priority_fifo_order |
---|
| 135 | ); |
---|
[aea4a91] | 136 | } |
---|
| 137 | |
---|
[f39f667a] | 138 | static void _Scheduler_simple_SMP_Extract_from_ready( |
---|
[3730a07f] | 139 | Scheduler_Context *context, |
---|
[48c4a55] | 140 | Thread_Control *thread |
---|
[a936aa49] | 141 | ) |
---|
| 142 | { |
---|
[3730a07f] | 143 | (void) context; |
---|
[a936aa49] | 144 | |
---|
[48c4a55] | 145 | _Chain_Extract_unprotected( &thread->Object.Node ); |
---|
[aea4a91] | 146 | } |
---|
[a936aa49] | 147 | |
---|
[e9ee2f0] | 148 | void _Scheduler_simple_SMP_Block( |
---|
[e1598a6] | 149 | const Scheduler_Control *scheduler, |
---|
[24934e36] | 150 | Thread_Control *thread |
---|
| 151 | ) |
---|
[aea4a91] | 152 | { |
---|
[f39f667a] | 153 | Scheduler_Context *context = _Scheduler_Get_context( scheduler ); |
---|
[a936aa49] | 154 | |
---|
[48c4a55] | 155 | _Scheduler_SMP_Block( |
---|
[f39f667a] | 156 | context, |
---|
[48c4a55] | 157 | thread, |
---|
[f39f667a] | 158 | _Scheduler_simple_SMP_Extract_from_ready, |
---|
[e9ee2f0] | 159 | _Scheduler_simple_SMP_Get_highest_ready, |
---|
| 160 | _Scheduler_simple_SMP_Move_from_ready_to_scheduled |
---|
[48c4a55] | 161 | ); |
---|
| 162 | } |
---|
[a936aa49] | 163 | |
---|
[e9ee2f0] | 164 | static void _Scheduler_simple_SMP_Enqueue_ordered( |
---|
[3730a07f] | 165 | Scheduler_Context *context, |
---|
[48c4a55] | 166 | Thread_Control *thread, |
---|
| 167 | Chain_Node_order order, |
---|
| 168 | Scheduler_SMP_Insert insert_ready, |
---|
| 169 | Scheduler_SMP_Insert insert_scheduled |
---|
| 170 | ) |
---|
| 171 | { |
---|
| 172 | _Scheduler_SMP_Enqueue_ordered( |
---|
[3730a07f] | 173 | context, |
---|
[48c4a55] | 174 | thread, |
---|
| 175 | order, |
---|
| 176 | insert_ready, |
---|
| 177 | insert_scheduled, |
---|
[e9ee2f0] | 178 | _Scheduler_simple_SMP_Move_from_scheduled_to_ready |
---|
[48c4a55] | 179 | ); |
---|
[a936aa49] | 180 | } |
---|
| 181 | |
---|
[f39f667a] | 182 | static void _Scheduler_simple_SMP_Enqueue_lifo( |
---|
| 183 | Scheduler_Context *context, |
---|
[c0bff5e] | 184 | Thread_Control *thread |
---|
[24934e36] | 185 | ) |
---|
[a936aa49] | 186 | { |
---|
[e9ee2f0] | 187 | _Scheduler_simple_SMP_Enqueue_ordered( |
---|
[f39f667a] | 188 | context, |
---|
[a936aa49] | 189 | thread, |
---|
[48c4a55] | 190 | _Scheduler_simple_Insert_priority_lifo_order, |
---|
[e9ee2f0] | 191 | _Scheduler_simple_SMP_Insert_ready_lifo, |
---|
[48c4a55] | 192 | _Scheduler_SMP_Insert_scheduled_lifo |
---|
[a936aa49] | 193 | ); |
---|
| 194 | } |
---|
| 195 | |
---|
[f39f667a] | 196 | static void _Scheduler_simple_SMP_Enqueue_fifo( |
---|
| 197 | Scheduler_Context *context, |
---|
[c0bff5e] | 198 | Thread_Control *thread |
---|
[24934e36] | 199 | ) |
---|
[a936aa49] | 200 | { |
---|
[e9ee2f0] | 201 | _Scheduler_simple_SMP_Enqueue_ordered( |
---|
[f39f667a] | 202 | context, |
---|
[a936aa49] | 203 | thread, |
---|
[c0bff5e] | 204 | _Scheduler_simple_Insert_priority_fifo_order, |
---|
| 205 | _Scheduler_simple_SMP_Insert_ready_fifo, |
---|
| 206 | _Scheduler_SMP_Insert_scheduled_fifo |
---|
| 207 | ); |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | static void _Scheduler_simple_SMP_Enqueue_scheduled_ordered( |
---|
| 211 | Scheduler_Context *context, |
---|
| 212 | Thread_Control *thread, |
---|
| 213 | Chain_Node_order order, |
---|
| 214 | Scheduler_SMP_Insert insert_ready, |
---|
| 215 | Scheduler_SMP_Insert insert_scheduled |
---|
| 216 | ) |
---|
| 217 | { |
---|
| 218 | _Scheduler_SMP_Enqueue_scheduled_ordered( |
---|
| 219 | context, |
---|
| 220 | thread, |
---|
| 221 | order, |
---|
| 222 | _Scheduler_simple_SMP_Get_highest_ready, |
---|
| 223 | insert_ready, |
---|
| 224 | insert_scheduled, |
---|
| 225 | _Scheduler_simple_SMP_Move_from_ready_to_scheduled |
---|
| 226 | ); |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | static void _Scheduler_simple_SMP_Enqueue_scheduled_lifo( |
---|
| 230 | Scheduler_Context *context, |
---|
| 231 | Thread_Control *thread |
---|
| 232 | ) |
---|
| 233 | { |
---|
| 234 | _Scheduler_simple_SMP_Enqueue_scheduled_ordered( |
---|
| 235 | context, |
---|
| 236 | thread, |
---|
| 237 | _Scheduler_simple_Insert_priority_lifo_order, |
---|
| 238 | _Scheduler_simple_SMP_Insert_ready_lifo, |
---|
| 239 | _Scheduler_SMP_Insert_scheduled_lifo |
---|
| 240 | ); |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | static void _Scheduler_simple_SMP_Enqueue_scheduled_fifo( |
---|
| 244 | Scheduler_Context *context, |
---|
| 245 | Thread_Control *thread |
---|
| 246 | ) |
---|
| 247 | { |
---|
| 248 | _Scheduler_simple_SMP_Enqueue_scheduled_ordered( |
---|
| 249 | context, |
---|
| 250 | thread, |
---|
[48c4a55] | 251 | _Scheduler_simple_Insert_priority_fifo_order, |
---|
[e9ee2f0] | 252 | _Scheduler_simple_SMP_Insert_ready_fifo, |
---|
[48c4a55] | 253 | _Scheduler_SMP_Insert_scheduled_fifo |
---|
[a936aa49] | 254 | ); |
---|
| 255 | } |
---|
| 256 | |
---|
[f39f667a] | 257 | void _Scheduler_simple_SMP_Unblock( |
---|
[e1598a6] | 258 | const Scheduler_Control *scheduler, |
---|
[24934e36] | 259 | Thread_Control *thread |
---|
| 260 | ) |
---|
[a936aa49] | 261 | { |
---|
[f39f667a] | 262 | Scheduler_Context *context = _Scheduler_Get_context( scheduler ); |
---|
| 263 | |
---|
[c0bff5e] | 264 | _Scheduler_SMP_Unblock( |
---|
| 265 | context, |
---|
| 266 | thread, |
---|
| 267 | _Scheduler_simple_SMP_Enqueue_fifo |
---|
| 268 | ); |
---|
[f39f667a] | 269 | } |
---|
[a936aa49] | 270 | |
---|
[f39f667a] | 271 | void _Scheduler_simple_SMP_Change_priority( |
---|
| 272 | const Scheduler_Control *scheduler, |
---|
| 273 | Thread_Control *thread, |
---|
| 274 | Priority_Control new_priority, |
---|
| 275 | bool prepend_it |
---|
| 276 | ) |
---|
| 277 | { |
---|
| 278 | Scheduler_Context *context = _Scheduler_Get_context( scheduler ); |
---|
| 279 | |
---|
| 280 | _Scheduler_SMP_Change_priority( |
---|
| 281 | context, |
---|
[48c4a55] | 282 | thread, |
---|
[f39f667a] | 283 | new_priority, |
---|
| 284 | prepend_it, |
---|
| 285 | _Scheduler_simple_SMP_Extract_from_ready, |
---|
| 286 | _Scheduler_simple_SMP_Do_update, |
---|
| 287 | _Scheduler_simple_SMP_Enqueue_fifo, |
---|
[c0bff5e] | 288 | _Scheduler_simple_SMP_Enqueue_lifo, |
---|
| 289 | _Scheduler_simple_SMP_Enqueue_scheduled_fifo, |
---|
| 290 | _Scheduler_simple_SMP_Enqueue_scheduled_lifo |
---|
[48c4a55] | 291 | ); |
---|
[a936aa49] | 292 | } |
---|
| 293 | |
---|
[e9ee2f0] | 294 | void _Scheduler_simple_SMP_Yield( |
---|
[e1598a6] | 295 | const Scheduler_Control *scheduler, |
---|
[24934e36] | 296 | Thread_Control *thread |
---|
| 297 | ) |
---|
[a936aa49] | 298 | { |
---|
[f39f667a] | 299 | Scheduler_Context *context = _Scheduler_Get_context( scheduler ); |
---|
[a936aa49] | 300 | ISR_Level level; |
---|
| 301 | |
---|
| 302 | _ISR_Disable( level ); |
---|
| 303 | |
---|
[f39f667a] | 304 | _Scheduler_SMP_Extract_from_scheduled( thread ); |
---|
[c0bff5e] | 305 | _Scheduler_simple_SMP_Enqueue_scheduled_fifo( context, thread ); |
---|
[a936aa49] | 306 | |
---|
| 307 | _ISR_Enable( level ); |
---|
| 308 | } |
---|