Skip to content

configurable CPU topology - #1237

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

iximeow wants to merge 16 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

@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 Resolved
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 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.

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.

I'd written this mostly because I expected saturation but saw PPR says 0xFF & , so I wanted to get an actual reading from a 192c part and see what that is, before doing anything other than bailing here.

in the interest of getting the cpu type widened for the API I'm thinking maybe we leave this (and the other >8bit TODO's) until we can do that comparison? since getting this out of the way will just be "bump the propolis commit" instead of all the API version plumbing, it'll be relatively straightforward I think.

Comment thread lib/propolis/src/cpuid.rs Resolved
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,
    },
);

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.

huhhh, I'd thought that eax: 0 here really meant to guest software that they should not consume this leaf, but for example this dump of a 2x192c no-SMT system sure has all-zeroes in eax. I'll change this over and adjust the comment a bit.

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 Resolved
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?

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.

not a particularly great reason. it would want to be a shared enum with -standalone (or duplicated) and I don't know how much any of this specific config plumbing will stick around beyond like the next week (see #1237 (comment) and #1263)

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

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.

I'd started trying to do something along these lines, but to make this work you'd need a deserialize_with. that's not bad or anything, but noodling over the sparse ACPI ID stuff you'd done in #1263 I'm pretty convinced that CpuTopology as it is here is.. basically good enough for how Propolis is used in a rack, but not enough for more interesting testcases we might want.

I don't know what something that can describe ACPI IDs explicitly would look like, but smt/sockets won't be right. what I should probably do here is actually make propolis-standalone more like this, for better or worse?

@iximeow iximeow left a comment

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.

I'd sat down to address @luqmana's comments this afternoon and ended up shuffling bits around somewhat more than I'd expected, plus finding at least two additional bugs along the way. hopefully this should be in a much better state now.

Comment thread lib/propolis/src/cpuid.rs
/// Leaf 0x1F (Intel)
Std1F = 0x1f,
/// LEAF 0x80000008 (AMD)
Ext8 = 0x80000008,

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.

@luqmana @acfoltzer one of the more important changes in the commits this evening is the new enum TopoActions. I'd noticed the set_num_phys_threads(1) in Nexus' milan_ideal and thought for a moment that we'd set NC=1 there (though, in reality that setter subtracts one before storing the value to the NC bits).

because the the NC and APIC ID size bits are left zero it would actually have been fine to keep the extant behavior of "clear the leaf's topology information if false, clear and set if true", since as this branch was the new "clearing" would leave 8000_0008 in the same state it came from Nexus. but after having written out TopoActions, I think it's mildly nicer anyway.

you might have already noticed this as a non-issue! let me know what you think 🙏

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.

Yup, I like the more explicit TopoActions.

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.

Agreed, I was thinking along these lines when I left this comment, but opted for a less-ambitious suggestion.

)
.with_cpu_topo(
has_smt,
topo_actions.leaves_to_set.clone().into_iter(),

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
topo_actions.leaves_to_set.clone().into_iter(),
topo_actions.leaves_to_set.iter().copied(),

And similarly for leaves_to_clear below

// that this bool can be taken as-is (see Propolis#1265 at the least)
let non_legacy_smt =
has_smt && !self.spec.board.has_legacy_cpu_topology();
let core_count = if non_legacy_smt { num_cpus / 2 } else { num_cpus };

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.

Reject odd number of vCPUs like standalone?

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.

I suppose we ought to, yeah! I was thinking about this as enforced by Nexus when sending a topology with actually-meaningful SMT

Comment on lines +1176 to +1180
if has_smt && !cpus.is_multiple_of(2) {
anyhow::bail!(
"SMT requires vCPU count is a multiple of two (got: {cpus})"
);
}

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.

One unfortunate consequence of no separate smt option is that a config with just cpus = 1 now fails since single_socket (has_smt = true) is the default.


let (sockets, has_smt) = match config.main.cpu_topology.as_str() {
"single_socket" => (1, true),
"legacy_single_thread_sockets" => (cpus, 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.

This is slightly different compared to server which does:

    pub fn legacy_single_thread_sockets(sockets: u16) -> Self {
        Self {
            has_smt: true,
            sockets,
            // The initial CPU topology as presented was even funkier than
            // simply "vCPU-many single-thread sockets"; we would report SMT
            // (above), pass a pre-defined leaf Ext8 as-is, if set, but clear
            // topology information from CPUID leaves Bh and 8000_001Eh.
            //
            // Intel-only CPUID leaf 4h would be specialized when this initial
            // CPU topology was the default - it is only included here for
            // completeness in describing the "before explicit virtual
            // platforms" state of a propolis-server VM. The value of `std_4`
            // has no bearing on the behavior of an Oxide rack's VMs.
            topo_leaves: TopoLeaves {
                std_4: TopoAction::Specialize,
                std_b: TopoAction::Clear,
                std_1f: TopoAction::Clear,
                ext_8: TopoAction::Ignore,
                ext_1e: TopoAction::Clear,
            },
        }
    }

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.

it is, but #1269 makes it more comparable: https://github.com/oxidecomputer/propolis/pull/1269/changes#diff-1955ce6f9c67d86b8bf2ad4fc707b4f53dc169ec0532e62e1c272488fc8fc678L166

though it's true that -standalone with #1237 and without #1269 would lose the HTT bit.. it's also the case that -standalone doesn't actually use the legacy_single_thread_socket's funky topology specialization - I think that's .. probably fine? standalone also doesn't use the exact Milan CPUID (or other control plane CPUID definitions) so the specialization done here or not isn't super valuable either..

my longer-term (like, over the rest of December) hope is to get virtual platforms integrated in Omicron, then pull all of that out into a crate that propolis-cli and -standalone can use directly so these can be brought in line in a way that's either product-reflective or at least useful.

Comment thread lib/propolis/src/cpuid.rs
set.insert(
CpuidIdent::subleaf(leaf, 1),
CpuidValues {
eax: 0x8,

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.

Not a blocker but this is also somewhere we'd need to update for sockets > 1: probably compute log2 as with ApicIdSize for Ext8.

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.

update for num_cpus > 255, you mean?

Comment thread lib/propolis/src/cpuid.rs
Comment on lines +304 to +305
const TOPO_FIELDS_MASK: u32 = 0x00_00_f0_ff;
features.ecx &= !TOPO_FIELDS_MASK;

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 should probably also clear this below since Specialize doesn't clear before setting.

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