Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Shared CPUs for helper threads (k8s/nri-shared-cpus)

How to install and use k8s/nri-shared-cpus on a Kubernetes node.

A busy-spinning pod gets whole cores of its own from the kubelet. Its helpers (dial, TLS, warnings, Aeron conductors) do not need a whole core, and running them on the loop’s core is what this layout forbids. With the helpers on the shared CPU and the quiet-CPU settings, one Azure Cobalt VM measured the loop at p50 0.02 µs, p99.99 0.03 µs, max 4.81 to 5.52 µs, with 0 involuntary switches a minute; 3.5 to 5.5 µs is the hypervisor’s floor (benchmarks). This is a containerd NRI plugin and a kubelet device plugin that give the pod the node’s shared housekeeping CPUs as well, and start every thread there.

The busy-spin loop keeps its exclusive core. Only sleepy helpers go to the shared CPUs. Never a spinner or SQPOLL there: either takes the CPU from every helper on it.

Source: k8s/nri-shared-cpus/.

Status: published as tag 0.1.6. Anyone can pull the image and the chart. The kind e2e passed at its source. Verified on EKS AL2023 (Kubernetes 1.36, c8g.xlarge) with the same plugin and chart source as published 0.1.2 (85098f8b; 0.1.3 to 0.1.5 leave CPU placement unchanged, 0.1.6 adds the shared-burst resource; not re-run on EKS), built from that source and pushed to the run’s ECR: the NRI socket, nodeadm’s TOML merge, the kubelet drop-in merge, /opt writable, system-node-critical outside kube-system. Latency of the spin loop is measured on one Azure VM. Related projects (credited): k8s/nri-shared-cpus/README.md.

Use the public chart

Do these in order. The chart installs the DaemonSet. It does not prepare the node, and it does not install the hot-pod admission policy.

  1. Prepare the node. Node setup below. Label it ergon.io/shared-cpus=true.
  2. Install. config.sharedCpus is the housekeeping CPU, inside reservedSystemCPUs, and not the IRQ CPU. For the 8-CPU split in that section the value is 0. One Helm release per shared-CPU layout. The three hostContract flags mount the node’s kubelet config, /sys and /proc read-only; the plugin checks every pod labelled ergon.io/latency: hot against them (Node setup).
helm install ergon-shared-cpus oci://ghcr.io/mimran1980/charts/ergon-shared-cpus \
  --version 0.1.6 \
  --namespace ergon-system --create-namespace \
  --set-string config.sharedCpus=0 \
  --set 'config.namespaces={trading}' \
  --set hostContract.kubeletConfig.enabled=true \
  --set hostContract.sys.enabled=true \
  --set hostContract.proc.enabled=true

EKS AL2023 (verified at 0.1.2 on EKS 1.36 c8g.xlarge, containerd 2.3.5, with the same plugin and chart source as published 0.1.2 (85098f8b), built from that source and pushed to the run’s ECR; 0.1.3 to 0.1.5 leave CPU placement unchanged and were not re-run there). nodeadm writes the base /etc/kubernetes/kubelet/config.json, puts the NodeConfig kubelet settings in the drop-in /etc/kubernetes/kubelet/config.json.d/40-nodeadm.conf, and runs the kubelet with --config-dir on that directory. kubeletConfigDir mounts it read-only and the hot-pod check merges its *.conf files as the kubelet does (lexical order, JSON merge patch):

helm install ergon-shared-cpus oci://ghcr.io/mimran1980/charts/ergon-shared-cpus \
  --version 0.1.6 \
  --namespace ergon-system --create-namespace \
  --set-string config.sharedCpus=0 \
  --set 'config.namespaces={trading}' \
  --set hostContract.kubeletConfig.enabled=true \
  --set hostContract.kubeletConfig.path=/etc/kubernetes/kubelet/config.json \
  --set hostContract.kubeletConfigDir.enabled=true \
  --set hostContract.sys.enabled=true \
  --set hostContract.proc.enabled=true

Without kubeletConfigDir every hot pod is refused on AL2023. The drop-in directory exists only when NodeConfig sets spec.kubelet.config; without it the plugin pod does not start.

A refused hot pod gets one line naming each failed node check in the order to fix them, with what was seen, what is needed and the fix. To check a node without a pod, run ergon-cpus explain in the plugin pod: it prints PASS, FAIL or SKIP per check and exits 1 on a failure. config.hotContract.mode: warn logs a failed check and lets the create go on while a fleet is brought into line; enforce is the default.

No node label? Set nodeSelector.ergon\.io/shared-cpus=null and the new label (for example nodeSelector.eks\.amazonaws\.com/nodegroup=trading): Helm merges maps, so the default key stays unless it is set to null.

Check the pulled image. This prints the index digest sha256:2b384eded978bf638bc5da981fda0538ef24edffb35229889e284e5bd1bbff91:

docker buildx imagetools inspect ghcr.io/mimran1980/ergon-shared-cpus:0.1.6

Chart digest sha256:407602c1216952c71076c21cac4becd69c0f43841c9b0591815a6f428514bc8d. image.digest renders repository@digest; an empty digest keeps repository:tag, and the default tag is the chart’s appVersion (0.1.6).

The chart renders every field config.File accepts, with seccomp.ioUring and ptp quoted "off". The plugin leaves them off. A later edit of the ConfigMap can turn a key on, and the pod still has to opt in. Aeron’s C media driver does not use io_uring.

admission.create defaults to false and renders a ConfigMap whose data.owner is external. Set it true to install the two named admission files (the policy, its binding, and the ergon-hot and ergon-helper PriorityClasses). A ConfigMap edit does not roll the DaemonSet. Drain first, then set layoutRevision.

helm install prints NOTES that say the chart is not published. It is published; ignore that line.

  1. Apply the hot-pod policy. These two files only, from k8s/nri-latency-pods/admission/:
kubectl apply -f priority-class.yaml -f validating-admission-policy.yaml

