From 394afa493edfbe28910f3e19ff6ec491f9271920 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Sun, 24 Mar 2019 21:39:15 +0800 Subject: [PATCH] Fix TODO in work stealing scheduler --- Cargo.toml | 9 +++++++++ crate/memory/src/paging/mock_page_table.rs | 8 ++++---- crate/thread/src/scheduler/work_stealing.rs | 22 +++++++++++++++++---- 3 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 Cargo.toml diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..1f06456 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] +members = [ + "bootloader", + "crate/bit-allocator", + "crate/memory", + "crate/sync", + "crate/thread", +] +exclude = ["kernel"] diff --git a/crate/memory/src/paging/mock_page_table.rs b/crate/memory/src/paging/mock_page_table.rs index 67f34be..cfcdf2e 100644 --- a/crate/memory/src/paging/mock_page_table.rs +++ b/crate/memory/src/paging/mock_page_table.rs @@ -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; diff --git a/crate/thread/src/scheduler/work_stealing.rs b/crate/thread/src/scheduler/work_stealing.rs index acb2044..e0a1757 100644 --- a/crate/thread/src/scheduler/work_stealing.rs +++ b/crate/thread/src/scheduler/work_stealing.rs @@ -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 {