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