ergon-tune 0.1.45

Start-up and housekeeping checks of a host's low-latency settings (CPU isolation, NIC interrupts, transparent hugepages, the Aeron directory, NUMA, scheduling policy, SMT siblings, a CPU quota and its throttling, how CLOCK_REALTIME is kept and the kernel's clock source, background noise on the hot CPUs (unbound workqueues, compaction, other processes' tasks, kernel instrumentation, KSM, steal), a hot thread's page faults, the IRQ CPUs' idle depth and TCP autocorking, and with `nic` the NIC's moderation, deferral, VF and ring): pure functions returning findings, with no threads or statics, and one audited unsafe call (a read-only adjtimex)
Documentation
//! # ergon-tune
//!
//! Checks of a Linux host's low-latency settings, for start-up and
//! housekeeping. A busy-spinning thread loses latency to whatever takes its
//! CPU: a timer tick, an interrupt, `khugepaged`, a busy hyperthread, a
//! container's CPU quota. Each check reads the host and returns a
//! [`Finding`]: what is wrong, the exact fix and the evidence. Nothing is
//! changed, and no check needs more than the standard library and
//! [rustix](https://crates.io/crates/rustix).
//!
//! At start-up, name the CPUs that busy-spin and log what the checks find:
//!
//! ```
//! use ergon_tune::{Component, Host, HotSet, Role, t1_isolation, t3_thp};
//!
//! let host = Host::system();
//! let hot = HotSet::new().with(3, Role::Loop); // the loop runs on CPU 3
//! for f in t1_isolation(&host, &hot).iter().chain(&t3_thp(&host, Component::Rt)) {
//!     // One line each: `T1 warn: <what, its measured effect, the fix> (evidence: <where>)`.
//!     if f.is_finding() {
//!         eprintln!("{f}");
//!     }
//! }
//! ```
//!
//! Before deploying, run the same checks on a node with the `ergon-tune`
//! command (`cargo install ergon-tune`). Feature `nic` adds N1-N5.
//!
//! # Documentation
//!
//! - [The ergon-tune book chapter](https://mimran1980.github.io/ergon/tune/overview.html):
//!   each setting in plain English, the evidence per check and a
//!   symptom-to-fix table.
//! - [Crate README](https://github.com/mimran1980/ergon/blob/main/tune/README.md):
//!   the `ERGON_HOST_CHECKS` switch, the guarantees and limits and the command's
//!   options.
//!
//! ## The checks
//!
//! | Check | Function | Meant for |
//! |---|---|---|
//! | T1 | [`t1_isolation`] | io, md, rt |
//! | T2 | [`t2_nic_irqs`] | io (egress NIC), md (data NICs, DPDK ports) |
//! | T3 | [`t3_thp`] | md, rt (warn); io (info) |
//! | T4 | [`t4_aeron_dir`] | md, rt |
//! | T5 | [`t5_numa_balancing`] | md, rt |
//! | T6 | [`t6_nic_node`] | md |
//! | T7 | [`t7_sched_policy`] | io, md, rt |
//! | T8 | [`t8_smt_siblings`] | io, md, rt |
//! | T9 | [`t9_cpu_quota`] at start; [`ThrottleWatch`] while running | io, md (start); `ThrottleWatch`: a runtime's housekeeping |
//! | T10 | [`t10_smt_on`] | io, md |
//! | T11 | [`t11_time_sync`] at start; [`ClockWatch`] while running | rt (start, housekeeping) |
//! | T12 | [`t12_clocksource`] at start; [`ClockWatch`] while running | rt (start, housekeeping) |
//! | T13 | [`t13_workqueue_cpumask`] | io, md |
//! | T14 | [`t14_compaction`] (info) | io, md |
//! | T15 | [`t15_host_tasks`] | io, md |
//! | T16 | [`t16_instrumentation`] (info) | io, md |
//! | T17 | [`t17_ksm`] | io, md |
//! | T18 | [`t18_steal`] (info) | io, md |
//! | T19 | [`FaultWatch`] while running | io (the polling thread, every few seconds from housekeeping) |
//! | T20 | [`t20_irq_idle`] | a node check (the CPU taking NIC interrupts) |
//! | T21 | [`t21_tcp_autocorking`] | io (a warning: its connections send latency-sensitive TCP) |
//! | T22 | [`t22_aeron_affinity_names`] | md |
//! | T23 | [`t23_aeron_hugepage_env`] | md |
//! | T24 | [`t24_dpdk_nic_pair`] | io (on DPDK), md (on a DPDK port) |
//! | T25 | [`t25_frequency`] | a node check (the CPU frequency governor) |
//! | T26 | [`t26_family_layout`] | a caller that declares its instance family (`c7i`, `c7a`, `c8g`, `c9g`) |
//! | T27 | [`t27_ephemeral_overlap`] | a caller whose app listens on ports that may fall in `net.ipv4.ip_local_port_range` |
//! | K1-K6 | [`k8s_checks`] (with T7 and T9), inside a pod only | io |
//! | K7 | [`k8s_checks`] with [`Needs::with_nic`] | a caller that names its NIC |
//! | N1 (`nic`) | `n1_adaptive_rx` | io, md (kernel sockets) |
//! | N2 (`nic`) | `n2_deferred_irqs` | io, md |
//! | N3 (`nic`) | `n3_azure_vf` | io |
//! | N4 (`nic`) | `n4_rx_ring` | md (socket transport with busy polling) |
//! | N5 (`nic`) | `n5_irq_headroom` | io, md (kernel sockets, with N1's setting) |
//!
//! - **Callers** ([`Component`]): io is a busy-spinning network I/O layer,
//!   md an Aeron media driver, rt an application's busy-spinning runtime.
//!   None of them is in this repository; each calls what it chooses.
//! - **Results**: each is a [`Finding`]. Its [`Status`] says whether the check
//!   fired; its [`Severity`] says how to log it.
//! - **Cost**: file reads and allocations. T7 reads `/proc/thread-self` (no
//!   system call); T2 reads one directory and two files per interrupt; N1 and
//!   N4 make one netlink exchange per interface per reset (plus one family
//!   lookup on first use), each with 100 ms send and receive timeouts.
//!   [`ThrottleWatch::check`] reads one open file (`cpu.stat` too once
//!   throttling shows) and allocates only when it reports. T11 scans
//!   `/proc` and waits at most 50 ms for chronyd; [`ClockWatch::check`]
//!   never waits and allocates only when a finding changes. T15 reads two
//!   files per task on the host; [`FaultWatch::check`] reads one open file
//!   and allocates only when it reports.
//! - **Evidence**: each finding's `evidence` names its source: the
//!   kernel's, Kubernetes' or a vendor's documentation, marked "not
//!   measured here".
//! - **The switch**: every host-check warning line ends with how to silence
//!   it. [`HOST_CHECKS_ENV`] is `off` (no warning line, the results are
//!   still returned), `on` (the default) or `require` (a warning is an error
//!   at start). See [`HostCheckPolicy`] and [`host_check_line`].

