Skip to content
Closed
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
4 changes: 4 additions & 0 deletions cmd/containerd-shim-runhcs-v1/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ func createPod(ctx context.Context, events publisher, req *task.CreateTaskReques
parent.Close()
return nil, err
}
if err := oci.HandleCPUGroupSetup(ctx, parent, s.Annotations); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't like passing in the UVM into the oci package and having it do work against it. Can we just cache the processorTopology information we get when we call HostProcessorInfo during UVM setup and just pass this into an exported AnnotationsToCpuGroupOptions and have this return the info we need?

parent.Close()
return nil, err
}
} else if !isWCOW {
return nil, errors.Wrap(errdefs.ErrFailedPrecondition, "oci spec does not contain WCOW or LCOW spec")
}
Expand Down
41 changes: 41 additions & 0 deletions internal/oci/cpugroup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package oci

import (
"context"
"fmt"

"github.com/Microsoft/hcsshim/internal/uvm"
)

// HandleCPUGroupSetup will parse the cpugroup annotations and setup the cpugroup for `vm`
func HandleCPUGroupSetup(ctx context.Context, vm *uvm.UtilityVM, annotations map[string]string) error {
cpuGroupOpts, err := annotationsToCPUGroupOptions(ctx, annotations)
if err != nil {
return err
}
if err := vm.ConfigureVMCPUGroup(ctx, cpuGroupOpts); err != nil {
return err
}
return nil
}

// annotationsToCPUGroupOptions parses the related cpugroup annotations and creates the CPUGroupOptions from the values
func annotationsToCPUGroupOptions(ctx context.Context, annotations map[string]string) (*uvm.CPUGroupOptions, error) {
processorTopology, err := uvm.HostProcessorInfo(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get host processor information: %s", err)
}
lpIndices := []uint32{}
for _, l := range processorTopology.LogicalProcessors {
lpIndices = append(lpIndices, l.LpIndex)
}

opts := &uvm.CPUGroupOptions{
CreateRandomID: parseAnnotationsBool(ctx, annotations, annotationCPUGroupCreateRandomID, false),
ID: parseAnnotationsString(annotations, annotationCPUGroupID, uvm.CPUGroupNullID),
LogicalProcessors: parseCommaSeperatedUint32(annotations, annotationCPUGroupLPs, lpIndices),
Cap: parseAnnotationsUint32(ctx, annotations, annotationCPUGroupCap, uvm.DefaultCPUGroupCap),
Priority: parseAnnotationsUint32(ctx, annotations, annotationCPUGroupPriority, uvm.DefaultCPUGroupPriority),
}
return opts, nil
}
26 changes: 26 additions & 0 deletions internal/oci/uvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ const (
// HCS-GCS bridge. Default value is true which means external bridge will be used
// by default.
annotationUseExternalGCSBridge = "io.microsoft.virtualmachine.useexternalgcsbridge"

// annotations relating to cpugroup creation
annotationCPUGroupCreateRandomID = "io.microsoft.virtualmachine.cpugroup.randomid"
annotationCPUGroupID = "io.microsoft.virtualmachine.cpugroup.id"
annotationCPUGroupLPs = "io.microsoft.virtualmachine.cpugroup.logicalprocessors"
annotationCPUGroupCap = "io.microsoft.virtualmachine.cpugroup.cap"
annotationCPUGroupPriority = "io.microsoft.virtualmachine.cpugroup.priority"
)

// parseAnnotationsBool searches `a` for `key` and if found verifies that the
Expand Down Expand Up @@ -318,6 +325,25 @@ func parseAnnotationsString(a map[string]string, key string, def string) string
return def
}

// parseCommaSeperatedUint32 searches `a` for `key`. If found verifies that the value
// is a comma separated slice of 32 bit unsigned integers. If `key` is not found,
// returns `def`.
func parseCommaSeperatedUint32(annotations map[string]string, key string, def []uint32) []uint32 {
if v, ok := annotations[key]; ok {
splitStrings := strings.Split(v, ",")
result := make([]uint32, len(splitStrings))
for i, c := range splitStrings {
countu, err := strconv.ParseUint(c, 10, 32)
if err != nil {
return def
}
result[i] = uint32(countu)
}
return result
}
return def
}

