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 Jun 9, 2016 at 7:30:40 PM

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
Line 
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
15 *  http://www.rtems.org/license/LICENSE.
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/**
29 * @addtogroup ScoreSchedulerEDF
30 *
31 * @{
32 */
33
34RTEMS_INLINE_ROUTINE Scheduler_EDF_Context *
35  _Scheduler_EDF_Get_context( const Scheduler_Control *scheduler )
36{
37  return (Scheduler_EDF_Context *) _Scheduler_Get_context( scheduler );
38}
39
40RTEMS_INLINE_ROUTINE Scheduler_EDF_Node *_Scheduler_EDF_Thread_get_node(
41  Thread_Control *the_thread
42)
43{
44  return (Scheduler_EDF_Node *) _Scheduler_Thread_get_node( the_thread );
45}
46
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;
75
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}
84
85RTEMS_INLINE_ROUTINE void _Scheduler_EDF_Enqueue(
86  Scheduler_EDF_Context *context,
87  Scheduler_EDF_Node    *node,
88  Priority_Control       current_priority
89)
90{
91  _RBTree_Insert_inline(
92    &context->Ready,
93    &node->Node,
94    &current_priority,
95    _Scheduler_EDF_Less
96  );
97}
98
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(
106    &context->Ready,
107    &node->Node,
108    &current_priority,
109    _Scheduler_EDF_Less_or_equal
110  );
111}
112
113RTEMS_INLINE_ROUTINE void _Scheduler_EDF_Extract(
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(
122  const Scheduler_Control *scheduler,
123  Thread_Control          *the_thread
124)
125{
126  Scheduler_EDF_Context *context;
127  Scheduler_EDF_Node    *node;
128
129  context = _Scheduler_EDF_Get_context( scheduler );
130  node = _Scheduler_EDF_Thread_get_node( the_thread );
131
132  _Scheduler_EDF_Extract( context, node );
133}
134
135RTEMS_INLINE_ROUTINE void _Scheduler_EDF_Schedule_body(
136  const Scheduler_Control *scheduler,
137  Thread_Control          *the_thread,
138  bool                     force_dispatch
139)
140{
141  Scheduler_EDF_Context *context;
142  RBTree_Node           *first;
143  Scheduler_EDF_Node    *node;
144
145  (void) the_thread;
146
147  context = _Scheduler_EDF_Get_context( scheduler );
148  first = _RBTree_Minimum( &context->Ready );
149  node = RTEMS_CONTAINER_OF( first, Scheduler_EDF_Node, Node );
150
151  _Scheduler_Update_heir( node->thread, force_dispatch );
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.