mod aeron;
mod cpu;
mod cpuset;
mod dpdk;
mod family;
mod faults;
mod finding;
mod freq;
mod host;
mod idle;
mod k8s;
mod mem;
mod net;
#[cfg(feature = "nic")]
mod nic;
mod noise;
mod platform;
mod ports;
mod quota;
mod report;
mod tcp;
mod time;

pub use aeron::{AERON_HUGEPAGE_BYTES, t22_aeron_affinity_names, t23_aeron_hugepage_env};
pub use cpu::{
    SchedPolicy, Thread, isolated_cpus, t1_isolation, t7_sched_policy, t8_smt_siblings, t10_smt_on,
    thread_affinity, thread_policy,
};
pub use cpuset::{CPU_LIMIT, CpuSet, CpuSetError};
pub use dpdk::{DpdkNicPair, t24_dpdk_nic_pair};
pub use family::t26_family_layout;
pub use faults::{FaultWatch, Faults};
pub use finding::{Component, Finding, HotCpu, HotSet, Role, Severity, Status};
pub use freq::t25_frequency;
pub use host::{Host, ReadError};
pub use idle::{
    IdleState, ResumeLimit, T20_MAX_EXIT_LATENCY_US, cpu_idle_states, cpuidle_driver, resume_limit,
    t20_irq_idle,
};
pub use k8s::{Needs, in_pod, k8s_checks};
pub use mem::{FsMagic, fs_magic, t3_thp, t4_aeron_dir, t4_from, t5_numa_balancing};
pub use net::{
    BusyPoll, Nic, NicIrq, busy_poll_sysctls, carrier_changes, nic_irqs, t2_nic_irqs, t6_nic_node,
};
#[cfg(feature = "nic")]
pub use nic::{
    Coalesce, Ethtool, EthtoolCache, EthtoolError, Netlink, Rings, n1_adaptive_rx,
    n2_deferred_irqs, n3_azure_vf, n4_rx_ring, n5_irq_headroom,
};
pub use noise::{
    CpuSteal, cpu_steal, t13_workqueue_cpumask, t14_compaction, t15_host_tasks,
    t16_instrumentation, t17_ksm, t18_steal,
};
pub use platform::{Arch, Cloud, Platform, Vendor};
pub use ports::{ip_local_port_range, ip_local_reserved_ports, t27_ephemeral_overlap};
pub use quota::{
    CgroupVersion, CpuCgroup, CpuQuota, ThrottleWatch, Throttling, cpu_cgroup, t9_cpu_quota,
};
pub use report::{
    HOST_CHECKS_ENV, HostCheckError, HostCheckPolicy, SILENCE, host_check_line,
    unknown_stops_require, warn_line,
};
pub use tcp::t21_tcp_autocorking;
pub use time::{
    Bound, BoundSource, ChronyAnswer, ChronyError, ChronyReference, ChronyTracking,
    ClockBoundAnswer, ClockBoundError, ClockBoundReading, ClockBoundStatus, ClockSample,
    ClockWatch, Clocksource, ClocksourceKind, ClocksourceName, KernelSync, Observed, PtpClock,
    RefclockId, SyncVerdict, TimeDaemon, TimeSync, TimeSyncLimits, TimeSyncProbe, t11_time_sync,
    t12_clocksource, time_sync,
};