1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

pkg/sysinfo: rm duplicates

The CPU CFS cgroup-aware scheduler is one single kernel feature, not
two, so it does not make sense to have two separate booleans
(CPUCfsQuota and CPUCfsPeriod). Merge these into CPUCfs.

Same for CPU realtime.

For compatibility reasons, /info stays the same for now.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2020-05-22 14:18:06 -07:00
parent 5643da825c
commit afbeaf6f29
7 changed files with 50 additions and 81 deletions

View file

@ -505,8 +505,8 @@ func verifyPlatformContainerResources(resources *containertypes.Resources, sysIn
if resources.NanoCPUs > 0 && resources.CPUQuota > 0 { if resources.NanoCPUs > 0 && resources.CPUQuota > 0 {
return warnings, fmt.Errorf("Conflicting options: Nano CPUs and CPU Quota cannot both be set") return warnings, fmt.Errorf("Conflicting options: Nano CPUs and CPU Quota cannot both be set")
} }
if resources.NanoCPUs > 0 && (!sysInfo.CPUCfsPeriod || !sysInfo.CPUCfsQuota) { if resources.NanoCPUs > 0 && !sysInfo.CPUCfs {
return warnings, fmt.Errorf("NanoCPUs can not be set, as your kernel does not support CPU cfs period/quota or the cgroup is not mounted") return warnings, fmt.Errorf("NanoCPUs can not be set, as your kernel does not support CPU CFS scheduler or the cgroup is not mounted")
} }
// The highest precision we could get on Linux is 0.001, by setting // The highest precision we could get on Linux is 0.001, by setting
// cpu.cfs_period_us=1000ms // cpu.cfs_period_us=1000ms
@ -523,17 +523,14 @@ func verifyPlatformContainerResources(resources *containertypes.Resources, sysIn
warnings = append(warnings, "Your kernel does not support CPU shares or the cgroup is not mounted. Shares discarded.") warnings = append(warnings, "Your kernel does not support CPU shares or the cgroup is not mounted. Shares discarded.")
resources.CPUShares = 0 resources.CPUShares = 0
} }
if resources.CPUPeriod > 0 && !sysInfo.CPUCfsPeriod { if (resources.CPUPeriod != 0 || resources.CPUQuota != 0) && !sysInfo.CPUCfs {
warnings = append(warnings, "Your kernel does not support CPU cfs period or the cgroup is not mounted. Period discarded.") warnings = append(warnings, "Your kernel does not support CPU CFS scheduler. CPU period/quota discarded.")
resources.CPUPeriod = 0 resources.CPUPeriod = 0
resources.CPUQuota = 0
} }
if resources.CPUPeriod != 0 && (resources.CPUPeriod < 1000 || resources.CPUPeriod > 1000000) { if resources.CPUPeriod != 0 && (resources.CPUPeriod < 1000 || resources.CPUPeriod > 1000000) {
return warnings, fmt.Errorf("CPU cfs period can not be less than 1ms (i.e. 1000) or larger than 1s (i.e. 1000000)") return warnings, fmt.Errorf("CPU cfs period can not be less than 1ms (i.e. 1000) or larger than 1s (i.e. 1000000)")
} }
if resources.CPUQuota > 0 && !sysInfo.CPUCfsQuota {
warnings = append(warnings, "Your kernel does not support CPU cfs quota or the cgroup is not mounted. Quota discarded.")
resources.CPUQuota = 0
}
if resources.CPUQuota > 0 && resources.CPUQuota < 1000 { if resources.CPUQuota > 0 && resources.CPUQuota < 1000 {
return warnings, fmt.Errorf("CPU cfs quota can not be less than 1ms (i.e. 1000)") return warnings, fmt.Errorf("CPU cfs quota can not be less than 1ms (i.e. 1000)")
} }
@ -1726,10 +1723,10 @@ func (daemon *Daemon) initCgroupsPath(path string) error {
path = filepath.Join(mnt, root, path) path = filepath.Join(mnt, root, path)
sysInfo := daemon.RawSysInfo(true) sysInfo := daemon.RawSysInfo(true)
if err := maybeCreateCPURealTimeFile(sysInfo.CPURealtimePeriod, daemon.configStore.CPURealtimePeriod, "cpu.rt_period_us", path); err != nil { if err := maybeCreateCPURealTimeFile(sysInfo.CPURealtime, daemon.configStore.CPURealtimePeriod, "cpu.rt_period_us", path); err != nil {
return err return err
} }
return maybeCreateCPURealTimeFile(sysInfo.CPURealtimeRuntime, daemon.configStore.CPURealtimeRuntime, "cpu.rt_runtime_us", path) return maybeCreateCPURealTimeFile(sysInfo.CPURealtime, daemon.configStore.CPURealtimeRuntime, "cpu.rt_runtime_us", path)
} }
func maybeCreateCPURealTimeFile(sysinfoPresent bool, configValue int64, file string, path string) error { func maybeCreateCPURealTimeFile(sysinfoPresent bool, configValue int64, file string, path string) error {

View file

@ -30,8 +30,8 @@ func (daemon *Daemon) fillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo)
v.KernelMemory = sysInfo.KernelMemory v.KernelMemory = sysInfo.KernelMemory
v.KernelMemoryTCP = sysInfo.KernelMemoryTCP v.KernelMemoryTCP = sysInfo.KernelMemoryTCP
v.OomKillDisable = sysInfo.OomKillDisable v.OomKillDisable = sysInfo.OomKillDisable
v.CPUCfsPeriod = sysInfo.CPUCfsPeriod v.CPUCfsPeriod = sysInfo.CPUCfs
v.CPUCfsQuota = sysInfo.CPUCfsQuota v.CPUCfsQuota = sysInfo.CPUCfs
v.CPUShares = sysInfo.CPUShares v.CPUShares = sysInfo.CPUShares
v.CPUSet = sysInfo.Cpuset v.CPUSet = sysInfo.Cpuset
v.PidsLimit = sysInfo.PidsLimit v.PidsLimit = sysInfo.PidsLimit

View file

@ -90,10 +90,8 @@ func applyCPUCgroupInfoV2(info *SysInfo, controllers map[string]struct{}, _ stri
return warnings return warnings
} }
info.CPUShares = true info.CPUShares = true
info.CPUCfsPeriod = true info.CPUCfs = true
info.CPUCfsQuota = true info.CPURealtime = false
info.CPURealtimePeriod = false
info.CPURealtimeRuntime = false
return warnings return warnings
} }

