source: rtems/cpukit/score/include/rtems/score/schedulerpriorityimpl.h @ 647b95d

4.115
Last change on this file since 647b95d was 647b95d, checked in by Sebastian Huber <sebastian.huber@…>, on 06/10/14 at 14:32:12

score: Use chain nodes for ready queue support

This reduces the API to the minimum data structures to maximize the
re-usability.

  • Property mode set to 100644
File size: 6.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{
[2369b10]41  return (Scheduler_priority_Context *) _Scheduler_Get_context( scheduler );
[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
[010192d]67/**
[647b95d]68 * @brief Enqueues a node on the specified ready queue.
[0faa9dad]69 *
[647b95d]70 * The node is placed as the last element of its priority group.
[d8134178]71 *
[647b95d]72 * @param[in] node The node to enqueue.
[beab7329]73 * @param[in] ready_queue The ready queue.
[494c2e3]74 * @param[in] bit_map The priority bit map of the scheduler instance.
[0faa9dad]75 */
76RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_enqueue(
[647b95d]77  Chain_Node                     *node,
[beab7329]78  Scheduler_priority_Ready_queue *ready_queue,
79  Priority_bit_map_Control       *bit_map
[0faa9dad]80)
81{
[beab7329]82  Chain_Control *ready_chain = ready_queue->ready_chain;
[108c4b0]83
[647b95d]84  _Chain_Append_unprotected( ready_chain, node );
[beab7329]85  _Priority_bit_map_Add( bit_map, &ready_queue->Priority_map );
[0faa9dad]86}
87
[010192d]88/**
[647b95d]89 * @brief Enqueues a node on the specified ready queue as first.
[0faa9dad]90 *
[647b95d]91 * The node is placed as the first element of its priority group.
[d8134178]92 *
[647b95d]93 * @param[in] node The node to enqueue as first.
[beab7329]94 * @param[in] ready_queue The ready queue.
[494c2e3]95 * @param[in] bit_map The priority bit map of the scheduler instance.
[0faa9dad]96 */
97RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_enqueue_first(
[647b95d]98  Chain_Node                     *node,
[beab7329]99  Scheduler_priority_Ready_queue *ready_queue,
100  Priority_bit_map_Control       *bit_map
[0faa9dad]101)
102{
[beab7329]103  Chain_Control *ready_chain = ready_queue->ready_chain;
[108c4b0]104
[647b95d]105  _Chain_Prepend_unprotected( ready_chain, node );
[beab7329]106  _Priority_bit_map_Add( bit_map, &ready_queue->Priority_map );
[0faa9dad]107}
108
[010192d]109/**
[647b95d]110 * @brief Extracts a node from the specified ready queue.
[0faa9dad]111 *
[647b95d]112 * @param[in] node The node to extract.
[beab7329]113 * @param[in] ready_queue The ready queue.
[494c2e3]114 * @param[in] bit_map The priority bit map of the scheduler instance.
[0faa9dad]115 */
116RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_extract(
[647b95d]117  Chain_Node                     *node,
[beab7329]118  Scheduler_priority_Ready_queue *ready_queue,
119  Priority_bit_map_Control       *bit_map
[0faa9dad]120)
121{
[beab7329]122  Chain_Control *ready_chain = ready_queue->ready_chain;
[0faa9dad]123
[0c551f7]124  if ( _Chain_Has_only_one_node( ready_chain ) ) {
125    _Chain_Initialize_empty( ready_chain );
[beab7329]126    _Priority_bit_map_Remove( bit_map, &ready_queue->Priority_map );
[108c4b0]127  } else {
[647b95d]128    _Chain_Extract_unprotected( node );
[108c4b0]129  }
[0faa9dad]130}
131
[494c2e3]132RTEMS_INLINE_ROUTINE void _Scheduler_priority_Extract_body(
[e1598a6]133  const Scheduler_Control *scheduler,
134  Thread_Control          *the_thread
[494c2e3]135)
136{
[e1598a6]137  Scheduler_priority_Context *context =
138    _Scheduler_priority_Get_context( scheduler );
[beab7329]139  Scheduler_priority_Node *node = _Scheduler_priority_Node_get( the_thread );
[494c2e3]140
[beab7329]141  _Scheduler_priority_Ready_queue_extract(
[647b95d]142    &the_thread->Object.Node,
[beab7329]143    &node->Ready_queue,
144    &context->Bit_map
145  );
[494c2e3]146}
147
[010192d]148/**
[647b95d]149 * @brief Return a pointer to the first node.
[0faa9dad]150 *
[647b95d]151 * This routines returns a pointer to the first node on @a ready_queues.
[0faa9dad]152 *
[494c2e3]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.
[0faa9dad]155 *
[647b95d]156 * @return This method returns the first node.
[0faa9dad]157 */
[647b95d]158RTEMS_INLINE_ROUTINE Chain_Node *_Scheduler_priority_Ready_queue_first(
[494c2e3]159  Priority_bit_map_Control *bit_map,
160  Chain_Control            *ready_queues
[0faa9dad]161)
162{
[494c2e3]163  Priority_Control index = _Priority_bit_map_Get_highest( bit_map );
[0faa9dad]164
[647b95d]165  return _Chain_First( &ready_queues[ index ] );
[0faa9dad]166}
167
[010192d]168/**
[d8134178]169 * @brief Scheduling decision logic.
[0faa9dad]170 *
[d8134178]171 * This kernel routine implements scheduling decision logic
172 * for priority-based scheduling.
[0faa9dad]173 */
[e5ca54c9]174RTEMS_INLINE_ROUTINE void _Scheduler_priority_Schedule_body(
[e1598a6]175  const Scheduler_Control *scheduler,
176  Thread_Control          *the_thread,
177  bool                     force_dispatch
[e5ca54c9]178)
[0faa9dad]179{
[e1598a6]180  Scheduler_priority_Context *context =
181    _Scheduler_priority_Get_context( scheduler );
[647b95d]182  Thread_Control *heir = (Thread_Control *)
183    _Scheduler_priority_Ready_queue_first(
184      &context->Bit_map,
185      &context->Ready[ 0 ]
186    );
[e5ca54c9]187
[24934e36]188  ( void ) the_thread;
[e5ca54c9]189
190  _Scheduler_Update_heir( heir, force_dispatch );
[0faa9dad]191}
192
[beab7329]193/**
[f39f667a]194 * @brief Updates the specified ready queue data according to the new priority
195 * value.
[beab7329]196 *
197 * @param[in] ready_queue The ready queue.
[f39f667a]198 * @param[in] new_priority The new priority.
[beab7329]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 */
202RTEMS_INLINE_ROUTINE void _Scheduler_priority_Ready_queue_update(
203  Scheduler_priority_Ready_queue *ready_queue,
[f39f667a]204  Priority_Control                new_priority,
[beab7329]205  Priority_bit_map_Control       *bit_map,
206  Chain_Control                  *ready_queues
[99b3505]207)
208{
[f39f667a]209  ready_queue->ready_chain = &ready_queues[ new_priority ];
[99b3505]210
211  _Priority_bit_map_Initialize_information(
[494c2e3]212    bit_map,
[beab7329]213    &ready_queue->Priority_map,
[f39f667a]214    new_priority
[99b3505]215  );
216}
217
[ac9d2ecc]218/**
[d8134178]219 * @brief Priority comparison.
[ac9d2ecc]220 *
[d8134178]221 * This routine implements priority comparison for priority-based
222 * scheduling.
[ac9d2ecc]223 *
[d8134178]224 * @return >0 for higher priority, 0 for equal and <0 for lower priority.
[ac9d2ecc]225 */
226RTEMS_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
[d8134178]235/** @} */
[0faa9dad]236
[f068384e]237#ifdef __cplusplus
238}
239#endif
240
[0faa9dad]241#endif
242/* end of include file */
Note: See TracBrowser for help on using the repository browser.