mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-03 01:17:41 +03:00
F #1636: Add KVM_CPU_FEATURES to Virtual Machines
Add support to <feature> element for the virtual cpu (see [1]). It includes: * A new probe that gets the supported features of the hypervisor CPU using virsh capabilities. * Generate AUTOMATIC_REQUIREMENTS if the CPU_MODEL/FEATURES is present. Note that a MODEL needs to be set for this to work (libvirt error otherwise is: "XML error: Non-empty feature list specified without CPU model...") [1] https://libvirt.org/formatdomain.html#cpu-model-and-topology Example -------------------------------------------------------------------------------- * Template configuration: CPU_MODEL = [ MODEL = "host-passthrough", FEATURES = "ss,vmx,tsc_adjust" ] * Generated AUTOMATIC_REQUIREMENTS in the VM: AUTOMATIC_REQUIREMENTS="(CLUSTER_ID = 0) & !(PUBLIC_CLOUD = YES) & !(PIN_POLICY = PINNED) & (KVM_CPU_FEATURES = \"*ss*\") & (KVM_CPU_FEATURES = \"*vmx*\") & (KVM_CPU_FEATURES = \"*tsc_adjust*\")" * Generated deployment file: <cpu mode='host-passthrough'> <feature policy='require' name='ss'/> <feature policy='require' name='vmx'/> <feature policy='require' name='tsc_adjust'/> </cpu> * Information gathered by the probe: ... MONITORING INFORMATION ARCH="x86_64" CGROUPS_VERSION="2" ... KVM_CPU_FEATURES="ss,vmx,pdcm,osxsave,hypervisor,tsc_adjust,clflushopt,umip,md-clear,stibp,arch-capabilities,ssbd,xsaves,pdpe1gb,ibpb,ibrs,amd-stibp,amd-ssbd,rdctl-no,ibrs-all,skip-l1dfl-vmentry,mds-no,pschange-mc-no" KVM_CPU_MODEL="Skylake-Client-noTSX-IBRS" ... co-authored-by: Neal Hansen <nhansen@opennebula.io>
This commit is contained in:
parent
0f776c9b40
commit
7a77dff659
@ -1477,6 +1477,7 @@ IM_PROBES_KVM_HOST_MONITOR_FILES="\
|
||||
IM_PROBES_KVM_HOST_SYSTEM_FILES="\
|
||||
src/im_mad/remotes/kvm-probes.d/host/system/architecture.sh \
|
||||
src/im_mad/remotes/kvm-probes.d/host/system/cpu.sh \
|
||||
src/im_mad/remotes/kvm-probes.d/host/system/cpu_features.sh \
|
||||
src/im_mad/remotes/kvm-probes.d/host/system/linux_host.rb \
|
||||
src/im_mad/remotes/kvm-probes.d/host/system/machines_models.rb \
|
||||
src/im_mad/remotes/kvm-probes.d/host/system/monitor_ds.rb \
|
||||
|
21
src/im_mad/remotes/kvm-probes.d/host/system/cpu_features.sh
Executable file
21
src/im_mad/remotes/kvm-probes.d/host/system/cpu_features.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||

|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2023, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
# -------------------------------------------------------------------------- #
|
||||

|
||||
FEATURES=$(virsh capabilities | grep '<feature name' | sed -e "s/^.*='//;s/'\/>$//" | xargs | tr ' ' ',')
|
||||

|
||||
echo "KVM_CPU_FEATURES=\"$FEATURES\""
|
@ -1599,6 +1599,9 @@ int VirtualMachine::automatic_requirements(set<int>& cluster_ids,
|
||||
return -1;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Set automatic Host requirements
|
||||
// -------------------------------------------------------------------------
|
||||
if ( !cluster_ids.empty() )
|
||||
{
|
||||
auto i = cluster_ids.begin();
|
||||
@ -1644,11 +1647,28 @@ int VirtualMachine::automatic_requirements(set<int>& cluster_ids,
|
||||
oss << "))";
|
||||
}
|
||||
|
||||
const VectorAttribute * cpu_model = obj_template->get("CPU_MODEL");
|
||||
|
||||
if ( cpu_model != nullptr )
|
||||
{
|
||||
vector<string> features_v;
|
||||
const string& features_s = cpu_model->vector_value("FEATURES");
|
||||
|
||||
one_util::split(features_s, ',', features_v);
|
||||
|
||||
for (const auto& feature: features_v)
|
||||
{
|
||||
oss << " & (KVM_CPU_FEATURES = \"*" << feature << "*\")";
|
||||
}
|
||||
}
|
||||
|
||||
obj_template->add("AUTOMATIC_REQUIREMENTS", oss.str());
|
||||
|
||||
oss.str("");
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Set automatic System DS requirements
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
if ( !cluster_ids.empty() || !datastore_ids.empty() )
|
||||
{
|
||||
|
@ -507,8 +507,9 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
|
||||
vector<string> boots;
|
||||
|
||||
string cpu_model = "";
|
||||
string cpu_mode = "";
|
||||
string cpu_model = "";
|
||||
string cpu_feature = "";
|
||||
string cpu_mode = "";
|
||||
|
||||
vector<const VectorAttribute *> disk;
|
||||
const VectorAttribute * context;
|
||||
@ -917,6 +918,7 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
// CPU SECTION
|
||||
// ------------------------------------------------------------------------
|
||||
get_attribute(vm, host, cluster, "CPU_MODEL", "MODEL", cpu_model);
|
||||
get_attribute(vm, nullptr, nullptr, "CPU_MODEL", "FEATURES", cpu_feature);
|
||||
|
||||
if (cpu_model == "host-passthrough")
|
||||
{
|
||||
@ -946,6 +948,19 @@ int LibVirtDriver::deployment_description_kvm(
|
||||
file << ">\n";
|
||||
}
|
||||
|
||||
if ( !cpu_feature.empty() && !cpu_model.empty() )
|
||||
{
|
||||
vector<string> features;
|
||||
|
||||
one_util::split(cpu_feature, ',', features);
|
||||
|
||||
for (const auto& feature: features)
|
||||
{
|
||||
file << "\t\t<feature policy='require'"
|
||||
<< " name=" << one_util::escape_xml_attr(feature) << "/>\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (nodes.empty() && memory_hotplug)
|
||||
{
|
||||
int cpus = to_i(vcpu) - 1;
|
||||
|
Loading…
Reference in New Issue
Block a user