Reduce number of required slices

This commit is contained in:
Holger Obermaier 2023-09-11 13:02:22 +02:00
parent 1b06270e9b
commit 188f0261b5

View File

@ -29,12 +29,12 @@ type HwthreadEntry struct {
} }
var cache struct { var cache struct {
HwthreadList, uniqHwthreadList []int // List of CPU hardware threads HwthreadList []int // List of CPU hardware threads
SMTList, uniqSMTList []int // List of symmetric hyper threading IDs SMTList []int // List of symmetric hyper threading IDs
CoreList, uniqCoreList []int // List of CPU core IDs CoreList []int // List of CPU core IDs
SocketList, uniqSocketList []int // List of CPU sockets (physical) IDs SocketList []int // List of CPU sockets (physical) IDs
DieList, uniqDieList []int // List of CPU Die IDs DieList []int // List of CPU Die IDs
NumaDomainList, uniqNumaDomainList []int // List of NUMA Domains NumaDomainList []int // List of NUMA Domains
CpuData []HwthreadEntry CpuData []HwthreadEntry
} }
@ -224,39 +224,33 @@ func init() {
} }
} }
cache.uniqHwthreadList = slices.Clone(cache.HwthreadList) slices.Sort(cache.HwthreadList)
slices.Sort(cache.uniqHwthreadList) cache.HwthreadList = slices.Compact(cache.HwthreadList)
cache.uniqHwthreadList = slices.Compact(cache.uniqHwthreadList)
cache.uniqSMTList = slices.Clone(cache.SMTList) slices.Sort(cache.SMTList)
slices.Sort(cache.uniqSMTList) cache.SMTList = slices.Compact(cache.SMTList)
cache.uniqSMTList = slices.Compact(cache.uniqSMTList)
cache.uniqCoreList = slices.Clone(cache.CoreList) slices.Sort(cache.CoreList)
slices.Sort(cache.uniqCoreList) cache.CoreList = slices.Compact(cache.CoreList)
cache.uniqCoreList = slices.Compact(cache.uniqCoreList)
cache.uniqSocketList = slices.Clone(cache.SocketList) slices.Sort(cache.SocketList)
slices.Sort(cache.uniqSocketList) cache.SocketList = slices.Compact(cache.SocketList)
cache.uniqSocketList = slices.Compact(cache.uniqSocketList)
cache.uniqDieList = slices.Clone(cache.DieList) slices.Sort(cache.DieList)
slices.Sort(cache.uniqDieList) cache.DieList = slices.Compact(cache.DieList)
cache.uniqDieList = slices.Compact(cache.uniqDieList)
cache.uniqNumaDomainList = slices.Clone(cache.NumaDomainList) slices.Sort(cache.NumaDomainList)
slices.Sort(cache.uniqNumaDomainList) cache.NumaDomainList = slices.Compact(cache.NumaDomainList)
cache.uniqNumaDomainList = slices.Compact(cache.uniqNumaDomainList)
} }
// SocketList gets the list of CPU socket IDs // SocketList gets the list of CPU socket IDs
func SocketList() []int { func SocketList() []int {
return slices.Clone(cache.uniqSocketList) return slices.Clone(cache.SocketList)
} }
// HwthreadList gets the list of hardware thread IDs in the order of listing in /proc/cpuinfo // HwthreadList gets the list of hardware thread IDs in the order of listing in /proc/cpuinfo
func HwthreadList() []int { func HwthreadList() []int {
return slices.Clone(cache.uniqHwthreadList) return slices.Clone(cache.HwthreadList)
} }
// Get list of hardware thread IDs in the order of listing in /proc/cpuinfo // Get list of hardware thread IDs in the order of listing in /proc/cpuinfo
@ -267,18 +261,18 @@ func CpuList() []int {
// CoreList gets the list of CPU core IDs in the order of listing in /proc/cpuinfo // CoreList gets the list of CPU core IDs in the order of listing in /proc/cpuinfo
func CoreList() []int { func CoreList() []int {
return slices.Clone(cache.uniqCoreList) return slices.Clone(cache.CoreList)
} }
// Get list of NUMA node IDs // Get list of NUMA node IDs
func NumaNodeList() []int { func NumaNodeList() []int {
return slices.Clone(cache.uniqNumaDomainList) return slices.Clone(cache.NumaDomainList)
} }
// DieList gets the list of CPU die IDs // DieList gets the list of CPU die IDs
func DieList() []int { func DieList() []int {
if len(cache.uniqDieList) > 0 { if len(cache.DieList) > 0 {
return slices.Clone(cache.uniqDieList) return slices.Clone(cache.DieList)
} }
return SocketList() return SocketList()
} }
@ -325,12 +319,12 @@ type CpuInformation struct {
// CpuInformation reports basic information about the CPU // CpuInformation reports basic information about the CPU
func CpuInfo() CpuInformation { func CpuInfo() CpuInformation {
return CpuInformation{ return CpuInformation{
NumNumaDomains: len(cache.uniqNumaDomainList), NumNumaDomains: len(cache.NumaDomainList),
SMTWidth: len(cache.uniqSMTList), SMTWidth: len(cache.SMTList),
NumDies: len(cache.uniqDieList), NumDies: len(cache.DieList),
NumCores: len(cache.uniqCoreList), NumCores: len(cache.CoreList),
NumSockets: len(cache.uniqSocketList), NumSockets: len(cache.SocketList),
NumHWthreads: len(cache.uniqHwthreadList), NumHWthreads: len(cache.HwthreadList),
} }
} }