source: rtems/cpukit/score/include/rtems/score/scheduler.h @ e27421f

5
Last change on this file since e27421f was e27421f, checked in by Sebastian Huber <sebastian.huber@…>, on 08/01/16 at 09:12:52

score: Move scheduler node to own header file

This makes it possible to add scheduler nodes to structures defined in
<rtems/score/thread.h>.

Update #2556.

  • Property mode set to 100644
File size: 11.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/thread.h>
23#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
24  #include <sys/cpuset.h>
25#endif
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31struct Per_CPU_Control;
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#if defined(RTEMS_SMP)
46  typedef Thread_Control * Scheduler_Void_or_thread;
47
48  #define SCHEDULER_RETURN_VOID_OR_NULL return NULL
49#else
50  typedef void Scheduler_Void_or_thread;
51
52  #define SCHEDULER_RETURN_VOID_OR_NULL return
53#endif
54
55/**
56 * @brief The scheduler operations.
57 */
58typedef struct {
59  /** @see _Scheduler_Handler_initialization() */
60  void ( *initialize )( const Scheduler_Control * );
61
62  /** @see _Scheduler_Schedule() */
63  void ( *schedule )( const Scheduler_Control *, Thread_Control *);
64
65  /** @see _Scheduler_Yield() */
66  Scheduler_Void_or_thread ( *yield )(
67    const Scheduler_Control *,
68    Thread_Control *
69  );
70
71  /** @see _Scheduler_Block() */
72  void ( *block )(
73    const Scheduler_Control *,
74    Thread_Control *
75  );
76
77  /** @see _Scheduler_Unblock() */
78  Scheduler_Void_or_thread ( *unblock )(
79    const Scheduler_Control *,
80    Thread_Control *
81  );
82
83  /** @see _Scheduler_Update_priority() */
84  Scheduler_Void_or_thread ( *update_priority )(
85    const Scheduler_Control *,
86    Thread_Control *
87  );
88
89  /** @see _Scheduler_Map_priority() */
90  Priority_Control ( *map_priority )(
91    const Scheduler_Control *,
92    Priority_Control
93  );
94
95  /** @see _Scheduler_Unmap_priority() */
96  Priority_Control ( *unmap_priority )(
97    const Scheduler_Control *,
98    Priority_Control
99  );
100
101#if defined(RTEMS_SMP)
102  /**
103   * Ask for help operation.
104   *
105   * @param[in] scheduler The scheduler of the thread offering help.
106   * @param[in] offers_help The thread offering help.
107   * @param[in] needs_help The thread needing help.
108   *
109   * @retval needs_help It was not possible to schedule the thread needing
110   *   help, so it is returned to continue the search for help.
111   * @retval next_needs_help It was possible to schedule the thread needing
112   *   help, but this displaced another thread eligible to ask for help.  So
113   *   this thread is returned to start a new search for help.
114   * @retval NULL It was possible to schedule the thread needing help, and no
115   *   other thread needs help as a result.
116   *
117   * @see _Scheduler_Ask_for_help().
118   */
119  Thread_Control *( *ask_for_help )(
120    const Scheduler_Control *scheduler,
121    Thread_Control          *offers_help,
122    Thread_Control          *needs_help
123  );
124#endif
125
126  /** @see _Scheduler_Node_initialize() */
127  void ( *node_initialize )(
128    const Scheduler_Control *,
129    Scheduler_Node *,
130    Thread_Control *,
131    Priority_Control
132  );
133
134  /** @see _Scheduler_Node_destroy() */
135  void ( *node_destroy )( const Scheduler_Control *, Scheduler_Node * );
136
137  /** @see _Scheduler_Release_job() */
138  Thread_Control *( *release_job ) (
139    const Scheduler_Control *,
140    Thread_Control *,
141    uint64_t
142  );
143
144  /** @see _Scheduler_Cancel_job() */
145  Thread_Control *( *cancel_job ) (
146    const Scheduler_Control *,
147    Thread_Control *
148  );
149
150  /** @see _Scheduler_Tick() */
151  void ( *tick )( const Scheduler_Control *, Thread_Control * );
152
153  /** @see _Scheduler_Start_idle() */
154  void ( *start_idle )(
155    const Scheduler_Control *,
156    Thread_Control *,
157    struct Per_CPU_Control *
158  );
159
160#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
161  /** @see _Scheduler_Get_affinity() */
162  bool ( *get_affinity )(
163    const Scheduler_Control *,
164    Thread_Control *,
165    size_t,
166    cpu_set_t *
167  );
168 
169  /** @see _Scheduler_Set_affinity() */
170  bool ( *set_affinity )(
171    const Scheduler_Control *,
172    Thread_Control *,
173    size_t,
174    const cpu_set_t *
175  );
176#endif
177} Scheduler_Operations;
178
179/**
180 * @brief Scheduler context.
181 *
182 * The scheduler context of a particular scheduler implementation must place
183 * this structure at the begin of its context structure.
184 */
185typedef struct Scheduler_Context {
186#if defined(RTEMS_SMP)
187  /**
188   * @brief Count of processors owned by this scheduler instance.
189   */
190  uint32_t processor_count;
191#endif
192} Scheduler_Context;
193
194/**
195 * @brief Scheduler control.
196 */
197struct Scheduler_Control {
198  /**
199   * @brief Reference to a statically allocated scheduler context.
200   */
201  Scheduler_Context *context;
202
203  /**
204   * @brief The scheduler operations.
205   */
206  Scheduler_Operations Operations;
207
208  /**
209   * @brief The maximum priority value of this scheduler.
210   *
211   * It defines the lowest (least important) thread priority for this
212   * scheduler.  For example the idle threads have this priority.
213   */
214  Priority_Control maximum_priority;
215
216  /**
217   * @brief The scheduler name.
218   */
219  uint32_t name;
220};
221
222/**
223 * @brief Registered schedulers.
224 *
225 * Application provided via <rtems/confdefs.h>.
226 *
227 * @see _Scheduler_Count.
228 */
229extern const Scheduler_Control _Scheduler_Table[];
230
231/**
232 * @brief Count of registered schedulers.
233 *
234 * Application provided via <rtems/confdefs.h> on SMP configurations.
235 *
236 * It is very important that this is a compile-time constant on uni-processor
237 * configurations (in this case RTEMS_SMP is not defined) so that the compiler
238 * can optimize the some loops away
239 *
240 * @see _Scheduler_Table.
241 */
242#if defined(RTEMS_SMP)
243  extern const size_t _Scheduler_Count;
244#else
245  #define _Scheduler_Count ( (size_t) 1 )
246#endif
247
248#if defined(RTEMS_SMP)
249  /**
250   * @brief The scheduler assignment default attributes.
251   */
252  #define SCHEDULER_ASSIGN_DEFAULT UINT32_C(0x0)
253
254  /**
255   * @brief The presence of this processor is optional.
256   */
257  #define SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL SCHEDULER_ASSIGN_DEFAULT
258
259  /**
260   * @brief The presence of this processor is mandatory.
261   */
262  #define SCHEDULER_ASSIGN_PROCESSOR_MANDATORY UINT32_C(0x1)
263
264  /**
265   * @brief Scheduler assignment.
266   */
267  typedef struct {
268    /**
269     * @brief The scheduler for this processor.
270     */
271    const Scheduler_Control *scheduler;
272
273    /**
274     * @brief The scheduler assignment attributes.
275     *
276     * Use @ref SCHEDULER_ASSIGN_DEFAULT to select default attributes.
277     *
278     * The presence of a processor can be
279     * - @ref SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL, or
280     * - @ref SCHEDULER_ASSIGN_PROCESSOR_MANDATORY.
281     */
282    uint32_t attributes;
283  } Scheduler_Assignment;
284
285  /**
286   * @brief The scheduler assignments.
287   *
288   * The length of this array must be equal to the maximum processors.
289   *
290   * Application provided via <rtems/confdefs.h>.
291   *
292   * @see _Scheduler_Table and rtems_configuration_get_maximum_processors().
293   */
294  extern const Scheduler_Assignment _Scheduler_Assignments[];
295#endif
296
297/**
298 * @brief Returns the thread priority.
299 *
300 * @param[in] scheduler Unused.
301 * @param[in] priority The thread priority.
302 *
303 * @return priority The thread priority.
304 */
305Priority_Control _Scheduler_default_Map_priority(
306  const Scheduler_Control *scheduler,
307  Priority_Control         priority
308);
309
310#define _Scheduler_default_Unmap_priority _Scheduler_default_Map_priority
311
312#if defined(RTEMS_SMP)
313  /**
314   * @brief Does nothing.
315   *
316   * @param[in] scheduler Unused.
317   * @param[in] offers_help Unused.
318   * @param[in] needs_help Unused.
319   *
320   * @retval NULL Always.
321   */
322  Thread_Control *_Scheduler_default_Ask_for_help(
323    const Scheduler_Control *scheduler,
324    Thread_Control          *offers_help,
325    Thread_Control          *needs_help
326  );
327
328  #define SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP \
329    _Scheduler_default_Ask_for_help,
330#else
331  #define SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP
332#endif
333
334/**
335 * @brief Does nothing.
336 *
337 * @param[in] scheduler Unused.
338 * @param[in] the_thread Unused.
339 */
340void _Scheduler_default_Schedule(
341  const Scheduler_Control *scheduler,
342  Thread_Control          *the_thread
343);
344
345/**
346 * @brief Performs the scheduler base node initialization.
347 *
348 * @param[in] scheduler Unused.
349 * @param[in] node The node to initialize.
350 * @param[in] the_thread Unused.
351 * @param[in] priority The thread priority.
352 */
353void _Scheduler_default_Node_initialize(
354  const Scheduler_Control *scheduler,
355  Scheduler_Node          *node,
356  Thread_Control          *the_thread,
357  Priority_Control         priority
358);
359
360/**
361 * @brief Does nothing.
362 *
363 * @param[in] scheduler Unused.
364 * @param[in] node Unused.
365 */
366void _Scheduler_default_Node_destroy(
367  const Scheduler_Control *scheduler,
368  Scheduler_Node          *node
369);
370
371/**
372 * @brief Does nothing.
373 *
374 * @param[in] scheduler Unused.
375 * @param[in] the_thread Unused.
376 * @param[in] deadline Unused.
377 *
378 * @retval NULL Always.
379 */
380Thread_Control *_Scheduler_default_Release_job(
381  const Scheduler_Control *scheduler,
382  Thread_Control          *the_thread,
383  uint64_t                 deadline
384);
385
386/**
387 * @brief Does nothing.
388 *
389 * @param[in] scheduler Unused.
390 * @param[in] the_thread Unused.
391 *
392 * @retval NULL Always.
393 */
394Thread_Control *_Scheduler_default_Cancel_job(
395  const Scheduler_Control *scheduler,
396  Thread_Control          *the_thread
397);
398
399/**
400 * @brief Performs tick operations depending on the CPU budget algorithm for
401 * each executing thread.
402 *
403 * This routine is invoked as part of processing each clock tick.
404 *
405 * @param[in] scheduler The scheduler.
406 * @param[in] executing An executing thread.
407 */
408void _Scheduler_default_Tick(
409  const Scheduler_Control *scheduler,
410  Thread_Control          *executing
411);
412
413/**
414 * @brief Starts an idle thread.
415 *
416 * @param[in] scheduler The scheduler.
417 * @param[in] the_thread An idle thread.
418 * @param[in] cpu This parameter is unused.
419 */
420void _Scheduler_default_Start_idle(
421  const Scheduler_Control *scheduler,
422  Thread_Control          *the_thread,
423  struct Per_CPU_Control  *cpu
424);
425
426#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
427  /**
428   * @brief Get affinity for the default scheduler.
429   *
430   * @param[in] scheduler The scheduler instance.
431   * @param[in] thread The associated thread.
432   * @param[in] cpusetsize The size of the cpuset.
433   * @param[out] cpuset Affinity set containing all CPUs.
434   *
435   * @retval 0 Successfully got cpuset
436   * @retval -1 The cpusetsize is invalid for the system
437   */
438  bool _Scheduler_default_Get_affinity(
439    const Scheduler_Control *scheduler,
440    Thread_Control          *thread,
441    size_t                   cpusetsize,
442    cpu_set_t               *cpuset
443  );
444
445  /**
446   * @brief Set affinity for the default scheduler.
447   *
448   * @param[in] scheduler The scheduler instance.
449   * @param[in] thread The associated thread.
450   * @param[in] cpusetsize The size of the cpuset.
451   * @param[in] cpuset Affinity new affinity set.
452   *
453   * @retval 0 Successful
454   *
455   *  This method always returns successful and does not save
456   *  the cpuset.
457   */
458  bool _Scheduler_default_Set_affinity(
459    const Scheduler_Control *scheduler,
460    Thread_Control          *thread,
461    size_t                   cpusetsize,
462    const cpu_set_t         *cpuset
463  );
464
465  #define SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
466    , _Scheduler_default_Get_affinity \
467    , _Scheduler_default_Set_affinity
468#else
469  #define SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY
470#endif
471
472/**
473 * @brief This defines the lowest (least important) thread priority of the
474 * first scheduler instance.
475 */
476#define PRIORITY_MAXIMUM ( _Scheduler_Table[ 0 ].maximum_priority )
477
478/**@}*/
479
480#ifdef __cplusplus
481}
482#endif
483
484#endif
485/* end of include file */
Note: See TracBrowser for help on using the repository browser.