Skip to main content

Scheduler

Struct Scheduler 

Source
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>

Source

pub(crate) fn init( opts: &'a Opts, open_object: &'a mut MaybeUninit<OpenObject>, shutdown: Arc<AtomicBool>, ) -> Result<Self>

Source

pub(crate) fn get_metrics(&mut self) -> Metrics

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub(crate) fn exited(&self) -> bool

Source

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.

Source

pub(crate) fn read_rtdl_state_noalloc(&self, cpu: usize) -> mlfq_rtdl_state

Stack-based read of RTDL state without heap allocation.

Source

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.

Source

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.

Source

pub(crate) fn run(&mut self, shutdown: Arc<AtomicBool>) -> Result<UserExitInfo>

Source

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.

Source

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.

Source

pub(crate) fn poll_train_results(&mut self)

Collect the finished fits from the training worker and apply the publish quality gate to each.

Source

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.

Source

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§

Source§

impl Drop for Scheduler<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pipe for T
where T: ?Sized,

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows 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) -> R
where R: 'a,

Mutably borrows 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
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows 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
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows 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
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .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
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .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
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more