Files
nomad/scheduler/numa_ce.go
Seth Hoenig 8b093a6a5d scheduler: support for device - aware numa scheduling (#1760) (#23837)
(CE backport of ENT 59433d56c7215c0b8bf33764f41b57d9bd30160f (without ent files))

* scheduler: enhance numa aware scheduling with support for devices

* cr: add comments
2024-08-20 07:53:04 -05:00

52 lines
1.5 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
//go:build !ent
package scheduler
import (
"math/rand"
"github.com/hashicorp/nomad/client/lib/idset"
"github.com/hashicorp/nomad/client/lib/numalib"
"github.com/hashicorp/nomad/client/lib/numalib/hw"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/nomad/structs"
)
type coreSelector struct {
topology *numalib.Topology
availableCores *idset.Set[hw.CoreID]
shuffle func([]numalib.Core)
deviceMemoryNode int
}
// Select returns a set of CoreIDs that satisfy the requested core reservations,
// as well as the amount of CPU bandwidth represented by those specific cores.
//
// NUMA preference is available in ent only.
func (cs *coreSelector) Select(ask *structs.Resources) ([]uint16, hw.MHz) {
cores := cs.availableCores.Slice()[0:ask.Cores]
mhz := hw.MHz(0)
for _, core := range cores {
mhz += cs.topology.Cores[core].MHz()
}
ids := helper.ConvertSlice(cores, func(id hw.CoreID) uint16 { return uint16(id) })
return ids, mhz
}
// randomize the cores so we can at least try to mitigate PFNR problems
func randomizeCores(cores []numalib.Core) {
rand.Shuffle(len(cores), func(x, y int) {
cores[x], cores[y] = cores[y], cores[x]
})
}
// candidateMemoryNodes return -1 on CE, indicating any memory node is acceptable
//
// (NUMA aware scheduling is an enterprise feature)
func (cs *coreSelector) candidateMemoryNodes(ask *structs.Resources) []int {
return []int{-1}
}