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.com/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_SCHEDULER_H |
---|
20 | #define _RTEMS_SCORE_SCHEDULER_H |
---|
21 | |
---|
22 | #include <rtems/score/percpu.h> |
---|
23 | #include <rtems/score/chain.h> |
---|
24 | #include <rtems/score/priority.h> |
---|
25 | #include <rtems/score/prioritybitmap.h> |
---|
26 | |
---|
27 | #ifdef __cplusplus |
---|
28 | extern "C" { |
---|
29 | #endif |
---|
30 | |
---|
31 | /** |
---|
32 | * @defgroup ScoreScheduler Scheduler Handler |
---|
33 | * |
---|
34 | * @ingroup Score |
---|
35 | * |
---|
36 | * This handler encapsulates functionality related to managing sets of threads |
---|
37 | * that are ready for execution. |
---|
38 | */ |
---|
39 | /**@{*/ |
---|
40 | |
---|
41 | /** |
---|
42 | * function jump table that holds pointers to the functions that |
---|
43 | * implement specific schedulers. |
---|
44 | */ |
---|
45 | typedef struct { |
---|
46 | /** Implements the scheduling decision logic (policy). */ |
---|
47 | void ( *initialize )(void); |
---|
48 | |
---|
49 | /** Implements the scheduling decision logic (policy). */ |
---|
50 | void ( *schedule )(void); |
---|
51 | |
---|
52 | /** Voluntarily yields the processor per the scheduling policy. */ |
---|
53 | void ( *yield )(void); |
---|
54 | |
---|
55 | /** Removes the given thread from scheduling decisions. */ |
---|
56 | void ( *block )(Thread_Control *); |
---|
57 | |
---|
58 | /** Adds the given thread to scheduling decisions. */ |
---|
59 | void ( *unblock )(Thread_Control *); |
---|
60 | |
---|
61 | /** allocates the scheduler field of the given thread */ |
---|
62 | void * ( *allocate )(Thread_Control *); |
---|
63 | |
---|
64 | /** frees the scheduler field of the given thread */ |
---|
65 | void ( *free )(Thread_Control *); |
---|
66 | |
---|
67 | /** updates the scheduler field of the given thread -- primarily used |
---|
68 | * when changing the thread's priority. */ |
---|
69 | void ( *update )(Thread_Control *); |
---|
70 | |
---|
71 | /** enqueue a thread as the last of its priority group */ |
---|
72 | void ( *enqueue )(Thread_Control *); |
---|
73 | |
---|
74 | /** enqueue a thread as the first of its priority group */ |
---|
75 | void ( *enqueue_first )(Thread_Control *); |
---|
76 | |
---|
77 | /** extract a thread from the ready set */ |
---|
78 | void ( *extract )(Thread_Control *); |
---|
79 | |
---|
80 | /** |
---|
81 | * Compares two priorities (returns >0 for higher priority, 0 for equal |
---|
82 | * and <0 for lower priority). |
---|
83 | */ |
---|
84 | int ( *priority_compare )(Priority_Control, Priority_Control); |
---|
85 | |
---|
86 | /** This routine is called upon release of a new job. */ |
---|
87 | void ( *release_job ) (Thread_Control *, uint32_t); |
---|
88 | |
---|
89 | /** perform scheduler update actions required at each clock tick */ |
---|
90 | void ( *tick )(void); |
---|
91 | |
---|
92 | } Scheduler_Operations; |
---|
93 | |
---|
94 | /** |
---|
95 | * This is the structure used to manage the scheduler. |
---|
96 | */ |
---|
97 | typedef struct { |
---|
98 | /** |
---|
99 | * This points to the data structure used to manage the ready set of |
---|
100 | * tasks. The pointer varies based upon the type of |
---|
101 | * ready queue required by the scheduler. |
---|
102 | */ |
---|
103 | void *information; |
---|
104 | |
---|
105 | /** The jump table for scheduler-specific functions */ |
---|
106 | Scheduler_Operations Operations; |
---|
107 | } Scheduler_Control; |
---|
108 | |
---|
109 | /** |
---|
110 | * The _Scheduler holds the structures used to manage the |
---|
111 | * scheduler. |
---|
112 | * |
---|
113 | * @note Can we make this per-cpu? then _Scheduler will be a macro. |
---|
114 | * |
---|
115 | * @note This is instantiated and initialized in confdefs.h. |
---|
116 | */ |
---|
117 | extern Scheduler_Control _Scheduler; |
---|
118 | |
---|
119 | /** |
---|
120 | * Macro testing whether @a p1 has lower priority than @a p2 |
---|
121 | * in the intuitive sense of priority. |
---|
122 | */ |
---|
123 | #define _Scheduler_Is_priority_lower_than( _p1, _p2 ) \ |
---|
124 | (_Scheduler_Priority_compare(_p1,_p2) < 0) |
---|
125 | |
---|
126 | /** |
---|
127 | * Macro testing whether @a p1 has higher priority than @a p2 |
---|
128 | * in the intuitive sense of priority. |
---|
129 | */ |
---|
130 | #define _Scheduler_Is_priority_higher_than( _p1, _p2 ) \ |
---|
131 | (_Scheduler_Priority_compare(_p1,_p2) > 0) |
---|
132 | |
---|
133 | /** |
---|
134 | * @brief Initializes the scheduler to the policy chosen by the user. |
---|
135 | * |
---|
136 | * This routine initializes the scheduler to the policy chosen by the user |
---|
137 | * through confdefs, or to the priority scheduler with ready chains by |
---|
138 | * default. |
---|
139 | */ |
---|
140 | void _Scheduler_Handler_initialization( void ); |
---|
141 | |
---|
142 | #ifndef __RTEMS_APPLICATION__ |
---|
143 | #include <rtems/score/scheduler.inl> |
---|
144 | #endif |
---|
145 | |
---|
146 | /**@}*/ |
---|
147 | |
---|
148 | #ifdef __cplusplus |
---|
149 | } |
---|
150 | #endif |
---|
151 | |
---|
152 | #endif |
---|
153 | /* end of include file */ |
---|