Merge pull request #1 from linux-on-ibm-z/SystemZ-Changes
System z changes
This commit is contained in:
commit
65019576b3
@ -21,6 +21,10 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
// s390/s390x changes
|
||||||
|
"syscall"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
info "github.com/google/cadvisor/info/v1"
|
info "github.com/google/cadvisor/info/v1"
|
||||||
"github.com/google/cadvisor/utils"
|
"github.com/google/cadvisor/utils"
|
||||||
@ -39,6 +43,11 @@ var swapCapacityRegexp = regexp.MustCompile("SwapTotal: *([0-9]+) kB")
|
|||||||
|
|
||||||
// GetClockSpeed returns the CPU clock speed, given a []byte formatted as the /proc/cpuinfo file.
|
// GetClockSpeed returns the CPU clock speed, given a []byte formatted as the /proc/cpuinfo file.
|
||||||
func GetClockSpeed(procInfo []byte) (uint64, error) {
|
func GetClockSpeed(procInfo []byte) (uint64, error) {
|
||||||
|
// s390/s390x changes
|
||||||
|
if (true == isSystemZ()) {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
// First look through sys to find a max supported cpu frequency.
|
// First look through sys to find a max supported cpu frequency.
|
||||||
const maxFreqFile = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"
|
const maxFreqFile = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"
|
||||||
if utils.FileExists(maxFreqFile) {
|
if utils.FileExists(maxFreqFile) {
|
||||||
@ -119,6 +128,12 @@ func parseCapacity(b []byte, r *regexp.Regexp) (int64, error) {
|
|||||||
|
|
||||||
func GetTopology(sysFs sysfs.SysFs, cpuinfo string) ([]info.Node, int, error) {
|
func GetTopology(sysFs sysfs.SysFs, cpuinfo string) ([]info.Node, int, error) {
|
||||||
nodes := []info.Node{}
|
nodes := []info.Node{}
|
||||||
|
|
||||||
|
// s390/s390x changes
|
||||||
|
if true == isSystemZ() {
|
||||||
|
return nodes, getNumCores(), nil
|
||||||
|
}
|
||||||
|
|
||||||
numCores := 0
|
numCores := 0
|
||||||
lastThread := -1
|
lastThread := -1
|
||||||
lastCore := -1
|
lastCore := -1
|
||||||
@ -241,3 +256,42 @@ func addNode(nodes *[]info.Node, id int) (int, error) {
|
|||||||
}
|
}
|
||||||
return idx, nil
|
return idx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// s390/s390x changes
|
||||||
|
func getMachineArch() (string, error) {
|
||||||
|
uname := syscall.Utsname{}
|
||||||
|
err := syscall.Uname(&uname)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var arch string
|
||||||
|
for _, val := range uname.Machine {
|
||||||
|
arch += string(int(val))
|
||||||
|
}
|
||||||
|
|
||||||
|
return arch, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// s390/s390x changes
|
||||||
|
func isSystemZ() bool {
|
||||||
|
arch, err := getMachineArch()
|
||||||
|
if err == nil {
|
||||||
|
if (true == strings.Contains(arch, "390")) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// s390/s390x changes
|
||||||
|
func getNumCores() int {
|
||||||
|
maxProcs := runtime.GOMAXPROCS(0)
|
||||||
|
numCPU := runtime.NumCPU()
|
||||||
|
|
||||||
|
if maxProcs < numCPU {
|
||||||
|
return maxProcs
|
||||||
|
}
|
||||||
|
|
||||||
|
return numCPU
|
||||||
|
}
|
||||||
|
@ -29,6 +29,7 @@ const (
|
|||||||
netDir = "/sys/class/net"
|
netDir = "/sys/class/net"
|
||||||
dmiDir = "/sys/class/dmi"
|
dmiDir = "/sys/class/dmi"
|
||||||
ppcDevTree = "/proc/device-tree"
|
ppcDevTree = "/proc/device-tree"
|
||||||
|
s390xDevTree = "/etc" // s390/s390x changes
|
||||||
)
|
)
|
||||||
|
|
||||||
type CacheInfo struct {
|
type CacheInfo struct {
|
||||||
@ -241,10 +242,14 @@ func (self *realSysFs) GetSystemUUID() (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
//If running on a KVM guest on Power then UUID is /proc/device-tree/vm,uuid
|
//If running on a KVM guest on Power then UUID is /proc/device-tree/vm,uuid
|
||||||
id, err = ioutil.ReadFile(path.Join(ppcDevTree, "vm,uuid"))
|
id, err = ioutil.ReadFile(path.Join(ppcDevTree, "vm,uuid"))
|
||||||
|
if err != nil {
|
||||||
|
// s390/s390x changes
|
||||||
|
id, err = ioutil.ReadFile(path.Join(s390xDevTree, "machine-id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return strings.TrimSpace(string(id)), nil
|
return strings.TrimSpace(string(id)), nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user