Skip to content

Commit 4f3f758

Browse files
Merge pull request #263 from arihant2math/more-proc-stat
2 parents eed4d1d + 267af05 commit 4f3f758

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/drivers/fs/proc/stat.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::arch::{Arch, ArchImpl};
22
use crate::drivers::timer::uptime;
33
use crate::kernel::cpu_id::CpuId;
4+
use crate::process::TASK_LIST;
45
use crate::process::clone::NUM_FORKS;
6+
use crate::sched::sched_task::state::TaskState;
57
use crate::sched::{CpuStat, NUM_CONTEXT_SWITCHES, get_cpu_stat};
68
use alloc::boxed::Box;
79
use alloc::format;
@@ -82,6 +84,20 @@ impl SimpleFile for ProcStatInode {
8284
stat.guest_nice
8385
));
8486
}
87+
let tasks = TASK_LIST.lock_save_irq();
88+
let mut procs_running = 0;
89+
let mut procs_blocked = 0;
90+
for task in tasks.values().filter_map(|t| t.upgrade()) {
91+
let state = task.state.load(Ordering::Relaxed);
92+
match state {
93+
TaskState::Running | TaskState::Runnable | TaskState::Woken => procs_running += 1,
94+
TaskState::Sleeping
95+
| TaskState::Stopped
96+
| TaskState::PendingSleep
97+
| TaskState::PendingStop => procs_blocked += 1,
98+
_ => {}
99+
}
100+
}
85101
stat_content.push_str(&format!(
86102
"ctxt {}\n",
87103
NUM_CONTEXT_SWITCHES.load(Ordering::Relaxed)
@@ -91,6 +107,8 @@ impl SimpleFile for ProcStatInode {
91107
"processes {}\n",
92108
NUM_FORKS.load(Ordering::Relaxed)
93109
));
110+
stat_content.push_str(&format!("procs_running {procs_running}\n",));
111+
stat_content.push_str(&format!("procs_blocked {procs_blocked}\n",));
94112
Ok(stat_content.into_bytes())
95113
}
96114
}

0 commit comments

Comments
 (0)