]> rtime.felk.cvut.cz Git - rtems-pluggable-edf.git/blob - src/edf/scheduler_edf.h
4b253f8a8f95b5bad456bfa54b8643c0a646bbc0
[rtems-pluggable-edf.git] / src / edf / scheduler_edf.h
1 #ifndef _SCHEDULER_EDF_H
2 #define _SCHEDULER_EDF_H
3
4 #include <rtems/score/scheduler.h>
5 #include <rtems/score/chain.h>
6 #include <rtems/score/thread.h>
7 #include "edf_types.h"
8 #include "rbtree.h"
9
10 // keeps the ready queue for EDF
11 EDF_Chain_Control _Thread_Ready_EDF_chain;
12
13 /// This routine is called when a task starts to execute a new period or
14 /// a first period.
15 void edf_next_period(void);
16
17 /// Changes scheduling policy from priorities to deadlines
18 void edf_deadline_init(uint32_t __rel_deadline__);
19
20 /// Changes scheduling policy from deadlines to priorities
21 void edf_deadline_cancel(void);
22
23
24
25
26 /// Pluggable scheduler callback functions
27 #define SCHEDULER_EDF_ENTRY_POINTS \
28         { \
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 */ \
41         }
42
43
44
45 /**
46  * This routine initializes the priority scheduler.
47  */
48 void _Scheduler_edf_Initialize(void);
49
50 /**
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
54  *  a new heir thread.
55  *
56  *  @param[in] the_thread is the thread to be blocked
57  */
58 void _Scheduler_edf_Block( 
59   Thread_Control    *the_thread 
60 );
61
62 /**
63  *  This kernel routine sets the heir thread to be the next ready thread 
64  *  by invoking the_scheduler->ready_queue->operations->first().
65  */
66 void _Scheduler_edf_Schedule(void);
67
68 /**
69  *  This routine allocates @a the_thread->scheduler.
70  *
71  *  @param[in] the_thread is the thread the scheduler is allocating
72  *             management memory for
73  */
74 void * _Scheduler_edf_Allocate(
75   Thread_Control      *the_thread
76 );
77
78 /**
79  *  This routine frees @a the_thread->scheduler.
80  *
81  *  @param[in] the_thread is the thread whose scheduler specific information
82  *             will be deallocated.
83  */
84 void _Scheduler_edf_Free(
85   Thread_Control      *the_thread
86 );
87
88 /**
89  *  This routine updates @a the_thread->scheduler based on @a the_scheduler 
90  *  structures and thread state.
91  *
92  *  @param[in] the_thread will have its scheduler specific information
93  *             structure updated.
94  */
95 void _Scheduler_edf_Update(
96   Thread_Control      *the_thread
97 );
98
99 /**
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.
103  *
104  *  @param[in] the_thread will be unblocked
105  */
106 void _Scheduler_edf_Unblock(
107   Thread_Control    *the_thread 
108 );
109
110 /**
111  *  This routine is invoked when a thread wishes to voluntarily
112  *  transfer control of the processor to another thread in the queue.
113  *
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.
120  */
121 void _Scheduler_edf_Yield( void );
122
123 /**
124  *  This routine puts @a the_thread on to the priority-based ready queue.
125  *
126  *  @param[in] the_thread will be enqueued at the TAIL of its priority.
127  */
128 void _Scheduler_edf_Enqueue(
129   Thread_Control    *the_thread
130 );
131
132 /**
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.
136  *
137  *  @param[in] the_thread will be enqueued at the HEAD of its priority.
138  */
139 void _Scheduler_edf_Enqueue_first(
140   Thread_Control    *the_thread
141 );
142
143 /**
144  *  This routine removes a specific thread from the scheduler's set
145  *  of ready threads.
146  *
147  *  @param[in] the_thread will be extracted from the ready set.
148  */
149 void _Scheduler_edf_Extract(
150   Thread_Control     *the_thread
151 );
152
153 /**
154  * Compares absolute dedlines of threads while taking into account time overflow.
155  * Deadline is later.
156  * @return 1 for p1 > p2; 0 for p1 == p2; -1 for p1 < p2
157  */
158 inline int _Scheduler_edf_Priority_compare (
159   Priority_Control p1, 
160   Priority_Control p2
161 );
162
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) )
166
167 #endif /*_SCHEDULER_EDF_H*/