Leave examples/ and mutating-admission-policy.yaml unapplied. A pod labelled ergon.io/latency: hot is refused when it has an exec probe, a container with restartPolicy: Always, no ergon.io/shared-millicpus request, no required-plugins.noderesource.dev annotation naming ergon-shared-cpus, or no priorityClassName with a value above 100.

  1. Run a Guaranteed pod in an allowlisted namespace. Whole-number cpu, requests equal limits, ergon.io/shared-millicpus. The pod spec is under Pod. Inside it, ERGON_SHARED_CPUS is the housekeeping list, ERGON_ISOLATED_CPUS is the exclusive list, PID 1 Cpus_allowed_list is the shared CPUs only, and cpuset.cpus.effective is the union.

Flux: a HelmRepository of type oci at oci://ghcr.io/mimran1980/charts, chart ergon-shared-cpus version 0.1.6, targetNamespace: ergon-system, and the same config and hostContract values. Copy the two admission files into the Git repo Flux already applies. Do not point Flux at the whole admission/ directory: that directory also holds pods the policy is meant to refuse.

See it on kind

k8s/nri-shared-cpus/examples/try/run.sh creates a throwaway kind cluster (kindest/node:v1.35.1, static CPU manager, reservedSystemCPUs: "0,1"), installs this public chart with sharedCpus: "0" and the three hostContract flags, and applies the two admission files. A kind node shares the host kernel and has no isolcpus, so no hot pod can start there.

podexpected
unlabelled, cpu: "2", ergon.io/shared-millicpus: "250"Ready. Log: ERGON_SHARED_CPUS=0, non-empty ERGON_ISOLATED_CPUS, PID 1 Cpus_allowed_list of 0, nproc=1
the same, labelled ergon.io/latency: hotadmitted, then refused by the plugin: exclusive CPU not isolated
the hot pod with an exec liveness probedenied by the admission policy

The script deletes the cluster on the way out and uses a kubeconfig under /tmp.

That run shows the shared-CPU grant and the HFT admission check. It does not measure latency. Kind on Docker Desktop has no hugepage pool, no NIC PHC and no cpuset.cpus.exclusive partition to demonstrate, and this sample does not ask for those grants.

Run end to end on kind against the published chart 0.1.6 (2026-12-01).

The 21-step test/e2e.sh is a different run. It builds ergon-shared-cpus:dev from this tree. It does not pull the public chart.

What it gives

itemvalue
exclusive CPUsthe kubelet’s static CPU manager, cpu: N
shared CPUsergon.io/shared-millicpus: M adds ceil(M/1000) shared CPUs. With ergon.io/shared-burst-cpus: B it adds B shared CPUs (at least ceil(M/1000)) and the node still reserves M
start affinitythe hook pins threads that exist at create onto the shared CPUs. A later thread inherits its creator’s mask. A helper created by a pinned hot thread inherits the hot mask. The application can change affinity. A C pthread_create did that on linuxkit with no isolcpus. A Go 1.27 OS thread started from the hot thread stayed on the shared CPU. Aeron: aeron-client, created by a thread before it pinned, kept that thread’s mask (a placement test in Docker, without the plugin’s hook); under the hook on a node, not run. JVM not run
timer slack1 ns on every thread, inherited by every thread and child the program makes
pinningthe app pins hot threads by index into ERGON_ISOLATED_CPUS

M is millicpus because extended resources are whole numbers and requests must equal limits. 250 is a quarter core of scheduler accounting only: the plugin still adds one whole shared CPU, and there is no hard cap. A pod asking 100 on a node with two shared CPUs gets one of them; 1,001 to 2,000 gets both. Pods given the same shared CPU split it by their cgroups’ cpu.weight (from the cpu request), not by M: two pods measured 0.33 : 0.66 on one shared CPU (fractional shared CPUs).

To reserve little and spread wide, add ergon.io/shared-burst-cpus: B beside M (for example 50 and 2: the node reserves 50 millicpus, the cpuset spans 2 shared CPUs). It is a carrier for the number, because Kubernetes forces request equal to limit on an extended resource. The plugin sets no quota and no weight: the kernel gives the idle time. A burst below ceil(M/1000), above the node’s shared CPUs, or with no M is refused at create, and the message names the fix. The node advertises 256 burst IDs for each shared CPU and a pod uses B of them, so pods that burst fit as long as their total B stays within 256 x shared CPUs; past that a pod is Pending, never refused.

Animation, in words: an illustrative 8-CPU node has CPU 0 for NIC interrupts, CPUs 1 and 2 as the shared CPUs, and CPUs 3 to 7 in the static CPU manager’s pool; the millicpu values are illustrative and the selection follows internal/assign/assign.go. Pod A (cpu: 2, 250 m) gets exclusive CPUs 3 and 4 from the kubelet. Need(250) is 1; Choose finds no remembered set, sorts the shared CPUs by load (both 0, ties to the lower number) and picks CPU 1; Hold books 250 m there. The cgroup gets 1,3-4, the env lists the two sets apart. Pod B (cpu: 2, 1,500 m) gets 5 and 6; Need(1500) is 2, so it takes both shared CPUs and Split books 750 m on each: CPU 1 reads 1,000 m, which is accounting, not a cap. Before A’s program starts, the hook sets 1 ns timer slack on the container’s init and pins it to CPU 1; the app’s later threads copy both, and the hot thread pins itself to index 0 of ERGON_ISOLATED_CPUS, CPU 3. A’s container stops: Release drops its 250 m and keeps its remembered set. Pod C (cpu: 1, 250 m) breaks the 750 m tie to CPU 1. A restarts with a new container ID and the same key, and Choose returns the remembered CPU 1 without sorting, although CPU 2 is lighter. Deleting pod A calls ForgetPod, which clears the remembered set; otherwise only a plugin restart does, since Synchronize rebuilds the table from live containers. A side panel shows the two timer-slack settings below. Operation counts come from the code; they are not timings.

