Merge pull request #521 from rjnagal/cpu

Fix cpuset returned in spec on a single core machine.
This commit is contained in:
Victor Marmol 2015-02-19 11:00:52 -08:00
commit d3d4bb8dbc
3 changed files with 32 additions and 10 deletions

View File

@ -227,12 +227,7 @@ func libcontainerConfigToContainerSpec(config *libcontainer.Config, mi *info.Mac
if config.Cgroups.CpuShares != 0 {
spec.Cpu.Limit = uint64(config.Cgroups.CpuShares)
}
if config.Cgroups.CpusetCpus == "" {
// All cores are active.
spec.Cpu.Mask = fmt.Sprintf("0-%d", mi.NumCores-1)
} else {
spec.Cpu.Mask = config.Cgroups.CpusetCpus
}
spec.Cpu.Mask = utils.FixCpuMask(config.Cgroups.CpusetCpus, mi.NumCores)
spec.HasNetwork = true
spec.HasDiskIo = true

View File

@ -217,10 +217,8 @@ func (self *rawContainerHandler) GetSpec() (info.ContainerSpec, error) {
if ok {
if utils.FileExists(cpusetRoot) {
spec.HasCpu = true
spec.Cpu.Mask = readString(cpusetRoot, "cpuset.cpus")
if spec.Cpu.Mask == "" {
spec.Cpu.Mask = fmt.Sprintf("0-%d", mi.NumCores-1)
}
mask := readString(cpusetRoot, "cpuset.cpus")
spec.Cpu.Mask = utils.FixCpuMask(mask, mi.NumCores)
}
}

29
utils/utils.go Normal file
View File

@ -0,0 +1,29 @@
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package utils
import "fmt"
// Returns a mask of all cores on the machine if the passed-in mask is empty.
func FixCpuMask(mask string, cores int) string {
if mask == "" {
if cores > 1 {
mask = fmt.Sprintf("0-%d", cores-1)
} else {
mask = "0"
}
}
return mask
}