source: rtems/cpukit/score/include/rtems/score/scheduleredf.h @ 99fc1d1d

5
Last change on this file since 99fc1d1d was 99fc1d1d, checked in by Sebastian Huber <sebastian.huber@…>, on 06/09/16 at 19:30:40

score: Rework EDF scheduler

Use inline red-black tree insert. Do not use shifting priorities since
this is not supported by the thread queues. Due to the 32-bit
Priority_Control this currently limits the uptime to 49days with a 1ms
clock tick.

Update #2173.

  • Property mode set to 100644
File size: 7.4 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
[99fc1d1d]38#define SCHEDULER_EDF_MAXIMUM_PRIORITY 0x7fffffff
[7dfb4b9]39
[5472ad41]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 */ \
[f39f667a]50    _Scheduler_EDF_Change_priority,  /* change priority entry point */ \
[77ff5599]51    _Scheduler_EDF_Map_priority,     /* map priority entry point */ \
52    _Scheduler_EDF_Unmap_priority,   /* unmap priority entry point */ \
[5c3d250]53    SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP \
[8e467384]54    _Scheduler_EDF_Node_initialize,  /* node initialize entry point */ \
55    _Scheduler_default_Node_destroy, /* node destroy entry point */ \
[4d1f500]56    _Scheduler_EDF_Update_priority,  /* update priority entry point */ \
[5472ad41]57    _Scheduler_EDF_Release_job,      /* new period of task */ \
[a344308]58    _Scheduler_default_Tick,         /* tick entry point */ \
[1ccb64e1]59    _Scheduler_default_Start_idle    /* start idle entry point */ \
[bd1431a]60    SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
[5472ad41]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
[3891983]72typedef struct {
[e1598a6]73  /**
74   * @brief Basic scheduler context.
75   */
76  Scheduler_Context Base;
77
[3891983]78  /**
79   * Top of the ready queue.
80   */
81  RBTree_Control Ready;
[e1598a6]82} Scheduler_EDF_Context;
[3891983]83
[5472ad41]84/**
[beab7329]85 * @brief Scheduler node specialization for EDF schedulers.
[5472ad41]86 */
87typedef struct {
[beab7329]88  /**
89   * @brief Basic scheduler node.
90   */
91  Scheduler_Node Base;
92
[5472ad41]93  /**
94   * Pointer to corresponding Thread Control Block.
95   */
96  Thread_Control *thread;
97  /**
98   * Rbtree node related to this thread.
99   */
100  RBTree_Node Node;
[99fc1d1d]101
102  /**
103   * @brief The thread priority used by this scheduler instance in case no job
104   * is released.
105   */
106  Priority_Control background_priority;
107
[5472ad41]108  /**
[99fc1d1d]109   * @brief The thread priority currently used by this scheduler instance.
[5472ad41]110   */
[99fc1d1d]111  Priority_Control current_priority;
[beab7329]112} Scheduler_EDF_Node;
[5472ad41]113
114/**
[a7e4de2]115 *  @brief Initialize EDF scheduler.
[5472ad41]116 *
[a7e4de2]117 *  This routine initializes the EDF scheduler.
118 *
119 *  @param[in] scheduler The scheduler instance.
[5472ad41]120 */
[e1598a6]121void _Scheduler_EDF_Initialize( const Scheduler_Control *scheduler );
[5472ad41]122
123/**
[a1f9934a]124 *  @brief Removes thread from ready queue.
[5472ad41]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 *
[a7e4de2]131 *  @param[in] scheduler The scheduler instance.
[5472ad41]132 *  @param[in] the_thread is the thread to be blocked.
133 */
134void _Scheduler_EDF_Block(
[e1598a6]135  const Scheduler_Control *scheduler,
136  Thread_Control          *the_thread
[5472ad41]137);
138
139/**
[a1f9934a]140 *  @brief Sets the heir thread to be the next ready thread
141 *  in the rbtree ready queue.
[5472ad41]142 *
143 *  This kernel routine sets the heir thread to be the next ready thread
144 *  in the rbtree ready queue.
[a7e4de2]145 *
146 *  @param[in] scheduler The scheduler instance.
147 *  @param[in] the_thread being scheduled.
[5472ad41]148 */
[24934e36]149void _Scheduler_EDF_Schedule(
[e1598a6]150  const Scheduler_Control *scheduler,
151  Thread_Control          *the_thread
[24934e36]152);
[5472ad41]153
154/**
[8e467384]155 *  @brief Initializes an EDF specific scheduler node of @a the_thread.
[a7e4de2]156 *
157 *  @param[in] scheduler The scheduler instance.
158 *  @param[in] the_thread being initialized.
[5472ad41]159 */
[8e467384]160void _Scheduler_EDF_Node_initialize(
[e1598a6]161  const Scheduler_Control *scheduler,
162  Thread_Control          *the_thread
[5472ad41]163);
164
165/**
[a1f9934a]166 *  @brief Updates position in the ready queue of @a the_thread.
[5472ad41]167 *
168 *  This routine updates position in the ready queue of @a the_thread.
169 *
[a7e4de2]170 *  @param[in] scheduler The scheduler instance.
[5472ad41]171 *  @param[in] the_thread will have its scheduler specific information
172 *             structure updated.
[a7e4de2]173 *  @param[in] new_priority is the desired new priority.
[5472ad41]174 */
[4d1f500]175void _Scheduler_EDF_Update_priority(
[e1598a6]176  const Scheduler_Control *scheduler,
[4d1f500]177  Thread_Control          *the_thread,
178  Priority_Control         new_priority
[5472ad41]179);
180
181/**
[a1f9934a]182 *  @brief Adds @a the_thread to the scheduling decision.
[5472ad41]183 *
184 *  This routine adds @a the_thread to the scheduling decision, that is,
185 *  adds it to the ready queue and updates any appropriate scheduling
186 *  variables, for example the heir thread.
187 *
[a7e4de2]188 *  @param[in] scheduler The scheduler instance.
[5472ad41]189 *  @param[in] the_thread will be unblocked.
190 */
[8568341]191Scheduler_Void_or_thread _Scheduler_EDF_Unblock(
[e1598a6]192  const Scheduler_Control *scheduler,
193  Thread_Control          *the_thread
[5472ad41]194);
195
[8568341]196Scheduler_Void_or_thread _Scheduler_EDF_Change_priority(
[f39f667a]197  const Scheduler_Control *scheduler,
198  Thread_Control          *the_thread,
199  Priority_Control         new_priority,
200  bool                     prepend_it
201);
202
[77ff5599]203Priority_Control _Scheduler_EDF_Map_priority(
204  const Scheduler_Control *scheduler,
205  Priority_Control         priority
206);
207
208Priority_Control _Scheduler_EDF_Unmap_priority(
209  const Scheduler_Control *scheduler,
210  Priority_Control         priority
211);
212
[5472ad41]213/**
[a1f9934a]214 *  @brief invoked when a thread wishes to voluntarily
215 *  transfer control of the processor to another thread
216 *  with equal deadline.
[5472ad41]217 *
218 *  This routine is invoked when a thread wishes to voluntarily
219 *  transfer control of the processor to another thread in the queue with
220 *  equal deadline. This does not have to happen very often.
221 *
[6eba7c85]222 *  This routine will remove the specified THREAD from the ready queue
223 *  and place it back. The rbtree ready queue is responsible for FIFO ordering
[5472ad41]224 *  in such a case.
[6eba7c85]225 *
[a7e4de2]226 *  @param[in] scheduler The scheduler instance.
227 *  @param[in,out] the_thread The yielding thread.
[5472ad41]228 */
[8568341]229Scheduler_Void_or_thread _Scheduler_EDF_Yield(
[e1598a6]230  const Scheduler_Control *scheduler,
231  Thread_Control          *the_thread
[24934e36]232);
[5472ad41]233
234/**
[a1f9934a]235 *  @brief Called when a new job of task is released.
[5472ad41]236 *
237 *  This routine is called when a new job of task is released.
238 *  It is called only from Rate Monotonic manager in the beginning
239 *  of new period.
240 *
[a7e4de2]241 *  @param[in] scheduler The scheduler instance.
[5472ad41]242 *  @param[in] the_thread is the owner of the job.
243 *  @param[in] deadline of the new job from now. If equal to 0,
244 *             the job was cancelled or deleted, thus a running task
245 *             has to be suspended.
246 */
247void _Scheduler_EDF_Release_job (
[e1598a6]248  const Scheduler_Control *scheduler,
249  Thread_Control          *the_thread,
[9a78f8a5]250  uint64_t                 deadline
[5472ad41]251);
252
253#ifdef __cplusplus
254}
255#endif
256
257/**@}*/
258
259#endif
[a15eaaf]260/* end of include file */
Note: See TracBrowser for help on using the repository browser.