Skip to content

Make physical CPU IDs easy to find and to type - #25

Merged
congwang-mk merged 2 commits into
mainfrom
cpu-id-usability
Nov 30, 2026
Merged

congwang-mk merged 2 commits into
mainfrom
cpu-id-usability

Conversation

@congwang-mk

Copy link
Copy Markdown
Contributor

--cpus takes physical CPU IDs, the one name of a CPU that every kernel on the machine agrees on. On arm64 that is the MPIDR, which is not in /proc/cpuinfo, is large and sparse, and was accepted and printed in decimal only. This makes the IDs easy to look up and natural to write.

kerf cpus

A new command lists every CPU with the host's logical number, its physical ID, its NUMA node, and who holds it:

CPU  MPIDR  NODE  STATE
0    0x0    0     host (boot)
1    0x1    0     host
4    0x100  0     web-server
5    0x101  0     pool
  • The ID column is named after the architecture: APIC ID, MPIDR or HART ID.
  • STATE is host, host (boot), pool, pool (unclaimed), or the name of the instance that holds the CPU.
  • A KIND column appears only on a machine with more than one kind of CPU.
  • A CPU the host gave to the pool may show - for its logical number or node, because the host stops reporting them (on x86 it leaves /proc/cpuinfo altogether).
  • It runs no external commands. It reads /proc/cpuinfo, sysfs, the MADT and the multikernel device trees.

The "invalid CPU" error of kerf init now points at kerf cpus.

Hex in and out

  • --cpus in init, create and update takes decimal or 0x hex on any architecture.
  • Where the IDs are MPIDRs they are written in hex: in kerf show, in the reports and in the error messages. APIC IDs and hart IDs stay decimal, so x86 output is unchanged.

Ranges

A range used to be every number from its first to its last, which for MPIDRs is mostly CPUs that do not exist. A range now takes the CPUs that exist in it, those of the host and of the pool: 0x0-0x103 on a machine with two clusters of 4 is 8 CPUs.

  • The two ends of a range are still validated, so a mistyped end is reported as invalid.
  • This applies to x86 as well: a range that spans a gap in the APIC IDs skips the gap where it used to fail. Ranges of consecutive IDs behave as before.

Testing

  • The full suite passes (693 passed, 1 skipped), with new tests in tests/test_cpus.py and tests/test_cpu_spec.py.
  • kerf cpus was run on an x86 host without a pool. The arm64 paths are covered by tests that fake the architecture and have not been run on arm64 hardware.

🤖 Generated with Claude Code

--cpus takes physical CPU IDs, the one name of a CPU that every kernel
on the machine agrees on. An APIC ID is at least in /proc/cpuinfo. An
MPIDR is not: it has to be dug out of the reg of the CPU's device tree
node, or out of the MADT on an ACPI host, and kerf itself only showed
the IDs in the error for a wrong one.

Add kerf cpus, which lists every CPU with the logical number the host
gives it, its physical ID, its NUMA node, and who holds it: the host,
the pool, or an instance. MPIDRs are written in hex, where each
affinity level is a byte to read. A machine with more than one kind of
CPU gets a KIND column.

The host forgets a CPU it gave to the pool to a degree that depends on
the architecture, so such a CPU may be listed without a logical number
or a node.

Signed-off-by: Cong Wang <cwang@multikernel.io>
An MPIDR packs one affinity level per byte, so 0x10100 says cluster and
core where 65792 says nothing, and hex is how the device tree, the
MADT and the kernel log all write it. Yet --cpus took decimal only, and
every list of CPUs that kerf printed was decimal too.

Take a physical CPU ID in decimal or 0x-prefixed hex wherever --cpus is
parsed, on any architecture. Write the IDs in hex where they are
MPIDRs, in kerf show, in the reports and in the error messages; APIC
IDs and hart IDs stay decimal.

A range needed a new meaning as well. It used to be every number from
its first to its last, which for MPIDRs is mostly CPUs that do not
exist: 0x0-0x103 names 8 CPUs of a machine with two clusters of 4, and
252 numbers that are not. A range now takes the CPUs that exist in it,
those of the host and of the pool. Its two ends are kept either way, so
a mistyped one is still reported as invalid. Where the IDs are
consecutive nothing changes.

The parser therefore returns the ranges, and init, create and update
expand them once they know the CPUs of the machine.

Signed-off-by: Cong Wang <cwang@multikernel.io>
@congwang-mk
congwang-mk merged commit 615a389 into main Nov 30, 2026
8 checks passed
@congwang-mk
congwang-mk deleted the cpu-id-usability branch November 30, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant