source: rtems/cpukit/score/include/rtems/score/scheduleredf.h @ 7ec66e08

5
Last change on this file since 7ec66e08 was 77ff5599, checked in by Sebastian Huber <sebastian.huber@…>, on 06/10/16 at 06:48:54

score: Introduce map priority scheduler operation

Introduce map/unmap priority scheduler operations to map thread priority
values from/to the user domain to/from the scheduler domain. Use the
map priority operation to validate the thread priority. The EDF
schedulers use this new operation to distinguish between normal
priorities and priorities obtain through a job release.

Update #2173.
Update #2556.

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