1 #ifndef _SCHEDULER_EDF_H
2 #define _SCHEDULER_EDF_H
4 #include <rtems/score/scheduler.h>
5 #include <rtems/score/chain.h>
6 #include <rtems/score/thread.h>
10 // keeps the ready queue for EDF
11 EDF_Chain_Control _Thread_Ready_EDF_chain;
13 /// This routine is called when a task starts to execute a new period or
15 void edf_next_period(void);
17 /// Changes scheduling policy from priorities to deadlines
18 void edf_deadline_init(uint32_t __rel_deadline__);
20 /// Changes scheduling policy from deadlines to priorities
21 void edf_deadline_cancel(void);
26 /// Pluggable scheduler callback functions
27 #define SCHEDULER_EDF_ENTRY_POINTS \
29 _Scheduler_edf_Initialize, /* initialize entry point */ \
30 _Scheduler_edf_Schedule, /* schedule entry point */ \
31 _Scheduler_edf_Yield, /* yield entry point */ \
32 _Scheduler_edf_Block, /* block entry point */ \
33 _Scheduler_edf_Unblock, /* unblock entry point */ \
34 _Scheduler_edf_Allocate, /* allocate entry point */ \
35 _Scheduler_edf_Free, /* free entry point */ \
36 _Scheduler_edf_Update, /* update entry point */ \
37 _Scheduler_edf_Enqueue, /* enqueue entry point */ \
38 _Scheduler_edf_Enqueue_first, /* enqueue_first entry point */ \
39 _Scheduler_edf_Extract, /* extract entry point */ \
40 _Scheduler_edf_Priority_compare /* compares two priorities */ \
46 * This routine initializes the priority scheduler.
48 void _Scheduler_edf_Initialize(void);
51 * This routine removes @a the_thread from the scheduling decision,
52 * that is, removes it from the ready queue. It performs
53 * any necessary scheduling operations including the selection of
56 * @param[in] the_thread is the thread to be blocked
58 void _Scheduler_edf_Block(
59 Thread_Control *the_thread
63 * This kernel routine sets the heir thread to be the next ready thread
64 * by invoking the_scheduler->ready_queue->operations->first().
66 void _Scheduler_edf_Schedule(void);
69 * This routine allocates @a the_thread->scheduler.
71 * @param[in] the_thread is the thread the scheduler is allocating
72 * management memory for
74 void * _Scheduler_edf_Allocate(
75 Thread_Control *the_thread
79 * This routine frees @a the_thread->scheduler.
81 * @param[in] the_thread is the thread whose scheduler specific information
82 * will be deallocated.
84 void _Scheduler_edf_Free(
85 Thread_Control *the_thread
89 * This routine updates @a the_thread->scheduler based on @a the_scheduler
90 * structures and thread state.
92 * @param[in] the_thread will have its scheduler specific information
95 void _Scheduler_edf_Update(
96 Thread_Control *the_thread
100 * This routine adds @a the_thread to the scheduling decision,
101 * that is, adds it to the ready queue and
102 * updates any appropriate scheduling variables, for example the heir thread.
104 * @param[in] the_thread will be unblocked
106 void _Scheduler_edf_Unblock(
107 Thread_Control *the_thread
111 * This routine is invoked when a thread wishes to voluntarily
112 * transfer control of the processor to another thread in the queue.
114 * This routine will remove the running THREAD from the ready queue
115 * and place it immediately at the rear of this chain. Reset timeslice
116 * and yield the processor functions both use this routine, therefore if
117 * reset is true and this is the only thread on the queue then the
118 * timeslice counter is reset. The heir THREAD will be updated if the
119 * running is also the currently the heir.
121 void _Scheduler_edf_Yield( void );
124 * This routine puts @a the_thread on to the priority-based ready queue.
126 * @param[in] the_thread will be enqueued at the TAIL of its priority.
128 void _Scheduler_edf_Enqueue(
129 Thread_Control *the_thread
133 * This routine puts @a the_thread to the head of the ready queue.
134 * For priority-based ready queues, the thread will be the first thread
135 * at its priority level.
137 * @param[in] the_thread will be enqueued at the HEAD of its priority.
139 void _Scheduler_edf_Enqueue_first(
140 Thread_Control *the_thread
144 * This routine removes a specific thread from the scheduler's set
147 * @param[in] the_thread will be extracted from the ready set.
149 void _Scheduler_edf_Extract(
150 Thread_Control *the_thread
154 * Compares absolute dedlines of threads while taking into account time overflow.
156 * @return 1 for p1 > p2; 0 for p1 == p2; -1 for p1 < p2
158 inline int _Scheduler_edf_Priority_compare (
163 #define edf_priority_is_lower(p1, p2) ( _Scheduler_edf_Priority_compare(p1, p2) == 1)
164 #define edf_priority_is_higher(p1, p2) ( _Scheduler_edf_Priority_compare(p1, p2) == -1)
165 #define edf_priority_is_equal(p1, p2) ( !_Scheduler_edf_Priority_compare(p1, p2) )
167 #endif /*_SCHEDULER_EDF_H*/