Timer slack

The kernel’s default timer slack is 50,000 ns. It is added to every sleep and to every epoll/io_uring timeout. The hook sets 1 ns, the kernel’s floor, on every thread the container has when it starts; the kernel copies it to every thread and child after that. A container that cannot have it does not start. The OCI hook runs as root, so it can write /proc/<tid>/timerslack_ns; a program can always set its own slack with prctl(PR_SET_TIMERSLACK).

The 1 ns slack takes the kernel’s 50 µs default off every sleep; its measured effect is not recorded here. The loop spins and never sleeps; the slack applies to sleeping helpers such as Aeron’s conductor. A thread a pod starts with kubectl exec has the kernel’s 50 µs, not the hook’s 1 ns.

Node setup

Do this before installing the plugin. Everything here is per node. The rest of the node checklist is Latency Pods: node setup.

settingvalue
Kubernetes>= 1.33: no CPU quota on exclusive containers (the labs ran 1.36)
kubeletcpuManagerPolicy: static; x86 full-pcpus-only; reservedSystemCPUs = the IRQ CPU(s) + the shared CPUs; cpuCFSQuota not false; feature gate DisableCPUQuotaWithExclusiveCPUs not false
kubelet config file/var/lib/kubelet/config.yaml (kubeadm, kind). The plugin pod does not start without it. Another path: --set hostContract.kubeletConfig.path=<file>. A kubelet run with --config-dir also needs hostContract.kubeletConfigDir; EKS AL2023: Use the public chart
kernel>= 6.2, cgroup v2. Boot line: isolcpus=managed_irq,domain, nohz_full and rcu_nocbs on every CPU outside reservedSystemCPUs, never on the shared ones. A cpu-partition opt-in also needs cpuset.cpus.exclusive: Linux 6.7, or a vendor kernel that backported that file. The plugin reads the file, not the version
NIC IRQsevery hardware NIC IRQ, requested and effective affinity, on the IRQ CPU(s): reservedSystemCPUs minus sharedCpus
isolated-CPU noiseTHP never and the fair server’s runtime 0 on each isolated CPU, at every boot (below). The plugin does not check them
containerd>= 2.2, NRI on, default validator on
node labelergon.io/shared-cpus=true

A pod labelled ergon.io/latency: hot is checked against the kubelet, kernel and NIC IRQ rows at every create: its exclusive CPUs must be in /sys/devices/system/cpu/isolated, the shared CPUs online and outside isolated and nohz_full. A miss refuses that create (CreateContainerError, naming the rule). Unlabelled pods get the same grants without the check.

CPU split. Pick three CPU sets on the node and write them down; every later step names one of them.

setwhoexample (8 CPUs)
exclusivethe pod’s busy-spin loops2,3 (and 4,5 for a second pod)
sharedhelpers, kubelet, containerd, system0
IRQNIC interrupts1

Kernel boot line. Isolate the exclusive CPUs only. Never the shared one.

nohz_full=2-5 rcu_nocbs=2-5 isolcpus=managed_irq,domain,2-5

kubelet: reservedSystemCPUs: "0,1" (shared + IRQ) with the policy above. Restart kubelet and check it took.

containerd: NRI on (disable = false) and the default validator on. The validator is what makes an unmet required-plugins annotation fail the create instead of starting the pod half-granted. Leave required_plugins empty: a node-wide list would also block kube-system pods and the plugin’s own pod while it is down. Leave tolerate_missing_plugins_annotation unset: a pod that carries the annotation it names skips the check, and the admission policy does not know that name.

Quiet isolated CPUs

The lab’s kernel trace named two sources of work sent to an isolated CPU that the boot line leaves on (what reached it, and the fix):

settingvaluewhynote
/sys/kernel/mm/transparent_hugepage/enablednever (madvise still runs khugepaged)khugepaged calls lru_add_drain_all: a kworker on every CPU with queued pagesor transparent_hugepage=never on the boot line
/sys/kernel/debug/sched/fair_server/cpu<N>/runtime, each isolated N0the fair server’s 1 s timer: a nohz kick and a reschedule IPI, and the tick kept onkernel 6.12+; debugfs, so lost at reboot: a oneshot unit after sys-kernel-debug.mount; safe only where nothing real-time runs on those CPUs

Apply both at every boot from a oneshot unit, and check them read-only after it runs.

Keep node events out of trading hours. Anything that calls lru_add_drain_all (block-device ioctls, systemctl daemon-reload and generators, mlock, page migration) or loads a BPF program (systemd units, a container start with seccomp, an SSH login) still reaches every isolated CPU. A systemd daily timer did both in the lab: a 40.60 µs max and one involuntary switch.

sourcerule
systemd daily timersmove them out of trading hours (systemctl list-timers)
pod churnno pod starts or restarts on the node during trading
loginsno SSH logins to the node during trading

Check the node with ergon-tune

ergon-tune reads the host and changes nothing. Every finding names what is wrong and the fix. Run it on the node, with the exclusive CPUs of the pods, the data NIC and the instance family:

ergon-tune --hot <exclusive CPUs> --nic <data NIC> --family <c7i|c7a|c8g|c9g> --tcp

Or from a pod that mounts the node’s root at /host:

ergon-tune --root /host --hot <exclusive CPUs> --require

The plugin and ergon-tune are two halves of one job: ergon-tune checks the node and the pod (isolated CPUs, CPU quotas, SMT, NIC interrupts, clocks), the plugin hands out the CPUs and refuses a hot pod that breaks the node contract.

The order to work in, on one node:

  1. Node settings: the table above.
  2. ergon-tune on the node; fix every finding.
  3. Install the chart (Use the public chart).
  4. ergon-cpus explain in the plugin pod: every failed hot-node check with its fix.
  5. The app’s start-up check: ERGON_HOST_CHECKS=require (the switch) refuses to start on a node that fails.

