[0faa9dad] | 1 | /** |
---|
| 2 | * @file rtems/score/scheduler.h |
---|
| 3 | * |
---|
[1dbbc0c] | 4 | * @brief Constants and Structures Associated with the Scheduler |
---|
| 5 | * |
---|
[0faa9dad] | 6 | * This include file contains all the constants and structures associated |
---|
| 7 | * with the scheduler. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | /* |
---|
| 11 | * Copyright (C) 2010 Gedare Bloom. |
---|
[010192d] | 12 | * Copyright (C) 2011 On-Line Applications Research Corporation (OAR). |
---|
[0faa9dad] | 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.com/license/LICENSE. |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #ifndef _RTEMS_SCORE_SCHEDULER_H |
---|
| 20 | #define _RTEMS_SCORE_SCHEDULER_H |
---|
| 21 | |
---|
[215f4014] | 22 | #include <rtems/score/percpu.h> |
---|
| 23 | #include <rtems/score/chain.h> |
---|
| 24 | #include <rtems/score/priority.h> |
---|
| 25 | #include <rtems/score/prioritybitmap.h> |
---|
| 26 | |
---|
| 27 | #ifdef __cplusplus |
---|
| 28 | extern "C" { |
---|
| 29 | #endif |
---|
| 30 | |
---|
[0faa9dad] | 31 | /** |
---|
| 32 | * @defgroup ScoreScheduler Scheduler Handler |
---|
| 33 | * |
---|
[d8cd045c] | 34 | * @ingroup Score |
---|
| 35 | * |
---|
[0faa9dad] | 36 | * This handler encapsulates functionality related to managing sets of threads |
---|
| 37 | * that are ready for execution. |
---|
| 38 | */ |
---|
| 39 | /**@{*/ |
---|
| 40 | |
---|
| 41 | /** |
---|
[215f4014] | 42 | * function jump table that holds pointers to the functions that |
---|
[0faa9dad] | 43 | * implement specific schedulers. |
---|
| 44 | */ |
---|
| 45 | typedef struct { |
---|
| 46 | /** Implements the scheduling decision logic (policy). */ |
---|
[010192d] | 47 | void ( *initialize )(void); |
---|
| 48 | |
---|
| 49 | /** Implements the scheduling decision logic (policy). */ |
---|
| 50 | void ( *schedule )(void); |
---|
[0faa9dad] | 51 | |
---|
[6eba7c85] | 52 | /** |
---|
| 53 | * @brief Voluntarily yields the processor per the scheduling policy. |
---|
| 54 | * |
---|
| 55 | * @see _Scheduler_Yield(). |
---|
| 56 | */ |
---|
| 57 | void ( *yield )( Thread_Control *thread ); |
---|
[0faa9dad] | 58 | |
---|
| 59 | /** Removes the given thread from scheduling decisions. */ |
---|
[010192d] | 60 | void ( *block )(Thread_Control *); |
---|
[0faa9dad] | 61 | |
---|
| 62 | /** Adds the given thread to scheduling decisions. */ |
---|
[010192d] | 63 | void ( *unblock )(Thread_Control *); |
---|
[0faa9dad] | 64 | |
---|
| 65 | /** allocates the scheduler field of the given thread */ |
---|
[108c4b0] | 66 | void * ( *allocate )(Thread_Control *); |
---|
[0faa9dad] | 67 | |
---|
| 68 | /** frees the scheduler field of the given thread */ |
---|
[108c4b0] | 69 | void ( *free )(Thread_Control *); |
---|
[215f4014] | 70 | |
---|
| 71 | /** updates the scheduler field of the given thread -- primarily used |
---|
[0faa9dad] | 72 | * when changing the thread's priority. */ |
---|
[108c4b0] | 73 | void ( *update )(Thread_Control *); |
---|
| 74 | |
---|
| 75 | /** enqueue a thread as the last of its priority group */ |
---|
| 76 | void ( *enqueue )(Thread_Control *); |
---|
| 77 | |
---|
| 78 | /** enqueue a thread as the first of its priority group */ |
---|
| 79 | void ( *enqueue_first )(Thread_Control *); |
---|
| 80 | |
---|
| 81 | /** extract a thread from the ready set */ |
---|
| 82 | void ( *extract )(Thread_Control *); |
---|
[3203e09] | 83 | |
---|
[ac9d2ecc] | 84 | /** |
---|
| 85 | * Compares two priorities (returns >0 for higher priority, 0 for equal |
---|
| 86 | * and <0 for lower priority). |
---|
| 87 | */ |
---|
| 88 | int ( *priority_compare )(Priority_Control, Priority_Control); |
---|
| 89 | |
---|
| 90 | /** This routine is called upon release of a new job. */ |
---|
| 91 | void ( *release_job ) (Thread_Control *, uint32_t); |
---|
| 92 | |
---|
[3203e09] | 93 | /** perform scheduler update actions required at each clock tick */ |
---|
| 94 | void ( *tick )(void); |
---|
[ac9d2ecc] | 95 | |
---|
[1ccb64e1] | 96 | /** |
---|
| 97 | * @brief Starts the idle thread for a particular processor. |
---|
| 98 | * |
---|
| 99 | * @see _Scheduler_Start_idle(). |
---|
| 100 | */ |
---|
| 101 | void ( *start_idle )( Thread_Control *thread, Per_CPU_Control *processor ); |
---|
[0faa9dad] | 102 | } Scheduler_Operations; |
---|
| 103 | |
---|
| 104 | /** |
---|
| 105 | * This is the structure used to manage the scheduler. |
---|
| 106 | */ |
---|
[108c4b0] | 107 | typedef struct { |
---|
[215f4014] | 108 | /** |
---|
[108c4b0] | 109 | * This points to the data structure used to manage the ready set of |
---|
| 110 | * tasks. The pointer varies based upon the type of |
---|
[0faa9dad] | 111 | * ready queue required by the scheduler. |
---|
| 112 | */ |
---|
[108c4b0] | 113 | void *information; |
---|
[0faa9dad] | 114 | |
---|
| 115 | /** The jump table for scheduler-specific functions */ |
---|
[108c4b0] | 116 | Scheduler_Operations Operations; |
---|
| 117 | } Scheduler_Control; |
---|
[0faa9dad] | 118 | |
---|
| 119 | /** |
---|
| 120 | * The _Scheduler holds the structures used to manage the |
---|
| 121 | * scheduler. |
---|
| 122 | * |
---|
| 123 | * @note Can we make this per-cpu? then _Scheduler will be a macro. |
---|
[010192d] | 124 | * |
---|
| 125 | * @note This is instantiated and initialized in confdefs.h. |
---|
[0faa9dad] | 126 | */ |
---|
[010192d] | 127 | extern Scheduler_Control _Scheduler; |
---|
[0faa9dad] | 128 | |
---|
[ac9d2ecc] | 129 | /** |
---|
| 130 | * Macro testing whether @a p1 has lower priority than @a p2 |
---|
| 131 | * in the intuitive sense of priority. |
---|
| 132 | */ |
---|
| 133 | #define _Scheduler_Is_priority_lower_than( _p1, _p2 ) \ |
---|
| 134 | (_Scheduler_Priority_compare(_p1,_p2) < 0) |
---|
| 135 | |
---|
| 136 | /** |
---|
| 137 | * Macro testing whether @a p1 has higher priority than @a p2 |
---|
| 138 | * in the intuitive sense of priority. |
---|
| 139 | */ |
---|
| 140 | #define _Scheduler_Is_priority_higher_than( _p1, _p2 ) \ |
---|
| 141 | (_Scheduler_Priority_compare(_p1,_p2) > 0) |
---|
| 142 | |
---|
[0faa9dad] | 143 | /** |
---|
[1dbbc0c] | 144 | * @brief Initializes the scheduler to the policy chosen by the user. |
---|
[8396c18e] | 145 | * |
---|
[215f4014] | 146 | * This routine initializes the scheduler to the policy chosen by the user |
---|
[0faa9dad] | 147 | * through confdefs, or to the priority scheduler with ready chains by |
---|
| 148 | * default. |
---|
| 149 | */ |
---|
| 150 | void _Scheduler_Handler_initialization( void ); |
---|
| 151 | |
---|
[a344308] | 152 | /** |
---|
| 153 | * @brief Performs tick operations depending on the CPU budget algorithm for |
---|
| 154 | * each executing thread. |
---|
| 155 | * |
---|
| 156 | * This routine is invoked as part of processing each clock tick. |
---|
| 157 | */ |
---|
| 158 | void _Scheduler_default_Tick( void ); |
---|
| 159 | |
---|
[1ccb64e1] | 160 | /** |
---|
| 161 | * @brief Unblocks the thread. |
---|
| 162 | * |
---|
| 163 | * @param[in/out] thread An idle thread. |
---|
| 164 | * @param[in] processor This parameter is unused. |
---|
| 165 | */ |
---|
| 166 | void _Scheduler_default_Start_idle( |
---|
| 167 | Thread_Control *thread, |
---|
| 168 | Per_CPU_Control *processor |
---|
| 169 | ); |
---|
| 170 | |
---|
[0faa9dad] | 171 | #ifndef __RTEMS_APPLICATION__ |
---|
| 172 | #include <rtems/score/scheduler.inl> |
---|
| 173 | #endif |
---|
| 174 | |
---|
[215f4014] | 175 | /**@}*/ |
---|
| 176 | |
---|
[0faa9dad] | 177 | #ifdef __cplusplus |
---|
| 178 | } |
---|
| 179 | #endif |
---|
| 180 | |
---|
| 181 | #endif |
---|
[a15eaaf] | 182 | /* end of include file */ |
---|