...

Source file src/github.com/Microsoft/hcsshim/internal/uvm/cpugroups.go

Documentation: github.com/Microsoft/hcsshim/internal/uvm

     1  //go:build windows
     2  
     3  package uvm
     4  
     5  import (
     6  	"context"
     7  	"errors"
     8  	"fmt"
     9  
    10  	"github.com/Microsoft/hcsshim/internal/cpugroup"
    11  	"github.com/Microsoft/hcsshim/internal/hcs/resourcepaths"
    12  	hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
    13  	"github.com/Microsoft/hcsshim/osversion"
    14  )
    15  
    16  var errCPUGroupCreateNotSupported = fmt.Errorf("cpu group assignment on create requires a build of %d or higher", osversion.V21H1)
    17  
    18  // ReleaseCPUGroup unsets the cpugroup from the VM
    19  func (uvm *UtilityVM) ReleaseCPUGroup(ctx context.Context) error {
    20  	if err := uvm.unsetCPUGroup(ctx); err != nil {
    21  		return fmt.Errorf("failed to remove VM %s from cpugroup", uvm.ID())
    22  	}
    23  	return nil
    24  }
    25  
    26  // SetCPUGroup setups up the cpugroup for the VM with the requested id
    27  func (uvm *UtilityVM) SetCPUGroup(ctx context.Context, id string) error {
    28  	if id == "" {
    29  		return errors.New("must specify an ID to use when configuring a VM's cpugroup")
    30  	}
    31  	return uvm.setCPUGroup(ctx, id)
    32  }
    33  
    34  // setCPUGroup sets the VM's cpugroup
    35  func (uvm *UtilityVM) setCPUGroup(ctx context.Context, id string) error {
    36  	req := &hcsschema.ModifySettingRequest{
    37  		ResourcePath: resourcepaths.CPUGroupResourcePath,
    38  		Settings: &hcsschema.CpuGroup{
    39  			Id: id,
    40  		},
    41  	}
    42  	if err := uvm.modify(ctx, req); err != nil {
    43  		return err
    44  	}
    45  	return nil
    46  }
    47  
    48  // unsetCPUGroup sets the VM's cpugroup to the null group ID
    49  // set groupID to 00000000-0000-0000-0000-000000000000 to remove the VM from a cpugroup
    50  //
    51  // Since a VM must be moved to the null group before potentially being added to a different
    52  // cpugroup, that means there may be a segment of time that the VM's cpu usage runs unrestricted.
    53  func (uvm *UtilityVM) unsetCPUGroup(ctx context.Context) error {
    54  	return uvm.setCPUGroup(ctx, cpugroup.NullGroupID)
    55  }
    56  

View as plain text