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
RevLine 
[5472ad41]1/**
2 *  @file  rtems/score/scheduleredf.h
3 *
[a1f9934a]4 *  @brief Data Related to the Manipulation of Threads for the EDF Scheduler
5 *
[5472ad41]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
[c499856]16 *  http://www.rtems.org/license/LICENSE.
[5472ad41]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/**
[a15eaaf]32 *  @defgroup ScoreSchedulerEDF EDF Scheduler
[5472ad41]33 *
[a15eaaf]34 *  @ingroup ScoreScheduler
[5472ad41]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 */ \
[f39f667a]48    _Scheduler_EDF_Change_priority,  /* change priority entry point */ \
[5472ad41]49    _Scheduler_EDF_Allocate,         /* allocate entry point */ \
[69aa3349]50    _Scheduler_default_Free,         /* free entry point */ \
[5472ad41]51    _Scheduler_EDF_Update,           /* update entry point */ \
52    _Scheduler_EDF_Priority_compare, /* compares two priorities */ \
53    _Scheduler_EDF_Release_job,      /* new period of task */ \
[a344308]54    _Scheduler_default_Tick,         /* tick entry point */ \
[1ccb64e1]55    _Scheduler_default_Start_idle    /* start idle entry point */ \
[5472ad41]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
[3891983]67typedef struct {
[e1598a6]68  /**
69   * @brief Basic scheduler context.
70   */
71  Scheduler_Context Base;
72
[3891983]73  /**
74   * Top of the ready queue.
75   */
76  RBTree_Control Ready;
[e1598a6]77} Scheduler_EDF_Context;
[3891983]78
[5472ad41]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/**
[beab7329]92 * @brief Scheduler node specialization for EDF schedulers.
[5472ad41]93 */
94typedef struct {
[beab7329]95  /**
96   * @brief Basic scheduler node.
97   */
98  Scheduler_Node Base;
99
[5472ad41]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;
[beab7329]112} Scheduler_EDF_Node;
[5472ad41]113
114/**
[a1f9934a]115 * @brief Initialize EDF scheduler.
[5472ad41]116 *
117 * This routine initializes the EDF scheduler.
118 */
[e1598a6]119void _Scheduler_EDF_Initialize( const Scheduler_Control *scheduler );
[5472ad41]120
121/**
[a1f9934a]122 *  @brief Removes thread from ready queue.
[5472ad41]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(
[e1598a6]132  const Scheduler_Control *scheduler,
133  Thread_Control          *the_thread
[5472ad41]134);
135
136/**
[a1f9934a]137 *  @brief Sets the heir thread to be the next ready thread
138 *  in the rbtree ready queue.
[5472ad41]139 *
140 *  This kernel routine sets the heir thread to be the next ready thread
141 *  in the rbtree ready queue.
142 */
[24934e36]143void _Scheduler_EDF_Schedule(
[e1598a6]144  const Scheduler_Control *scheduler,
145  Thread_Control          *the_thread
[24934e36]146);
[5472ad41]147
148/**
[a1f9934a]149 *  @brief Allocates EDF specific information of @a the_thread.
[5472ad41]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 */
[69aa3349]156bool _Scheduler_EDF_Allocate(
[e1598a6]157  const Scheduler_Control *scheduler,
158  Thread_Control          *the_thread
[5472ad41]159);
160
161/**
[a1f9934a]162 *  @brief Updates position in the ready queue of @a the_thread.
[5472ad41]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(
[e1598a6]170  const Scheduler_Control *scheduler,
171  Thread_Control          *the_thread
[5472ad41]172);
173
174/**
[a1f9934a]175 *  @brief Adds @a the_thread to the scheduling decision.
[5472ad41]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(
[e1598a6]184  const Scheduler_Control *scheduler,
185  Thread_Control          *the_thread
[5472ad41]186);
187
[f39f667a]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
[5472ad41]195/**
[a1f9934a]196 *  @brief invoked when a thread wishes to voluntarily
197 *  transfer control of the processor to another thread
198 *  with equal deadline.
[5472ad41]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 *
[6eba7c85]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
[5472ad41]206 *  in such a case.
[6eba7c85]207 *
[961669d]208 *  @param[in,out] thread The yielding thread.
[5472ad41]209 */
[24934e36]210void _Scheduler_EDF_Yield(
[e1598a6]211  const Scheduler_Control *scheduler,
212  Thread_Control          *the_thread
[24934e36]213);
[5472ad41]214
215/**
[a1f9934a]216 *  @brief Explicitly compare absolute dedlines (priorities) of threads.
[5472ad41]217 *
218 * This routine explicitly compares absolute dedlines (priorities) of threads.
219 * In case of EDF scheduling time overflow is taken into account.
220 *
[a1f9934a]221 * @retval >0 for p1 > p2; 0 for p1 == p2; <0 for p1 < p2.
[5472ad41]222 */
223int _Scheduler_EDF_Priority_compare (
224  Priority_Control p1,
225  Priority_Control p2
226);
227
228/**
[a1f9934a]229 *  @brief Called when a new job of task is released.
[5472ad41]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 (
[e1598a6]241  const Scheduler_Control *scheduler,
242  Thread_Control          *the_thread,
243  uint32_t                 deadline
[5472ad41]244);
245
246#ifdef __cplusplus
247}
248#endif
249
250/**@}*/
251
252#endif
[a15eaaf]253/* end of include file */
Note: See TracBrowser for help on using the repository browser.