source: rtems/cpukit/score/include/rtems/score/schedulerpriorityimpl.h @ 5b1ff71a

4.115
Last change on this file since 5b1ff71a was 5b1ff71a, checked in by Sebastian Huber <sebastian.huber@…>, on 05/13/14 at 13:57:43

score: Scheduler documentation

  • Property mode set to 100644
File size: 7.2 KB
Line 
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
30extern "C" {
31#endif
32
33/**
34 * @addtogroup ScoreSchedulerDPS
35 */
36/**@{**/
37
38RTEMS_INLINE_ROUTINE Scheduler_priority_Context *
39  _Scheduler_priority_Get_context( const Scheduler_Control *scheduler )
40{
41  return (Scheduler_priority_Context *) scheduler->context;
42}
43
44/**
45 * @brief Ready queue initialization.
46 *
47 * This routine initializes @a ready_queues for priority-based scheduling.
48 */
49RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_initialize(
50  Chain_Control *ready_queues
51)
52{
53  size_t index;
54
55  /* initialize ready queue structures */
56  for( index=0; index <= PRIORITY_MAXIMUM; index++)
57    _Chain_Initialize_empty( &ready_queues[index] );
58}
59
60RTEMS_INLINE_ROUTINE Scheduler_priority_Per_thread *
61_Scheduler_priority_Get_scheduler_info( Thread_Control *thread )
62{
63  return ( Scheduler_priority_Per_thread * ) thread->scheduler_info;
64}
65
66/**
67 * @brief Put a thread to the ready queue.
68 *
69 * This routine puts @a the_thread on to the priority-based ready queue.
70 *
71 * @param[in] the_thread The thread to enqueue.
72 * @param[in] bit_map The priority bit map of the scheduler instance.
73 */
74RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_enqueue(
75  Thread_Control           *the_thread,
76  Priority_bit_map_Control *bit_map
77)
78{
79  Scheduler_priority_Per_thread *sched_info_of_thread =
80    _Scheduler_priority_Get_scheduler_info( the_thread );
81  Chain_Control *ready_chain = sched_info_of_thread->ready_chain;
82
83  _Chain_Append_unprotected( ready_chain, &the_thread->Object.Node );
84  _Priority_bit_map_Add( bit_map, &sched_info_of_thread->Priority_map );
85}
86
87/**
88 * @brief Put a thread to the head of the ready queue.
89 *
90 * This routine puts @a the_thread to the head of the ready queue.
91 * For priority-based ready queues, the thread will be the first thread
92 * at its priority level.
93 *
94 * @param[in] the_thread The thread to enqueue.
95 * @param[in] bit_map The priority bit map of the scheduler instance.
96 */
97RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_enqueue_first(
98  Thread_Control           *the_thread,
99  Priority_bit_map_Control *bit_map
100)
101{
102  Scheduler_priority_Per_thread *sched_info_of_thread =
103    _Scheduler_priority_Get_scheduler_info( the_thread );
104  Chain_Control *ready_chain = sched_info_of_thread->ready_chain;
105
106  _Chain_Prepend_unprotected( ready_chain, &the_thread->Object.Node );
107  _Priority_bit_map_Add( bit_map, &sched_info_of_thread->Priority_map );
108}
109
110/**
111 * @brief Remove a specific thread from the ready queue.
112 *
113 * This routine removes a specific thread from the specified
114 * priority-based ready queue.
115 *
116 * @param[in] the_thread The thread to extract.
117 * @param[in] bit_map The priority bit map of the scheduler instance.
118 */
119RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_extract(
120  Thread_Control           *the_thread,
121  Priority_bit_map_Control *bit_map
122)
123{
124  Scheduler_priority_Per_thread *sched_info_of_thread =
125    _Scheduler_priority_Get_scheduler_info( the_thread );
126  Chain_Control *ready_chain = sched_info_of_thread->ready_chain;
127
128  if ( _Chain_Has_only_one_node( ready_chain ) ) {
129    _Chain_Initialize_empty( ready_chain );
130    _Priority_bit_map_Remove( bit_map, &sched_info_of_thread->Priority_map );
131  } else {
132    _Chain_Extract_unprotected( &the_thread->Object.Node );
133  }
134}
135
136RTEMS_INLINE_ROUTINE void _Scheduler_priority_Extract_body(
137  const Scheduler_Control *scheduler,
138  Thread_Control          *the_thread
139)
140{
141  Scheduler_priority_Context *context =
142    _Scheduler_priority_Get_context( scheduler );
143
144  _Scheduler_priority_Ready_queue_extract( the_thread, &context->Bit_map );
145}
146
147/**
148 * @brief Return a pointer to the first thread.
149 *
150 * This routines returns a pointer to the first thread on @a ready_queues.
151 *
152 * @param[in] bit_map The priority bit map of the scheduler instance.
153 * @param[in] ready_queues The ready queues of the scheduler instance.
154 *
155 * @return This method returns the first thread or NULL
156 */
157RTEMS_INLINE_ROUTINE Thread_Control *_Scheduler_priority_Ready_queue_first(
158  Priority_bit_map_Control *bit_map,
159  Chain_Control            *ready_queues
160)
161{
162  Priority_Control index = _Priority_bit_map_Get_highest( bit_map );
163
164  return (Thread_Control *) _Chain_First( &ready_queues[ index ] );
165}
166
167/**
168 * @brief Requeue a thread on the ready queue.
169 *
170 * This routine is invoked when a thread changes priority and should be
171 * moved to a different position on the ready queue.
172 *
173 * @param[in] the_thread is a pointer to the thread
174 */
175RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_requeue(
176  Thread_Control            *the_thread
177)
178{
179  Scheduler_priority_Per_thread *sched_info_of_thread =
180    _Scheduler_priority_Get_scheduler_info( the_thread );
181  Chain_Control *ready_chain = sched_info_of_thread->ready_chain;
182
183  if ( !_Chain_Has_only_one_node( ready_chain ) ) {
184    _Chain_Extract_unprotected( &the_thread->Object.Node );
185    _Chain_Append_unprotected( ready_chain, &the_thread->Object.Node );
186  }
187}
188
189/**
190 * @brief Scheduling decision logic.
191 *
192 * This kernel routine implements scheduling decision logic
193 * for priority-based scheduling.
194 */
195RTEMS_INLINE_ROUTINE void _Scheduler_priority_Schedule_body(
196  const Scheduler_Control *scheduler,
197  Thread_Control          *the_thread,
198  bool                     force_dispatch
199)
200{
201  Scheduler_priority_Context *context =
202    _Scheduler_priority_Get_context( scheduler );
203  Thread_Control *heir = _Scheduler_priority_Ready_queue_first(
204    &context->Bit_map,
205    &context->Ready[ 0 ]
206  );
207
208  ( void ) the_thread;
209
210  _Scheduler_Update_heir( heir, force_dispatch );
211}
212
213RTEMS_INLINE_ROUTINE void _Scheduler_priority_Update_body(
214  Thread_Control           *thread,
215  Priority_bit_map_Control *bit_map,
216  Chain_Control            *ready_queues
217)
218{
219  Scheduler_priority_Per_thread *sched_info_of_thread =
220    _Scheduler_priority_Get_scheduler_info( thread );
221
222  sched_info_of_thread->ready_chain =
223    &ready_queues[ thread->current_priority ];
224
225  _Priority_bit_map_Initialize_information(
226    bit_map,
227    &sched_info_of_thread->Priority_map,
228    thread->current_priority
229  );
230}
231
232/**
233 * @brief Priority comparison.
234 *
235 * This routine implements priority comparison for priority-based
236 * scheduling.
237 *
238 * @return >0 for higher priority, 0 for equal and <0 for lower priority.
239 */
240RTEMS_INLINE_ROUTINE int _Scheduler_priority_Priority_compare_body(
241  Priority_Control      p1,
242  Priority_Control      p2
243)
244{
245  /* High priority in priority scheduler is represented by low numbers. */
246  return ( p2 - p1 );
247}
248
249/** @} */
250
251#ifdef __cplusplus
252}
253#endif
254
255#endif
256/* end of include file */
Note: See TracBrowser for help on using the repository browser.