Skip to main content

Crate ergon_tune

Crate ergon_tune 

Source
Expand description

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

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: each setting in plain English, the evidence per check and a symptom-to-fix table.
  • Crate README: the ERGON_HOST_CHECKS switch, the guarantees and limits and the command’s options.

§The checks

CheckFunctionMeant for
T1t1_isolationio, md, rt
T2t2_nic_irqsio (egress NIC), md (data NICs, DPDK ports)
T3t3_thpmd, rt (warn); io (info)
T4t4_aeron_dirmd, rt
T5t5_numa_balancingmd, rt
T6t6_nic_nodemd
T7t7_sched_policyio, md, rt
T8t8_smt_siblingsio, md, rt
T9t9_cpu_quota at start; ThrottleWatch while runningio, md (start); ThrottleWatch: a runtime’s housekeeping
T10t10_smt_onio, md
T11t11_time_sync at start; ClockWatch while runningrt (start, housekeeping)
T12t12_clocksource at start; ClockWatch while runningrt (start, housekeeping)
T13t13_workqueue_cpumaskio, md
T14t14_compaction (info)io, md
T15t15_host_tasksio, md
T16t16_instrumentation (info)io, md
T17t17_ksmio, md
T18t18_steal (info)io, md
T19FaultWatch while runningio (the polling thread, every few seconds from housekeeping)
T20t20_irq_idlea node check (the CPU taking NIC interrupts)
T21t21_tcp_autocorkingio (a warning: its connections send latency-sensitive TCP)
T22t22_aeron_affinity_namesmd
T23t23_aeron_hugepage_envmd
T24t24_dpdk_nic_pairio (on DPDK), md (on a DPDK port)
T25t25_frequencya node check (the CPU frequency governor)
T26t26_family_layouta caller that declares its instance family (c7i, c7a, c8g, c9g)
T27t27_ephemeral_overlapa caller whose app listens on ports that may fall in net.ipv4.ip_local_port_range
K1-K6k8s_checks (with T7 and T9), inside a pod onlyio
K7k8s_checks with Needs::with_nica caller that names its NIC
N1 (nic)n1_adaptive_rxio, md (kernel sockets)
N2 (nic)n2_deferred_irqsio, md
N3 (nic)n3_azure_vfio
N4 (nic)n4_rx_ringmd (socket transport with busy polling)
N5 (nic)n5_irq_headroomio, 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.

Structs§

Bound
A bound on CLOCK_REALTIME’s error against UTC.
BusyPoll
The host-wide kernel busy-polling settings.
ChronyTracking
chronyd’s tracking report (chronyc tracking), as it answered.
ClockBoundReading
ClockBound’s bound, as of a read.
ClockSample
One check’s fresh reads: what ClockWatch::check reads, or what a test gives ClockWatch::update. A plain value: no allocation.
ClockWatch
T11 and T12 checked again from housekeeping, modelled on ThrottleWatch.
Clocksource
The kernel’s clock source and, for the fix, the CPU’s architecture and whether its TSC is invariant: what T12 judges. Build one to judge a host that is not here.
ClocksourceName
A clock source’s name held inline (at most 32 bytes, the kernel’s CS_NAME_LEN), so ClockWatch compares a fresh read with nothing allocated.
Coalesce
A NIC’s interrupt coalescing, as ethtool’s COALESCE_GET reports it.
CpuCgroup
This process’s CPU cgroup, as far as it can be seen from here.
CpuQuota
One cgroup’s CPU quota (its CFS bandwidth limit).
CpuSet
A set of CPU numbers. Its bitmap never ends in an empty word, so the derived equality is set equality.
CpuSteal
One CPU’s time since boot, from its /proc/stat line.
DpdkNicPair
The NIC the ENA device plugin granted this container.
EthtoolCache
Ethtool answers per interface, valid while its index and carrier_changes stay the same.
FaultWatch
T19 while the loop runs: a hot thread’s page faults since the last check.
Faults
A task’s page faults since it started.
Finding
One result of a check.
FsMagic
A filesystem’s type, as statfs gives it (f_type).
Host
The host the checks read: its /sys and /proc under a root.
HotCpu
A CPU and what the component uses it for.
HotSet
The CPUs a component uses, with their roles. A CPU may appear with more than one role.
IdleState
One cpuidle state of a CPU (/sys/devices/system/cpu/cpu<N>/cpuidle/state<i>).
KernelSync
The kernel’s view of the wall clock: adjtimex with modes 0.
Needs
What the caller does in the pod, so the checks warn only about the privileges and the layout it needs.
Netlink
Ethtool over generic netlink, unprivileged.
NicIrq
One interrupt of a NIC.
Observed
Everything read about the wall clock’s discipline, before judging it: what a TimeSyncProbe observes, or a test’s fixture.
Platform
The host’s architecture, vendor, cloud and instance type.
PtpClock
A PTP hardware clock: /sys/class/ptp/<device>/clock_name.
RefclockId
A reference clock’s ID as chrony prints it (UTI_RefidToString): the printable bytes of its four, in order. Held inline: no allocation.
Rings
A NIC’s ring sizes, as ethtool’s RINGS_GET reports them.
ThrottleWatch
T9 while the loop runs: this process’s cgroup’s throttling counters, read again to see whether the kernel stopped it since the last read.
Throttling
A cgroup’s throttling counters, from its cpu.stat and cpu.stat.local. None: not given here.
TimeSync
How CLOCK_REALTIME is kept: the verdict, what keeps it, its error bound where known, and what was read.
TimeSyncLimits
What T11 warns over.
TimeSyncProbe
What T11 asks and where (and what it warns over): the defaults read the running host; a test points them at fixtures and a fake chronyd.

