source: rtems/cpukit/score/include/rtems/score/scheduler.h @ 0e754fac

5
Last change on this file since 0e754fac was 0e754fac, checked in by Sebastian Huber <sebastian.huber@…>, on 10/21/16 at 12:41:19

score: Delete unused scheduler ask for help X op

  • Property mode set to 100644
File size: 13.4 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  );
[5c3d250]151#endif
152
[8e467384]153  /** @see _Scheduler_Node_initialize() */
[9bfad8c]154  void ( *node_initialize )(
[4d1f500]155    const Scheduler_Control *,
[df2177ab]156    Scheduler_Node *,
[4d1f500]157    Thread_Control *,
158    Priority_Control
159  );
[108c4b0]160
[9bfad8c]161  /** @see _Scheduler_Node_destroy() */
[df2177ab]162  void ( *node_destroy )( const Scheduler_Control *, Scheduler_Node * );
[9bfad8c]163
[5b1ff71a]164  /** @see _Scheduler_Release_job() */
[300f6a48]165  void ( *release_job ) (
[e1598a6]166    const Scheduler_Control *,
167    Thread_Control *,
[300f6a48]168    Priority_Node *,
169    uint64_t,
170    Thread_queue_Context *
[e1598a6]171  );
[ac9d2ecc]172
[21bdca4]173  /** @see _Scheduler_Cancel_job() */
[300f6a48]174  void ( *cancel_job ) (
[21bdca4]175    const Scheduler_Control *,
[300f6a48]176    Thread_Control *,
177    Priority_Node *,
178    Thread_queue_Context *
[21bdca4]179  );
180
[5b1ff71a]181  /** @see _Scheduler_Tick() */
[c5831a3f]182  void ( *tick )( const Scheduler_Control *, Thread_Control * );
[ac9d2ecc]183
[5b1ff71a]184  /** @see _Scheduler_Start_idle() */
[24934e36]185  void ( *start_idle )(
[e1598a6]186    const Scheduler_Control *,
[24934e36]187    Thread_Control *,
[96316d1b]188    struct Per_CPU_Control *
[24934e36]189  );
[cfe457f]190
191#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
[5b1ff71a]192  /** @see _Scheduler_Get_affinity() */
[24934e36]193  bool ( *get_affinity )(
[e1598a6]194    const Scheduler_Control *,
[24934e36]195    Thread_Control *,
196    size_t,
197    cpu_set_t *
198  );
[cfe457f]199 
[5b1ff71a]200  /** @see _Scheduler_Set_affinity() */
[cfe457f]201  bool ( *set_affinity )(
[e1598a6]202    const Scheduler_Control *,
[24934e36]203    Thread_Control *,
204    size_t,
205    const cpu_set_t *
[cfe457f]206  );
207#endif
[0faa9dad]208} Scheduler_Operations;
209
210/**
[e1598a6]211 * @brief Scheduler context.
212 *
213 * The scheduler context of a particular scheduler implementation must place
214 * this structure at the begin of its context structure.
215 */
[38b59a6]216typedef struct Scheduler_Context {
[913864c]217  /**
218   * @brief Lock to protect this scheduler instance.
219   */
220  ISR_LOCK_MEMBER( Lock )
221
[c5831a3f]222#if defined(RTEMS_SMP)
223  /**
224   * @brief Count of processors owned by this scheduler instance.
225   */
226  uint32_t processor_count;
227#endif
[e1598a6]228} Scheduler_Context;
229
230/**
231 * @brief Scheduler control.
[0faa9dad]232 */
[24934e36]233struct Scheduler_Control {
[215f4014]234  /**
[e1598a6]235   * @brief Reference to a statically allocated scheduler context.
[0faa9dad]236   */
[e1598a6]237  Scheduler_Context *context;
[0faa9dad]238
[e1598a6]239  /**
240   * @brief The scheduler operations.
241   */
242  Scheduler_Operations Operations;
[133d54c5]243
[7dfb4b9]244  /**
245   * @brief The maximum priority value of this scheduler.
246   *
247   * It defines the lowest (least important) thread priority for this
248   * scheduler.  For example the idle threads have this priority.
249   */
250  Priority_Control maximum_priority;
251
[133d54c5]252  /**
253   * @brief The scheduler name.
254   */
255  uint32_t name;
[24934e36]256};
[0faa9dad]257
258/**
[e1598a6]259 * @brief Registered schedulers.
260 *
261 * Application provided via <rtems/confdefs.h>.
262 *
263 * @see _Scheduler_Count.
264 */
265extern const Scheduler_Control _Scheduler_Table[];
266
267/**
268 * @brief Count of registered schedulers.
[0faa9dad]269 *
[e1598a6]270 * Application provided via <rtems/confdefs.h> on SMP configurations.
[010192d]271 *
[e1598a6]272 * It is very important that this is a compile-time constant on uni-processor
273 * configurations (in this case RTEMS_SMP is not defined) so that the compiler
274 * can optimize the some loops away
275 *
276 * @see _Scheduler_Table.
[0faa9dad]277 */
[e1598a6]278#if defined(RTEMS_SMP)
279  extern const size_t _Scheduler_Count;
280#else
281  #define _Scheduler_Count ( (size_t) 1 )
282#endif
[0faa9dad]283
[c5831a3f]284#if defined(RTEMS_SMP)
285  /**
286   * @brief The scheduler assignment default attributes.
287   */
288  #define SCHEDULER_ASSIGN_DEFAULT UINT32_C(0x0)
289
290  /**
291   * @brief The presence of this processor is optional.
292   */
293  #define SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL SCHEDULER_ASSIGN_DEFAULT
294
295  /**
296   * @brief The presence of this processor is mandatory.
297   */
298  #define SCHEDULER_ASSIGN_PROCESSOR_MANDATORY UINT32_C(0x1)
299
300  /**
301   * @brief Scheduler assignment.
302   */
303  typedef struct {
304    /**
305     * @brief The scheduler for this processor.
306     */
307    const Scheduler_Control *scheduler;
308
309    /**
310     * @brief The scheduler assignment attributes.
311     *
312     * Use @ref SCHEDULER_ASSIGN_DEFAULT to select default attributes.
313     *
314     * The presence of a processor can be
315     * - @ref SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL, or
316     * - @ref SCHEDULER_ASSIGN_PROCESSOR_MANDATORY.
317     */
318    uint32_t attributes;
319  } Scheduler_Assignment;
320
321  /**
322   * @brief The scheduler assignments.
323   *
324   * The length of this array must be equal to the maximum processors.
325   *
326   * Application provided via <rtems/confdefs.h>.
327   *
328   * @see _Scheduler_Table and rtems_configuration_get_maximum_processors().
329   */
330  extern const Scheduler_Assignment _Scheduler_Assignments[];
331#endif
332
[77ff5599]333/**
334 * @brief Returns the thread priority.
335 *
336 * @param[in] scheduler Unused.
337 * @param[in] priority The thread priority.
338 *
339 * @return priority The thread priority.
340 */
341Priority_Control _Scheduler_default_Map_priority(
342  const Scheduler_Control *scheduler,
343  Priority_Control         priority
344);
345
346#define _Scheduler_default_Unmap_priority _Scheduler_default_Map_priority
347
[5c3d250]348#if defined(RTEMS_SMP)
[351c14d]349  /**
350   * @brief Does nothing.
351   *
352   * @param[in] scheduler Unused.
353   * @param[in] the_thread Unused.
354   * @param[in] node Unused.
355   *
356   * @retval false Always.
357   */
358  bool _Scheduler_default_Ask_for_help(
359    const Scheduler_Control *scheduler,
360    Thread_Control          *the_thread,
361    Scheduler_Node          *node
362  );
363
364  /**
365   * @brief Does nothing.
366   *
367   * @param[in] scheduler Unused.
368   * @param[in] the_thread Unused.
369   * @param[in] node Unused.
370   */
371  void _Scheduler_default_Reconsider_help_request(
372    const Scheduler_Control *scheduler,
373    Thread_Control          *the_thread,
374    Scheduler_Node          *node
375  );
376
377  /**
378   * @brief Does nothing.
379   *
380   * @param[in] scheduler Unused.
381   * @param[in] the_thread Unused.
382   * @param[in] node Unused.
383   * @param[in] next_state Unused.
384   */
385  void _Scheduler_default_Withdraw_node(
386    const Scheduler_Control *scheduler,
387    Thread_Control          *the_thread,
388    Scheduler_Node          *node,
389    Thread_Scheduler_state   next_state
390  );
391
[5c3d250]392  #define SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP \
[351c14d]393    _Scheduler_default_Ask_for_help, \
394    _Scheduler_default_Reconsider_help_request, \
[0e754fac]395    _Scheduler_default_Withdraw_node,
[5c3d250]396#else
397  #define SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP
398#endif
399
[62d947d]400/**
[3733b224]401 * @brief Does nothing.
402 *
403 * @param[in] scheduler Unused.
404 * @param[in] the_thread Unused.
405 */
406void _Scheduler_default_Schedule(
407  const Scheduler_Control *scheduler,
408  Thread_Control          *the_thread
409);
410
411/**
[9bfad8c]412 * @brief Performs the scheduler base node initialization.
[62d947d]413 *
[24934e36]414 * @param[in] scheduler Unused.
[df2177ab]415 * @param[in] node The node to initialize.
[24934e36]416 * @param[in] the_thread Unused.
[9bfad8c]417 * @param[in] priority The thread priority.
[62d947d]418 */
[8e467384]419void _Scheduler_default_Node_initialize(
[e1598a6]420  const Scheduler_Control *scheduler,
[df2177ab]421  Scheduler_Node          *node,
[9bfad8c]422  Thread_Control          *the_thread,
423  Priority_Control         priority
[62d947d]424);
425
426/**
427 * @brief Does nothing.
428 *
[24934e36]429 * @param[in] scheduler Unused.
[df2177ab]430 * @param[in] node Unused.
[62d947d]431 */
[8e467384]432void _Scheduler_default_Node_destroy(
[e1598a6]433  const Scheduler_Control *scheduler,
[df2177ab]434  Scheduler_Node          *node
[62d947d]435);
436
[037cfd1]437/**
438 * @brief Does nothing.
439 *
[24934e36]440 * @param[in] scheduler Unused.
441 * @param[in] the_thread Unused.
[300f6a48]442 * @param[in] priority_node Unused.
[037cfd1]443 * @param[in] deadline Unused.
[300f6a48]444 * @param[in] queue_context Unused.
[ee0e4135]445 *
446 * @retval NULL Always.
[037cfd1]447 */
[300f6a48]448void _Scheduler_default_Release_job(
[e1598a6]449  const Scheduler_Control *scheduler,
450  Thread_Control          *the_thread,
[300f6a48]451  Priority_Node           *priority_node,
452  uint64_t                 deadline,
453  Thread_queue_Context    *queue_context
[037cfd1]454);
455
[21bdca4]456/**
457 * @brief Does nothing.
458 *
459 * @param[in] scheduler Unused.
460 * @param[in] the_thread Unused.
[300f6a48]461 * @param[in] priority_node Unused.
462 * @param[in] queue_context Unused.
[ee0e4135]463 *
464 * @retval NULL Always.
[21bdca4]465 */
[300f6a48]466void _Scheduler_default_Cancel_job(
[21bdca4]467  const Scheduler_Control *scheduler,
[300f6a48]468  Thread_Control          *the_thread,
469  Priority_Node           *priority_node,
470  Thread_queue_Context    *queue_context
[21bdca4]471);
472
[a344308]473/**
474 * @brief Performs tick operations depending on the CPU budget algorithm for
475 * each executing thread.
476 *
477 * This routine is invoked as part of processing each clock tick.
[24934e36]478 *
479 * @param[in] scheduler The scheduler.
[a7e4de2]480 * @param[in] executing An executing thread.
[a344308]481 */
[c5831a3f]482void _Scheduler_default_Tick(
483  const Scheduler_Control *scheduler,
484  Thread_Control          *executing
485);
[a344308]486
[1ccb64e1]487/**
[24934e36]488 * @brief Starts an idle thread.
[1ccb64e1]489 *
[24934e36]490 * @param[in] scheduler The scheduler.
491 * @param[in] the_thread An idle thread.
492 * @param[in] cpu This parameter is unused.
[1ccb64e1]493 */
494void _Scheduler_default_Start_idle(
[e1598a6]495  const Scheduler_Control *scheduler,
496  Thread_Control          *the_thread,
[96316d1b]497  struct Per_CPU_Control  *cpu
[1ccb64e1]498);
499
[cfe457f]500#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
501  /**
502   * @brief Get affinity for the default scheduler.
503   *
[a7e4de2]504   * @param[in] scheduler The scheduler instance.
[cfe457f]505   * @param[in] thread The associated thread.
506   * @param[in] cpusetsize The size of the cpuset.
507   * @param[out] cpuset Affinity set containing all CPUs.
508   *
509   * @retval 0 Successfully got cpuset
510   * @retval -1 The cpusetsize is invalid for the system
511   */
512  bool _Scheduler_default_Get_affinity(
[e1598a6]513    const Scheduler_Control *scheduler,
514    Thread_Control          *thread,
515    size_t                   cpusetsize,
516    cpu_set_t               *cpuset
[cfe457f]517  );
518
519  /**
520   * @brief Set affinity for the default scheduler.
521   *
[a7e4de2]522   * @param[in] scheduler The scheduler instance.
[cfe457f]523   * @param[in] thread The associated thread.
524   * @param[in] cpusetsize The size of the cpuset.
525   * @param[in] cpuset Affinity new affinity set.
526   *
527   * @retval 0 Successful
528   *
529   *  This method always returns successful and does not save
530   *  the cpuset.
531   */
532  bool _Scheduler_default_Set_affinity(
[e1598a6]533    const Scheduler_Control *scheduler,
534    Thread_Control          *thread,
535    size_t                   cpusetsize,
536    const cpu_set_t         *cpuset
[cfe457f]537  );
[bd1431a]538
539  #define SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
540    , _Scheduler_default_Get_affinity \
541    , _Scheduler_default_Set_affinity
542#else
543  #define SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY
[cfe457f]544#endif
545
[7dfb4b9]546/**
547 * @brief This defines the lowest (least important) thread priority of the
548 * first scheduler instance.
549 */
550#define PRIORITY_MAXIMUM ( _Scheduler_Table[ 0 ].maximum_priority )
551
[215f4014]552/**@}*/
553
[0faa9dad]554#ifdef __cplusplus
555}
556#endif
557
558#endif
[a15eaaf]559/* end of include file */
Note: See TracBrowser for help on using the repository browser.