source: rtems/cpukit/score/include/rtems/score/scheduleredf.h @ 21bdca4

5
Last change on this file since 21bdca4 was 21bdca4, checked in by Sebastian Huber <sebastian.huber@…>, on 08/03/16 at 13:41:31

score: Indroduce cancel job scheduler operation

Do not use a deadline value of zero to indicate a job cancellation. Use
a dedicated scheduler operation for this.

  • 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#include <limits.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/**
34 *  @defgroup ScoreSchedulerEDF EDF Scheduler
35 *
36 *  @ingroup ScoreScheduler
37 */
38/**@{*/
39
40/*
41 * Actually the EDF scheduler supports a maximum priority of
42 * 0x7fffffffffffffff, but the user API is limited to uint32_t or int for
43 * thread priorities.  Ignore ILP64 targets for now.
44 */
45#define SCHEDULER_EDF_MAXIMUM_PRIORITY INT_MAX
46
47/**
48 *  Entry points for the Earliest Deadline First Scheduler.
49 */
50#define SCHEDULER_EDF_ENTRY_POINTS \
51  { \
52    _Scheduler_EDF_Initialize,       /* initialize entry point */ \
53    _Scheduler_EDF_Schedule,         /* schedule entry point */ \
54    _Scheduler_EDF_Yield,            /* yield entry point */ \
55    _Scheduler_EDF_Block,            /* block entry point */ \
56    _Scheduler_EDF_Unblock,          /* unblock entry point */ \
57    _Scheduler_EDF_Update_priority,  /* update priority entry point */ \
58    _Scheduler_EDF_Map_priority,     /* map priority entry point */ \
59    _Scheduler_EDF_Unmap_priority,   /* unmap priority entry point */ \
60    SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP \
61    _Scheduler_EDF_Node_initialize,  /* node initialize entry point */ \
62    _Scheduler_default_Node_destroy, /* node destroy entry point */ \
63    _Scheduler_EDF_Release_job,      /* new period of task */ \
64    _Scheduler_EDF_Cancel_job,       /* cancel period of task */ \
65    _Scheduler_default_Tick,         /* tick entry point */ \
66    _Scheduler_default_Start_idle    /* start idle entry point */ \
67    SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
68  }
69
70typedef struct {
71  /**
72   * @brief Basic scheduler context.
73   */
74  Scheduler_Context Base;
75
76  /**
77   * Top of the ready queue.
78   */
79  RBTree_Control Ready;
80} Scheduler_EDF_Context;
81
82/**
83 * @brief Scheduler node specialization for EDF schedulers.
84 */
85typedef struct {
86  /**
87   * @brief Basic scheduler node.
88   */
89  Scheduler_Node Base;
90
91  /**
92   * Pointer to corresponding Thread Control Block.
93   */
94  Thread_Control *thread;
95  /**
96   * Rbtree node related to this thread.
97   */
98  RBTree_Node Node;
99
100  /**
101   * @brief The thread priority used by this scheduler instance in case no job
102   * is released.
103   */
104  Priority_Control background_priority;
105
106  /**
107   * @brief The thread priority currently used by this scheduler instance.
108   */
109  Priority_Control current_priority;
110} Scheduler_EDF_Node;
111
112/**
113 *  @brief Initialize EDF scheduler.
114 *
115 *  This routine initializes the EDF scheduler.
116 *
117 *  @param[in] scheduler The scheduler instance.
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] scheduler The scheduler instance.
130 *  @param[in] the_thread is the thread to be blocked.
131 */
132void _Scheduler_EDF_Block(
133  const Scheduler_Control *scheduler,
134  Thread_Control          *the_thread
135);
136
137/**
138 *  @brief Sets the heir thread to be the next ready thread
139 *  in the rbtree ready queue.
140 *
141 *  This kernel routine sets the heir thread to be the next ready thread
142 *  in the rbtree ready queue.
143 *
144 *  @param[in] scheduler The scheduler instance.
145 *  @param[in] the_thread being scheduled.
146 */
147void _Scheduler_EDF_Schedule(
148  const Scheduler_Control *scheduler,
149  Thread_Control          *the_thread
150);
151
152/**
153 *  @brief Initializes an EDF specific scheduler node of @a the_thread.
154 *
155 *  @param[in] scheduler The scheduler instance.
156 *  @param[in] node being initialized.
157 *  @param[in] the_thread the thread of the node.
158 *  @param[in] priority The thread priority.
159 */
160void _Scheduler_EDF_Node_initialize(
161  const Scheduler_Control *scheduler,
162  Scheduler_Node          *node,
163  Thread_Control          *the_thread,
164  Priority_Control         priority
165);
166
167/**
168 *  @brief Adds @a the_thread to the scheduling decision.
169 *
170 *  This routine adds @a the_thread to the scheduling decision, that is,
171 *  adds it to the ready queue and updates any appropriate scheduling
172 *  variables, for example the heir thread.
173 *
174 *  @param[in] scheduler The scheduler instance.
175 *  @param[in] the_thread will be unblocked.
176 */
177Scheduler_Void_or_thread _Scheduler_EDF_Unblock(
178  const Scheduler_Control *scheduler,
179  Thread_Control          *the_thread
180);
181
182Scheduler_Void_or_thread _Scheduler_EDF_Update_priority(
183  const Scheduler_Control *scheduler,
184  Thread_Control          *the_thread
185);
186
187Priority_Control _Scheduler_EDF_Map_priority(
188  const Scheduler_Control *scheduler,
189  Priority_Control         priority
190);
191
192Priority_Control _Scheduler_EDF_Unmap_priority(
193  const Scheduler_Control *scheduler,
194  Priority_Control         priority
195);
196
197/**
198 *  @brief invoked when a thread wishes to voluntarily
199 *  transfer control of the processor to another thread
200 *  with equal deadline.
201 *
202 *  This routine is invoked when a thread wishes to voluntarily
203 *  transfer control of the processor to another thread in the queue with
204 *  equal deadline. This does not have to happen very often.
205 *
206 *  This routine will remove the specified THREAD from the ready queue
207 *  and place it back. The rbtree ready queue is responsible for FIFO ordering
208 *  in such a case.
209 *
210 *  @param[in] scheduler The scheduler instance.
211 *  @param[in,out] the_thread The yielding thread.
212 */
213Scheduler_Void_or_thread _Scheduler_EDF_Yield(
214  const Scheduler_Control *scheduler,
215  Thread_Control          *the_thread
216);
217
218/**
219 *  @brief Called when a new job of task is released.
220 *
221 *  This routine is called when a new job of task is released.
222 *  It is called only from Rate Monotonic manager in the beginning
223 *  of new period.
224 *
225 *  @param[in] scheduler The scheduler instance.
226 *  @param[in] the_thread is the owner of the job.
227 *  @param[in] deadline of the new job from now. If equal to 0,
228 *             the job was cancelled or deleted, thus a running task
229 *             has to be suspended.
230 */
231void _Scheduler_EDF_Release_job(
232  const Scheduler_Control *scheduler,
233  Thread_Control          *the_thread,
234  uint64_t                 deadline
235);
236
237void _Scheduler_EDF_Cancel_job(
238  const Scheduler_Control *scheduler,
239  Thread_Control          *the_thread
240);
241
242#ifdef __cplusplus
243}
244#endif
245
246/**@}*/
247
248#endif
249/* end of include file */
Note: See TracBrowser for help on using the repository browser.