source: rtems/cpukit/score/include/rtems/score/scheduleredf.h @ 2369b10

4.115
Last change on this file since 2369b10 was beab7329, checked in by Sebastian Huber <sebastian.huber@…>, on 05/13/14 at 14:03:05

score: Introduce scheduler nodes

Rename scheduler per-thread information into scheduler nodes using
Scheduler_Node as the base type. Use inheritance for specialized
schedulers.

Move the scheduler specific states from the thread control block into
the scheduler node structure.

Validate the SMP scheduler node state transitions in case RTEMS_DEBUG is
defined.

  • Property mode set to 100644
File size: 7.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_Allocate,         /* allocate entry point */ \
49    _Scheduler_default_Free,         /* free entry point */ \
50    _Scheduler_EDF_Update,           /* update entry point */ \
51    _Scheduler_EDF_Enqueue,          /* enqueue entry point */ \
52    _Scheduler_EDF_Enqueue_first,    /* enqueue_first entry point */ \
53    _Scheduler_EDF_Extract,          /* extract entry point */ \
54    _Scheduler_EDF_Priority_compare, /* compares two priorities */ \
55    _Scheduler_EDF_Release_job,      /* new period of task */ \
56    _Scheduler_default_Tick,         /* tick entry point */ \
57    _Scheduler_default_Start_idle    /* start idle entry point */ \
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 Allocates EDF specific information of @a the_thread.
152 *
153 *  This routine allocates EDF specific information of @a the_thread.
154 *
155 *  @param[in] the_thread is the thread the scheduler is allocating
156 *             management memory for.
157 */
158bool _Scheduler_EDF_Allocate(
159  const Scheduler_Control *scheduler,
160  Thread_Control          *the_thread
161);
162
163/**
164 *  @brief Updates position in the ready queue of @a the_thread.
165 *
166 *  This routine updates position in the ready queue of @a the_thread.
167 *
168 *  @param[in] the_thread will have its scheduler specific information
169 *             structure updated.
170 */
171void _Scheduler_EDF_Update(
172  const Scheduler_Control *scheduler,
173  Thread_Control          *the_thread
174);
175
176/**
177 *  @brief Adds @a the_thread to the scheduling decision.
178 *
179 *  This routine adds @a the_thread to the scheduling decision, that is,
180 *  adds it to the ready queue and updates any appropriate scheduling
181 *  variables, for example the heir thread.
182 *
183 *  @param[in] the_thread will be unblocked.
184 */
185void _Scheduler_EDF_Unblock(
186  const Scheduler_Control *scheduler,
187  Thread_Control          *the_thread
188);
189
190/**
191 *  @brief invoked when a thread wishes to voluntarily
192 *  transfer control of the processor to another thread
193 *  with equal deadline.
194 *
195 *  This routine is invoked when a thread wishes to voluntarily
196 *  transfer control of the processor to another thread in the queue with
197 *  equal deadline. This does not have to happen very often.
198 *
199 *  This routine will remove the specified THREAD from the ready queue
200 *  and place it back. The rbtree ready queue is responsible for FIFO ordering
201 *  in such a case.
202 *
203 *  @param[in,out] thread The yielding thread.
204 */
205void _Scheduler_EDF_Yield(
206  const Scheduler_Control *scheduler,
207  Thread_Control          *the_thread
208);
209
210/**
211 *  @brief Put @a the_thread to the rbtree ready queue.
212 *
213 *  This routine puts @a the_thread to the rbtree ready queue.
214 *
215 *  @param[in] the_thread will be enqueued to the ready queue.
216 */
217void _Scheduler_EDF_Enqueue(
218  const Scheduler_Control *scheduler,
219  Thread_Control          *the_thread
220);
221
222/**
223 *  @brief Enqueue a thread to the ready queue.
224 *
225 *  This routine puts @a the_thread to the rbtree ready queue.
226 *  For the EDF scheduler this is the same as @a _Scheduler_EDF_Enqueue.
227 *
228 *  @param[in] the_thread will be enqueued to the ready queue.
229 */
230void _Scheduler_EDF_Enqueue_first(
231  const Scheduler_Control *scheduler,
232  Thread_Control          *the_thread
233);
234
235/**
236 *  @brief Remove a specific thread from the scheduler's set
237 *  of ready threads.
238 *
239 *  This routine removes a specific thread from the scheduler's set
240 *  of ready threads.
241 *
242 *  @param[in] the_thread will be extracted from the ready set.
243 */
244void _Scheduler_EDF_Extract(
245  const Scheduler_Control *scheduler,
246  Thread_Control          *the_thread
247);
248
249/**
250 *  @brief Explicitly compare absolute dedlines (priorities) of threads.
251 *
252 * This routine explicitly compares absolute dedlines (priorities) of threads.
253 * In case of EDF scheduling time overflow is taken into account.
254 *
255 * @retval >0 for p1 > p2; 0 for p1 == p2; <0 for p1 < p2.
256 */
257int _Scheduler_EDF_Priority_compare (
258  Priority_Control p1,
259  Priority_Control p2
260);
261
262/**
263 *  @brief Called when a new job of task is released.
264 *
265 *  This routine is called when a new job of task is released.
266 *  It is called only from Rate Monotonic manager in the beginning
267 *  of new period.
268 *
269 *  @param[in] the_thread is the owner of the job.
270 *  @param[in] deadline of the new job from now. If equal to 0,
271 *             the job was cancelled or deleted, thus a running task
272 *             has to be suspended.
273 */
274void _Scheduler_EDF_Release_job (
275  const Scheduler_Control *scheduler,
276  Thread_Control          *the_thread,
277  uint32_t                 deadline
278);
279
280#ifdef __cplusplus
281}
282#endif
283
284/**@}*/
285
286#endif
287/* end of include file */
Note: See TracBrowser for help on using the repository browser.