Skip to content

Commit

Permalink
instance/driver_qemu: call TaskSchedulerTrigger hook onstart/stop/update
Browse files Browse the repository at this point in the history
Put calls to the cgroup.TaskSchedulerTrigger in a few critical places:
- on instance start
- on instance CPU configuration change
- on instance stop

Signed-off-by: Alexander Mikhalitsyn <[email protected]>
  • Loading branch information
mihalicyn committed Apr 5, 2024
1 parent 22e8ddb commit 0b22377
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions lxd/instance/drivers/driver_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -1704,27 +1704,11 @@ func (d *qemu) start(stateful bool, op *operationlock.InstanceOperation) error {
return err
}
}
} else {
// Confirm nothing weird is going on.
if len(cpuInfo.vcpus) != len(pids) {
err = fmt.Errorf("QEMU has less vCPUs than configured")
op.Done(err)
return err
}

for i, pid := range pids {
set := unix.CPUSet{}
set.Set(int(cpuInfo.vcpus[uint64(i)]))

// Apply the pin.
err := unix.SchedSetaffinity(pid, &set)
if err != nil {
op.Done(err)
return err
}
}
}

// Trigger a rebalance
cgroup.TaskSchedulerTrigger("virtual-machine", d.name, "started")

// Run monitor hooks from devices.
for _, monHook := range monHooks {
err = monHook(monitor)
Expand Down Expand Up @@ -4930,6 +4914,9 @@ func (d *qemu) Stop(stateful bool) error {
return err
}

// Trigger a rebalance
cgroup.TaskSchedulerTrigger("virtual-machine", d.name, "stopped")

return nil
}

Expand Down Expand Up @@ -5591,6 +5578,8 @@ func (d *qemu) Update(args db.InstanceArgs, userRequested bool) error {
return err
}

cpuLimitWasChanged := false

if isRunning {
// Only certain keys can be changed on a running VM.
liveUpdateKeys := []string{
Expand Down Expand Up @@ -5669,6 +5658,8 @@ func (d *qemu) Update(args db.InstanceArgs, userRequested bool) error {
if err != nil {
return fmt.Errorf("Failed updating cpu limit: %w", err)
}

cpuLimitWasChanged = true
} else if key == "limits.memory" {
err = d.updateMemoryLimit(value)
if err != nil {
Expand Down Expand Up @@ -5792,6 +5783,11 @@ func (d *qemu) Update(args db.InstanceArgs, userRequested bool) error {
// Changes have been applied and recorded, do not revert if an error occurs from here.
revert.Success()

if cpuLimitWasChanged {
// Trigger a scheduler re-run
cgroup.TaskSchedulerTrigger("virtual-machine", d.name, "changed")
}

if isRunning {
// Send devlxd notifications only for user.* key changes
for _, key := range changedConfig {
Expand Down

0 comments on commit 0b22377

Please sign in to comment.