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

5
Last change on this file since d097b546 was d097b546, checked in by Sebastian Huber <sebastian.huber@…>, on 09/21/16 at 13:17:37

score: Rename scheduler ask for help stuff

Rename the scheduler ask for help stuff since this will be replaced step
by step with a second generation of the scheduler helping protocol.
Keep the old one for now in parallel to reduce the patch set sizes.

Update #2556.

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