Step 4, in the plugin pod on that node:

kubectl -n ergon-system exec pod/<plugin pod> -- /ergon-cpus explain \
  --config /etc/ergon-shared-cpus/config.yaml \
  --kubelet-config /host/kubelet-config --host-sys /host/sys --host-proc /host/proc

On EKS AL2023 the kubelet settings sit in a drop-in directory, so add --kubelet-config-dir /host/kubelet-config-dir (the chart mounts it when hostContract.kubeletConfigDir.enabled is set), or explain reports different kubelet settings from the ones the plugin reads.

Install on Kubernetes

The plugin is public. No image pull secret.

whataddress
imageghcr.io/mimran1980/ergon-shared-cpus:0.1.6 (and :latest)
digest of 0.1.6 and latestsha256:2b384eded978bf638bc5da981fda0538ef24edffb35229889e284e5bd1bbff91
chartoci://ghcr.io/mimran1980/charts/ergon-shared-cpus version 0.1.6
helm install ergon-shared-cpus oci://ghcr.io/mimran1980/charts/ergon-shared-cpus \
  --version 0.1.6 \
  --namespace ergon-system --create-namespace \
  --set-string config.sharedCpus=0 \
  --set 'config.namespaces={trading}' \
  --set hostContract.kubeletConfig.enabled=true \
  --set hostContract.sys.enabled=true \
  --set hostContract.proc.enabled=true

config.sharedCpus is this node’s shared CPU. For the 8-CPU split above that is 0: inside reservedSystemCPUs, and not the IRQ CPU. The chart creates ergon-system with the privileged Pod Security labels and selects nodes labelled ergon.io/shared-cpus=true. It does not label nodes, and it does not set the boot line, the kubelet, or containerd.

Do the node setup above first, then the steps below. The public install is Use the public chart. Step 4 below is the local image ergon-shared-cpus:dev. The kind sample that pulls the public chart is See it on kind.

1. Label the nodes that take the plugin

kubectl label node <node> ergon.io/shared-cpus=true

Only labelled nodes run the DaemonSet. A pod that asks for the device on an unlabelled node stays pending.

2. Edit deploy/configmap.yaml

This is the step people get wrong. The file is k8s/nri-shared-cpus/deploy/configmap.yaml, and it becomes /etc/ergon-shared-cpus/config.yaml in the plugin’s container.

sharedCpus: "0"          # the node's shared CPUs, kernel cpulist
oversubscription: 1
namespaces: ["trading"]  # who may opt in. Empty refuses every pod
defaultAffinity: shared
annotationOptIn: false
devRoot: /host/dev       # where the DaemonSet mounts the host's /dev; without
                         # it the plugin finds no PHC and refuses ptp grants

# These three are "off" by default. A latency node turns the first two on.
# Each one is a node-level permission: the pod still opts in by annotation,
# and a pod that asks for a grant this field does not allow is refused.
seccomp:
  ioUring: "allow"       # default "off". Without it, a pod asking for
                         # seccomp.ergon.io/<ctr>: "io-uring" is refused.
                         # For apps that use io_uring. Aeron's C media
                         # driver does not use it. Needs containerd 2.3
                         # or later (earlier ones are refused)
ptp: "auto"              # default "off". Without it, a pod asking for
                         # ptp.ergon.io/<ctr> is refused. "auto" allows any
                         # PHC the node has; a /dev/ptp* path allows only that
                         # one. The grant is read-only, root included,
                         # and needs containerd 2.2 or later

Rules:

  • sharedCpus must sit inside the kubelet’s reservedSystemCPUs, minus the IRQ CPU(s). In the table above that is 0.
  • namespaces is an allowlist. Create those namespaces before applying.
  • Quote off, on, yes, no. YAML 1.1 turns unquoted ones into booleans.
  • An unknown field or an out-of-range value stops the plugin at start, and the message names the field.
  • off is not harmless. It is a refusal. A pod whose annotation asks for a grant the ConfigMap does not allow does not start: the kubelet shows CreateContainerError and the text names the field to change.

3. Install the public chart

Use the helm install at the top of this section. One Helm release per shared-CPU layout: the chart has one ConfigMap.

The plugin is root on the node and installs an executable at /opt/ergon/bin/ergon-cpus. Only this repository’s publish workflow pushes.

Kind, or a node with no registry: docker build -t ergon-shared-cpus:dev . from k8s/nri-shared-cpus, load that image, and apply the three manifests in the next step. deploy/daemonset.yaml ships image: ergon-shared-cpus:dev with imagePullPolicy: IfNotPresent.

4. Apply the three manifests

Skip this when the Helm release above is installed. It is the kind path.

kubectl apply -f deploy/namespace.yaml \
              -f deploy/configmap.yaml \
              -f deploy/daemonset.yaml

The :dev DaemonSet needs eight host paths: /var/run/nri, /var/lib/kubelet/device-plugins and /opt/ergon/bin read-write, plus /dev at /host/dev, the host cgroup v2 tree at /sys/fs/cgroup, /var/lib/kubelet/config.yaml at /host/kubelet-config, /sys at /host/sys and /proc at /host/proc, the last five read-only. The kubelet file is a File mount: the pod does not start when that path is missing. The namespace is labelled Pod Security privileged for that reason. The plugin is root on the node: anything on the NRI socket can change any container.

5. Verify the plugin before any workload

The pod is Ready on every labelled node, allocatable shows ergon.io/shared-millicpus greater than zero, /readyz is healthy, and the logs show no config error (strict YAML: a bad field stops it). If allocatable is empty the device plugin did not register: check the logs and that /var/lib/kubelet/device-plugins is mounted.

6. Run a pod and check the grants landed

Use the pod under Pod. Inside it:

kubectl exec trader -- sh -c 'echo isolated=$ERGON_ISOLATED_CPUS shared=$ERGON_SHARED_CPUS'
kubectl exec trader -- cat /proc/1/status | grep Cpus_allowed_list

