Skip to content

Commit

Permalink
libct/cg/fs: fix setting rt_period vs rt_runtime
Browse files Browse the repository at this point in the history
The issue is the same as in commit 1b2adcf but for RT scheduler;
the fix is also the same.

Test case by ls-ggg.

Co-authored-by: ls-ggg <[email protected]>
Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin and ls-ggg committed Apr 25, 2024
1 parent e74ff0f commit b60079e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
20 changes: 18 additions & 2 deletions libcontainer/cgroups/fs/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,31 @@ func (s *CpuGroup) Apply(path string, r *configs.Resources, pid int) error {
}

func (s *CpuGroup) SetRtSched(path string, r *configs.Resources) error {
var period string
if r.CpuRtPeriod != 0 {
if err := cgroups.WriteFile(path, "cpu.rt_period_us", strconv.FormatUint(r.CpuRtPeriod, 10)); err != nil {
return err
period = strconv.FormatUint(r.CpuRtPeriod, 10)
if err := cgroups.WriteFile(path, "cpu.rt_period_us", period); err != nil {
// The values of cpu.rt_period_us and cpu.rt_runtime_us
// are inter-dependent and need to be set in a proper order.
// If the kernel rejects the new period value with EINVAL
// and the new runtime value is also being set, let's
// ignore the error for now and retry later.
if !errors.Is(err, unix.EINVAL) || r.CpuRtRuntime == 0 {
return err
}
} else {
period = ""
}
}
if r.CpuRtRuntime != 0 {
if err := cgroups.WriteFile(path, "cpu.rt_runtime_us", strconv.FormatInt(r.CpuRtRuntime, 10)); err != nil {
return err
}
if period != "" {
if err := cgroups.WriteFile(path, "cpu.rt_period_us", period); err != nil {
return err
}
}
}
return nil
}
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,17 @@ EOF

check_cgroup_value "cpu.rt_period_us" 900001
check_cgroup_value "cpu.rt_runtime_us" 600001

# https://github.com/opencontainers/runc/issues/4094
runc update test_update_rt --cpu-rt-period 10000 --cpu-rt-runtime 3000
[ "$status" -eq 0 ]
check_cgroup_value "cpu.rt_period_us" 10000
check_cgroup_value "cpu.rt_runtime_us" 3000

runc update test_update_rt --cpu-rt-period 100000 --cpu-rt-runtime 20000
[ "$status" -eq 0 ]
check_cgroup_value "cpu.rt_period_us" 100000
check_cgroup_value "cpu.rt_runtime_us" 20000
}

@test "update devices [minimal transition rules]" {
Expand Down

0 comments on commit b60079e

Please sign in to comment.