source: rtems/cpukit/score/include/rtems/score/schedulerpriorityimpl.h @ beab7329

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

score: Introduce scheduler nodes

Rename scheduler per-thread information into scheduler nodes using
Scheduler_Node as the base type. Use inheritance for specialized
schedulers.

Move the scheduler specific states from the thread control block into
the scheduler node structure.

Validate the SMP scheduler node state transitions in case RTEMS_DEBUG is
defined.

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