]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/sched_context-fixed_prio.cpp
318aebff1fd6923e6b4af602f07fc3b57f50a138
[l4.git] / kernel / fiasco / src / kern / sched_context-fixed_prio.cpp
1
2 /*
3  * Timeslice infrastructure
4  */
5
6 INTERFACE [sched_fixed_prio]:
7
8 #include "member_offs.h"
9 #include "types.h"
10 #include "globals.h"
11 #include "ready_queue_fp.h"
12
13
14 class Sched_context
15 {
16   MEMBER_OFFSET();
17   friend class Jdb_list_timeouts;
18   friend class Jdb_thread_list;
19
20 public:
21
22   class Ready_queue : public Ready_queue_fp<Sched_context>
23   {
24   public:
25     Context *schedule_in_progress;
26     void activate(Sched_context *s)
27     { _current_sched = s; }
28     Sched_context *current_sched() const { return _current_sched; }
29
30   private:
31     Sched_context *_current_sched;
32   };
33
34   Context *context() const { return context_of(this); }
35
36 private:
37   static Sched_context *fp_elem(Sched_context *x) { return x; }
38
39   Sched_context *_ready_next;
40   Sched_context *_ready_prev;
41   unsigned short _prio;
42   Unsigned64 _quantum;
43   Unsigned64 _left;
44
45   friend class Ready_queue_fp<Sched_context>;
46 };
47
48
49 IMPLEMENTATION [sched_fixed_prio]:
50
51 #include <cassert>
52 #include "cpu_lock.h"
53 #include "kdb_ke.h"
54 #include "std_macros.h"
55 #include "config.h"
56
57
58 /**
59  * Constructor
60  */
61 PUBLIC
62 Sched_context::Sched_context()
63 : _ready_next(0),
64   _prio(Config::boot_prio),
65   _quantum(Config::default_time_slice),
66   _left(Config::default_time_slice)
67 {}
68
69
70
71 /**
72  * Return priority of Sched_context
73  */
74 PUBLIC inline
75 unsigned short
76 Sched_context::prio() const
77 {
78   return _prio;
79 }
80
81 /**
82  * Set priority of Sched_context
83  */
84 PUBLIC inline
85 void
86 Sched_context::set_prio (unsigned short const prio)
87 {
88   _prio = prio;
89 }
90
91 /**
92  * Return full time quantum of Sched_context
93  */
94 PUBLIC inline
95 Unsigned64
96 Sched_context::quantum() const
97 {
98   return _quantum;
99 }
100
101 /**
102  * Set full time quantum of Sched_context
103  */
104 PUBLIC inline
105 void
106 Sched_context::set_quantum (Unsigned64 const quantum)
107 {
108   _quantum = quantum;
109 }
110
111 /**
112  * Return remaining time quantum of Sched_context
113  */
114 PUBLIC inline
115 Unsigned64
116 Sched_context::left() const
117 {
118   return _left;
119 }
120
121 PUBLIC inline NEEDS[Sched_context::set_left, Sched_context::quantum]
122 void
123 Sched_context::replenish()
124 { set_left(quantum()); }
125
126 /**
127  * Set remaining time quantum of Sched_context
128  */
129 PUBLIC inline
130 void
131 Sched_context::set_left (Unsigned64 const left)
132 {
133   _left = left;
134 }
135
136
137 /**
138  * Check if Context is in ready-list.
139  * @return 1 if thread is in ready-list, 0 otherwise
140  */
141 PUBLIC inline
142 Mword
143 Sched_context::in_ready_list() const
144 {
145   return _ready_next != 0;
146 }
147
148 /**
149  * Remove context from ready-list.
150  */
151 PUBLIC inline NEEDS ["cpu_lock.h", "kdb_ke.h", "std_macros.h"]
152 void
153 Sched_context::ready_dequeue()
154 {
155   assert_kdb (cpu_lock.test());
156
157   // Don't dequeue threads which aren't enqueued
158   if (EXPECT_FALSE (!in_ready_list()))
159     return;
160
161   unsigned cpu = current_cpu();
162
163   _ready_q.cpu(cpu).dequeue(this);
164 }
165
166 /**
167  * Enqueue context in ready-list.
168  */
169 PUBLIC inline
170 void
171 Sched_context::ready_enqueue(unsigned cpu)
172 {
173   assert_kdb(cpu_lock.test());
174
175   // Don't enqueue threads which are already enqueued
176   if (EXPECT_FALSE (in_ready_list()))
177     return;
178
179   Ready_queue &rq = _ready_q.cpu(cpu);
180
181   rq.enqueue(this, this == rq.current_sched());
182 }
183
184 PUBLIC inline
185 void
186 Sched_context::requeue(unsigned cpu)
187 {
188   _ready_q.cpu(cpu).requeue(this);
189 }
190
191 /**
192  * Return if there is currently a schedule() in progress
193  */
194 PUBLIC static inline
195 Context *
196 Sched_context::schedule_in_progress(unsigned cpu)
197 {
198   return _ready_q.cpu(cpu).schedule_in_progress;
199 }
200
201 PUBLIC static inline
202 void
203 Sched_context::reset_schedule_in_progress(unsigned cpu)
204 { _ready_q.cpu(cpu).schedule_in_progress = 0; }
205
206
207 /**
208  * Invalidate (expire) currently active global Sched_context.
209  */
210 PUBLIC static inline
211 void
212 Sched_context::invalidate_sched(unsigned cpu)
213 {
214   _ready_q.cpu(cpu).activate(0);
215 }
216
217 PUBLIC inline
218 bool
219 Sched_context::dominates(Sched_context *sc)
220 { return prio() > sc->prio(); }
221
222 PUBLIC inline
223 void
224 Sched_context::deblock_refill(unsigned)
225 {}
226