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

Commit

Permalink
cpuinfo/arm64: Refine CPUInfo in Arm64
Browse files Browse the repository at this point in the history
The CPUinfo need to be refined in Arm architecture, because the
vendor and model of CPU may refer to different meaning in Arm architecture.
Besides, relevant contents extracted from /proc/cpuinfo may need to be
normalized for human-readability.

Fixes: #368

Signed-off-by: Penny Zheng <[email protected]>
Signed-off-by: Wei Chen <[email protected]>
  • Loading branch information
Pennyzct committed Jun 4, 2018
1 parent fdb6d95 commit 7757dce
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cli/kata-check_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ func hostIsVMContainerCapable(details vmContainerCapableDetails) error {
func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool {
return genericArchKernelParamHandler(onVMM, fields, msg)
}

func getCPUDetails() (vendor, model string, err error) {
return genericGetCPUDetails()
}
71 changes: 68 additions & 3 deletions cli/kata-check_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@

package main

import "github.com/sirupsen/logrus"
import (
"fmt"

"github.com/sirupsen/logrus"
)

const (
cpuFlagsTag = "Features"
archCPUVendorField = "CPU implementer"
archCPUModelField = "CPU variant"
archCPUModelField = "CPU architecture"
)

// archRequiredCPUFlags maps a CPU flag value to search for and a
Expand Down Expand Up @@ -49,9 +53,70 @@ func archHostCanCreateVMContainer() error {
// hostIsVMContainerCapable checks to see if the host is theoretically capable
// of creating a VM container.
func hostIsVMContainerCapable(details vmContainerCapableDetails) error {
return genericHostIsVMContainerCapable(details)
count, err := checkKernelModules(details.requiredKernelModules, archKernelParamHandler)
if err != nil {
return err
}

if count == 0 {
return nil
}

return fmt.Errorf("ERROR: %s", failMessage)

}

func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool {
return genericArchKernelParamHandler(onVMM, fields, msg)
}

// The CPU Vendor here for Arm means the CPU core
// IP Implementer.
// normalizeArmVendor maps 'CPU implementer' in /proc/cpuinfo
// to human-readable description of that value.
func normalizeArmVendor(vendor string) string {

switch vendor {
case "0x41":
vendor = "ARM Limited"
default:
vendor = "3rd Party Limited"
}

return vendor
}

// The CPU Model here for Arm means the Instruction set, that is
// the variant number of Arm processor.
// normalizeArmModel maps 'CPU architecture' in /proc/cpuinfo
// to human-readable description of that value.
func normalizeArmModel(model string) string {
switch model {
case "8":
model = "v8"
case "7", "7M", "?(12)", "?(13)", "?(14)", "?(15)", "?(16)", "?(17)":
model = "v7"
case "6", "6TEJ":
model = "v6"
case "5", "5T", "5TE", "5TEJ":
model = "v5"
case "4", "4T":
model = "v4"
case "3":
model = "v3"
default:
model = "unknown"
}

return model
}

func getCPUDetails() (vendor, model string, err error) {
if vendor, model, err := genericGetCPUDetails(); err == nil {
vendor = normalizeArmVendor(vendor)
model = normalizeArmModel(model)
return vendor, model, err
} else {
return vendor, model, err
}
}
4 changes: 4 additions & 0 deletions cli/kata-check_ppc64le.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ func kvmIsUsable() error {
func archKernelParamHandler(onVMM bool, fields logrus.Fields, msg string) bool {
return genericArchKernelParamHandler(onVMM, fields, msg)
}

func getCPUDetails() (vendor, model string, err error) {
return genericGetCPUDetails()
}
4 changes: 2 additions & 2 deletions cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ func getDistroDetails() (name, version string, err error) {
return "", "", fmt.Errorf("failed to find expected fields in one of %v", files)
}

// getCPUDetails returns the vendor and model of the CPU.
// genericGetCPUDetails returns the vendor and model of the CPU.
// If it is not possible to determine both values an error is
// returned.
func getCPUDetails() (vendor, model string, err error) {
func genericGetCPUDetails() (vendor, model string, err error) {
cpuinfo, err := getCPUInfo(procCPUInfo)
if err != nil {
return "", "", err
Expand Down

0 comments on commit 7757dce

Please sign in to comment.