From 8e7b567a6bedfc689b8710fbacbd9d84d91f350c Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 17 Nov 2016 16:39:47 -0800 Subject: [PATCH] Fix cfs period calculation Signed-off-by: Michael Crosby Upstream-commit: aff99136b44c0a3d9ef381afd38a5cd05328ddc6 Component: engine --- components/engine/daemon/daemon_unix.go | 5 +---- .../engine/integration-cli/docker_cli_run_unix_test.go | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/components/engine/daemon/daemon_unix.go b/components/engine/daemon/daemon_unix.go index 37c4bc09c4..acfa7766b5 100644 --- a/components/engine/daemon/daemon_unix.go +++ b/components/engine/daemon/daemon_unix.go @@ -112,11 +112,8 @@ func getCPUResources(config containertypes.Resources) *specs.CPU { } if config.NanoCPUs > 0 { - // We set the highest value possible (1s), as is specified in: // https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt - // cpu.cfs_period_us=1s - // The purpose is to get the highest precision - period := uint64(1 * time.Second / time.Microsecond) + period := uint64(100 * time.Millisecond / time.Microsecond) quota := uint64(config.NanoCPUs) * period / 1e9 cpu.Period = &period cpu.Quota = "a diff --git a/components/engine/integration-cli/docker_cli_run_unix_test.go b/components/engine/integration-cli/docker_cli_run_unix_test.go index 49544f4225..4c2f829e3c 100644 --- a/components/engine/integration-cli/docker_cli_run_unix_test.go +++ b/components/engine/integration-cli/docker_cli_run_unix_test.go @@ -1577,7 +1577,7 @@ func (s *DockerSuite) TestRunWithNanoCPUs(c *check.C) { file1 := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us" file2 := "/sys/fs/cgroup/cpu/cpu.cfs_period_us" out, _ := dockerCmd(c, "run", "--cpus", "0.5", "--name", "test", "busybox", "sh", "-c", fmt.Sprintf("cat %s && cat %s", file1, file2)) - c.Assert(strings.TrimSpace(out), checker.Equals, "500000\n1000000") + c.Assert(strings.TrimSpace(out), checker.Equals, "50000\n100000") out = inspectField(c, "test", "HostConfig.NanoCpus") c.Assert(out, checker.Equals, "5e+08", check.Commentf("setting the Nano CPUs failed"))