-
Couldn't load subscription status.
- Fork 2k
Use core ID when selecting cores #25340
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
Merged
allisonlarson
merged 3 commits into
hashicorp:main
from
carlosgaldino:carlosgaldino/fix-numa-core-selector-panic
Apr 10, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ```release-note:bug | ||
| scheduler: Use core ID when selecting cores. This fixes a panic in the scheduler when the `reservable_cores` is not a contiguous list of core IDs. | ||
| ``` |
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,92 @@ | ||
| package scheduler | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/nomad/client/lib/idset" | ||
| "github.com/hashicorp/nomad/client/lib/numalib" | ||
| "github.com/hashicorp/nomad/client/lib/numalib/hw" | ||
| "github.com/hashicorp/nomad/nomad/structs" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestCoreSelectorSelect(t *testing.T) { | ||
| var ( | ||
| totalCores = 46 | ||
| maxSpeed = 100 | ||
| coreIds = make([]uint16, totalCores) | ||
| cores = make([]numalib.Core, totalCores) | ||
| ) | ||
| for i := 1; i < 24; i++ { | ||
| coreIds[i-1] = uint16(i) | ||
| cores[i-1] = numalib.Core{ | ||
| SocketID: 0, | ||
| NodeID: 0, | ||
| ID: hw.CoreID(i), | ||
| Grade: false, | ||
| Disable: false, | ||
| BaseSpeed: 0, | ||
| MaxSpeed: hw.MHz(maxSpeed), | ||
| GuessSpeed: 0, | ||
| } | ||
| } | ||
| for i := 25; i < 48; i++ { | ||
| coreIds[i-2] = uint16(i) | ||
| cores[i-2] = numalib.Core{ | ||
| SocketID: 0, | ||
| NodeID: 0, | ||
| ID: hw.CoreID(i), | ||
| Grade: false, | ||
| Disable: false, | ||
| BaseSpeed: 0, | ||
| MaxSpeed: hw.MHz(maxSpeed), | ||
| GuessSpeed: 0, | ||
| } | ||
| } | ||
| require.Equal(t, coreIds, []uint16{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}) | ||
|
|
||
| selector := &coreSelector{ | ||
| topology: &numalib.Topology{ | ||
| Cores: cores, | ||
| }, | ||
| availableCores: idset.From[hw.CoreID](coreIds), | ||
| } | ||
|
|
||
| for _, test := range []struct { | ||
| name string | ||
| resources *structs.Resources | ||
| expectedIds []uint16 | ||
| expectedMhz hw.MHz | ||
| }{ | ||
| { | ||
| name: "request all cores", | ||
| resources: &structs.Resources{ | ||
| Cores: totalCores, | ||
| }, | ||
| expectedIds: coreIds, | ||
| expectedMhz: hw.MHz(totalCores * maxSpeed), | ||
| }, | ||
| { | ||
| name: "request half the cores", | ||
| resources: &structs.Resources{ | ||
| Cores: 10, | ||
| }, | ||
| expectedIds: coreIds[:10], | ||
| expectedMhz: hw.MHz(10 * maxSpeed), | ||
| }, | ||
| { | ||
| name: "request one core", | ||
| resources: &structs.Resources{ | ||
| Cores: 1, | ||
| }, | ||
| expectedIds: coreIds[:1], | ||
| expectedMhz: hw.MHz(1 * maxSpeed), | ||
| }, | ||
| } { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| ids, mhz := selector.Select(test.resources) | ||
| require.Equal(t, test.expectedIds, ids) | ||
| require.Equal(t, test.expectedMhz, mhz) | ||
| }) | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know what you think about leaving it like this, or if it's better to rework how the cores are stored in the
struct.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine; we want to keep that data structure the same due to requirements in the enterprise version.