Windows: [TP4] Add CPU Weight

Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
John Howard 2015-09-22 16:05:00 -07:00 committed by John Howard
parent 9dc0973655
commit a5879bb83b
4 changed files with 17 additions and 3 deletions

View File

@ -72,8 +72,10 @@ func populateCommand(c *Container, env []string) error {
// TODO Windows. This can probably be factored out.
pid.HostPid = c.hostConfig.PidMode.IsHost()
// TODO Windows. Resource controls to be implemented later.
resources := &execdriver.Resources{}
// TODO Windows. More resource controls to be implemented later.
resources := &execdriver.Resources{
CPUShares: c.hostConfig.CPUShares,
}
// TODO Windows. Further refactoring required (privileged/user)
processConfig := execdriver.ProcessConfig{

View File

@ -5,6 +5,7 @@ import (
"os"
"syscall"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/daemon/graphdriver"
// register the windows graph driver
_ "github.com/docker/docker/daemon/graphdriver/windows"
@ -16,6 +17,8 @@ import (
const (
defaultVirtualSwitch = "Virtual Switch"
platformSupported = true
windowsMinCPUShares = 1
windowsMaxCPUShares = 9
)
func parseSecurityOpt(container *Container, config *runconfig.HostConfig) error {
@ -33,6 +36,13 @@ func checkKernel() error {
// adaptContainerSettings is called during container creation to modify any
// settings necessary in the HostConfig structure.
func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig, adjustCPUShares bool) {
if hostConfig.CPUShares < 0 {
logrus.Warnf("Changing requested CPUShares of %d to minimum allowed of %d", hostConfig.CPUShares, windowsMinCPUShares)
hostConfig.CPUShares = windowsMinCPUShares
} else if hostConfig.CPUShares > windowsMaxCPUShares {
logrus.Warnf("Changing requested CPUShares of %d to maximum allowed of %d", hostConfig.CPUShares, windowsMaxCPUShares)
hostConfig.CPUShares = windowsMaxCPUShares
}
}
// verifyPlatformContainerSettings performs platform-specific validation of the

View File

@ -186,7 +186,7 @@ type ProcessConfig struct {
ConsoleSize [2]int `json:"-"` // h,w of initial console size
}
// Command wrapps an os/exec.Cmd to add more metadata
// Command wraps an os/exec.Cmd to add more metadata
//
// TODO Windows: Factor out unused fields such as LxcConfig, AppArmorProfile,
// and CgroupParent.

View File

@ -69,6 +69,7 @@ type containerInit struct {
IgnoreFlushesDuringBoot bool // Optimisation hint for container startup in Windows
LayerFolderPath string // Where the layer folders are located
Layers []layer // List of storage layers
ProcessorWeight int64 // CPU Shares 1..9 on Windows; or 0 is platform default.
}
// defaultOwner is a tag passed to HCS to allow it to differentiate between
@ -98,6 +99,7 @@ func (d *Driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, hooks execd
VolumePath: c.Rootfs,
IgnoreFlushesDuringBoot: c.FirstStart,
LayerFolderPath: c.LayerFolder,
ProcessorWeight: c.Resources.CPUShares,
}
for i := 0; i < len(c.LayerPaths); i++ {