Skip to content

configurable CPU topology - #1237

Open
iximeow wants to merge 7 commits into
masterfrom
cpu-topology
Open

iximeow wants to merge 7 commits into
masterfrom
cpu-topology

Conversation

@iximeow

@iximeow iximeow commented Oct 30, 2026

Copy link
Copy Markdown
Member

this moves a VM's apparent CPU topology into the propolis-server API (and makes it more configurable in propolis-standalone as well). this is really intended as a stepping stone for all of: more explicit CPU pinning directives based on control plane CPU selection, CCX-aware CPU placement, getting Propolis a bit out of the way of >254 vCPU work, and, most excitingly to me, closing VMs should not have vCPU-many sockets.

realistically this is a demonstrator for another change I'll have up against Omicron in a bit here to select a new virtual platform which has as a detail more reasonable CPU topology.

it's also full of TODOs and could use at least one (1) test that on AMD the guest gets a topology we'd want it to get, instead of single-thread sockets.

@iximeow iximeow mentioned this pull request Oct 30, 2026
2 tasks
@iximeow
iximeow marked this pull request as ready for review November 17, 2026 17:18
@iximeow

iximeow commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

this actually does the needful now and would be something I'm willing to merge, but the conflicts of course need addressing. even if rebased this will conflict with #1217 on account of the API changes, so we should probably get that in, then I'll get this in, and then we can do a new ACPI type in the API to set up X2APIC structs over there too.

@acfoltzer
acfoltzer self-requested a review November 19, 2026 20:24
this also plumbs the configuration to propolis-server's API as well as
propolis-standalone. beyond simply specifying a number of sockets, some
additional specializer support was needed along the way. specific
topology leaves to specialize (or discard) are taken in the API in
support of the (pretty funky) existing topology that guests see.

choice of a given CPU toplogy will be determined, for now, in Nexus by
the corresponding virtual platform for an instance.

@acfoltzer acfoltzer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments for everything except propolis::cpuid itself, which I ran out of time
to tackle until tomorrow

Comment thread phd-tests/tests/src/cpuid.rs Resolved
Comment thread phd-tests/tests/src/cpuid.rs Resolved
Comment thread phd-tests/tests/src/cpuid.rs Resolved
Comment thread phd-tests/tests/src/cpuid.rs Resolved
Comment thread bin/propolis-cli/src/main.rs Resolved
Comment on lines +22 to +28
// The initial CPU platform as presented was even funkier than
// simply "vCPU-many single-thread sockets"; we would report SMT
// (above), but clear topology information from CPUID leaves Bh and
// 8000_001Eh. CPUID leaf 4h got topology information because it is
// Intel-only, so by populating that information we would not alter
// VMs in the product but would get to make Intel more right by
// default.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit hard to follow. Maybe referencing details in #1258 would help? The
last part about changing (I think?) Intel behavior should probably be fleshed
out a bit more.

Comment on lines +48 to +54
// This `From` impl, like others, is lossy. It should probably be a
// try_from and fail if this is not the implied default topology in
// v6.
cpu_topology: _,
} = new.board;

// Like above, this is lossy, should instead be an error in a TryFrom.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making sure I understand the potential consequences of this lossiness: an older
client requesting an instance_spec could end up with, say, a response with
255 for a newer instance with >255 cpus. Just want to make sure this is an
acceptable loss of information vs bubbling up an error into
instance_spec_get_v7

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's right. nothing actually uses instance_spec_get these days except for phd's get_spec and propolis-cli, which is both why I haven't made these TryFrom, and why they could easily become TryFrom at any point

Comment on lines +31 to +34
/// Typically this will be configured as `threads_per_core: 2` to indicate SMT,
/// and one socket. The number of vCPUs in each socket is the same, meaning that
/// the number of vCPUs must divide evenly into the number of sockets in the
/// topology.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Typically this will be configured as `threads_per_core: 2` to indicate SMT,
/// and one socket. The number of vCPUs in each socket is the same, meaning that
/// the number of vCPUs must divide evenly into the number of sockets in the
/// topology.
/// Typically this will be configured as `threads_per_core: 2` to indicate SMT,
/// and one socket. Each socket has the same number of vCPUs, so the total
/// number of vCPUs specified in `cpus` must divide evenly into the number of
/// sockets in the topology.