Enums§

Arch
The CPU architecture, from /proc/cpuinfo.
BoundSource
Where an error bound came from.
CgroupVersion
The cgroup hierarchy the CPU controller is on.
ChronyAnswer
What chronyd’s command port said. A plain value: no allocation.
ChronyError
Why chronyd gave no tracking report. A plain value: making one allocates nothing.
ChronyReference
What chronyd’s clock is synchronised to, from its tracking report.
ClockBoundAnswer
What ClockBound’s segment said. A plain value: no allocation.
ClockBoundError
Why ClockBound’s segment could not be used. A plain value: making one allocates nothing.
ClockBoundStatus
ClockBound’s clock status (ClockStatus).
ClocksourceKind
What a clock source is to the hardware counter.
Cloud
The cloud, from the DMI system vendor.
Component
The component calling the checks. Some checks weigh differently per component (THP: a warning for the processes that run Aeron, information for a network I/O layer alone).
CpuSetError
Why a CPU list or mask did not parse.
EthtoolError
Why an ethtool query has no answer.
HostCheckError
What a caller does with a host-check policy or its report.
HostCheckPolicy
What HOST_CHECKS_ENV is set to.
Nic
A NIC, by kernel interface name or PCI address.
ReadError
Why something on the host could not be read. A check that meets one reports Status::Unknown with it as the reason, never a warning.
ResumeLimit
A CPU’s resume latency limit (pm_qos) (/sys/devices/system/cpu/cpu<N>/power/pm_qos_resume_latency_us).
Role
What a hot CPU is used for.
SchedPolicy
A scheduling policy, as /proc/<tid>/stat gives it.
Severity
How a caller reports a Status::Finding: a warning line, or an informational one. Opt-in strict modes (refusing to start) are the caller’s.
Status
What a check found.
SyncVerdict
How CLOCK_REALTIME is kept, as far as this process can see.
Thread
A thread whose policy or affinity is read.
TimeDaemon
A time daemon recognised by its process name (comm).
Vendor
The CPU vendor, from /proc/cpuinfo’s vendor_id (x86) or CPU implementer (Arm).

Constants§

AERON_HUGEPAGE_BYTES
Page size Aeron must be told when AERON_DIR is on the plugin’s 2 MiB mount.
CPU_LIMIT
The highest CPU number accepted, exclusive.
HOST_CHECKS_ENV
The one switch over every host-check warning.
SILENCE
What every printed warning line ends with.
T20_MAX_EXIT_LATENCY_US
The deepest exit latency (µs) T20 accepts on a CPU that takes a data NIC’s interrupts: C1’s. On intel_idle C1E (2 µs) is the first state past it.

Traits§

Ethtool
Where ethtool settings come from: Netlink on the running host, or a stand-in in tests.

Functions§

