Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/cpugroup/cpugroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package cpugroup
import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"

"github.com/Microsoft/hcsshim/internal/hcs"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
"github.com/pkg/errors"
)

const NullGroupID = "00000000-0000-0000-0000-000000000000"
Expand Down Expand Up @@ -48,7 +48,7 @@ func Create(ctx context.Context, id string, logicalProcessors []uint32) error {
LogicalProcessorCount: uint32(len(logicalProcessors)),
}
if err := modifyCPUGroupRequest(ctx, operation, details); err != nil {
return fmt.Errorf("failed to make cpugroups CreateGroup request for details %+v with: %s", details, err)
return errors.Wrapf(err, "failed to make cpugroups CreateGroup request for details %+v", details)
}
return nil
}
Expand All @@ -65,7 +65,7 @@ func getCPUGroupConfig(ctx context.Context, id string) (*hcsschema.CpuGroupConfi
}
groupConfigs := &hcsschema.CpuGroupConfigurations{}
if err := json.Unmarshal(cpuGroupsPresent.Properties[0], groupConfigs); err != nil {
return nil, fmt.Errorf("failed to unmarshal host cpugroups: %v", err)
return nil, errors.Wrap(err, "failed to unmarshal host cpugroups")
}

for _, c := range groupConfigs.CpuGroups {
Expand Down
3 changes: 3 additions & 0 deletions internal/cpugroup/cpugroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ func TestCPUGroupCreateWithIDAndDelete(t *testing.T) {
lps := []uint32{0, 1}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

id, err := guid.NewV4()
if err != nil {
t.Fatalf("failed to create cpugroup guid with: %v", err)
}

err = Create(ctx, id.String(), lps)
if err != nil {
t.Fatalf("failed to create cpugroup %s with: %v", id.String(), err)
}

defer func() {
if err := Delete(ctx, id.String()); err != nil {
t.Fatalf("failed to delete cpugroup %s with: %v", id.String(), err)
Expand Down
5 changes: 4 additions & 1 deletion internal/hcs/schema2/processor_2.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 2.1
* API version: 2.5
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/

Expand All @@ -17,4 +17,7 @@ type Processor2 struct {
Weight int32 `json:"Weight,omitempty"`

ExposeVirtualizationExtensions bool `json:"ExposeVirtualizationExtensions,omitempty"`

// An optional object that configures the CPU Group to which a Virtual Machine is going to bind to.
CpuGroup *CpuGroup `json:"CpuGroup,omitempty"`
}
13 changes: 6 additions & 7 deletions internal/uvm/cpugroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
)

// Build that assigning a cpu group on creation of a vm is supported
const cpuGroupCreateBuild = 20124

var errCPUGroupCreateNotSupported = fmt.Errorf("cpu group assignment on create requires a build of %d or higher", cpuGroupCreateBuild)

// ReleaseCPUGroup unsets the cpugroup from the VM
func (uvm *UtilityVM) ReleaseCPUGroup(ctx context.Context) error {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we keeping this for the future modify path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

groupID := uvm.cpuGroupID
if groupID == "" {
// not set, don't try to do anything
return nil
}
if err := uvm.unsetCPUGroup(ctx); err != nil {
return fmt.Errorf("failed to remove VM %s from cpugroup %s", uvm.ID(), groupID)
return fmt.Errorf("failed to remove VM %s from cpugroup", uvm.ID())
}
return nil
}
Expand All @@ -42,7 +42,6 @@ func (uvm *UtilityVM) setCPUGroup(ctx context.Context, id string) error {
if err := uvm.modify(ctx, req); err != nil {
return err
}
uvm.cpuGroupID = id
return nil
}

Expand Down
3 changes: 0 additions & 3 deletions internal/uvm/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@ func (uvm *UtilityVM) Close() (err error) {
windows.Close(uvm.vmmemProcess)

if uvm.hcsSystem != nil {
if err := uvm.ReleaseCPUGroup(ctx); err != nil {
log.G(ctx).WithError(err).Warn("failed to release VM resource")
}
_ = uvm.hcsSystem.Terminate(ctx)
_ = uvm.Wait()
}
Expand Down
20 changes: 14 additions & 6 deletions internal/uvm/create_lcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func CreateLCOW(ctx context.Context, opts *OptionsLCOW) (_ *UtilityVM, err error
vpciDevices: make(map[string]*VPCIDevice),
physicallyBacked: !opts.AllowOvercommit,
devicesPhysicallyBacked: opts.FullyPhysicallyBacked,
cpuGroupID: opts.CPUGroupID,
createOpts: opts,
}

Expand Down Expand Up @@ -204,6 +203,19 @@ func CreateLCOW(ctx context.Context, opts *OptionsLCOW) (_ *UtilityVM, err error
// Align the requested memory size.
memorySizeInMB := uvm.normalizeMemorySize(ctx, opts.MemorySizeInMB)

processor := &hcsschema.Processor2{
Count: uvm.processorCount,
Limit: opts.ProcessorLimit,
Weight: opts.ProcessorWeight,
}
// We can set a cpu group for the VM at creation time in recent builds.
if opts.CPUGroupID != "" {
if osversion.Build() < cpuGroupCreateBuild {
return nil, errCPUGroupCreateNotSupported
}
processor.CpuGroup = &hcsschema.CpuGroup{Id: opts.CPUGroupID}
}

doc := &hcsschema.ComputeSystem{
Owner: uvm.owner,
SchemaVersion: schemaversion.SchemaV21(),
Expand All @@ -221,11 +233,7 @@ func CreateLCOW(ctx context.Context, opts *OptionsLCOW) (_ *UtilityVM, err error
HighMMIOBaseInMB: opts.HighMMIOBaseInMB,
HighMMIOGapInMB: opts.HighMMIOGapInMB,
},
Processor: &hcsschema.Processor2{
Count: uvm.processorCount,
Limit: opts.ProcessorLimit,
Weight: opts.ProcessorWeight,
},
Processor: processor,
},
Devices: &hcsschema.Devices{
HvSocket: &hcsschema.HvSocket2{
Expand Down
21 changes: 15 additions & 6 deletions internal/uvm/create_wcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/Microsoft/hcsshim/internal/uvmfolder"
"github.com/Microsoft/hcsshim/internal/wclayer"
"github.com/Microsoft/hcsshim/internal/wcow"
"github.com/Microsoft/hcsshim/osversion"
"github.com/containerd/ttrpc"
"github.com/pkg/errors"
"go.opencensus.io/trace"
Expand Down Expand Up @@ -122,6 +123,19 @@ func prepareConfigDoc(ctx context.Context, uvm *UtilityVM, opts *OptionsWCOW, uv
}
}

processor := &hcsschema.Processor2{
Count: uvm.processorCount,
Limit: opts.ProcessorLimit,
Weight: opts.ProcessorWeight,
}
// We can set a cpu group for the VM at creation time in recent builds.
if opts.CPUGroupID != "" {
if osversion.Build() < cpuGroupCreateBuild {
return nil, errCPUGroupCreateNotSupported
}
processor.CpuGroup = &hcsschema.CpuGroup{Id: opts.CPUGroupID}
}

doc := &hcsschema.ComputeSystem{
Owner: uvm.owner,
SchemaVersion: schemaversion.SchemaV21(),
Expand All @@ -148,11 +162,7 @@ func prepareConfigDoc(ctx context.Context, uvm *UtilityVM, opts *OptionsWCOW, uv
HighMMIOBaseInMB: opts.HighMMIOBaseInMB,
HighMMIOGapInMB: opts.HighMMIOGapInMB,
},
Processor: &hcsschema.Processor2{
Count: uvm.processorCount,
Limit: opts.ProcessorLimit,
Weight: opts.ProcessorWeight,
},
Processor: processor,
},
Devices: &hcsschema.Devices{
HvSocket: &hcsschema.HvSocket2{
Expand Down Expand Up @@ -215,7 +225,6 @@ func CreateWCOW(ctx context.Context, opts *OptionsWCOW) (_ *UtilityVM, err error
vpciDevices: make(map[string]*VPCIDevice),
physicallyBacked: !opts.AllowOvercommit,
devicesPhysicallyBacked: opts.FullyPhysicallyBacked,
cpuGroupID: opts.CPUGroupID,
createOpts: *opts,
}

Expand Down
7 changes: 0 additions & 7 deletions internal/uvm/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,6 @@ func (uvm *UtilityVM) Start(ctx context.Context) (err error) {
}
}()

// assign the VM to the cpugroup specified, if any
if uvm.cpuGroupID != "" {
if err := uvm.SetCPUGroup(ctx, uvm.cpuGroupID); err != nil {
return err
}
}

// Start waiting on the utility VM.
uvm.exitCh = make(chan struct{})
go func() {
Expand Down
3 changes: 0 additions & 3 deletions internal/uvm/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ type UtilityVM struct {
// Access to this variable should be done atomically.
mountCounter uint64

// cpuGroupID is the ID of the cpugroup on the host that this UVM is assigned to
cpuGroupID string

// specifies if this UVM is created to be saved as a template
IsTemplate bool

Expand Down