mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-04-23 20:57:10 +00:00
Merge pull request #2055 from routerhan/feat-add-hypervisor
feat: add support to differentiate specific hypervisors on s390x
This commit is contained in:
commit
c6c517ed8a
2 changed files with 38 additions and 0 deletions
|
@ -928,6 +928,7 @@ The following features are available for matching:
|
|||
| | | **`family`** | int | CPU family |
|
||||
| | | **`vendor_id`** | string | CPU vendor ID |
|
||||
| | | **`id`** | int | CPU model ID |
|
||||
| | | **`hypervisor`** | string | Hypervisor type information from `/proc/sysinfo` (s390x-only feature) |
|
||||
| **`cpu.pstate`** | attribute | | | State of the Intel pstate driver. Does not exist if the driver is not enabled. |
|
||||
| | | **`status`** | string | Status of the driver, possible values are 'active' and 'passive' |
|
||||
| | | **`turbo`** | bool | 'true' if turbo frequencies are enabled, otherwise 'false' |
|
||||
|
|
|
@ -19,6 +19,7 @@ package cpu
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -263,9 +264,45 @@ 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
|
||||
}
|
||||
}
|
||||
// Replace forbidden symbols
|
||||
fullRegex := regexp.MustCompile("[^-A-Za-z0-9_.]+")
|
||||
hypervisor = fullRegex.ReplaceAllString(hypervisor, "_")
|
||||
|
||||
return hypervisor, nil
|
||||
}
|
||||
|
||||
func discoverTopology() map[string]string {
|
||||
features := make(map[string]string)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue