Use CpuMaximum instead of CpuPercent for more precision
Signed-off-by: Darren Stahl <darst@microsoft.com>
This commit is contained in:
parent
b90f294c1c
commit
425973cbb8
2 changed files with 12 additions and 9 deletions
|
@ -120,7 +120,7 @@ func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) {
|
|||
|
||||
// In s.Windows.Resources
|
||||
cpuShares := uint16(c.HostConfig.CPUShares)
|
||||
cpuPercent := uint8(c.HostConfig.CPUPercent)
|
||||
cpuMaximum := uint16(c.HostConfig.CPUPercent) * 100
|
||||
cpuCount := uint64(c.HostConfig.CPUCount)
|
||||
if c.HostConfig.NanoCPUs > 0 {
|
||||
if isHyperV {
|
||||
|
@ -128,21 +128,24 @@ func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) {
|
|||
leftoverNanoCPUs := c.HostConfig.NanoCPUs % 1e9
|
||||
if leftoverNanoCPUs != 0 {
|
||||
cpuCount++
|
||||
cpuPercent = uint8(c.HostConfig.NanoCPUs * 100 / int64(cpuCount) / 1e9)
|
||||
cpuMaximum = uint16(c.HostConfig.NanoCPUs / int64(cpuCount) / (1e9 / 10000))
|
||||
if cpuMaximum < 1 {
|
||||
// The requested NanoCPUs is so small that we rounded to 0, use 1 instead
|
||||
cpuMaximum = 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cpuPercent = uint8(c.HostConfig.NanoCPUs * 100 / int64(sysinfo.NumCPU()) / 1e9)
|
||||
|
||||
if cpuPercent < 1 {
|
||||
cpuMaximum = uint16(c.HostConfig.NanoCPUs / int64(sysinfo.NumCPU()) / (1e9 / 10000))
|
||||
if cpuMaximum < 1 {
|
||||
// The requested NanoCPUs is so small that we rounded to 0, use 1 instead
|
||||
cpuPercent = 1
|
||||
cpuMaximum = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
memoryLimit := uint64(c.HostConfig.Memory)
|
||||
s.Windows.Resources = &specs.WindowsResources{
|
||||
CPU: &specs.WindowsCPUResources{
|
||||
Percent: &cpuPercent,
|
||||
Maximum: &cpuMaximum,
|
||||
Shares: &cpuShares,
|
||||
Count: &cpuCount,
|
||||
},
|
||||
|
|
|
@ -128,8 +128,8 @@ func (clnt *client) Create(containerID string, checkpoint string, checkpointDir
|
|||
if spec.Windows.Resources.CPU.Shares != nil {
|
||||
configuration.ProcessorWeight = uint64(*spec.Windows.Resources.CPU.Shares)
|
||||
}
|
||||
if spec.Windows.Resources.CPU.Percent != nil {
|
||||
configuration.ProcessorMaximum = int64(*spec.Windows.Resources.CPU.Percent) * 100 // ProcessorMaximum is a value between 1 and 10000
|
||||
if spec.Windows.Resources.CPU.Maximum != nil {
|
||||
configuration.ProcessorMaximum = int64(*spec.Windows.Resources.CPU.Maximum)
|
||||
}
|
||||
}
|
||||
if spec.Windows.Resources.Memory != nil {
|
||||
|
|
Loading…
Reference in a new issue