]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/sched_context-fixed_prio.cpp
03eb5a23227c43ef32f5c1dcd970430825ebde8f
[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 : _prio(Config::boot_prio),
64   _quantum(Config::default_time_slice),
65   _left(Config::default_time_slice)
66 {}
67
68
69
70 /**
71  * Return priority of Sched_context
72  */
73 PUBLIC inline
74 unsigned short
75 Sched_context::prio() const
76 {
77   return _prio;
78 }
79
80 /**
81  * Set priority of Sched_context
82  */
83 PUBLIC inline
84 void
85 Sched_context::set_prio (unsigned short const prio)
86 {
87   _prio = prio;
88 }
89
90 /**
91  * Return full time quantum of Sched_context
92  */
93 PUBLIC inline
94 Unsigned64
95 Sched_context::quantum() const
96 {
97   return _quantum;
98 }
99
100 /**
101  * Set full time quantum of Sched_context
102  */
103 PUBLIC inline
104 void
105 Sched_context::set_quantum (Unsigned64 const quantum)
106 {
107   _quantum = quantum;
108 }
109
110 /**
111  * Return remaining time quantum of Sched_context
112  */
113 PUBLIC inline
114 Unsigned64
115 Sched_context::left() const
116 {
117   return _left;
118 }
119
120 PUBLIC inline NEEDS[Sched_context::set_left, Sched_context::quantum]
121 void
122 Sched_context::replenish()
123 { set_left(quantum()); }
124
125 /**
126  * Set remaining time quantum of Sched_context
127  */
128 PUBLIC inline
129 void
130 Sched_context::set_left (Unsigned64 const left)
131 {
132   _left = left;
133 }
134
135
136 /**
137  * Check if Context is in ready-list.
138  * @return 1 if thread is in ready-list, 0 otherwise
139  */
140 PUBLIC inline
141 Mword
142 Sched_context::in_ready_list() const
143 {
144   return _ready_next != 0;
145 }
146
147 /**
148  * Remove context from ready-list.
149  */
150 PUBLIC inline NEEDS ["cpu_lock.h", "kdb_ke.h", "std_macros.h"]
151 void
152 Sched_context::ready_dequeue()
153 {
154   assert_kdb (cpu_lock.test());
155
156   // Don't dequeue threads which aren't enqueued
157   if (EXPECT_FALSE (!in_ready_list()))
158     return;
159
160   unsigned cpu = current_cpu();
161
162   _ready_q.cpu(cpu).dequeue(this);
163 }
164
165 /**
166  * Enqueue context in ready-list.
167  */
168 PUBLIC inline
169 void
170 Sched_context::ready_enqueue(unsigned cpu)
171 {
172   assert_kdb(cpu_lock.test());
173
174   // Don't enqueue threads which are already enqueued
175   if (EXPECT_FALSE (in_ready_list()))
176     return;
177
178   Ready_queue &rq = _ready_q.cpu(cpu);
179
180   rq.enqueue(this, this == rq.current_sched());
181 }
182
183 PUBLIC inline
184 void
185 Sched_context::requeue(unsigned cpu)
186 {
187   _ready_q.cpu(cpu).requeue(this);
188 }
189
190 /**
191  * Return if there is currently a schedule() in progress
192  */
193 PUBLIC static inline
194 Context *
195 Sched_context::schedule_in_progress(unsigned cpu)
196 {
197   return _ready_q.cpu(cpu).schedule_in_progress;
198 }
199
200 PUBLIC static inline
201 void
202 Sched_context::reset_schedule_in_progress(unsigned cpu)
203 { _ready_q.cpu(cpu).schedule_in_progress = 0; }
204
205
206 /**
207  * Invalidate (expire) currently active global Sched_context.
208  */
209 PUBLIC static inline
210 void
211 Sched_context::invalidate_sched(unsigned cpu)
212 {
213   _ready_q.cpu(cpu).activate(0);
214 }
215
216 PUBLIC inline
217 bool
218 Sched_context::dominates(Sched_context *sc)
219 { return prio() > sc->prio(); }
220
221 PUBLIC inline
222 void
223 Sched_context::deblock_refill(unsigned)
224 {}
225