native-cpu-expert: drop the process expert layout and the GPU-wait hook nobody installs (STRA-338)

install_layout/expert_layout (a process RwLock cell) and install_release_gpu_waits (a process
OnceLock hook read on a pool stall) have no caller anywhere in the workspace, so the cells were
never written and the hook never ran. They are deleted instead of injected; the origin of the
pool's diagnostic millisecond clock is now a field of the pool's shared state (Shared::origin)
instead of a process OnceLock. Three process-global exceptions deleted.
This commit is contained in:
Pavlo Ratushnyi
2026-11-24 01:00:07 +01:00
parent 79765ac804
commit 5951540336
6 changed files with 18 additions and 43 deletions
-3
View File
@@ -227,9 +227,6 @@
{"crate": "leleka-cuda-driver", "file": "src/vram_ledger.rs", "ratchet": "process-global", "reason": "the process-wide VRAM ledger (LELEKA_VRAM_LEDGER): a diagnostic singleton fed by every allocation site"},
{"crate": "leleka-cuda-driver", "file": "src/marker_files.rs", "ratchet": "process-global", "reason": "the marker files of the A/B controls: the paths named by the operator are read once and the time of the first look is kept (OnceLock), so a hot path looks at the disk at most every 250 ms; one type serves the three controls"},
{"crate": "leleka-native-cpu-expert", "file": "src/rust_bench_frontend.rs", "ratchet": "process-global", "reason": "FFI: `static mut stdout` is libc's C stream, declared in an extern block"},
{"crate": "leleka-native-cpu-expert", "file": "src/rust_expert_layout.rs", "ratchet": "process-global", "reason": "the process-wide expert layout the pool threads read; it is set at load time by the engine"},
{"crate": "leleka-native-cpu-expert", "file": "src/rust_general_pool/job_default.rs", "ratchet": "process-global", "reason": "the origin instant of the pool's job timestamps"},
{"crate": "leleka-native-cpu-expert", "file": "src/rust_general_pool.rs", "ratchet": "process-global", "reason": "the hook that releases the GPU waits, installed once by the engine (a function pointer)"},
{"crate": "leleka-native-cpu-expert", "file": "src/settings.rs", "ratchet": "process-global", "reason": "the cell of a Setting: the operator's switches and the CPU probes the kernels dispatch on are computed on the first read and kept for the process life (immutable; a hot path pays one atomic load, and kernel code carries no context to pass a settings value through)"}
],
"source_patterns": [
@@ -2,10 +2,7 @@
//! is numerical layout only; actual ModelBinding/source admission stays outside.
use super::rust_ggml::{Kind, NativeFormat};
use super::{Error, FF, H, Result};
use std::{
path::Path,
sync::{OnceLock, RwLock},
};
use std::path::Path;
#[derive(Clone)]
pub struct ExpertLayout {
pub native: bool,
@@ -199,18 +196,6 @@ fn atoll(value: &str) -> i64 {
}
out.wrapping_mul(sign)
}
static LAYOUT: OnceLock<RwLock<ExpertLayout>> = OnceLock::new();
pub fn install_layout(layout: ExpertLayout) {
*LAYOUT.get_or_init(|| RwLock::new(ExpertLayout::canonical(0, 512))).write().unwrap_or_else(|p| p.into_inner()) =
layout;
}
pub fn expert_layout() -> ExpertLayout {
LAYOUT
.get_or_init(|| RwLock::new(ExpertLayout::canonical(0, 512)))
.read()
.unwrap_or_else(|p| p.into_inner())
.clone()
}
pub fn cpu_name() -> String {
// SAFETY: CPUID is architectural on x86_64; leaves 0x80000002..=4 are queried only after leaf 0x80000000 reported
// them.
@@ -9,7 +9,7 @@ use super::{Error, FF, H, Result};
use std::{
cell::UnsafeCell,
sync::{
Arc, Condvar, Mutex, OnceLock,
Arc, Condvar, Mutex,
atomic::{AtomicBool, AtomicI32, AtomicI64, AtomicU32, AtomicU64, Ordering},
},
thread,
@@ -79,9 +79,16 @@ struct Shared {
single: Vec<UnsafeCell<SingleSplit>>,
states: Vec<AtomicI32>,
host: AtomicI32,
/// The instant `host_ms` and `now_ms` count from: the creation of this pool.
origin: Instant,
host_ms: AtomicI64,
}
static RELEASE_GPU_WAITS: OnceLock<fn()> = OnceLock::new();
impl Shared {
/// Milliseconds since this pool was created (diagnostic timestamps of the host thread).
fn now_ms(&self) -> i64 {
self.origin.elapsed().as_millis().min(i64::MAX as u128) as i64
}
}
#[derive(Clone, Debug)]
pub struct Diagnostic {
pub epoch: u32,
@@ -113,8 +120,6 @@ mod exec;
mod job_default;
use job_default::alloc_with;
use job_default::cells;
pub use job_default::install_release_gpu_waits;
use job_default::now_ms;
mod epoch_scheduling;
mod expert_pool;
mod expert_pool_split_multi_run;
@@ -1,7 +1,7 @@
//! `Shared` of the general pool: publishing a job epoch, claiming work, draining, the worker loop and the waits.
//! Apart from `exec`, which runs one job.
use super::{Duration, Instant, Ordering, RELEASE_GPU_WAITS, Shared, now_ms};
use super::{Duration, Instant, Ordering, Shared};
impl Shared {
pub(super) fn publish(&self) {
@@ -31,7 +31,7 @@ impl Shared {
self.states[id].store(s, Ordering::Relaxed);
} else {
self.host.store(s, Ordering::Relaxed);
self.host_ms.store(now_ms(), Ordering::Relaxed);
self.host_ms.store(self.now_ms(), Ordering::Relaxed);
}
}
pub(super) fn drain(&self, e: u32, id: usize) {
@@ -91,9 +91,6 @@ impl Shared {
}
pub(super) fn stall(&self, what: &str) -> ! {
eprintln!("strata: the CPU expert pool stalled {what}");
if let Some(f) = RELEASE_GPU_WAITS.get() {
f();
}
std::process::abort()
}
pub(super) fn wait_parked(&self) {
@@ -4,7 +4,7 @@
use super::{
Arc, AtomicBool, AtomicI32, AtomicI64, AtomicU32, AtomicU64, Batch, Condvar, CpuTopology, Diagnostic, Duration,
Error, ExpertPool, H, Instant, Job, Line, Mutex, NativeFormat, Ordering, PlanarJob, PoolAffinity, Result, Shared,
SingleScratch, SingleSplit, Split, UnsafeCell, alloc_with, cells, now_ms, thread,
SingleScratch, SingleSplit, Split, UnsafeCell, alloc_with, cells, thread,
};
impl ExpertPool {
@@ -74,7 +74,8 @@ impl ExpertPool {
single: cells::<SingleSplit>(16)?,
states: alloc_with(n, || AtomicI32::new(-1))?,
host: AtomicI32::new(-10),
host_ms: AtomicI64::new(now_ms()),
origin: Instant::now(),
host_ms: AtomicI64::new(0),
}))
}
fn spawn_worker(s: Arc<Shared>, i: usize, core: i32) -> Result<thread::JoinHandle<()>> {
@@ -131,7 +132,7 @@ impl ExpertPool {
mode,
workers: s.states.iter().map(|s| s.load(Ordering::SeqCst)).collect(),
host: s.host.load(Ordering::SeqCst),
host_for_ms: now_ms() - s.host_ms.load(Ordering::SeqCst),
host_for_ms: s.now_ms() - s.host_ms.load(Ordering::SeqCst),
}
}
pub(super) fn phase(&mut self, mode: u32, tasks: usize, rows: usize, parts: usize) {
@@ -1,10 +1,7 @@
//! Defaults of the pool's raw job and scratch types, the Send/Sync claim for Shared with its safety argument,
//! and small helpers: fallible zeroed allocation, the GPU-wait release hook and a process-relative millisecond clock.
//! and small helpers: fallible zeroed allocation.
use super::{
Error, FF, Instant, Job, OnceLock, PlanarActivation, RELEASE_GPU_WAITS, Result, Shared, SingleSplit, Split,
UnsafeCell,
};
use super::{Error, FF, Job, PlanarActivation, Result, Shared, SingleSplit, Split, UnsafeCell};
impl Default for Job {
fn default() -> Self {
@@ -45,10 +42,3 @@ pub(super) fn alloc_with<T>(n: usize, make: impl FnMut() -> T) -> Result<Vec<T>>
pub(super) fn cells<T: Default>(n: usize) -> Result<Vec<UnsafeCell<T>>> {
alloc_with(n, || UnsafeCell::new(T::default()))
}
pub fn install_release_gpu_waits(callback: fn()) -> Result<()> {
RELEASE_GPU_WAITS.set(callback).map_err(|_| Error::Shape)
}
pub(super) fn now_ms() -> i64 {
static START: OnceLock<Instant> = OnceLock::new();
START.get_or_init(Instant::now).elapsed().as_millis().min(i64::MAX as u128) as i64
}