source: rtems/cpukit/score/include/rtems/score/scheduleredfimpl.h @ 99fc1d1d

5
Last change on this file since 99fc1d1d was 99fc1d1d, checked in by Sebastian Huber <sebastian.huber@…>, on 06/09/16 at 19:30:40

score: Rework EDF scheduler

Use inline red-black tree insert. Do not use shifting priorities since
this is not supported by the thread queues. Due to the 32-bit
Priority_Control this currently limits the uptime to 49days with a 1ms
clock tick.

Update #2173.

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[e5ca54c9]1/**
2 * @file
3 *
4 * @ingroup ScoreSchedulerEDF
5 *
6 * @brief EDF Scheduler Implementation
7 */
8
9/*
10 *  Copryight (c) 2011 Petr Benes.
11 *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
12 *
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.
[e5ca54c9]16 */
17
18#ifndef _RTEMS_SCORE_SCHEDULEREDFIMPL_H
19#define _RTEMS_SCORE_SCHEDULEREDFIMPL_H
20
21#include <rtems/score/scheduleredf.h>
22#include <rtems/score/schedulerimpl.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/**
[e0eb07a]29 * @addtogroup ScoreSchedulerEDF
[e5ca54c9]30 *
31 * @{
32 */
33
[e1598a6]34RTEMS_INLINE_ROUTINE Scheduler_EDF_Context *
35  _Scheduler_EDF_Get_context( const Scheduler_Control *scheduler )
[3891983]36{
[2369b10]37  return (Scheduler_EDF_Context *) _Scheduler_Get_context( scheduler );
[3891983]38}
39
[08d9760]40RTEMS_INLINE_ROUTINE Scheduler_EDF_Node *_Scheduler_EDF_Thread_get_node(
[beab7329]41  Thread_Control *the_thread
42)
43{
[08d9760]44  return (Scheduler_EDF_Node *) _Scheduler_Thread_get_node( the_thread );
[beab7329]45}
46
[99fc1d1d]47RTEMS_INLINE_ROUTINE bool _Scheduler_EDF_Less(
48  const void        *left,
49  const RBTree_Node *right
50)
51{
52  const Priority_Control   *the_left;
53  const Scheduler_EDF_Node *the_right;
54  Priority_Control          prio_left;
55  Priority_Control          prio_right;
56
57  the_left = left;
58  the_right = RTEMS_CONTAINER_OF( right, Scheduler_EDF_Node, Node );
59
60  prio_left = *the_left;
61  prio_right = the_right->current_priority;
62
63  return prio_left < prio_right;
64}
65
66RTEMS_INLINE_ROUTINE bool _Scheduler_EDF_Less_or_equal(
67  const void        *left,
68  const RBTree_Node *right
69)
70{
71  const Priority_Control   *the_left;
72  const Scheduler_EDF_Node *the_right;
73  Priority_Control          prio_left;
74  Priority_Control          prio_right;
[b8f76fa]75
[99fc1d1d]76  the_left = left;
77  the_right = RTEMS_CONTAINER_OF( right, Scheduler_EDF_Node, Node );
78
79  prio_left = *the_left;
80  prio_right = the_right->current_priority;
81
82  return prio_left <= prio_right;
83}
[64939bc]84
[f39f667a]85RTEMS_INLINE_ROUTINE void _Scheduler_EDF_Enqueue(
[99fc1d1d]86  Scheduler_EDF_Context *context,
87  Scheduler_EDF_Node    *node,
88  Priority_Control       current_priority
[f39f667a]89)
90{
[99fc1d1d]91  _RBTree_Insert_inline(
92    &context->Ready,
93    &node->Node,
94    &current_priority,
95    _Scheduler_EDF_Less
96  );
97}
[f39f667a]98
[99fc1d1d]99RTEMS_INLINE_ROUTINE void _Scheduler_EDF_Enqueue_first(
100  Scheduler_EDF_Context *context,
101  Scheduler_EDF_Node    *node,
102  Priority_Control       current_priority
103)
104{
105  _RBTree_Insert_inline(
[64939bc]106    &context->Ready,
107    &node->Node,
[99fc1d1d]108    &current_priority,
109    _Scheduler_EDF_Less_or_equal
[64939bc]110  );
[f39f667a]111}
112
113RTEMS_INLINE_ROUTINE void _Scheduler_EDF_Extract(
[99fc1d1d]114  Scheduler_EDF_Context *context,
115  Scheduler_EDF_Node    *node
116)
117{
118  _RBTree_Extract( &context->Ready, &node->Node );
119}
120
121RTEMS_INLINE_ROUTINE void _Scheduler_EDF_Extract_body(
[f39f667a]122  const Scheduler_Control *scheduler,
123  Thread_Control          *the_thread
124)
125{
[99fc1d1d]126  Scheduler_EDF_Context *context;
127  Scheduler_EDF_Node    *node;
[f39f667a]128
[99fc1d1d]129  context = _Scheduler_EDF_Get_context( scheduler );
130  node = _Scheduler_EDF_Thread_get_node( the_thread );
131
132  _Scheduler_EDF_Extract( context, node );
[f39f667a]133}
134
[e5ca54c9]135RTEMS_INLINE_ROUTINE void _Scheduler_EDF_Schedule_body(
[e1598a6]136  const Scheduler_Control *scheduler,
137  Thread_Control          *the_thread,
138  bool                     force_dispatch
[e5ca54c9]139)
140{
[99fc1d1d]141  Scheduler_EDF_Context *context;
142  RBTree_Node           *first;
143  Scheduler_EDF_Node    *node;
144
145  (void) the_thread;
[e5ca54c9]146
[99fc1d1d]147  context = _Scheduler_EDF_Get_context( scheduler );
148  first = _RBTree_Minimum( &context->Ready );
149  node = RTEMS_CONTAINER_OF( first, Scheduler_EDF_Node, Node );
[e5ca54c9]150
[99fc1d1d]151  _Scheduler_Update_heir( node->thread, force_dispatch );
[e5ca54c9]152}
153
154/**@}*/
155
156#ifdef __cplusplus
157}
158#endif
159
160#endif
161/* end of include file */
Note: See TracBrowser for help on using the repository browser.