]> rtime.felk.cvut.cz Git - l4.git/blobdiff - kernel/fiasco/src/kern/ready_queue_wfq.cpp
update
[l4.git] / kernel / fiasco / src / kern / ready_queue_wfq.cpp
index 5459a21a66e72dbaa8a678df292d89fca30453e8..609b96ff362743a654d99a9802c3e9b8d040e02b 100644 (file)
@@ -4,6 +4,13 @@ INTERFACE[sched_wfq || sched_fp_wfq]:
 #include "types.h"
 #include "globals.h"
 
+struct L4_sched_param_wfq : public L4_sched_param
+{
+  enum : Smword { Class = -2 };
+  Mword quantum;
+  Mword weight;
+};
+
 template< typename E >
 class Ready_queue_wfq
 {
@@ -19,11 +26,11 @@ public:
   void set_idle(E *sc)
   {
     idle = sc;
-    E::wfq_elem(sc)->_ready_link = &idle;
-    E::wfq_elem(sc)->_idle = 1;
+    _e(sc)->_ready_link = &idle;
+    _e(sc)->_idle = 1;
   }
 
-  void enqueue(E *);
+  void enqueue(E *, bool is_current);
   void dequeue(E *);
   E *next_to_run() const;
 
@@ -35,6 +42,23 @@ private:
   E *_current_sched;
   unsigned _cnt;
   E *_heap[1024];
+
+  static typename E::Wfq_sc *_e(E *e) { return E::wfq_elem(e); }
+};
+
+template< typename IMPL >
+class Sched_context_wfq
+{
+public:
+  bool operator <= (Sched_context_wfq const &o) const
+  { return _impl()._dl <= o._impl()._dl; }
+
+  bool operator < (Sched_context_wfq const &o) const
+  { return _impl()._dl < o._impl()._dl; }
+
+private:
+  IMPL const &_impl() const { return static_cast<IMPL const &>(*this); }
+  IMPL &_impl() { return static_cast<IMPL &>(*this); }
 };
 
 
@@ -57,7 +81,7 @@ Ready_queue_wfq<E>::next_to_run() const
     return _heap[0];
 
   if (_current_sched)
-    E::wfq_elem(idle)->_dl = E::wfq_elem(_current_sched)->_dl;
+    _e(idle)->_dl = _e(_current_sched)->_dl;
 
   return idle;
 }
@@ -67,8 +91,8 @@ template<typename E>
 void
 Ready_queue_wfq<E>::swap(unsigned a, unsigned b)
 {
-  E::wfq_elem(_heap[a])->_ready_link = &_heap[b];
-  E::wfq_elem(_heap[b])->_ready_link = &_heap[a];
+  _e(_heap[a])->_ready_link = &_heap[b];
+  _e(_heap[b])->_ready_link = &_heap[a];
   E *s = _heap[a];
   _heap[a] = _heap[b];
   _heap[b] = s;
@@ -82,7 +106,7 @@ Ready_queue_wfq<E>::heap_up(unsigned a)
   for (;a > 0;)
     {
       unsigned p = (a-1)/2;
-      if (*E::wfq_elem(_heap[p]) < *E::wfq_elem(_heap[a]))
+      if (*_e(_heap[p]) < *_e(_heap[a]))
        return;
       swap(p, a);
       a = p;
@@ -102,10 +126,10 @@ Ready_queue_wfq<E>::heap_down(unsigned a)
       if (_cnt <= c1)
        return;
 
-      if (_cnt > c2 && *E::wfq_elem(_heap[c2]) <= *E::wfq_elem(_heap[c1]))
+      if (_cnt > c2 && *_e(_heap[c2]) <= *_e(_heap[c1]))
        c1 = c2;
 
-      if (*E::wfq_elem(_heap[a]) <= *E::wfq_elem(_heap[c1]))
+      if (*_e(_heap[a]) <= *_e(_heap[c1]))
        return;
 
       swap(c1, a);
@@ -120,7 +144,7 @@ Ready_queue_wfq<E>::heap_down(unsigned a)
 IMPLEMENT
 template<typename E>
 void
-Ready_queue_wfq<E>::enqueue(E *i)
+Ready_queue_wfq<E>::enqueue(E *i, bool /*is_current_sched**/)
 {
   assert_kdb(cpu_lock.test());
 
@@ -132,7 +156,7 @@ Ready_queue_wfq<E>::enqueue(E *i)
 
   E *&h = _heap[n];
   h = i;
-  E::wfq_elem(i)->_ready_link = &h;
+  _e(i)->_ready_link = &h;
 
   heap_up(n);
 }
@@ -151,17 +175,17 @@ Ready_queue_wfq<E>::dequeue(E *i)
   if (EXPECT_FALSE (!i->in_ready_list() || i == idle))
     return;
 
-  unsigned x = E::wfq_elem(i)->_ready_link - _heap;
+  unsigned x = _e(i)->_ready_link - _heap;
 
   if (x == --_cnt)
     {
-      E::wfq_elem(i)->_ready_link = 0;
+      _e(i)->_ready_link = 0;
       return;
     }
 
   swap(x, _cnt);
   heap_down(x);
-  E::wfq_elem(i)->_ready_link = 0;
+  _e(i)->_ready_link = 0;
 }
 
 /**
@@ -173,8 +197,26 @@ void
 Ready_queue_wfq<E>::requeue(E *i)
 {
   if (!i->in_ready_list())
-    enqueue(i);
+    enqueue(i, false);
+
+  heap_down(_e(i)->_ready_link - _heap);
+}
+
+
+PUBLIC template< typename E > inline
+void
+Ready_queue_wfq<E>::deblock_refill(E *sc)
+{
+  Unsigned64 da = 0;
+  if (EXPECT_TRUE(_current_sched != 0))
+    da = _e(_current_sched)->_dl;
+
+  if (_e(sc)->_dl >= da)
+    return;
 
-  heap_down(E::wfq_elem(i)->_ready_link - _heap);
+  _e(sc)->_left += (da - _e(sc)->_dl) * _e(sc)->_w;
+  if (_e(sc)->_left > _e(sc)->_q)
+    _e(sc)->_left = _e(sc)->_q;
+  _e(sc)->_dl = da;
 }