Skip to content

Commit 59d8bb5

Browse files
committed
feat: add support to differentiate specific hypervisors on s390x
Signed-off-by: Ching Han Chen <[email protected]>
1 parent 216fca7 commit 59d8bb5

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

source/cpu/cpuid_linux_s390x.go

+39-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ unsigned long gethwcap() {
2525
*/
2626
import "C"
2727

28+
import (
29+
"os"
30+
"strings"
31+
32+
"k8s.io/klog/v2"
33+
)
34+
2835
/*
2936
all special features for s390x should be defined here; canonical list:
3037
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/s390/include/asm/elf.h
@@ -96,4 +103,35 @@ func getCpuidFlags() []string {
96103
return r
97104
}
98105

99-
func getCpuidAttributes() map[string]string { return nil }
106+
func getCpuidAttributes() map[string]string {
107+
ret := make(map[string]string)
108+
109+
hypervisor, err := getHypervisor()
110+
if err != nil {
111+
klog.ErrorS(err, "failed to detect hypervisor")
112+
return ret
113+
}
114+
ret["hypervisor"] = hypervisor
115+
116+
return ret
117+
}
118+
119+
func getHypervisor() (string, error) {
120+
data, err := os.ReadFile("/proc/sysinfo")
121+
if err != nil {
122+
return "", err
123+
}
124+
125+
hypervisor := "PR/SM"
126+
for _, line := range strings.Split(string(data), "\n") {
127+
if strings.Contains(line, "Control Program:") {
128+
parts := strings.SplitN(line, ":", 2)
129+
if len(parts) == 2 {
130+
hypervisor = strings.TrimSpace(parts[1])
131+
}
132+
break
133+
}
134+
}
135+
136+
return hypervisor, nil
137+
}

0 commit comments

Comments
 (0)