source: rtems/cpukit/score/include/rtems/score/scheduleredf.h @ 14de20f1

5
Last change on this file since 14de20f1 was 9bfad8c, checked in by Sebastian Huber <sebastian.huber@…>, on 06/08/16 at 20:22:46

score: Add thread priority to scheduler nodes

The thread priority is manifest in two independent areas. One area is
the user visible thread priority along with a potential thread queue.
The other is the scheduler. Currently, a thread priority update via
_Thread_Change_priority() first updates the user visble thread priority
and the thread queue, then the scheduler is notified if necessary. The
priority is passed to the scheduler via a local variable. A generation
counter ensures that the scheduler discards out-of-date priorities.

This use of a local variable ties the update in these two areas close
together. For later enhancements and the OMIP locking protocol
implementation we need more flexibility. Add a thread priority
information block to Scheduler_Node and synchronize priority value
updates via a sequence lock on SMP configurations.

Update #2556.

  • Property mode set to 100644
File size: 6.8 KB
Line 
1/**
2 *  @file  rtems/score/scheduleredf.h
3 *
4 *  @brief Data Related to the Manipulation of Threads for the EDF Scheduler
5 *
6 *  This include file contains all the constants and structures associated
7 *  with the manipulation of threads for the EDF scheduler.
8 */
9
10/*
11 *  Copryight (c) 2011 Petr Benes.
12 *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#ifndef _RTEMS_SCORE_SCHEDULEREDF_H
20#define _RTEMS_SCORE_SCHEDULEREDF_H
21
22#include <rtems/score/priority.h>
23#include <rtems/score/scheduler.h>
24#include <rtems/score/schedulerpriority.h>
25#include <rtems/score/rbtree.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/**
32 *  @defgroup ScoreSchedulerEDF EDF Scheduler
33 *
34 *  @ingroup ScoreScheduler
35 */
36/**@{*/
37
38#define SCHEDULER_EDF_MAXIMUM_PRIORITY 0x7fffffff
39
40/**
41 *  Entry points for the Earliest Deadline First Scheduler.
42 */
43#define SCHEDULER_EDF_ENTRY_POINTS \
44  { \
45    _Scheduler_EDF_Initialize,       /* initialize entry point */ \
46    _Scheduler_EDF_Schedule,         /* schedule entry point */ \
47    _Scheduler_EDF_Yield,            /* yield entry point */ \
48    _Scheduler_EDF_Block,            /* block entry point */ \
49    _Scheduler_EDF_Unblock,          /* unblock entry point */ \
50    _Scheduler_EDF_Update_priority,  /* update priority entry point */ \
51    _Scheduler_EDF_Map_priority,     /* map priority entry point */ \
52    _Scheduler_EDF_Unmap_priority,   /* unmap priority entry point */ \
53    SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP \
54    _Scheduler_EDF_Node_initialize,  /* node initialize entry point */ \
55    _Scheduler_default_Node_destroy, /* node destroy entry point */ \
56    _Scheduler_EDF_Release_job,      /* new period of task */ \
57    _Scheduler_default_Tick,         /* tick entry point */ \
58    _Scheduler_default_Start_idle    /* start idle entry point */ \
59    SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
60  }
61
62/**
63 * This is just a most significant bit of Priority_Control type. It
64 * distinguishes threads which are deadline driven (priority
65 * represented by a lower number than @a SCHEDULER_EDF_PRIO_MSB) from those
66 * ones who do not have any deadlines and thus are considered background
67 * tasks.
68 */
69#define SCHEDULER_EDF_PRIO_MSB 0x80000000
70
71typedef struct {
72  /**
73   * @brief Basic scheduler context.
74   */
75  Scheduler_Context Base;
76
77  /**
78   * Top of the ready queue.
79   */
80  RBTree_Control Ready;
81} Scheduler_EDF_Context;
82
83/**
84 * @brief Scheduler node specialization for EDF schedulers.
85 */
86typedef struct {
87  /**
88   * @brief Basic scheduler node.
89   */
90  Scheduler_Node Base;
91
92  /**
93   * Pointer to corresponding Thread Control Block.
94   */
95  Thread_Control *thread;
96  /**
97   * Rbtree node related to this thread.
98   */
99  RBTree_Node Node;
100
101  /**
102   * @brief The thread priority used by this scheduler instance in case no job
103   * is released.
104   */
105  Priority_Control background_priority;
106
107  /**
108   * @brief The thread priority currently used by this scheduler instance.
109   */
110  Priority_Control current_priority;
111} Scheduler_EDF_Node;
112
113/**
114 *  @brief Initialize EDF scheduler.
115 *
116 *  This routine initializes the EDF scheduler.
117 *
118 *  @param[in] scheduler The scheduler instance.
119 */
120void _Scheduler_EDF_Initialize( const Scheduler_Control *scheduler );
121
122/**
123 *  @brief Removes thread from ready queue.
124 *
125 *  This routine removes @a the_thread from the scheduling decision,
126 *  that is, removes it from the ready queue.  It performs
127 *  any necessary scheduling operations including the selection of
128 *  a new heir thread.
129 *
130 *  @param[in] scheduler The scheduler instance.
131 *  @param[in] the_thread is the thread to be blocked.
132 */
133void _Scheduler_EDF_Block(
134  const Scheduler_Control *scheduler,
135  Thread_Control          *the_thread
136);
137
138/**
139 *  @brief Sets the heir thread to be the next ready thread
140 *  in the rbtree ready queue.
141 *
142 *  This kernel routine sets the heir thread to be the next ready thread
143 *  in the rbtree ready queue.
144 *
145 *  @param[in] scheduler The scheduler instance.
146 *  @param[in] the_thread being scheduled.
147 */
148void _Scheduler_EDF_Schedule(
149  const Scheduler_Control *scheduler,
150  Thread_Control          *the_thread
151);
152
153/**
154 *  @brief Initializes an EDF specific scheduler node of @a the_thread.
155 *
156 *  @param[in] scheduler The scheduler instance.
157 *  @param[in] the_thread being initialized.
158 *  @param[in] priority The thread priority.
159 */
160void _Scheduler_EDF_Node_initialize(
161  const Scheduler_Control *scheduler,
162  Thread_Control          *the_thread,
163  Priority_Control         priority
164);
165
166/**
167 *  @brief Adds @a the_thread to the scheduling decision.
168 *
169 *  This routine adds @a the_thread to the scheduling decision, that is,
170 *  adds it to the ready queue and updates any appropriate scheduling
171 *  variables, for example the heir thread.
172 *
173 *  @param[in] scheduler The scheduler instance.
174 *  @param[in] the_thread will be unblocked.
175 */
176Scheduler_Void_or_thread _Scheduler_EDF_Unblock(
177  const Scheduler_Control *scheduler,
178  Thread_Control          *the_thread
179);
180
181Scheduler_Void_or_thread _Scheduler_EDF_Update_priority(
182  const Scheduler_Control *scheduler,
183  Thread_Control          *the_thread
184);
185
186Priority_Control _Scheduler_EDF_Map_priority(
187  const Scheduler_Control *scheduler,
188  Priority_Control         priority
189);
190
191Priority_Control _Scheduler_EDF_Unmap_priority(
192  const Scheduler_Control *scheduler,
193  Priority_Control         priority
194);
195
196/**
197 *  @brief invoked when a thread wishes to voluntarily
198 *  transfer control of the processor to another thread
199 *  with equal deadline.
200 *
201 *  This routine is invoked when a thread wishes to voluntarily
202 *  transfer control of the processor to another thread in the queue with
203 *  equal deadline. This does not have to happen very often.
204 *
205 *  This routine will remove the specified THREAD from the ready queue
206 *  and place it back. The rbtree ready queue is responsible for FIFO ordering
207 *  in such a case.
208 *
209 *  @param[in] scheduler The scheduler instance.
210 *  @param[in,out] the_thread The yielding thread.
211 */
212Scheduler_Void_or_thread _Scheduler_EDF_Yield(
213  const Scheduler_Control *scheduler,
214  Thread_Control          *the_thread
215);
216
217/**
218 *  @brief Called when a new job of task is released.
219 *
220 *  This routine is called when a new job of task is released.
221 *  It is called only from Rate Monotonic manager in the beginning
222 *  of new period.
223 *
224 *  @param[in] scheduler The scheduler instance.
225 *  @param[in] the_thread is the owner of the job.
226 *  @param[in] deadline of the new job from now. If equal to 0,
227 *             the job was cancelled or deleted, thus a running task
228 *             has to be suspended.
229 */
230void _Scheduler_EDF_Release_job (
231  const Scheduler_Control *scheduler,
232  Thread_Control          *the_thread,
233  uint64_t                 deadline
234);
235
236#ifdef __cplusplus
237}
238#endif
239
240/**@}*/
241
242#endif
243/* end of include file */
Note: See TracBrowser for help on using the repository browser.