RTEMS CPU Kit with SuperCore  4.11.2
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/priority.h>
23 #include <rtems/score/thread.h>
24 #if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
25  #include <sys/cpuset.h>
26 #endif
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 struct Per_CPU_Control;
33 
45 
46 typedef struct Scheduler_Node Scheduler_Node;
47 
48 #if defined(RTEMS_SMP)
49  typedef Thread_Control * Scheduler_Void_or_thread;
50 
51  #define SCHEDULER_RETURN_VOID_OR_NULL return NULL
52 #else
53  typedef void Scheduler_Void_or_thread;
54 
55  #define SCHEDULER_RETURN_VOID_OR_NULL return
56 #endif
57 
61 typedef struct {
63  void ( *initialize )( const Scheduler_Control * );
64 
66  void ( *schedule )( const Scheduler_Control *, Thread_Control *);
67 
69  Scheduler_Void_or_thread ( *yield )(
70  const Scheduler_Control *,
72  );
73 
75  void ( *block )(
76  const Scheduler_Control *,
78  );
79 
81  Scheduler_Void_or_thread ( *unblock )(
82  const Scheduler_Control *,
84  );
85 
87  Scheduler_Void_or_thread ( *change_priority )(
88  const Scheduler_Control *,
91  bool
92  );
93 
94 #if defined(RTEMS_SMP)
95 
112  Thread_Control *( *ask_for_help )(
113  const Scheduler_Control *scheduler,
114  Thread_Control *offers_help,
115  Thread_Control *needs_help
116  );
117 #endif
118 
120  void ( *node_initialize )( const Scheduler_Control *, Thread_Control * );
121 
123  void ( *node_destroy )( const Scheduler_Control *, Thread_Control * );
124 
126  void ( *update_priority )(
127  const Scheduler_Control *,
128  Thread_Control *,
130  );
131 
133  int ( *priority_compare )(
136  );
137 
139  void ( *release_job ) (
140  const Scheduler_Control *,
141  Thread_Control *,
142  uint32_t
143  );
144 
146  void ( *tick )( const Scheduler_Control *, Thread_Control * );
147 
149  void ( *start_idle )(
150  const Scheduler_Control *,
151  Thread_Control *,
152  struct Per_CPU_Control *
153  );
154 
155 #if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
156 
157  bool ( *get_affinity )(
158  const Scheduler_Control *,
159  Thread_Control *,
160  size_t,
161  cpu_set_t *
162  );
163 
165  bool ( *set_affinity )(
166  const Scheduler_Control *,
167  Thread_Control *,
168  size_t,
169  const cpu_set_t *
170  );
171 #endif
173 
180 typedef struct Scheduler_Context {
181 #if defined(RTEMS_SMP)
182 
185  uint32_t processor_count;
186 #endif
188 
197 
202 
206  uint32_t name;
207 };
208 
209 #if defined(RTEMS_SMP)
210 
228 typedef enum {
236  SCHEDULER_HELP_YOURSELF,
237 
253  SCHEDULER_HELP_ACTIVE_OWNER,
254 
264  SCHEDULER_HELP_ACTIVE_RIVAL,
265 
274  SCHEDULER_HELP_PASSIVE
275 } Scheduler_Help_state;
276 #endif
277 
282 #if defined(RTEMS_SMP)
283 
293  Chain_Node Node;
294 
298  Thread_Control *user;
299 
303  Scheduler_Help_state help_state;
304 
308  Thread_Control *owner;
309 
319  Thread_Control *idle;
320 
325  Thread_Control *accepts_help;
326 #endif
327 };
328 
336 extern const Scheduler_Control _Scheduler_Table[];
337 
349 #if defined(RTEMS_SMP)
350  extern const size_t _Scheduler_Count;
351 #else
352  #define _Scheduler_Count ( (size_t) 1 )
353 #endif
354 
355 #if defined(RTEMS_SMP)
356 
359  #define SCHEDULER_ASSIGN_DEFAULT UINT32_C(0x0)
360 
364  #define SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL SCHEDULER_ASSIGN_DEFAULT
365 
369  #define SCHEDULER_ASSIGN_PROCESSOR_MANDATORY UINT32_C(0x1)
370 
374  typedef struct {
378  const Scheduler_Control *scheduler;
379 
389  uint32_t attributes;
390  } Scheduler_Assignment;
391 
401  extern const Scheduler_Assignment _Scheduler_Assignments[];
402 #endif
403 
404 #if defined(RTEMS_SMP)
405 
414  Thread_Control *_Scheduler_default_Ask_for_help(
415  const Scheduler_Control *scheduler,
416  Thread_Control *offers_help,
417  Thread_Control *needs_help
418  );
419 
420  #define SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP \
421  _Scheduler_default_Ask_for_help,
422 #else
423  #define SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP
424 #endif
425 
433  const Scheduler_Control *scheduler,
434  Thread_Control *the_thread
435 );
436 
444  const Scheduler_Control *scheduler,
445  Thread_Control *the_thread
446 );
447 
455  const Scheduler_Control *scheduler,
456  Thread_Control *the_thread
457 );
458 
467  const Scheduler_Control *scheduler,
468  Thread_Control *the_thread,
469  Priority_Control new_priority
470 );
471 
480  const Scheduler_Control *scheduler,
481  Thread_Control *the_thread,
482  uint32_t deadline
483 );
484 
495  const Scheduler_Control *scheduler,
496  Thread_Control *executing
497 );
498 
507  const Scheduler_Control *scheduler,
508  Thread_Control *the_thread,
509  struct Per_CPU_Control *cpu
510 );
511 
512 #if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
513 
524  bool _Scheduler_default_Get_affinity(
525  const Scheduler_Control *scheduler,
526  Thread_Control *thread,
527  size_t cpusetsize,
528  cpu_set_t *cpuset
529  );
530 
544  bool _Scheduler_default_Set_affinity(
545  const Scheduler_Control *scheduler,
546  Thread_Control *thread,
547  size_t cpusetsize,
548  const cpu_set_t *cpuset
549  );
550 
551  #define SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
552  , _Scheduler_default_Get_affinity \
553  , _Scheduler_default_Set_affinity
554 #else
555  #define SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY
556 #endif
557 
560 #ifdef __cplusplus
561 }
562 #endif
563 
564 #endif
565 /* end of include file */
Thread Priority Manipulation Routines.
This is used to manage each element (node) which is placed on a chain.
Definition: chain.h:65
Scheduler control.
Definition: scheduler.h:192
Scheduler_Operations Operations
The scheduler operations.
Definition: scheduler.h:201
Scheduler context.
Definition: scheduler.h:180
The scheduler operations.
Definition: scheduler.h:61
struct Scheduler_Context Scheduler_Context
Scheduler context.
Scheduler_Context * context
Reference to a statically allocated scheduler context.
Definition: scheduler.h:196
void _Scheduler_default_Release_job(const Scheduler_Control *scheduler, Thread_Control *the_thread, uint32_t deadline)
Does nothing.
Definition: schedulerdefaultreleasejob.c:24
Constants and Structures Related with the Thread Control Block.
uint32_t Priority_Control
The following type defines the control block used to manage thread priorities.
Definition: priority.h:56
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
uint32_t name
The scheduler name.
Definition: scheduler.h:206
This structure defines the Thread Control Block (TCB).
Definition: thread.h:671
Per CPU Core Structure.
Definition: percpu.h:233
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:16
void _Scheduler_default_Node_destroy(const Scheduler_Control *scheduler, Thread_Control *the_thread)
Does nothing.
Definition: schedulerdefaultnodedestroy.c:24
void _Scheduler_default_Node_initialize(const Scheduler_Control *scheduler, Thread_Control *the_thread)
Does nothing.
Definition: schedulerdefaultnodeinit.c:24
void _Scheduler_default_Schedule(const Scheduler_Control *scheduler, Thread_Control *the_thread)
Does nothing.
Definition: schedulerdefaultschedule.c:16
Scheduler node for per-thread data.
Definition: scheduler.h:281
const Scheduler_Control _Scheduler_Table[]
Registered schedulers.
void _Scheduler_default_Update_priority(const Scheduler_Control *scheduler, Thread_Control *the_thread, Priority_Control new_priority)
Does nothing.
Definition: schedulerdefaultupdate.c:24
#define _Scheduler_Count
Count of registered schedulers.
Definition: scheduler.h:352