Skip to content

Commit f072d85

Browse files
log: print the cur task's pid on log
print the current task's PID and TID on log if the scheduler is initialized and the initial task has been initialized Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 613e545 commit f072d85

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/aero_kernel/src/logger.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use alloc::string::String;
2424
use log::{Level, LevelFilter, Metadata, Record};
2525
use spin::Once;
2626

27+
use crate::userland::scheduler;
2728
use crate::utils::buffer::RingBuffer;
2829
use crate::utils::sync::Mutex;
2930

@@ -71,6 +72,20 @@ impl log::Log for AeroLogger {
7172

7273
serial_print!("\x1b[37;1m{file}:{line} ");
7374

75+
if scheduler::is_initialized() {
76+
// fetch the current task, grab the TID and PID.
77+
scheduler::get_scheduler()
78+
.inner
79+
.current_task_optional()
80+
.map(|task| {
81+
serial_print!(
82+
"(tid={}, pid={}) ",
83+
task.tid().as_usize(),
84+
task.pid().as_usize()
85+
);
86+
});
87+
}
88+
7489
match record.level() {
7590
Level::Info => serial_print!("\x1b[32;1minfo "), // green info
7691
Level::Warn => serial_print!("\x1b[33;1mwarn "), // yellow warn

src/aero_kernel/src/userland/scheduler/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ pub trait SchedulerInterface: Send + Sync + Downcastable {
4444
/// Register the provided task into the task scheduler queue.
4545
fn register_task(&self, task: Arc<Task>);
4646

47-
/// Get a reference-counting pointer to the current task.
48-
fn current_task(&self) -> Arc<Task>;
47+
fn current_task(&self) -> Arc<Task> {
48+
self.current_task_optional()
49+
.expect("current_task: current task not found")
50+
}
51+
52+
fn current_task_optional(&self) -> Option<Arc<Task>>;
4953

5054
fn init(&self);
5155
fn wake_up(&self, task: Arc<Task>);

src/aero_kernel/src/userland/scheduler/round_robin.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,8 @@ impl SchedulerInterface for RoundRobin {
194194
queue.push_runnable(task);
195195
}
196196

197-
fn current_task(&self) -> Arc<Task> {
198-
let queue = self.queue.get();
199-
200-
queue.current_task.as_ref().unwrap().clone()
197+
fn current_task_optional(&self) -> Option<Arc<Task>> {
198+
self.queue.get().current_task.as_ref().cloned()
201199
}
202200

203201
fn init(&self) {

0 commit comments

Comments
 (0)