Cpus_allowed_list must print the shared CPUs only. That is the point of the plugin.

Config

/etc/ergon-shared-cpus/config.yaml, from the ConfigMap. Strict YAML: an unknown field is an error at start. No hot reload. A ConfigMap edit does not roll the DaemonSet. Drain trading workloads, then set layoutRevision (or restart the pods), before a new CPU layout is used. Running grants stay as they were at create.

fielddefaultwhat it is
sharedCpusrequiredthe housekeeping CPUs, kernel cpulist ("4" or "0,2"). Inside reservedSystemCPUs, never the IRQ CPU(s)
oversubscription11–100. Capacity is len(sharedCpus) x 1000 x this; the max is 100,000 device IDs (the kubelet’s 4 MiB gRPC limit)
namespacesemptythe allowlist. Empty refuses every opt-in. Each must be a valid namespace name
defaultAffinitysharedshared injects the hook that starts every thread on the shared CPUs. all injects nothing; use the ergon-cpus wrapper (see Bottlerocket below)
hookPath/opt/ergon/bin/ergon-cpuswhere the daemon writes the hook on the node. Must be a clean absolute path ending in /ergon-cpus; the daemon writes it as root, so the name is fixed
annotationOptInfalseallow the pod annotation cpu-shared.ergon.io/<container> as a fallback when the device plugin is not used
metricsAddress:9466serves /metrics, /healthz and /readyz
rlimits.memlock, .nofile, .rtPrio, .niceunsetthe ceiling a pod may ask for by kind. "inf" or a positive count. The pod asks for kinds, never values
seccomp.ioUring (nested: seccomp: then ioUring:)offallow widens the container’s seccomp profile for io_uring_*. See Latency Pods
seccompProfilePath/etc/ergon-shared-cpus/ergon-io-uring.jsonthe shipped io_uring profile on the node, the fallback for a pod that cannot take the NRI grant
devRoot/devwhere this process sees the host’s /dev. The DaemonSet mounts it read-only at /host/dev so the plugin can stat the PHC and PM QoS nodes; granted paths stay /dev/...
ptpoffoff, auto, or a /dev/ptp* path the node has. auto grants the NIC’s PHC
hugepagesAeronDirunsetabsolute AERON_DIR to export when the pod mounts a sized hugetlbfs

cgroupRoot is not a field. The parser rejects it. The binary uses /sys/fs/cgroup, and the DaemonSet mounts the host cgroup tree read-only at that path. The createRuntime hook matches the same path against /proc/<pid>/cgroup.

The chart can also write profiles and nodeProfileLabel instead of the flat fields. At startup the binary reads its node once and uses the label’s value as the profile name. A missing or unknown label stops the process. It does not watch the node and it does not change the label. Setting sharedCpus and profiles in the same file is rejected. Drain before changing a label or a profile. Containers that are already running keep the helper CPUs recorded at create. This selection was not run on a multi-node cluster.

Quote off, on, yes and no in this file. YAML 1.1 turns unquoted ones into booleans.

Unknown fields and out-of-range values are refused at start, each naming its field: oversubscription outside 1–100, a namespaces entry that is not a namespace name, hookPath not ending in /ergon-cpus, an rlimits value that is neither inf nor a positive count, ptp / seccomp.ioUring outside their sets. A schedFifo key from an older release is refused the same way.

Pod

apiVersion: v1
kind: Pod
metadata:
  name: trader
  namespace: trading                       # must be in the plugin's allowlist
  annotations:
    required-plugins.noderesource.dev: '["ergon-shared-cpus"]'
spec:
  nodeSelector: { ergon.io/shared-cpus: "true" }
  containers:
  - name: app
    image: my-app
    resources:
      requests: { cpu: "2", memory: 1Gi, ergon.io/shared-millicpus: "250" }
      limits:   { cpu: "2", memory: 1Gi, ergon.io/shared-millicpus: "250" }

Inside the container:

itemvalue
cpuset.cpus.effectivethe exclusive CPUs plus the shared ones
affinity of PID 1 and of every new threadthe shared CPUs only
nproc, GOMAXPROCS, availableProcessors()usually the shared CPUs: they count the affinity mask

Env vars

namevalueformat
ERGON_ISOLATED_CPUSthe exclusive CPUssorted comma list, no ranges: 1,5
ERGON_SHARED_CPUSthis container’s shared CPUssame
ERGON_ISOLATED_CORESthe exclusive CPUs by physical coregroups by ;, CPUs by ,: 1,5;2,6
ERGON_SHARED_MILLICPUSMdecimal
ERGON_SHARED_BURST_CPUSB, only when the pod asked for a burstdecimal, CPUs
ERGON_HELPER_CPUSsame as ERGON_SHARED_CPUScomma list
OPENSHIFT_ISOLATED_CPUSsame as ERGON_ISOLATED_CPUSkernel cpulist with ranges
OPENSHIFT_SHARED_CPUSsame as ERGON_SHARED_CPUSsame

Read the CPUs from these variables or from cpuset.cpus.effective, never from the process’s own affinity: the start mask is the shared CPUs.

Pinning by index

Pin each hot thread to isolated index i. The app never needs the real CPU numbers.

/* SPDX-License-Identifier: Apache-2.0 */
/*
 * Pin a hot thread by index into ERGON_ISOLATED_CPUS. Leave helpers alone:
 * every thread already starts on the shared CPUs.
 *
 * Build:  cc -O2 -o pin pin.c
 * Run:    in a container that asked for ergon.io/shared-millicpus.
 */
#define _GNU_SOURCE
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

/* The i-th number of a list like "1,5"; -1 if there is none. */
static int nth_cpu(const char *list, int i)
{
    if (list == NULL)
        return -1;
    for (const char *p = list; *p != '\0'; i--) {
        char *end;
        long cpu = strtol(p, &end, 10);
        if (end == p)
            return -1;
        if (i == 0)
            return (int)cpu;
        p = (*end == ',') ? end + 1 : "";
    }
    return -1;
}

