Improve multi_core support

This commit is contained in:
Jeremy Soller
2017-12-05 21:26:45 -07:00
parent cd54352f47
commit c2644adf3d
7 changed files with 41 additions and 27 deletions
+7 -5
View File
@@ -231,11 +231,13 @@ impl Context {
pub fn unblock(&mut self) -> bool {
if self.status == Status::Blocked {
self.status = Status::Runnable;
if let Some(cpu_id) = self.cpu_id {
if cpu_id != ::cpu_id() {
// Send IPI if not on current CPU
// TODO: Make this more architecture independent
unsafe { device::local_apic::LOCAL_APIC.ipi(cpu_id) };
if cfg!(feature = "multi_core") {
if let Some(cpu_id) = self.cpu_id {
if cpu_id != ::cpu_id() {
// Send IPI if not on current CPU
// TODO: Make this more architecture independent
unsafe { device::local_apic::LOCAL_APIC.set_icr(3 << 18 | 1 << 14 | 0x40) };
}
}
}
true
+7 -13
View File
@@ -42,14 +42,14 @@ pub unsafe fn switch() -> bool {
}
let check_context = |context: &mut Context| -> bool {
// Take ownership if not already owned
if context.cpu_id == None {
context.cpu_id = Some(cpu_id);
// println!("{}: take {} {}", cpu_id, context.id, ::core::str::from_utf8_unchecked(&context.name.lock()));
}
// Restore from signal
if context.ksig_restore {
println!("Restore from ksig");
let ksig = context.ksig.take().expect("context::switch: ksig not set with ksig_restore");
context.arch = ksig.0;
if let Some(ref mut kfx) = context.kfx {
@@ -64,16 +64,15 @@ pub unsafe fn switch() -> bool {
}
context.ksig_restore = false;
//TODO: Interrupt
if context.status == Status::Blocked {
context.unblock();
}
context.unblock();
}
// Unblock when there are pending signals
if context.status == Status::Blocked && !context.pending.is_empty() {
context.unblock();
}
// Wake from sleep
if context.status == Status::Blocked && context.wake.is_some() {
let wake = context.wake.expect("context::switch: wake not set");
@@ -84,13 +83,8 @@ pub unsafe fn switch() -> bool {
}
}
if context.cpu_id == Some(cpu_id) {
if context.status == Status::Runnable && !context.running {
return true;
}
}
false
// Switch to context if it needs to run, is not currently running, and is owned by the current CPU
!context.running && context.status == Status::Runnable && context.cpu_id == Some(cpu_id)
};
for (pid, context_lock) in contexts.iter() {