Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
kata-runtime: Return correct kata-env on ppc64le
Browse files Browse the repository at this point in the history
The contents of /proc/cpuinfo were
trimmed and hence the "model" field could
not be parsed despite being a field in
/proc/cpuinfo. Fix this issue.

Fixes: #1089

Signed-off-by: Nitesh Konkar niteshkonkar@in.ibm.com
  • Loading branch information
nitkon committed Jan 9, 2019
1 parent 8161b4c commit 11e24aa
Showing 1 changed file with 53 additions and 4 deletions.
57 changes: 53 additions & 4 deletions cli/kata-check_ppc64le.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,61 @@ func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool {
return genericArchKernelParamHandler(onVMM, fields, msg)
}

func getPPC64leCPUInfo(cpuInfoFile string) (string, error) {
text, err := katautils.GetFileContents(cpuInfoFile)
if err != nil {
return "", err
}

if len(strings.TrimSpace(text)) == 0 {
return "", fmt.Errorf("Cannot determine CPU details")
}

return text, nil
}

func getCPUDetails() (vendor, model string, err error) {
vendor, model, err = genericGetCPUDetails()
if err == nil {
model = "POWER8"

if vendor, model, err := genericGetCPUDetails(); err == nil {
return vendor, model, nil
}

cpuinfo, err := getPPC64leCPUInfo(procCPUInfo)
if err != nil {
return "", "", err
}
return vendor, model, err

lines := strings.Split(cpuinfo, "\n")

for _, line := range lines {
if archCPUVendorField != "" {
if strings.HasPrefix(line, archCPUVendorField) {
fields := strings.Split(line, ":")
if len(fields) > 1 {
vendor = strings.TrimSpace(fields[1])
}
}
}

if archCPUModelField != "" {
if strings.HasPrefix(line, archCPUModelField) {
fields := strings.Split(line, ":")
if len(fields) > 1 {
model = strings.TrimSpace(fields[1])
}
}
}
}

if archCPUVendorField != "" && vendor == "" {
return "", "", fmt.Errorf("cannot find vendor field in file %v", procCPUInfo)
}

if archCPUModelField != "" && model == "" {
return "", "", fmt.Errorf("cannot find model field in file %v", procCPUInfo)
}

return vendor, model, nil
}

func isSMTOff() bool {
Expand Down

0 comments on commit 11e24aa

Please # to comment.