/* Pin the calling thread to isolated CPU index i. Returns the CPU, or -1. */
int pin_isolated(int i)
{
    int cpu = nth_cpu(getenv("ERGON_ISOLATED_CPUS"), i);
    if (cpu < 0)
        return -1;
    cpu_set_t set;
    CPU_ZERO(&set);
    CPU_SET(cpu, &set);
    return sched_setaffinity(0, sizeof set, &set) == 0 ? cpu : -1;
}

/* Report which CPU the calling thread is on and where its mask is. */
static void report(const char *who)
{
    int now = sched_getcpu();
    cpu_set_t set;
    CPU_ZERO(&set);
    if (sched_getaffinity(0, sizeof set, &set) != 0) {
        perror("sched_getaffinity");
        return;
    }
    printf("%s: running on cpu %d, mask", who, now);
    for (int c = 0; c < CPU_SETSIZE; c++)
        if (CPU_ISSET(c, &set))
            printf(" %d", c);
    printf("\n");
}

int main(void)
{
    const char *iso = getenv("ERGON_ISOLATED_CPUS");
    const char *sh = getenv("ERGON_SHARED_CPUS");
    printf("ERGON_ISOLATED_CPUS=%s\nERGON_SHARED_CPUS=%s\n",
           iso ? iso : "(unset)", sh ? sh : "(unset)");

    /* Every thread starts on the shared CPUs. */
    report("helper (default)");

    /* Pin the hot thread to isolated index 0. */
    int cpu = pin_isolated(0);
    if (cpu < 0) {
        fprintf(stderr, "pin_isolated(0) failed\n");
        return 1;
    }
    printf("pinned the hot thread to isolated index 0 = cpu %d\n", cpu);
    report("hot (pinned)");

    /* Index 1, when the pod asked for more than one CPU. */
    int cpu1 = pin_isolated(1);
    if (cpu1 >= 0) {
        printf("isolated index 1 = cpu %d\n", cpu1);
        report("hot2 (pinned)");
    }
    return 0;
}

In Rust the ergo-cpus crate (cpus/, not released yet) reads these variables, pins by index, and has an AffinityGuard that puts a pinned hot thread on the shared CPUs while it creates helpers. It needs no unsafe.

Rules:

  • leave helpers alone: they start on the shared CPUs;
  • create helpers from a thread that is still on the shared set (a new thread copies its creator’s mask);
  • each sleepy helper checks sched_getcpu() when it wakes and alarms if it is not on ERGON_SHARED_CPUS;
  • never a spinner or SQPOLL on a shared CPU. Give SQPOLL a CPU of the pod’s own outside ERGON_HELPER_CPUS, and refuse to start when there is none;
  • two indices are two physical cores only when they are two groups in ERGON_ISOLATED_CORES. On SMT, 1,5 is one core and its two threads share every execution unit: two “hot cores” there is one hot core.

A core is never split between the exclusive and the shared CPUs. On SMT the hot thread and the helpers would time-share one physical core, which is the contention this whole setup exists to remove. The plugin refuses such a container rather than start it claiming an isolation it does not have. On x86 keep SMT off, or use full-pcpus-only and put whole cores in reservedSystemCPUs and in sharedCpus. On an SMT node the node contract checks this up front: smt-whole-cores (the shared and reserved CPUs are whole cores) and smt-full-pcpus-only (the kubelet runs static with full-pcpus-only) fail a hot pod with the value seen, the value needed and the fix. Without SMT both rows are skipped. The rows read what the kubelet runs with: the kubelet process’s own argv from the host proc (flags such as --cpu-manager-policy-options and --reserved-cpus override the file; every kubelet process found is checked, and one with the option off fails the row), the /configz copy when mounted (a static copy: when it disagrees with the live argv the row fails and says to refresh it), and the kubelet file and its drop-ins. When no kubelet process is found and no configz is mounted, ergon-cpus explain says that flag overrides are unverifiable and which chart value enables each source.

Worked example: an Aeron media driver

Two pinned cores (sender and receiver) plus the conductor on the shared CPU, with huge pages. This is the layout a latency node wants.

Node boot line (from the table above), for exclusive CPUs 2 and 3, shared 0, IRQ 1:

nohz_full=2-3 rcu_nocbs=2-3 isolcpus=managed_irq,domain,2-3 hugepagesz=2M hugepages=512

ConfigMap (sharedCpus: "0"), kubelet (reservedSystemCPUs: "0,1"), and a namespace in the allowlist.

Pod. Three grants on top of the shared CPU: a sized hugetlbfs for AERON_DIR, io_uring seccomp, and the NIC PHC. The isolation of CPUs 2-3 comes from the boot line, not from a grant: cpu-partition needs the program to move its own threads between cgroups (Latency Pods), and the media driver does not.

apiVersion: v1
kind: Pod
metadata:
  name: aeron-driver
  namespace: trading
  labels: { ergon.io/latency: "hot" }
  annotations:
    required-plugins.noderesource.dev: '["ergon-shared-cpus"]'
    hugepages.ergon.io/app: "2M"          # sized hugetlbfs for AERON_DIR
    seccomp.ergon.io/app: "io-uring"      # for apps that use io_uring; Aeron does not
    ptp.ergon.io/app: "auto"              # the NIC's PHC
spec:
  nodeSelector: { ergon.io/shared-cpus: "true" }
  priorityClassName: ergon-hot              # k8s/nri-latency-pods/admission/priority-class.yaml
  containers:
  - name: app
    image: ergon-media-driver:dev
    command: ["ergon-cpus",
              "--env", "AERON_SENDER_CPU_AFFINITY=isolated:0",
              "--env", "AERON_RECEIVER_CPU_AFFINITY=isolated:1",
              "--", "media_driver"]       # rusteron-media-driver's binary
    env:
    - { name: AERON_THREADING_MODE, value: DEDICATED }
    - { name: AERON_DIR, value: /dev/hugepages/aeron }   # set by the app, see below
    resources:
      requests: { cpu: "2", memory: 2Gi, ergon.io/shared-millicpus: "250", hugepages-2Mi: 256Mi }
      limits:   { cpu: "2", memory: 2Gi, ergon.io/shared-millicpus: "250", hugepages-2Mi: 256Mi }

