Skip to content

Commit

Permalink
Add mapping of the CPUs
Browse files Browse the repository at this point in the history
This patch adds the mapping of CPUs from oVirt to OCP. This includes the
additional flags pointed out in the source environment.

Signed-off-by: Liran Rotenberg <[email protected]>
  • Loading branch information
liranr23 committed Dec 24, 2023
1 parent a4f8bd7 commit 7bb4a7c
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion pkg/controller/plan/adapter/ovirt/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,64 @@ var osMap = map[string]string{
"windows_11": "win11",
}

var cpuMap = map[string]string{
"Nehalem": "Nehalem",
"Nehalem,+spec-ctrl,+ssbd": "Nehalem-IBRS",
"Westmere": "Westmere",
"Westmere,+pcid,+spec-ctrl,+ssbd": "Westmere-IBRS",
"SandyBridge": "SandyBridge",
"SandyBridge,+pcid,+spec-ctrl,+ssbd,+md-clear": "SandyBridge-IBRS",
"IvyBridge": "IvyBridge",
"IvyBridge,+pcid,+spec-ctrl,+ssbd,+md-clear": "IvyBridge-IBRS",
"Haswell-noTSX": "Haswell-noTSX",
"Haswell-noTSX,+spec-ctrl,+ssbd,+md-clear": "Haswell-noTSX-IBRS",
"Broadwell-noTSX": "Broadwell-noTSX",
"Broadwell-noTSX,+spec-ctrl,+ssbd,+md-clear": "Broadwell-noTSX-IBRS",
"Skylake-Client,-hle,-rtm,-mpx": "Skylake-Client",
"Skylake-Client-noTSX-IBRS,+ssbd,+md-clear,-mpx": "Skylake-Client-noTSX-IBRS",
"Skylake-Server,-hle,-rtm,-mpx": "Skylake-Server",
"Skylake-Server-noTSX-IBRS,+ssbd,+md-clear,-mpx": "Skylake-Server-noTSX-IBRS",
"Cascadelake-Server,-hle,-rtm,-mpx": "Cascadelake-Server",
"Cascadelake-Server-noTSX,-mpx": "Cascadelake-Server-noTSX",
"Icelake-Server-noTSX,-mpx": "Icelake-Server",
"Icelake-Server-noTSX,+arch-capabilities,+rdctl-no,+ibrs-all,+skip-l1dfl-vmentry,+mds-no,+pschange-mc-no,-mpx": "Icelake-Server-noTSX",
"Opteron_G4": "Opteron_G4",
"Opteron_G5": "Opteron_G5",
"EPYC": "EPYC",
"EPYC,+ibpb,+virt-ssbd": "EPYC-IBPB",
"POWER8": "POWER8",
"POWER9": "POWER9",
}

var clusterCpuMap = map[string]string{
"Intel Nehalem Family": "Nehalem",
"Secure Intel Nehalem Family": "Nehalem,+spec-ctrl,+ssbd",
"Intel Westmere Family": "Westmere",
"Secure Intel Westmere Family": "Westmere,+pcid,+spec-ctrl,+ssbd",
"Intel SandyBridge Family": "SandyBridge",
"Secure Intel SandyBridge Family": "SandyBridge,+pcid,+spec-ctrl,+ssbd,+md-clear",
"Intel IvyBridge Family": "IvyBridge",
"Secure Intel IvyBridge Family": "IvyBridge,+pcid,+spec-ctrl,+ssbd,+md-clear",
"Intel Haswell Family": "Haswell-noTSX",
"Secure Intel Haswell Family": "Haswell-noTSX,+spec-ctrl,+ssbd,+md-clear",
"Intel Broadwell Family": "Broadwell-noTSX",
"Secure Intel Broadwell Family": "Broadwell-noTSX,+spec-ctrl,+ssbd,+md-clear",
"Intel Skylake Client Family": "Skylake-Client",
"Secure Intel Skylake Client Family": "Skylake-Client-noTSX-IBRS,+ssbd,+md-clear,-mpx",
"Intel Skylake Server Family": "Skylake-Server,-hle,-rtm,-mpx",
"Secure Intel Skylake Server Family": "Skylake-Server-noTSX-IBRS,+ssbd,+md-clear,-mpx",
"Intel Cascadelake Server Family": "Cascadelake-Server,-hle,-rtm,-mpx",
"Secure Intel Cascadelake Server Family": "Cascadelake-Server-noTSX,-mpx",
"Intel Icelake Server Family": "Icelake-Server-noTSX,-mpx",
"Secure Intel Icelake Server Family": "Icelake-Server-noTSX,+arch-capabilities,+rdctl-no,+ibrs-all,+skip-l1dfl-vmentry,+mds-no,+pschange-mc-no,-mpx",
"AMD Opteron G4": "Opteron_G4",
"AMD Opteron G5": "Opteron_G5",
"AMD EPYC": "EPYC",
"Secure AMD EPYC": "EPYC,+ibpb,+virt-ssbd",
"IBM POWER8": "POWER8",
"IBM POWER9": "POWER9",
}

// oVirt builder.
type Builder struct {
*plancontext.Context
Expand Down Expand Up @@ -391,7 +449,21 @@ func (r *Builder) mapCPU(vm *model.Workload, object *cnv.VirtualMachineSpec) {
if vm.CpuPinningPolicy == model.Dedicated {
object.Template.Spec.Domain.CPU.DedicatedCPUPlacement = true
}

var fullCpu string
if r.Plan.Spec.PreserveClusterCPUModel {
fullCpu = clusterCpuMap[vm.Cluster.CPU.Type]
}
object.Template.Spec.Domain.CPU.Model = cpuMap[fullCpu]
cpuFlags := strings.Split(fullCpu, ",")
for _, val := range cpuFlags[1:] {
if flag, found := strings.CutPrefix(val, "+"); found {
object.Template.Spec.Domain.CPU.Features = append(object.Template.Spec.Domain.CPU.Features, cnv.CPUFeature{Name: flag, Policy: "require"})
} else if flag, found = strings.CutPrefix(val, "-"); found {
object.Template.Spec.Domain.CPU.Features = append(object.Template.Spec.Domain.CPU.Features, cnv.CPUFeature{Name: flag, Policy: "disable"})
} else {
object.Template.Spec.Domain.CPU.Features = append(object.Template.Spec.Domain.CPU.Features, cnv.CPUFeature{Name: flag})
}
}
}

func (r *Builder) mapFirmware(vm *model.Workload, cluster *model.Cluster, object *cnv.VirtualMachineSpec) {
Expand Down

0 comments on commit 7bb4a7c

Please sign in to comment.