This commit is contained in:
Wildan M
2026-06-19 16:50:14 +07:00
parent b93260ed2d
commit 101f090ef9
3 changed files with 16 additions and 8 deletions
+1 -1
View File
@@ -1,10 +1,10 @@
use alloc::{collections::BTreeSet, sync::Arc, vec::Vec};
use arrayvec::ArrayString;
use core::{
cmp::Reverse,
mem::{self, size_of, ManuallyDrop},
num::NonZeroUsize,
sync::atomic::{AtomicU32, Ordering},
cmp::Reverse,
};
use syscall::{SigProcControl, Sigcontrol, UPPER_FDTBL_TAG};
+2 -2
View File
@@ -3,10 +3,10 @@
//! For resources on contexts, please consult [wikipedia](https://en.wikipedia.org/wiki/Context_switch) and [osdev](https://wiki.osdev.org/Context_Switching)
use alloc::{
collections::{BTreeSet, VecDeque, BTreeMap},
collections::{BTreeMap, BTreeSet, VecDeque},
sync::{Arc, Weak},
};
use core::{num::NonZeroUsize, ops::Deref, cmp::Reverse};
use core::{cmp::Reverse, num::NonZeroUsize, ops::Deref};
use crate::{
context::memory::AddrSpaceWrapper,
+13 -5
View File
@@ -15,11 +15,11 @@ use crate::{
use alloc::sync::Arc;
use core::{
cell::{Cell, RefCell},
cmp::Reverse,
hint, matches, mem,
option::Option::{None, Some},
sync::atomic::Ordering,
u64,
cmp::Reverse,
};
use smallvec::SmallVec;
use syscall::PtraceFlags;
@@ -220,7 +220,9 @@ pub fn switch(token: &mut CleanLockToken) -> SwitchResult {
guard.queue_key = Some(key);
drop(guard);
run_contexts.queue.insert(key, (new_vtime, weight, context_ref));
run_contexts
.queue
.insert(key, (new_vtime, weight, context_ref));
}
}
@@ -599,7 +601,10 @@ fn select_next_context(
}
} else if prev_is_eligible && eligible_best.is_some() {
if let Some((ref guard, _)) = eligible_best {
if prev_context_guard.vd < guard.vd || (prev_context_guard.vd == guard.vd && prev_context_guard.rem_slice > guard.rem_slice) {
if prev_context_guard.vd < guard.vd
|| (prev_context_guard.vd == guard.vd
&& prev_context_guard.rem_slice > guard.rem_slice)
{
eligible_best = None;
}
}
@@ -621,7 +626,6 @@ fn select_next_context(
}
if let Some((chosen_guard, addr_space)) = final_winner {
if prev_runnable {
let (vd, rem_slice, ctxt_id, vtime) = (
prev_context_guard.vd,
@@ -634,7 +638,11 @@ fn select_next_context(
let weight = SCHED_PRIO_TO_WEIGHT[prev_context_guard.prio] as u64;
contexts_data.queue.insert(
(vd, Reverse(rem_slice), ctxt_id),
(vtime, weight, WeakContextRef(Arc::downgrade(&prev_context_lock))),
(
vtime,
weight,
WeakContextRef(Arc::downgrade(&prev_context_lock)),
),
);
} else if !is_idle {
idle_contexts(token.token())