Print log target

toolchain_update
WangRunji 7 years ago
parent 2ad61cae65
commit eaaace0d48

@ -69,7 +69,7 @@ impl Log for SimpleLogger {
} }
fn log(&self, record: &Record) { fn log(&self, record: &Record) {
if self.enabled(record.metadata()) { if self.enabled(record.metadata()) {
print_in_color(format_args!("{}\n", record.args()), Color::from(record.level())); print_in_color(format_args!("[{}] {}\n", record.target(), record.args()), Color::from(record.level()));
} }
} }
fn flush(&self) {} fn flush(&self) {}

@ -64,7 +64,7 @@ impl Processor {
(_, &Status::Ready) => self.scheduler.insert(pid), (_, &Status::Ready) => self.scheduler.insert(pid),
_ => {} _ => {}
} }
trace!("Processor: process {} {:?} -> {:?}", pid, status0, status); trace!("process {} {:?} -> {:?}", pid, status0, status);
self.get_mut(pid).status = status; self.get_mut(pid).status = status;
} }
@ -77,7 +77,7 @@ impl Processor {
} }
self.event_hub.tick(); self.event_hub.tick();
while let Some(event) = self.event_hub.pop() { while let Some(event) = self.event_hub.pop() {
debug!("Processor: event {:?}", event); debug!("event {:?}", event);
match event { match event {
Event::Schedule => { Event::Schedule => {
self.event_hub.push(10, Event::Schedule); self.event_hub.push(10, Event::Schedule);
@ -153,7 +153,7 @@ impl Processor {
*from_pt = Some(old_table); *from_pt = Some(old_table);
} }
info!("Processor: switch from {} to {}\n rsp: ??? -> {:#x}", pid0, pid, to.rsp); info!("switch from {} to {}\n rsp: ??? -> {:#x}", pid0, pid, to.rsp);
unsafe { unsafe {
// FIXME: safely pass MutexGuard // FIXME: safely pass MutexGuard
use core::mem::forget; use core::mem::forget;
@ -181,7 +181,7 @@ impl Processor {
} }
pub fn exit(&mut self, pid: Pid, error_code: ErrorCode) { pub fn exit(&mut self, pid: Pid, error_code: ErrorCode) {
info!("Processor: {} exit, code: {}", pid, error_code); info!("{} exit, code: {}", pid, error_code);
self.set_status(pid, Status::Exited(error_code)); self.set_status(pid, Status::Exited(error_code));
if let Some(waiter) = self.find_waiter(pid) { if let Some(waiter) = self.find_waiter(pid) {
info!(" then wakeup {}", waiter); info!(" then wakeup {}", waiter);
@ -203,7 +203,7 @@ impl Processor {
/// Let current process wait for another /// Let current process wait for another
pub fn current_wait_for(&mut self, pid: Pid) -> WaitResult { pub fn current_wait_for(&mut self, pid: Pid) -> WaitResult {
info!("Processor: current {} wait for {:?}", self.current_pid, pid); info!("current {} wait for {:?}", self.current_pid, pid);
if self.procs.values().filter(|&p| p.parent == self.current_pid).next().is_none() { if self.procs.values().filter(|&p| p.parent == self.current_pid).next().is_none() {
return WaitResult::NotExist; return WaitResult::NotExist;
} }
@ -214,7 +214,7 @@ impl Processor {
self.try_wait(pid).unwrap() self.try_wait(pid).unwrap()
}); });
let exit_code = self.get(pid).exit_code().unwrap(); let exit_code = self.get(pid).exit_code().unwrap();
info!("Processor: {} wait end and remove {}", self.current_pid, pid); info!("{} wait end and remove {}", self.current_pid, pid);
self.procs.remove(&pid); self.procs.remove(&pid);
WaitResult::Ok(pid, exit_code) WaitResult::Ok(pid, exit_code)
} }

@ -10,20 +10,26 @@ pub trait Scheduler {
fn tick(&mut self, current: Pid) -> bool; // need reschedule? fn tick(&mut self, current: Pid) -> bool; // need reschedule?
} }
pub struct RRScheduler { pub use self::rr::RRScheduler;
pub use self::stride::StrideScheduler;
mod rr {
use super::*;
pub struct RRScheduler {
max_time_slice: usize, max_time_slice: usize,
infos: [RRProcInfo; MAX_PROCESS_NUM], infos: [RRProcInfo; MAX_PROCESS_NUM],
} }
#[derive(Debug, Default, Copy, Clone)] #[derive(Debug, Default, Copy, Clone)]
struct RRProcInfo { struct RRProcInfo {
present: bool, present: bool,
rest_slice: usize, rest_slice: usize,
prev: Pid, prev: Pid,
next: Pid, next: Pid,
} }
impl Scheduler for RRScheduler { impl Scheduler for RRScheduler {
fn insert(&mut self, pid: Pid) { fn insert(&mut self, pid: Pid) {
let pid = pid + 1; let pid = pid + 1;
{ {
@ -35,7 +41,7 @@ impl Scheduler for RRScheduler {
} }
} }
self._list_add_before(pid, 0); self._list_add_before(pid, 0);
debug!("RRScheduler: insert {}", pid - 1); debug!("insert {}", pid - 1);
} }
fn remove(&mut self, pid: Pid) { fn remove(&mut self, pid: Pid) {
@ -43,7 +49,7 @@ impl Scheduler for RRScheduler {
assert!(self.infos[pid].present); assert!(self.infos[pid].present);
self.infos[pid].present = false; self.infos[pid].present = false;
self._list_remove(pid); self._list_remove(pid);
debug!("RRScheduler: remove {}", pid - 1); debug!("remove {}", pid - 1);
} }
fn select(&mut self) -> Option<Pid> { fn select(&mut self) -> Option<Pid> {
@ -51,7 +57,7 @@ impl Scheduler for RRScheduler {
0 => None, 0 => None,
i => Some(i - 1), i => Some(i - 1),
}; };
debug!("RRScheduler: select {:?}", ret); debug!("select {:?}", ret);
ret ret
} }
@ -67,9 +73,9 @@ impl Scheduler for RRScheduler {
} }
*rest == 0 *rest == 0
} }
} }
impl RRScheduler { impl RRScheduler {
pub fn new(max_time_slice: usize) -> Self { pub fn new(max_time_slice: usize) -> Self {
RRScheduler { RRScheduler {
max_time_slice, max_time_slice,
@ -91,24 +97,27 @@ impl RRScheduler {
self.infos[i].next = 0; self.infos[i].next = 0;
self.infos[i].prev = 0; self.infos[i].prev = 0;
} }
}
} }
mod stride {
use super::*;
pub struct StrideScheduler { pub struct StrideScheduler {
max_time_slice: usize, max_time_slice: usize,
infos: [StrideProcInfo; MAX_PROCESS_NUM], infos: [StrideProcInfo; MAX_PROCESS_NUM],
queue: BinaryHeap<(Stride, Pid)>, // It's max heap, so pass < 0 queue: BinaryHeap<(Stride, Pid)>, // It's max heap, so pass < 0
} }
#[derive(Debug, Default, Copy, Clone)] #[derive(Debug, Default, Copy, Clone)]
struct StrideProcInfo { struct StrideProcInfo {
present: bool, present: bool,
rest_slice: usize, rest_slice: usize,
stride: Stride, stride: Stride,
priority: u8, priority: u8,
} }
impl StrideProcInfo { impl StrideProcInfo {
fn pass(&mut self) { fn pass(&mut self) {
const BIG_STRIDE: Stride = 1 << 20; const BIG_STRIDE: Stride = 1 << 20;
let pass = if self.priority == 0 { let pass = if self.priority == 0 {
@ -120,11 +129,11 @@ impl StrideProcInfo {
// self.stride.overflowing_add(pass); // self.stride.overflowing_add(pass);
self.stride += pass; self.stride += pass;
} }
} }
type Stride = i32; type Stride = i32;
impl Scheduler for StrideScheduler { impl Scheduler for StrideScheduler {
fn insert(&mut self, pid: Pid) { fn insert(&mut self, pid: Pid) {
let info = &mut self.infos[pid]; let info = &mut self.infos[pid];
assert!(!info.present); assert!(!info.present);
@ -133,7 +142,7 @@ impl Scheduler for StrideScheduler {
info.rest_slice = self.max_time_slice; info.rest_slice = self.max_time_slice;
} }
self.queue.push((-info.stride, pid)); self.queue.push((-info.stride, pid));
debug!("StrideScheduler: insert {}", pid); debug!("insert {}", pid);
} }
fn remove(&mut self, pid: Pid) { fn remove(&mut self, pid: Pid) {
@ -142,7 +151,7 @@ impl Scheduler for StrideScheduler {
info.present = false; info.present = false;
// FIXME: Support removing any element // FIXME: Support removing any element
assert_eq!(self.queue.pop().unwrap().1, pid, "Can only remove the top"); assert_eq!(self.queue.pop().unwrap().1, pid, "Can only remove the top");
debug!("StrideScheduler: remove {}", pid); debug!("remove {}", pid);
} }
fn select(&mut self) -> Option<Pid> { fn select(&mut self) -> Option<Pid> {
@ -151,9 +160,9 @@ impl Scheduler for StrideScheduler {
let old_stride = self.infos[pid].stride; let old_stride = self.infos[pid].stride;
self.infos[pid].pass(); self.infos[pid].pass();
let stride = self.infos[pid].stride; let stride = self.infos[pid].stride;
debug!("StrideScheduler: {} stride {:#x} -> {:#x}", pid, old_stride, stride); debug!("{} stride {:#x} -> {:#x}", pid, old_stride, stride);
} }
debug!("StrideScheduler: select {:?}", ret); debug!("select {:?}", ret);
ret ret
} }
@ -168,9 +177,9 @@ impl Scheduler for StrideScheduler {
} }
*rest == 0 *rest == 0
} }
} }
impl StrideScheduler { impl StrideScheduler {
pub fn new(max_time_slice: usize) -> Self { pub fn new(max_time_slice: usize) -> Self {
StrideScheduler { StrideScheduler {
max_time_slice, max_time_slice,
@ -180,6 +189,7 @@ impl StrideScheduler {
} }
pub fn set_priority(&mut self, pid: Pid, priority: u8) { pub fn set_priority(&mut self, pid: Pid, priority: u8) {
self.infos[pid].priority = priority; self.infos[pid].priority = priority;
debug!("StrideScheduler: {} priority = {}", pid, priority); debug!("{} priority = {}", pid, priority);
}
} }
} }

@ -31,6 +31,7 @@ pub fn spawn<F, T>(f: F) -> JoinHandle<T>
F: Send + 'static + FnOnce() -> T, F: Send + 'static + FnOnce() -> T,
T: Send + 'static, T: Send + 'static,
{ {
info!("spawn:");
use process; use process;
let pid = process::add_kernel_process(kernel_thread_entry::<F, T>, &f as *const _ as usize); let pid = process::add_kernel_process(kernel_thread_entry::<F, T>, &f as *const _ as usize);
return JoinHandle { return JoinHandle {
@ -43,7 +44,6 @@ pub fn spawn<F, T>(f: F) -> JoinHandle<T>
F: Send + 'static + FnOnce() -> T, F: Send + 'static + FnOnce() -> T,
T: Send + 'static, T: Send + 'static,
{ {
debug!("kernel_thread_entry");
let f = unsafe { ptr::read(f as *mut F) }; let f = unsafe { ptr::read(f as *mut F) };
let ret = Box::new(f()); let ret = Box::new(f());
let mut processor = PROCESSOR.try().unwrap().lock(); let mut processor = PROCESSOR.try().unwrap().lock();
@ -63,6 +63,7 @@ pub fn yield_now() {
/// Blocks unless or until the current thread's token is made available. /// Blocks unless or until the current thread's token is made available.
pub fn park() { pub fn park() {
info!("park:");
let mut processor = PROCESSOR.try().unwrap().lock(); let mut processor = PROCESSOR.try().unwrap().lock();
let pid = processor.current_pid(); let pid = processor.current_pid();
processor.sleep_(pid); processor.sleep_(pid);

Loading…
Cancel
Save