1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-31 04:04:51 +00:00
This commit is contained in:
ChingHan Chen 2025-03-28 05:12:05 -07:00 committed by GitHub
commit 7d31bbd0b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -263,9 +263,42 @@ func getCPUModel() map[string]string {
cpuModelInfo["family"] = strconv.Itoa(cpuid.CPU.Family)
cpuModelInfo["id"] = strconv.Itoa(cpuid.CPU.Model)
hypervisor, err := getHypervisor()
if err != nil {
klog.ErrorS(err, "failed to detect hypervisor")
} else if hypervisor != "" {
cpuModelInfo["hypervisor"] = hypervisor
}
return cpuModelInfo
}
// getHypervisor detects the hypervisor on s390x by reading /proc/sysinfo.
// If the file does not exist, it returns an empty string with no error.
func getHypervisor() (string, error) {
if _, err := os.Stat("/proc/sysinfo"); os.IsNotExist(err) {
return "", nil
}
data, err := os.ReadFile("/proc/sysinfo")
if err != nil {
return "", err
}
hypervisor := "PR/SM"
for _, line := range strings.Split(string(data), "\n") {
if strings.Contains(line, "Control Program:") {
parts := strings.SplitN(line, ":", 2)
if len(parts) == 2 {
hypervisor = strings.TrimSpace(parts[1])
}
break
}
}
return hypervisor, nil
}
func discoverTopology() map[string]string {
features := make(map[string]string)