source: rtems/cpukit/score/include/rtems/score/scheduleredf.h @ f39f667a

4.115
Last change on this file since f39f667a was f39f667a, checked in by Sebastian Huber <sebastian.huber@…>, on 05/14/14 at 11:50:48

score: Simplify _Thread_Change_priority()

The function to change a thread priority was too complex. Simplify it
with a new scheduler operation. This increases the average case
performance due to the simplified logic. The interrupt disabled
critical section is a bit prolonged since now the extract, update and
enqueue steps are executed atomically. This should however not impact
the worst-case interrupt latency since at least for the Deterministic
Priority Scheduler this sequence can be carried out with a wee bit of
instructions and no loops.

Add _Scheduler_Change_priority() to replace the sequence of

  • _Thread_Set_transient(),
  • _Scheduler_Extract(),
  • _Scheduler_Enqueue(), and
  • _Scheduler_Enqueue_first().

Delete STATES_TRANSIENT, _States_Is_transient() and
_Thread_Set_transient() since this state is now superfluous.

With this change it is possible to get rid of the
SCHEDULER_SMP_NODE_IN_THE_AIR state. This considerably simplifies the
implementation of the new SMP locking protocols.

  • Property mode set to 100644
File size: 6.9 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/**
39 *  Entry points for the Earliest Deadline First Scheduler.
40 */
41#define SCHEDULER_EDF_ENTRY_POINTS \
42  { \
43    _Scheduler_EDF_Initialize,       /* initialize entry point */ \
44    _Scheduler_EDF_Schedule,         /* schedule entry point */ \
45    _Scheduler_EDF_Yield,            /* yield entry point */ \
46    _Scheduler_EDF_Block,            /* block entry point */ \
47    _Scheduler_EDF_Unblock,          /* unblock entry point */ \
48    _Scheduler_EDF_Change_priority,  /* change priority entry point */ \
49    _Scheduler_EDF_Allocate,         /* allocate entry point */ \
50    _Scheduler_default_Free,         /* free entry point */ \
51    _Scheduler_EDF_Update,           /* update entry point */ \
52    _Scheduler_EDF_Priority_compare, /* compares two priorities */ \
53    _Scheduler_EDF_Release_job,      /* new period of task */ \
54    _Scheduler_default_Tick,         /* tick entry point */ \
55    _Scheduler_default_Start_idle    /* start idle entry point */ \
56  }
57
58/**
59 * This is just a most significant bit of Priority_Control type. It
60 * distinguishes threads which are deadline driven (priority
61 * represented by a lower number than @a SCHEDULER_EDF_PRIO_MSB) from those
62 * ones who do not have any deadlines and thus are considered background
63 * tasks.
64 */
65#define SCHEDULER_EDF_PRIO_MSB 0x80000000
66
67typedef struct {
68  /**
69   * @brief Basic scheduler context.
70   */
71  Scheduler_Context Base;
72
73  /**
74   * Top of the ready queue.
75   */
76  RBTree_Control Ready;
77} Scheduler_EDF_Context;
78
79/**
80 * @typedef Scheduler_EDF_Queue_state
81 *
82 * This enumeration distiguishes state of a thread with respect to the
83 * ready queue.
84 */
85typedef enum {
86  SCHEDULER_EDF_QUEUE_STATE_NOT_PRESENTLY,
87  SCHEDULER_EDF_QUEUE_STATE_YES,
88  SCHEDULER_EDF_QUEUE_STATE_NEVER_HAS_BEEN
89} Scheduler_EDF_Queue_state;
90
91/**
92 * @brief Scheduler node specialization for EDF schedulers.
93 */
94typedef struct {
95  /**
96   * @brief Basic scheduler node.
97   */
98  Scheduler_Node Base;
99
100  /**
101   * Pointer to corresponding Thread Control Block.
102   */
103  Thread_Control *thread;
104  /**
105   * Rbtree node related to this thread.
106   */
107  RBTree_Node Node;
108  /**
109   * State of the thread with respect to ready queue.
110   */
111  Scheduler_EDF_Queue_state queue_state;
112} Scheduler_EDF_Node;
113
114/**
115 * @brief Initialize EDF scheduler.
116 *
117 * This routine initializes the EDF scheduler.
118 */
119void _Scheduler_EDF_Initialize( const Scheduler_Control *scheduler );
120
121/**
122 *  @brief Removes thread from ready queue.
123 *
124 *  This routine removes @a the_thread from the scheduling decision,
125 *  that is, removes it from the ready queue.  It performs
126 *  any necessary scheduling operations including the selection of
127 *  a new heir thread.
128 *
129 *  @param[in] the_thread is the thread to be blocked.
130 */
131void _Scheduler_EDF_Block(
132  const Scheduler_Control *scheduler,
133  Thread_Control          *the_thread
134);
135
136/**
137 *  @brief Sets the heir thread to be the next ready thread
138 *  in the rbtree ready queue.
139 *
140 *  This kernel routine sets the heir thread to be the next ready thread
141 *  in the rbtree ready queue.
142 */
143void _Scheduler_EDF_Schedule(
144  const Scheduler_Control *scheduler,
145  Thread_Control          *the_thread
146);
147
148/**
149 *  @brief Allocates EDF specific information of @a the_thread.
150 *
151 *  This routine allocates EDF specific information of @a the_thread.
152 *
153 *  @param[in] the_thread is the thread the scheduler is allocating
154 *             management memory for.
155 */
156bool _Scheduler_EDF_Allocate(
157  const Scheduler_Control *scheduler,
158  Thread_Control          *the_thread
159);
160
161/**
162 *  @brief Updates position in the ready queue of @a the_thread.
163 *
164 *  This routine updates position in the ready queue of @a the_thread.
165 *
166 *  @param[in] the_thread will have its scheduler specific information
167 *             structure updated.
168 */
169void _Scheduler_EDF_Update(
170  const Scheduler_Control *scheduler,
171  Thread_Control          *the_thread
172);
173
174/**
175 *  @brief Adds @a the_thread to the scheduling decision.
176 *
177 *  This routine adds @a the_thread to the scheduling decision, that is,
178 *  adds it to the ready queue and updates any appropriate scheduling
179 *  variables, for example the heir thread.
180 *
181 *  @param[in] the_thread will be unblocked.
182 */
183void _Scheduler_EDF_Unblock(
184  const Scheduler_Control *scheduler,
185  Thread_Control          *the_thread
186);
187
188void _Scheduler_EDF_Change_priority(
189  const Scheduler_Control *scheduler,
190  Thread_Control          *the_thread,
191  Priority_Control         new_priority,
192  bool                     prepend_it
193);
194
195/**
196 *  @brief invoked when a thread wishes to voluntarily
197 *  transfer control of the processor to another thread
198 *  with equal deadline.
199 *
200 *  This routine is invoked when a thread wishes to voluntarily
201 *  transfer control of the processor to another thread in the queue with
202 *  equal deadline. This does not have to happen very often.
203 *
204 *  This routine will remove the specified THREAD from the ready queue
205 *  and place it back. The rbtree ready queue is responsible for FIFO ordering
206 *  in such a case.
207 *
208 *  @param[in,out] thread The yielding thread.
209 */
210void _Scheduler_EDF_Yield(
211  const Scheduler_Control *scheduler,
212  Thread_Control          *the_thread
213);
214
215/**
216 *  @brief Explicitly compare absolute dedlines (priorities) of threads.
217 *
218 * This routine explicitly compares absolute dedlines (priorities) of threads.
219 * In case of EDF scheduling time overflow is taken into account.
220 *
221 * @retval >0 for p1 > p2; 0 for p1 == p2; <0 for p1 < p2.
222 */
223int _Scheduler_EDF_Priority_compare (
224  Priority_Control p1,
225  Priority_Control p2
226);
227
228/**
229 *  @brief Called when a new job of task is released.
230 *
231 *  This routine is called when a new job of task is released.
232 *  It is called only from Rate Monotonic manager in the beginning
233 *  of new period.
234 *
235 *  @param[in] the_thread is the owner of the job.
236 *  @param[in] deadline of the new job from now. If equal to 0,
237 *             the job was cancelled or deleted, thus a running task
238 *             has to be suspended.
239 */
240void _Scheduler_EDF_Release_job (
241  const Scheduler_Control *scheduler,
242  Thread_Control          *the_thread,
243  uint32_t                 deadline
244);
245
246#ifdef __cplusplus
247}
248#endif
249
250/**@}*/
251
252#endif
253/* end of include file */
Note: See TracBrowser for help on using the repository browser.