Skip to content

Commit

Permalink
WIP: neonvm: apply code review fixes, rename constant name for sysfs …
Browse files Browse the repository at this point in the history
…scaling

Signed-off-by: Misha Sakhnov <[email protected]>
  • Loading branch information
mikhail-sakhnov committed Oct 21, 2024
1 parent 56fcb36 commit f1af40d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion neonvm-controller/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func main() {
return nil
},
)
flag.StringVar(&defaultCpuScalingMode, "default-cpu-scaling-mode", vmv1.CpuScalingModeQMP, fmt.Sprintf("Default: CPU scaling: %s || %s", vmv1.CpuScalingModeQMP, vmv1.CpuScalingModeCpuSysfsState))
flag.StringVar(&defaultCpuScalingMode, "default-cpu-scaling-mode", vmv1.CpuScalingModeQMP, fmt.Sprintf("Default: CPU scaling: %s || %s", vmv1.CpuScalingModeQMP, vmv1.CpuScalingModeSysfs))
flag.BoolVar(&disableRunnerCgroup, "disable-runner-cgroup", false, "Disable creation of a cgroup in neonvm-runner for fractional CPU limiting")
flag.StringVar(&qemuDiskCacheSettings, "qemu-disk-cache-settings", "cache=none", "Set neonvm-runner's QEMU disk cache settings")
flag.Func("default-memory-provider", "Set default memory provider to use for new VMs", defaultMemoryProvider.FlagFunc)
Expand Down
8 changes: 4 additions & 4 deletions neonvm-runner/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ func buildQEMUCmd(
minCPUs := vmSpec.Guest.CPUs.Min.RoundedUp()

switch cfg.cpuScalingMode {
case vmv1.CpuScalingModeCpuSysfsState:
case vmv1.CpuScalingModeSysfs:
qemuCmd = append(qemuCmd, "-smp", fmt.Sprintf(
// if we use sysfs based scaling we specify initial value for cpus qemu arg equal to max cpus
"cpus=%d,maxcpus=%d,sockets=1,cores=%d,threads=1",
Expand Down Expand Up @@ -998,7 +998,7 @@ func makeKernelCmdline(cfg *Config, vmSpec *vmv1.VirtualMachineSpec, vmStatus *v
if cfg.appendKernelCmdline != "" {
cmdlineParts = append(cmdlineParts, cfg.appendKernelCmdline)
}
if cfg.cpuScalingMode == vmv1.CpuScalingModeCpuSysfsState {
if cfg.cpuScalingMode == vmv1.CpuScalingModeSysfs {
// if we use sysfs based scaling we need to specify the start cpus as min CPUs to mark every CPU except 0 as offline
cmdlineParts = append(cmdlineParts, fmt.Sprintf("maxcpus=%d", vmSpec.Guest.CPUs.Min.RoundedUp()))
}
Expand Down Expand Up @@ -1049,7 +1049,7 @@ func runQEMU(

wg.Add(1)
go terminateQemuOnSigterm(ctx, logger, &wg)
if !cfg.skipCgroupManagement || cfg.cpuScalingMode == vmv1.CpuScalingModeCpuSysfsState {
if !cfg.skipCgroupManagement || cfg.cpuScalingMode == vmv1.CpuScalingModeSysfs {
var callbacks cpuServerCallbacks

lastValue := &atomic.Uint32{}
Expand All @@ -1060,7 +1060,7 @@ func runQEMU(
return lo.ToPtr(vmv1.MilliCPU(lastValue.Load())), nil
},
set: func(logger *zap.Logger, cpu vmv1.MilliCPU) error {
if cfg.cpuScalingMode == vmv1.CpuScalingModeCpuSysfsState {
if cfg.cpuScalingMode == vmv1.CpuScalingModeSysfs {
err := setNeonvmDaemonCPU(cpu)
if err != nil {
logger.Error("setting CPU through NeonVM Daemon failed", zap.Any("cpu", cpu), zap.Error(err))
Expand Down
4 changes: 2 additions & 2 deletions neonvm/apis/neonvm/v1/virtualmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ const (
// that the VM should use QMP to scale CPUs.
CpuScalingModeQMP string = "qmpScaling"

// CpuScalingModeCpuSysfsState is the value of the VirtualMachineSpec.CpuScalingMode field that
// CpuScalingModeSysfs is the value of the VirtualMachineSpec.CpuScalingMode field that
// indicates that the VM should use the CPU sysfs state interface to scale CPUs.
CpuScalingModeCpuSysfsState string = "sysfsScaling"
CpuScalingModeSysfs string = "sysfsScaling"
)

// VirtualMachineUsage provides information about a VM's current usage. This is the type of the
Expand Down
2 changes: 1 addition & 1 deletion pkg/neonvm/controllers/vm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ func (r *VMReconciler) doReconcile(ctx context.Context, vm *vmv1.VirtualMachine)
}

switch *vm.Spec.CpuScalingMode {
case vmv1.CpuScalingModeCpuSysfsState:
case vmv1.CpuScalingModeSysfs:
log.Info("CPU scaling mode is set to CpuSysfsState, CPU usage check based on cgroups")
pluggedCPU = cgroupUsage.VCPUs.RoundedUp()
case vmv1.CpuScalingModeQMP:
Expand Down
2 changes: 1 addition & 1 deletion pkg/neonvm/controllers/vm_controller_cpu_scaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (r *VMReconciler) handleCPUScaling(ctx context.Context, vm *vmv1.VirtualMac

log := log.FromContext(ctx)
useCpuSysfsStateScaling := false
if vm.Spec.CpuScalingMode != nil && *vm.Spec.CpuScalingMode == vmv1.CpuScalingModeCpuSysfsState {
if vm.Spec.CpuScalingMode != nil && *vm.Spec.CpuScalingMode == vmv1.CpuScalingModeSysfs {
useCpuSysfsStateScaling = true
}

Expand Down

0 comments on commit f1af40d

Please sign in to comment.