Skip to content

Commit

Permalink
Fix cpuset returned in spec on a single core machine.
Browse files Browse the repository at this point in the history
Switch from "0-0" to "0".
  • Loading branch information
rjnagal committed Feb 19, 2015
1 parent fa3ca8e commit e09f968
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
7 changes: 1 addition & 6 deletions container/docker/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions container/raw/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
29 changes: 29 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit e09f968

Please sign in to comment.