From 1f5856c6710f8cf4a944b9f1215b36fe294cf681 Mon Sep 17 00:00:00 2001 From: Holger Obermaier <40787752+ho-ob@users.noreply.github.com> Date: Thu, 7 Sep 2023 10:24:43 +0200 Subject: [PATCH] Reuse information from /proc/cpuinfo --- pkg/ccTopology/ccTopology.go | 38 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/pkg/ccTopology/ccTopology.go b/pkg/ccTopology/ccTopology.go index b2a6929..4cc09c3 100644 --- a/pkg/ccTopology/ccTopology.go +++ b/pkg/ccTopology/ccTopology.go @@ -92,16 +92,6 @@ func init() { slices.Sort(cache.uniqSocketList) cache.uniqSocketList = slices.Compact(cache.uniqSocketList) - getCore := - func(basePath string) int { - return fileToInt(filepath.Join(basePath, "core_id")) - } - - getSocket := - func(basePath string) int { - return fileToInt(filepath.Join(basePath, "physical_package_id")) - } - getDie := func(basePath string) int { return fileToInt(filepath.Join(basePath, "die_id")) @@ -149,18 +139,16 @@ func init() { return 0 } - for _, c := range cache.HwthreadList { - cache.CpuData = - append( - cache.CpuData, - HwthreadEntry{ - CpuID: c, - Socket: -1, - NumaDomain: -1, - Die: -1, - Core: -1, - }, - ) + cache.CpuData = make([]HwthreadEntry, len(cache.HwthreadList)) + for i := range cache.HwthreadList { + cache.CpuData[i] = + HwthreadEntry{ + CpuID: cache.HwthreadList[i], + Socket: cache.SocketList[i], + NumaDomain: -1, + Die: -1, + Core: cache.CoreList[i], + } } for i := range cache.CpuData { cEntry := &cache.CpuData[i] @@ -170,12 +158,6 @@ func init() { base := filepath.Join("/sys/devices/system/cpu", cpuStr) topoBase := filepath.Join(base, "topology") - // Lookup CPU core id - cEntry.Core = getCore(topoBase) - - // Lookup CPU socket id - cEntry.Socket = getSocket(topoBase) - // Lookup CPU die id cEntry.Die = getDie(topoBase) if cEntry.Die < 0 {