1 | /** |
---|
2 | * @file rtems/score/schedulerpriority.h |
---|
3 | * |
---|
4 | * @brief Thread Manipulation with the Priority-Based Scheduler |
---|
5 | * |
---|
6 | * This include file contains all the constants and structures associated |
---|
7 | * with the manipulation of threads for the priority-based scheduler. |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * Copryight (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_SCHEDULERPRIORITY_H |
---|
20 | #define _RTEMS_SCORE_SCHEDULERPRIORITY_H |
---|
21 | |
---|
22 | #include <rtems/score/chain.h> |
---|
23 | #include <rtems/score/prioritybitmap.h> |
---|
24 | #include <rtems/score/scheduler.h> |
---|
25 | |
---|
26 | #ifdef __cplusplus |
---|
27 | extern "C" { |
---|
28 | #endif |
---|
29 | |
---|
30 | /** |
---|
31 | * @defgroup ScoreSchedulerDPS Deterministic Priority-based Scheduler |
---|
32 | * |
---|
33 | * @ingroup ScoreScheduler |
---|
34 | */ |
---|
35 | /**@{*/ |
---|
36 | |
---|
37 | #if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP) |
---|
38 | #define SCHEDULER_PRIORITY_ADDITIONAL_SMP_ENTRY_POINTS \ |
---|
39 | _Scheduler_default_Get_affinity, /* get affinity entry point */ \ |
---|
40 | _Scheduler_default_Set_affinity /* set affinity entry point */ |
---|
41 | #else |
---|
42 | #define SCHEDULER_PRIORITY_ADDITIONAL_SMP_ENTRY_POINTS |
---|
43 | #endif |
---|
44 | |
---|
45 | /** |
---|
46 | * Entry points for the Deterministic Priority Based Scheduler. |
---|
47 | */ |
---|
48 | #define SCHEDULER_PRIORITY_ENTRY_POINTS \ |
---|
49 | { \ |
---|
50 | _Scheduler_priority_Initialize, /* initialize entry point */ \ |
---|
51 | _Scheduler_priority_Schedule, /* schedule entry point */ \ |
---|
52 | _Scheduler_priority_Yield, /* yield entry point */ \ |
---|
53 | _Scheduler_priority_Block, /* block entry point */ \ |
---|
54 | _Scheduler_priority_Unblock, /* unblock entry point */ \ |
---|
55 | _Scheduler_default_Allocate, /* allocate entry point */ \ |
---|
56 | _Scheduler_default_Free, /* free entry point */ \ |
---|
57 | _Scheduler_priority_Update, /* update entry point */ \ |
---|
58 | _Scheduler_priority_Enqueue, /* enqueue entry point */ \ |
---|
59 | _Scheduler_priority_Enqueue_first, /* enqueue_first entry point */ \ |
---|
60 | _Scheduler_priority_Extract, /* extract entry point */ \ |
---|
61 | _Scheduler_priority_Priority_compare, /* compares two priorities */ \ |
---|
62 | _Scheduler_default_Release_job, /* new period of task */ \ |
---|
63 | _Scheduler_default_Tick, /* tick entry point */ \ |
---|
64 | _Scheduler_default_Start_idle, /* start idle entry point */ \ |
---|
65 | SCHEDULER_PRIORITY_ADDITIONAL_SMP_ENTRY_POINTS \ |
---|
66 | } |
---|
67 | |
---|
68 | typedef struct { |
---|
69 | /** |
---|
70 | * @brief Basic scheduler context. |
---|
71 | */ |
---|
72 | Scheduler_Context Base; |
---|
73 | |
---|
74 | /** |
---|
75 | * @brief Bit map to indicate non-empty ready queues. |
---|
76 | */ |
---|
77 | Priority_bit_map_Control Bit_map; |
---|
78 | |
---|
79 | /** |
---|
80 | * @brief One ready queue per priority level. |
---|
81 | */ |
---|
82 | Chain_Control Ready[ 0 ]; |
---|
83 | } Scheduler_priority_Context; |
---|
84 | |
---|
85 | /** |
---|
86 | * Per-thread data related to the _Scheduler_PRIORITY scheduling policy. |
---|
87 | */ |
---|
88 | typedef struct { |
---|
89 | /** This field points to the Ready FIFO for this thread's priority. */ |
---|
90 | Chain_Control *ready_chain; |
---|
91 | |
---|
92 | /** This field contains precalculated priority map indices. */ |
---|
93 | Priority_bit_map_Information Priority_map; |
---|
94 | } Scheduler_priority_Per_thread; |
---|
95 | |
---|
96 | /** |
---|
97 | * @brief Initializes the priority scheduler. |
---|
98 | * This routine initializes the priority scheduler. |
---|
99 | */ |
---|
100 | void _Scheduler_priority_Initialize( const Scheduler_Control *scheduler ); |
---|
101 | |
---|
102 | /** |
---|
103 | * @brief Removes @a the_thread from the scheduling decision. |
---|
104 | * |
---|
105 | * This routine removes @a the_thread from the scheduling decision, |
---|
106 | * that is, removes it from the ready queue. It performs |
---|
107 | * any necessary scheduling operations including the selection of |
---|
108 | * a new heir thread. |
---|
109 | * |
---|
110 | * @param[in] the_thread is the thread to be blocked |
---|
111 | */ |
---|
112 | void _Scheduler_priority_Block( |
---|
113 | const Scheduler_Control *scheduler, |
---|
114 | Thread_Control *the_thread |
---|
115 | ); |
---|
116 | |
---|
117 | /** |
---|
118 | * @brief Sets the heir thread to be the next ready thread. |
---|
119 | * |
---|
120 | * This kernel routine sets the heir thread to be the next ready thread |
---|
121 | * by invoking the_scheduler->ready_queue->operations->first(). |
---|
122 | */ |
---|
123 | void _Scheduler_priority_Schedule( |
---|
124 | const Scheduler_Control *scheduler, |
---|
125 | Thread_Control *the_thread |
---|
126 | ); |
---|
127 | |
---|
128 | /** |
---|
129 | * @brief Update the scheduler priority. |
---|
130 | * This routine updates @a the_thread->scheduler based on @a the_scheduler |
---|
131 | * structures and thread state. |
---|
132 | * |
---|
133 | * @param[in] the_thread will have its scheduler specific information |
---|
134 | * structure updated. |
---|
135 | */ |
---|
136 | void _Scheduler_priority_Update( |
---|
137 | const Scheduler_Control *scheduler, |
---|
138 | Thread_Control *the_thread |
---|
139 | ); |
---|
140 | |
---|
141 | /** |
---|
142 | * @brief Add @a the_thread to the scheduling decision. |
---|
143 | * |
---|
144 | * This routine adds @a the_thread to the scheduling decision, |
---|
145 | * that is, adds it to the ready queue and |
---|
146 | * updates any appropriate scheduling variables, for example the heir thread. |
---|
147 | * |
---|
148 | * @param[in] the_thread will be unblocked |
---|
149 | */ |
---|
150 | void _Scheduler_priority_Unblock( |
---|
151 | const Scheduler_Control *scheduler, |
---|
152 | Thread_Control *the_thread |
---|
153 | ); |
---|
154 | |
---|
155 | /** |
---|
156 | * @brief The specified THREAD yields. |
---|
157 | * |
---|
158 | * This routine is invoked when a thread wishes to voluntarily |
---|
159 | * transfer control of the processor to another thread in the queue. |
---|
160 | * |
---|
161 | * This routine will remove the specified THREAD from the ready queue |
---|
162 | * and place it immediately at the rear of this chain. Reset timeslice |
---|
163 | * and yield the processor functions both use this routine, therefore if |
---|
164 | * reset is true and this is the only thread on the queue then the |
---|
165 | * timeslice counter is reset. The heir THREAD will be updated if the |
---|
166 | * running is also the currently the heir. |
---|
167 | * |
---|
168 | * - INTERRUPT LATENCY: |
---|
169 | * + ready chain |
---|
170 | * + select heir |
---|
171 | * |
---|
172 | * @param[in,out] thread The yielding thread. |
---|
173 | */ |
---|
174 | void _Scheduler_priority_Yield( |
---|
175 | const Scheduler_Control *scheduler, |
---|
176 | Thread_Control *the_thread |
---|
177 | ); |
---|
178 | |
---|
179 | /** |
---|
180 | * @brief Puts @a the_thread on to the priority-based ready queue. |
---|
181 | * |
---|
182 | * This routine puts @a the_thread on to the priority-based ready queue. |
---|
183 | * |
---|
184 | * @param[in] the_thread will be enqueued at the TAIL of its priority. |
---|
185 | */ |
---|
186 | void _Scheduler_priority_Enqueue( |
---|
187 | const Scheduler_Control *scheduler, |
---|
188 | Thread_Control *the_thread |
---|
189 | ); |
---|
190 | |
---|
191 | /** |
---|
192 | * @brief Puts @a the_thread to the head of the ready queue. |
---|
193 | * |
---|
194 | * This routine puts @a the_thread to the head of the ready queue. |
---|
195 | * For priority-based ready queues, the thread will be the first thread |
---|
196 | * at its priority level. |
---|
197 | * |
---|
198 | * @param[in] the_thread will be enqueued at the HEAD of its priority. |
---|
199 | */ |
---|
200 | void _Scheduler_priority_Enqueue_first( |
---|
201 | const Scheduler_Control *scheduler, |
---|
202 | Thread_Control *the_thread |
---|
203 | ); |
---|
204 | |
---|
205 | /** |
---|
206 | * @brief Remove a specific thread from scheduler. |
---|
207 | * |
---|
208 | * This routine removes a specific thread from the scheduler's set |
---|
209 | * of ready threads. |
---|
210 | * |
---|
211 | * @param[in] the_thread will be extracted from the ready set. |
---|
212 | */ |
---|
213 | void _Scheduler_priority_Extract( |
---|
214 | const Scheduler_Control *scheduler, |
---|
215 | Thread_Control *the_thread |
---|
216 | ); |
---|
217 | |
---|
218 | /** |
---|
219 | * @brief Compare two priorities. |
---|
220 | * |
---|
221 | * This routine compares two priorities. |
---|
222 | */ |
---|
223 | int _Scheduler_priority_Priority_compare( |
---|
224 | Priority_Control p1, |
---|
225 | Priority_Control p2 |
---|
226 | ); |
---|
227 | |
---|
228 | /**@}*/ |
---|
229 | |
---|
230 | #ifdef __cplusplus |
---|
231 | } |
---|
232 | #endif |
---|
233 | |
---|
234 | #endif |
---|
235 | /* end of include file */ |
---|