3 * Timeslice infrastructure
6 INTERFACE [sched_fixed_prio]:
8 #include "member_offs.h"
11 #include "ready_queue_fp.h"
17 friend class Jdb_list_timeouts;
18 friend class Jdb_thread_list;
22 class Ready_queue : public Ready_queue_fp<Sched_context>
25 Context *schedule_in_progress;
26 void activate(Sched_context *s)
27 { _current_sched = s; }
28 Sched_context *current_sched() const { return _current_sched; }
31 Sched_context *_current_sched;
34 Context *context() const { return context_of(this); }
37 static Sched_context *fp_elem(Sched_context *x) { return x; }
39 Sched_context *_ready_next;
40 Sched_context *_ready_prev;
45 friend class Ready_queue_fp<Sched_context>;
49 IMPLEMENTATION [sched_fixed_prio]:
54 #include "std_macros.h"
62 Sched_context::Sched_context()
64 _prio(Config::boot_prio),
65 _quantum(Config::default_time_slice),
66 _left(Config::default_time_slice)
72 * Return priority of Sched_context
76 Sched_context::prio() const
82 * Set priority of Sched_context
86 Sched_context::set_prio (unsigned short const prio)
92 * Return full time quantum of Sched_context
96 Sched_context::quantum() const
102 * Set full time quantum of Sched_context
106 Sched_context::set_quantum (Unsigned64 const quantum)
112 * Return remaining time quantum of Sched_context
116 Sched_context::left() const
121 PUBLIC inline NEEDS[Sched_context::set_left, Sched_context::quantum]
123 Sched_context::replenish()
124 { set_left(quantum()); }
127 * Set remaining time quantum of Sched_context
131 Sched_context::set_left (Unsigned64 const left)
138 * Check if Context is in ready-list.
139 * @return 1 if thread is in ready-list, 0 otherwise
143 Sched_context::in_ready_list() const
145 return _ready_next != 0;
149 * Remove context from ready-list.
151 PUBLIC inline NEEDS ["cpu_lock.h", "kdb_ke.h", "std_macros.h"]
153 Sched_context::ready_dequeue()
155 assert_kdb (cpu_lock.test());
157 // Don't dequeue threads which aren't enqueued
158 if (EXPECT_FALSE (!in_ready_list()))
161 unsigned cpu = current_cpu();
163 _ready_q.cpu(cpu).dequeue(this);
167 * Enqueue context in ready-list.
171 Sched_context::ready_enqueue(unsigned cpu)
173 assert_kdb(cpu_lock.test());
175 // Don't enqueue threads which are already enqueued
176 if (EXPECT_FALSE (in_ready_list()))
179 Ready_queue &rq = _ready_q.cpu(cpu);
181 rq.enqueue(this, this == rq.current_sched());
186 Sched_context::requeue(unsigned cpu)
188 _ready_q.cpu(cpu).requeue(this);
192 * Return if there is currently a schedule() in progress
196 Sched_context::schedule_in_progress(unsigned cpu)
198 return _ready_q.cpu(cpu).schedule_in_progress;
203 Sched_context::reset_schedule_in_progress(unsigned cpu)
204 { _ready_q.cpu(cpu).schedule_in_progress = 0; }
208 * Invalidate (expire) currently active global Sched_context.
212 Sched_context::invalidate_sched(unsigned cpu)
214 _ready_q.cpu(cpu).activate(0);
219 Sched_context::dominates(Sched_context *sc)
220 { return prio() > sc->prio(); }
224 Sched_context::deblock_refill(unsigned)