source: rtems/cpukit/score/include/rtems/score/scheduleredf.h @ 993f5ac

4.115
Last change on this file since 993f5ac was 5c3d250, checked in by Sebastian Huber <sebastian.huber@…>, on 07/04/14 at 12:34:23

score: Implement scheduler helping protocol

The following scheduler operations return a thread in need for help

  • unblock,
  • change priority, and
  • yield.

A thread in need for help is a thread that encounters a scheduler state
change from scheduled to ready or a thread that cannot be scheduled in
an unblock operation. Such a thread can ask threads which depend on
resources owned by this thread for help.

Add a new ask for help scheduler operation. This operation is used by
_Scheduler_Ask_for_help() to help threads in need for help returned by
the operations mentioned above. This operation is also used by
_Scheduler_Thread_change_resource_root() in case the root of a resource
sub-tree changes. A use case is the ownership change of a resource.

In case it is not possible to schedule a thread in need for help, then
the corresponding scheduler node will be placed into the set of ready
scheduler nodes of the scheduler instance. Once a state change from
ready to scheduled happens for this scheduler node it may be used to
schedule the thread in need for help.

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