Browse code

Fix cfs period calculation

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>

Michael Crosby authored on 2016/11/18 09:39:47
Showing 2 changed files
... ...
@@ -112,11 +112,8 @@ func getCPUResources(config containertypes.Resources) *specs.CPU {
112 112
 	}
113 113
 
114 114
 	if config.NanoCPUs > 0 {
115
-		// We set the highest value possible (1s), as is specified in:
116 115
 		// https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt
117
-		//    	cpu.cfs_period_us=1s
118
-		// The purpose is to get the highest precision
119
-		period := uint64(1 * time.Second / time.Microsecond)
116
+		period := uint64(100 * time.Millisecond / time.Microsecond)
120 117
 		quota := uint64(config.NanoCPUs) * period / 1e9
121 118
 		cpu.Period = &period
122 119
 		cpu.Quota = &quota
... ...
@@ -1577,7 +1577,7 @@ func (s *DockerSuite) TestRunWithNanoCPUs(c *check.C) {
1577 1577
 	file1 := "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"
1578 1578
 	file2 := "/sys/fs/cgroup/cpu/cpu.cfs_period_us"
1579 1579
 	out, _ := dockerCmd(c, "run", "--cpus", "0.5", "--name", "test", "busybox", "sh", "-c", fmt.Sprintf("cat %s && cat %s", file1, file2))
1580
-	c.Assert(strings.TrimSpace(out), checker.Equals, "500000\n1000000")
1580
+	c.Assert(strings.TrimSpace(out), checker.Equals, "50000\n100000")
1581 1581
 
1582 1582
 	out = inspectField(c, "test", "HostConfig.NanoCpus")
1583 1583
 	c.Assert(out, checker.Equals, "5e+08", check.Commentf("setting the Nano CPUs failed"))