1 INTERFACE[sched_wfq || sched_fp_wfq]:
3 #include "member_offs.h"
7 struct L4_sched_param_wfq : public L4_sched_param
9 enum : Smword { Class = -2 };
14 template< typename E >
17 friend class Jdb_thread_list;
19 friend class Jdb_thread_list_policy;
22 E *current_sched() const { return _current_sched; }
23 void activate(E *s) { _current_sched = s; }
29 _e(sc)->_ready_link = &idle;
33 void enqueue(E *, bool is_current);
35 E *next_to_run() const;
38 void swap(unsigned a, unsigned b);
39 void heap_up(unsigned a);
40 void heap_down(unsigned a);
46 static typename E::Wfq_sc *_e(E *e) { return E::wfq_elem(e); }
49 template< typename IMPL >
50 class Sched_context_wfq
53 bool operator <= (Sched_context_wfq const &o) const
54 { return _impl()._dl <= o._impl()._dl; }
56 bool operator < (Sched_context_wfq const &o) const
57 { return _impl()._dl < o._impl()._dl; }
60 IMPL const &_impl() const { return static_cast<IMPL const &>(*this); }
61 IMPL &_impl() { return static_cast<IMPL &>(*this); }
65 // --------------------------------------------------------------------------
66 IMPLEMENTATION [sched_wfq || sched_fp_wfq]:
72 #include "std_macros.h"
78 Ready_queue_wfq<E>::next_to_run() const
84 _e(idle)->_dl = _e(_current_sched)->_dl;
92 Ready_queue_wfq<E>::swap(unsigned a, unsigned b)
94 _e(_heap[a])->_ready_link = &_heap[b];
95 _e(_heap[b])->_ready_link = &_heap[a];
104 Ready_queue_wfq<E>::heap_up(unsigned a)
108 unsigned p = (a-1)/2;
109 if (*_e(_heap[p]) < *_e(_heap[a]))
119 Ready_queue_wfq<E>::heap_down(unsigned a)
123 unsigned c1 = 2*a + 1;
124 unsigned c2 = 2*a + 2;
129 if (_cnt > c2 && *_e(_heap[c2]) <= *_e(_heap[c1]))
132 if (*_e(_heap[a]) <= *_e(_heap[c1]))
142 * Enqueue context in ready-list.
147 Ready_queue_wfq<E>::enqueue(E *i, bool /*is_current_sched**/)
149 assert_kdb(cpu_lock.test());
151 // Don't enqueue threads which are already enqueued
152 if (EXPECT_FALSE (i->in_ready_list()))
159 _e(i)->_ready_link = &h;
165 * Remove context from ready-list.
167 IMPLEMENT inline NEEDS ["cpu_lock.h", "kdb_ke.h", "std_macros.h"]
170 Ready_queue_wfq<E>::dequeue(E *i)
172 assert_kdb (cpu_lock.test());
174 // Don't dequeue threads which aren't enqueued
175 if (EXPECT_FALSE (!i->in_ready_list() || i == idle))
178 unsigned x = _e(i)->_ready_link - _heap;
182 _e(i)->_ready_link = 0;
188 _e(i)->_ready_link = 0;
192 * Enqueue context in ready-list.
197 Ready_queue_wfq<E>::requeue(E *i)
199 if (!i->in_ready_list())
202 heap_down(_e(i)->_ready_link - _heap);
206 PUBLIC template< typename E > inline
208 Ready_queue_wfq<E>::deblock_refill(E *sc)
211 if (EXPECT_TRUE(_current_sched != 0))
212 da = _e(_current_sched)->_dl;
214 if (_e(sc)->_dl >= da)
217 _e(sc)->_left += (da - _e(sc)->_dl) * _e(sc)->_w;
218 if (_e(sc)->_left > _e(sc)->_q)
219 _e(sc)->_left = _e(sc)->_q;