2022-01-30 14:59:26 +01:00
|
|
|
package ccTopology
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"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"
|
2022-01-30 14:59:26 +01:00
|
|
|
)
|
|
|
|
|
2022-02-07 13:22:26 +01:00
|
|
|
const SYSFS_NUMABASE = `/sys/devices/system/node`
|
|
|
|
const SYSFS_CPUBASE = `/sys/devices/system/cpu`
|
|
|
|
const PROCFS_CPUINFO = `/proc/cpuinfo`
|
|
|
|
|
2022-01-30 14:59:26 +01:00
|
|
|
// intArrayContains scans an array of ints if the value str is present in the array
|
|
|
|
// If the specified value is found, the corresponding array index is returned.
|
|
|
|
// The bool value is used to signal success or failure
|
|
|
|
func intArrayContains(array []int, str int) (int, bool) {
|
|
|
|
for i, a := range array {
|
|
|
|
if a == str {
|
|
|
|
return i, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1, false
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Used internally for sysfs file reads
|
2022-02-01 18:26:54 +01:00
|
|
|
func fileToInt(path string) int {
|
|
|
|
buffer, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
cclogger.ComponentError("ccTopology", "Reading", path, ":", err.Error())
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
sbuffer := strings.Replace(string(buffer), "\n", "", -1)
|
|
|
|
var id int64
|
|
|
|
//_, err = fmt.Scanf("%d", sbuffer, &id)
|
|
|
|
id, err = strconv.ParseInt(sbuffer, 10, 32)
|
|
|
|
if err != nil {
|
|
|
|
cclogger.ComponentError("ccTopology", "Parsing", path, ":", sbuffer, err.Error())
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
return int(id)
|
|
|
|
}
|
2022-01-30 14:59:26 +01:00
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Get list of CPU socket IDs
|
2022-01-30 14:59:26 +01:00
|
|
|
func SocketList() []int {
|
2022-02-07 13:22:26 +01:00
|
|
|
buffer, err := ioutil.ReadFile(string(PROCFS_CPUINFO))
|
2022-01-30 14:59:26 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ll := strings.Split(string(buffer), "\n")
|
2022-05-13 14:28:07 +02:00
|
|
|
packs := make([]int, 0)
|
2022-01-30 14:59:26 +01:00
|
|
|
for _, line := range ll {
|
|
|
|
if strings.HasPrefix(line, "physical id") {
|
|
|
|
lv := strings.Fields(line)
|
|
|
|
id, err := strconv.ParseInt(lv[3], 10, 32)
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
return packs
|
|
|
|
}
|
|
|
|
_, found := intArrayContains(packs, int(id))
|
|
|
|
if !found {
|
|
|
|
packs = append(packs, int(id))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return packs
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Get list of hardware thread IDs in the order of listing in /proc/cpuinfo
|
|
|
|
func HwthreadList() []int {
|
2022-02-07 13:22:26 +01:00
|
|
|
buffer, err := ioutil.ReadFile(string(PROCFS_CPUINFO))
|
2022-01-30 14:59:26 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ll := strings.Split(string(buffer), "\n")
|
2022-02-01 18:26:54 +01:00
|
|
|
cpulist := make([]int, 0)
|
2022-01-30 14:59:26 +01:00
|
|
|
for _, line := range ll {
|
|
|
|
if strings.HasPrefix(line, "processor") {
|
|
|
|
lv := strings.Fields(line)
|
|
|
|
id, err := strconv.ParseInt(lv[2], 10, 32)
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
return cpulist
|
|
|
|
}
|
|
|
|
_, found := intArrayContains(cpulist, int(id))
|
|
|
|
if !found {
|
|
|
|
cpulist = append(cpulist, int(id))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cpulist
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Get list of hardware thread IDs in the order of listing in /proc/cpuinfo
|
|
|
|
// Deprecated! Use HwthreadList()
|
|
|
|
func CpuList() []int {
|
|
|
|
return HwthreadList()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get list of CPU core IDs in the order of listing in /proc/cpuinfo
|
2022-02-01 18:26:54 +01:00
|
|
|
func CoreList() []int {
|
2022-02-07 13:22:26 +01:00
|
|
|
buffer, err := ioutil.ReadFile(string(PROCFS_CPUINFO))
|
2022-02-01 18:26:54 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ll := strings.Split(string(buffer), "\n")
|
|
|
|
corelist := make([]int, 0)
|
|
|
|
for _, line := range ll {
|
|
|
|
if strings.HasPrefix(line, "core id") {
|
|
|
|
lv := strings.Fields(line)
|
|
|
|
id, err := strconv.ParseInt(lv[3], 10, 32)
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
return corelist
|
|
|
|
}
|
|
|
|
_, found := intArrayContains(corelist, int(id))
|
|
|
|
if !found {
|
|
|
|
corelist = append(corelist, int(id))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return corelist
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Get list of NUMA node IDs
|
2022-02-01 18:26:54 +01:00
|
|
|
func NumaNodeList() []int {
|
2022-02-07 13:22:26 +01:00
|
|
|
numaList := make([]int, 0)
|
|
|
|
globPath := filepath.Join(string(SYSFS_NUMABASE), "node*")
|
|
|
|
regexPath := filepath.Join(string(SYSFS_NUMABASE), "node(\\d+)")
|
|
|
|
regex := regexp.MustCompile(regexPath)
|
|
|
|
files, err := filepath.Glob(globPath)
|
2022-02-01 18:26:54 +01:00
|
|
|
if err != nil {
|
2022-02-07 13:22:26 +01:00
|
|
|
cclogger.ComponentError("CCTopology", "NumaNodeList", err.Error())
|
2022-02-01 18:26:54 +01:00
|
|
|
}
|
|
|
|
for _, f := range files {
|
2022-02-07 13:22:26 +01:00
|
|
|
if !regex.MatchString(f) {
|
|
|
|
continue
|
|
|
|
}
|
2022-02-01 18:26:54 +01:00
|
|
|
finfo, err := os.Lstat(f)
|
2022-02-07 13:22:26 +01:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !finfo.IsDir() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
matches := regex.FindStringSubmatch(f)
|
|
|
|
if len(matches) == 2 {
|
|
|
|
id, err := strconv.Atoi(matches[1])
|
2022-02-01 18:26:54 +01:00
|
|
|
if err == nil {
|
2022-02-07 13:22:26 +01:00
|
|
|
if _, found := intArrayContains(numaList, id); !found {
|
|
|
|
numaList = append(numaList, id)
|
2022-02-01 18:26:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-07 13:22:26 +01:00
|
|
|
|
2022-02-01 18:26:54 +01:00
|
|
|
}
|
2022-02-07 13:22:26 +01:00
|
|
|
return numaList
|
2022-02-01 18:26:54 +01:00
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Get list of CPU die IDs
|
2022-02-01 18:26:54 +01:00
|
|
|
func DieList() []int {
|
2022-05-13 14:28:07 +02:00
|
|
|
cpulist := HwthreadList()
|
2022-02-01 18:26:54 +01:00
|
|
|
dielist := make([]int, 0)
|
|
|
|
for _, c := range cpulist {
|
2022-02-07 13:22:26 +01:00
|
|
|
diepath := filepath.Join(string(SYSFS_CPUBASE), fmt.Sprintf("cpu%d", c), "topology/die_id")
|
|
|
|
dieid := fileToInt(diepath)
|
|
|
|
if dieid > 0 {
|
|
|
|
_, found := intArrayContains(dielist, int(dieid))
|
|
|
|
if !found {
|
|
|
|
dielist = append(dielist, int(dieid))
|
|
|
|
}
|
2022-02-01 18:26:54 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-22 15:58:10 +01:00
|
|
|
if len(dielist) > 0 {
|
|
|
|
return dielist
|
|
|
|
}
|
|
|
|
return SocketList()
|
2022-02-01 18:26:54 +01:00
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Get 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{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Structure holding all information about a hardware thread
|
|
|
|
type HwthreadEntry struct {
|
2022-01-30 14:59:26 +01:00
|
|
|
Cpuid int
|
|
|
|
SMT int
|
|
|
|
Core int
|
|
|
|
Socket int
|
|
|
|
Numadomain int
|
|
|
|
Die int
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
func CpuData() []HwthreadEntry {
|
|
|
|
|
|
|
|
// fileToInt := func(path string) int {
|
|
|
|
// buffer, err := ioutil.ReadFile(path)
|
|
|
|
// if err != nil {
|
|
|
|
// log.Print(err)
|
|
|
|
// //cclogger.ComponentError("ccTopology", "Reading", path, ":", err.Error())
|
|
|
|
// return -1
|
|
|
|
// }
|
|
|
|
// sbuffer := strings.Replace(string(buffer), "\n", "", -1)
|
|
|
|
// var id int64
|
|
|
|
// //_, err = fmt.Scanf("%d", sbuffer, &id)
|
|
|
|
// id, err = strconv.ParseInt(sbuffer, 10, 32)
|
|
|
|
// if err != nil {
|
|
|
|
// cclogger.ComponentError("ccTopology", "Parsing", path, ":", sbuffer, err.Error())
|
|
|
|
// return -1
|
|
|
|
// }
|
|
|
|
// return int(id)
|
|
|
|
// }
|
2022-01-30 14:59:26 +01:00
|
|
|
getCore := func(basepath string) int {
|
|
|
|
return fileToInt(fmt.Sprintf("%s/core_id", basepath))
|
|
|
|
}
|
|
|
|
|
|
|
|
getSocket := func(basepath string) int {
|
|
|
|
return fileToInt(fmt.Sprintf("%s/physical_package_id", basepath))
|
|
|
|
}
|
|
|
|
|
|
|
|
getDie := func(basepath string) int {
|
|
|
|
return fileToInt(fmt.Sprintf("%s/die_id", basepath))
|
|
|
|
}
|
|
|
|
|
|
|
|
getSMT := func(cpuid int, basepath string) int {
|
|
|
|
buffer, err := ioutil.ReadFile(fmt.Sprintf("%s/thread_siblings_list", basepath))
|
|
|
|
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
|
|
|
}
|
|
|
|
threadlist := make([]int, 0)
|
|
|
|
sbuffer := strings.Replace(string(buffer), "\n", "", -1)
|
|
|
|
for _, x := range strings.Split(sbuffer, ",") {
|
|
|
|
id, err := strconv.ParseInt(x, 10, 32)
|
|
|
|
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
|
|
|
}
|
|
|
|
threadlist = append(threadlist, int(id))
|
|
|
|
}
|
|
|
|
for i, x := range threadlist {
|
|
|
|
if x == cpuid {
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
getNumaDomain := func(basepath string) int {
|
2022-02-07 13:22:26 +01:00
|
|
|
globPath := filepath.Join(basepath, "node*")
|
|
|
|
regexPath := filepath.Join(basepath, "node(\\d+)")
|
|
|
|
regex := regexp.MustCompile(regexPath)
|
|
|
|
files, err := filepath.Glob(globPath)
|
2022-01-30 14:59:26 +01:00
|
|
|
if err != nil {
|
2022-02-07 13:22:26 +01:00
|
|
|
cclogger.ComponentError("CCTopology", "CpuData:getNumaDomain", err.Error())
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
|
|
|
for _, f := range files {
|
|
|
|
finfo, err := os.Lstat(f)
|
2022-02-07 13:22:26 +01:00
|
|
|
if err == nil && finfo.IsDir() {
|
|
|
|
matches := regex.FindStringSubmatch(f)
|
|
|
|
if len(matches) == 2 {
|
|
|
|
id, err := strconv.Atoi(matches[1])
|
|
|
|
if err == nil {
|
|
|
|
return id
|
|
|
|
}
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
clist := make([]HwthreadEntry, 0)
|
|
|
|
for _, c := range HwthreadList() {
|
|
|
|
clist = append(clist, HwthreadEntry{Cpuid: c})
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
2022-03-22 15:58:10 +01:00
|
|
|
for i, centry := range clist {
|
2022-01-30 14:59:26 +01:00
|
|
|
centry.Socket = -1
|
|
|
|
centry.Numadomain = -1
|
|
|
|
centry.Die = -1
|
|
|
|
centry.Core = -1
|
|
|
|
// Set base directory for topology lookup
|
2022-02-07 13:22:26 +01:00
|
|
|
cpustr := fmt.Sprintf("cpu%d", centry.Cpuid)
|
|
|
|
base := filepath.Join("/sys/devices/system/cpu", cpustr)
|
|
|
|
topoBase := filepath.Join(base, "topology")
|
2022-01-30 14:59:26 +01:00
|
|
|
|
|
|
|
// Lookup CPU core id
|
2022-02-07 13:22:26 +01:00
|
|
|
centry.Core = getCore(topoBase)
|
2022-01-30 14:59:26 +01:00
|
|
|
|
|
|
|
// Lookup CPU socket id
|
2022-02-07 13:22:26 +01:00
|
|
|
centry.Socket = getSocket(topoBase)
|
2022-01-30 14:59:26 +01:00
|
|
|
|
|
|
|
// Lookup CPU die id
|
2022-02-07 13:22:26 +01:00
|
|
|
centry.Die = getDie(topoBase)
|
2022-02-04 18:12:24 +01:00
|
|
|
if centry.Die < 0 {
|
|
|
|
centry.Die = centry.Socket
|
|
|
|
}
|
2022-01-30 14:59:26 +01:00
|
|
|
|
|
|
|
// Lookup SMT thread id
|
2022-02-07 13:22:26 +01:00
|
|
|
centry.SMT = getSMT(centry.Cpuid, topoBase)
|
2022-01-30 14:59:26 +01:00
|
|
|
|
|
|
|
// Lookup NUMA domain id
|
|
|
|
centry.Numadomain = getNumaDomain(base)
|
|
|
|
|
2022-03-22 15:58:10 +01:00
|
|
|
// Update values in output list
|
|
|
|
clist[i] = centry
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
|
|
|
return clist
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Get basic information about the CPU
|
2022-01-30 14:59:26 +01:00
|
|
|
func CpuInfo() CpuInformation {
|
|
|
|
var c CpuInformation
|
|
|
|
|
2022-02-07 13:22:26 +01:00
|
|
|
smtList := make([]int, 0)
|
|
|
|
numaList := make([]int, 0)
|
|
|
|
dieList := make([]int, 0)
|
|
|
|
socketList := make([]int, 0)
|
|
|
|
coreList := make([]int, 0)
|
2022-01-30 14:59:26 +01:00
|
|
|
cdata := CpuData()
|
|
|
|
for _, d := range cdata {
|
2022-02-07 13:22:26 +01:00
|
|
|
if _, ok := intArrayContains(smtList, d.SMT); !ok {
|
|
|
|
smtList = append(smtList, d.SMT)
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
2022-02-07 13:22:26 +01:00
|
|
|
if _, ok := intArrayContains(numaList, d.Numadomain); !ok {
|
|
|
|
numaList = append(numaList, d.Numadomain)
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
2022-02-07 13:22:26 +01:00
|
|
|
if _, ok := intArrayContains(dieList, d.Die); !ok {
|
|
|
|
dieList = append(dieList, d.Die)
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
2022-02-07 13:22:26 +01:00
|
|
|
if _, ok := intArrayContains(socketList, d.Socket); !ok {
|
|
|
|
socketList = append(socketList, d.Socket)
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
2022-02-07 13:22:26 +01:00
|
|
|
if _, ok := intArrayContains(coreList, d.Core); !ok {
|
|
|
|
coreList = append(coreList, d.Core)
|
2022-02-01 18:26:54 +01:00
|
|
|
}
|
2022-01-30 14:59:26 +01:00
|
|
|
}
|
2022-02-07 13:22:26 +01:00
|
|
|
c.NumNumaDomains = len(numaList)
|
|
|
|
c.SMTWidth = len(smtList)
|
|
|
|
c.NumDies = len(dieList)
|
|
|
|
c.NumCores = len(coreList)
|
|
|
|
c.NumSockets = len(socketList)
|
2022-01-30 14:59:26 +01:00
|
|
|
c.NumHWthreads = len(cdata)
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Get the CPU socket ID for a given hardware thread ID
|
|
|
|
func GetHwthreadSocket(cpuid int) int {
|
2022-01-30 14:59:26 +01:00
|
|
|
cdata := CpuData()
|
|
|
|
for _, d := range cdata {
|
|
|
|
if d.Cpuid == cpuid {
|
|
|
|
return d.Socket
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Get the NUMA node ID for a given hardware thread ID
|
|
|
|
func GetHwthreadNumaDomain(cpuid int) int {
|
2022-01-30 14:59:26 +01:00
|
|
|
cdata := CpuData()
|
|
|
|
for _, d := range cdata {
|
|
|
|
if d.Cpuid == cpuid {
|
|
|
|
return d.Numadomain
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Get the CPU die ID for a given hardware thread ID
|
|
|
|
func GetHwthreadDie(cpuid int) int {
|
2022-01-30 14:59:26 +01:00
|
|
|
cdata := CpuData()
|
|
|
|
for _, d := range cdata {
|
|
|
|
if d.Cpuid == cpuid {
|
|
|
|
return d.Die
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Get the CPU core ID for a given hardware thread ID
|
|
|
|
func GetHwthreadCore(cpuid int) int {
|
2022-01-30 14:59:26 +01:00
|
|
|
cdata := CpuData()
|
|
|
|
for _, d := range cdata {
|
|
|
|
if d.Cpuid == cpuid {
|
|
|
|
return d.Core
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|
2022-02-01 18:26:54 +01:00
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Get the all hardware thread ID associated with a CPU socket
|
|
|
|
func GetSocketHwthreads(socket int) []int {
|
2022-02-01 18:26:54 +01:00
|
|
|
all := CpuData()
|
|
|
|
cpulist := make([]int, 0)
|
|
|
|
for _, d := range all {
|
|
|
|
if d.Socket == socket {
|
|
|
|
cpulist = append(cpulist, d.Cpuid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cpulist
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Get the all hardware thread ID associated with a NUMA node
|
|
|
|
func GetNumaDomainHwthreads(domain int) []int {
|
2022-02-01 18:26:54 +01:00
|
|
|
all := CpuData()
|
|
|
|
cpulist := make([]int, 0)
|
|
|
|
for _, d := range all {
|
|
|
|
if d.Numadomain == domain {
|
|
|
|
cpulist = append(cpulist, d.Cpuid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cpulist
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Get the all hardware thread ID associated with a CPU die
|
|
|
|
func GetDieHwthreads(die int) []int {
|
2022-02-01 18:26:54 +01:00
|
|
|
all := CpuData()
|
|
|
|
cpulist := make([]int, 0)
|
|
|
|
for _, d := range all {
|
|
|
|
if d.Die == die {
|
|
|
|
cpulist = append(cpulist, d.Cpuid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cpulist
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:28:07 +02:00
|
|
|
// Get the all hardware thread ID associated with a CPU core
|
|
|
|
func GetCoreHwthreads(core int) []int {
|
2022-02-01 18:26:54 +01:00
|
|
|
all := CpuData()
|
|
|
|
cpulist := make([]int, 0)
|
|
|
|
for _, d := range all {
|
|
|
|
if d.Core == core {
|
|
|
|
cpulist = append(cpulist, d.Cpuid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cpulist
|
|
|
|
}
|