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 Scheduler |
---|
32 | * |
---|
33 | * @ingroup ScoreScheduler |
---|
34 | */ |
---|
35 | /**@{*/ |
---|
36 | |
---|
37 | /** |
---|
38 | * Entry points for the Deterministic Priority Based Scheduler. |
---|
39 | */ |
---|
40 | #define SCHEDULER_PRIORITY_ENTRY_POINTS \ |
---|
41 | { \ |
---|
42 | _Scheduler_priority_Initialize, /* initialize entry point */ \ |
---|
43 | _Scheduler_priority_Schedule, /* schedule entry point */ \ |
---|
44 | _Scheduler_priority_Yield, /* yield entry point */ \ |
---|
45 | _Scheduler_priority_Block, /* block entry point */ \ |
---|
46 | _Scheduler_priority_Unblock, /* unblock entry point */ \ |
---|
47 | _Scheduler_priority_Change_priority, /* change priority entry point */ \ |
---|
48 | SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP \ |
---|
49 | _Scheduler_default_Node_initialize, /* node initialize entry point */ \ |
---|
50 | _Scheduler_default_Node_destroy, /* node destroy entry point */ \ |
---|
51 | _Scheduler_priority_Update_priority, /* update priority entry point */ \ |
---|
52 | _Scheduler_default_Release_job, /* new period of task */ \ |
---|
53 | _Scheduler_default_Tick, /* tick entry point */ \ |
---|
54 | _Scheduler_default_Start_idle /* start idle entry point */ \ |
---|
55 | SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \ |
---|
56 | } |
---|
57 | |
---|
58 | typedef struct { |
---|
59 | /** |
---|
60 | * @brief Basic scheduler context. |
---|
61 | */ |
---|
62 | Scheduler_Context Base; |
---|
63 | |
---|
64 | /** |
---|
65 | * @brief Bit map to indicate non-empty ready queues. |
---|
66 | */ |
---|
67 | Priority_bit_map_Control Bit_map; |
---|
68 | |
---|
69 | /** |
---|
70 | * @brief One ready queue per priority level. |
---|
71 | */ |
---|
72 | Chain_Control Ready[ 0 ]; |
---|
73 | } Scheduler_priority_Context; |
---|
74 | |
---|
75 | /** |
---|
76 | * @brief Data for ready queue operations. |
---|
77 | */ |
---|
78 | typedef struct { |
---|
79 | /** This field points to the Ready FIFO for this thread's priority. */ |
---|
80 | Chain_Control *ready_chain; |
---|
81 | |
---|
82 | /** This field contains precalculated priority map indices. */ |
---|
83 | Priority_bit_map_Information Priority_map; |
---|
84 | } Scheduler_priority_Ready_queue; |
---|
85 | |
---|
86 | /** |
---|
87 | * @brief Scheduler node specialization for Deterministic Priority schedulers. |
---|
88 | */ |
---|
89 | typedef struct { |
---|
90 | /** |
---|
91 | * @brief Basic scheduler node. |
---|
92 | */ |
---|
93 | Scheduler_Node Base; |
---|
94 | |
---|
95 | /** |
---|
96 | * @brief The associated ready queue of this node. |
---|
97 | */ |
---|
98 | Scheduler_priority_Ready_queue Ready_queue; |
---|
99 | } Scheduler_priority_Node; |
---|
100 | |
---|
101 | /** |
---|
102 | * @brief Initializes the priority scheduler. |
---|
103 | * This routine initializes the priority scheduler. |
---|
104 | */ |
---|
105 | void _Scheduler_priority_Initialize( const Scheduler_Control *scheduler ); |
---|
106 | |
---|
107 | /** |
---|
108 | * @brief Removes @a the_thread from the scheduling decision. |
---|
109 | * |
---|
110 | * This routine removes @a the_thread from the scheduling decision, |
---|
111 | * that is, removes it from the ready queue. It performs |
---|
112 | * any necessary scheduling operations including the selection of |
---|
113 | * a new heir thread. |
---|
114 | * |
---|
115 | * @param[in] scheduler The scheduler instance. |
---|
116 | * @param[in] the_thread is the thread to be blocked |
---|
117 | */ |
---|
118 | void _Scheduler_priority_Block( |
---|
119 | const Scheduler_Control *scheduler, |
---|
120 | Thread_Control *the_thread |
---|
121 | ); |
---|
122 | |
---|
123 | /** |
---|
124 | * @brief Sets the heir thread to be the next ready thread. |
---|
125 | * |
---|
126 | * This kernel routine sets the heir thread to be the next ready thread |
---|
127 | * by invoking the_scheduler->ready_queue->operations->first(). |
---|
128 | */ |
---|
129 | void _Scheduler_priority_Schedule( |
---|
130 | const Scheduler_Control *scheduler, |
---|
131 | Thread_Control *the_thread |
---|
132 | ); |
---|
133 | |
---|
134 | /** |
---|
135 | * @brief Updates the scheduler node to reflect the new priority of the |
---|
136 | * thread. |
---|
137 | */ |
---|
138 | void _Scheduler_priority_Update_priority( |
---|
139 | const Scheduler_Control *scheduler, |
---|
140 | Thread_Control *the_thread, |
---|
141 | Priority_Control new_priority |
---|
142 | ); |
---|
143 | |
---|
144 | /** |
---|
145 | * @brief Add @a the_thread to the scheduling decision. |
---|
146 | * |
---|
147 | * This routine adds @a the_thread to the scheduling decision, |
---|
148 | * that is, adds it to the ready queue and |
---|
149 | * updates any appropriate scheduling variables, for example the heir thread. |
---|
150 | * |
---|
151 | * @param[in] scheduler The scheduler instance. |
---|
152 | * @param[in] the_thread will be unblocked |
---|
153 | */ |
---|
154 | Scheduler_Void_or_thread _Scheduler_priority_Unblock( |
---|
155 | const Scheduler_Control *scheduler, |
---|
156 | Thread_Control *the_thread |
---|
157 | ); |
---|
158 | |
---|
159 | Scheduler_Void_or_thread _Scheduler_priority_Change_priority( |
---|
160 | const Scheduler_Control *scheduler, |
---|
161 | Thread_Control *the_thread, |
---|
162 | Priority_Control new_priority, |
---|
163 | bool prepend_it |
---|
164 | ); |
---|
165 | |
---|
166 | /** |
---|
167 | * @brief The specified THREAD yields. |
---|
168 | * |
---|
169 | * This routine is invoked when a thread wishes to voluntarily |
---|
170 | * transfer control of the processor to another thread in the queue. |
---|
171 | * |
---|
172 | * This routine will remove the specified THREAD from the ready queue |
---|
173 | * and place it immediately at the rear of this chain. Reset timeslice |
---|
174 | * and yield the processor functions both use this routine, therefore if |
---|
175 | * reset is true and this is the only thread on the queue then the |
---|
176 | * timeslice counter is reset. The heir THREAD will be updated if the |
---|
177 | * running is also the currently the heir. |
---|
178 | * |
---|
179 | * - INTERRUPT LATENCY: |
---|
180 | * + ready chain |
---|
181 | * + select heir |
---|
182 | * |
---|
183 | * @param[in] scheduler The scheduler instance. |
---|
184 | * @param[in,out] the_thread The yielding thread. |
---|
185 | */ |
---|
186 | Scheduler_Void_or_thread _Scheduler_priority_Yield( |
---|
187 | const Scheduler_Control *scheduler, |
---|
188 | Thread_Control *the_thread |
---|
189 | ); |
---|
190 | |
---|
191 | /**@}*/ |
---|
192 | |
---|
193 | #ifdef __cplusplus |
---|
194 | } |
---|
195 | #endif |
---|
196 | |
---|
197 | #endif |
---|
198 | /* end of include file */ |
---|