// handleAnnotationKernelDirectBoot handles parsing annotationKernelDirectBoot and setting
// implied annotations from the result.
func handleAnnotationKernelDirectBoot(ctx context.Context, a map[string]string, lopts *uvm.OptionsLCOW) {
Expand Down
15 changes: 15 additions & 0 deletions internal/schema2/cpu_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* HCS API
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 2.4
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/

package hcsschema

// CPU groups allow Hyper-V administrators to better manage and allocate the host's CPU resources across guest virtual machines
type CpuGroup struct {
Id string `json:"Id,omitempty"`
}
15 changes: 15 additions & 0 deletions internal/schema2/cpu_group_affinity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* HCS API
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 2.4
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/

package hcsschema

type CpuGroupAffinity struct {
LogicalProcessorCount int32 `json:"LogicalProcessorCount,omitempty"`
LogicalProcessors []int32 `json:"LogicalProcessors,omitempty"`
}
18 changes: 18 additions & 0 deletions internal/schema2/cpu_group_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* HCS API
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 2.4
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/

package hcsschema

type CpuGroupConfig struct {
GroupId string `json:"GroupId,omitempty"`
Affinity *CpuGroupAffinity `json:"Affinity,omitempty"`
GroupProperties []CpuGroupProperty `json:"GroupProperties,omitempty"`
// Hypervisor CPU group IDs exposed to clients
HypervisorGroupId int32 `json:"HypervisorGroupId,omitempty"`
}
15 changes: 15 additions & 0 deletions internal/schema2/cpu_group_configurations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* HCS API
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 2.4
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/

package hcsschema

// Structure used to return cpu groups for a Service property query
type CpuGroupConfigurations struct {
CpuGroups []CpuGroupConfig `json:"CpuGroups,omitempty"`
}
18 changes: 18 additions & 0 deletions internal/schema2/cpu_group_operations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* HCS API
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 2.4
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/

package hcsschema

type CPUGroupOperation string

const (
CreateGroup CPUGroupOperation = "CreateGroup"
DeleteGroup CPUGroupOperation = "DeleteGroup"
SetProperty CPUGroupOperation = "SetProperty"
)
15 changes: 15 additions & 0 deletions internal/schema2/cpu_group_property.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* HCS API
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 2.4
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/

package hcsschema

type CpuGroupProperty struct {
PropertyCode uint32 `json:"PropertyCode,omitempty"`
PropertyValue uint32 `json:"PropertyValue,omitempty"`
}
17 changes: 17 additions & 0 deletions internal/schema2/create_group_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* HCS API
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 2.4
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/

package hcsschema

// Create group operation settings
type CreateGroupOperation struct {
GroupId string `json:"GroupId,omitempty"`
LogicalProcessorCount uint32 `json:"LogicalProcessorCount,omitempty"`
LogicalProcessors []uint32 `json:"LogicalProcessors,omitempty"`
}
15 changes: 15 additions & 0 deletions internal/schema2/delete_group_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* HCS API
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 2.4
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/

package hcsschema

// Delete group operation settings
type DeleteGroupOperation struct {
GroupId string `json:"GroupId,omitempty"`
}
16 changes: 16 additions & 0 deletions internal/schema2/host_processor_modify_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* HCS API
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 2.4
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/

package hcsschema

// Structure used to request a service processor modification
type HostProcessorModificationRequest struct {
Operation CPUGroupOperation `json:"Operation,omitempty"`
OperationDetails interface{} `json:"OperationDetails,omitempty"`
}
1 change: 1 addition & 0 deletions internal/schema2/property_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ const (
PTGuestConnection PropertyType = "GuestConnection"
PTICHeartbeatStatus PropertyType = "ICHeartbeatStatus"
PTProcessorTopology PropertyType = "ProcessorTopology"
PTCPUGroup PropertyType = "CpuGroup"
)
22 changes: 22 additions & 0 deletions internal/schema2/set_property_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* HCS API
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 2.4
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/

package hcsschema

const (
CpuCapPropertyCode = uint32(0x00010000)
SchedulingPriorityPropertyCode = uint32(0x00020000)
)

// Set properties operation settings
type SetPropertyOperation struct {
GroupId string `json:"GroupId,omitempty"`
PropertyCode uint32 `json:"PropertyCode,omitempty"`
PropertyValue uint32 `json:"PropertyValue,omitempty"`
}
Loading