]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/sched_context-fixed_prio.cpp
update
[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 <dlist>
9 #include "member_offs.h"
10 #include "types.h"
11 #include "globals.h"
12 #include "ready_queue_fp.h"
13
14
15 class Sched_context : public cxx::D_list_item
16 {
17   MEMBER_OFFSET();
18   friend class Jdb_list_timeouts;
19   friend class Jdb_thread_list;
20
21   template<typename T>
22   friend struct Jdb_thread_list_policy;
23
24 public:
25   typedef cxx::Sd_list<Sched_context> Fp_list;
26
27   class Ready_queue : public Ready_queue_fp<Sched_context>
28   {
29   public:
30     Context *schedule_in_progress;
31     void activate(Sched_context *s)
32     { _current_sched = s; }
33     Sched_context *current_sched() const { return _current_sched; }
34
35   private:
36     Sched_context *_current_sched;
37   };
38
39   Context *context() const { return context_of(this); }
40
41 private:
42   unsigned short _prio;
43   Unsigned64 _quantum;
44   Unsigned64 _left;
45
46   friend class Ready_queue_fp<Sched_context>;
47 };
48
49
50 IMPLEMENTATION [sched_fixed_prio]:
51
52 #include <cassert>
53 #include "cpu_lock.h"
54 #include "kdb_ke.h"
55 #include "std_macros.h"
56 #include "config.h"
57
58
59 /**
60  * Constructor
61  */
62 PUBLIC
63 Sched_context::Sched_context()
64 : _prio(Config::Default_prio),
65   _quantum(Config::Default_time_slice),
66   _left(Config::Default_time_slice)
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 Fp_list::in_list(this);
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