pub(crate) struct Scheduler<'a> {Show 25 fields
pub(crate) skel: BpfSkel<'a>,
pub(crate) struct_ops: Option<Link>,
pub(crate) stats_server: StatsServer<(), Metrics>,
pub(crate) webui_tx: Option<Sender<WebMetrics>>,
pub(crate) webui_join: Option<JoinHandle<()>>,
pub(crate) cpu_static: Vec<PerCpuMetrics>,
pub(crate) cur_freq_khz: Vec<u64>,
pub(crate) freq_read_at: Option<Instant>,
pub(crate) started_at: Instant,
pub(crate) pm_qos_fd: Option<File>,
pub(crate) rb_mgr: RingBuffer<'static>,
pub(crate) sample_rx: Receiver<TreeSample>,
pub(crate) window: VecDeque<TreeSample>,
pub(crate) pid_counts: HashMap<u32, u32>,
pub(crate) tree_samples_cap_dropped: u64,
pub(crate) last_train_at: Option<Instant>,
pub(crate) train_tx: Sender<Vec<TreeSample>>,
pub(crate) train_rx: Receiver<Result<TrainResult, Error>>,
pub(crate) model: ModelMeta,
pub(crate) train_snapshot_buf: Vec<TreeSample>,
pub(crate) web_statics_buf: Vec<Option<PerCpuMetrics>>,
pub(crate) web_per_cpu_buf: Vec<PerCpuMetrics>,
pub(crate) op_lat_buf: Vec<u64>,
pub(crate) wakeup_raw_buf: Vec<u8>,
pub(crate) op_lat_raw_buf: Vec<u8>,
}Expand description
The Scheduler facade owns the loaded skeleton, the struct_ops link, the stats server and the MLFQ tree daemon state; drives the run loop until shutdown or UEI exit.
Fields§
§skel: BpfSkel<'a>§struct_ops: Option<Link>§stats_server: StatsServer<(), Metrics>§webui_tx: Option<Sender<WebMetrics>>§webui_join: Option<JoinHandle<()>>§cpu_static: Vec<PerCpuMetrics>§cur_freq_khz: Vec<u64>§freq_read_at: Option<Instant>§started_at: Instant§pm_qos_fd: Option<File>§rb_mgr: RingBuffer<'static>§sample_rx: Receiver<TreeSample>§window: VecDeque<TreeSample>§pid_counts: HashMap<u32, u32>§tree_samples_cap_dropped: u64§last_train_at: Option<Instant>§train_tx: Sender<Vec<TreeSample>>§train_rx: Receiver<Result<TrainResult, Error>>§model: ModelMeta§train_snapshot_buf: Vec<TreeSample>§web_statics_buf: Vec<Option<PerCpuMetrics>>§web_per_cpu_buf: Vec<PerCpuMetrics>§op_lat_buf: Vec<u64>§wakeup_raw_buf: Vec<u8>§op_lat_raw_buf: Vec<u8>Implementations§
Source§impl<'a> Scheduler<'a>
impl<'a> Scheduler<'a>
pub(crate) fn init( opts: &'a Opts, open_object: &'a mut MaybeUninit<OpenObject>, shutdown: Arc<AtomicBool>, ) -> Result<Self>
pub(crate) fn get_metrics(&mut self) -> Metrics
Sourcepub(crate) fn get_web_metrics(&mut self) -> WebMetrics
pub(crate) fn get_web_metrics(&mut self) -> WebMetrics
Web-metrics snapshot. The raw scheduler counters plus the per-CPU state and the runnable gauges, pushed to the web UI every run-loop iteration. Gauges only, no interval deltas.
Sourcepub(crate) fn read_cpu_state(&self, cpu: usize) -> mlfq_cpu_state
pub(crate) fn read_cpu_state(&self, cpu: usize) -> mlfq_cpu_state
Read one CPU’s dynamic state from the per-CPU array map. A failed lookup or an unexpected value size yields an all-zero state.
Sourcepub(crate) fn read_rtdl_state(&self, cpu: usize) -> mlfq_rtdl_state
pub(crate) fn read_rtdl_state(&self, cpu: usize) -> mlfq_rtdl_state
Read one CPU’s realtime-occupancy state from the per-CPU array map; a failed lookup yields an all-zero state (not occupied).
Sourcepub(crate) fn read_queue_runnable(&self) -> Vec<u64>
pub(crate) fn read_queue_runnable(&self) -> Vec<u64>
Tracked runnable tasks per queue (index 0 unused, 1..3 = Q1..Q3).
The gauge is the BPF-side mlfq_queue_runnable bss array, which
counts the runnable tasks placed in each queue’s DSQs (the
accounting contract is in intf.h next to the counters). Read
through the generated bss type, so a layout change is a compile
error rather than a silent misread.
Sourcepub(crate) fn read_llc_runnable(&self) -> Vec<u64>
pub(crate) fn read_llc_runnable(&self) -> Vec<u64>
Tracked runnable tasks per LLC domain (MLFQ_MAX_LLCS entries).
Same contract and access path as read_queue_runnable.
pub(crate) fn exited(&self) -> bool
Sourcepub(crate) fn read_cpu_state_noalloc(&self, cpu: usize) -> mlfq_cpu_state
pub(crate) fn read_cpu_state_noalloc(&self, cpu: usize) -> mlfq_cpu_state
Stack-based read of per-CPU state without heap allocation. Uses the raw bpf_map_lookup_elem syscall with a stack buffer, so the 100 ms web snapshot does not allocate one Vec per CPU.
Sourcepub(crate) fn read_rtdl_state_noalloc(&self, cpu: usize) -> mlfq_rtdl_state
pub(crate) fn read_rtdl_state_noalloc(&self, cpu: usize) -> mlfq_rtdl_state
Stack-based read of RTDL state without heap allocation.
Sourcepub(crate) fn read_op_lat(&mut self) -> Vec<u64>
pub(crate) fn read_op_lat(&mut self) -> Vec<u64>
Sum the per-CPU op-latency histogram into a flat per-op vector (MLFQ_OP_LAT_OPS x MLFQ_OP_LAT_BUCKETS entries, op-major). The map is per-CPU so the BPF charges never contend. A failed lookup or an unexpected value size yields zeros for that entry.
Sourcepub(crate) fn read_wakeup_total(&mut self) -> u64
pub(crate) fn read_wakeup_total(&mut self) -> u64
Sum the per-CPU lifetime wakeup totals from the mlfq_wakeup_stats map. Each CPU’s total is bumped atomically on the wakeup path, so this read is tear-free, and the u64 slots cannot wrap. A failed lookup yields zero. The observation-only contract holds, so the totals grow even while the adaptation is disabled.
pub(crate) fn run(&mut self, shutdown: Arc<AtomicBool>) -> Result<UserExitInfo>
Sourcepub(crate) fn ingest_sample(&mut self, s: TreeSample)
pub(crate) fn ingest_sample(&mut self, s: TreeSample)
Fold one emitted sample into the sliding training window and kick a retrain on the cadence. On the first window that reaches the minimum training size, then every MLFQ_TREE_RETRAIN_INTERVAL.
The window admits at most MLFQ_TREE_PER_PID_CAP samples per pid. A pid that already holds its share is dropped here and counted in tree_samples_cap_dropped. The cap check runs before the window accounting, so a rejected sample never disturbs the per-pid counts, and the eviction bookkeeping below decrements the pid of the sample the window actually pops.
Sourcepub(crate) fn kick_training(&mut self)
pub(crate) fn kick_training(&mut self)
Hand a snapshot of the window to the training worker.
The retrain cadence counts every kick, so a rejected model cannot turn into a per-sample retrain storm. try_send drops the kick when the worker is still busy with the previous fit, which the 60 s cadence makes rare.
Sourcepub(crate) fn poll_train_results(&mut self)
pub(crate) fn poll_train_results(&mut self)
Collect the finished fits from the training worker and apply the publish quality gate to each.
Sourcepub(crate) fn apply_train_result(&mut self, res: TrainResult)
pub(crate) fn apply_train_result(&mut self, res: TrainResult)
Commit a finished fit when it passes validation and the publish quality gate; otherwise keep the previous model.
The gate and the meta computation are pure functions in mlfq_tree (mlfq_tree::should_publish, mlfq_tree::tree_meta), which the unit tests cover.
Sourcepub(crate) fn publish_tree(
&mut self,
tree: &SerializedTree,
gen: u64,
) -> Result<()>
pub(crate) fn publish_tree( &mut self, tree: &SerializedTree, gen: u64, ) -> Result<()>
Publish a validated tree into the inactive map entry and commit the meta last.
The full map value is written (live nodes at the front, zeroed tail), so a shrinking tree never leaves stale nodes behind the new node count. A release fence orders the map-value write before the meta write, which flips the active entry, bumps the generation and sets the trained bit: a BPF reader that loaded the meta once sees either the old tree or the fully committed new one, never a partially written one.
The protocol is sound at the 60 s publish cadence: a reader could only observe a torn tree if two publishes completed within one tree walk, and each walk is a few dozen memory reads while a publish moves up to 2048 nodes, so two consecutive publishes cannot complete inside one walk. The consequence of the theoretical race is one mispredicted burst, which the queue-band nets absorb. The walk masks every index to the buffer bound, so it is never a memory-safety issue.
Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Scheduler<'a>
impl<'a> !Sync for Scheduler<'a>
impl<'a> !UnwindSafe for Scheduler<'a>
impl<'a> Freeze for Scheduler<'a>
impl<'a> Send for Scheduler<'a>
impl<'a> Unpin for Scheduler<'a>
impl<'a> UnsafeUnpin for Scheduler<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.