source: rtems/cpukit/score/include/rtems/score/scheduler.h @ 9c238e1

5
Last change on this file since 9c238e1 was 9c238e1, checked in by Sebastian Huber <sebastian.huber@…>, on 10/21/16 at 12:33:01

score: Simplify update priority scheduler op

Remove unused return status.

  • Property mode set to 100644
File size: 14.7 KB
RevLine 
[0faa9dad]1/**
2 *  @file  rtems/score/scheduler.h
3 *
[1dbbc0c]4 *  @brief Constants and Structures Associated with the Scheduler
5 *
[0faa9dad]6 *  This include file contains all the constants and structures associated
7 *  with the scheduler.
8 */
9
10/*
11 *  Copyright (C) 2010 Gedare Bloom.
[010192d]12 *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
[0faa9dad]13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
[c499856]16 *  http://www.rtems.org/license/LICENSE.
[0faa9dad]17 */
18
19#ifndef _RTEMS_SCORE_SCHEDULER_H
20#define _RTEMS_SCORE_SCHEDULER_H
21
[e1598a6]22#include <rtems/score/thread.h>
[cfe457f]23#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
24  #include <sys/cpuset.h>
25#endif
[215f4014]26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
[96316d1b]31struct Per_CPU_Control;
32
[0faa9dad]33/**
34 *  @defgroup ScoreScheduler Scheduler Handler
35 *
[d8cd045c]36 *  @ingroup Score
37 *
[0faa9dad]38 *  This handler encapsulates functionality related to managing sets of threads
39 *  that are ready for execution.
40 */
41/**@{*/
42
[24934e36]43typedef struct Scheduler_Control Scheduler_Control;
44
[8568341]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
[0faa9dad]55/**
[5b1ff71a]56 * @brief The scheduler operations.
[0faa9dad]57 */
58typedef struct {
[5b1ff71a]59  /** @see _Scheduler_Handler_initialization() */
[e1598a6]60  void ( *initialize )( const Scheduler_Control * );
[010192d]61
[5b1ff71a]62  /** @see _Scheduler_Schedule() */
[e1598a6]63  void ( *schedule )( const Scheduler_Control *, Thread_Control *);
[0faa9dad]64
[5b1ff71a]65  /** @see _Scheduler_Yield() */
[8568341]66  Scheduler_Void_or_thread ( *yield )(
67    const Scheduler_Control *,
[2df4abc]68    Thread_Control *,
69    Scheduler_Node *
[8568341]70  );
[0faa9dad]71
[5b1ff71a]72  /** @see _Scheduler_Block() */
[8568341]73  void ( *block )(
74    const Scheduler_Control *,
[e382a1b]75    Thread_Control *,
76    Scheduler_Node *
[8568341]77  );
[0faa9dad]78
[5b1ff71a]79  /** @see _Scheduler_Unblock() */
[8568341]80  Scheduler_Void_or_thread ( *unblock )(
81    const Scheduler_Control *,
[72e0bdb]82    Thread_Control *,
83    Scheduler_Node *
[8568341]84  );
[0faa9dad]85
[9bfad8c]86  /** @see _Scheduler_Update_priority() */
[9c238e1]87  void ( *update_priority )(
[f39f667a]88    const Scheduler_Control *,
[501043a]89    Thread_Control *,
90    Scheduler_Node *
[f39f667a]91  );
92
[77ff5599]93  /** @see _Scheduler_Map_priority() */
94  Priority_Control ( *map_priority )(
95    const Scheduler_Control *,
96    Priority_Control
97  );
98
99  /** @see _Scheduler_Unmap_priority() */
100  Priority_Control ( *unmap_priority )(
101    const Scheduler_Control *,
102    Priority_Control
103  );
104
[5c3d250]105#if defined(RTEMS_SMP)
[351c14d]106  /**
107   * @brief Ask for help operation.
108   *
109   * @param[in] scheduler The scheduler instance to ask for help.
110   * @param[in] the_thread The thread needing help.
111   * @param[in] node The scheduler node.
112   *
113   * @retval true Ask for help was successful.
114   * @retval false Otherwise.
115   */
116  bool ( *ask_for_help )(
117    const Scheduler_Control *scheduler,
118    Thread_Control          *the_thread,
119    Scheduler_Node          *node
120  );
121
122  /**
123   * @brief Reconsider help operation.
124   *
125   * @param[in] scheduler The scheduler instance to reconsider the help
126   *   request.
127   * @param[in] the_thread The thread reconsidering a help request.
128   * @param[in] node The scheduler node.
129   */
130  void ( *reconsider_help_request )(
131    const Scheduler_Control *scheduler,
132    Thread_Control          *the_thread,
133    Scheduler_Node          *node
134  );
135
136  /**
137   * @brief Withdraw node operation.
138   *
139   * @param[in] scheduler The scheduler instance to withdraw the node.
140   * @param[in] the_thread The thread using the node.
141   * @param[in] node The scheduler node to withdraw.
142   * @param[in] next_state The next thread scheduler state in case the node is
143   *   scheduled.
144   */
145  void ( *withdraw_node )(
146    const Scheduler_Control *scheduler,
147    Thread_Control          *the_thread,
148    Scheduler_Node          *node,
149    Thread_Scheduler_state   next_state
150  );
151
[5c3d250]152  /**
153   * Ask for help operation.
154   *
155   * @param[in] scheduler The scheduler of the thread offering help.
156   * @param[in] offers_help The thread offering help.
157   * @param[in] needs_help The thread needing help.
158   *
159   * @retval needs_help It was not possible to schedule the thread needing
160   *   help, so it is returned to continue the search for help.
161   * @retval next_needs_help It was possible to schedule the thread needing
162   *   help, but this displaced another thread eligible to ask for help.  So
163   *   this thread is returned to start a new search for help.
164   * @retval NULL It was possible to schedule the thread needing help, and no
165   *   other thread needs help as a result.
166   *
[d097b546]167   * @see _Scheduler_Ask_for_help_X().
[5c3d250]168   */
[d097b546]169  Thread_Control *( *ask_for_help_X )(
[5c3d250]170    const Scheduler_Control *scheduler,
171    Thread_Control          *offers_help,
172    Thread_Control          *needs_help
173  );
174#endif
175
[8e467384]176  /** @see _Scheduler_Node_initialize() */
[9bfad8c]177  void ( *node_initialize )(
[4d1f500]178    const Scheduler_Control *,
[df2177ab]179    Scheduler_Node *,
[4d1f500]180    Thread_Control *,
181    Priority_Control
182  );
[108c4b0]183
[9bfad8c]184  /** @see _Scheduler_Node_destroy() */
[df2177ab]185  void ( *node_destroy )( const Scheduler_Control *, Scheduler_Node * );
[9bfad8c]186
[5b1ff71a]187  /** @see _Scheduler_Release_job() */
[300f6a48]188  void ( *release_job ) (
[e1598a6]189    const Scheduler_Control *,
190    Thread_Control *,
[300f6a48]191    Priority_Node *,
192    uint64_t,
193    Thread_queue_Context *
[e1598a6]194  );
[ac9d2ecc]195
[21bdca4]196  /** @see _Scheduler_Cancel_job() */
[300f6a48]197  void ( *cancel_job ) (
[21bdca4]198    const Scheduler_Control *,
[300f6a48]199    Thread_Control *,
200    Priority_Node *,
201    Thread_queue_Context *
[21bdca4]202  );
203
[5b1ff71a]204  /** @see _Scheduler_Tick() */
[c5831a3f]205  void ( *tick )( const Scheduler_Control *, Thread_Control * );
[ac9d2ecc]206
[5b1ff71a]207  /** @see _Scheduler_Start_idle() */
[24934e36]208  void ( *start_idle )(
[e1598a6]209    const Scheduler_Control *,
[24934e36]210    Thread_Control *,
[96316d1b]211    struct Per_CPU_Control *
[24934e36]212  );
[cfe457f]213
214#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
[5b1ff71a]215  /** @see _Scheduler_Get_affinity() */
[24934e36]216  bool ( *get_affinity )(
[e1598a6]217    const Scheduler_Control *,
[24934e36]218    Thread_Control *,
219    size_t,
220    cpu_set_t *
221  );
[cfe457f]222 
[5b1ff71a]223  /** @see _Scheduler_Set_affinity() */
[cfe457f]224  bool ( *set_affinity )(
[e1598a6]225    const Scheduler_Control *,
[24934e36]226    Thread_Control *,
227    size_t,
228    const cpu_set_t *
[cfe457f]229  );
230#endif
[0faa9dad]231} Scheduler_Operations;
232
233/**
[e1598a6]234 * @brief Scheduler context.
235 *
236 * The scheduler context of a particular scheduler implementation must place
237 * this structure at the begin of its context structure.
238 */
[38b59a6]239typedef struct Scheduler_Context {
[913864c]240  /**
241   * @brief Lock to protect this scheduler instance.
242   */
243  ISR_LOCK_MEMBER( Lock )
244
[c5831a3f]245#if defined(RTEMS_SMP)
246  /**
247   * @brief Count of processors owned by this scheduler instance.
248   */
249  uint32_t processor_count;
250#endif
[e1598a6]251} Scheduler_Context;
252
253/**
254 * @brief Scheduler control.
[0faa9dad]255 */
[24934e36]256struct Scheduler_Control {
[215f4014]257  /**
[e1598a6]258   * @brief Reference to a statically allocated scheduler context.
[0faa9dad]259   */
[e1598a6]260  Scheduler_Context *context;
[0faa9dad]261
[e1598a6]262  /**
263   * @brief The scheduler operations.
264   */
265  Scheduler_Operations Operations;
[133d54c5]266
[7dfb4b9]267  /**
268   * @brief The maximum priority value of this scheduler.
269   *
270   * It defines the lowest (least important) thread priority for this
271   * scheduler.  For example the idle threads have this priority.
272   */
273  Priority_Control maximum_priority;
274
[133d54c5]275  /**
276   * @brief The scheduler name.
277   */
278  uint32_t name;
[24934e36]279};
[0faa9dad]280
281/**
[e1598a6]282 * @brief Registered schedulers.
283 *
284 * Application provided via <rtems/confdefs.h>.
285 *
286 * @see _Scheduler_Count.
287 */
288extern const Scheduler_Control _Scheduler_Table[];
289
290/**
291 * @brief Count of registered schedulers.
[0faa9dad]292 *
[e1598a6]293 * Application provided via <rtems/confdefs.h> on SMP configurations.
[010192d]294 *
[e1598a6]295 * It is very important that this is a compile-time constant on uni-processor
296 * configurations (in this case RTEMS_SMP is not defined) so that the compiler
297 * can optimize the some loops away
298 *
299 * @see _Scheduler_Table.
[0faa9dad]300 */
[e1598a6]301#if defined(RTEMS_SMP)
302  extern const size_t _Scheduler_Count;
303#else
304  #define _Scheduler_Count ( (size_t) 1 )
305#endif
[0faa9dad]306
[c5831a3f]307#if defined(RTEMS_SMP)
308  /**
309   * @brief The scheduler assignment default attributes.
310   */
311  #define SCHEDULER_ASSIGN_DEFAULT UINT32_C(0x0)
312
313  /**
314   * @brief The presence of this processor is optional.
315   */
316  #define SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL SCHEDULER_ASSIGN_DEFAULT
317
318  /**
319   * @brief The presence of this processor is mandatory.
320   */
321  #define SCHEDULER_ASSIGN_PROCESSOR_MANDATORY UINT32_C(0x1)
322
323  /**
324   * @brief Scheduler assignment.
325   */
326  typedef struct {
327    /**
328     * @brief The scheduler for this processor.
329     */
330    const Scheduler_Control *scheduler;
331
332    /**
333     * @brief The scheduler assignment attributes.
334     *
335     * Use @ref SCHEDULER_ASSIGN_DEFAULT to select default attributes.
336     *
337     * The presence of a processor can be
338     * - @ref SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL, or
339     * - @ref SCHEDULER_ASSIGN_PROCESSOR_MANDATORY.
340     */
341    uint32_t attributes;
342  } Scheduler_Assignment;
343
344  /**
345   * @brief The scheduler assignments.
346   *
347   * The length of this array must be equal to the maximum processors.
348   *
349   * Application provided via <rtems/confdefs.h>.
350   *
351   * @see _Scheduler_Table and rtems_configuration_get_maximum_processors().
352   */
353  extern const Scheduler_Assignment _Scheduler_Assignments[];
354#endif
355
[77ff5599]356/**
357 * @brief Returns the thread priority.
358 *
359 * @param[in] scheduler Unused.
360 * @param[in] priority The thread priority.
361 *
362 * @return priority The thread priority.
363 */
364Priority_Control _Scheduler_default_Map_priority(
365  const Scheduler_Control *scheduler,
366  Priority_Control         priority
367);
368
369#define _Scheduler_default_Unmap_priority _Scheduler_default_Map_priority
370
[5c3d250]371#if defined(RTEMS_SMP)
[351c14d]372  /**
373   * @brief Does nothing.
374   *
375   * @param[in] scheduler Unused.
376   * @param[in] the_thread Unused.
377   * @param[in] node Unused.
378   *
379   * @retval false Always.
380   */
381  bool _Scheduler_default_Ask_for_help(
382    const Scheduler_Control *scheduler,
383    Thread_Control          *the_thread,
384    Scheduler_Node          *node
385  );
386
387  /**
388   * @brief Does nothing.
389   *
390   * @param[in] scheduler Unused.
391   * @param[in] the_thread Unused.
392   * @param[in] node Unused.
393   */
394  void _Scheduler_default_Reconsider_help_request(
395    const Scheduler_Control *scheduler,
396    Thread_Control          *the_thread,
397    Scheduler_Node          *node
398  );
399
400  /**
401   * @brief Does nothing.
402   *
403   * @param[in] scheduler Unused.
404   * @param[in] the_thread Unused.
405   * @param[in] node Unused.
406   * @param[in] next_state Unused.
407   */
408  void _Scheduler_default_Withdraw_node(
409    const Scheduler_Control *scheduler,
410    Thread_Control          *the_thread,
411    Scheduler_Node          *node,
412    Thread_Scheduler_state   next_state
413  );
414
[5c3d250]415  /**
416   * @brief Does nothing.
417   *
418   * @param[in] scheduler Unused.
419   * @param[in] offers_help Unused.
420   * @param[in] needs_help Unused.
421   *
422   * @retval NULL Always.
423   */
[d097b546]424  Thread_Control *_Scheduler_default_Ask_for_help_X(
[5c3d250]425    const Scheduler_Control *scheduler,
426    Thread_Control          *offers_help,
427    Thread_Control          *needs_help
428  );
429
430  #define SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP \
[351c14d]431    _Scheduler_default_Ask_for_help, \
432    _Scheduler_default_Reconsider_help_request, \
433    _Scheduler_default_Withdraw_node, \
[d097b546]434    _Scheduler_default_Ask_for_help_X,
[5c3d250]435#else
436  #define SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP
437#endif
438
[62d947d]439/**
[3733b224]440 * @brief Does nothing.
441 *
442 * @param[in] scheduler Unused.
443 * @param[in] the_thread Unused.
444 */
445void _Scheduler_default_Schedule(
446  const Scheduler_Control *scheduler,
447  Thread_Control          *the_thread
448);
449
450/**
[9bfad8c]451 * @brief Performs the scheduler base node initialization.
[62d947d]452 *
[24934e36]453 * @param[in] scheduler Unused.
[df2177ab]454 * @param[in] node The node to initialize.
[24934e36]455 * @param[in] the_thread Unused.
[9bfad8c]456 * @param[in] priority The thread priority.
[62d947d]457 */
[8e467384]458void _Scheduler_default_Node_initialize(
[e1598a6]459  const Scheduler_Control *scheduler,
[df2177ab]460  Scheduler_Node          *node,
[9bfad8c]461  Thread_Control          *the_thread,
462  Priority_Control         priority
[62d947d]463);
464
465/**
466 * @brief Does nothing.
467 *
[24934e36]468 * @param[in] scheduler Unused.
[df2177ab]469 * @param[in] node Unused.
[62d947d]470 */
[8e467384]471void _Scheduler_default_Node_destroy(
[e1598a6]472  const Scheduler_Control *scheduler,
[df2177ab]473  Scheduler_Node          *node
[62d947d]474);
475
[037cfd1]476/**
477 * @brief Does nothing.
478 *
[24934e36]479 * @param[in] scheduler Unused.
480 * @param[in] the_thread Unused.
[300f6a48]481 * @param[in] priority_node Unused.
[037cfd1]482 * @param[in] deadline Unused.
[300f6a48]483 * @param[in] queue_context Unused.
[ee0e4135]484 *
485 * @retval NULL Always.
[037cfd1]486 */
[300f6a48]487void _Scheduler_default_Release_job(
[e1598a6]488  const Scheduler_Control *scheduler,
489  Thread_Control          *the_thread,
[300f6a48]490  Priority_Node           *priority_node,
491  uint64_t                 deadline,
492  Thread_queue_Context    *queue_context
[037cfd1]493);
494
[21bdca4]495/**
496 * @brief Does nothing.
497 *
498 * @param[in] scheduler Unused.
499 * @param[in] the_thread Unused.
[300f6a48]500 * @param[in] priority_node Unused.
501 * @param[in] queue_context Unused.
[ee0e4135]502 *
503 * @retval NULL Always.
[21bdca4]504 */
[300f6a48]505void _Scheduler_default_Cancel_job(
[21bdca4]506  const Scheduler_Control *scheduler,
[300f6a48]507  Thread_Control          *the_thread,
508  Priority_Node           *priority_node,
509  Thread_queue_Context    *queue_context
[21bdca4]510);
511
[a344308]512/**
513 * @brief Performs tick operations depending on the CPU budget algorithm for
514 * each executing thread.
515 *
516 * This routine is invoked as part of processing each clock tick.
[24934e36]517 *
518 * @param[in] scheduler The scheduler.
[a7e4de2]519 * @param[in] executing An executing thread.
[a344308]520 */
[c5831a3f]521void _Scheduler_default_Tick(
522  const Scheduler_Control *scheduler,
523  Thread_Control          *executing
524);
[a344308]525
[1ccb64e1]526/**
[24934e36]527 * @brief Starts an idle thread.
[1ccb64e1]528 *
[24934e36]529 * @param[in] scheduler The scheduler.
530 * @param[in] the_thread An idle thread.
531 * @param[in] cpu This parameter is unused.
[1ccb64e1]532 */
533void _Scheduler_default_Start_idle(
[e1598a6]534  const Scheduler_Control *scheduler,
535  Thread_Control          *the_thread,
[96316d1b]536  struct Per_CPU_Control  *cpu
[1ccb64e1]537);
538
[cfe457f]539#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
540  /**
541   * @brief Get affinity for the default scheduler.
542   *
[a7e4de2]543   * @param[in] scheduler The scheduler instance.
[cfe457f]544   * @param[in] thread The associated thread.
545   * @param[in] cpusetsize The size of the cpuset.
546   * @param[out] cpuset Affinity set containing all CPUs.
547   *
548   * @retval 0 Successfully got cpuset
549   * @retval -1 The cpusetsize is invalid for the system
550   */
551  bool _Scheduler_default_Get_affinity(
[e1598a6]552    const Scheduler_Control *scheduler,
553    Thread_Control          *thread,
554    size_t                   cpusetsize,
555    cpu_set_t               *cpuset
[cfe457f]556  );
557
558  /**
559   * @brief Set affinity for the default scheduler.
560   *
[a7e4de2]561   * @param[in] scheduler The scheduler instance.
[cfe457f]562   * @param[in] thread The associated thread.
563   * @param[in] cpusetsize The size of the cpuset.
564   * @param[in] cpuset Affinity new affinity set.
565   *
566   * @retval 0 Successful
567   *
568   *  This method always returns successful and does not save
569   *  the cpuset.
570   */
571  bool _Scheduler_default_Set_affinity(
[e1598a6]572    const Scheduler_Control *scheduler,
573    Thread_Control          *thread,
574    size_t                   cpusetsize,
575    const cpu_set_t         *cpuset
[cfe457f]576  );
[bd1431a]577
578  #define SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
579    , _Scheduler_default_Get_affinity \
580    , _Scheduler_default_Set_affinity
581#else
582  #define SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY
[cfe457f]583#endif
584
[7dfb4b9]585/**
586 * @brief This defines the lowest (least important) thread priority of the
587 * first scheduler instance.
588 */
589#define PRIORITY_MAXIMUM ( _Scheduler_Table[ 0 ].maximum_priority )
590
[215f4014]591/**@}*/
592
[0faa9dad]593#ifdef __cplusplus
594}
595#endif
596
597#endif
[a15eaaf]598/* end of include file */
Note: See TracBrowser for help on using the repository browser.