-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Add cpuset helper library. #51132
Add cpuset helper library. #51132
Conversation
/assign @derekwaynecarr @sjenning |
32fe4ac
to
8f38abb
Compare
/release-note-none |
pkg/kubelet/cm/cpuset/cpuset.go
Outdated
} | ||
|
||
// Add mutates this set to contain the supplied elements. | ||
func (s CPUSet) Add(cpus ...int) { |
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.
Is there possibility of data race during operating this data structure?
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.
Yes there is. Add and Remove are not safe to call in a concurrent context. Is it sufficient to document this? The expected use of Add and Remove follows the examples in this package, mutating "owned" references as in:
func myCoolFunction() cpuset.CPUSet {
result := cpuset.NewCPUSet()
for i := 0; i < 10; i++ {
result.Add(i)
}
return result
}
If a doc update isn't sufficient, I would prefer not to add an RWLock to this type. Another option could be to encode the expected use by creating a mutable builder type from which the user can retrieve the immutable result CPUSet (I quite like this idea). That could look something like this:
func myCoolFunction() cpuset.CPUSet {
builder := cpuset.NewBuilder()
for i := 0; i < 10; i++ {
builder.Add(i)
}
return builder.Result()
}
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.
Updated; added Builder
and made CPUSet
immutable outside of the cpuset
package.
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.
Thanks, the builder design make sense
pkg/kubelet/cm/cpuset/cpuset.go
Outdated
) | ||
|
||
// CPUSet is a set-like data structure for CPU IDs. | ||
type CPUSet map[int]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.
Do you think it make sense to use uint64 or uint32 instead of int?
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.
How about just uint
, which is guaranteed to be at least 32 bits wide?
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.
I'm not totally convinced it's worth it to use an unsigned type here, in terms of the inconvenience to calling code. In practice, on any real system the valid elements are already a tiny subset of int
, and int
is similarly guaranteed to be at least 32 bits wide.
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.
sgtm
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.
👍
pkg/kubelet/cm/cpuset/cpuset.go
Outdated
return s.FilterNot(func(cpu int) bool { return s2.Contains(cpu) }) | ||
} | ||
|
||
// AsSlice returns a slice of integers that contains all elements from |
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.
It seem ToSlice() sounds better here.
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.
No opinion either way on this, will update.
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.
Renamed to ToSlice()
cd1026b
to
9c46e53
Compare
Fixed comments |
9c46e53
to
780f8e9
Compare
780f8e9
to
515d86f
Compare
/retest |
/lgtm Can I ask that you use sets.Int internally in the implementation in a follow-on PR so we do not have to keep the set arithmetic stuff duplicated? I don't want to block follow-on changes on this simple refactor. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ConnorDoyle, derekwaynecarr Associated issue: 49186 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
Automatic merge from submit-queue (batch tested with PRs 50033, 49988, 51132, 49674, 51207) |
Automatic merge from submit-queue (batch tested with PRs 51439, 51361, 51140, 51539, 51585) CPU manager interfaces. Please review / merge #51132 first. Blocker for CPU manager #49186 (3 of 6) @sjenning @derekwaynecarr
Blocker for CPU manager #49186 (2 of 6)
@sjenning @derekwaynecarr