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) {
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) {}

@ -64,7 +64,7 @@ impl Processor {
(_, &Status::Ready) => self.scheduler.insert(pid),
_ => {}
}
trace!("Processor: process {} {:?} -> {:?}", pid, status0, status);
trace!("process {} {:?} -> {:?}", pid, status0, status);
self.get_mut(pid).status = status;
}
@ -77,7 +77,7 @@ impl Processor {
}
self.event_hub.tick();
while let Some(event) = self.event_hub.pop() {
debug!("Processor: event {:?}", event);
debug!("event {:?}", event);
match event {
Event::Schedule => {
self.event_hub.push(10, Event::Schedule);
@ -153,7 +153,7 @@ impl Processor {
*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 {
// FIXME: safely pass MutexGuard
use core::mem::forget;
@ -181,7 +181,7 @@ impl Processor {
}
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));
if let Some(waiter) = self.find_waiter(pid) {
info!(" then wakeup {}", waiter);
@ -203,7 +203,7 @@ impl Processor {
/// Let current process wait for another
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() {
return WaitResult::NotExist;
}
@ -214,7 +214,7 @@ impl Processor {
self.try_wait(pid).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);
WaitResult::Ok(pid, exit_code)
}

@ -10,6 +10,12 @@ pub trait Scheduler {
fn tick(&mut self, current: Pid) -> bool; // need reschedule?
}
pub use self::rr::RRScheduler;
pub use self::stride::StrideScheduler;
mod rr {
use super::*;
pub struct RRScheduler {
max_time_slice: usize,
infos: [RRProcInfo; MAX_PROCESS_NUM],
@ -35,7 +41,7 @@ impl Scheduler for RRScheduler {
}
}
self._list_add_before(pid, 0);
debug!("RRScheduler: insert {}", pid - 1);
debug!("insert {}", pid - 1);
}
fn remove(&mut self, pid: Pid) {
@ -43,7 +49,7 @@ impl Scheduler for RRScheduler {
assert!(self.infos[pid].present);
self.infos[pid].present = false;
self._list_remove(pid);
debug!("RRScheduler: remove {}", pid - 1);
debug!("remove {}", pid - 1);
}
fn select(&mut self) -> Option<Pid> {
@ -51,7 +57,7 @@ impl Scheduler for RRScheduler {
0 => None,
i => Some(i - 1),
};
debug!("RRScheduler: select {:?}", ret);
debug!("select {:?}", ret);
ret
}
@ -92,7 +98,10 @@ impl RRScheduler {
self.infos[i].prev = 0;
}
}
}
mod stride {
use super::*;
pub struct StrideScheduler {
max_time_slice: usize,
@ -133,7 +142,7 @@ impl Scheduler for StrideScheduler {
info.rest_slice = self.max_time_slice;
}
self.queue.push((-info.stride, pid));
debug!("StrideScheduler: insert {}", pid);
debug!("insert {}", pid);
}
fn remove(&mut self, pid: Pid) {
@ -142,7 +151,7 @@ impl Scheduler for StrideScheduler {
info.present = false;
// FIXME: Support removing any element
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> {
@ -151,9 +160,9 @@ impl Scheduler for StrideScheduler {
let old_stride = self.infos[pid].stride;
self.infos[pid].pass();
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
}
@ -180,6 +189,7 @@ impl StrideScheduler {
}
pub fn set_priority(&mut self, pid: Pid, priority: u8) {
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,
T: Send + 'static,
{
info!("spawn:");
use process;
let pid = process::add_kernel_process(kernel_thread_entry::<F, T>, &f as *const _ as usize);
return JoinHandle {
@ -43,7 +44,6 @@ pub fn spawn<F, T>(f: F) -> JoinHandle<T>
F: Send + 'static + FnOnce() -> T,
T: Send + 'static,
{
debug!("kernel_thread_entry");
let f = unsafe { ptr::read(f as *mut F) };
let ret = Box::new(f());
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.
pub fn park() {
info!("park:");
let mut processor = PROCESSOR.try().unwrap().lock();
let pid = processor.current_pid();
processor.sleep_(pid);

Loading…
Cancel
Save