File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -263,9 +263,42 @@ func getCPUModel() map[string]string {
263
263
cpuModelInfo ["family" ] = strconv .Itoa (cpuid .CPU .Family )
264
264
cpuModelInfo ["id" ] = strconv .Itoa (cpuid .CPU .Model )
265
265
266
+ hypervisor , err := getHypervisor ()
267
+ if err != nil {
268
+ klog .ErrorS (err , "failed to detect hypervisor" )
269
+ } else if hypervisor != "" {
270
+ cpuModelInfo ["hypervisor" ] = hypervisor
271
+ }
272
+
266
273
return cpuModelInfo
267
274
}
268
275
276
+ // getHypervisor detects the hypervisor on s390x by reading /proc/sysinfo.
277
+ // If the file does not exist, it returns an empty string with no error.
278
+ func getHypervisor () (string , error ) {
279
+ if _ , err := os .Stat ("/proc/sysinfo" ); os .IsNotExist (err ) {
280
+ return "" , nil
281
+ }
282
+
283
+ data , err := os .ReadFile ("/proc/sysinfo" )
284
+ if err != nil {
285
+ return "" , err
286
+ }
287
+
288
+ hypervisor := "PR/SM"
289
+ for _ , line := range strings .Split (string (data ), "\n " ) {
290
+ if strings .Contains (line , "Control Program:" ) {
291
+ parts := strings .SplitN (line , ":" , 2 )
292
+ if len (parts ) == 2 {
293
+ hypervisor = strings .TrimSpace (parts [1 ])
294
+ }
295
+ break
296
+ }
297
+ }
298
+
299
+ return hypervisor , nil
300
+ }
301
+
269
302
func discoverTopology () map [string ]string {
270
303
features := make (map [string ]string )
271
304
Original file line number Diff line number Diff line change @@ -96,4 +96,4 @@ func getCpuidFlags() []string {
96
96
return r
97
97
}
98
98
99
- func getCpuidAttributes () map [string ]string { return nil }
99
+ func getCpuidAttributes () map [string ]string { return nil }
You can’t perform that action at this time.
0 commit comments