source: rtems/cpukit/score/include/rtems/score/schedulercbs.h @ ee0e4135

5
Last change on this file since ee0e4135 was ee0e4135, checked in by Sebastian Huber <sebastian.huber@…>, on 08/04/16 at 08:20:29

score: Fix a release/cancel job race condition

Split up the potential thread priority change in the scheduler
release/cancel job operation. Protect the rate monotonic period state
with a dedicated SMP lock. This avoids a race condition during
_Rate_monotonic_Timeout() while _Rate_monotonic_Cancel() is called on
another processor.

  • Property mode set to 100644
File size: 9.3 KB
Line 
1/**
2 *  @file  rtems/score/schedulercbs.h
3 *
4 *  @brief Thread manipulation for the CBS scheduler
5 *
6 *  This include file contains all the constants and structures associated
7 *  with the manipulation of threads for the CBS 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_SCHEDULERCBS_H
20#define _RTEMS_SCORE_SCHEDULERCBS_H
21
22#include <rtems/score/chain.h>
23#include <rtems/score/priority.h>
24#include <rtems/score/scheduler.h>
25#include <rtems/score/rbtree.h>
26#include <rtems/score/scheduleredf.h>
27#include <rtems/rtems/signal.h>
28#include <rtems/rtems/timer.h>
29#include <rtems/score/thread.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35/**
36 *  @defgroup ScoreSchedulerCBS CBS Scheduler
37 *
38 *  @ingroup ScoreScheduler
39 */
40/**@{*/
41
42#define SCHEDULER_CBS_MAXIMUM_PRIORITY SCHEDULER_EDF_MAXIMUM_PRIORITY
43
44/**
45 *  Entry points for the Constant Bandwidth Server Scheduler.
46 *
47 *  @note: The CBS scheduler is an enhancement of EDF scheduler,
48 *         therefor some routines are similar.
49 */
50#define SCHEDULER_CBS_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_CBS_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_CBS_Node_initialize,  /* node initialize entry point */ \
62    _Scheduler_default_Node_destroy, /* node destroy entry point */ \
63    _Scheduler_CBS_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
70/* Return values for CBS server. */
71#define SCHEDULER_CBS_OK                        0
72#define SCHEDULER_CBS_ERROR_GENERIC            -16
73#define SCHEDULER_CBS_ERROR_NO_MEMORY          -17
74#define SCHEDULER_CBS_ERROR_INVALID_PARAMETER  -18
75#define SCHEDULER_CBS_ERROR_UNAUTHORIZED       -19
76#define SCHEDULER_CBS_ERROR_UNIMPLEMENTED      -20
77#define SCHEDULER_CBS_ERROR_MISSING_COMPONENT  -21
78#define SCHEDULER_CBS_ERROR_INCONSISTENT_STATE -22
79#define SCHEDULER_CBS_ERROR_SYSTEM_OVERLOAD    -23
80#define SCHEDULER_CBS_ERROR_INTERNAL_ERROR     -24
81#define SCHEDULER_CBS_ERROR_NOT_FOUND          -25
82#define SCHEDULER_CBS_ERROR_FULL               -26
83#define SCHEDULER_CBS_ERROR_EMPTY              -27
84#define SCHEDULER_CBS_ERROR_NOSERVER           SCHEDULER_CBS_ERROR_NOT_FOUND
85
86/** Maximum number of simultaneous servers. */
87extern const uint32_t _Scheduler_CBS_Maximum_servers;
88
89/** Server id. */
90typedef uint32_t Scheduler_CBS_Server_id;
91
92/** Callback function invoked when a budget overrun of a task occurs. */
93typedef void (*Scheduler_CBS_Budget_overrun)(
94    Scheduler_CBS_Server_id server_id
95);
96
97/**
98 * This structure handles server parameters.
99 */
100typedef struct {
101  /** Relative deadline of the server. */
102  time_t deadline;
103  /** Budget (computation time) of the server. */
104  time_t budget;
105} Scheduler_CBS_Parameters;
106
107/**
108 * This structure represents a time server.
109 */
110typedef struct {
111  /**
112   * Task id.
113   *
114   * @note: The current implementation of CBS handles only one task per server.
115   */
116  rtems_id                 task_id;
117  /** Server paramenters. */
118  Scheduler_CBS_Parameters parameters;
119  /** Callback function invoked when a budget overrun occurs. */
120  Scheduler_CBS_Budget_overrun  cbs_budget_overrun;
121
122  /**
123   * @brief Indicates if this CBS server is initialized.
124   *
125   * @see _Scheduler_CBS_Create_server() and _Scheduler_CBS_Destroy_server().
126   */
127  bool initialized;
128} Scheduler_CBS_Server;
129
130/**
131 * This structure handles CBS specific data of a thread.
132 */
133typedef struct {
134  /** EDF scheduler specific data of a task. */
135  Scheduler_EDF_Node            Base;
136  /** CBS server specific data of a task. */
137  Scheduler_CBS_Server         *cbs_server;
138} Scheduler_CBS_Node;
139
140
141/**
142 * List of servers. The @a Scheduler_CBS_Server is the index to the array
143 * of pointers to @a _Scheduler_CBS_Server_list.
144 */
145extern Scheduler_CBS_Server _Scheduler_CBS_Server_list[];
146
147/**
148 *  @brief Unblocks a thread from the queue.
149 *
150 *  This routine adds @a the_thread to the scheduling decision, that is,
151 *  adds it to the ready queue and updates any appropriate scheduling
152 *  variables, for example the heir thread. It is checked whether the
153 *  remaining budget is sufficient. If not, the thread continues as a
154 *  new job in order to protect concurrent threads.
155 *
156 *  @param[in] scheduler The scheduler instance.
157 *  @param[in] the_thread will be unblocked.
158 *
159 *  @note This has to be asessed as missed deadline of the current job.
160 */
161Scheduler_Void_or_thread _Scheduler_CBS_Unblock(
162  const Scheduler_Control *scheduler,
163  Thread_Control          *the_thread
164);
165
166Thread_Control *_Scheduler_CBS_Release_job(
167  const Scheduler_Control *scheduler,
168  Thread_Control          *the_thread,
169  uint64_t                 length
170);
171
172/**
173 *  @brief _Scheduler_CBS_Initialize
174 *
175 *  Initializes the CBS library.
176 *
177 *  @retval status code.
178 */
179int _Scheduler_CBS_Initialize(void);
180
181/**
182 *  @brief Attach a task to an already existing server.
183 *
184 *  Attach a task to an already existing server.
185 *
186 *  @retval status code.
187 */
188int _Scheduler_CBS_Attach_thread (
189  Scheduler_CBS_Server_id server_id,
190  rtems_id                task_id
191);
192
193/**
194 *  @brief Detach from the CBS Server.
195 *
196 *  Detach from the CBS Server.
197 *
198 *  @retval status code.
199 */
200int _Scheduler_CBS_Detach_thread (
201  Scheduler_CBS_Server_id server_id,
202  rtems_id                task_id
203);
204
205/**
206 *  @brief Cleanup resources associated to the CBS Library.
207 *
208 *  Cleanup resources associated to the CBS Library.
209 *
210 *  @retval status code.
211 */
212int _Scheduler_CBS_Cleanup (void);
213
214/**
215 *  @brief Create a new server with specified parameters.
216 *
217 *  Create a new server with specified parameters.
218 *
219 *  @retval status code.
220 */
221int _Scheduler_CBS_Create_server (
222  Scheduler_CBS_Parameters     *params,
223  Scheduler_CBS_Budget_overrun  budget_overrun_callback,
224  rtems_id                     *server_id
225);
226
227/**
228 *  @brief Detach all tasks from a server and destroy it.
229 *
230 *  Detach all tasks from a server and destroy it.
231 *
232 *  @param[in] server_id is the ID of the server
233 *
234 *  @retval status code.
235 */
236int _Scheduler_CBS_Destroy_server (
237  Scheduler_CBS_Server_id server_id
238);
239
240/**
241 *  @brief Retrieve the approved budget.
242 *
243 *  Retrieve the budget that has been approved for the subsequent
244 *  server instances.
245 *
246 *  @retval status code.
247 */
248int _Scheduler_CBS_Get_approved_budget (
249  Scheduler_CBS_Server_id  server_id,
250  time_t                  *approved_budget
251);
252
253/**
254 *  @brief Retrieve remaining budget for the current server instance.
255 *
256 *  Retrieve remaining budget for the current server instance.
257 *
258 *  @retval status code.
259 */
260int _Scheduler_CBS_Get_remaining_budget (
261  Scheduler_CBS_Server_id  server_id,
262  time_t                  *remaining_budget
263);
264
265/**
266 *  @brief Get relative time info.
267 *
268 *  Retrieve time info relative to @a server_id. The server status code is returned.
269 *
270 *  @param[in] server_id is the server to get the status code from.
271 *  @param[in] exec_time is the execution time.
272 *  @param[in] abs_time is not apparently used.
273 *
274 *  @retval status code.
275 */
276int _Scheduler_CBS_Get_execution_time (
277  Scheduler_CBS_Server_id   server_id,
278  time_t                   *exec_time,
279  time_t                   *abs_time
280);
281
282/**
283 *  @brief Retrieve CBS scheduling parameters.
284 *
285 *  Retrieve CBS scheduling parameters.
286 *
287 *  @retval status code.
288 */
289int _Scheduler_CBS_Get_parameters (
290  Scheduler_CBS_Server_id   server_id,
291  Scheduler_CBS_Parameters *params
292);
293
294/**
295 *  @brief Get a thread server id.
296 *
297 *  Get a thread server id, or SCHEDULER_CBS_ERROR_NOT_FOUND if it is not
298 *  attached to any server.
299 *
300 *  @retval status code.
301 */
302int _Scheduler_CBS_Get_server_id (
303  rtems_id                 task_id,
304  Scheduler_CBS_Server_id *server_id
305);
306
307/**
308 *  @brief Set parameters for CBS scheduling.
309 *
310 *  Change CBS scheduling parameters.
311 *
312 *  @param[in] server_id is the ID of the server.
313 *  @param[in] parameters are the parameters to set.
314 *
315 *  @retval status code.
316 */
317int _Scheduler_CBS_Set_parameters (
318  Scheduler_CBS_Server_id   server_id,
319  Scheduler_CBS_Parameters *parameters
320);
321
322/**
323 *  @brief Invoked when a limited time quantum is exceeded.
324 *
325 *  This routine is invoked when a limited time quantum is exceeded.
326 */
327void _Scheduler_CBS_Budget_callout(
328  Thread_Control *the_thread
329);
330
331/**
332 *  @brief Initializes a CBS specific scheduler node of @a the_thread.
333 */
334void _Scheduler_CBS_Node_initialize(
335  const Scheduler_Control *scheduler,
336  Scheduler_Node          *node,
337  Thread_Control          *the_thread,
338  Priority_Control         priority
339);
340
341#ifdef __cplusplus
342}
343#endif
344
345/**@}*/
346
347#endif
348/* end of include file */
Note: See TracBrowser for help on using the repository browser.