-
Notifications
You must be signed in to change notification settings - Fork 287
jobobject,jobcontainers,hcsoci: add CPU group affinity support for job-object containers #2693
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
Open
wenyang
wants to merge
10
commits into
microsoft:main
Choose a base branch
from
wenyang:feature/windows-cpu-affinity-hcs-containers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0ef80ab
hcsoci: wire Windows CPU affinity to HCS container processor schema
95fdd2d
Retry CI
4782c00
hcsoci: address PR review comments
b1bb00b
jobobject: add tests for CPU group affinity
f12d4ae
jobobject: fix GetCPUGroupAffinities to use retry pattern instead of …
4d02dd9
jobobject: add test for GetCPUGroupAffinities on unaffinied job
296a13c
jobobject: fix TestGetCPUGroupAffinitiesNoAffinitySet expectation
eed2745
Update internal/hcsoci/hcsdoc_wcow.go
wenyang 6fd200f
hcsoci,task_hcs: remove incorrect HCS container CPU GROUP_AFFINITY sc…
ae42312
hcsoci,jobcontainers: rename ConvertCPUAffinity to ValidateCPUAffinity
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| // ProcessorGroupAffinity specifies a processor group and an affinity mask within | ||
| // that group for an HCS container. It mirrors the Win32 GROUP_AFFINITY structure. | ||
| // Requires Windows Server 2022 (build 20348) or later. | ||
| // https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/miniport/ns-miniport-_group_affinity | ||
| type ProcessorGroupAffinity struct { | ||
| // Mask is the bitmask of processors within Group. | ||
| Mask uint64 `json:"Mask,omitempty"` | ||
| // Group is the processor group number (0-based). Group 0 is the most common | ||
| // value; the tag intentionally omits omitempty so that group 0 is not | ||
| // silently dropped from the JSON sent to HCS. | ||
| Group uint16 `json:"Group"` | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| //go:build windows | ||
|
|
||
| package hcsoci | ||
|
|
||
| import ( | ||
| "errors" | ||
| "testing" | ||
|
|
||
| specs "github.com/opencontainers/runtime-spec/specs-go" | ||
|
|
||
| "github.com/Microsoft/hcsshim/osversion" | ||
| ) | ||
|
|
||
| func TestConvertCPUAffinity_Group0MaskSet(t *testing.T) { | ||
| s := &specs.Spec{ | ||
| Windows: &specs.Windows{ | ||
| Resources: &specs.WindowsResources{ | ||
| CPU: &specs.WindowsCPUResources{ | ||
| Affinity: []specs.WindowsCPUGroupAffinity{ | ||
| {Mask: 0x3, Group: 0}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| affinities, err := ConvertCPUAffinity(s) | ||
| if err != nil { | ||
| t.Fatalf("ConvertCPUAffinity failed: %v", err) | ||
| } | ||
| if len(affinities) != 1 || affinities[0].Mask != 0x3 || affinities[0].Group != 0 { | ||
| t.Fatalf("unexpected cpu affinity: got %v", affinities) | ||
| } | ||
| } | ||
|
|
||
| func TestConvertCPUAffinity_MultiGroup(t *testing.T) { | ||
| s := &specs.Spec{ | ||
| Windows: &specs.Windows{ | ||
| Resources: &specs.WindowsResources{ | ||
| CPU: &specs.WindowsCPUResources{ | ||
| Affinity: []specs.WindowsCPUGroupAffinity{ | ||
| {Mask: 0x1, Group: 0}, | ||
| {Mask: 0x1, Group: 1}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| affinities, err := ConvertCPUAffinity(s) | ||
| if osversion.Build() >= osversion.LTSC2022 { | ||
| // Multi-group is supported on WS2022+. | ||
| if err != nil { | ||
| t.Fatalf("expected success for multi-group on WS2022+, got: %v", err) | ||
| } | ||
| if len(affinities) != 2 { | ||
| t.Fatalf("expected 2 affinity entries, got %d", len(affinities)) | ||
| } | ||
| } else { | ||
| if err == nil { | ||
| t.Fatal("expected error for multiple affinity entries on pre-WS2022") | ||
| } | ||
| if !errors.Is(err, ErrCPUAffinityMultipleGroupsNotSupported) { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestConvertCPUAffinity_NonZeroGroup(t *testing.T) { | ||
| s := &specs.Spec{ | ||
| Windows: &specs.Windows{ | ||
| Resources: &specs.WindowsResources{ | ||
| CPU: &specs.WindowsCPUResources{ | ||
| Affinity: []specs.WindowsCPUGroupAffinity{ | ||
| {Mask: 0x1, Group: 1}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| affinities, err := ConvertCPUAffinity(s) | ||
| if osversion.Build() >= osversion.LTSC2022 { | ||
| // Non-zero group is supported on WS2022+. | ||
| if err != nil { | ||
| t.Fatalf("expected success for non-zero group on WS2022+, got: %v", err) | ||
| } | ||
| if len(affinities) != 1 || affinities[0].Group != 1 { | ||
| t.Fatalf("unexpected affinity: got %v", affinities) | ||
| } | ||
| } else { | ||
| if err == nil { | ||
| t.Fatal("expected error for non-zero affinity group on pre-WS2022") | ||
| } | ||
| if !errors.Is(err, ErrCPUAffinityNonZeroGroupNotSupported) { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestConvertCPUAffinity_ZeroMaskRejected(t *testing.T) { | ||
| s := &specs.Spec{ | ||
| Windows: &specs.Windows{ | ||
| Resources: &specs.WindowsResources{ | ||
| CPU: &specs.WindowsCPUResources{ | ||
| Affinity: []specs.WindowsCPUGroupAffinity{ | ||
| {Mask: 0, Group: 0}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| _, err := ConvertCPUAffinity(s) | ||
| if err == nil { | ||
| t.Fatal("expected error for zero affinity mask") | ||
| } | ||
| if !errors.Is(err, ErrCPUAffinityMaskZero) { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestConvertCPUAffinity_NoAffinity(t *testing.T) { | ||
| testCases := []struct { | ||
| name string | ||
| spec *specs.Spec | ||
| }{ | ||
| { | ||
| name: "nil spec.Windows", | ||
| spec: &specs.Spec{}, | ||
| }, | ||
| { | ||
| name: "nil spec.Windows.Resources", | ||
| spec: &specs.Spec{ | ||
| Windows: &specs.Windows{}, | ||
| }, | ||
| }, | ||
| { | ||
| name: "nil spec.Windows.Resources.CPU", | ||
| spec: &specs.Spec{ | ||
| Windows: &specs.Windows{ | ||
| Resources: &specs.WindowsResources{}, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "empty affinity slice", | ||
| spec: &specs.Spec{ | ||
| Windows: &specs.Windows{ | ||
| Resources: &specs.WindowsResources{ | ||
| CPU: &specs.WindowsCPUResources{ | ||
| Affinity: []specs.WindowsCPUGroupAffinity{}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| affinities, err := ConvertCPUAffinity(tc.spec) | ||
| if err != nil { | ||
| t.Fatalf("ConvertCPUAffinity failed: %v", err) | ||
| } | ||
| if len(affinities) != 0 { | ||
| t.Fatalf("expected empty affinities, got %v", affinities) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.