cpuunclaimed(8)

πŸ“¦ version 0.36.1, in alpine 3.24, nixpkgs unstable, opensuse-leap 16.0

✨ NAME ✨

bestie, this is the System Manager's Manual page for cpuunclaimed(8) πŸŽ€ It's a tool that samples CPU run queues and works out unclaimed idle CPU. It uses Linux eBPF/bcc, so it's giving low-level Linux tracing energy πŸ’œ

πŸ¦‹ SYNOPSIS πŸ¦‹

cpuunclaimed [-T] [-j] [-J] [interval [count]]

πŸ’– DESCRIPTION πŸ’–

okay so this tool samples the length of the run queues and figures out when there are idle CPUs πŸ‘€ but there are also threads queued up waiting for their turn. That's the real tea β˜• It reports the leftover idle CPU (the stuff that isn't being claimed by waiting threads) as a system-wide percentage.

This can happen for a few reasons, and they're kinda iconic 😭

  • An application got bound to some CPUs but not all of them, so its runnable threads can't hop over to the other CPUs because of that setup πŸ™ˆ
  • CPU affinity 🧚 This is an optimization that keeps threads on the CPUs where the caches are still warm, even if that means a short wait while other CPUs sit idle. The wait period is tunable (see sysctl, kernel.sched*) ✨
  • Scheduler bugs πŸ’€

Here's the vibe check: an unclaimed idle below 1% is probably CPU affinity, and honestly not usually something to stress about πŸ’… Leaving the CPU idle can even improve overall system throughput. This tool is best at spotting the bigger issues, like anything above 2%, because its samples only fire at 99 Hertz so it's kinda coarse 🌸

This tool is experimental πŸ§ͺ It works by sampling to keep overhead low, and it leans on a few assumptions:

  • CPU samples consistently fire around the same offset πŸ•°οΈ Sometimes there's a lag because higher-priority interrupts delay a sample, but the later samples are expected to catch back up to the expected offsets (and that's what happens in practice). You can use -J to inspect sample offsets. Some systems power down CPUs when idle, and when those CPUs wake up they may start firing at a skewed offset. When that happens this tool detects the skew, prints an error, and exits 😭
  • All CPUs are online (see ncpu) 🌈

If it flags unclaimed CPU, you can double-check by dumping the raw samples with -j, and you can also use other tracing tools to instrument scheduler events. Heads up though, that second approach has way higher overhead πŸ‘€

Since this uses BPF, only the root user can run this tool. No exceptions, bestie πŸ”₯

πŸŽ€ REQUIREMENTS πŸŽ€

You'll need CONFIG_BPF and bcc πŸ’œ

πŸ“ EXAMPLES πŸ“

Sample and calculate unclaimed idle CPUs, output every 1 second (default:

# cpuunclaimed

Print 5 second summaries, 10 times:

# cpuunclaimed 5 10

Print 1 second summaries with timestamps:

# cpuunclaimed -T 1

Raw dump of all samples (verbose), as comma-separated values:

# cpuunclaimed -j

🌷 FIELDS 🌷

  • %CPU β€” CPU utilization as a system-wide percentage ✨
  • unclaimed idle β€” the percentage of CPU resources that were idle while work was queued up on other CPUs, as a system-wide percentage πŸ‘€
  • TIME β€” the time, formatted as HH:MM:SS ⏰
  • TIMESTAMP_ns β€” the timestamp, in nanoseconds πŸ’«
  • CPU# β€” the CPU ID πŸ¦‹
  • OFFSET_ns_CPU# β€” the time offset at which a sample fired within a sample group for this CPU 🧚

🫢 OVERHEAD 🫢

The overhead is expected to be low, basically negligible πŸ₯Ή This tool samples at 99 Hertz on all CPUs, which has a fixed and small cost. Other approaches sample every scheduler event instead, and that can mean instrumenting millions of events per second, which is a whole mood πŸ’€ Sampled CPUs, run queue lengths, and timestamps get written to ring buffers, and user space reads them periodically for reporting. Still, measure the overhead in a test environment first, no shortcuts πŸ™ˆ

🌈 SOURCE 🌈

This comes from bcc πŸ’–

There's also a companion _examples.txt file in the bcc distribution with example usage, output, and commentary for this tool, so go check that out too πŸ“š

πŸ’œ OS πŸ’œ

Linux 🐧

πŸ§ͺ STABILITY πŸ§ͺ

Unstable, it's still in development 🚧

πŸ‘‘ AUTHOR πŸ‘‘

Brendan Gregg, the legend himself ✨

πŸ”— SEE ALSO πŸ”—


Till next time, bestie πŸ¦‹ That's the USER COMMANDS manual, dated 2016-12-21, for cpuunclaimed(8) πŸ’…βœ¨