source: rtems/cpukit/score/include/rtems/score/schedulercbs.h @ 9a78f8a5

5
Last change on this file since 9a78f8a5 was 9a78f8a5, checked in by Sebastian Huber <sebastian.huber@…>, on 06/16/16 at 15:08:54

score: Modify release job scheduler operation

Pass the deadline in watchdog ticks to the scheduler.

Update #2173.

  • Property mode set to 100644
File size: 9.7 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_Change_priority,  /* change 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_EDF_Update_priority,  /* update priority entry point */ \
64    _Scheduler_CBS_Release_job,      /* new 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
166/**
167 *  @brief Called when a new job of task is released.
168 *
169 *  This routine is called when a new job of task is released.
170 *  It is called only from Rate Monotonic manager in the beginning
171 *  of new period. Deadline has to be shifted and budget replenished.
172 *
173 *  @param[in] scheduler The scheduler instance.
174 *  @param[in] the_thread is the owner of the job.
175 *  @param[in] length of the new job from now. If equal to 0,
176 *             the job was cancelled or deleted.
177 */
178
179void _Scheduler_CBS_Release_job (
180  const Scheduler_Control *scheduler,
181  Thread_Control          *the_thread,
182  uint64_t                 length
183);
184
185/**
186 *  @brief _Scheduler_CBS_Initialize
187 *
188 *  Initializes the CBS library.
189 *
190 *  @retval status code.
191 */
192int _Scheduler_CBS_Initialize(void);
193
194/**
195 *  @brief Attach a task to an already existing server.
196 *
197 *  Attach a task to an already existing server.
198 *
199 *  @retval status code.
200 */
201int _Scheduler_CBS_Attach_thread (
202  Scheduler_CBS_Server_id server_id,
203  rtems_id                task_id
204);
205
206/**
207 *  @brief Detach from the CBS Server.
208 *
209 *  Detach from the CBS Server.
210 *
211 *  @retval status code.
212 */
213int _Scheduler_CBS_Detach_thread (
214  Scheduler_CBS_Server_id server_id,
215  rtems_id                task_id
216);
217
218/**
219 *  @brief Cleanup resources associated to the CBS Library.
220 *
221 *  Cleanup resources associated to the CBS Library.
222 *
223 *  @retval status code.
224 */
225int _Scheduler_CBS_Cleanup (void);
226
227/**
228 *  @brief Create a new server with specified parameters.
229 *
230 *  Create a new server with specified parameters.
231 *
232 *  @retval status code.
233 */
234int _Scheduler_CBS_Create_server (
235  Scheduler_CBS_Parameters     *params,
236  Scheduler_CBS_Budget_overrun  budget_overrun_callback,
237  rtems_id                     *server_id
238);
239
240/**
241 *  @brief Detach all tasks from a server and destroy it.
242 *
243 *  Detach all tasks from a server and destroy it.
244 *
245 *  @param[in] server_id is the ID of the server
246 *
247 *  @retval status code.
248 */
249int _Scheduler_CBS_Destroy_server (
250  Scheduler_CBS_Server_id server_id
251);
252
253/**
254 *  @brief Retrieve the approved budget.
255 *
256 *  Retrieve the budget that has been approved for the subsequent
257 *  server instances.
258 *
259 *  @retval status code.
260 */
261int _Scheduler_CBS_Get_approved_budget (
262  Scheduler_CBS_Server_id  server_id,
263  time_t                  *approved_budget
264);
265
266/**
267 *  @brief Retrieve remaining budget for the current server instance.
268 *
269 *  Retrieve remaining budget for the current server instance.
270 *
271 *  @retval status code.
272 */
273int _Scheduler_CBS_Get_remaining_budget (
274  Scheduler_CBS_Server_id  server_id,
275  time_t                  *remaining_budget
276);
277
278/**
279 *  @brief Get relative time info.
280 *
281 *  Retrieve time info relative to @a server_id. The server status code is returned.
282 *
283 *  @param[in] server_id is the server to get the status code from.
284 *  @param[in] exec_time is the execution time.
285 *  @param[in] abs_time is not apparently used.
286 *
287 *  @retval status code.
288 */
289int _Scheduler_CBS_Get_execution_time (
290  Scheduler_CBS_Server_id   server_id,
291  time_t                   *exec_time,
292  time_t                   *abs_time
293);
294
295/**
296 *  @brief Retrieve CBS scheduling parameters.
297 *
298 *  Retrieve CBS scheduling parameters.
299 *
300 *  @retval status code.
301 */
302int _Scheduler_CBS_Get_parameters (
303  Scheduler_CBS_Server_id   server_id,
304  Scheduler_CBS_Parameters *params
305);
306
307/**
308 *  @brief Get a thread server id.
309 *
310 *  Get a thread server id, or SCHEDULER_CBS_ERROR_NOT_FOUND if it is not
311 *  attached to any server.
312 *
313 *  @retval status code.
314 */
315int _Scheduler_CBS_Get_server_id (
316  rtems_id                 task_id,
317  Scheduler_CBS_Server_id *server_id
318);
319
320/**
321 *  @brief Set parameters for CBS scheduling.
322 *
323 *  Change CBS scheduling parameters.
324 *
325 *  @param[in] server_id is the ID of the server.
326 *  @param[in] parameters are the parameters to set.
327 *
328 *  @retval status code.
329 */
330int _Scheduler_CBS_Set_parameters (
331  Scheduler_CBS_Server_id   server_id,
332  Scheduler_CBS_Parameters *parameters
333);
334
335/**
336 *  @brief Invoked when a limited time quantum is exceeded.
337 *
338 *  This routine is invoked when a limited time quantum is exceeded.
339 */
340void _Scheduler_CBS_Budget_callout(
341  Thread_Control *the_thread
342);
343
344/**
345 *  @brief Initializes a CBS specific scheduler node of @a the_thread.
346 */
347void _Scheduler_CBS_Node_initialize(
348  const Scheduler_Control *scheduler,
349  Thread_Control          *the_thread
350);
351
352#ifdef __cplusplus
353}
354#endif
355
356/**@}*/
357
358#endif
359/* end of include file */
Note: See TracBrowser for help on using the repository browser.