2021-03-31 07:23:48 +02:00
|
|
|
package model
|
|
|
|
|
2022-01-31 15:16:05 +01:00
|
|
|
import "strconv"
|
|
|
|
|
2021-12-17 15:49:22 +01:00
|
|
|
type Cluster struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
MetricConfig []*MetricConfig `json:"metricConfig"`
|
|
|
|
FilterRanges *FilterRanges `json:"filterRanges"`
|
|
|
|
Partitions []*Partition `json:"partitions"`
|
2021-04-14 18:53:18 +02:00
|
|
|
|
2021-12-17 15:49:22 +01:00
|
|
|
// NOT part of the API:
|
|
|
|
MetricDataRepository *MetricDataRepository `json:"metricDataRepository"`
|
2021-04-22 15:00:54 +02:00
|
|
|
}
|
2021-12-08 10:12:19 +01:00
|
|
|
|
2021-12-17 15:49:22 +01:00
|
|
|
type MetricDataRepository struct {
|
|
|
|
Kind string `json:"kind"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
Token string `json:"token"`
|
2022-01-24 10:06:25 +01:00
|
|
|
|
|
|
|
// If metrics are known to this MetricDataRepository under a different
|
|
|
|
// name than in the `metricConfig` section of the 'cluster.json',
|
|
|
|
// provide this optional mapping of local to remote name for this metric.
|
|
|
|
Renamings map[string]string `json:"metricRenamings"`
|
2021-12-08 10:12:19 +01:00
|
|
|
}
|
2022-01-12 13:03:01 +01:00
|
|
|
|
|
|
|
// Return a list of socket IDs given a list of hwthread IDs.
|
|
|
|
// Even if just one hwthread is in that socket, add it to the list.
|
|
|
|
// If no hwthreads other than those in the argument list are assigned to
|
|
|
|
// one of the sockets in the first return value, return true as the second value.
|
|
|
|
// TODO: Optimize this, there must be a more efficient way/algorithm.
|
2022-01-17 13:33:35 +01:00
|
|
|
func (topo *Topology) GetSocketsFromHWThreads(hwthreads []int) (sockets []int, exclusive bool) {
|
2022-01-12 13:03:01 +01:00
|
|
|
socketsMap := map[int]int{}
|
|
|
|
for _, hwthread := range hwthreads {
|
|
|
|
for socket, hwthreadsInSocket := range topo.Socket {
|
|
|
|
for _, hwthreadInSocket := range hwthreadsInSocket {
|
|
|
|
if hwthread == hwthreadInSocket {
|
|
|
|
socketsMap[socket] += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exclusive = true
|
|
|
|
hwthreadsPerSocket := len(topo.Node) / len(topo.Socket)
|
|
|
|
sockets = make([]int, 0, len(socketsMap))
|
|
|
|
for socket, count := range socketsMap {
|
|
|
|
sockets = append(sockets, socket)
|
|
|
|
exclusive = exclusive && count == hwthreadsPerSocket
|
|
|
|
}
|
|
|
|
|
|
|
|
return sockets, exclusive
|
|
|
|
}
|
2022-01-17 13:33:35 +01:00
|
|
|
|
|
|
|
// Return a list of core IDs given a list of hwthread IDs.
|
|
|
|
// Even if just one hwthread is in that core, add it to the list.
|
|
|
|
// If no hwthreads other than those in the argument list are assigned to
|
|
|
|
// one of the cores in the first return value, return true as the second value.
|
|
|
|
// TODO: Optimize this, there must be a more efficient way/algorithm.
|
|
|
|
func (topo *Topology) GetCoresFromHWThreads(hwthreads []int) (cores []int, exclusive bool) {
|
|
|
|
coresMap := map[int]int{}
|
|
|
|
for _, hwthread := range hwthreads {
|
|
|
|
for core, hwthreadsInCore := range topo.Core {
|
|
|
|
for _, hwthreadInCore := range hwthreadsInCore {
|
|
|
|
if hwthread == hwthreadInCore {
|
|
|
|
coresMap[core] += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exclusive = true
|
|
|
|
hwthreadsPerCore := len(topo.Node) / len(topo.Core)
|
|
|
|
cores = make([]int, 0, len(coresMap))
|
|
|
|
for core, count := range coresMap {
|
|
|
|
cores = append(cores, core)
|
|
|
|
exclusive = exclusive && count == hwthreadsPerCore
|
|
|
|
}
|
|
|
|
|
|
|
|
return cores, exclusive
|
|
|
|
}
|
2022-01-31 15:16:05 +01:00
|
|
|
|
|
|
|
func (topo *Topology) GetAcceleratorIDs() ([]int, error) {
|
|
|
|
accels := make([]int, 0)
|
|
|
|
for _, accel := range topo.Accelerators {
|
|
|
|
id, err := strconv.Atoi(accel.ID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
accels = append(accels, id)
|
|
|
|
}
|
|
|
|
return accels, nil
|
|
|
|
}
|