Repository navigation
configurable CPU topology #1237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
|
|
||
| use std::convert::TryInto; | ||
| use std::fs::File; | ||
| use std::num::{NonZeroU8, NonZeroUsize}; | ||
| use std::num::{NonZeroU16, NonZeroUsize}; | ||
| use std::os::unix::fs::FileTypeExt; | ||
| use std::sync::Arc; | ||
| use std::time::{SystemTime, UNIX_EPOCH}; | ||
|
|
@@ -51,6 +51,7 @@ use propolis::intr_pins; | |
| use propolis::vmm::{self, Builder, Machine}; | ||
| use propolis::vsock::GuestCid; | ||
| use propolis_api_types::instance::InstanceProperties; | ||
| use propolis_api_types::instance_spec::components::board::TopoLeaves; | ||
| use propolis_api_types::instance_spec::components::devices::SerialPortNumber; | ||
| use propolis_api_types::instance_spec::{self, SpecKey}; | ||
| use propolis_types::{CpuidIdent, CpuidVendor}; | ||
|
|
@@ -119,6 +120,9 @@ pub enum MachineInitError { | |
| #[error("failed to start attestation server")] | ||
| AttestationServer(#[source] std::io::Error), | ||
|
|
||
| #[error("unsupported VM configuration")] | ||
| UnsupportedCpuConfig(&'static str), | ||
|
|
||
| #[cfg(feature = "falcon")] | ||
| #[error("softnpu p9 device missing")] | ||
| SoftNpuP9Missing, | ||
|
|
@@ -1229,7 +1233,7 @@ impl MachineInitializer<'_> { | |
| fn generate_smbios( | ||
| &self, | ||
| bootrom_version: &Option<String>, | ||
| ) -> smbios::TableBytes { | ||
| ) -> Result<smbios::TableBytes, MachineInitError> { | ||
| use smbios::table::{type0, type1, type16, type4}; | ||
|
|
||
| let rom_size = | ||
|
|
@@ -1337,6 +1341,12 @@ impl MachineInitializer<'_> { | |
| .and_then(|vals| propolis::cpuid::parse_brand_string(vals).ok()) | ||
| .unwrap_or_default(); | ||
|
|
||
| let num_cpus: u8 = self.spec.board.cpus.try_into().map_err(|_| { | ||
| MachineInitError::UnsupportedCpuConfig( | ||
| "more CPUs than expressible in Type 4 SMBIOS v2.7 tables", | ||
| ) | ||
| })?; | ||
|
Comment on lines
+1344
to
+1348
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for my own understanding: this is what would currently prevent a >255 |
||
|
|
||
| let smb_type4 = smbios::table::Type4 { | ||
| proc_type: type4::ProcType::Central, | ||
| proc_family, | ||
|
|
@@ -1347,9 +1357,9 @@ impl MachineInitializer<'_> { | |
| // unknown | ||
| proc_upgrade: 0x2, | ||
| // make core and thread counts equal for now | ||
| core_count: self.spec.board.cpus, | ||
| core_enabled: self.spec.board.cpus, | ||
| thread_count: self.spec.board.cpus, | ||
| core_count: num_cpus, | ||
| core_enabled: num_cpus, | ||
| thread_count: num_cpus, | ||
| proc_characteristics: type4::Characteristics::IS_64_BIT | ||
| | type4::Characteristics::MULTI_CORE, | ||
| ..Default::default() | ||
|
|
@@ -1391,7 +1401,7 @@ impl MachineInitializer<'_> { | |
| smb_tables.add(0x1700.into(), &smb_type17).unwrap(); | ||
| smb_tables.add(0x3200.into(), &smb_type32).unwrap(); | ||
|
|
||
| smb_tables.commit() | ||
| Ok(smb_tables.commit()) | ||
| } | ||
|
|
||
| fn generate_e820(&self) -> Result<Entry, MachineInitError> { | ||
|
|
@@ -1478,7 +1488,7 @@ impl MachineInitializer<'_> { | |
| fn generate_acpi_tables( | ||
| &self, | ||
| acpi_variant: acpi::AcpiVariant, | ||
| cpus: u8, | ||
| cpus: u16, | ||
| ) -> Result<fwcfg::formats::AcpiTables, MachineInitError> { | ||
| let (lowmem, _) = get_spec_guest_ram_limits(self.spec); | ||
| let generators: Vec<_> = self | ||
|
|
@@ -1518,7 +1528,7 @@ impl MachineInitializer<'_> { | |
| /// Should not be called before [`Self::initialize_rom()`]. | ||
| pub fn initialize_fwcfg( | ||
| &mut self, | ||
| cpus: u8, | ||
| cpus: u16, | ||
| bootrom_version: &Option<String>, | ||
| acpi_variant: acpi::AcpiVariant, | ||
| ) -> Result<Arc<ramfb::RamFb>, MachineInitError> { | ||
|
|
@@ -1531,7 +1541,7 @@ impl MachineInitializer<'_> { | |
| .map_err(|e| MachineInitError::FwcfgInsertFailed("cpu count", e))?; | ||
|
|
||
| let smbios::TableBytes { entry_point, structure_table } = | ||
| self.generate_smbios(bootrom_version); | ||
| self.generate_smbios(bootrom_version)?; | ||
| fwcfg | ||
| .insert_named( | ||
| "etc/smbios/smbios-tables", | ||
|
|
@@ -1589,11 +1599,49 @@ impl MachineInitializer<'_> { | |
| Ok(ramfb) | ||
| } | ||
|
|
||
| fn topo_cpuid_leaves(&self) -> Result<Vec<TopoKind>, MachineInitError> { | ||
| // This is trying to find a local minima of annoying.. the alternative | ||
| // here would to have `CpuTopology` hold a `Vec<TopoKind>` directly. | ||
| // That opens questions like, what is the semantic of including a leaf | ||
| // multiple times? And we would want another glue type between the | ||
| // `propolis-server`-internal `TopoKind` that we use, to whatever | ||
| // version's external `TopoKind`. On those axes, it would be mildly | ||
| // simpler to just have a bag of bools for what leaves we want to | ||
| // specialize in this CPU topology. | ||
| // | ||
| // The downside of a bag of bools is that we have to map them to the | ||
| // internal `TopoKinds` enum at some point. This is that point. This | ||
| // conversion is incredibly typo-sensitive: would you spot | ||
| // `if std_4 { topo_leaves.push(TopoKind::StdB); }`? But converting | ||
| // across `TopoKinds` enums in versioned conversions would be similarly | ||
| // sensitive, and at least with a bag of booleans the fields are named | ||
| // and `std_4: std_b` would stand out. | ||
|
Comment on lines
+1603
to
+1618
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like Typo-sensitivity could then be addressed:
|
||
| let mut topo_leaves = Vec::new(); | ||
|
|
||
| let TopoLeaves { std_4, std_b, ext_8, ext_1e } = | ||
| self.spec.board.cpu_topology.topo_leaves; | ||
|
|
||
| if std_4 { | ||
| topo_leaves.push(TopoKind::Std4); | ||
| } | ||
| if std_b { | ||
| topo_leaves.push(TopoKind::StdB); | ||
| } | ||
| if ext_8 { | ||
| topo_leaves.push(TopoKind::Ext8); | ||
| } | ||
| if ext_1e { | ||
| topo_leaves.push(TopoKind::Ext1E); | ||
| } | ||
| Ok(topo_leaves) | ||
| } | ||
|
|
||
| /// Initialize virtual CPUs by first setting their capabilities, inserting | ||
| /// them into the device map, and then, if a kstat sampler is provided, | ||
| /// tracking their kstats. | ||
| pub async fn initialize_cpus(&mut self) -> Result<(), MachineInitError> { | ||
| let hv_interface = self.machine.guest_hv_interface.as_ref(); | ||
|
|
||
| for vcpu in self.machine.vcpus.iter() { | ||
| // Report that the guest is running on bhyve. | ||
| // | ||
|
|
@@ -1605,33 +1653,29 @@ impl MachineInitializer<'_> { | |
| requests to set hypervisor leaves", | ||
| ); | ||
|
|
||
| // Instead of `TopoKind::supported`, we use an intentionally-reduced | ||
| // list of Intel-only leaves for the moment. This is because if we | ||
| // specialize leaves used by AMD (or just both vendors), we'll | ||
| // change the topology a guest sees. | ||
| let has_smt = self.spec.board.cpu_topology.has_smt; | ||
| // Instead of `TopoKind::supported`, the instance spec selects what | ||
| // leaves may get specialized topology data. This is to maintain the | ||
| // reported topology of VMs created either before CPU platforms or | ||
| // with platforms that inadvertently reported `board.cpus`-many | ||
| // single-core sockets. | ||
| // | ||
| // The initial CPU platform defined in Nexus (Omicron#8728) hews to | ||
| // the pre-specialization topology, which won't have leaf B at all. | ||
| // Before that is sent, though, we'll see the present-but-zero | ||
| // leaves from bhyve, which we would happily specialize into | ||
| // something reflecting the guest if requested here. Once | ||
| // Omicron#8728 lands and propolis-server receives explicit CPUID | ||
| // profiles, we can add AMD leaves here too. | ||
| let cpu_topo_leaves = [TopoKind::Std4]; | ||
|
|
||
| let specialized = propolis::cpuid::Specializer::new() | ||
| .with_vcpu_count( | ||
| NonZeroU8::new(self.spec.board.cpus).unwrap(), | ||
| true, | ||
| ) | ||
| .with_vcpuid(vcpu.id) | ||
| .with_cache_topo() | ||
| .clear_cpu_topo(TopoKind::iter()) | ||
| .with_cpu_topo(cpu_topo_leaves.into_iter()) | ||
| .execute(set) | ||
| .map_err(|e| { | ||
| MachineInitError::CpuidSpecializationFailed(vcpu.id, e) | ||
| })?; | ||
| // While it's probably OK to go change that, one would not expect | ||
| // their CPU sockets to unify across a reboot. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I know what you mean by unify across a reboot, but it might be worth spelling it out |
||
| let cpu_topo_leaves = self.topo_cpuid_leaves()?; | ||
| info!(self.log, "computed cpu topo leaves {:?}", cpu_topo_leaves); | ||
|
|
||
| let specialized = propolis::cpuid::Specializer::new( | ||
| NonZeroU16::new(self.spec.board.cpus).unwrap(), | ||
| ) | ||
| .with_cpu_topo(has_smt, cpu_topo_leaves.into_iter()) | ||
| .with_vcpuid(vcpu.id) | ||
| .with_cache_topo() | ||
| .clear_cpu_topo(TopoKind::iter()) | ||
|
Comment on lines
+1671
to
+1674
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize a similar pair of builder calls was already here, but I was very I note that |
||
| .execute(set) | ||
| .map_err(|e| { | ||
| MachineInitError::CpuidSpecializationFailed(vcpu.id, e) | ||
| })?; | ||
|
|
||
| info!(self.log, "setting CPUID for vCPU"; | ||
| "vcpu" => vcpu.id, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment explaining this particular combo of values would be useful (I believe
this is for compat with pre-patch behavior?)