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

[Carry 3962] Support process.scheduler #4025

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

lifubang
Copy link
Member

@lifubang lifubang commented Sep 25, 2023

(this is a carry of #3962)

Spec: opencontainers/runtime-spec#1188
Close: #3895 #3962

@lifubang lifubang force-pushed the feat-sched-carry-3962 branch 2 times, most recently from ecd3e1a to 8d1145b Compare September 25, 2023 11:08
@@ -81,6 +81,7 @@ func (p *setnsProcess) signal(sig os.Signal) error {

func (p *setnsProcess) start() (retErr error) {
defer p.messageSockPair.parent.Close()

Copy link
Contributor

Choose a reason for hiding this comment

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

unrelated; please remove

Comment on lines 71 to 72
if errors.Is(err, unix.EPERM) {
return fmt.Errorf("error setting scheduler(please check you have appropriate privileges or valid cpus config): %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you do want to distinguish between the two cases for EPERM, maybe it makes sense to check if we have cpus set first.

Also, maybe move this code into a separate function (setupScheduler), as we have the same 8 lines of code in both setns_init_linux.go and standard_init_linux.go

Copy link
Member Author

@lifubang lifubang Sep 27, 2023

Choose a reason for hiding this comment

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

maybe it makes sense to check if we have cpus set first.

I also considered it when writing the code, but there is another corner case is that if the cpus value includes all cpus in the machine, it will be no error. So I don't want to check cpus value.

Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

@lifubang thanks for the carry! Left some comments, mostly minor.

@lifubang lifubang force-pushed the feat-sched-carry-3962 branch 3 times, most recently from 3087839 to dc3aa07 Compare September 28, 2023 15:15
@lifubang
Copy link
Member Author

@lifubang thanks for the carry! Left some comments, mostly minor.

Thanks, there are all resolved, PTAL.

return nil
}
if s.Policy == "" {
return fmt.Errorf("scheduler policy is required")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: errors.New.

Comment on lines 368 to 370
niceValue := s.Nice
if niceValue < -20 || niceValue > 19 {
return fmt.Errorf("invalid scheduler.nice: %d", niceValue)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to use s.Nice directly (drop the intermediate variable) here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the original author used an intermediate variable because repeating config.Scheduler.Nice three times was too much.

But, just in case an intermediate variable is preferred, it is better to limit its scope:

if n := s.Nice; n < -20 || n > 19 {
	return fmt.Errorf("invalid scheduler.nice: %d", n)
}

Comment on lines 640 to 642
if config.Cgroups.CpusetCpus == "" {
return errors.New("please check you have appropriate privileges to set process scheduler")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe don't make this a special case.

I.e. something like

if err := unix.SchedSetAttr(0, attr, 0); err != nil {
    if errors.Is(err, unix.EPERM) && config.Cgroups.CpusetCpus != "" {
        return errors.New("process scheduler can not be used together with AllowedCPUs")
    }
    return fmt.Errorf("error setting scheduler: %w", err)
}

Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

Left some nits.

Also, you can add Co-authored-by: ... footer.

@lifubang lifubang force-pushed the feat-sched-carry-3962 branch 3 times, most recently from eded31e to 25b3d41 Compare October 3, 2023 23:08
@lifubang lifubang marked this pull request as draft October 3, 2023 23:10
@lifubang lifubang force-pushed the feat-sched-carry-3962 branch 2 times, most recently from fd43bb2 to cf74bfc Compare October 4, 2023 03:35
@lifubang lifubang marked this pull request as ready for review October 4, 2023 04:18
@lifubang lifubang requested a review from kolyshkin October 4, 2023 04:18
Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

@lifubang I mean, put yourself as a co-author (@utam0k is already marked as the author, no need to add him as a co-author).

Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

LGTM

Spec: opencontainers/runtime-spec#1188
Fix: opencontainers#3895

Co-authored-by: lifubang <[email protected]>
Signed-off-by: utam0k <[email protected]>
Signed-off-by: lifubang <[email protected]>
@lifubang lifubang force-pushed the feat-sched-carry-3962 branch from cf74bfc to 770728e Compare October 4, 2023 07:53
@AkihiroSuda AkihiroSuda merged commit 0274ca2 into opencontainers:main Oct 11, 2023
45 checks passed
@lifubang lifubang deleted the feat-sched-carry-3962 branch October 15, 2024 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support process.scheduler
4 participants