source: rtems/cpukit/score/include/rtems/score/scheduler.h @ 3733b224

4.115
Last change on this file since 3733b224 was 3733b224, checked in by Sebastian Huber <sebastian.huber@…>, on 05/15/14 at 06:46:56

score: Add and use _Scheduler_default_Schedule()

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