source: rtems/cpukit/score/include/rtems/score/schedulersmpimpl.h @ 8568341

4.115
Last change on this file since 8568341 was 8568341, checked in by Sebastian Huber <sebastian.huber@…>, on 06/11/14 at 12:31:03

score: Need for help indicator for scheduler ops

Return a thread in need for help for the following scheduler operations

  • unblock,
  • change priority, and
  • yield.

A thread in need for help is a thread that encounters a scheduler state
change from scheduled to ready or a thread that cannot be scheduled in
an unblock operation. Such a thread can ask threads which depend on
resources owned by this thread for help.

  • Property mode set to 100644
File size: 20.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief SMP Scheduler Implementation
5 *
6 * @ingroup ScoreSchedulerSMP
7 */
8
9/*
10 * Copyright (c) 2013-2014 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Dornierstr. 4
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#ifndef _RTEMS_SCORE_SCHEDULERSMPIMPL_H
24#define _RTEMS_SCORE_SCHEDULERSMPIMPL_H
25
26#include <rtems/score/schedulersmp.h>
27#include <rtems/score/assert.h>
28#include <rtems/score/chainimpl.h>
29#include <rtems/score/schedulersimpleimpl.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif /* __cplusplus */
34
35/**
36 * @addtogroup ScoreSchedulerSMP
37 *
38 * The scheduler nodes can be in four states
39 * - @ref SCHEDULER_SMP_NODE_BLOCKED,
40 * - @ref SCHEDULER_SMP_NODE_SCHEDULED, and
41 * - @ref SCHEDULER_SMP_NODE_READY.
42 *
43 * State transitions are triggered via basic operations
44 * - _Scheduler_SMP_Enqueue_ordered(),
45 * - _Scheduler_SMP_Enqueue_scheduled_ordered(), and
46 * - _Scheduler_SMP_Block().
47 *
48 * @dot
49 * digraph {
50 *   node [style="filled"];
51 *
52 *   bs [label="BLOCKED"];
53 *   ss [label="SCHEDULED", fillcolor="green"];
54 *   rs [label="READY", fillcolor="red"];
55 *
56 *   edge [label="enqueue"];
57 *   edge [fontcolor="darkgreen", color="darkgreen"];
58 *
59 *   bs -> ss;
60 *
61 *   edge [fontcolor="red", color="red"];
62 *
63 *   bs -> rs;
64 *
65 *   edge [label="enqueue other"];
66 *
67 *   ss -> rs;
68 *
69 *   edge [label="block"];
70 *   edge [fontcolor="black", color="black"];
71 *
72 *   ss -> bs;
73 *   rs -> bs;
74 *
75 *   edge [label="block other"];
76 *   edge [fontcolor="darkgreen", color="darkgreen"];
77 *
78 *   rs -> ss;
79 * }
80 * @enddot
81 *
82 * During system initialization each processor of the scheduler instance starts
83 * with an idle thread assigned to it.  Lets have a look at an example with two
84 * idle threads I and J with priority 5.  We also have blocked threads A, B and
85 * C with priorities 1, 2 and 3 respectively.  The scheduler nodes are ordered
86 * with respect to the thread priority from left to right in the below
87 * diagrams.  The highest priority node (lowest priority number) is the
88 * leftmost node.  Since the processor assignment is independent of the thread
89 * priority the processor indices may move from one state to the other.
90 *
91 * @dot
92 * digraph {
93 *   node [style="filled"];
94 *   edge [dir="none"];
95 *   subgraph {
96 *     rank = same;
97 *
98 *     i [label="I (5)", fillcolor="green"];
99 *     j [label="J (5)", fillcolor="green"];
100 *     a [label="A (1)"];
101 *     b [label="B (2)"];
102 *     c [label="C (3)"];
103 *     i -> j;
104 *   }
105 *
106 *   subgraph {
107 *     rank = same;
108 *
109 *     p0 [label="PROCESSOR 0", shape="box"];
110 *     p1 [label="PROCESSOR 1", shape="box"];
111 *   }
112 *
113 *   i -> p0;
114 *   j -> p1;
115 * }
116 * @enddot
117 *
118 * Lets start A.  For this an enqueue operation is performed.
119 *
120 * @dot
121 * digraph {
122 *   node [style="filled"];
123 *   edge [dir="none"];
124 *
125 *   subgraph {
126 *     rank = same;
127 *
128 *     i [label="I (5)", fillcolor="green"];
129 *     j [label="J (5)", fillcolor="red"];
130 *     a [label="A (1)", fillcolor="green"];
131 *     b [label="B (2)"];
132 *     c [label="C (3)"];
133 *     a -> i;
134 *   }
135 *
136 *   subgraph {
137 *     rank = same;
138 *
139 *     p0 [label="PROCESSOR 0", shape="box"];
140 *     p1 [label="PROCESSOR 1", shape="box"];
141 *   }
142 *
143 *   i -> p0;
144 *   a -> p1;
145 * }
146 * @enddot
147 *
148 * Lets start C.
149 *
150 * @dot
151 * digraph {
152 *   node [style="filled"];
153 *   edge [dir="none"];
154 *
155 *   subgraph {
156 *     rank = same;
157 *
158 *     a [label="A (1)", fillcolor="green"];
159 *     c [label="C (3)", fillcolor="green"];
160 *     i [label="I (5)", fillcolor="red"];
161 *     j [label="J (5)", fillcolor="red"];
162 *     b [label="B (2)"];
163 *     a -> c;
164 *     i -> j;
165 *   }
166 *
167 *   subgraph {
168 *     rank = same;
169 *
170 *     p0 [label="PROCESSOR 0", shape="box"];
171 *     p1 [label="PROCESSOR 1", shape="box"];
172 *   }
173 *
174 *   c -> p0;
175 *   a -> p1;
176 * }
177 * @enddot
178 *
179 * Lets start B.
180 *
181 * @dot
182 * digraph {
183 *   node [style="filled"];
184 *   edge [dir="none"];
185 *
186 *   subgraph {
187 *     rank = same;
188 *
189 *     a [label="A (1)", fillcolor="green"];
190 *     b [label="B (2)", fillcolor="green"];
191 *     c [label="C (3)", fillcolor="red"];
192 *     i [label="I (5)", fillcolor="red"];
193 *     j [label="J (5)", fillcolor="red"];
194 *     a -> b;
195 *     c -> i -> j;
196 *   }
197 *
198 *   subgraph {
199 *     rank = same;
200 *
201 *     p0 [label="PROCESSOR 0", shape="box"];
202 *     p1 [label="PROCESSOR 1", shape="box"];
203 *   }
204 *
205 *   b -> p0;
206 *   a -> p1;
207 * }
208 * @enddot
209 *
210 * Lets change the priority of thread A to 4.
211 *
212 * @dot
213 * digraph {
214 *   node [style="filled"];
215 *   edge [dir="none"];
216 *
217 *   subgraph {
218 *     rank = same;
219 *
220 *     b [label="B (2)", fillcolor="green"];
221 *     c [label="C (3)", fillcolor="green"];
222 *     a [label="A (4)", fillcolor="red"];
223 *     i [label="I (5)", fillcolor="red"];
224 *     j [label="J (5)", fillcolor="red"];
225 *     b -> c;
226 *     a -> i -> j;
227 *   }
228 *
229 *   subgraph {
230 *     rank = same;
231 *
232 *     p0 [label="PROCESSOR 0", shape="box"];
233 *     p1 [label="PROCESSOR 1", shape="box"];
234 *   }
235 *
236 *   b -> p0;
237 *   c -> p1;
238 * }
239 * @enddot
240 *
241 * Now perform a blocking operation with thread B.  Please note that thread A
242 * migrated now from processor 0 to processor 1 and thread C still executes on
243 * processor 1.
244 *
245 * @dot
246 * digraph {
247 *   node [style="filled"];
248 *   edge [dir="none"];
249 *
250 *   subgraph {
251 *     rank = same;
252 *
253 *     c [label="C (3)", fillcolor="green"];
254 *     a [label="A (4)", fillcolor="green"];
255 *     i [label="I (5)", fillcolor="red"];
256 *     j [label="J (5)", fillcolor="red"];
257 *     b [label="B (2)"];
258 *     c -> a;
259 *     i -> j;
260 *   }
261 *
262 *   subgraph {
263 *     rank = same;
264 *
265 *     p0 [label="PROCESSOR 0", shape="box"];
266 *     p1 [label="PROCESSOR 1", shape="box"];
267 *   }
268 *
269 *   a -> p0;
270 *   c -> p1;
271 * }
272 * @enddot
273 *
274 * @{
275 */
276
277typedef Scheduler_Node *( *Scheduler_SMP_Get_highest_ready )(
278  Scheduler_Context *context,
279  Scheduler_Node    *node
280);
281
282typedef Scheduler_Node *( *Scheduler_SMP_Get_lowest_scheduled )(
283  Scheduler_Context *context,
284  Scheduler_Node    *filter,
285  Chain_Node_order   order
286);
287
288typedef void ( *Scheduler_SMP_Extract )(
289  Scheduler_Context *context,
290  Scheduler_Node    *node_to_extract
291);
292
293typedef void ( *Scheduler_SMP_Insert )(
294  Scheduler_Context *context,
295  Scheduler_Node    *node_to_insert
296);
297
298typedef void ( *Scheduler_SMP_Move )(
299  Scheduler_Context *context,
300  Scheduler_Node    *node_to_move
301);
302
303typedef void ( *Scheduler_SMP_Update )(
304  Scheduler_Context *context,
305  Scheduler_Node    *node_to_update,
306  Priority_Control   new_priority
307);
308
309typedef Thread_Control *( *Scheduler_SMP_Enqueue )(
310  Scheduler_Context *context,
311  Scheduler_Node    *node_to_enqueue,
312  Thread_Control    *needs_help
313);
314
315typedef Thread_Control *( *Scheduler_SMP_Enqueue_scheduled )(
316  Scheduler_Context *context,
317  Scheduler_Node    *node_to_enqueue
318);
319
320typedef void ( *Scheduler_SMP_Allocate_processor )(
321  Scheduler_Context *context,
322  Thread_Control    *scheduled,
323  Thread_Control    *victim
324);
325
326static inline bool _Scheduler_SMP_Insert_priority_lifo_order(
327  const Chain_Node *to_insert,
328  const Chain_Node *next
329)
330{
331  const Scheduler_SMP_Node *node_to_insert =
332    (const Scheduler_SMP_Node *) to_insert;
333  const Scheduler_SMP_Node *node_next =
334    (const Scheduler_SMP_Node *) next;
335
336  return node_to_insert->priority <= node_next->priority;
337}
338
339static inline bool _Scheduler_SMP_Insert_priority_fifo_order(
340  const Chain_Node *to_insert,
341  const Chain_Node *next
342)
343{
344  const Scheduler_SMP_Node *node_to_insert =
345    (const Scheduler_SMP_Node *) to_insert;
346  const Scheduler_SMP_Node *node_next =
347    (const Scheduler_SMP_Node *) next;
348
349  return node_to_insert->priority < node_next->priority;
350}
351
352static inline Scheduler_SMP_Context *_Scheduler_SMP_Get_self(
353  Scheduler_Context *context
354)
355{
356  return (Scheduler_SMP_Context *) context;
357}
358
359static inline void _Scheduler_SMP_Initialize(
360  Scheduler_SMP_Context *self
361)
362{
363  _Chain_Initialize_empty( &self->Scheduled );
364}
365
366static inline Scheduler_SMP_Node *_Scheduler_SMP_Thread_get_node(
367  Thread_Control *thread
368)
369{
370  return (Scheduler_SMP_Node *) _Scheduler_Thread_get_node( thread );
371}
372
373static inline Scheduler_SMP_Node *_Scheduler_SMP_Node_downcast(
374  Scheduler_Node *node
375)
376{
377  return (Scheduler_SMP_Node *) node;
378}
379
380static inline void _Scheduler_SMP_Node_initialize(
381  Scheduler_SMP_Node *node,
382  Thread_Control     *thread
383)
384{
385  _Scheduler_Node_do_initialize( &node->Base, thread );
386  node->state = SCHEDULER_SMP_NODE_BLOCKED;
387}
388
389static inline void _Scheduler_SMP_Node_update_priority(
390  Scheduler_SMP_Node *node,
391  Priority_Control    new_priority
392)
393{
394  node->priority = new_priority;
395}
396
397extern const bool _Scheduler_SMP_Node_valid_state_changes[ 3 ][ 3 ];
398
399static inline void _Scheduler_SMP_Node_change_state(
400  Scheduler_SMP_Node      *node,
401  Scheduler_SMP_Node_state new_state
402)
403{
404  _Assert(
405    _Scheduler_SMP_Node_valid_state_changes[ node->state ][ new_state ]
406  );
407
408  node->state = new_state;
409}
410
411static inline bool _Scheduler_SMP_Is_processor_owned_by_us(
412  const Scheduler_Context *context,
413  const Per_CPU_Control   *cpu
414)
415{
416  return cpu->scheduler_context == context;
417}
418
419static inline void _Scheduler_SMP_Allocate_processor_lazy(
420  Scheduler_Context *context,
421  Thread_Control    *scheduled_thread,
422  Thread_Control    *victim_thread
423)
424{
425  Per_CPU_Control *scheduled_cpu = _Thread_Get_CPU( scheduled_thread );
426  Per_CPU_Control *victim_cpu = _Thread_Get_CPU( victim_thread );
427  Per_CPU_Control *cpu_self = _Per_CPU_Get();
428  Thread_Control *heir;
429
430  _Assert( _ISR_Get_level() != 0 );
431
432  if ( _Thread_Is_executing_on_a_processor( scheduled_thread ) ) {
433    if ( _Scheduler_SMP_Is_processor_owned_by_us( context, scheduled_cpu ) ) {
434      heir = scheduled_cpu->heir;
435      _Thread_Dispatch_update_heir(
436        cpu_self,
437        scheduled_cpu,
438        scheduled_thread
439      );
440    } else {
441      /* We have to force a migration to our processor set */
442      _Assert(
443        scheduled_thread->Scheduler.debug_real_cpu->heir != scheduled_thread
444      );
445      heir = scheduled_thread;
446    }
447  } else {
448    heir = scheduled_thread;
449  }
450
451  if ( heir != victim_thread ) {
452    _Thread_Set_CPU( heir, victim_cpu );
453    _Thread_Dispatch_update_heir( cpu_self, victim_cpu, heir );
454  }
455}
456
457static inline void _Scheduler_SMP_Allocate_processor(
458  Scheduler_Context                *context,
459  Scheduler_Node                   *scheduled,
460  Scheduler_Node                   *victim,
461  Scheduler_SMP_Allocate_processor  allocate_processor
462)
463{
464  Thread_Control *scheduled_thread = _Scheduler_Node_get_user( scheduled );
465  Thread_Control *victim_thread = _Scheduler_Node_get_user( victim );
466
467  _Scheduler_SMP_Node_change_state(
468    _Scheduler_SMP_Node_downcast( scheduled ),
469    SCHEDULER_SMP_NODE_SCHEDULED
470  );
471
472  ( *allocate_processor )( context, scheduled_thread, victim_thread );
473}
474
475static inline Scheduler_Node *_Scheduler_SMP_Get_lowest_scheduled(
476  Scheduler_Context *context,
477  Scheduler_Node    *filter,
478  Chain_Node_order   order
479)
480{
481  Scheduler_SMP_Context *self = _Scheduler_SMP_Get_self( context );
482  Chain_Control *scheduled = &self->Scheduled;
483  Scheduler_Node *lowest_scheduled =
484    (Scheduler_Node *) _Chain_Last( scheduled );
485
486  (void) filter;
487  (void) order;
488
489  _Assert( &lowest_scheduled->Node != _Chain_Tail( scheduled ) );
490
491  return lowest_scheduled;
492}
493
494/**
495 * @brief Enqueues a node according to the specified order function.
496 *
497 * The node must not be in the scheduled state.
498 *
499 * @param[in] context The scheduler instance context.
500 * @param[in] node The node to enqueue.
501 * @param[in] needs_help The thread needing help in case the node cannot be
502 *   scheduled.
503 * @param[in] order The order function.
504 * @param[in] insert_ready Function to insert a node into the set of ready
505 *   nodes.
506 * @param[in] insert_scheduled Function to insert a node into the set of
507 *   scheduled nodes.
508 * @param[in] move_from_scheduled_to_ready Function to move a node from the set
509 *   of scheduled nodes to the set of ready nodes.
510 * @param[in] get_lowest_scheduled Function to select the node from the
511 *   scheduled nodes to replace.  It may not be possible to find one, in this
512 *   case a pointer must be returned so that the order functions returns false
513 *   if this pointer is passed as the second argument to the order function.
514 * @param[in] allocate_processor Function to allocate a processor to a node
515 *   based on the rules of the scheduler.
516 */
517static inline Thread_Control *_Scheduler_SMP_Enqueue_ordered(
518  Scheduler_Context                  *context,
519  Scheduler_Node                     *node,
520  Thread_Control                     *needs_help,
521  Chain_Node_order                    order,
522  Scheduler_SMP_Insert                insert_ready,
523  Scheduler_SMP_Insert                insert_scheduled,
524  Scheduler_SMP_Move                  move_from_scheduled_to_ready,
525  Scheduler_SMP_Get_lowest_scheduled  get_lowest_scheduled,
526  Scheduler_SMP_Allocate_processor    allocate_processor
527)
528{
529  Scheduler_Node *lowest_scheduled =
530    ( *get_lowest_scheduled )( context, node, order );
531
532  if ( ( *order )( &node->Node, &lowest_scheduled->Node ) ) {
533    _Scheduler_SMP_Node_change_state(
534      _Scheduler_SMP_Node_downcast( lowest_scheduled ),
535      SCHEDULER_SMP_NODE_READY
536    );
537
538    _Scheduler_SMP_Allocate_processor(
539      context,
540      node,
541      lowest_scheduled,
542      allocate_processor
543    );
544
545    ( *insert_scheduled )( context, node );
546    ( *move_from_scheduled_to_ready )( context, lowest_scheduled );
547
548    needs_help = _Scheduler_Node_get_user( lowest_scheduled );
549  } else {
550    ( *insert_ready )( context, node );
551  }
552
553  return needs_help;
554}
555
556/**
557 * @brief Enqueues a scheduled node according to the specified order
558 * function.
559 *
560 * @param[in] context The scheduler instance context.
561 * @param[in] node The node to enqueue.
562 * @param[in] order The order function.
563 * @param[in] get_highest_ready Function to get the highest ready node.
564 * @param[in] insert_ready Function to insert a node into the set of ready
565 *   nodes.
566 * @param[in] insert_scheduled Function to insert a node into the set of
567 *   scheduled nodes.
568 * @param[in] move_from_ready_to_scheduled Function to move a node from the set
569 *   of ready nodes to the set of scheduled nodes.
570 * @param[in] allocate_processor Function to allocate a processor to a node
571 *   based on the rules of the scheduler.
572 */
573static inline Thread_Control *_Scheduler_SMP_Enqueue_scheduled_ordered(
574  Scheduler_Context                *context,
575  Scheduler_Node                   *node,
576  Chain_Node_order                  order,
577  Scheduler_SMP_Get_highest_ready   get_highest_ready,
578  Scheduler_SMP_Insert              insert_ready,
579  Scheduler_SMP_Insert              insert_scheduled,
580  Scheduler_SMP_Move                move_from_ready_to_scheduled,
581  Scheduler_SMP_Allocate_processor  allocate_processor
582)
583{
584  Scheduler_Node *highest_ready = ( *get_highest_ready )( context, node );
585  Thread_Control *needs_help;
586
587  _Assert( highest_ready != NULL );
588
589  /*
590   * The node has been extracted from the scheduled chain.  We have to place
591   * it now on the scheduled or ready set.
592   */
593  if ( ( *order )( &node->Node, &highest_ready->Node ) ) {
594    ( *insert_scheduled )( context, node );
595
596    needs_help = NULL;
597  } else {
598    _Scheduler_SMP_Node_change_state(
599      _Scheduler_SMP_Node_downcast( node ),
600      SCHEDULER_SMP_NODE_READY
601    );
602
603    _Scheduler_SMP_Allocate_processor(
604      context,
605      highest_ready,
606      node,
607      allocate_processor
608    );
609
610    ( *insert_ready )( context, node );
611    ( *move_from_ready_to_scheduled )( context, highest_ready );
612
613    needs_help = _Scheduler_Node_get_user( node );
614  }
615
616  return needs_help;
617}
618
619static inline void _Scheduler_SMP_Extract_from_scheduled(
620  Scheduler_Node *node
621)
622{
623  _Chain_Extract_unprotected( &node->Node );
624}
625
626static inline void _Scheduler_SMP_Schedule_highest_ready(
627  Scheduler_Context                *context,
628  Scheduler_Node                   *victim,
629  Scheduler_SMP_Get_highest_ready   get_highest_ready,
630  Scheduler_SMP_Move                move_from_ready_to_scheduled,
631  Scheduler_SMP_Allocate_processor  allocate_processor
632)
633{
634  Scheduler_Node *highest_ready = ( *get_highest_ready )( context, victim );
635
636  _Scheduler_SMP_Allocate_processor(
637    context,
638    highest_ready,
639    victim,
640    allocate_processor
641  );
642
643  ( *move_from_ready_to_scheduled )( context, highest_ready );
644}
645
646/**
647 * @brief Blocks a thread.
648 *
649 * @param[in] context The scheduler instance context.
650 * @param[in] thread The thread of the scheduling operation.
651 * @param[in] extract_from_ready Function to extract a node from the set of
652 * ready nodes.
653 * @param[in] get_highest_ready Function to get the highest ready node.
654 * @param[in] move_from_ready_to_scheduled Function to move a node from the set
655 * of ready nodes to the set of scheduled nodes.
656 */
657static inline void _Scheduler_SMP_Block(
658  Scheduler_Context                *context,
659  Thread_Control                   *thread,
660  Scheduler_SMP_Extract             extract_from_ready,
661  Scheduler_SMP_Get_highest_ready   get_highest_ready,
662  Scheduler_SMP_Move                move_from_ready_to_scheduled,
663  Scheduler_SMP_Allocate_processor  allocate_processor
664)
665{
666  Scheduler_SMP_Node *node = _Scheduler_SMP_Thread_get_node( thread );
667  bool is_scheduled = node->state == SCHEDULER_SMP_NODE_SCHEDULED;
668
669  _Scheduler_SMP_Node_change_state( node, SCHEDULER_SMP_NODE_BLOCKED );
670
671  if ( is_scheduled ) {
672    _Scheduler_SMP_Extract_from_scheduled( &node->Base );
673
674    _Scheduler_SMP_Schedule_highest_ready(
675      context,
676      &node->Base,
677      get_highest_ready,
678      move_from_ready_to_scheduled,
679      allocate_processor
680    );
681  } else {
682    ( *extract_from_ready )( context, &node->Base );
683  }
684}
685
686static inline Thread_Control *_Scheduler_SMP_Unblock(
687  Scheduler_Context     *context,
688  Thread_Control        *thread,
689  Scheduler_SMP_Enqueue  enqueue_fifo
690)
691{
692  Scheduler_SMP_Node *node = _Scheduler_SMP_Thread_get_node( thread );
693
694  _Scheduler_SMP_Node_change_state( node, SCHEDULER_SMP_NODE_READY );
695
696  return ( *enqueue_fifo )( context, &node->Base, thread );
697}
698
699static inline Thread_Control *_Scheduler_SMP_Change_priority(
700  Scheduler_Context               *context,
701  Thread_Control                  *thread,
702  Priority_Control                 new_priority,
703  bool                             prepend_it,
704  Scheduler_SMP_Extract            extract_from_ready,
705  Scheduler_SMP_Update             update,
706  Scheduler_SMP_Enqueue            enqueue_fifo,
707  Scheduler_SMP_Enqueue            enqueue_lifo,
708  Scheduler_SMP_Enqueue_scheduled  enqueue_scheduled_fifo,
709  Scheduler_SMP_Enqueue_scheduled  enqueue_scheduled_lifo
710)
711{
712  Scheduler_SMP_Node *node = _Scheduler_SMP_Thread_get_node( thread );
713  Thread_Control *needs_help;
714
715  if ( node->state == SCHEDULER_SMP_NODE_SCHEDULED ) {
716    _Scheduler_SMP_Extract_from_scheduled( &node->Base );
717
718    ( *update )( context, &node->Base, new_priority );
719
720    if ( prepend_it ) {
721      needs_help = ( *enqueue_scheduled_lifo )( context, &node->Base );
722    } else {
723      needs_help = ( *enqueue_scheduled_fifo )( context, &node->Base );
724    }
725  } else {
726    ( *extract_from_ready )( context, &node->Base );
727
728    ( *update )( context, &node->Base, new_priority );
729
730    if ( prepend_it ) {
731      needs_help = ( *enqueue_lifo )( context, &node->Base, NULL );
732    } else {
733      needs_help = ( *enqueue_fifo )( context, &node->Base, NULL );
734    }
735  }
736
737  return needs_help;
738}
739
740static inline Thread_Control *_Scheduler_SMP_Yield(
741  Scheduler_Context               *context,
742  Thread_Control                  *thread,
743  Scheduler_SMP_Extract            extract_from_ready,
744  Scheduler_SMP_Enqueue            enqueue_fifo,
745  Scheduler_SMP_Enqueue_scheduled  enqueue_scheduled_fifo
746)
747{
748  Scheduler_SMP_Node *node = _Scheduler_SMP_Thread_get_node( thread );
749  Thread_Control *needs_help;
750
751  if ( node->state == SCHEDULER_SMP_NODE_SCHEDULED ) {
752    _Scheduler_SMP_Extract_from_scheduled( &node->Base );
753
754    needs_help = ( *enqueue_scheduled_fifo )( context, &node->Base );
755  } else {
756    ( *extract_from_ready )( context, &node->Base );
757
758    needs_help = ( *enqueue_fifo )( context, &node->Base, NULL );
759  }
760
761  return needs_help;
762}
763
764static inline void _Scheduler_SMP_Insert_scheduled_lifo(
765  Scheduler_Context *context,
766  Scheduler_Node    *node_to_insert
767)
768{
769  Scheduler_SMP_Context *self = _Scheduler_SMP_Get_self( context );
770
771  _Chain_Insert_ordered_unprotected(
772    &self->Scheduled,
773    &node_to_insert->Node,
774    _Scheduler_SMP_Insert_priority_lifo_order
775  );
776}
777
778static inline void _Scheduler_SMP_Insert_scheduled_fifo(
779  Scheduler_Context *context,
780  Scheduler_Node    *node_to_insert
781)
782{
783  Scheduler_SMP_Context *self = _Scheduler_SMP_Get_self( context );
784
785  _Chain_Insert_ordered_unprotected(
786    &self->Scheduled,
787    &node_to_insert->Node,
788    _Scheduler_SMP_Insert_priority_fifo_order
789  );
790}
791
792/** @} */
793
794#ifdef __cplusplus
795}
796#endif /* __cplusplus */
797
798#endif /* _RTEMS_SCORE_SCHEDULERSMPIMPL_H */
Note: See TracBrowser for help on using the repository browser.