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 | /** |
---|
53 | * @brief Voluntarily yields the processor per the scheduling policy. |
---|
54 | * |
---|
55 | * @see _Scheduler_Yield(). |
---|
56 | */ |
---|
57 | void ( *yield )( Thread_Control *thread ); |
---|
58 | |
---|
59 | /** Removes the given thread from scheduling decisions. */ |
---|
60 | void ( *block )(Thread_Control *); |
---|
61 | |
---|
62 | /** Adds the given thread to scheduling decisions. */ |
---|
63 | void ( *unblock )(Thread_Control *); |
---|
64 | |
---|
65 | /** allocates the scheduler field of the given thread */ |
---|
66 | void * ( *allocate )(Thread_Control *); |
---|
67 | |
---|
68 | /** frees the scheduler field of the given thread */ |
---|
69 | void ( *free )(Thread_Control *); |
---|
70 | |
---|
71 | /** updates the scheduler field of the given thread -- primarily used |
---|
72 | * when changing the thread's priority. */ |
---|
73 | void ( *update )(Thread_Control *); |
---|
74 | |
---|
75 | /** enqueue a thread as the last of its priority group */ |
---|
76 | void ( *enqueue )(Thread_Control *); |
---|
77 | |
---|
78 | /** enqueue a thread as the first of its priority group */ |
---|
79 | void ( *enqueue_first )(Thread_Control *); |
---|
80 | |
---|
81 | /** extract a thread from the ready set */ |
---|
82 | void ( *extract )(Thread_Control *); |
---|
83 | |
---|
84 | /** |
---|
85 | * Compares two priorities (returns >0 for higher priority, 0 for equal |
---|
86 | * and <0 for lower priority). |
---|
87 | */ |
---|
88 | int ( *priority_compare )(Priority_Control, Priority_Control); |
---|
89 | |
---|
90 | /** This routine is called upon release of a new job. */ |
---|
91 | void ( *release_job ) (Thread_Control *, uint32_t); |
---|
92 | |
---|
93 | /** perform scheduler update actions required at each clock tick */ |
---|
94 | void ( *tick )(void); |
---|
95 | |
---|
96 | /** |
---|
97 | * @brief Starts the idle thread for a particular processor. |
---|
98 | * |
---|
99 | * @see _Scheduler_Start_idle(). |
---|
100 | */ |
---|
101 | void ( *start_idle )( Thread_Control *thread, Per_CPU_Control *processor ); |
---|
102 | } Scheduler_Operations; |
---|
103 | |
---|
104 | /** |
---|
105 | * This is the structure used to manage the scheduler. |
---|
106 | */ |
---|
107 | typedef struct { |
---|
108 | /** |
---|
109 | * This points to the data structure used to manage the ready set of |
---|
110 | * tasks. The pointer varies based upon the type of |
---|
111 | * ready queue required by the scheduler. |
---|
112 | */ |
---|
113 | void *information; |
---|
114 | |
---|
115 | /** The jump table for scheduler-specific functions */ |
---|
116 | Scheduler_Operations Operations; |
---|
117 | } Scheduler_Control; |
---|
118 | |
---|
119 | /** |
---|
120 | * The _Scheduler holds the structures used to manage the |
---|
121 | * scheduler. |
---|
122 | * |
---|
123 | * @note Can we make this per-cpu? then _Scheduler will be a macro. |
---|
124 | * |
---|
125 | * @note This is instantiated and initialized in confdefs.h. |
---|
126 | */ |
---|
127 | extern Scheduler_Control _Scheduler; |
---|
128 | |
---|
129 | /** |
---|
130 | * Macro testing whether @a p1 has lower priority than @a p2 |
---|
131 | * in the intuitive sense of priority. |
---|
132 | */ |
---|
133 | #define _Scheduler_Is_priority_lower_than( _p1, _p2 ) \ |
---|
134 | (_Scheduler_Priority_compare(_p1,_p2) < 0) |
---|
135 | |
---|
136 | /** |
---|
137 | * Macro testing whether @a p1 has higher priority than @a p2 |
---|
138 | * in the intuitive sense of priority. |
---|
139 | */ |
---|
140 | #define _Scheduler_Is_priority_higher_than( _p1, _p2 ) \ |
---|
141 | (_Scheduler_Priority_compare(_p1,_p2) > 0) |
---|
142 | |
---|
143 | /** |
---|
144 | * @brief Initializes the scheduler to the policy chosen by the user. |
---|
145 | * |
---|
146 | * This routine initializes the scheduler to the policy chosen by the user |
---|
147 | * through confdefs, or to the priority scheduler with ready chains by |
---|
148 | * default. |
---|
149 | */ |
---|
150 | void _Scheduler_Handler_initialization( void ); |
---|
151 | |
---|
152 | /** |
---|
153 | * @brief Performs tick operations depending on the CPU budget algorithm for |
---|
154 | * each executing thread. |
---|
155 | * |
---|
156 | * This routine is invoked as part of processing each clock tick. |
---|
157 | */ |
---|
158 | void _Scheduler_default_Tick( void ); |
---|
159 | |
---|
160 | /** |
---|
161 | * @brief Unblocks the thread. |
---|
162 | * |
---|
163 | * @param[in/out] thread An idle thread. |
---|
164 | * @param[in] processor This parameter is unused. |
---|
165 | */ |
---|
166 | void _Scheduler_default_Start_idle( |
---|
167 | Thread_Control *thread, |
---|
168 | Per_CPU_Control *processor |
---|
169 | ); |
---|
170 | |
---|
171 | #ifndef __RTEMS_APPLICATION__ |
---|
172 | #include <rtems/score/scheduler.inl> |
---|
173 | #endif |
---|
174 | |
---|
175 | /**@}*/ |
---|
176 | |
---|
177 | #ifdef __cplusplus |
---|
178 | } |
---|
179 | #endif |
---|
180 | |
---|
181 | #endif |
---|
182 | /* end of include file */ |
---|