busy_poll_sysctls
Reads net.core.busy_read and busy_poll. They exist only in the host’s network namespace: in a pod they are absent, which is an error (unknown), never zero.
carrier_changes
How many times interface’s carrier has changed (/sys/class/net/<if>/carrier_changes): a re-check is due when it moves (an ENA reset brings the interface down and up).
cpu_cgroup
This process’s CPU cgroup and the quotas on it and its parents visible here.
cpu_idle_states
CPU cpu’s cpuidle states, shallowest first; none when it has no cpuidle directory.
cpu_steal
Each CPU’s steal and total time since boot, from /proc/stat. Read it twice and subtract to see the steal between the two reads.
cpuidle_driver
The cpuidle driver (intel_idle, acpi_idle, haltpoll), or None when there is none (none, or a kernel without cpuidle: the hypervisor’s or the architecture’s idle, such as Graviton’s WFI).
fs_magic
The filesystem path is on, or, if it does not exist yet (Aeron creates its directory), its nearest existing ancestor’s.
host_check_line
The one line of f as the caller prints it: <prefix> warning: … with SILENCE on a warning, <prefix> info: … on an info finding or an unknown, and nothing on an ok.
in_pod
Whether this runs inside a Kubernetes pod: the environment of the running host, the service account mount, or a kubepods cgroup path.
ip_local_port_range
Reads net.ipv4.ip_local_port_range: the range of ports the kernel hands to outgoing connections, both ends included.
ip_local_reserved_ports
Reads net.ipv4.ip_local_reserved_ports: the ports the kernel will not hand to an outgoing connection, as the sorted, merged ranges of the comma-separated list (single ports and lo-hi ranges).
isolated_cpus
The CPUs isolated from the scheduler’s load balancing.
k8s_checks
The checks that apply here: K1–K7, with T9 and T7 reused. Empty when this does not run inside a pod. Call this once, before the loop.
n1_adaptive_rx
N1: ENA’s adaptive RX interrupt moderation is off on interface. For kernel-socket paths on AWS, x86 and Graviton; other drivers are not checked.
n2_deferred_irqs
N2: interface (and on Azure its VF) defers no interrupts when no socket on it busy-polls.
n3_azure_vf
N3: a hv_netvsc interface (Hyper-V’s synthetic NIC) has an accelerated-networking VF (lower_*) that is up. Other drivers are not checked.
n4_rx_ring
N4: the kernel RX ring of interface (on Azure its VF) holds at least min(4096, its maximum) entries. For the media driver’s socket transport with busy polling.
n5_irq_headroom
N5: with adaptive RX moderation off, interface’s interrupts do not fire on a busy-spinning (receiver) CPU.
nic_irqs
The interrupts of nic’s PCI devices (an interface’s VFs included), in IRQ order: each device’s msi_irqs, or its legacy irq when that has a handler.
resume_limit
CPU cpu’s resume latency limit (pm_qos).
t1_isolation
T1: each busy-spinning CPU of cpus (Role::spins) is isolated from the scheduler’s load balancing, nohz_full, and outside /proc/irq/default_smp_affinity.
t2_nic_irqs
T2: no interrupt of nic may fire on a busy-spinning CPU of cpus.
t3_thp
T3: transparent hugepages are off, at every size.
t4_aeron_dir
T4: the Aeron directory is on a memory-backed filesystem (tmpfs, hugetlbfs or ramfs). The media driver checks its own directory, a runtime the directory it connects to.
t4_from
T4 from a fs_magic result already taken.
t5_numa_balancing
T5: automatic NUMA balancing is off, on a host with more than one node.
t6_nic_node
T6: on a host with more than one NUMA node, nic is on the node of the busy-spinning CPUs of cpus. The media driver’s check (a network I/O layer need not call it).
t7_sched_policy
T7: thread, in role, is not under SCHED_FIFO or SCHED_RR. The media driver checks its process before the agents start.
t8_smt_siblings
T8: no busy-spinning CPU of cpus shares its physical core with another of the component’s threads.
t9_cpu_quota
T9: no CPU quota on this process’s cgroup, nor on a parent visible here.
t10_smt_on
T10: SMT is off on this x86 host.
t11_time_sync
T11: how CLOCK_REALTIME is kept, as findings (TimeSync::findings): the verdict always, and warnings for an unsettled clock, a wide error bound or a pending leap second.
t12_clocksource
T12: the kernel’s clock source on host (Clocksource::finding).
t13_workqueue_cpumask
T13: the unbound workqueue cpumask (/sys/devices/virtual/workqueue/cpumask) leaves out every busy-spinning CPU of cpus (Role::spins).
t14_compaction
T14: memory compaction leaves a hot thread’s pages in place.
t15_host_tasks
T15: no task of another process may run on a busy-spinning CPU of cpus (its Cpus_allowed_list, from /proc/<pid>/task/<tid>/status).
t16_instrumentation
T16: no kernel instrumentation is loaded.
t17_ksm
T17: kernel same-page merging is not running (/sys/kernel/mm/ksm/run 0 or 2).
t18_steal
T18: no time stolen from a busy-spinning CPU of cpus since boot.
t20_irq_idle
T20: the CPUs that take the data NICs’ interrupts may not sleep deeper than C1 (T20_MAX_EXIT_LATENCY_US), and a hot CPU that is not busy-spinning is reported (information) when it may.
t21_tcp_autocorking
T21: TCP autocorking is off (net.ipv4.tcp_autocorking 0).
t22_aeron_affinity_names
T22: no Aeron affinity setting is given by a name Aeron 1.54 no longer reads.
t23_aeron_hugepage_env
T23: a directory on hugetlbfs has the page size and non-sparse terms set.
t24_dpdk_nic_pair
T24: a process on DPDK has the device plugin’s NIC pair complete and consistent.
t25_frequency
T25: every online CPU with a cpufreq governor is in performance.
t26_family_layout
T26: the host’s CPU layout matches the declared instance family, and the pinning map map fits that layout.
t27_ephemeral_overlap
T27: no port an application listens on is one the kernel can hand to an outgoing connection.
thread_affinity
The CPUs thread may run on (Cpus_allowed_list of its status).
thread_policy
The policy of thread: the 41st field of its stat, counted after the command name (which may hold spaces and parentheses).
time_sync
How CLOCK_REALTIME is kept on host now: TimeSyncProbe’s defaults.
unknown_stops_require
Whether an unknown result of check id stops a HostCheckPolicy::Require start.
warn_line
The one warning line of f, if it is a warning: <prefix> warning: <the finding> (ERGON_HOST_CHECKS=off silences host-check warnings).