kernel: manual resolution of P7-cache-affine-context for current fork
The P7-cache-affine-context patch fails to apply because the current
fork's context.rs has drifted from the patch's baseline (the
supplementary-groups field from P4-supplementary-groups is already
present, and other line numbers have shifted).
This is a manual surgical insertion of the P7 hunks that the kernel
needs to compile with the in-progress P8-percpu-wiring:
- Add SchedPolicy enum + SCHED_PRIORITY_LEVELS/DEFAULT_SCHED_OTHER_PRIORITY/
DEFAULT_SCHED_RR_QUANTUM constants at top of context.rs
- Add rt_priority_to_kernel_prio() and clamp_sched_other_prio() helpers
- Add PhysicalAddress to the memory import (used by futex_pi_waiters)
- Add last_cpu: Option<LogicalCpuId> field next to cpu_id
- Add sched_policy/sched_rt_priority/sched_rr_ticks_consumed/
sched_static_prio/sched_rr_quantum/vruntime/futex_pi_boost/
futex_pi_original_prio/futex_pi_waiters fields after prio
- Initialize all new fields in Context::new() with sensible defaults
Combined with the earlier RUN_QUEUE_COUNT pre-flight, this unblocks
P8-percpu-sched and P8-percpu-wiring to apply cleanly. cargo check
goes from 7 errors (RUN_QUEUE_COUNT + PercpuBlock field errors) to
1 error (the pre-existing unrelated fadt.rs type mismatch).
Phase 0c, plan order pre-flight for P7. The P7 patch file remains
in local/patches/kernel/ as historical reference; the local fork
now contains its essential content.
This commit is contained in:
+59
-1
@@ -18,7 +18,8 @@ use crate::{
|
||||
cpu_stats,
|
||||
ipi::{ipi, IpiKind, IpiTarget},
|
||||
memory::{
|
||||
allocate_p2frame, deallocate_p2frame, Enomem, Frame, RaiiFrame, RmmA, RmmArch, PAGE_SIZE,
|
||||
allocate_p2frame, deallocate_p2frame, Enomem, Frame, PhysicalAddress, RaiiFrame, RmmA,
|
||||
RmmArch, PAGE_SIZE,
|
||||
},
|
||||
percpu::PercpuBlock,
|
||||
scheme::{CallerCtx, FileHandle, SchemeId},
|
||||
@@ -62,6 +63,38 @@ impl Status {
|
||||
}
|
||||
}
|
||||
|
||||
pub const SCHED_PRIORITY_LEVELS: usize = 40;
|
||||
pub const DEFAULT_SCHED_OTHER_PRIORITY: usize = 20;
|
||||
pub const DEFAULT_SCHED_RR_QUANTUM: u128 = 100_000_000;
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum SchedPolicy {
|
||||
Fifo = 0,
|
||||
RoundRobin = 1,
|
||||
Other = 2,
|
||||
}
|
||||
|
||||
impl SchedPolicy {
|
||||
pub fn try_from_raw(raw: u8) -> Option<Self> {
|
||||
match raw {
|
||||
0 => Some(Self::Fifo),
|
||||
1 => Some(Self::RoundRobin),
|
||||
2 => Some(Self::Other),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rt_priority_to_kernel_prio(rt_priority: u8) -> usize {
|
||||
(SCHED_PRIORITY_LEVELS - 1)
|
||||
.saturating_sub((usize::from(rt_priority.min(99)) * (SCHED_PRIORITY_LEVELS - 1)) / 99)
|
||||
}
|
||||
|
||||
fn clamp_sched_other_prio(prio: usize) -> usize {
|
||||
prio.min(SCHED_PRIORITY_LEVELS - 1)
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum HardBlockedReason {
|
||||
/// "SIGSTOP", only procmgr is allowed to switch contexts this state
|
||||
@@ -96,6 +129,7 @@ pub struct Context {
|
||||
pub running: bool,
|
||||
/// Current CPU ID
|
||||
pub cpu_id: Option<LogicalCpuId>,
|
||||
pub last_cpu: Option<LogicalCpuId>,
|
||||
/// Time this context was switched to
|
||||
pub switch_time: u128,
|
||||
/// Amount of CPU time used
|
||||
@@ -140,6 +174,20 @@ pub struct Context {
|
||||
pub fmap_ret: Option<Frame>,
|
||||
/// Priority
|
||||
pub prio: usize,
|
||||
pub sched_policy: SchedPolicy,
|
||||
pub sched_rt_priority: u8,
|
||||
pub sched_rr_ticks_consumed: u32,
|
||||
pub sched_static_prio: usize,
|
||||
pub sched_rr_quantum: u128,
|
||||
/// Virtual runtime for SCHED_OTHER fair scheduling.
|
||||
/// CPU-bound threads accumulate vruntime faster; I/O-bound stay lower.
|
||||
pub vruntime: u128,
|
||||
#[allow(dead_code)]
|
||||
pub futex_pi_boost: bool,
|
||||
#[allow(dead_code)]
|
||||
pub futex_pi_original_prio: usize,
|
||||
#[allow(dead_code)]
|
||||
pub futex_pi_waiters: Vec<PhysicalAddress>,
|
||||
|
||||
// TODO: id can reappear after wraparound?
|
||||
pub owner_proc_id: Option<NonZeroUsize>,
|
||||
@@ -184,6 +232,7 @@ impl Context {
|
||||
status_reason: "",
|
||||
running: false,
|
||||
cpu_id: None,
|
||||
last_cpu: None,
|
||||
switch_time: 0,
|
||||
cpu_time: 0,
|
||||
sched_affinity: LogicalCpuSet::all(),
|
||||
@@ -200,6 +249,15 @@ impl Context {
|
||||
userspace: false,
|
||||
fmap_ret: None,
|
||||
prio: 20,
|
||||
sched_policy: SchedPolicy::Other,
|
||||
sched_rt_priority: 0,
|
||||
sched_rr_ticks_consumed: 0,
|
||||
sched_static_prio: 20,
|
||||
sched_rr_quantum: DEFAULT_SCHED_RR_QUANTUM,
|
||||
vruntime: 0,
|
||||
futex_pi_boost: false,
|
||||
futex_pi_original_prio: 0,
|
||||
futex_pi_waiters: Vec::new(),
|
||||
being_sigkilled: false,
|
||||
owner_proc_id,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user