mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
arch: CpuProfile enum
Introduce a CpuProfile enum that will be deserialized from the user's selected CPU profile. Currently we only have a "host" variant, but in the future there will be a build script automatically constructing this enum based on pre-generated CPU profiles. Signed-off-by: Oliver Anderson <oliver.anderson@cyberus-technology.de> On-behalf-of: SAP oliver.anderson@sap.com
This commit is contained in:
committed by
Rob Bradford
parent
b1109f7328
commit
d96de000f2
+25
-2
@@ -9,9 +9,11 @@
|
|||||||
//! Supported platforms: x86_64, aarch64, riscv64.
|
//! Supported platforms: x86_64, aarch64, riscv64.
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{fmt, result};
|
use std::{fmt, result};
|
||||||
|
|
||||||
|
use serde::de::IntoDeserializer;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
@@ -53,6 +55,26 @@ pub enum Error {
|
|||||||
/// Type for returning public functions outcome.
|
/// Type for returning public functions outcome.
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
|
// If the target_arch is x86_64 we import CpuProfile from the x86_64 module, otherwise we
|
||||||
|
// declare it here with only "host" as a selectable CPU profile. This trick is useful to prevent
|
||||||
|
// excessive conditional compilation throughout the codebase.
|
||||||
|
#[cfg(not(target_arch = "x86_64"))]
|
||||||
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
|
/// A [`CpuProfile`] is a mechanism for ensuring live migration compatibility
|
||||||
|
/// between host's with potentially different CPU models.
|
||||||
|
pub enum CpuProfile {
|
||||||
|
#[default]
|
||||||
|
Host,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note that this trait impl is architecture agnostic and may thus reside here.
|
||||||
|
impl FromStr for CpuProfile {
|
||||||
|
type Err = serde::de::value::Error;
|
||||||
|
fn from_str(s: &str) -> result::Result<Self, Self::Err> {
|
||||||
|
Self::deserialize(s.into_deserializer())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Type for memory region types.
|
/// Type for memory region types.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||||
pub enum RegionType {
|
pub enum RegionType {
|
||||||
@@ -100,8 +122,9 @@ pub mod x86_64;
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub use x86_64::{
|
pub use x86_64::{
|
||||||
_NSIG, CpuidConfig, CpuidFeatureEntry, EntryPoint, arch_memory_regions, configure_system,
|
_NSIG, CpuidConfig, CpuidFeatureEntry, EntryPoint, arch_memory_regions, configure_system,
|
||||||
configure_vcpu, generate_common_cpuid, generate_ram_ranges, get_host_cpu_phys_bits,
|
configure_vcpu, cpu_profile::CpuProfile, generate_common_cpuid, generate_ram_ranges,
|
||||||
initramfs_load_addr, layout, layout::CMDLINE_MAX_SIZE, layout::CMDLINE_START, regs,
|
get_host_cpu_phys_bits, initramfs_load_addr, layout, layout::CMDLINE_MAX_SIZE,
|
||||||
|
layout::CMDLINE_START, regs,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Safe wrapper for `sysconf(_SC_PAGESIZE)`.
|
/// Safe wrapper for `sysconf(_SC_PAGESIZE)`.
|
||||||
|
|||||||
@@ -4,3 +4,13 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
pub mod cpuid_adjustments;
|
pub mod cpuid_adjustments;
|
||||||
|
|
||||||
|
// TODO: Auto generate the CpuProfile enum with a build script once we introduce user facing CPU profiles.
|
||||||
|
|
||||||
|
/// A [`CpuProfile`] is a mechanism for ensuring live migration compatibility
|
||||||
|
/// between hosts with potentially different CPU models.
|
||||||
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
|
pub enum CpuProfile {
|
||||||
|
#[default]
|
||||||
|
Host,
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user