Capture event stat, change stat source for contexts

This commit is contained in:
Wildan M
2026-05-12 12:24:49 +07:00
parent 97bd0fb4a6
commit bd44956e96
4 changed files with 35 additions and 29 deletions
+14
View File
@@ -82,6 +82,7 @@ static IDLE_CONTEXTS: Mutex<L2, VecDeque<WeakContextRef>> = Mutex::new(VecDeque:
pub struct RunContextData {
set: [VecDeque<WeakContextRef>; 40],
count: usize,
}
impl RunContextData {
@@ -89,8 +90,13 @@ impl RunContextData {
const EMPTY_VEC: VecDeque<WeakContextRef> = VecDeque::new();
Self {
set: [EMPTY_VEC; 40],
count: 0,
}
}
pub fn update_count(&mut self) -> usize {
self.count = self.set.iter().map(|q| q.len()).sum();
self.count
}
}
/// Get the global schemes list, const
@@ -322,3 +328,11 @@ impl Drop for PreemptGuardL2<'_> {
self.context.write(self.token.token()).preempt_locks -= 1;
}
}
pub fn get_contexts_stats(token: &mut CleanLockToken) -> (usize, usize, usize) {
let alive = contexts(token.downgrade()).len();
let running = run_contexts(token.token()).count;
let blocked = idle_contexts(token.downgrade()).len();
(alive, running, blocked)
}
+2 -2
View File
@@ -384,7 +384,6 @@ fn select_next_context(
) -> Option<(ArcContextLockWriteGuard, Option<AddrSpaceSwitchReadGuard>)> {
let contexts_data = run_contexts(token.token());
let (mut contexts_data, mut token) = contexts_data.into_split();
let contexts_list = &mut contexts_data.set;
let idle_context = percpu.switch_internals.idle_context();
let mut balance = percpu.balance.get();
let mut i = percpu.last_queue.get() % 40;
@@ -396,7 +395,8 @@ fn select_next_context(
let mut total_iters = 0;
let mut next_context_guard_opt = None;
let total_contexts: usize = contexts_list.iter().map(|q| q.len()).sum();
let total_contexts: usize = contexts_data.update_count();
let contexts_list = &mut contexts_data.set;
let mut skipped_contexts = 0;
'priority: loop {