@@ -18,8 +18,6 @@ package topology
18
18
19
19
import (
20
20
"fmt"
21
- "io/ioutil"
22
- "strings"
23
21
24
22
cadvisorapi "github.com/google/cadvisor/info/v1"
25
23
"k8s.io/klog/v2"
@@ -218,34 +216,28 @@ func (d CPUDetails) CPUsInCores(ids ...int) cpuset.CPUSet {
218
216
}
219
217
220
218
// Discover returns CPUTopology based on cadvisor node info
221
- func Discover (machineInfo * cadvisorapi.MachineInfo , numaNodeInfo NUMANodeInfo ) (* CPUTopology , error ) {
219
+ func Discover (machineInfo * cadvisorapi.MachineInfo ) (* CPUTopology , error ) {
222
220
if machineInfo .NumCores == 0 {
223
221
return nil , fmt .Errorf ("could not detect number of cpus" )
224
222
}
225
223
226
224
CPUDetails := CPUDetails {}
227
225
numPhysicalCores := 0
228
226
229
- for _ , socket := range machineInfo .Topology {
230
- numPhysicalCores += len (socket .Cores )
231
- for _ , core := range socket .Cores {
227
+ for _ , node := range machineInfo .Topology {
228
+ numPhysicalCores += len (node .Cores )
229
+ for _ , core := range node .Cores {
232
230
if coreID , err := getUniqueCoreID (core .Threads ); err == nil {
233
231
for _ , cpu := range core .Threads {
234
- numaNodeID := 0
235
- for id , cset := range numaNodeInfo {
236
- if cset .Contains (cpu ) {
237
- numaNodeID = id
238
- }
239
- }
240
232
CPUDetails [cpu ] = CPUInfo {
241
233
CoreID : coreID ,
242
- SocketID : socket . Id ,
243
- NUMANodeID : numaNodeID ,
234
+ SocketID : core . SocketID ,
235
+ NUMANodeID : node . Id ,
244
236
}
245
237
}
246
238
} else {
247
239
klog .Errorf ("could not get unique coreID for socket: %d core %d threads: %v" ,
248
- socket . Id , core .Id , core .Threads )
240
+ core . SocketID , core .Id , core .Threads )
249
241
return nil , err
250
242
}
251
243
}
@@ -280,49 +272,3 @@ func getUniqueCoreID(threads []int) (coreID int, err error) {
280
272
281
273
return min , nil
282
274
}
283
-
284
- // GetNUMANodeInfo uses sysfs to return a map of NUMANode id to the list of
285
- // CPUs associated with that NUMANode.
286
- //
287
- // TODO: This is a temporary workaround until cadvisor provides this
288
- // information directly in machineInfo. We should remove this once this
289
- // information is available from cadvisor.
290
- func GetNUMANodeInfo () (NUMANodeInfo , error ) {
291
- // Get the possible NUMA nodes on this machine. If reading this file
292
- // is not possible, this is not an error. Instead, we just return a
293
- // nil NUMANodeInfo, indicating that no NUMA information is available
294
- // on this machine. This should implicitly be interpreted as having a
295
- // single NUMA node with id 0 for all CPUs.
296
- nodelist , err := ioutil .ReadFile ("/sys/devices/system/node/online" )
297
- if err != nil {
298
- return nil , nil
299
- }
300
-
301
- // Parse the nodelist into a set of Node IDs
302
- nodes , err := cpuset .Parse (strings .TrimSpace (string (nodelist )))
303
- if err != nil {
304
- return nil , err
305
- }
306
-
307
- info := make (NUMANodeInfo )
308
-
309
- // For each node...
310
- for _ , node := range nodes .ToSlice () {
311
- // Read the 'cpulist' of the NUMA node from sysfs.
312
- path := fmt .Sprintf ("/sys/devices/system/node/node%d/cpulist" , node )
313
- cpulist , err := ioutil .ReadFile (path )
314
- if err != nil {
315
- return nil , err
316
- }
317
-
318
- // Convert the 'cpulist' into a set of CPUs.
319
- cpus , err := cpuset .Parse (strings .TrimSpace (string (cpulist )))
320
- if err != nil {
321
- return nil , err
322
- }
323
-
324
- info [node ] = cpus
325
- }
326
-
327
- return info , nil
328
- }
0 commit comments