View file

@ -62,17 +62,11 @@ type cgroupCPUInfo struct {
// Whether CPU shares is supported or not // Whether CPU shares is supported or not
CPUShares bool CPUShares bool
// Whether CPU CFS(Completely Fair Scheduler) period is supported or not // Whether CPU CFS (Completely Fair Scheduler) is supported
CPUCfsPeriod bool CPUCfs bool
// Whether CPU CFS(Completely Fair Scheduler) quota is supported or not // Whether CPU real-time scheduler is supported
CPUCfsQuota bool CPURealtime bool
// Whether CPU real-time period is supported or not
CPURealtimePeriod bool
// Whether CPU real-time runtime is supported or not
CPURealtimeRuntime bool
} }
type cgroupBlkioInfo struct { type cgroupBlkioInfo struct {

View file

@ -144,27 +144,17 @@ func applyCPUCgroupInfo(info *SysInfo, cgMounts map[string]string) []string {
info.CPUShares = cgroupEnabled(mountPoint, "cpu.shares") info.CPUShares = cgroupEnabled(mountPoint, "cpu.shares")
if !info.CPUShares { if !info.CPUShares {
warnings = append(warnings, "Your kernel does not support cgroup cpu shares") warnings = append(warnings, "Your kernel does not support CPU shares")
} }
info.CPUCfsPeriod = cgroupEnabled(mountPoint, "cpu.cfs_period_us") info.CPUCfs = cgroupEnabled(mountPoint, "cpu.cfs_quota_us")
if !info.CPUCfsPeriod { if !info.CPUCfs {
warnings = append(warnings, "Your kernel does not support cgroup cfs period") warnings = append(warnings, "Your kernel does not support CPU CFS scheduler")
} }
info.CPUCfsQuota = cgroupEnabled(mountPoint, "cpu.cfs_quota_us") info.CPURealtime = cgroupEnabled(mountPoint, "cpu.rt_period_us")
if !info.CPUCfsQuota { if !info.CPURealtime {
warnings = append(warnings, "Your kernel does not support cgroup cfs quotas") warnings = append(warnings, "Your kernel does not support CPU realtime scheduler")
}
info.CPURealtimePeriod = cgroupEnabled(mountPoint, "cpu.rt_period_us")
if !info.CPURealtimePeriod {
warnings = append(warnings, "Your kernel does not support cgroup rt period")
}
info.CPURealtimeRuntime = cgroupEnabled(mountPoint, "cpu.rt_runtime_us")
if !info.CPURealtimeRuntime {
warnings = append(warnings, "Your kernel does not support cgroup rt runtime")
} }
return warnings return warnings

View file

@ -242,8 +242,7 @@ func TestValidateResources(t *testing.T) {
type resourceTest struct { type resourceTest struct {
ConfigCPURealtimePeriod int64 ConfigCPURealtimePeriod int64
ConfigCPURealtimeRuntime int64 ConfigCPURealtimeRuntime int64
SysInfoCPURealtimePeriod bool SysInfoCPURealtime bool
SysInfoCPURealtimeRuntime bool
ErrorExpected bool ErrorExpected bool
FailureMsg string FailureMsg string
} }
@ -252,32 +251,28 @@ func TestValidateResources(t *testing.T) {
{ {
ConfigCPURealtimePeriod: 1000, ConfigCPURealtimePeriod: 1000,
ConfigCPURealtimeRuntime: 1000, ConfigCPURealtimeRuntime: 1000,
SysInfoCPURealtimePeriod: true, SysInfoCPURealtime: true,
SysInfoCPURealtimeRuntime: true,
ErrorExpected: false, ErrorExpected: false,
FailureMsg: "Expected valid configuration", FailureMsg: "Expected valid configuration",
}, },
{ {
ConfigCPURealtimePeriod: 5000, ConfigCPURealtimePeriod: 5000,
ConfigCPURealtimeRuntime: 5000, ConfigCPURealtimeRuntime: 5000,
SysInfoCPURealtimePeriod: false, SysInfoCPURealtime: false,
SysInfoCPURealtimeRuntime: true,
ErrorExpected: true, ErrorExpected: true,
FailureMsg: "Expected failure when cpu-rt-period is set but kernel doesn't support it", FailureMsg: "Expected failure when cpu-rt-period is set but kernel doesn't support it",
}, },
{ {
ConfigCPURealtimePeriod: 5000, ConfigCPURealtimePeriod: 5000,
ConfigCPURealtimeRuntime: 5000, ConfigCPURealtimeRuntime: 5000,
SysInfoCPURealtimePeriod: true, SysInfoCPURealtime: false,
SysInfoCPURealtimeRuntime: false,
ErrorExpected: true, ErrorExpected: true,
FailureMsg: "Expected failure when cpu-rt-runtime is set but kernel doesn't support it", FailureMsg: "Expected failure when cpu-rt-runtime is set but kernel doesn't support it",
}, },
{ {
ConfigCPURealtimePeriod: 5000, ConfigCPURealtimePeriod: 5000,
ConfigCPURealtimeRuntime: 10000, ConfigCPURealtimeRuntime: 10000,
SysInfoCPURealtimePeriod: true, SysInfoCPURealtime: true,
SysInfoCPURealtimeRuntime: false,
ErrorExpected: true, ErrorExpected: true,
FailureMsg: "Expected failure when cpu-rt-runtime is greater than cpu-rt-period", FailureMsg: "Expected failure when cpu-rt-runtime is greater than cpu-rt-period",
}, },
@ -289,8 +284,7 @@ func TestValidateResources(t *testing.T) {
hc.Resources.CPURealtimeRuntime = rt.ConfigCPURealtimeRuntime hc.Resources.CPURealtimeRuntime = rt.ConfigCPURealtimeRuntime
var si sysinfo.SysInfo var si sysinfo.SysInfo
si.CPURealtimePeriod = rt.SysInfoCPURealtimePeriod si.CPURealtime = rt.SysInfoCPURealtime
si.CPURealtimeRuntime = rt.SysInfoCPURealtimeRuntime
if err := validateResources(&hc, &si); (err != nil) != rt.ErrorExpected { if err := validateResources(&hc, &si); (err != nil) != rt.ErrorExpected {
t.Fatal(rt.FailureMsg, err) t.Fatal(rt.FailureMsg, err)

View file

@ -85,12 +85,8 @@ func validateResources(hc *container.HostConfig, si *sysinfo.SysInfo) error {
return nil return nil
} }
if hc.Resources.CPURealtimePeriod > 0 && !si.CPURealtimePeriod { if (hc.Resources.CPURealtimePeriod != 0 || hc.Resources.CPURealtimeRuntime != 0) && !si.CPURealtime {
return fmt.Errorf("Your kernel does not support cgroup cpu real-time period") return fmt.Errorf("Your kernel does not support CPU real-time scheduler")
}
if hc.Resources.CPURealtimeRuntime > 0 && !si.CPURealtimeRuntime {
return fmt.Errorf("Your kernel does not support cgroup cpu real-time runtime")
} }
if hc.Resources.CPURealtimePeriod != 0 && hc.Resources.CPURealtimeRuntime != 0 && hc.Resources.CPURealtimeRuntime > hc.Resources.CPURealtimePeriod { if hc.Resources.CPURealtimePeriod != 0 && hc.Resources.CPURealtimeRuntime != 0 && hc.Resources.CPURealtimeRuntime > hc.Resources.CPURealtimePeriod {