Skip to content

Commit 613e545

Browse files
pf: add LOG_PF_PTABLE to log the ptable on pf
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 8cfef52 commit 613e545

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

src/aero_kernel/src/arch/x86_64/interrupts/exceptions.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ use crate::unwind;
2626
use crate::userland::scheduler;
2727
use crate::utils::io;
2828

29+
const LOG_PF_PTABLE: bool = true;
30+
2931
macro interrupt_exception(fn $name:ident() => $message:expr) {
3032
pub fn $name(stack: &mut InterruptErrorStack) {
3133
unwind::prepare_panic();
@@ -110,7 +112,7 @@ pub(super) fn page_fault(stack: &mut InterruptErrorStack) {
110112
let task = scheduler::get_scheduler().current_task();
111113

112114
log::error!(
113-
"process: (pid={}, pid={})",
115+
"process: (tid={}, pid={})",
114116
task.tid().as_usize(),
115117
task.pid().as_usize()
116118
);
@@ -121,8 +123,12 @@ pub(super) fn page_fault(stack: &mut InterruptErrorStack) {
121123
.expect("userland application does not have a path set")
122124
);
123125

124-
scheduler::get_scheduler().current_task().vm.log();
125-
scheduler::get_scheduler().current_task().file_table.log();
126+
task.vm.log();
127+
task.file_table.log();
128+
129+
if LOG_PF_PTABLE {
130+
scheduler::get_scheduler().log_ptable();
131+
}
126132

127133
unwind::unwind_stack_trace();
128134

src/aero_kernel/src/syscall/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn exit(status: usize) -> ! {
4848
status = status
4949
);
5050

51-
scheduler::get_scheduler().inner.exit(status as isize);
51+
scheduler::get_scheduler().exit(status as isize);
5252
}
5353
}
5454

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#[cfg(feature = "round-robin")]
2121
pub mod round_robin;
2222

23+
use alloc::string::String;
2324
use alloc::sync::Arc;
2425

2526
use crate::apic;
@@ -59,25 +60,20 @@ pub trait SchedulerInterface: Send + Sync + Downcastable {
5960
fn exit(&self, status: isize) -> !;
6061
}
6162

62-
/// Container or a transparent struct containing a hashmap of all of the taskes
63-
/// in the scheduler's queue protected by mutex. The hashmap has a key
64-
/// of `ProcessId` and a value of a reference-counting pointer
65-
/// to the task or task.
66-
#[repr(transparent)]
6763
struct TaskContainer(Mutex<hashbrown::HashMap<TaskId, Arc<Task>>>);
6864

6965
impl TaskContainer {
70-
/// Creates a new task container with no taskes by default.
71-
#[inline]
7266
fn new() -> Self {
7367
Self(Mutex::new(hashbrown::HashMap::new()))
7468
}
7569

76-
/// Registers the provided `task` in the task container.
77-
#[inline]
7870
fn register_task(&self, task_id: TaskId, task: Arc<Task>) {
7971
self.0.lock().insert(task_id, task);
8072
}
73+
74+
fn remove_task(&self, task: Arc<Task>) {
75+
self.0.lock().remove(&task.pid());
76+
}
8177
}
8278

8379
unsafe impl Send for TaskContainer {}
@@ -120,6 +116,22 @@ impl Scheduler {
120116
self.inner.current_task()
121117
}
122118

119+
pub fn exit(&self, status: isize) -> ! {
120+
let current_task = self.inner.current_task();
121+
self.tasks.remove_task(current_task);
122+
123+
self.inner.exit(status)
124+
}
125+
126+
pub fn log_ptable(&self) {
127+
self.tasks.0.lock().iter().for_each(|(pid, task)| {
128+
log::info!(
129+
"task(pid={pid:?}, path={:?})",
130+
task.path().unwrap_or(String::from("<unknown>"))
131+
)
132+
});
133+
}
134+
123135
/// Lookup a task by ID
124136
#[inline]
125137
pub fn find_task(&self, task_id: TaskId) -> Option<Arc<Task>> {

src/aero_kernel/src/userland/signals.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ mod default {
8181
];
8282

8383
fn terminate() {
84-
scheduler::get_scheduler().inner.exit(1);
84+
scheduler::get_scheduler().exit(1);
8585
}
8686

8787
fn terminate_thread() {
@@ -421,7 +421,7 @@ pub fn check_for_signals() -> Option<(usize, SignalEntry)> {
421421
// Check if a SIGKILL is pending, and if so, kill the task.
422422
if signals.is_pending(SIGKILL as u64) {
423423
signals.clear_pending(SIGKILL as u64);
424-
scheduler::get_scheduler().inner.exit(1);
424+
scheduler::get_scheduler().exit(1);
425425
}
426426

427427
for i in 0..SIGNAL_COUNT {

0 commit comments

Comments
 (0)