Strawman wording change in the suggestion. A few issues I see here:

  • threads_per_core is not mentioned anywhere else in the repo; stale name?
  • vCPUs vs Board::cpus: at least in the generated JSON, "vCPUs" only shows
    up from this one docstring. Perhaps in the API context we should stick with
    cpus since Board was there first? Though that would be unfortunate because...
  • The API docs make it unclear whether Board::cpus are cores or threads. E.g.,
    is cpus: 4, sockets: 4, has_smt: true a valid config? If so, does it
    have 4 threads or 8?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, on reflection, this change doesn't support any number of sockets other than cpus-many, or one. I've wordsmithed this a bit but also I'll have it error on other socket counts I suppose..

Comment on lines +15 to +19
/// Leaves may be selected here without being present in `Cpuid`, in which case
/// the extra selected topology leaves are ignored. Conversely, `Cpuid` leaves
/// with topology information that are not mentioend here probably indicate a
/// bug (at best, those leaves will probably indicate collection of single-core
/// sockets in the machine.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Leaves may be selected here without being present in `Cpuid`, in which case
/// the extra selected topology leaves are ignored. Conversely, `Cpuid` leaves
/// with topology information that are not mentioend here probably indicate a
/// bug (at best, those leaves will probably indicate collection of single-core
/// sockets in the machine.)
/// Leaves may be selected here without being present in `Cpuid`, in which case
/// the extra selected topology leaves are ignored. Conversely, `Cpuid` leaves
/// with topology information that are not mentioned here probably indicate a
/// bug (at best, those leaves will probably indicate collection of single-core
/// sockets in the machine.)

Typo suggestion above, but also I wonder if this could be rewritten to be more
actionable to users of the API. The last sentence reads more like a note-to-self
than an active solicitation of bug reports/feature requests.

I suspect this behavior is too subtle to cram a complete description in this
field. Maybe we can reference a longer explanation in other docs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the users of the propolis-server API and types here are really us (in Nexus via propolis-client) - none of this ends up in the user-facing API to create a VM (.... yet?). that's really why the docs on Propolis are somewhat less formal and, which I think is something you're getting at in a few comments here?

@acfoltzer acfoltzer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple last pending comments before turning it over to you, @iximeow 🫡

