source: rtems/cpukit/score/include/rtems/score/scheduler.h @ 5b1ff71a

4.115
Last change on this file since 5b1ff71a was 5b1ff71a, checked in by Sebastian Huber <sebastian.huber@…>, on 05/13/14 at 13:57:43

score: Scheduler documentation

  • Property mode set to 100644
File size: 8.7 KB
Line 
1/**
2 *  @file  rtems/score/scheduler.h
3 *
4 *  @brief Constants and Structures Associated with the Scheduler
5 *
6 *  This include file contains all the constants and structures associated
7 *  with the scheduler.
8 */
9
10/*
11 *  Copyright (C) 2010 Gedare Bloom.
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_SCHEDULER_H
20#define _RTEMS_SCORE_SCHEDULER_H
21
22#include <rtems/score/percpu.h>
23#include <rtems/score/priority.h>
24#include <rtems/score/thread.h>
25#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
26  #include <sys/cpuset.h>
27#endif
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/**
34 *  @defgroup ScoreScheduler Scheduler Handler
35 *
36 *  @ingroup Score
37 *
38 *  This handler encapsulates functionality related to managing sets of threads
39 *  that are ready for execution.
40 */
41/**@{*/
42
43typedef struct Scheduler_Control Scheduler_Control;
44
45/**
46 * @brief The scheduler operations.
47 */
48typedef struct {
49  /** @see _Scheduler_Handler_initialization() */
50  void ( *initialize )( const Scheduler_Control * );
51
52  /** @see _Scheduler_Schedule() */
53  void ( *schedule )( const Scheduler_Control *, Thread_Control *);
54
55  /** @see _Scheduler_Yield() */
56  void ( *yield )( const Scheduler_Control *, Thread_Control *);
57
58  /** @see _Scheduler_Block() */
59  void ( *block )( const Scheduler_Control *, Thread_Control * );
60
61  /** @see _Scheduler_Unblock() */
62  void ( *unblock )( const Scheduler_Control *, Thread_Control * );
63
64  /** @see _Scheduler_Allocate() */
65  bool ( *allocate )( const Scheduler_Control *, Thread_Control * );
66
67  /** @see _Scheduler_Free() */
68  void ( *free )( const Scheduler_Control *, Thread_Control * );
69
70  /** @see _Scheduler_Update() */
71  void ( *update )( const Scheduler_Control *, Thread_Control * );
72
73  /** @see _Scheduler_Enqueue() */
74  void ( *enqueue )( const Scheduler_Control *, Thread_Control * );
75
76  /** @see _Scheduler_Enqueue_first() */
77  void ( *enqueue_first )( const Scheduler_Control *, Thread_Control * );
78
79  /** @see _Scheduler_Extract() */
80  void ( *extract )( const Scheduler_Control *, Thread_Control * );
81
82  /** @see _Scheduler_Priority_compare() */
83  int ( *priority_compare )(
84    Priority_Control,
85    Priority_Control
86  );
87
88  /** @see _Scheduler_Release_job() */
89  void ( *release_job ) (
90    const Scheduler_Control *,
91    Thread_Control *,
92    uint32_t
93  );
94
95  /** @see _Scheduler_Tick() */
96  void ( *tick )( const Scheduler_Control *, Thread_Control * );
97
98  /** @see _Scheduler_Start_idle() */
99  void ( *start_idle )(
100    const Scheduler_Control *,
101    Thread_Control *,
102    Per_CPU_Control *
103  );
104
105#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
106  /** @see _Scheduler_Get_affinity() */
107  bool ( *get_affinity )(
108    const Scheduler_Control *,
109    Thread_Control *,
110    size_t,
111    cpu_set_t *
112  );
113 
114  /** @see _Scheduler_Set_affinity() */
115  bool ( *set_affinity )(
116    const Scheduler_Control *,
117    Thread_Control *,
118    size_t,
119    const cpu_set_t *
120  );
121#endif
122} Scheduler_Operations;
123
124/**
125 * @brief Scheduler context.
126 *
127 * The scheduler context of a particular scheduler implementation must place
128 * this structure at the begin of its context structure.
129 */
130typedef struct Scheduler_Context {
131#if defined(RTEMS_SMP)
132  /**
133   * @brief Count of processors owned by this scheduler instance.
134   */
135  uint32_t processor_count;
136#endif
137} Scheduler_Context;
138
139/**
140 * @brief Scheduler control.
141 */
142struct Scheduler_Control {
143  /**
144   * @brief Reference to a statically allocated scheduler context.
145   */
146  Scheduler_Context *context;
147
148  /**
149   * @brief The scheduler operations.
150   */
151  Scheduler_Operations Operations;
152
153  /**
154   * @brief The scheduler name.
155   */
156  uint32_t name;
157};
158
159/**
160 * @brief Registered schedulers.
161 *
162 * Application provided via <rtems/confdefs.h>.
163 *
164 * @see _Scheduler_Count.
165 */
166extern const Scheduler_Control _Scheduler_Table[];
167
168/**
169 * @brief Count of registered schedulers.
170 *
171 * Application provided via <rtems/confdefs.h> on SMP configurations.
172 *
173 * It is very important that this is a compile-time constant on uni-processor
174 * configurations (in this case RTEMS_SMP is not defined) so that the compiler
175 * can optimize the some loops away
176 *
177 * @see _Scheduler_Table.
178 */
179#if defined(RTEMS_SMP)
180  extern const size_t _Scheduler_Count;
181#else
182  #define _Scheduler_Count ( (size_t) 1 )
183#endif
184
185#if defined(RTEMS_SMP)
186  /**
187   * @brief The scheduler assignment default attributes.
188   */
189  #define SCHEDULER_ASSIGN_DEFAULT UINT32_C(0x0)
190
191  /**
192   * @brief The presence of this processor is optional.
193   */
194  #define SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL SCHEDULER_ASSIGN_DEFAULT
195
196  /**
197   * @brief The presence of this processor is mandatory.
198   */
199  #define SCHEDULER_ASSIGN_PROCESSOR_MANDATORY UINT32_C(0x1)
200
201  /**
202   * @brief Scheduler assignment.
203   */
204  typedef struct {
205    /**
206     * @brief The scheduler for this processor.
207     */
208    const Scheduler_Control *scheduler;
209
210    /**
211     * @brief The scheduler assignment attributes.
212     *
213     * Use @ref SCHEDULER_ASSIGN_DEFAULT to select default attributes.
214     *
215     * The presence of a processor can be
216     * - @ref SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL, or
217     * - @ref SCHEDULER_ASSIGN_PROCESSOR_MANDATORY.
218     */
219    uint32_t attributes;
220  } Scheduler_Assignment;
221
222  /**
223   * @brief The scheduler assignments.
224   *
225   * The length of this array must be equal to the maximum processors.
226   *
227   * Application provided via <rtems/confdefs.h>.
228   *
229   * @see _Scheduler_Table and rtems_configuration_get_maximum_processors().
230   */
231  extern const Scheduler_Assignment _Scheduler_Assignments[];
232#endif
233
234/**
235 * @brief Returns an arbitrary non-NULL value.
236 *
237 * @param[in] scheduler Unused.
238 * @param[in] the_thread Unused.
239 *
240 * @retval true Always.
241 */
242bool _Scheduler_default_Allocate(
243  const Scheduler_Control *scheduler,
244  Thread_Control          *the_thread
245);
246
247/**
248 * @brief Does nothing.
249 *
250 * @param[in] scheduler Unused.
251 * @param[in] the_thread Unused.
252 */
253void _Scheduler_default_Free(
254  const Scheduler_Control *scheduler,
255  Thread_Control          *the_thread
256);
257
258/**
259 * @brief Does nothing.
260 *
261 * @param[in] scheduler Unused.
262 * @param[in] the_thread Unused.
263 */
264void _Scheduler_default_Update(
265  const Scheduler_Control *scheduler,
266  Thread_Control          *the_thread
267);
268
269/**
270 * @brief Does nothing.
271 *
272 * @param[in] scheduler Unused.
273 * @param[in] the_thread Unused.
274 * @param[in] deadline Unused.
275 */
276void _Scheduler_default_Release_job(
277  const Scheduler_Control *scheduler,
278  Thread_Control          *the_thread,
279  uint32_t                 deadline
280);
281
282/**
283 * @brief Performs tick operations depending on the CPU budget algorithm for
284 * each executing thread.
285 *
286 * This routine is invoked as part of processing each clock tick.
287 *
288 * @param[in] scheduler The scheduler.
289 * @param[in] execution An executing thread.
290 */
291void _Scheduler_default_Tick(
292  const Scheduler_Control *scheduler,
293  Thread_Control          *executing
294);
295
296/**
297 * @brief Starts an idle thread.
298 *
299 * @param[in] scheduler The scheduler.
300 * @param[in] the_thread An idle thread.
301 * @param[in] cpu This parameter is unused.
302 */
303void _Scheduler_default_Start_idle(
304  const Scheduler_Control *scheduler,
305  Thread_Control          *the_thread,
306  Per_CPU_Control         *cpu
307);
308
309#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
310  /**
311   * @brief Get affinity for the default scheduler.
312   *
313   * @param[in] thread The associated thread.
314   * @param[in] cpusetsize The size of the cpuset.
315   * @param[out] cpuset Affinity set containing all CPUs.
316   *
317   * @retval 0 Successfully got cpuset
318   * @retval -1 The cpusetsize is invalid for the system
319   */
320  bool _Scheduler_default_Get_affinity(
321    const Scheduler_Control *scheduler,
322    Thread_Control          *thread,
323    size_t                   cpusetsize,
324    cpu_set_t               *cpuset
325  );
326
327  /**
328   * @brief Set affinity for the default scheduler.
329   *
330   * @param[in] thread The associated thread.
331   * @param[in] cpusetsize The size of the cpuset.
332   * @param[in] cpuset Affinity new affinity set.
333   *
334   * @retval 0 Successful
335   *
336   *  This method always returns successful and does not save
337   *  the cpuset.
338   */
339  bool _Scheduler_default_Set_affinity(
340    const Scheduler_Control *scheduler,
341    Thread_Control          *thread,
342    size_t                   cpusetsize,
343    const cpu_set_t         *cpuset
344  );
345#endif
346
347/**
348 * @brief Indicates if thread priority queues are broken with the configured
349 * scheduler or not.
350 *
351 * See also PR2174: Memory corruption with EDF scheduler and thread priority
352 * queues.
353 */
354extern const bool _Scheduler_FIXME_thread_priority_queues_are_broken;
355
356/**@}*/
357
358#ifdef __cplusplus
359}
360#endif
361
362#endif
363/* end of include file */
Note: See TracBrowser for help on using the repository browser.