RTEMS  5.0.0
scheduler.h
Go to the documentation of this file.
1 
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 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 struct Per_CPU_Control;
29 
41 
45 typedef struct {
47  void ( *initialize )( const Scheduler_Control * );
48 
50  void ( *schedule )( const Scheduler_Control *, Thread_Control *);
51 
53  void ( *yield )(
54  const Scheduler_Control *,
57  );
58 
60  void ( *block )(
61  const Scheduler_Control *,
62  Thread_Control *,
64  );
65 
67  void ( *unblock )(
68  const Scheduler_Control *,
69  Thread_Control *,
71  );
72 
74  void ( *update_priority )(
75  const Scheduler_Control *,
76  Thread_Control *,
78  );
79 
81  Priority_Control ( *map_priority )(
82  const Scheduler_Control *,
84  );
85 
87  Priority_Control ( *unmap_priority )(
88  const Scheduler_Control *,
90  );
91 
92 #if defined(RTEMS_SMP)
93 
103  bool ( *ask_for_help )(
104  const Scheduler_Control *scheduler,
105  Thread_Control *the_thread,
106  Scheduler_Node *node
107  );
108 
117  void ( *reconsider_help_request )(
118  const Scheduler_Control *scheduler,
119  Thread_Control *the_thread,
120  Scheduler_Node *node
121  );
122 
132  void ( *withdraw_node )(
133  const Scheduler_Control *scheduler,
134  Thread_Control *the_thread,
135  Scheduler_Node *node,
136  Thread_Scheduler_state next_state
137  );
138 
147  void ( *pin )(
148  const Scheduler_Control *scheduler,
149  Thread_Control *the_thread,
150  Scheduler_Node *node,
151  struct Per_CPU_Control *cpu
152  );
153 
162  void ( *unpin )(
163  const Scheduler_Control *scheduler,
164  Thread_Control *the_thread,
165  Scheduler_Node *node,
166  struct Per_CPU_Control *cpu
167  );
168 
175  void ( *add_processor )(
176  const Scheduler_Control *scheduler,
177  Thread_Control *idle
178  );
179 
188  Thread_Control *( *remove_processor )(
189  const Scheduler_Control *scheduler,
190  struct Per_CPU_Control *cpu
191  );
192 #endif
193 
195  void ( *node_initialize )(
196  const Scheduler_Control *,
197  Scheduler_Node *,
198  Thread_Control *,
200  );
201 
203  void ( *node_destroy )( const Scheduler_Control *, Scheduler_Node * );
204 
206  void ( *release_job ) (
207  const Scheduler_Control *,
208  Thread_Control *,
209  Priority_Node *,
210  uint64_t,
212  );
213 
215  void ( *cancel_job ) (
216  const Scheduler_Control *,
217  Thread_Control *,
218  Priority_Node *,
220  );
221 
223  void ( *tick )( const Scheduler_Control *, Thread_Control * );
224 
226  void ( *start_idle )(
227  const Scheduler_Control *,
228  Thread_Control *,
229  struct Per_CPU_Control *
230  );
231 
232 #if defined(RTEMS_SMP)
233 
234  bool ( *set_affinity )(
235  const Scheduler_Control *,
236  Thread_Control *,
237  Scheduler_Node *,
238  const Processor_mask *
239  );
240 #endif
242 
249 typedef struct Scheduler_Context {
253  ISR_LOCK_MEMBER( Lock )
254 
255 #if defined(RTEMS_SMP)
256 
259  Processor_mask Processors;
260 #endif
262 
271 
276 
284 
288  uint32_t name;
289 };
290 
298 extern const Scheduler_Control _Scheduler_Table[];
299 
311 #if defined(RTEMS_SMP)
312  extern const size_t _Scheduler_Count;
313 #else
314  #define _Scheduler_Count ( (size_t) 1 )
315 #endif
316 
317 #if defined(RTEMS_SMP)
318 
321  #define SCHEDULER_ASSIGN_DEFAULT UINT32_C(0x0)
322 
326  #define SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL SCHEDULER_ASSIGN_DEFAULT
327 
331  #define SCHEDULER_ASSIGN_PROCESSOR_MANDATORY UINT32_C(0x1)
332 
336  typedef struct {
340  const Scheduler_Control *scheduler;
341 
351  uint32_t attributes;
352  } Scheduler_Assignment;
353 
363  extern const Scheduler_Assignment _Scheduler_Initial_assignments[];
364 #endif
365 
376  const Scheduler_Control *scheduler,
377  Priority_Control priority
378 );
379 
390  const Scheduler_Control *scheduler,
391  Priority_Control priority
392 );
393 
394 #if defined(RTEMS_SMP)
395 
404  bool _Scheduler_default_Ask_for_help(
405  const Scheduler_Control *scheduler,
406  Thread_Control *the_thread,
407  Scheduler_Node *node
408  );
409 
417  void _Scheduler_default_Reconsider_help_request(
418  const Scheduler_Control *scheduler,
419  Thread_Control *the_thread,
420  Scheduler_Node *node
421  );
422 
431  void _Scheduler_default_Withdraw_node(
432  const Scheduler_Control *scheduler,
433  Thread_Control *the_thread,
434  Scheduler_Node *node,
435  Thread_Scheduler_state next_state
436  );
437 
447  void _Scheduler_default_Pin_or_unpin(
448  const Scheduler_Control *scheduler,
449  Thread_Control *the_thread,
450  Scheduler_Node *node,
451  struct Per_CPU_Control *cpu
452  );
453 
454  #define SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP \
455  _Scheduler_default_Ask_for_help, \
456  _Scheduler_default_Reconsider_help_request, \
457  _Scheduler_default_Withdraw_node, \
458  _Scheduler_default_Pin_or_unpin, \
459  _Scheduler_default_Pin_or_unpin, \
460  NULL, \
461  NULL,
462 #else
463  #define SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP
464 #endif
465 
473  const Scheduler_Control *scheduler,
474  Thread_Control *the_thread
475 );
476 
486  const Scheduler_Control *scheduler,
487  Scheduler_Node *node,
488  Thread_Control *the_thread,
489  Priority_Control priority
490 );
491 
499  const Scheduler_Control *scheduler,
500  Scheduler_Node *node
501 );
502 
515  const Scheduler_Control *scheduler,
516  Thread_Control *the_thread,
517  Priority_Node *priority_node,
518  uint64_t deadline,
519  Thread_queue_Context *queue_context
520 );
521 
533  const Scheduler_Control *scheduler,
534  Thread_Control *the_thread,
535  Priority_Node *priority_node,
536  Thread_queue_Context *queue_context
537 );
538 
549  const Scheduler_Control *scheduler,
550  Thread_Control *executing
551 );
552 
561  const Scheduler_Control *scheduler,
562  Thread_Control *the_thread,
563  struct Per_CPU_Control *cpu
564 );
565 
566 #if defined(RTEMS_SMP)
567 
578  bool _Scheduler_default_Set_affinity(
579  const Scheduler_Control *scheduler,
580  Thread_Control *thread,
581  Scheduler_Node *node,
582  const Processor_mask *affinity
583  );
584 
585  #define SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
586  , _Scheduler_default_Set_affinity
587 #else
588  #define SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY
589 #endif
590 
595 #define PRIORITY_MAXIMUM ( _Scheduler_Table[ 0 ].maximum_priority )
596 
599 #ifdef __cplusplus
600 }
601 #endif
602 
603 #endif
604 /* end of include file */
Scheduler context.
Definition: scheduler.h:249
The scheduler operations.
Definition: scheduler.h:45
struct Scheduler_Context Scheduler_Context
Scheduler context.
Thread queue context for the thread queue methods.
Definition: threadq.h:193
The priority node to build up a priority aggregation.
Definition: priority.h:94
Priority_Control _Scheduler_default_Map_priority(const Scheduler_Control *scheduler, Priority_Control priority)
Returns the scheduler internal thread priority mapped by SCHEDULER_PRIORITY_MAP().
Definition: schedulerdefaultmappriority.c:15
#define ISR_LOCK_MEMBER(_designator)
Defines an ISR lock member.
Definition: isrlock.h:89
uint32_t name
The scheduler name.
Definition: scheduler.h:288
void _Scheduler_default_Cancel_job(const Scheduler_Control *scheduler, Thread_Control *the_thread, Priority_Node *priority_node, Thread_queue_Context *queue_context)
Does nothing.
Definition: schedulerdefaultreleasejob.c:39
uint64_t Priority_Control
The thread priority control.
Definition: priority.h:66
void _Scheduler_default_Tick(const Scheduler_Control *scheduler, Thread_Control *executing)
Performs tick operations depending on the CPU budget algorithm for each executing thread...
Definition: schedulerdefaulttick.c:27
Definition: thread.h:728
Priority_Control _Scheduler_default_Unmap_priority(const Scheduler_Control *scheduler, Priority_Control priority)
Returns the user visible thread priority unmapped by SCHEDULER_PRIORITY_UNMAP().
Definition: schedulerdefaultmappriority.c:23
Per CPU Core Structure.
Definition: percpu.h:290
Priority_Control maximum_priority
The maximum priority value of this scheduler.
Definition: scheduler.h:283
void _Scheduler_default_Start_idle(const Scheduler_Control *scheduler, Thread_Control *the_thread, struct Per_CPU_Control *cpu)
Starts an idle thread.
Definition: schedulerdefaultstartidle.c:15
void _Scheduler_default_Schedule(const Scheduler_Control *scheduler, Thread_Control *the_thread)
Does nothing.
Definition: schedulerdefaultschedule.c:15
void _Scheduler_default_Release_job(const Scheduler_Control *scheduler, Thread_Control *the_thread, Priority_Node *priority_node, uint64_t deadline, Thread_queue_Context *queue_context)
Does nothing.
Definition: schedulerdefaultreleasejob.c:24
Scheduler_Operations Operations
The scheduler operations.
Definition: scheduler.h:275
Scheduler control.
Definition: scheduler.h:266
Scheduler node for per-thread data.
Definition: schedulernode.h:65
const Scheduler_Control _Scheduler_Table[]
Registered schedulers.
Scheduler_Context * context
Reference to a statically allocated scheduler context.
Definition: scheduler.h:270
Constants and Structures Related with the Thread Control Block.
void _Scheduler_default_Node_initialize(const Scheduler_Control *scheduler, Scheduler_Node *node, Thread_Control *the_thread, Priority_Control priority)
Performs the scheduler base node initialization.
Definition: schedulerdefaultnodeinit.c:24
void _Scheduler_default_Node_destroy(const Scheduler_Control *scheduler, Scheduler_Node *node)
Does nothing.
Definition: schedulerdefaultnodedestroy.c:24
#define _Scheduler_Count
Count of registered schedulers.
Definition: scheduler.h:314