فهرست منبع

Windows: [TP4] Add CPU Weight

Signed-off-by: John Howard <jhoward@microsoft.com>
John Howard 9 سال پیش
والد
کامیت
a5879bb83b
4فایلهای تغییر یافته به همراه17 افزوده شده و 3 حذف شده
  1. 4 2
      daemon/container_windows.go
  2. 10 0
      daemon/daemon_windows.go
  3. 1 1
      daemon/execdriver/driver.go
  4. 2 0
      daemon/execdriver/windows/run.go

+ 4 - 2
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{

+ 10 - 0
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

+ 1 - 1
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.

+ 2 - 0
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++ {