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

5
Last change on this file since 7851555 was 7851555, checked in by Sebastian Huber <sebastian.huber@…>, on 07/03/17 at 12:05:26

score: Move processor affinity to Thread_Control

Update #3059.

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