What each piece does:

pieceeffect
cpu: "2"two exclusive CPUs from the static CPU manager: the sender’s and the receiver’s
ergon.io/shared-millicpus: "250"the plugin adds the shared CPU and starts every thread there
AERON_SENDER_CPU_AFFINITY=isolated:0sender on the pod’s first exclusive CPU
AERON_RECEIVER_CPU_AFFINITY=isolated:1receiver on its second
media_driverthe C media driver, as built by rusteron-media-driver (cargo install rusteron-media-driver --features static); it reads the same AERON_* variables as Aeron’s aeronmd, which works here too
AERON_CONDUCTOR_CPU_AFFINITY unsetthe conductor stays on the shared CPU
AERON_THREADING_MODE=DEDICATEDsender, receiver and conductor on their own threads
hugepages.ergon.io/app: "2M" + hugepages-2Mia sized hugetlbfs mounted at /dev/hugepages
AERON_DIR on that hugetlbfsthe CnC file and the terms are 2 MiB pages, not 4 KiB
seccomp.ergon.io/app: "io-uring"the profile gains the io_uring_* calls an app that uses io_uring needs; never Unconfined
ptp.ergon.io/app: "auto"the NIC’s PHC, for clock work
ergon.io/latency: "hot" (pod label)the admission policy refuses exec probes and restartPolicy: Always sidecars
isolcpus=managed_irq,domain,2-3 on the boot lineCPUs 2-3 leave the scheduler’s load-balancing domains (settings)

The app sets AERON_DIR itself. The plugin exports ERGON_HUGEPAGES_DIR, ERGON_HUGEPAGE_SIZE, AERON_FILE_PAGE_SIZE=2097152 and AERON_TERM_BUFFER_SPARSE_FILE=false. It does not set AERON_DIR, because the app must create the subdirectory:

mkdir -p "$ERGON_HUGEPAGES_DIR/aeron"
export AERON_DIR="$ERGON_HUGEPAGES_DIR/aeron"

An unsized hugetlbfs (what emptyDir: {medium: HugePages} gives you) is rejected by Aeron. That is why the size comes from the annotation.

Affinity variables:

variableagenthere
AERON_SENDER_CPU_AFFINITYsenderisolated:0
AERON_RECEIVER_CPU_AFFINITYreceiverisolated:1
AERON_CONDUCTOR_CPU_AFFINITYconductorleave unset: it starts on the shared CPUs
AERON_DRIVER_NATIVE_RESOURCE_AGENT_CPU_AFFINITYnative resource agentleave unset
AERON_THREAD_AFFINITY_USE_CPUSET_OFFSETS (before Aeron 1.54: AERON_DRIVER_CPUSET_AFFINITY)makes the four above offsets into the cgroup cpusetkeep false; the wrapper refuses to translate when either is true

isolated:0 is an index, not a CPU number. cpu: "2" gives the pod two exclusive CPUs; the static CPU manager picks which (here 2 and 3, on another node maybe 5 and 9) and the plugin lists them, sorted, in ERGON_ISOLATED_CPUS. isolated:<i> is position i in that list, counted from 0, so the manifest stays the same on every node:

ERGON_ISOLATED_CPUSisolated:0isolated:1isolated:2
2,3CPU 2CPU 3refused: the pod has 2
5,9CPU 5CPU 9refused

ergon-cpus turns each spec into the real CPU number and sets the variable to it (AERON_SENDER_CPU_AFFINITY=2) before exec, so the driver sees a plain number and needs no offset mode. An index past the list is an error, not a wrap. It also sets its own affinity to the shared CPUs, so the driver starts there.

Check it worked:

kubectl exec aeron-driver -- sh -c 'echo isolated=$ERGON_ISOLATED_CPUS shared=$ERGON_SHARED_CPUS'
kubectl exec aeron-driver -- sh -c 'echo hugepages=$ERGON_HUGEPAGES_DIR size=$ERGON_HUGEPAGE_SIZE'
kubectl exec aeron-driver -- sh -c 'ps -L -o pid,tid,psr,comm | head'

psr must show the sender and receiver on 2 and 3 and every other thread on 0. mount | grep hugepages must show a size, not just hugetlbfs.

Fractional shared CPUs

  • Extended resources are whole numbers and requests must equal limits, so the unit is millicpus: 250 = a quarter.
  • The plugin adds ceil(M/1000) shared CPUs, at least one. It does not grant the whole helper set unless M = 1000 × |S|. With oversubscription: 1 that request takes every configured helper CPU, using the same allocator.
  • A reconnect keeps the helper CPUs recorded at create. It does not pick replacements for a container that is already running.
  • The fraction is scheduler accounting only. With 2 shared CPUs and oversubscription 2, a node offers 4000; sixteen pods at 250 fit.
  • There is no hard cap. Helpers may use the whole shared CPU, shared with the kubelet, containerd, system daemons and other pods.
  • Measured on two shared CPUs, busy helpers: 100 millicpus got one shared CPU and used 0.99 cores of it, 1,001 got both and used 1.99, idle helpers 0.04; nr_throttled 0. Two pods on one shared CPU (cpu: 1 and cpu: 2, 100 millicpus each) split it 0.33 : 0.66, by cgroup cpu.weight from the integer cpu request, not by millicpus (scaling).
  • A helper wake-up on a shared CPU waits on the node’s other load; the size of that wait is not measured. It slows connects and the conductor, not the loop.

Fail closed

