mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
* numalib: provide a fallback for topology scanning on linux * numalib: better package var names * cl: add cl * lint: fix my sloppy code * cl: fixup wording
48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package numalib
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/hashicorp/nomad/client/lib/idset"
|
|
"github.com/hashicorp/nomad/client/lib/numalib/hw"
|
|
"github.com/shirou/gopsutil/v3/cpu"
|
|
)
|
|
|
|
const (
|
|
genericNodeID = hw.NodeID(0)
|
|
genericSocketID = hw.SocketID(0)
|
|
genericMaxSpeed = hw.KHz(0)
|
|
)
|
|
|
|
func scanGeneric(top *Topology) {
|
|
// hardware may or may not be NUMA, but for now we only
|
|
// detect such topology on linux systems
|
|
top.NodeIDs = idset.Empty[hw.NodeID]()
|
|
top.NodeIDs.Insert(genericNodeID)
|
|
|
|
// cores
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
|
|
count, err := cpu.CountsWithContext(ctx, true)
|
|
if err != nil {
|
|
return
|
|
}
|
|
top.Cores = make([]Core, count)
|
|
|
|
infos, err := cpu.InfoWithContext(ctx)
|
|
if err != nil || len(infos) == 0 {
|
|
return
|
|
}
|
|
|
|
for i := 0; i < count; i++ {
|
|
info := infos[0]
|
|
speed := hw.KHz(hw.MHz(info.Mhz) * 1000)
|
|
top.insert(genericNodeID, genericSocketID, hw.CoreID(i), Performance, genericMaxSpeed, speed)
|
|
}
|
|
}
|