Comment thread lib/propolis/src/cpuid.rs
Self {
num_vcpu: count,
vcpuid: None,
has_smt: false,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for the record, this is the false I mentioned in today's call

Comment thread lib/propolis/src/cpuid.rs Resolved
@iximeow

iximeow commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

(for Adam's benefit, for the time being the migrate-from-base tests currently fail any time we add new external API revs because of #980 .)

@iximeow

iximeow commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

using 81d8bb4 I've gone through and given this a look across Windows, Ubuntu 22.04, 24.04, 26.06, OmniOS r151052 (getting a bit old..), FreeBSD 14.1, and Windows Server 2022 (also showing its age..). I did patch propolis-server just a bit to be willing to start 80 vcpus on my 32-core workstation.

in all cases, things boot and look the same as before with legacy_single_thread_sockets`. OmniOS is as sad as #940 mentions, Windows Server 2022 just doesn't bother listing more than the 64th socket, and alpine 3.24 hangs at boot.

when booting with single_socket, guests all come up and the various topology tools (cat /sys/devices/system/cpu/cpu*/topology/package_cpus_list, psrinfo -vp, sysctl kern.sched.topology_spec, Get-CimInstance -ClassName Win32_Processor | Select-Object Name, NumberOfCores, NumberOfLogicalProcessors) all agree that there are 80 logical processors, 40 cores (SMT! yay!) and one socket.

once tests are done running, I'll merge this, fix conflicts some conflicts this will introduce, and onwards with virtual platforms..

assert!(!guest_topo.has_smt().await);

// thread_siblings() should only have a single bit, matching the core's ID.
let siblings: Vec<_> = guest_topo.thread_siblings().await.collect();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know thread_siblings() is pre-existing but it sure would be nice to use /sys/devices/system/cpu/cpuX/topology/thread_siblings_list (core_cpus_list for the non-deprecated name) instead of dealing with these hex bitmaps.

Comment on lines +597 to +598
// bhyve's default topology applies instead. This is probably a bug
// to fix in bhyve's legacy_emulate_cpuid to make these consistent.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's file an issue for that.

"sockets": {
"type": "integer",
"format": "uint16",
"minimum": 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we can't use NonZeroU16?

Comment on lines +20 to +29
// v9 adds a CpuTopology field to the instance's Board. Remove it,
// convert the rest, add it back.
let older_topo =
v9::instance_spec::CpuTopology::legacy_single_thread_sockets(
spec.board.cpus,
);
let topo =
std::mem::replace(&mut spec.board.cpu_topology, older_topo);
let v6_spec: v6::instance_spec::InstanceSpec = spec.into();
(v6_spec, topo)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We swap out board.cpu_topology but this eventually ends up in TryFrom<Spec> for v1::instance_spec::InstanceSpec which will bail if board.cpus can't fit in a u8. Sending an ensure request with cpus: 300 will fail but we still store the spec meaning a subsequent GET /instance or GET /instance/spec will bring us here and panic.

pub ext_1e: bool,
}

/// A *very* simple topology for for a VM's vCPUs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// A *very* simple topology for for a VM's vCPUs.
/// A *very* simple topology for a VM's vCPUs.

Comment thread lib/propolis/src/cpuid.rs
if let Some(ent) = set.get_mut(CpuidIdent::leaf(1)) {
ent.edx |= (0x1 << 28);
// bits 23:16 contain max IDs for logical CPUs in package
// TODO: what is in this leaf when `num_vcpu` saturates u8?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should saturate (along with EBX[31:24] above). The extended topology leaves would then be used for the full 32-bit x2APIC IDs.

Comment thread lib/propolis/src/cpuid.rs
set.remove_leaf(leaf);
}
TopoKind::Std1F => {
// TODO: handle 0x1f topo info

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As someone who occasionally runs propolis on Intel: can we keep the previous behaviour of clearing this leaf as well? It doesn't matter on AMD but on Intel now a guest will get the host's 0x1F leaf (which Linux will prefer to 0xB).

Comment thread lib/propolis/src/cpuid.rs
leaf,
num_vcpu,
value: num_vcpu,
why: Some("Leaf B.1 would have EAX=0"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: should be B.0. But also, can we handle this for has_smt = false as well? Something like:

// Subleaf 0 is the "Logical Processor" (thread) level:
// EAX indicates the number of bits in an APIC ID shared
// by threads on the same core and EBX is the number of
// threads per core.
//
// Without SMT, there's one thread per core and nothing
// to shift off.
let (smt_shift, threads_per_core) =
    if self.has_smt { (1, 2) } else { (0, 1) };
set.insert(
    CpuidIdent::subleaf(leaf, 0),
    CpuidValues {
        eax: smt_shift,
        ebx: threads_per_core,
        ecx: 0x100,
        edx: vcpuid,
    },
);

Comment thread lib/propolis/src/cpuid.rs
Comment on lines +503 to +514
ext_8h.ecx &= !0xff;
if num_vcpu >= 256 {
return Err(SpecializeError::IncompatibleTopology {
leaf,
value: num_vcpu,
why: Some(
"Don't know how to specialize CPUID leaf \
8000_0008 for more than 256 processors!",
),
});
}
ext_8h.ecx |= num_vcpu - 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another place we'd just saturate at 0xff.

Comment thread lib/propolis/src/cpuid.rs
});
}
ext_8h.ecx |= num_vcpu - 1;
let apic_id_size = num_vcpu.ilog2() + 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one too high for power-of-two num_vcpu values? e.g., apic_id_size would be 3 for 4 vCPUs even though we only need 2 bits.

Suggested change
let apic_id_size = num_vcpu.ilog2() + 1;
let apic_id_size = num_vcpu.next_power_of_two().trailing_zeros();

Comment on lines +337 to +348
.map(|cfg| cfg.machine_settings.cpu_topology.as_str())
{
None | Some("single_socket") => CpuTopology::single_socket_smt(),
Some("legacy_single_thread_sockets") => {
CpuTopology::legacy_single_thread_sockets(self.vcpus)
}
Some(other) => {
anyhow::bail!(
"cpu_topology must be omitted, \"single_socket\" \
or \"legacy_single_thread_sockets\". got: {other}"
)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would sure be nice if this could be an enum, but, i suppose there is probably some reason it cannot?

Comment thread crates/propolis-config-toml/src/lib.rs Outdated
Comment on lines +130 to +127
#[serde(default = "default_smt")]
pub smt: bool,
#[serde(default = "default_sockets")]
pub sockets: u16,
#[serde(default = "default_cpu_topology")]
pub cpu_topology: String,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have this consistent with propolis-standalone's config.

Perhaps accepting either a string

cpu_topology = "single_socket" | "legacy_single_thread_sockets"

or explicit values

[cpu_topology]
smt = true
sockets = 1

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.

4 participants