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

Add cpuset helper library. #51132

Merged
merged 3 commits into from
Aug 25, 2017

Conversation

ConnorDoyle
Copy link
Contributor

@ConnorDoyle ConnorDoyle commented Aug 22, 2017

Blocker for CPU manager #49186 (2 of 6)

@sjenning @derekwaynecarr

NONE

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 22, 2017
@k8s-github-robot k8s-github-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. release-note-label-needed labels Aug 22, 2017
@ncdc
Copy link
Member

ncdc commented Aug 22, 2017

/assign @derekwaynecarr @sjenning
/unassign

@k8s-ci-robot k8s-ci-robot assigned derekwaynecarr and sjenning and unassigned ncdc Aug 22, 2017
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-label-needed labels Aug 22, 2017
@ConnorDoyle
Copy link
Contributor Author

/release-note-none

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Aug 22, 2017
@ConnorDoyle ConnorDoyle mentioned this pull request Aug 22, 2017
6 tasks
}

// Add mutates this set to contain the supplied elements.
func (s CPUSet) Add(cpus ...int) {
Copy link
Contributor

@resouer resouer Aug 23, 2017

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?

Copy link
Contributor Author

@ConnorDoyle ConnorDoyle Aug 23, 2017

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()
}

Copy link
Contributor Author

@ConnorDoyle ConnorDoyle Aug 23, 2017

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.

Copy link
Contributor

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

)

// CPUSet is a set-like data structure for CPU IDs.
type CPUSet map[int]struct{}
Copy link
Contributor

@resouer resouer Aug 23, 2017

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

sgtm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

return s.FilterNot(func(cpu int) bool { return s2.Contains(cpu) })
}

// AsSlice returns a slice of integers that contains all elements from
Copy link
Contributor

@resouer resouer Aug 23, 2017

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to ToSlice()

@ConnorDoyle
Copy link
Contributor Author

Fixed comments

@ConnorDoyle
Copy link
Contributor Author

/retest

@derekwaynecarr
Copy link
Member

/lgtm
/approve

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.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 24, 2017
@k8s-github-robot
Copy link

[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 /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 24, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 50033, 49988, 51132, 49674, 51207)

@k8s-github-robot k8s-github-robot merged commit fe0c519 into kubernetes:master Aug 25, 2017
@ConnorDoyle ConnorDoyle deleted the cpuset-helpers branch August 25, 2017 18:11
k8s-github-robot pushed a commit that referenced this pull request Aug 30, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants