Fix TODO in work stealing scheduler

master
Jiajie Chen 6 years ago
parent 7ee69db575
commit 394afa493e

@ -0,0 +1,9 @@
[workspace]
members = [
"bootloader",
"crate/bit-allocator",
"crate/memory",
"crate/sync",
"crate/thread",
]
exclude = ["kernel"]

@ -54,11 +54,11 @@ impl Entry for MockEntry {
fn swapped(&self) -> bool { self.swapped }
fn set_swapped(&mut self, value: bool) { self.swapped = value; }
fn user(&self) -> bool { unimplemented!() }
fn set_user(&mut self, value: bool) { unimplemented!() }
fn set_user(&mut self, _value: bool) { unimplemented!() }
fn execute(&self) -> bool { unimplemented!() }
fn set_execute(&mut self, value: bool) { unimplemented!() }
fn mmio(&self) -> bool { unimplemented!() }
fn set_mmio(&mut self, value: bool) { unimplemented!() }
fn set_execute(&mut self, _value: bool) { unimplemented!() }
fn mmio(&self) -> u8 { unimplemented!() }
fn set_mmio(&mut self, _value: u8) { unimplemented!() }
}
type PageFaultHandler = Box<FnMut(&mut MockPageTable, VirtAddr)>;

@ -17,10 +17,24 @@ impl WorkStealingScheduler {
impl Scheduler for WorkStealingScheduler {
fn push(&self, tid: usize) {
// TODO: push to random queue?
// now just push to cpu0
self.workers[0].push(tid);
trace!("work-stealing: cpu0 push thread {}", tid);
// not random, but uniform
// no sync, because we don't need to
static mut WORKER_CPU: usize = 0;
let n = self.workers.len();
let mut cpu = unsafe {
WORKER_CPU = WORKER_CPU + 1;
if WORKER_CPU >= n {
WORKER_CPU -= n;
}
WORKER_CPU
};
// potential racing, so we just check once more
if cpu >= n {
cpu -= n;
}
self.workers[cpu].push(tid);
trace!("work-stealing: cpu{} push thread {}", cpu, tid);
}
fn pop(&self, cpu_id: usize) -> Option<usize> {

Loading…
Cancel
Save