2018-06-03 19:05:43 +04:00
|
|
|
use spin::Once;
|
2018-07-16 20:23:02 +04:00
|
|
|
use sync::{SpinNoIrqLock, Mutex, MutexGuard, SpinNoIrq};
|
2018-10-23 20:27:25 +04:00
|
|
|
pub use self::context::ContextImpl;
|
|
|
|
pub use ucore_process::processor::*;
|
2018-07-16 21:56:28 +04:00
|
|
|
pub use ucore_process::scheduler::*;
|
2018-07-17 15:06:30 +04:00
|
|
|
pub use ucore_process::thread::*;
|
2018-10-23 20:27:25 +04:00
|
|
|
use alloc::boxed::Box;
|
|
|
|
use consts::MAX_CPU_NUM;
|
|
|
|
use arch::cpu;
|
|
|
|
use alloc::sync::Arc;
|
|
|
|
use alloc::vec::Vec;
|
2018-04-27 19:10:39 +04:00
|
|
|
|
2018-07-16 20:23:02 +04:00
|
|
|
mod context;
|
2018-07-16 21:56:28 +04:00
|
|
|
|
2018-07-12 08:13:39 +04:00
|
|
|
pub fn init() {
|
2018-10-23 20:27:25 +04:00
|
|
|
// NOTE: max_time_slice <= 5 to ensure 'priority' test pass
|
|
|
|
let scheduler = Box::new(RRScheduler::new(5));
|
|
|
|
let manager = Arc::new(ProcessManager::new(scheduler));
|
|
|
|
|
|
|
|
extern fn idle(_arg: usize) -> ! {
|
|
|
|
loop { cpu::halt(); }
|
|
|
|
}
|
|
|
|
for i in 0..MAX_CPU_NUM {
|
|
|
|
manager.add(ContextImpl::new_kernel(idle, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
for cpu_id in 0..MAX_CPU_NUM {
|
|
|
|
PROCESSORS[cpu_id].init(cpu_id, ContextImpl::new_init(), manager.clone());
|
|
|
|
}
|
|
|
|
}
|
2018-08-07 10:59:45 +04:00
|
|
|
info!("process init end");
|
2018-04-27 19:10:39 +04:00
|
|
|
}
|
|
|
|
|
2018-10-23 20:27:25 +04:00
|
|
|
static PROCESSORS: [Processor; MAX_CPU_NUM] = [Processor::new(), Processor::new(), Processor::new(), Processor::new(), Processor::new(), Processor::new(), Processor::new(), Processor::new()];
|
2018-04-27 19:10:39 +04:00
|
|
|
|
2018-10-23 20:27:25 +04:00
|
|
|
pub fn processor() -> &'static Processor {
|
|
|
|
&PROCESSORS[cpu::id()]
|
2018-07-17 15:06:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
pub type thread = ThreadMod<ThreadSupportImpl>;
|
|
|
|
|
|
|
|
pub mod thread_ {
|
|
|
|
pub type Thread = super::Thread<super::ThreadSupportImpl>;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ThreadSupportImpl;
|
|
|
|
|
|
|
|
impl ThreadSupport for ThreadSupportImpl {
|
2018-10-23 20:27:25 +04:00
|
|
|
fn processor() -> &'static Processor {
|
2018-07-17 15:06:30 +04:00
|
|
|
processor()
|
|
|
|
}
|
2018-10-23 20:27:25 +04:00
|
|
|
fn new_kernel(entry: extern fn(usize) -> !, arg: usize) -> Box<Context> {
|
|
|
|
ContextImpl::new_kernel(entry, arg)
|
|
|
|
}
|
2018-04-27 19:10:39 +04:00
|
|
|
}
|