Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support updating cpugroup membership #1202

Merged
merged 1 commit into from
Oct 27, 2021
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
Support updating cpugroup membership
Signed-off-by: Kathryn Baldauf <kabaldau@microsoft.com>
  • Loading branch information
katiewasnothere committed Oct 20, 2021
commit ac4a76a71168cd35647f72f22ff729eedd07725f
8 changes: 8 additions & 0 deletions internal/hcs/schema2/cpu_group_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@

package hcsschema

type CPUGroupPropertyCode uint32

const (
CPUCapacityProperty = 0x00010000
CPUSchedulingPriorityProperty = 0x00020000
IdleLPReserveProperty = 0x00030000
)

type CpuGroupProperty struct {
PropertyCode uint32 `json:"PropertyCode,omitempty"`
PropertyValue uint32 `json:"PropertyValue,omitempty"`
Expand Down
6 changes: 2 additions & 4 deletions internal/uvm/cpugroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import (
"github.com/Microsoft/hcsshim/internal/cpugroup"
"github.com/Microsoft/hcsshim/internal/hcs/resourcepaths"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
"github.com/Microsoft/hcsshim/osversion"
)

// 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)
var errCPUGroupCreateNotSupported = fmt.Errorf("cpu group assignment on create requires a build of %d or higher", osversion.V21H1)

// ReleaseCPUGroup unsets the cpugroup from the VM
func (uvm *UtilityVM) ReleaseCPUGroup(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/uvm/create_lcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func CreateLCOW(ctx context.Context, opts *OptionsLCOW) (_ *UtilityVM, err error
}
// We can set a cpu group for the VM at creation time in recent builds.
if opts.CPUGroupID != "" {
if osversion.Build() < cpuGroupCreateBuild {
if osversion.Build() < osversion.V21H1 {
return nil, errCPUGroupCreateNotSupported
}
processor.CpuGroup = &hcsschema.CpuGroup{Id: opts.CPUGroupID}
Expand Down
2 changes: 1 addition & 1 deletion internal/uvm/create_wcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func prepareConfigDoc(ctx context.Context, uvm *UtilityVM, opts *OptionsWCOW, uv
}
// We can set a cpu group for the VM at creation time in recent builds.
if opts.CPUGroupID != "" {
if osversion.Build() < cpuGroupCreateBuild {
if osversion.Build() < osversion.V21H1 {
return nil, errCPUGroupCreateNotSupported
}
processor.CpuGroup = &hcsschema.CpuGroup{Id: opts.CPUGroupID}
Expand Down
10 changes: 9 additions & 1 deletion internal/uvm/update_uvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"

hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
"github.com/Microsoft/hcsshim/pkg/annotations"
specs "github.com/opencontainers/runtime-spec/specs-go"
)

func (uvm *UtilityVM) UpdateConstraints(ctx context.Context, data interface{}, annotations map[string]string) error {
func (uvm *UtilityVM) UpdateConstraints(ctx context.Context, data interface{}, annots map[string]string) error {
var memoryLimitInBytes *uint64
var processorLimits *hcsschema.ProcessorLimits

Expand Down Expand Up @@ -52,5 +53,12 @@ func (uvm *UtilityVM) UpdateConstraints(ctx context.Context, data interface{}, a
}
}

// Check if an annotation was sent to update cpugroup membership
if cpuGroupID, ok := annots[annotations.CPUGroupID]; ok {
if err := uvm.SetCPUGroup(ctx, cpuGroupID); err != nil {
return err
}
}

return nil
}
103 changes: 103 additions & 0 deletions test/cri-containerd/pod_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import (
"fmt"
"testing"

"github.com/Microsoft/hcsshim/internal/cpugroup"
"github.com/Microsoft/hcsshim/internal/processorinfo"
"github.com/Microsoft/hcsshim/osversion"
"github.com/Microsoft/hcsshim/pkg/annotations"
testutilities "github.com/Microsoft/hcsshim/test/functional/utilities"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
)

Expand Down Expand Up @@ -215,3 +219,102 @@ func Test_Pod_UpdateResources_CPUShares(t *testing.T) {
})
}
}

func Test_Pod_UpdateResources_CPUGroup(t *testing.T) {
testutilities.RequiresBuild(t, osversion.V21H1)
ctx := context.Background()

processorTopology, err := processorinfo.HostProcessorInfo(ctx)
if err != nil {
t.Fatalf("failed to get host processor information: %s", err)
}
lpIndices := make([]uint32, processorTopology.LogicalProcessorCount)
for i, p := range processorTopology.LogicalProcessors {
lpIndices[i] = p.LpIndex
}

startCPUGroupID := "FA22A12C-36B3-486D-A3E9-BC526C2B450B"
if err := cpugroup.Create(ctx, startCPUGroupID, lpIndices); err != nil {
t.Fatalf("failed to create test cpugroup with: %v", err)
}

defer func() {
err := cpugroup.Delete(ctx, startCPUGroupID)
if err != nil && err != cpugroup.ErrHVStatusInvalidCPUGroupState {
t.Fatalf("failed to clean up test cpugroup with: %v", err)
}
}()

updateCPUGroupID := "FA22A12C-36B3-486D-A3E9-BC526C2B450C"
if err := cpugroup.Create(ctx, updateCPUGroupID, lpIndices); err != nil {
t.Fatalf("failed to create test cpugroup with: %v", err)
}

defer func() {
err := cpugroup.Delete(ctx, updateCPUGroupID)
if err != nil && err != cpugroup.ErrHVStatusInvalidCPUGroupState {
t.Fatalf("failed to clean up test cpugroup with: %v", err)
}
}()

type config struct {
name string
requiredFeatures []string
runtimeHandler string
sandboxImage string
}

tests := []config{
{
name: "WCOW_Hypervisor",
requiredFeatures: []string{featureWCOWHypervisor},
runtimeHandler: wcowHypervisorRuntimeHandler,
sandboxImage: imageWindowsNanoserver,
},
{
name: "LCOW",
requiredFeatures: []string{featureLCOW},
runtimeHandler: lcowRuntimeHandler,
sandboxImage: imageLcowK8sPause,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
requireFeatures(t, test.requiredFeatures...)
if test.runtimeHandler == lcowRuntimeHandler {
pullRequiredLCOWImages(t, []string{test.sandboxImage})
} else {
pullRequiredImages(t, []string{test.sandboxImage})
}

podRequest := getRunPodSandboxRequest(t, test.runtimeHandler, WithSandboxAnnotations(map[string]string{
annotations.CPUGroupID: startCPUGroupID,
}))
client := newTestRuntimeClient(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

podID := runPodSandbox(t, client, ctx, podRequest)
defer removePodSandbox(t, client, ctx, podID)
defer stopPodSandbox(t, client, ctx, podID)

updateReq := &runtime.UpdateContainerResourcesRequest{
ContainerId: podID,
Annotations: map[string]string{
annotations.CPUGroupID: updateCPUGroupID,
},
}

if test.runtimeHandler == lcowRuntimeHandler {
updateReq.Linux = &runtime.LinuxContainerResources{}
} else {
updateReq.Windows = &runtime.WindowsContainerResources{}
}

if _, err := client.UpdateContainerResources(ctx, updateReq); err != nil {
anmaxvl marked this conversation as resolved.
Show resolved Hide resolved
t.Fatalf("updating container resources for %s with %v", podID, err)
}
})
}
}
2 changes: 1 addition & 1 deletion test/cri-containerd/runpodsandbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ func Test_RunPodSandbox_Mount_SandboxDir_NoShare_WCOW(t *testing.T) {
}

func Test_RunPodSandbox_CPUGroup(t *testing.T) {
testutilities.RequiresBuild(t, 20124)
testutilities.RequiresBuild(t, osversion.V21H1)
ctx := context.Background()
presentID := "FA22A12C-36B3-486D-A3E9-BC526C2B450B"

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.