1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Inlined Routines Associated with the Manipulation of the |
---|
5 | * Priority-Based Scheduling Structures |
---|
6 | * |
---|
7 | * This inline file contains all of the inlined routines associated with |
---|
8 | * the manipulation of the priority-based scheduling structures. |
---|
9 | */ |
---|
10 | |
---|
11 | /* |
---|
12 | * Copyright (C) 2010 Gedare Bloom. |
---|
13 | * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.org/license/LICENSE. |
---|
18 | */ |
---|
19 | |
---|
20 | #ifndef _RTEMS_SCORE_SCHEDULERPRIORITYIMPL_H |
---|
21 | #define _RTEMS_SCORE_SCHEDULERPRIORITYIMPL_H |
---|
22 | |
---|
23 | #include <rtems/score/schedulerpriority.h> |
---|
24 | #include <rtems/score/chainimpl.h> |
---|
25 | #include <rtems/score/prioritybitmapimpl.h> |
---|
26 | #include <rtems/score/schedulerimpl.h> |
---|
27 | #include <rtems/score/thread.h> |
---|
28 | |
---|
29 | #ifdef __cplusplus |
---|
30 | extern "C" { |
---|
31 | #endif |
---|
32 | |
---|
33 | /** |
---|
34 | * @addtogroup ScoreSchedulerDPS |
---|
35 | */ |
---|
36 | /**@{**/ |
---|
37 | |
---|
38 | RTEMS_INLINE_ROUTINE Scheduler_priority_Context * |
---|
39 | _Scheduler_priority_Get_context( const Scheduler_Control *scheduler ) |
---|
40 | { |
---|
41 | return (Scheduler_priority_Context *) _Scheduler_Get_context( scheduler ); |
---|
42 | } |
---|
43 | |
---|
44 | RTEMS_INLINE_ROUTINE Scheduler_priority_Node *_Scheduler_priority_Thread_get_node( |
---|
45 | Thread_Control *the_thread |
---|
46 | ) |
---|
47 | { |
---|
48 | return (Scheduler_priority_Node *) _Scheduler_Thread_get_node( the_thread ); |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * @brief Ready queue initialization. |
---|
53 | * |
---|
54 | * This routine initializes @a ready_queues for priority-based scheduling. |
---|
55 | */ |
---|
56 | RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_initialize( |
---|
57 | Chain_Control *ready_queues |
---|
58 | ) |
---|
59 | { |
---|
60 | size_t index; |
---|
61 | |
---|
62 | /* initialize ready queue structures */ |
---|
63 | for( index=0; index <= PRIORITY_MAXIMUM; index++) |
---|
64 | _Chain_Initialize_empty( &ready_queues[index] ); |
---|
65 | } |
---|
66 | |
---|
67 | /** |
---|
68 | * @brief Enqueues a node on the specified ready queue. |
---|
69 | * |
---|
70 | * The node is placed as the last element of its priority group. |
---|
71 | * |
---|
72 | * @param[in] node The node to enqueue. |
---|
73 | * @param[in] ready_queue The ready queue. |
---|
74 | * @param[in] bit_map The priority bit map of the scheduler instance. |
---|
75 | */ |
---|
76 | RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_enqueue( |
---|
77 | Chain_Node *node, |
---|
78 | Scheduler_priority_Ready_queue *ready_queue, |
---|
79 | Priority_bit_map_Control *bit_map |
---|
80 | ) |
---|
81 | { |
---|
82 | Chain_Control *ready_chain = ready_queue->ready_chain; |
---|
83 | |
---|
84 | _Chain_Append_unprotected( ready_chain, node ); |
---|
85 | _Priority_bit_map_Add( bit_map, &ready_queue->Priority_map ); |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * @brief Enqueues a node on the specified ready queue as first. |
---|
90 | * |
---|
91 | * The node is placed as the first element of its priority group. |
---|
92 | * |
---|
93 | * @param[in] node The node to enqueue as first. |
---|
94 | * @param[in] ready_queue The ready queue. |
---|
95 | * @param[in] bit_map The priority bit map of the scheduler instance. |
---|
96 | */ |
---|
97 | RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_enqueue_first( |
---|
98 | Chain_Node *node, |
---|
99 | Scheduler_priority_Ready_queue *ready_queue, |
---|
100 | Priority_bit_map_Control *bit_map |
---|
101 | ) |
---|
102 | { |
---|
103 | Chain_Control *ready_chain = ready_queue->ready_chain; |
---|
104 | |
---|
105 | _Chain_Prepend_unprotected( ready_chain, node ); |
---|
106 | _Priority_bit_map_Add( bit_map, &ready_queue->Priority_map ); |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | * @brief Extracts a node from the specified ready queue. |
---|
111 | * |
---|
112 | * @param[in] node The node to extract. |
---|
113 | * @param[in] ready_queue The ready queue. |
---|
114 | * @param[in] bit_map The priority bit map of the scheduler instance. |
---|
115 | */ |
---|
116 | RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_extract( |
---|
117 | Chain_Node *node, |
---|
118 | Scheduler_priority_Ready_queue *ready_queue, |
---|
119 | Priority_bit_map_Control *bit_map |
---|
120 | ) |
---|
121 | { |
---|
122 | Chain_Control *ready_chain = ready_queue->ready_chain; |
---|
123 | |
---|
124 | if ( _Chain_Has_only_one_node( ready_chain ) ) { |
---|
125 | _Chain_Initialize_empty( ready_chain ); |
---|
126 | _Priority_bit_map_Remove( bit_map, &ready_queue->Priority_map ); |
---|
127 | } else { |
---|
128 | _Chain_Extract_unprotected( node ); |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | RTEMS_INLINE_ROUTINE void _Scheduler_priority_Extract_body( |
---|
133 | const Scheduler_Control *scheduler, |
---|
134 | Thread_Control *the_thread |
---|
135 | ) |
---|
136 | { |
---|
137 | Scheduler_priority_Context *context = |
---|
138 | _Scheduler_priority_Get_context( scheduler ); |
---|
139 | Scheduler_priority_Node *node = _Scheduler_priority_Thread_get_node( the_thread ); |
---|
140 | |
---|
141 | _Scheduler_priority_Ready_queue_extract( |
---|
142 | &the_thread->Object.Node, |
---|
143 | &node->Ready_queue, |
---|
144 | &context->Bit_map |
---|
145 | ); |
---|
146 | } |
---|
147 | |
---|
148 | /** |
---|
149 | * @brief Return a pointer to the first node. |
---|
150 | * |
---|
151 | * This routines returns a pointer to the first node on @a ready_queues. |
---|
152 | * |
---|
153 | * @param[in] bit_map The priority bit map of the scheduler instance. |
---|
154 | * @param[in] ready_queues The ready queues of the scheduler instance. |
---|
155 | * |
---|
156 | * @return This method returns the first node. |
---|
157 | */ |
---|
158 | RTEMS_INLINE_ROUTINE Chain_Node *_Scheduler_priority_Ready_queue_first( |
---|
159 | Priority_bit_map_Control *bit_map, |
---|
160 | Chain_Control *ready_queues |
---|
161 | ) |
---|
162 | { |
---|
163 | Priority_Control index = _Priority_bit_map_Get_highest( bit_map ); |
---|
164 | |
---|
165 | return _Chain_First( &ready_queues[ index ] ); |
---|
166 | } |
---|
167 | |
---|
168 | /** |
---|
169 | * @brief Scheduling decision logic. |
---|
170 | * |
---|
171 | * This kernel routine implements scheduling decision logic |
---|
172 | * for priority-based scheduling. |
---|
173 | */ |
---|
174 | RTEMS_INLINE_ROUTINE void _Scheduler_priority_Schedule_body( |
---|
175 | const Scheduler_Control *scheduler, |
---|
176 | Thread_Control *the_thread, |
---|
177 | bool force_dispatch |
---|
178 | ) |
---|
179 | { |
---|
180 | Scheduler_priority_Context *context = |
---|
181 | _Scheduler_priority_Get_context( scheduler ); |
---|
182 | Thread_Control *heir = (Thread_Control *) |
---|
183 | _Scheduler_priority_Ready_queue_first( |
---|
184 | &context->Bit_map, |
---|
185 | &context->Ready[ 0 ] |
---|
186 | ); |
---|
187 | |
---|
188 | ( void ) the_thread; |
---|
189 | |
---|
190 | _Scheduler_Update_heir( heir, force_dispatch ); |
---|
191 | } |
---|
192 | |
---|
193 | /** |
---|
194 | * @brief Updates the specified ready queue data according to the new priority |
---|
195 | * value. |
---|
196 | * |
---|
197 | * @param[in] ready_queue The ready queue. |
---|
198 | * @param[in] new_priority The new priority. |
---|
199 | * @param[in] bit_map The priority bit map of the scheduler instance. |
---|
200 | * @param[in] ready_queues The ready queues of the scheduler instance. |
---|
201 | */ |
---|
202 | RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_update( |
---|
203 | Scheduler_priority_Ready_queue *ready_queue, |
---|
204 | Priority_Control new_priority, |
---|
205 | Priority_bit_map_Control *bit_map, |
---|
206 | Chain_Control *ready_queues |
---|
207 | ) |
---|
208 | { |
---|
209 | ready_queue->ready_chain = &ready_queues[ new_priority ]; |
---|
210 | |
---|
211 | _Priority_bit_map_Initialize_information( |
---|
212 | bit_map, |
---|
213 | &ready_queue->Priority_map, |
---|
214 | new_priority |
---|
215 | ); |
---|
216 | } |
---|
217 | |
---|
218 | /** |
---|
219 | * @brief Priority comparison. |
---|
220 | * |
---|
221 | * This routine implements priority comparison for priority-based |
---|
222 | * scheduling. |
---|
223 | * |
---|
224 | * @return >0 for higher priority, 0 for equal and <0 for lower priority. |
---|
225 | */ |
---|
226 | RTEMS_INLINE_ROUTINE int _Scheduler_priority_Priority_compare_body( |
---|
227 | Priority_Control p1, |
---|
228 | Priority_Control p2 |
---|
229 | ) |
---|
230 | { |
---|
231 | /* High priority in priority scheduler is represented by low numbers. */ |
---|
232 | return ( p2 - p1 ); |
---|
233 | } |
---|
234 | |
---|
235 | /** @} */ |
---|
236 | |
---|
237 | #ifdef __cplusplus |
---|
238 | } |
---|
239 | #endif |
---|
240 | |
---|
241 | #endif |
---|
242 | /* end of include file */ |
---|