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

Crates.io API Docs Book

Checks of a Linux host's low-latency settings, for start-up and housekeeping.

AI assistance. Like the rest of ergon, this crate was written with heavy AI assistance. See AI assistance disclosure. It is not production-ready.

What it does

  • A busy-spinning thread (one that loops on its CPU without sleeping) loses latency to whatever takes that CPU: a timer tick, an interrupt, khugepaged, a busy hyperthread on its core, or a container's CPU quota running out.
  • Each of those is a host setting, and a reboot, a new image or a NIC reset can undo it.
  • ergon-tune reads the host and returns findings: what is wrong, the exact fix, and the evidence (an archived A/B, or documentation and "not measured here"). It changes nothing.
  • Call them at start-up and from housekeeping in your own busy loop, media driver or network I/O layer.
Check What it looks at
T1 busy-spinning CPUs isolated, nohz_full, outside the default IRQ affinity
T2 NIC interrupts off those CPUs
T3 transparent hugepages off
T4 the Aeron directory on tmpfs or hugetlbfs
T5, T6 NUMA balancing off, and the NIC on the hot CPUs' node (multi-node hosts)
T7 no hot thread under SCHED_FIFO or SCHED_RR
T8 no two busy threads on one CPU or one physical core
T9 no CPU quota on the process's cgroup (a Kubernetes CPU limit, docker run --cpus); ThrottleWatch reads its throttling counters while the loop runs. Fix on Kubernetes: kubelet 1.33+, cpuManagerPolicy: static, a Guaranteed pod and a whole-number CPU request, so the kubelet drops the quota itself. Never cpuCFSQuota: false: it removes every pod's CPU limit on the node
T10 SMT (hyperthreading) off on x86 (Graviton and arm64 pass: one vCPU is one physical core). On x86 a Kubernetes cpu: 2 is one physical core, and a busy sibling slows the loop: the two share the core's execution units (not measured here). The fix is on the node: EKS/EC2 CpuOptions: ThreadsPerCore: 1, self-managed nosmt, or an instance type without SMT
K1-K7 inside a Kubernetes pod only, with T7 and T9: Guaranteed QoS, exclusive CPUs (the static CPU manager, not the shared pool), the loop's SMT sibling inside the pod's cpuset, a CPU for the helper threads (ERGON_SHARED_CPUS/ERGON_HELPER_CPUS), the capabilities the caller says it uses (Needs: busy polling, SCHED_FIFO, mlockall), no memory.high, and, when the caller names the NIC (Needs::with_nic), its NUMA node. Each finding says whether the fix goes in the pod spec or on the node, with the exact setting
T11 how CLOCK_REALTIME is kept: PTP-grade (chronyd locked to a PTP hardware clock, or phc2sys) is ok; NTP-disciplined or unsynchronised warns, with the chrony refclock PHC line for the host's PHC (a node setting); a correction still being slewed out, an error bound wider than 1 ms or a pending leap second warns. What the process cannot see (in a pod: the daemons and chronyd's port) is unknown, never a warning
T12 the kernel's clock source: the counter (tsc, arch_sys_counter) is ok; a hypervisor's view of it (kvm-clock, Hyper-V's TSC page) is info; anything else (hpet, acpi_pm) on x86-64 or 64-bit Arm warns: every CLOCK_REALTIME and CLOCK_MONOTONIC read is a system call. On another architecture a source other than tsc or arch_sys_counter is unknown
T13 the unbound workqueue cpumask (/sys/devices/virtual/workqueue/cpumask) leaves out the busy-spinning CPUs
T14 memory compaction leaves a hot thread's pages in place: vm.compaction_proactiveness 0 and vm.compact_unevictable_allowed 0 (info)
T15 no task of another process may run on a busy-spinning CPU (Cpus_allowed_list from /proc; kernel threads are T1's and T13's)
T16 no kprobe, ftrace hook or BPF program loaded (info; unprivileged, usually unknown)
T17 KSM not running (/sys/kernel/mm/ksm/run 0 or 2)
T18 no steal on the busy-spinning CPUs since boot (/proc/stat; info)
T19 FaultWatch: a hot thread takes no page fault while it runs
T20 the CPUs that take the data NICs' interrupts sleep no deeper than C1 (exit latency 1 µs; cpuidle disable and pm_qos_resume_latency_us counted). Warns for an IRQ CPU that may enter C1E or C6, with the per-CPU disable lines, intel_idle.max_cstate=1 / processor.max_cstate=1 and /dev/cpu_dma_latency as fixes (node settings on Kubernetes). Info for acpi_idle stopping at C1, and for a hot CPU that sleeps (the conductor). No cpuidle driver (Graviton) is ok
T21 TCP autocorking off (net.ipv4.tcp_autocorking 0, in the process's network namespace): on, a small send waits for the previous one's transmit to complete, even with TCP_NODELAY. A warning for a caller sending latency-sensitive TCP, info otherwise. Fix sysctl -w net.ipv4.tcp_autocorking=0; on Kubernetes in the pod's securityContext.sysctls (an unsafe sysctl the kubelet must allow), or on the node for a hostNetwork pod. Unknown under ergon-tune --root: the tree's /proc/sys/net need not be the application's namespace
T22 No Aeron affinity setting named as before Aeron 1.54 (AERON_DRIVER_CPUSET_AFFINITY, AERON_DRIVER_CPUSET_WARNINGS_AS_ERRORS): 1.54 ignores those names. Fix: rename to AERON_THREAD_AFFINITY_USE_CPUSET_OFFSETS and AERON_THREAD_AFFINITY_FAIL_ON_VALIDATION_ERRORS
T23 AERON_DIR on hugetlbfs has AERON_FILE_PAGE_SIZE=2097152 and AERON_TERM_BUFFER_SPARSE_FILE=false. The nri-shared-cpus plugin sets both when hugepages.ergon.io/<container> is 2M and the container has a hugepages-2Mi limit. The process still sets AERON_DIR to $ERGON_HUGEPAGES_DIR/aeron. The address, the gateway and the PCI address are never filled in
T24 a DPDK NIC pair, injected by a NIC device plugin not shipped here, for a caller on DPDK: RUSTERON_DPDK_SENDER_{PCI,IPV4_CIDR,GATEWAY} missing, empty or unparsable warns with the exact keys; all three set, the finding prints the copy lines built from them (copied, never guessed). Off when this process is not on DPDK, ok with no pair granted: no device plugin granted a pair, not a guessed address. Reads only: no export, no bind, no AERON_DIR, never unknown
T25 the CPU frequency governor performance on every online CPU that has one (cpufreq/scaling_governor): another governor drops a CPU's frequency between bursts, so a hot core's next busy-spin pays the ramp. Fix on the node: cpupower frequency-set -g performance or boot with cpufreq.default_governor=performance (a privileged DaemonSet or the node image on Kubernetes). No cpufreq on arm64 (Graviton) is ok; on x86 it is unknown
T26 with --family (c7i, c7a, c8g, c9g): the host's CPU vendor and threads per core match the declared instance family, every CPU of the pinning map is online, and no two busy threads of the map share a physical core. A mismatch warns, an unreadable vendor or layout is unknown, and both stop require. The fix names one CPU per physical core and the launch option (ThreadsPerCore: 1 on c7i); on Kubernetes the kubelet's full-pcpus-only on the node
T27 the ports an application listens on (t27_ephemeral_overlap(host, listen)): a listen range that overlaps net.ipv4.ip_local_port_range and is not covered by net.ipv4.ip_local_reserved_ports warns, because the kernel can hand a listen port to an outgoing connection and the listening app then fails with Address already in use. The fix names the unreserved overlap and the exact net.ipv4.ip_local_reserved_ports= sysctl line, or moves the listen range below the ephemeral range
N1-N5 (nic) ENA adaptive RX moderation, deferred interrupts without a busy poller, the Hyper-V accelerated-networking VF, the kernel RX ring, and with ENA's moderation off its interrupts off the busy-spinning CPUs (N5: a warning on Graviton, info elsewhere)

A finding names its fix. T1 on a stock host with its loop on CPU 2 of 8 gives isolcpus=nohz,domain,managed_irq,2 nohz_full=2 rcu_nocbs=2 irqaffinity=0-1,3-7.

The switch

Callers read one switch, ERGON_HOST_CHECKS, through HostCheckPolicy (any other value is an error at start):

Value What it does
on (default; warn is the same) checks run and the warning lines print
off no warning line prints; the results are still returned, and info lines still print
require a warning is an error at start, and so is a check that could not prove a property it must prove (see below)

require is a readiness gate, not a blanket refusal. It refuses on a warning (a check fired) and on an unproven check whose job is to prove a property of this pod or process: its CPUs are its own, they are isolated, there is no CPU quota, its helpers have a core, its pinning map fits the declared instance family (T26). Starting on an unproven claim is the false pass those checks exist to stop. An unknown of a check whose subsystem the node may not have (memory.high, a NUMA node, a NIC knob, THP) is printed and allowed through: that is a real host, and refusing there would stop every start on it. unknown_stops_require(id) says which: T3, T4, T5, T6, T11, T13-T21, T25, K6, K7, N1-N5 and M4 do not block; every other id does, a caller's own included. Under require, T10 refuses every x86 host with SMT on, and K2 refuses a stock static-CPU-manager pod: it proves exclusive CPUs only from an isolated or root cpuset partition (Linux 6.7+, as the nri-latency-pods plugin sets).

Every printed warning line ends with (ERGON_HOST_CHECKS=off silences host-check warnings). A caller may make off stronger and run no check at all. The caller reads the switch; the checks stay pure functions over a Host.

With ergon-shared-cpus

k8s/nri-shared-cpus (README) hands a pod its exclusive CPUs and the node's shared housekeeping CPUs; it does not tune the node. Its pods rely on T1, T2, T8, T9 and K1 to K7 (QoS, exclusive CPUs, SMT sibling, helper CPU, capabilities, memory.high, NUMA node): the helper CPU in ERGON_SHARED_CPUS is the plugin's own. Check the node with ergon-tune first, then ergon-cpus explain in the plugin pod.

When to use it

Use it for Not for
start-up, before a latency-sensitive loop the hot path: checks read files and allocate; N1, N4 and N5 make netlink exchanges with 100 ms send and receive timeouts each
housekeeping: an ENA reset turns adaptive moderation back on and moves queue interrupts; ThrottleWatch::check sees a CPU quota stopping the container; ClockWatch::check sees time sync or the clock source change; FaultWatch::check sees a hot thread fault tuning a host: it only reads
CI or review, against a captured or hand-made /sys and /proc tree hosts other than Linux: every reader reports unknown

Guarantees and limits

  • Read-only. No check writes a file or changes a setting. T11 asks the kernel with adjtimex modes 0 (unprivileged, changes nothing) and chronyd with its tracking monitoring request (UDP to 127.0.0.1:323, an address, no name lookup).
  • Unknown is never a warning. Unreadable data (a pod's network namespace, an interface with no device, hidepid) gives an unknown result with the reason.
  • Safe before a busy loop. No threads, statics, thread-locals, atomics or DNS, and it logs nothing.
  • One unsafe call. T11's adjtimex (src/time/kernel.rs): rustix has no wrapper for it yet, so the crate declares the C library's function over a hand-written struct timex (64-bit x86 and Arm Linux only; its size and field offsets, from the kernel's include/uapi/linux/timex.h, are asserted at compile time). It goes when rustix wraps adjtimex. Everything else is safe Rust.
  • Runs on fixtures. Every read goes through a Host: the running host (Host::system()) or a tree standing for its / (Host::at), on any OS. Kernel queries (T4's statfs, T11's adjtimex, N1's, N4's and N5's ethtool) reach only the running host; on a tree they report unknown.
  • Evidence named. Each finding's evidence names its source: kernel, driver, Kubernetes or vendor documentation, and "not measured here". Hosts differ: measure yours.
  • Only what the table lists. T20 never opens /dev/cpu_dma_latency (opening it registers a request), so a process holding it is not seen.

Check a node first: the ergon-tune command

Before deploying, run the checks on the node, or in a pod that mounts the node's root, and fix what they report:

cargo install ergon-tune
ergon-tune --hot 2-7 --nic ens6 --tcp           # on the node
ergon-tune --root /host --hot 2-7 --require     # a pod with the node's / at /host
Option Meaning
--hot CPUS the busy-spinning CPUs; default the node's isolated ones
--nic NAME|PCI a data NIC (ens6) or DPDK port (0000:00:06.0): adds T2, T6, T20; repeatable
--family NAME the instance family (c7i, c7a, c8g, c9g): adds T26, which checks the layout and the --hot map against it
--tcp the app sends latency-sensitive TCP: T21 warns
--busy-poll sockets busy-poll: K5 asks for CAP_NET_ADMIN
--component io|md|rt who spins, for T3's severity (default md)
--root DIR check a mounted tree instead of /; T9 (CPU quota) is not checked there, since /proc/self is ergon-tune itself: the app checks its own quota at start
--all print the checks that passed too
--require exit 1 where ERGON_HOST_CHECKS=require would refuse a start, or when there are no hot CPUs to check

Each line is a finding (WARN, info, UNKNOWN, ok) with its evidence and its fix; a summary line ends the output. Exit status: 0 reported, 1 refused (--require), 2 usage.

How to use it

[dependencies]
ergon-tune = "0.1"   # features = ["nic"] for N1-N5

At start-up, name the CPUs that busy-spin and log what the checks find. Component is the caller: a media driver (Md), a network I/O layer (Io) or an application's busy-spinning runtime (Rt). Transparent hugepages warn for Md and Rt and inform for Io.

use ergon_tune::{Component, Host, HotSet, Role, t1_isolation, t3_thp};

fn main() {
    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 effect, the fix> (evidence: <where>)`.
        if f.is_finding() {
            eprintln!("{f}");
        }
    }
}

In a container, check for a CPU quota before the loop, then watch the throttling counters from housekeeping. check reads cpu.stat.local, opened by open, and cpu.stat only after that grew (printing cpu.stat takes a kernel lock every cgroup shares). It allocates only when it reports:

use ergon_tune::{Host, ThrottleWatch, t9_cpu_quota};

fn main() {
    let host = Host::system();
    let t9 = t9_cpu_quota(&host); // before the loop
    if t9.is_finding() {
        eprintln!("{t9}");
    }
    let mut watch = ThrottleWatch::open(&host).ok(); // before the loop
    // From housekeeping, every few seconds; never inside the hot path:
    if let Some(f) = watch.as_mut().and_then(ThrottleWatch::check) {
        eprintln!("{f}"); // `T9 warn: this process's cgroup (...) was throttled ...`
    }
}

How CLOCK_REALTIME is kept (T11) and the clock source (T12), before the loop and then from housekeeping. open scans /proc and asks chronyd, waiting at most 50 ms; check never waits and allocates only when a finding changes. chronyd's answer is read one check late:

use ergon_tune::{ClockWatch, Host, TimeSyncProbe};

fn main() {
    let host = Host::system();
    let (mut watch, findings) = ClockWatch::open(&host, &TimeSyncProbe::default()); // before the loop
    for f in &findings {
        eprintln!("{f}"); // `T11 warn: CLOCK_REALTIME is not disciplined to a PTP hardware clock ...`
    }
    // From housekeeping, every few seconds; never inside the hot path:
    for f in watch.check() {
        eprintln!("{f}"); // none unless T11's judgement or the clock source changed
    }
    let _ = (watch.verdict(), watch.bound(), watch.leap_pending());
}

The same checks read a tree that stands for a host, on any OS:

use ergon_tune::{Component, Host, Status, t3_thp};

fn main() -> std::io::Result<()> {
    // A host's `/`, cut down to the one file T3 reads.
    let root = std::env::temp_dir().join(format!("ergon-tune-readme-{}", std::process::id()));
    let thp = root.join("sys/kernel/mm/transparent_hugepage");
    std::fs::create_dir_all(&thp)?;
    std::fs::write(thp.join("enabled"), "always [madvise] never\n")?;

    let found = t3_thp(&Host::at(&root), Component::Md);
    assert_eq!(found[0].status, Status::Finding);
    assert!(found[0].is_warning());
    assert!(found[0].message.contains("echo never > /sys/kernel/mm/transparent_hugepage/enabled"));

    std::fs::remove_dir_all(&root)
}
  • Feature nic adds N1-N5. N1, N4 and N5 ask the kernel over ethtool's generic netlink, unprivileged.
  • The only dependency is rustix, on Linux.

Further reading

  • The book chapter: each setting in plain English, the evidence per check, and a symptom-to-fix table: ergon-tune.
  • What the terms mean (IRQ, nohz_full, interrupt moderation, busy polling, THP, …), with pros and cons: the chapter's glossary.
  • API reference: docs.rs/ergon-tune.

Licensed under Apache-2.0.