]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ready_queue_fp.cpp
update
[l4.git] / kernel / fiasco / src / kern / ready_queue_fp.cpp
1 INTERFACE [sched_fixed_prio || sched_fp_wfq]:
2
3 #include "config.h"
4 #include <cxx/dlist>
5 #include "member_offs.h"
6 #include "types.h"
7 #include "globals.h"
8
9
10 struct L4_sched_param_fixed_prio : public L4_sched_param
11 {
12   enum : Smword { Class = -1 };
13   Mword quantum;
14   unsigned short prio;
15 };
16
17 template<typename E>
18 class Ready_queue_fp
19 {
20   friend class Jdb_thread_list;
21   template<typename T>
22   friend struct Jdb_thread_list_policy;
23
24 private:
25   typedef typename E::Fp_list List;
26   unsigned prio_highest;
27   List prio_next[256];
28
29 public:
30   void set_idle(E *sc)
31   { sc->_prio = Config::Kernel_prio; }
32
33   void enqueue(E *, bool);
34   void dequeue(E *);
35   E *next_to_run() const;
36 };
37
38
39 // ---------------------------------------------------------------------------
40 IMPLEMENTATION [sched_fixed_prio || sched_fp_wfq]:
41
42 #include <cassert>
43 #include "cpu_lock.h"
44 #include "kdb_ke.h"
45 #include "std_macros.h"
46 #include "config.h"
47
48
49 IMPLEMENT inline
50 template<typename E>
51 E *
52 Ready_queue_fp<E>::next_to_run() const
53 { return prio_next[prio_highest].front(); }
54
55 /**
56  * Enqueue context in ready-list.
57  */
58 IMPLEMENT
59 template<typename E>
60 void
61 Ready_queue_fp<E>::enqueue(E *i, bool is_current_sched)
62 {
63   assert_kdb(cpu_lock.test());
64
65   // Don't enqueue threads which are already enqueued
66   if (EXPECT_FALSE (i->in_ready_list()))
67     return;
68
69   unsigned short prio = i->prio();
70
71   if (prio > prio_highest)
72     prio_highest = prio;
73
74   prio_next[prio].push(i, is_current_sched ? List::Front : List::Back);
75 }
76
77 /**
78  * Remove context from ready-list.
79  */
80 IMPLEMENT inline NEEDS ["cpu_lock.h", "kdb_ke.h", "std_macros.h"]
81 template<typename E>
82 void
83 Ready_queue_fp<E>::dequeue(E *i)
84 {
85   assert_kdb (cpu_lock.test());
86
87   // Don't dequeue threads which aren't enqueued
88   if (EXPECT_FALSE (!i->in_ready_list()))
89     return;
90
91   unsigned short prio = i->prio();
92
93   prio_next[prio].remove(i);
94
95   while (prio_next[prio_highest].empty() && prio_highest)
96     prio_highest--;
97 }
98
99
100 PUBLIC inline
101 template<typename E>
102 void
103 Ready_queue_fp<E>::requeue(E *i)
104 {
105   if (!i->in_ready_list())
106     enqueue(i, false);
107
108   prio_next[i->prio()].rotate_to(*++List::iter(i));
109 }
110
111
112 PUBLIC template<typename E> inline
113 void
114 Ready_queue_fp<E>::deblock_refill(E *)
115 {}
116