@@ -271,67 +271,44 @@ func getCPUModel() map[string]string {
271
271
func discoverTopology () map [string ]string {
272
272
features := make (map [string ]string )
273
273
274
- if ht , err := haveThreadSiblings (); err != nil {
275
- klog .ErrorS (err , "failed to detect hyper-threading" )
276
- } else {
277
- features ["hardware_multithreading" ] = strconv .FormatBool (ht )
278
- }
279
-
280
- if socketCount , err := getCPUSocketCount (); err != nil {
281
- klog .ErrorS (err , "failed to get sockets count" )
282
- } else {
283
- features ["socket_count" ] = strconv .FormatInt (socketCount , 10 )
284
- }
285
-
286
- return features
287
- }
288
-
289
- func getCPUSocketCount () (int64 , error ) {
290
274
files , err := os .ReadDir (hostpath .SysfsDir .Path ("bus/cpu/devices" ))
291
275
if err != nil {
292
- return 0 , err
276
+ klog .ErrorS (err , "failed to read devices folder" )
277
+ return features
293
278
}
294
279
280
+ ht := false
295
281
uniquePhysicalIDs := sets .NewString ()
296
282
297
- for _ , file := range files {
298
- // Try to read physical_package_id from topology
299
- physicalID , err := os .ReadFile (hostpath .SysfsDir .Path ("bus/cpu/devices" , file .Name (), "topology/physical_package_id" ))
300
- if err != nil {
301
- return 0 , err
302
- }
303
- id := strings .TrimSpace (string (physicalID ))
304
- if err != nil {
305
- return 0 , err
306
- }
307
- uniquePhysicalIDs .Insert (id )
308
- }
309
- return int64 (uniquePhysicalIDs .Len ()), nil
310
- }
311
-
312
- // Check if any (online) CPUs have thread siblings
313
- func haveThreadSiblings () (bool , error ) {
314
-
315
- files , err := os .ReadDir (hostpath .SysfsDir .Path ("bus/cpu/devices" ))
316
- if err != nil {
317
- return false , err
318
- }
319
-
320
283
for _ , file := range files {
321
284
// Try to read siblings from topology
322
285
siblings , err := os .ReadFile (hostpath .SysfsDir .Path ("bus/cpu/devices" , file .Name (), "topology/thread_siblings_list" ))
323
286
if err != nil {
324
- return false , err
287
+ klog .ErrorS (err , "error while reading thread_sigblings_list file" )
288
+ return map [string ]string {}
325
289
}
326
290
for _ , char := range siblings {
327
291
// If list separator found, we determine that there are multiple siblings
328
292
if char == ',' || char == '-' {
329
- return true , nil
293
+ ht = true
294
+ break
330
295
}
331
296
}
297
+
298
+ // Try to read physical_package_id from topology
299
+ physicalID , err := os .ReadFile (hostpath .SysfsDir .Path ("bus/cpu/devices" , file .Name (), "topology/physical_package_id" ))
300
+ if err != nil {
301
+ klog .ErrorS (err , "error while reading physical_package_id file" )
302
+ return map [string ]string {}
303
+ }
304
+ id := strings .TrimSpace (string (physicalID ))
305
+ uniquePhysicalIDs .Insert (id )
332
306
}
333
- // No siblings were found
334
- return false , nil
307
+
308
+ features ["hardware_multithreading" ] = strconv .FormatBool (ht )
309
+ features ["socket_count" ] = strconv .FormatInt (int64 (uniquePhysicalIDs .Len ()), 10 )
310
+
311
+ return features
335
312
}
336
313
337
314
func (s * cpuSource ) initCpuidFilter () {
0 commit comments