From a5879bb83b8e2855e23b5a1e282940362fc35dba Mon Sep 17 00:00:00 2001 From: John Howard Date: Tue, 22 Sep 2015 16:05:00 -0700 Subject: [PATCH] Windows: [TP4] Add CPU Weight Signed-off-by: John Howard --- daemon/container_windows.go | 6 ++++-- daemon/daemon_windows.go | 10 ++++++++++ daemon/execdriver/driver.go | 2 +- daemon/execdriver/windows/run.go | 2 ++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/daemon/container_windows.go b/daemon/container_windows.go index 2fa1297fb6..5700d80882 100644 --- a/daemon/container_windows.go +++ b/daemon/container_windows.go @@ -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{ diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go index 399df9b1a9..33d5049710 100644 --- a/daemon/daemon_windows.go +++ b/daemon/daemon_windows.go @@ -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 diff --git a/daemon/execdriver/driver.go b/daemon/execdriver/driver.go index 7e8998d272..9977711188 100644 --- a/daemon/execdriver/driver.go +++ b/daemon/execdriver/driver.go @@ -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. diff --git a/daemon/execdriver/windows/run.go b/daemon/execdriver/windows/run.go index 09d31aa29e..4093a8bf27 100644 --- a/daemon/execdriver/windows/run.go +++ b/daemon/execdriver/windows/run.go @@ -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++ {