eventeffectguard
plugin down at createNRI makes no changerequired-plugins.noderesource.dev makes the create fail; the wrapper refuses without ERGON_SHARED_CPUS; the resource does not allocate
kubelet restart, plugin upthe re-write keeps the unionthe plugin re-widens in UpdateContainer
kubelet restart, plugin downcpuset shrinks to the exclusive CPUs; helpers fall onto them until the plugin is backnothing prevents it. The pod detects it and leaves Ready (below); Synchronize re-widens on reconnect
sharedCpus outside reservedSystemCPUsevery shared-CPU opt-in is refused, hot or notthe kubelet config, when mounted. hotContract.mode: warn lets it go on
a node check overruns the NRI request timeoutthe create is refused (warned in warn mode)the plugin cuts the check off in time
host drifta new hot create is refusedthe plugin stays connected. /healthz stays up. This is not a liveness restart
hook binary missingthe create failsthe DaemonSet installs the binary before it connects

Running pods during a plugin outage

required-plugins protects creation, not a pod that is already running. While the plugin is down, a kubelet restart rewrites the cpuset to the exclusive CPUs only. Every helper thread moves onto them and competes with the loop until the plugin reconnects.

The contract:

  • Detection is in the pod. Placement holds while cpuset.cpus.effective contains ERGON_ISOLATED_CPUS and ERGON_SHARED_CPUS. In a cpu-partition pod the partition holds the exclusive CPUs, and the probe also requires the ergon-isolated child’s cpuset.cpus.partition to read isolated, not isolated invalid. During the outage nothing on the node is running to report a shrunk cpuset.
  • Pod spec. Start the app as ergon-cpus --ready-addr :8086 -- <app> and add an httpGet readiness probe on :8086/placement (periodSeconds: 1, failureThreshold: 1). The admission policy denies exec probes on hot pods; an httpGet probe runs from the kubelet. The endpoint answers 503 placement broken: <reason> while a list is missing or the partition is invalid, and 200 placement verified otherwise. The endpoint listens on every interface (the kubelet probes the pod IP) and returns the CPU lists; on a hostNetwork pod choose a port that is free on the node.
  • App. While the endpoint answers 503, stop the work that needs the exclusive CPUs. A helper thread can poll it on localhost or make the same comparison itself; the hot thread never does.
  • Node. On reconnect the plugin’s Synchronize re-widens every managed container and counts it in ergon_shared_cpus_rewidened_total{event="sync"}. The counter belongs to the plugin process, starts at 0 and goes up only when a container had lost its shared CPUs. Alert on ergon_shared_cpus_rewidened_total{event="sync"} > 0 (or on the plugin’s sync: re-widen log line), not on increase(): the re-widen comes right after a new plugin pod connects, usually before its first scrape, and increase() ignores a new series’ first sample. The alert keeps firing until that plugin pod restarts. The pod is Ready again only once its cpuset holds both lists. In the e2e the helper was back on its shared CPU by then. test/e2e.sh steps 9, 10 and 18 check this on kind and time it (plugin outage timings).

Limits and what is not verified

  • The plugin is root on the node. With the install flags the chart mounts eight host paths: /var/run/nri, /var/lib/kubelet/device-plugins and /opt/ergon/bin read-write; the host’s /dev at /host/dev, /sys/fs/cgroup, the kubelet config, /sys and /proc read-only. The :dev manifest mounts the same. No hostPID, no hostNetwork, not privileged, capabilities.drop: [ALL], readOnlyRootFilesystem: true, seccomp RuntimeDefault. API access only to create Events (chart events.enabled, default on; off removes --events and the RBAC, and the token too unless config.profiles needs it), plus a get-only ClusterRole on nodes when config.profiles is set. Only namespaces in the allowlist may opt in.
  • AKS has no supported way to enable containerd NRI plugins and no reservedSystemCPUs. Not supported.
  • CRI-O users use its shared_cpuset instead.
  • Bottlerocket: whether runc may exec a hook binary that a pod wrote to a host path is not verified. Use defaultAffinity: all and the wrapper until checked.
  • kubectl exec and exec probes start on any CPU of the cpuset, exclusive ones included. No exec probes on hot containers; run debug commands as ergon-cpus -- <cmd>.
  • In-place CPU resize leaves the CPU env stale. Use resizePolicy: RestartContainer for cpu.
  • EKS AL2023: the kubelet settings are in a config.json.d/ drop-in, so hot pods need kubeletConfigDir (Use the public chart). Without it every hot pod is refused there; unlabelled pods get the grants.
  • The plugin cannot see the kubelet’s command line. A kubeletConfigDir the kubelet does not read (no --config-dir) makes the check trust drop-ins the kubelet ignores; kubeletConfigZ with a fresh /configz copy cross-checks.
  • Measured on one Azure Cobalt VM: the exclusive core with the plugin on, helpers on the shared CPU and the quiet-CPU settings: p50 0.02 µs, p99.99 0.03 µs, max 4.81 to 5.52 µs over 3 reps of 60 s, 0 involuntary switches, no interrupt on the spin’s CPU; the gaps left have no guest event (the hypervisor’s 3.5 to 5.5 µs floor) (benchmarks).
  • Verified on EKS AL2023 (runs eks-nri-20261025-070515, eks-nri-20261025-082023): the NRI socket, nodeadm TOML merge, the kubelet drop-in merge, /opt writable, system-node-critical outside kube-system. A warm ENI the VPC CNI attaches after boot came up with its IRQs on the shared CPU, and the plugin refused hot pods until they were re-pinned: pin IRQs again after the CNI attaches an ENI.
  • Not measured: how often node events reach isolated CPUs in production; the spin loop on EKS.

Decision. Use it on kind or a self-managed node where you can set reservedSystemCPUs and enable NRI. With the quiet-CPU settings the exclusive cores took no context switch and nothing above the hypervisor’s 5.5 µs in steady state; keep node events out of trading hours. Not for AKS or CRI-O.