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 /// @param __rel_deadline__ in ticks, if a CBS is running, this option is ommited
16 /// @param flags Prepared for late unblock protocol
17 rtems_status_code edf_next_period(rtems_id period_id, uint32_t __rel_deadline__, uint8_t flags);
19 /// Changes scheduling policy from priorities to deadlines
20 rtems_status_code edf_deadline_init(rtems_name name, rtems_id *period_id);
22 /// Changes scheduling policy from deadlines to priorities
23 rtems_status_code edf_deadline_cancel(rtems_id period_id);
27 /// Pluggable scheduler callback functions
28 #define SCHEDULER_EDF_ENTRY_POINTS \
30 _Scheduler_edf_Initialize, /* initialize entry point */ \
31 _Scheduler_edf_Schedule, /* schedule entry point */ \
32 _Scheduler_edf_Yield, /* yield entry point */ \
33 _Scheduler_edf_Block, /* block entry point */ \
34 _Scheduler_edf_Unblock, /* unblock entry point */ \
35 _Scheduler_edf_Allocate, /* allocate entry point */ \
36 _Scheduler_edf_Free, /* free entry point */ \
37 _Scheduler_edf_Update, /* update entry point */ \
38 _Scheduler_edf_Enqueue, /* enqueue entry point */ \
39 _Scheduler_edf_Enqueue_first, /* enqueue_first entry point */ \
40 _Scheduler_edf_Extract, /* extract entry point */ \
41 _Scheduler_edf_Priority_compare /* compares two priorities */ \
47 * This routine initializes the priority scheduler.
49 void _Scheduler_edf_Initialize(void);
52 * This routine removes @a the_thread from the scheduling decision,
53 * that is, removes it from the ready queue. It performs
54 * any necessary scheduling operations including the selection of
57 * @param[in] the_thread is the thread to be blocked
59 void _Scheduler_edf_Block(
60 Thread_Control *the_thread
64 * This kernel routine sets the heir thread to be the next ready thread
65 * by invoking the_scheduler->ready_queue->operations->first().
67 void _Scheduler_edf_Schedule(void);
70 * This routine allocates @a the_thread->scheduler.
72 * @param[in] the_thread is the thread the scheduler is allocating
73 * management memory for
75 void * _Scheduler_edf_Allocate(
76 Thread_Control *the_thread
80 * This routine frees @a the_thread->scheduler.
82 * @param[in] the_thread is the thread whose scheduler specific information
83 * will be deallocated.
85 void _Scheduler_edf_Free(
86 Thread_Control *the_thread
90 * This routine updates @a the_thread->scheduler based on @a the_scheduler
91 * structures and thread state.
93 * @param[in] the_thread will have its scheduler specific information
96 void _Scheduler_edf_Update(
97 Thread_Control *the_thread
101 * This routine adds @a the_thread to the scheduling decision,
102 * that is, adds it to the ready queue and
103 * updates any appropriate scheduling variables, for example the heir thread.
105 * @param[in] the_thread will be unblocked
107 void _Scheduler_edf_Unblock(
108 Thread_Control *the_thread
112 * This routine is invoked when a thread wishes to voluntarily
113 * transfer control of the processor to another thread in the queue.
115 * This routine will remove the running THREAD from the ready queue
116 * and place it immediately at the rear of this chain. Reset timeslice
117 * and yield the processor functions both use this routine, therefore if
118 * reset is true and this is the only thread on the queue then the
119 * timeslice counter is reset. The heir THREAD will be updated if the
120 * running is also the currently the heir.
122 void _Scheduler_edf_Yield( void );
125 * This routine puts @a the_thread on to the priority-based ready queue.
127 * @param[in] the_thread will be enqueued at the TAIL of its priority.
129 void _Scheduler_edf_Enqueue(
130 Thread_Control *the_thread
134 * This routine puts @a the_thread to the head of the ready queue.
135 * For priority-based ready queues, the thread will be the first thread
136 * at its priority level.
138 * @param[in] the_thread will be enqueued at the HEAD of its priority.
140 void _Scheduler_edf_Enqueue_first(
141 Thread_Control *the_thread
145 * This routine removes a specific thread from the scheduler's set
148 * @param[in] the_thread will be extracted from the ready set.
150 void _Scheduler_edf_Extract(
151 Thread_Control *the_thread
155 * Compares absolute dedlines of threads while taking into account time overflow.
157 * @return 1 for p1 > p2; 0 for p1 == p2; -1 for p1 < p2
159 int _Scheduler_edf_Priority_compare (
164 #define edf_priority_is_lower(p1, p2) ( _Scheduler_edf_Priority_compare(p1, p2) == 1)
165 #define edf_priority_is_higher(p1, p2) ( _Scheduler_edf_Priority_compare(p1, p2) == -1)
166 #define edf_priority_is_equal(p1, p2) ( !_Scheduler_edf_Priority_compare(p1, p2) )
168 #endif /*_SCHEDULER_EDF_H*/