2022-01-30 14:59:26 +01:00
|
|
|
package ccTopology
|
|
|
|
|
|
|
|
import (
|
2023-09-06 10:03:33 +02:00
|
|
|
"bufio"
|
2022-01-30 14:59:26 +01:00
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2022-02-07 13:22:26 +01:00
|
|
|
"regexp"
|
2022-01-30 14:59:26 +01:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2022-10-10 11:53:11 +02:00
|
|
|
cclogger "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
|
2023-09-06 09:45:01 +02:00
|
|
|
"golang.org/x/exp/slices"
|
2022-01-30 14:59:26 +01:00
|
|
|
)
|
|
|
|
|
2023-09-06 09:45:01 +02:00
|
|
|
const (
|
|
|
|
SYSFS_NUMABASE = `/sys/devices/system/node`
|
|
|
|
SYSFS_CPUBASE = `/sys/devices/system/cpu`
|
|
|
|
PROCFS_CPUINFO = `/proc/cpuinfo`
|
|
|
|
)
|
2022-01-30 14:59:26 +01:00
|
|
|
|
2023-09-06 16:46:30 +02:00
|
|
|
// Structure holding all information about a hardware thread
|
|
|
|
type HwthreadEntry struct {
|
|
|
|
CpuID int
|
|
|
|
SMT int
|
|
|
|
Core int
|
|
|
|
Socket int
|
|
|
|
NumaDomain int
|
|
|
|
Die int
|
|
|
|
}
|
|
|
|
|
2023-09-06 16:19:16 +02:00
|
|
|
var cache struct {
|
2023-09-07 10:11:20 +02:00
|
|
|
HwthreadList []int
|
|
|
|
uniqHwthreadList []int
|
2023-09-07 11:45:38 +02:00
|
|
|
|
|
|
|
CoreList []int
|
|
|
|
uniqCoreList []int
|
|
|
|
|
|
|
|
SocketList []int
|
|
|
|
uniqSocketList []int
|
|
|
|
|
2023-09-07 13:04:16 +02:00
|
|
|
DieList []int
|
|
|
|
uniqDieList []int
|
|
|
|
|
2023-09-07 11:45:38 +02:00
|
|
|
CpuData []HwthreadEntry
|
2023-09-06 16:19:16 +02:00
|
|
|
}
|
|
|
|
|
2023-09-07 10:11:20 +02:00
|
|
|
func init() {
|
2023-09-06 17:29:37 +02:00
|
|
|
file, err := os.Open(PROCFS_CPUINFO)
|
2022-01-30 14:59:26 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
2023-09-06 16:19:16 +02:00
|
|
|
return
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
2023-09-06 10:03:33 +02:00
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
for scanner.Scan() {
|
2023-09-06 16:19:16 +02:00
|
|
|
lineSplit := strings.Split(scanner.Text(), ":")
|
|
|
|
if len(lineSplit) == 2 {
|
|
|
|
key := strings.TrimSpace(lineSplit[0])
|
|
|
|
value := strings.TrimSpace(lineSplit[1])
|
|
|
|
switch key {
|
|
|
|
case "physical id":
|
|
|
|
id, err := strconv.Atoi(value)
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
return
|
|
|
|
}
|
2023-09-07 10:11:20 +02:00
|
|
|
cache.SocketList = append(cache.SocketList, id)
|
2023-09-06 16:19:16 +02:00
|
|
|
case "processor":
|
|
|
|
id, err := strconv.Atoi(value)
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
return
|
|
|
|
}
|
2023-09-07 10:11:20 +02:00
|
|
|
cache.HwthreadList = append(cache.HwthreadList, id)
|
2023-09-06 16:19:16 +02:00
|
|
|
case "core id":
|
|
|
|
id, err := strconv.Atoi(value)
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
return
|
|
|
|
}
|
2023-09-07 10:11:20 +02:00
|
|
|
cache.CoreList = append(cache.CoreList, id)
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-07 13:04:16 +02:00
|
|
|
cache.DieList = make([]int, len(cache.HwthreadList))
|
|
|
|
for i, c := range cache.HwthreadList {
|
|
|
|
// Set base directory for topology lookup
|
|
|
|
cpuStr := fmt.Sprintf("cpu%d", c)
|
|
|
|
base := filepath.Join("/sys/devices/system/cpu", cpuStr)
|
|
|
|
topoBase := filepath.Join(base, "topology")
|
|
|
|
|
|
|
|
// Lookup CPU die id
|
|
|
|
cache.DieList[i] = fileToInt(filepath.Join(topoBase, "die_id"))
|
|
|
|
if cache.DieList[i] < 0 {
|
|
|
|
cache.DieList[i] = cache.SocketList[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-07 10:11:20 +02:00
|
|
|
cache.uniqHwthreadList = slices.Clone(cache.HwthreadList)
|
|
|
|
slices.Sort(cache.uniqHwthreadList)
|
|
|
|
cache.uniqHwthreadList = slices.Compact(cache.uniqHwthreadList)
|
2022-05-13 14:28:07 +02:00
|
|
|
|
2023-09-07 10:11:20 +02:00
|
|
|
cache.uniqCoreList = slices.Clone(cache.CoreList)
|
|
|
|
slices.Sort(cache.uniqCoreList)
|
|
|
|
cache.uniqCoreList = slices.Compact(cache.uniqCoreList)
|
2022-05-13 14:28:07 +02:00
|
|
|
|
2023-09-07 10:11:20 +02:00
|
|
|
cache.uniqSocketList = slices.Clone(cache.SocketList)
|
|
|
|
slices.Sort(cache.uniqSocketList)
|
|
|
|
cache.uniqSocketList = slices.Compact(cache.uniqSocketList)
|
2022-05-13 14:28:07 +02:00
|
|
|
|
2023-09-07 13:04:16 +02:00
|
|
|
cache.uniqDieList = slices.Clone(cache.DieList)
|
|
|
|
slices.Sort(cache.uniqDieList)
|
|
|
|
cache.uniqDieList = slices.Compact(cache.uniqDieList)
|
2023-09-06 11:35:45 +02:00
|
|
|
|
|
|
|
getSMT :=
|
|
|
|
func(cpuID int, basePath string) int {
|
2023-09-06 16:46:30 +02:00
|
|
|
buffer, err := os.ReadFile(filepath.Join(basePath, "thread_siblings_list"))
|
2022-01-30 14:59:26 +01:00
|
|
|
if err != nil {
|
2022-02-07 13:22:26 +01:00
|
|
|
cclogger.ComponentError("CCTopology", "CpuData:getSMT", err.Error())
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
2023-09-06 11:35:45 +02:00
|
|
|
threadList := make([]int, 0)
|
|
|
|
stringBuffer := strings.TrimSpace(string(buffer))
|
|
|
|
for _, x := range strings.Split(stringBuffer, ",") {
|
2023-09-06 15:28:49 +02:00
|
|
|
id, err := strconv.Atoi(x)
|
2023-09-06 11:35:45 +02:00
|
|
|
if err != nil {
|
|
|
|
cclogger.ComponentError("CCTopology", "CpuData:getSMT", err.Error())
|
|
|
|
}
|
2023-09-06 15:28:49 +02:00
|
|
|
threadList = append(threadList, id)
|
2023-09-06 11:35:45 +02:00
|
|
|
}
|
|
|
|
if i := slices.Index(threadList, cpuID); i != -1 {
|
2022-01-30 14:59:26 +01:00
|
|
|
return i
|
|
|
|
}
|
2023-09-06 11:35:45 +02:00
|
|
|
return 1
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
|
|
|
|
2023-09-06 11:35:45 +02:00
|
|
|
getNumaDomain :=
|
|
|
|
func(basePath string) int {
|
|
|
|
globPath := filepath.Join(basePath, "node*")
|
|
|
|
regexPath := filepath.Join(basePath, "node([[:digit:]]+)")
|
|
|
|
regex := regexp.MustCompile(regexPath)
|
|
|
|
files, err := filepath.Glob(globPath)
|
|
|
|
if err != nil {
|
|
|
|
cclogger.ComponentError("CCTopology", "CpuData:getNumaDomain", err.Error())
|
|
|
|
}
|
|
|
|
for _, file := range files {
|
|
|
|
matches := regex.FindStringSubmatch(file)
|
2022-02-07 13:22:26 +01:00
|
|
|
if len(matches) == 2 {
|
|
|
|
id, err := strconv.Atoi(matches[1])
|
|
|
|
if err == nil {
|
|
|
|
return id
|
|
|
|
}
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-06 11:35:45 +02:00
|
|
|
return 0
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
|
|
|
|
2023-09-07 10:24:43 +02:00
|
|
|
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,
|
2023-09-07 13:04:16 +02:00
|
|
|
Die: cache.DieList[i],
|
2023-09-07 10:24:43 +02:00
|
|
|
Core: cache.CoreList[i],
|
|
|
|
}
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
2023-09-06 16:46:30 +02:00
|
|
|
for i := range cache.CpuData {
|
|
|
|
cEntry := &cache.CpuData[i]
|
2023-09-06 11:35:45 +02:00
|
|
|
|
2022-01-30 14:59:26 +01:00
|
|
|
// Set base directory for topology lookup
|
2023-09-06 11:35:45 +02:00
|
|
|
cpuStr := fmt.Sprintf("cpu%d", cEntry.CpuID)
|
|
|
|
base := filepath.Join("/sys/devices/system/cpu", cpuStr)
|
2022-02-07 13:22:26 +01:00
|
|
|
topoBase := filepath.Join(base, "topology")
|
2022-01-30 14:59:26 +01:00
|
|
|
|
|
|
|
// Lookup SMT thread id
|
2023-09-06 11:35:45 +02:00
|
|
|
cEntry.SMT = getSMT(cEntry.CpuID, topoBase)
|
2022-01-30 14:59:26 +01:00
|
|
|
|
|
|
|
// Lookup NUMA domain id
|
2023-09-06 11:35:45 +02:00
|
|
|
cEntry.NumaDomain = getNumaDomain(base)
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
2023-09-06 16:46:30 +02:00
|
|
|
}
|
|
|
|
|
2023-09-07 10:11:20 +02:00
|
|
|
// fileToInt reads an integer value from a file
|
|
|
|
// In case of an error -1 is returned
|
|
|
|
// Used internally for sysfs file reads
|
|
|
|
func fileToInt(path string) int {
|
|
|
|
buffer, err := os.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
cclogger.ComponentError("ccTopology", "Reading", path, ":", err.Error())
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
stringBuffer := strings.TrimSpace(string(buffer))
|
|
|
|
id, err := strconv.Atoi(stringBuffer)
|
|
|
|
if err != nil {
|
|
|
|
cclogger.ComponentError("ccTopology", "Parsing", path, ":", stringBuffer, err.Error())
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// SocketList gets the list of CPU socket IDs
|
|
|
|
func SocketList() []int {
|
|
|
|
return slices.Clone(cache.uniqSocketList)
|
|
|
|
}
|
|
|
|
|
|
|
|
// HwthreadList gets the list of hardware thread IDs in the order of listing in /proc/cpuinfo
|
|
|
|
func HwthreadList() []int {
|
|
|
|
return slices.Clone(cache.uniqHwthreadList)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get list of hardware thread IDs in the order of listing in /proc/cpuinfo
|
|
|
|
// Deprecated! Use HwthreadList()
|
|
|
|
func CpuList() []int {
|
|
|
|
return HwthreadList()
|
|
|
|
}
|
|
|
|
|
|
|
|
// CoreList gets the list of CPU core IDs in the order of listing in /proc/cpuinfo
|
|
|
|
func CoreList() []int {
|
|
|
|
return slices.Clone(cache.uniqCoreList)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get list of NUMA node IDs
|
|
|
|
func NumaNodeList() []int {
|
|
|
|
numaList := make([]int, 0)
|
|
|
|
globPath := filepath.Join(SYSFS_NUMABASE, "node*")
|
|
|
|
regexPath := filepath.Join(SYSFS_NUMABASE, "node(\\d+)")
|
|
|
|
regex := regexp.MustCompile(regexPath)
|
|
|
|
files, err := filepath.Glob(globPath)
|
|
|
|
if err != nil {
|
|
|
|
cclogger.ComponentError("CCTopology", "NumaNodeList", err.Error())
|
2023-09-06 16:46:30 +02:00
|
|
|
}
|
2023-09-07 10:11:20 +02:00
|
|
|
for _, f := range files {
|
|
|
|
if !regex.MatchString(f) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
finfo, err := os.Lstat(f)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !finfo.IsDir() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
matches := regex.FindStringSubmatch(f)
|
|
|
|
if len(matches) == 2 {
|
|
|
|
id, err := strconv.Atoi(matches[1])
|
|
|
|
if err == nil {
|
|
|
|
if found := slices.Contains(numaList, id); !found {
|
|
|
|
numaList = append(numaList, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return numaList
|
|
|
|
}
|
|
|
|
|
|
|
|
// DieList gets the list of CPU die IDs
|
|
|
|
func DieList() []int {
|
|
|
|
cpuList := HwthreadList()
|
|
|
|
dieList := make([]int, 0)
|
|
|
|
for _, c := range cpuList {
|
|
|
|
diePath := filepath.Join(
|
|
|
|
SYSFS_CPUBASE,
|
|
|
|
fmt.Sprintf("cpu%d", c),
|
|
|
|
"topology/die_id")
|
|
|
|
dieID := fileToInt(diePath)
|
|
|
|
if dieID > 0 {
|
|
|
|
if found := slices.Contains(dieList, dieID); !found {
|
|
|
|
dieList = append(dieList, dieID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(dieList) > 0 {
|
|
|
|
return dieList
|
|
|
|
}
|
|
|
|
return SocketList()
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTypeList gets the list of specified type using the naming format inside ClusterCockpit
|
|
|
|
func GetTypeList(topology_type string) []int {
|
|
|
|
switch topology_type {
|
|
|
|
case "node":
|
|
|
|
return []int{0}
|
|
|
|
case "socket":
|
|
|
|
return SocketList()
|
|
|
|
case "die":
|
|
|
|
return DieList()
|
|
|
|
case "memoryDomain":
|
|
|
|
return NumaNodeList()
|
|
|
|
case "core":
|
|
|
|
return CoreList()
|
|
|
|
case "hwthread":
|
|
|
|
return HwthreadList()
|
|
|
|
}
|
|
|
|
return []int{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func CpuData() []HwthreadEntry {
|
2023-09-06 16:46:30 +02:00
|
|
|
return slices.Clone(cache.CpuData)
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Structure holding basic information about a CPU
|
2022-01-30 14:59:26 +01:00
|
|
|
type CpuInformation struct {
|
|
|
|
NumHWthreads int
|
|
|
|
SMTWidth int
|
|
|
|
NumSockets int
|
|
|
|
NumDies int
|
2022-02-01 18:26:54 +01:00
|
|
|
NumCores int
|
2022-01-30 14:59:26 +01:00
|
|
|
NumNumaDomains int
|
|
|
|
}
|
|
|
|
|
2023-09-06 15:28:49 +02:00
|
|
|
// CpuInformation reports basic information about the CPU
|
2022-01-30 14:59:26 +01:00
|
|
|
func CpuInfo() CpuInformation {
|
|
|
|
|
2022-02-07 13:22:26 +01:00
|
|
|
smtList := make([]int, 0)
|
|
|
|
numaList := make([]int, 0)
|
2023-09-07 11:45:38 +02:00
|
|
|
for i := range cache.CpuData {
|
|
|
|
d := &cache.CpuData[i]
|
2023-09-06 09:45:01 +02:00
|
|
|
if ok := slices.Contains(smtList, d.SMT); !ok {
|
2022-02-07 13:22:26 +01:00
|
|
|
smtList = append(smtList, d.SMT)
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
2023-09-06 10:37:57 +02:00
|
|
|
if ok := slices.Contains(numaList, d.NumaDomain); !ok {
|
|
|
|
numaList = append(numaList, d.NumaDomain)
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-06 09:45:01 +02:00
|
|
|
return CpuInformation{
|
|
|
|
NumNumaDomains: len(numaList),
|
|
|
|
SMTWidth: len(smtList),
|
2023-09-07 13:04:16 +02:00
|
|
|
NumDies: len(cache.uniqDieList),
|
2023-09-07 11:45:38 +02:00
|
|
|
NumCores: len(cache.uniqCoreList),
|
|
|
|
NumSockets: len(cache.uniqSocketList),
|
|
|
|
NumHWthreads: len(cache.uniqHwthreadList),
|
2023-09-06 09:45:01 +02:00
|
|
|
}
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
|
|
|
|
2023-09-06 15:28:49 +02:00
|
|
|
// GetHwthreadSocket gets the CPU socket ID for a given hardware thread ID
|
|
|
|
// In case hardware thread ID is not found -1 is returned
|
|
|
|
func GetHwthreadSocket(cpuID int) int {
|
2023-09-07 11:45:38 +02:00
|
|
|
for i := range cache.CpuData {
|
|
|
|
d := &cache.CpuData[i]
|
2023-09-06 15:28:49 +02:00
|
|
|
if d.CpuID == cpuID {
|
2022-01-30 14:59:26 +01:00
|
|
|
return d.Socket
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
2023-09-06 15:28:49 +02:00
|
|
|
// GetHwthreadNumaDomain gets the NUMA domain ID for a given hardware thread ID
|
|
|
|
// In case hardware thread ID is not found -1 is returned
|
|
|
|
func GetHwthreadNumaDomain(cpuID int) int {
|
2023-09-07 11:45:38 +02:00
|
|
|
for i := range cache.CpuData {
|
|
|
|
d := &cache.CpuData[i]
|
2023-09-06 15:28:49 +02:00
|
|
|
if d.CpuID == cpuID {
|
2023-09-06 10:37:57 +02:00
|
|
|
return d.NumaDomain
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
2023-09-06 15:28:49 +02:00
|
|
|
// GetHwthreadDie gets the CPU die ID for a given hardware thread ID
|
|
|
|
// In case hardware thread ID is not found -1 is returned
|
|
|
|
func GetHwthreadDie(cpuID int) int {
|
2023-09-07 11:45:38 +02:00
|
|
|
for i := range cache.CpuData {
|
|
|
|
d := &cache.CpuData[i]
|
2023-09-06 15:28:49 +02:00
|
|
|
if d.CpuID == cpuID {
|
2022-01-30 14:59:26 +01:00
|
|
|
return d.Die
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
2023-09-06 15:28:49 +02:00
|
|
|
// GetHwthreadCore gets the CPU core ID for a given hardware thread ID
|
|
|
|
// In case hardware thread ID is not found -1 is returned
|
|
|
|
func GetHwthreadCore(cpuID int) int {
|
2023-09-07 11:45:38 +02:00
|
|
|
for i := range cache.CpuData {
|
|
|
|
d := &cache.CpuData[i]
|
2023-09-06 15:28:49 +02:00
|
|
|
if d.CpuID == cpuID {
|
2022-01-30 14:59:26 +01:00
|
|
|
return d.Core
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|
2022-02-01 18:26:54 +01:00
|
|
|
|
2023-09-06 15:28:49 +02:00
|
|
|
// GetSocketHwthreads gets all hardware thread IDs associated with a CPU socket
|
2022-05-13 14:28:07 +02:00
|
|
|
func GetSocketHwthreads(socket int) []int {
|
2023-09-06 15:28:49 +02:00
|
|
|
cpuList := make([]int, 0)
|
2023-09-07 13:04:16 +02:00
|
|
|
for i := range cache.CpuData {
|
|
|
|
d := &cache.CpuData[i]
|
2022-02-01 18:26:54 +01:00
|
|
|
if d.Socket == socket {
|
2023-09-06 15:28:49 +02:00
|
|
|
cpuList = append(cpuList, d.CpuID)
|
2022-02-01 18:26:54 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-06 15:28:49 +02:00
|
|
|
return cpuList
|
2022-02-01 18:26:54 +01:00
|
|
|
}
|
|
|
|
|
2023-09-06 15:28:49 +02:00
|
|
|
// GetNumaDomainHwthreads gets the all hardware thread IDs associated with a NUMA domain
|
|
|
|
func GetNumaDomainHwthreads(numaDomain int) []int {
|
|
|
|
cpuList := make([]int, 0)
|
2023-09-07 13:04:16 +02:00
|
|
|
for i := range cache.CpuData {
|
|
|
|
d := &cache.CpuData[i]
|
2023-09-06 15:28:49 +02:00
|
|
|
if d.NumaDomain == numaDomain {
|
|
|
|
cpuList = append(cpuList, d.CpuID)
|
2022-02-01 18:26:54 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-06 15:28:49 +02:00
|
|
|
return cpuList
|
2022-02-01 18:26:54 +01:00
|
|
|
}
|
|
|
|
|
2023-09-06 15:28:49 +02:00
|
|
|
// GetDieHwthreads gets all hardware thread IDs associated with a CPU die
|
2022-05-13 14:28:07 +02:00
|
|
|
func GetDieHwthreads(die int) []int {
|
2023-09-06 15:28:49 +02:00
|
|
|
cpuList := make([]int, 0)
|
2023-09-07 13:04:16 +02:00
|
|
|
for i := range cache.CpuData {
|
|
|
|
d := &cache.CpuData[i]
|
2022-02-01 18:26:54 +01:00
|
|
|
if d.Die == die {
|
2023-09-06 15:28:49 +02:00
|
|
|
cpuList = append(cpuList, d.CpuID)
|
2022-02-01 18:26:54 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-06 15:28:49 +02:00
|
|
|
return cpuList
|
2022-02-01 18:26:54 +01:00
|
|
|
}
|
|
|
|
|
2023-09-06 15:28:49 +02:00
|
|
|
// GetCoreHwthreads get all hardware thread IDs associated with a CPU core
|
2022-05-13 14:28:07 +02:00
|
|
|
func GetCoreHwthreads(core int) []int {
|
2023-09-06 15:28:49 +02:00
|
|
|
cpuList := make([]int, 0)
|
2023-09-07 13:04:16 +02:00
|
|
|
for i := range cache.CpuData {
|
|
|
|
d := &cache.CpuData[i]
|
2022-02-01 18:26:54 +01:00
|
|
|
if d.Core == core {
|
2023-09-06 15:28:49 +02:00
|
|
|
cpuList = append(cpuList, d.CpuID)
|
2022-02-01 18:26:54 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-06 15:28:49 +02:00
|
|
|
return cpuList
|
2022-02-01 18:26:54 +01:00
|
|
|
}
|