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

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. // TODO Windows. This can probably be factored out.
pid.HostPid = c.hostConfig.PidMode.IsHost() pid.HostPid = c.hostConfig.PidMode.IsHost()
// TODO Windows. Resource controls to be implemented later. // TODO Windows. More resource controls to be implemented later.
resources := &execdriver.Resources{} resources := &execdriver.Resources{
CPUShares: c.hostConfig.CPUShares,
}
// TODO Windows. Further refactoring required (privileged/user) // TODO Windows. Further refactoring required (privileged/user)
processConfig := execdriver.ProcessConfig{ processConfig := execdriver.ProcessConfig{

View file

@ -5,6 +5,7 @@ import (
"os" "os"
"syscall" "syscall"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/daemon/graphdriver" "github.com/docker/docker/daemon/graphdriver"
// register the windows graph driver // register the windows graph driver
_ "github.com/docker/docker/daemon/graphdriver/windows" _ "github.com/docker/docker/daemon/graphdriver/windows"
@ -16,6 +17,8 @@ import (
const ( const (
defaultVirtualSwitch = "Virtual Switch" defaultVirtualSwitch = "Virtual Switch"
platformSupported = true platformSupported = true
windowsMinCPUShares = 1
windowsMaxCPUShares = 9
) )
func parseSecurityOpt(container *Container, config *runconfig.HostConfig) error { func parseSecurityOpt(container *Container, config *runconfig.HostConfig) error {
@ -33,6 +36,13 @@ func checkKernel() error {
// adaptContainerSettings is called during container creation to modify any // adaptContainerSettings is called during container creation to modify any
// settings necessary in the HostConfig structure. // settings necessary in the HostConfig structure.
func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig, adjustCPUShares bool) { 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 // 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 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, // TODO Windows: Factor out unused fields such as LxcConfig, AppArmorProfile,
// and CgroupParent. // and CgroupParent.

View file

@ -69,6 +69,7 @@ type containerInit struct {
IgnoreFlushesDuringBoot bool // Optimisation hint for container startup in Windows IgnoreFlushesDuringBoot bool // Optimisation hint for container startup in Windows
LayerFolderPath string // Where the layer folders are located LayerFolderPath string // Where the layer folders are located
Layers []layer // List of storage layers 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 // 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, VolumePath: c.Rootfs,
IgnoreFlushesDuringBoot: c.FirstStart, IgnoreFlushesDuringBoot: c.FirstStart,
LayerFolderPath: c.LayerFolder, LayerFolderPath: c.LayerFolder,
ProcessorWeight: c.Resources.CPUShares,
} }
for i := 0; i < len(c.LayerPaths); i++ { for i := 0; i < len(c.LayerPaths); i++ {